mirror of
https://github.com/thedevs-network/the-guard-bot
synced 2025-08-30 13:47:54 +00:00
Added /groups
This commit is contained in:
2
TODO.md
2
TODO.md
@@ -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.
|
||||
|
30
handlers/commands/groups.js
Normal file
30
handlers/commands/groups.js
Normal 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;
|
2
index.js
2
index.js
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user