catch invalid command
This commit is contained in:
parent
c9d312d78f
commit
bf88195901
14
index.mjs
14
index.mjs
@ -26,7 +26,11 @@ bot.on("message", async message => {
|
||||
if (message.text.startsWith('/')) {
|
||||
let respond = text => conversation.sendMessage({text});
|
||||
let cmd = message.text.split(' ')[0].slice(1).toLowerCase();
|
||||
let commandList = `/list, /leave, /join, /ping`;
|
||||
switch(cmd) {
|
||||
case "ping":
|
||||
await respond("pong");
|
||||
return;
|
||||
case "list":
|
||||
let {conversations} = await bot.listConversations();
|
||||
await respond(`${conversations.length} members in group chat: ${conversations.map(c => '@' + c.members.find(m => m.did != bot.profile.did).handle).join(', ')}`);
|
||||
@ -36,13 +40,13 @@ bot.on("message", async message => {
|
||||
await conversation.leave();
|
||||
return;
|
||||
case "join":
|
||||
await respond(`Welcome to the group chat!`);
|
||||
return;
|
||||
case "ping":
|
||||
await respond("pong");
|
||||
await respond(`You joined the group chat`);
|
||||
return;
|
||||
case "help":
|
||||
await respond(`Commands: /list, /leave, /join, /ping`);
|
||||
await respond(`Commands: ${commandList}`);
|
||||
return;
|
||||
default:
|
||||
await respond(`Only these commands are accepted: ${commandList}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user