2
0
mirror of https://github.com/thedevs-network/the-guard-bot synced 2025-08-30 05:37:59 +00:00

Added /groups

This commit is contained in:
GingerPlusPlus 2017-09-24 23:23:36 +02:00
parent 0b5aa1b02f
commit ac6780f4f5
3 changed files with 33 additions and 1 deletions

View File

@ -33,7 +33,7 @@
- [ ] Ban and remove Arabic/Russian/Indian text.
- [x] `/report` and `@admin` to report a message to admins.
- [ ] `/link` to show the link of current group.
- [ ] `/groups` to show the list of groups' link.
- [x] `/groups` to show the list of groups' link.
- [ ] custom commands -- seeing a defined command, bot should reply with static text, read from db. Can be used to implement `/channel` and `/rules`.
- [ ] `/channel` to show the channel link.
- [x] `/staff` to show the list of admins.

View File

@ -0,0 +1,30 @@
'use strict';
// Utils
const { escapeHtml } = require('../../utils/tg');
// DB
const { listGroups } = require('../../stores/groups');
const config = require('../../config.json');
const entry = group =>
'» ' + (group.username
? '@' + group.username
: escapeHtml(group.title));
const groupsHandler = async ctx => {
if (config.groupsString) {
return ctx.replyWithHTML(config.groupsString);
}
const groups = await listGroups();
const entries = groups.map(entry).join('\n');
return ctx.replyWithHTML(`<b>Groups I manage</b>:\n${entries}`);
/* TODO: Obtain invite links as well, maybe cache them in db */
};
module.exports = groupsHandler;

View File

@ -30,6 +30,7 @@ const banHandler = require('./handlers/commands/ban');
const unbanHandler = require('./handlers/commands/unban');
const reportHandler = require('./handlers/commands/report');
const staffHandler = require('./handlers/commands/staff');
const groupsHandler = require('./handlers/commands/groups');
bot.on('new_chat_members', addedToGroupHandler);
bot.use(leaveUnmanagedHandler);
@ -48,6 +49,7 @@ bot.command('unban', unbanHandler);
bot.command('report', reportHandler);
bot.hears(/^@admins?$/i, reportHandler);
bot.command('staff', staffHandler);
bot.command('groups', groupsHandler);
bot.catch(logErrorProperly);