Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions actions/ban.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const dedent = require('dedent-js');

const { telegram } = require('../bot');
Expand Down
10 changes: 4 additions & 6 deletions actions/warn.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const dedent = require('dedent-js');

const { context } = require('../bot');
Expand All @@ -26,10 +24,10 @@ module.exports = async ({ admin, userToWarn, reason }) => {
reason: 'Reached max number of warnings',
userToBan: userToWarn,
});
return warnMessage +
'\n\n' +
'🚫 The user was <b>banned</b> ' +
`for receiving ${numberOfWarnsToBan} warnings!`;
return warnMessage
+ '\n\n'
+ '🚫 The user was <b>banned</b> '
+ `for receiving ${numberOfWarnsToBan} warnings!`;
}

return warnMessage;
Expand Down
2 changes: 0 additions & 2 deletions bot/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const Telegraf = require('telegraf');
const config = require('../config');

Expand Down
2 changes: 0 additions & 2 deletions bot/options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const replyOptions = {
disable_web_page_preview: true,
parse_mode: 'HTML',
Expand Down
2 changes: 1 addition & 1 deletion example.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';


/*
* Create `config.js` by running `cp example.config.js config.js`
Expand Down
20 changes: 9 additions & 11 deletions handlers/commands/addCommand.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// DB
const { addCommand, getCommand } = require('../../stores/command');

Expand Down Expand Up @@ -27,15 +25,15 @@ const addCommandHandler = async (ctx, next) => {
const isValidName = commandName && commandName.match(/^(?:[!])?(\w+)$/);
if (!isValidName) {
return reply(
'<b>Send a valid command.</b>\n\nExample:\n' +
'<code>/addcommand rules</code>',
'<b>Send a valid command.</b>\n\nExample:\n'
+ '<code>/addcommand rules</code>',
replyOptions
);
}
const newCommand = isValidName[1].toLowerCase();
if (preserved.includes(newCommand)) {
reply('❗️ Sorry you can\'t use this name, it\'s preserved.\n\n' +
'Try another one.');
reply('❗️ Sorry you can\'t use this name, it\'s preserved.\n\n'
+ 'Try another one.');
return next();
}

Expand All @@ -45,11 +43,11 @@ const addCommandHandler = async (ctx, next) => {

if (!replaceCmd && cmdExists) {
return ctx.replyWithHTML(
'ℹ️ <b>This command already exists.</b>\n\n' +
'/commands - to see the list of commands.\n' +
'/addcommand <code>&lt;name&gt;</code> - to add a command.\n' +
'/removecommand <code>&lt;name&gt;</code>' +
' - to remove a command.',
'ℹ️ <b>This command already exists.</b>\n\n'
+ '/commands - to see the list of commands.\n'
+ '/addcommand <code>&lt;name&gt;</code> - to add a command.\n'
+ '/removecommand <code>&lt;name&gt;</code>'
+ ' - to remove a command.',
Markup.keyboard([ [ `/replaceCommand ${newCommand}` ] ])
.oneTime()
.resize()
Expand Down
8 changes: 4 additions & 4 deletions handlers/commands/admin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// Utils
const { link } = require('../../utils/tg');
const { logError } = require('../../utils/log');
Expand Down Expand Up @@ -40,14 +38,16 @@ const adminHandler = async ({ message, reply, state }) => {
if (await getWarns(userToAdmin)) {
try {
await nowarns(userToAdmin);
} catch (err) {
}
catch (err) {
logError(err);
}
}

try {
await admin(userToAdmin);
} catch (err) {
}
catch (err) {
logError(err);
}

Expand Down
2 changes: 0 additions & 2 deletions handlers/commands/ban.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// Utils
const { link, scheduleDeletion } = require('../../utils/tg');

Expand Down
10 changes: 4 additions & 6 deletions handlers/commands/commands.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// DB
const { listCommands } = require('../../stores/command');

Expand Down Expand Up @@ -33,13 +31,13 @@ const commandReferenceHandler = async ({ chat, replyWithHTML }) => {

const customCommands = await listCommands();
const customCommandsText = customCommands.length
? '\n<b>Custom commands:</b>\n' +
customCommands
? '\n<b>Custom commands:</b>\n'
+ customCommands
.filter(command => command.isActive)
.sort((a, b) => a.role.toLowerCase() < b.role.toLowerCase())
.map(command =>
`[${command.role.toLowerCase()}] ` +
`<code>!${command.name}</code>`)
`[${command.role.toLowerCase()}] `
+ `<code>!${command.name}</code>`)
.join('\n')
: '';
return replyWithHTML(commandReference + customCommandsText);
Expand Down
2 changes: 0 additions & 2 deletions handlers/commands/groups.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// Utils
const { escapeHtml, scheduleDeletion } = require('../../utils/tg');

Expand Down
1 change: 0 additions & 1 deletion handlers/commands/help.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
const { Markup } = require('telegraf');
const { homepage } = require('../../package.json');

Expand Down
2 changes: 0 additions & 2 deletions handlers/commands/hideGroup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const { hideGroup } = require('../../stores/group');

const noop = Function.prototype;
Expand Down
6 changes: 2 additions & 4 deletions handlers/commands/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const { Composer } = require('telegraf');

const composer = new Composer();
Expand Down Expand Up @@ -27,8 +25,8 @@ const helpHandler = require('./help');
const { deleteCommands = 'own' } = require('../../config');

if (![ 'all', 'own', 'none' ].includes(deleteCommands)) {
throw new Error('Invalid value for `deleteCommands` in `config.json`: ' +
deleteCommands);
throw new Error('Invalid value for `deleteCommands` in `config.json`: '
+ deleteCommands);
}

const deleteMessage = ({ chat, message, telegram }, next) => {
Expand Down
2 changes: 0 additions & 2 deletions handlers/commands/leave.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const { managesGroup, removeGroup } = require('../../stores/group');

const leaveCommandHandler = async ctx => {
Expand Down
6 changes: 2 additions & 4 deletions handlers/commands/link.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// Utils
const { scheduleDeletion } = require('../../utils/tg');

Expand All @@ -13,8 +11,8 @@ const linkHandler = async ({ chat, replyWithHTML }, next) => {

const group = await managesGroup({ id: chat.id });

return replyWithHTML('ℹ️ <b>Group\'s link:</b>\n\n' +
`<a href="${group.link}">${group.title}</a>`).then(scheduleDeletion);
return replyWithHTML('ℹ️ <b>Group\'s link:</b>\n\n'
+ `<a href="${group.link}">${group.title}</a>`).then(scheduleDeletion);
};

module.exports = linkHandler;
9 changes: 4 additions & 5 deletions handlers/commands/nowarns.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// Utils
const { link, scheduleDeletion } = require('../../utils/tg');
const { logError } = require('../../utils/log');
Expand Down Expand Up @@ -53,7 +51,8 @@ const nowarnsHandler = async ({ message, reply, state, telegram }) => {

try {
await nowarns(userToUnwarn);
} catch (err) {
}
catch (err) {
logError(err);
}

Expand All @@ -69,8 +68,8 @@ const nowarnsHandler = async ({ message, reply, state, telegram }) => {
}

return reply(
`♻️ ${link(user)} <b>pardoned</b> ${link(userToUnwarn)} ` +
'<b>for all of their warnings.</b>',
`♻️ ${link(user)} <b>pardoned</b> ${link(userToUnwarn)} `
+ '<b>for all of their warnings.</b>',
replyOptions
);
};
Expand Down
10 changes: 4 additions & 6 deletions handlers/commands/removeCommand.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// DB
const { getCommand, removeCommand } = require('../../stores/command');

Expand All @@ -20,8 +18,8 @@ const removeCommandHandler = async ({ chat, message, reply, state }) => {
const [ , commandName ] = text.split(' ');
if (!commandName) {
return reply(
'<b>Send a valid command.</b>\n\nExample:\n' +
'<code>/removecommand rules</code>',
'<b>Send a valid command.</b>\n\nExample:\n'
+ '<code>/removecommand rules</code>',
replyOptions
);
}
Expand All @@ -44,8 +42,8 @@ const removeCommandHandler = async ({ chat, message, reply, state }) => {

await removeCommand({ name: commandName.toLowerCase() });
return reply(
`✅ <code>!${commandName}</code> ` +
'<b>has been removed successfully.</b>',
`✅ <code>!${commandName}</code> `
+ '<b>has been removed successfully.</b>',
replyOptions
);
};
Expand Down
12 changes: 5 additions & 7 deletions handlers/commands/report.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// Utils
const { link, scheduleDeletion } = require('../../utils/tg');

Expand All @@ -16,18 +14,18 @@ const reportHandler = async ctx => {
}
const admins = (await ctx.getChatAdministrators())
.filter(member =>
member.status === 'creator' ||
member.can_delete_messages &&
member.can_restrict_members
member.status === 'creator'
|| member.can_delete_messages
&& member.can_restrict_members
// eslint-disable-next-line function-paren-newline
).map(member => member.user);
const adminObjects = admins.map(user => ({
first_name: '​', // small hack to be able to use link function
id: user.id,
}));
const adminsMention = adminObjects.map(link).join('');
const s = `❗️${link(ctx.from)} <b>reported the message to the admins.</b>` +
`${adminsMention}`;
const s = `❗️${link(ctx.from)} <b>reported the message to the admins.</b>`
+ `${adminsMention}`;
return ctx.replyWithHTML(s, {
reply_to_message_id: msg.reply_to_message.message_id
});
Expand Down
5 changes: 2 additions & 3 deletions handlers/commands/showGroup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const { updateGroup } = require('../../stores/group');

module.exports = async (ctx, next) => {
Expand All @@ -13,7 +11,8 @@ module.exports = async (ctx, next) => {
: await ctx.exportChatInviteLink();

return updateGroup({ id, link, title });
} catch (err) {
}
catch (err) {
return ctx.reply(String(err));
}
};
2 changes: 0 additions & 2 deletions handlers/commands/staff.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// Utils
const { quietLink, scheduleDeletion } = require('../../utils/tg');

Expand Down
5 changes: 2 additions & 3 deletions handlers/commands/unadmin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// Utils
const { link, scheduleDeletion } = require('../../utils/tg');
const { logError } = require('../../utils/log');
Expand Down Expand Up @@ -55,7 +53,8 @@ const unAdminHandler = async ({ message, reply, state }) => {

try {
await unadmin(userToUnadmin);
} catch (err) {
}
catch (err) {
logError(err);
}

Expand Down
16 changes: 8 additions & 8 deletions handlers/commands/unban.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// Utils
const { link, scheduleDeletion } = require('../../utils/tg');
const { logError } = require('../../utils/log');
Expand Down Expand Up @@ -42,13 +40,15 @@ const unbanHandler = async ({ message, reply, telegram, state }) => {

try {
await Promise.all(unbans);
} catch (err) {
}
catch (err) {
logError(err);
}

try {
await unban(userToUnban);
} catch (err) {
}
catch (err) {
logError(err);
}

Expand All @@ -62,13 +62,13 @@ const unbanHandler = async ({ message, reply, telegram, state }) => {
// (it's an expected, non-critical failure)

if (userToUnban.first_name === '') {
return reply(`♻️ ${link(user)} <b>unbanned an user ` +
`with id</b> <code>${userToUnban.id}</code>.`, replyOptions);
return reply(`♻️ ${link(user)} <b>unbanned an user `
+ `with id</b> <code>${userToUnban.id}</code>.`, replyOptions);
}


return reply(`♻️ ${link(user)} <b>unbanned</b> ` +
`${link(userToUnban)}.`, replyOptions);
return reply(`♻️ ${link(user)} <b>unbanned</b> `
+ `${link(userToUnban)}.`, replyOptions);
};

module.exports = unbanHandler;
8 changes: 3 additions & 5 deletions handlers/commands/unwarn.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

// Utils
const { link, scheduleDeletion } = require('../../utils/tg');

Expand Down Expand Up @@ -64,9 +62,9 @@ const unwarnHandler = async ({ message, reply, state, telegram }) => {
}

return reply(
`❎ ${link(user)} <b>pardoned</b> ${link(userToUnwarn)} ` +
`<b>for:</b>\n\n${allWarns[allWarns.length - 1]}` +
` (${allWarns.length - 1}/${numberOfWarnsToBan})`,
`❎ ${link(user)} <b>pardoned</b> ${link(userToUnwarn)} `
+ `<b>for:</b>\n\n${allWarns[allWarns.length - 1]}`
+ ` (${allWarns.length - 1}/${numberOfWarnsToBan})`,
replyOptions
);
};
Expand Down
Loading