Compare commits

..

No commits in common. "bf8819590100909229374aa2b90f8e6b100e3153" and "58c92991ebb1286bc60b950fd76223800080de80" have entirely different histories.

View File

@ -6,10 +6,6 @@ var bot = new Bot({
emitEvents: false, emitEvents: false,
emitChatEvents: true emitChatEvents: true
}); });
bot.on("error", error => {
console.error("bot error", error);
});
await bot.login({ await bot.login({
identifier: process.env.IDENTIFIER, identifier: process.env.IDENTIFIER,
password: process.env.PASSWORD password: process.env.PASSWORD
@ -26,11 +22,7 @@ bot.on("message", async message => {
if (message.text.startsWith('/')) { if (message.text.startsWith('/')) {
let respond = text => conversation.sendMessage({text}); let respond = text => conversation.sendMessage({text});
let cmd = message.text.split(' ')[0].slice(1).toLowerCase(); let cmd = message.text.split(' ')[0].slice(1).toLowerCase();
let commandList = `/list, /leave, /join, /ping`;
switch(cmd) { switch(cmd) {
case "ping":
await respond("pong");
return;
case "list": case "list":
let {conversations} = await bot.listConversations(); 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(', ')}`); await respond(`${conversations.length} members in group chat: ${conversations.map(c => '@' + c.members.find(m => m.did != bot.profile.did).handle).join(', ')}`);
@ -40,13 +32,13 @@ bot.on("message", async message => {
await conversation.leave(); await conversation.leave();
return; return;
case "join": case "join":
await respond(`You joined the group chat`); await respond(`Welcome to the group chat!`);
return;
case "ping":
await respond("pong");
return; return;
case "help": case "help":
await respond(`Commands: ${commandList}`); await respond(`Commands: /list, /leave, /join, /ping`);
return;
default:
await respond(`Only these commands are accepted: ${commandList}`);
return; return;
} }
} }