inline_query
This commit is contained in:
parent
1713148f27
commit
1b77a21274
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "cuffeo",
|
||||
"version": "1.2.1",
|
||||
"version": "1.2.2",
|
||||
"description": "A multi-protocol chatbot library with nearly zero dependencies.",
|
||||
"main": "src/index.mjs",
|
||||
"scripts": {},
|
||||
|
|
|
@ -55,11 +55,12 @@ export default class tg extends EventEmitter {
|
|||
if(!_res.ok)
|
||||
throw { type: "tg", message: _res.description};
|
||||
if(_res.result.length === 0)
|
||||
return;
|
||||
return
|
||||
|
||||
this.lastUpdate = _res.result[_res.result.length - 1].update_id + 1;
|
||||
|
||||
_res.result.forEach(async res => {
|
||||
if(res.hasOwnProperty("message")) {
|
||||
if(res.message?.date >= ~~(Date.now() / 1000) - 10 && res.message?.message_id !== this.lastMessage) {
|
||||
this.lastMessage = res.message.message_id;
|
||||
if(!this.server.user.has(res.message.from.username || res.message.from.first_name)) {
|
||||
|
@ -88,6 +89,16 @@ export default class tg extends EventEmitter {
|
|||
|
||||
this.emit("data", ["message", this.reply(res.message)]);
|
||||
}
|
||||
}
|
||||
else if(res.hasOwnProperty("callback_query")) {
|
||||
this.emit("data", ["callback_query", {
|
||||
...res.callback_query,
|
||||
editMessageText: this.editMessageText.bind(this)
|
||||
}]);
|
||||
}
|
||||
else if(res.hasOwnProperty("inline_query")) {
|
||||
this.emit("data", ["inline_query", res.inline_query]);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(err) {
|
||||
|
@ -103,7 +114,19 @@ export default class tg extends EventEmitter {
|
|||
}, this.options.pollrate);
|
||||
}
|
||||
}
|
||||
async send(chatid, msg, reply = null) {
|
||||
async editMessageText(chat_id, message_id, text, opt = {}) {
|
||||
const opts = {
|
||||
method: "POST",
|
||||
body: {
|
||||
chat_id: chat_id,
|
||||
message_id: message_id,
|
||||
text: text,
|
||||
...opt
|
||||
}
|
||||
};
|
||||
await fetch(`${this.api}/editMessageText`, opts);
|
||||
}
|
||||
async send(chatid, msg, reply = null, opt = {}) {
|
||||
msg = Array.isArray(msg) ? msg.join("\n") : msg;
|
||||
if (msg.length === 0 || msg.length > 2048)
|
||||
return this.emit("data", ["error", "msg to short or to long lol"]);
|
||||
|
@ -112,7 +135,8 @@ export default class tg extends EventEmitter {
|
|||
body: {
|
||||
chat_id: chatid,
|
||||
text: this.format(msg),
|
||||
parse_mode: "HTML"
|
||||
parse_mode: "HTML",
|
||||
...opt
|
||||
}
|
||||
};
|
||||
if (reply)
|
||||
|
@ -138,8 +162,8 @@ export default class tg extends EventEmitter {
|
|||
message: tmp.text,
|
||||
time: tmp.date,
|
||||
raw: tmp,
|
||||
media: tmp.media || null,
|
||||
reply: msg => this.send(tmp.chat.id, msg, tmp.message_id),
|
||||
photo: tmp.media || null,
|
||||
reply: (msg, opt = {}) => this.send(tmp.chat.id, msg, tmp.message_id, opt),
|
||||
replyAction: msg => this.send(tmp.chat.id, `Uwe ${msg}`, tmp.message_id),
|
||||
replyNotice: msg => this.send(tmp.chat.id, msg, tmp.message_id),
|
||||
_user: this.server.user
|
||||
|
@ -150,9 +174,10 @@ export default class tg extends EventEmitter {
|
|||
.split("&").join("&")
|
||||
.split("<").join("<")
|
||||
.split(">").join(">")
|
||||
.replace(/\[b\](.*?)\[\/b\]/g, "<b>$1</b>") // bold
|
||||
.replace(/\[i\](.*?)\[\/i\]/g, "<i>$1</i>") // italic
|
||||
.replace(/\[color=(.*?)](.*?)\[\/color\]/g, "$2")
|
||||
.replace(/\[b\](.*?)\[\/b\]/gsm, "<b>$1</b>") // bold
|
||||
.replace(/\[i\](.*?)\[\/i\]/gsm, "<i>$1</i>") // italic
|
||||
.replace(/\[color=(.*?)](.*?)\[\/color\]/gsm, "$2")
|
||||
.replace(/\[pre\](.*?)\[\/pre\]/gsm, "<pre>$1</pre>")
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user