Skip to content

Commit d9ce330

Browse files
committed
Merge branch 'develop'
2 parents 40ea78e + 702dd57 commit d9ce330

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+667
-333
lines changed

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Don't lint plugins
2+
plugins/*
3+
# ...but do lint plugin loader
4+
!plugins/index.js

.eslintrc.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"error",
2727
"always"
2828
],
29-
"no-console": "off",
29+
"no-console": [ "error", { "allow": [ "assert" ] } ],
3030
"for-direction": "error",
3131
"no-await-in-loop": "error",
3232
"no-extra-parens": "error",
@@ -153,6 +153,7 @@
153153
"allowArrowFunctions": true
154154
}
155155
],
156+
"function-paren-newline": ["error", "multiline"],
156157
"key-spacing": "error",
157158
"keyword-spacing": "error",
158159
"lines-around-comment": "error",
@@ -278,4 +279,4 @@
278279
"symbol-description": "error",
279280
"template-curly-spacing": "error"
280281
}
281-
}
282+
}

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,31 @@ You need [Node.js](https://nodejs.org/) (> 8.1) to run this bot.
1919

2020
Now you can add the bot as **administrator** to your groups.
2121

22+
## Features
23+
* Synchronized database accross multiple groups.
24+
* Adding admins to the bot.
25+
* Auto-remove and warn channels and groups ads.
26+
* Kick bots added by users.
27+
* Warn and ban users to controll the group.
28+
* Commands work with replying, mentioning and ID.
29+
* Removes commands and temporary bot messages.
30+
* Ability to create custom commands.
31+
* Supports plugins.
32+
33+
Overally, keeps the groups clean and healthy to use.
34+
2235
## Commands
2336
Command | Role | Available at | Description
2437
----------------------- | ---------- | ------------ | -----------------
25-
`/admin` | _Master_ | _Everywhere_ | Makes the user admin.
38+
`/admin` | _Master_ | _Everywhere_ | Makes the user admin in the bot and groups.
2639
`/unadmin` | _Master_ | _Everywhere_ | Demotes the user from admin list.
2740
`/leave <name\|id>` | _Master_ | _Everywhere_ | Make the bot to leave the group cleanly.
2841
`/warn <reason>` | _Admin_ | _Groups_ | Warns the user.
2942
`/unwarn` | _Admin_ | _Everywhere_ | Removes the last warn from the user.
3043
`/nowarns` | _Admin_ | _Everywhere_ | Clears warns for the user.
31-
`/getwarns` | _Admin_ | _Everywhere_ | Shows a list of warns for the user.
3244
`/ban <reason>` | _Admin_ | _Groups_ | Bans the user from groups.
3345
`/unban` | _Admin_ | _Everywhere_ | Removes the user from ban list.
46+
`/user` | _Admin_ | _Everywhere_ | Shows the status of the user.
3447
`/addcommand` | _Admin_ | _In-Bot_ | Create a custom command.
3548
`/removecommand <name>` | _Admin_ | _In-Bot_ | Remove a custom command.
3649
`/staff` | _Everyone_ | _Everywhere_ | Shows a list of admins.
@@ -40,7 +53,7 @@ Command | Role | Available at | Description
4053
`/commands` | _Everyone_ | _In-Bot_ | Shows a list of available commands.
4154
`/help` \| `/start` | _Everyone_ | _In-Bot_ | How to use the bot.
4255

43-
All commands and actions are synchronized across all of the groups managed by the owner and they work with both **replying** and **mentioning** a user.
56+
All commands and actions are synchronized across all of the groups managed by the owner and they work with **replying**, **mentioning** or **ID** of a user.
4457

4558
If used by reply, `/ban` and `/warn` would remove the replied-to message.
4659

bot/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const config = require('../config.json');
55

66
const bot = new Telegraf(config.token);
77

8+
if (process.env.NODE_ENV === 'development') {
9+
bot.state.offset = -1;
10+
}
11+
812
module.exports = bot;
913

1014

config.example.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
{
22
"master": 123456789, // master admin ID as a number or username as astring.
33
"token": "", // bot token.
4+
"plugins": [], // list of plugin names to be loaded
5+
6+
"deleteCommands": "own", // which messages with commands should be deleted?
7+
// valid options: "all", "own" (leave commands meant for other bots, this is the default), "none".
8+
49
"numberOfWarnsToBan": 3, // Number of warns that will get someone banned.
510
"groupsInlineKeyboard": [], // [[inlineButton]] -> inline keyboard to be added to reply to /groups
6-
"excludedChannels": [], // [String] -> list of channels usernames to be excluded from warnings, use "*" to disable this feature.
7-
"excludedGroups": [] // [String] -> list of groups links to be excluded from warnings, use "*" to disable this feature.
11+
"warnInlineKeyboard": [], // [[inlineButton]] -> inline keyboard to be added to warn message
12+
13+
// [String] -> list of channels or groups links/usernames that you want to be excluded from warnings
14+
// use "*" to disable this feature.
15+
"excludedChannels": [],
16+
"excludedGroups": []
817
}

handlers/commands/addCommand.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ const addCommandHandler = async ({ chat, reply, state }) => {
1111
if (chat.type !== 'private') return null;
1212

1313
if (!isAdmin) {
14-
return reply('ℹ️ <b>Sorry, only admins access this command.</b>',
15-
replyOptions);
14+
return reply(
15+
'ℹ️ <b>Sorry, only admins access this command.</b>',
16+
replyOptions
17+
);
1618
}
1719
await addCommand({ id: user.id });
18-
return reply('Enter a name for the command without forward slash "/".' +
20+
return reply(
21+
'Enter a name for the command without forward slash "/".' +
1922
'\n\nFor example: <b>rules</b>',
20-
replyOptions);
23+
replyOptions
24+
);
2125
};
2226

2327
module.exports = addCommandHandler;

handlers/commands/admin.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ const adminHandler = async ({ message, reply, state }) => {
3131
}
3232

3333
if (await isAdmin(userToAdmin)) {
34-
return reply(`⭐️ ${link(userToAdmin)} <b>is already admin.</b>`,
35-
replyOptions);
34+
return reply(
35+
`⭐️ ${link(userToAdmin)} <b>is already admin.</b>`,
36+
replyOptions
37+
);
3638
}
3739

3840
if (await getWarns(userToAdmin)) {

handlers/commands/ban.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
// Utils
4-
const { link } = require('../../utils/tg');
4+
const { link, scheduleDeletion } = require('../../utils/tg');
55
const { logError } = require('../../utils/log');
66

77
// Bot
@@ -13,41 +13,50 @@ const { listGroups } = require('../../stores/group');
1313
const { isAdmin, isBanned, ban } = require('../../stores/user');
1414

1515
const banHandler = async ({ chat, message, reply, telegram, me, state }) => {
16-
if (!state.isAdmin) return null;
17-
1816
const userToBan = message.reply_to_message
1917
? message.reply_to_message.from
2018
: message.commandMention
2119
? message.commandMention
2220
: null;
2321
const reason = message.text.split(' ').slice(1).join(' ').trim();
2422

25-
if (!userToBan) {
26-
return reply('ℹ️ <b>Reply to a message or mention a user.</b>',
27-
replyOptions);
23+
if (!state.isAdmin || userToBan.username === me) return null;
24+
25+
if (message.chat.type === 'private') {
26+
return reply(
27+
'ℹ️ <b>This command is only available in groups.</b>',
28+
replyOptions
29+
);
2830
}
2931

30-
if (message.chat.type === 'private' || userToBan.username === me) {
31-
return null;
32+
if (!userToBan) {
33+
return reply(
34+
'ℹ️ <b>Reply to a message or mention a user.</b>',
35+
replyOptions
36+
).then(scheduleDeletion);
3237
}
3338

3439
if (await isAdmin(userToBan)) {
3540
return reply('ℹ️ <b>Can\'t ban other admins.</b>', replyOptions);
3641
}
3742

3843
if (reason.length === 0) {
39-
return reply('ℹ️ <b>Need a reason to ban.</b>', replyOptions);
44+
return reply('ℹ️ <b>Need a reason to ban.</b>', replyOptions)
45+
.then(scheduleDeletion);
4046
}
4147

4248
if (message.reply_to_message) {
4349
bot.telegram.deleteMessage(
4450
chat.id,
45-
message.reply_to_message.message_id);
51+
message.reply_to_message.message_id
52+
);
4653
}
4754

4855
if (await isBanned(userToBan)) {
49-
return reply(`🚫 ${link(userToBan)} <b>is already banned.</b>`,
50-
replyOptions);
56+
return reply(
57+
`🚫 ${link(userToBan)} <b>is already banned.</b>`,
58+
replyOptions
59+
);
5160
}
5261

5362
try {

handlers/commands/commands.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ const commandReference = `\
1313
<code>/warn &lt;reason&gt;</code> - Warns the user.
1414
<code>/unwarn</code> - Removes the last warn from the user.
1515
<code>/nowarns</code> - Clears warns for the user.
16-
<code>/getwarns</code> - Shows a list of warns for the user.
1716
<code>/ban &lt;reason&gt;</code> - Bans the user from groups.
1817
<code>/unban</code> - Removes the user from ban list.
18+
<code>/user</code> - Shows user's status and warns.
1919
2020
<b>Commands for everyone</b>:
2121
<code>/staff</code> - Shows a list of admins.
@@ -25,8 +25,8 @@ const commandReference = `\
2525
`;
2626

2727
const actions = `\n
28-
/addcommand - to create custom commands.
29-
/removecommand <code>&lt;name&gt;</code> - to remove a custom command.`;
28+
<code>/addcommand</code> - to create custom commands.
29+
<code>/removecommand &lt;name&gt;</code> - to remove a custom command.`;
3030

3131
const commandReferenceHandler = async ({ chat, replyWithHTML }) => {
3232
if (chat.type !== 'private') return null;

handlers/commands/getwarns.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)