Should only accept commands if the message starts with them

This commit is contained in:
Mahdi Dibaiee 2015-07-04 23:57:00 +04:30
parent bfa2313f3a
commit 5fd35f89c1
3 changed files with 6 additions and 2 deletions

View File

@ -203,6 +203,7 @@ var Bot = (function (_EventEmitter) {
if (!ev) { if (!ev) {
return; return;
} }
ev.listener(res.message); ev.listener(res.message);
}); });
} }

View File

@ -107,7 +107,7 @@ export default class Bot extends EventEmitter {
*/ */
command(cmd, listener) { command(cmd, listener) {
this._userEvents.push({ this._userEvents.push({
pattern: new RegExp(`/${cmd}`), pattern: new RegExp(`^/${cmd}`),
listener listener
}); });
@ -145,6 +145,8 @@ export default class Bot extends EventEmitter {
const regex = new RegExp(`@${this.info.username}$`); const regex = new RegExp(`@${this.info.username}$`);
text = text.replace(regex, ''); text = text.replace(regex, '');
res.message.text = text; res.message.text = text;
console.log(res.message.text);
} }
let ev = this._userEvents.find(({pattern}) => pattern.test(text)); let ev = this._userEvents.find(({pattern}) => pattern.test(text));
@ -152,6 +154,7 @@ export default class Bot extends EventEmitter {
if (!ev) { if (!ev) {
return; return;
} }
ev.listener(res.message); ev.listener(res.message);
}); });
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "telegram-api", "name": "telegram-api",
"version": "0.4.6", "version": "0.4.61",
"description": "Control Telegram bots easily using the new Telegram API", "description": "Control Telegram bots easily using the new Telegram API",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {