From 1036ad5f887d6f322b8af2f90bd367ea710cc152 Mon Sep 17 00:00:00 2001 From: Pouria Ezzati Date: Sun, 24 Sep 2017 14:28:18 +0330 Subject: [PATCH] added styling format for messages --- handlers/commands/admin.js | 7 ++++--- handlers/commands/ban.js | 11 ++++++----- handlers/commands/getwarns.js | 6 +++--- handlers/commands/nowarns.js | 5 +++-- handlers/commands/unadmin.js | 8 +++++--- handlers/commands/unban.js | 7 ++++--- handlers/commands/unwarn.js | 4 ++-- handlers/commands/warn.js | 10 +++++----- handlers/middlewares/addedToGroup.js | 6 +++++- handlers/middlewares/antibot.js | 6 +++++- handlers/middlewares/middleware.js | 2 +- handlers/middlewares/removeLinks.js | 11 +++++------ 12 files changed, 48 insertions(+), 35 deletions(-) diff --git a/handlers/commands/admin.js b/handlers/commands/admin.js index f39cdc8..c424a9f 100644 --- a/handlers/commands/admin.js +++ b/handlers/commands/admin.js @@ -25,11 +25,12 @@ const adminHandler = async ({ message, reply }) => { : message.from; if (await isBanned(userToAdmin)) { - return reply('Can\'t admin banned user'); + return reply('ℹ️ Can\'t admin banned user.', replyOptions); } if (await isAdmin(userToAdmin)) { - return reply('Already admin'); + return reply(`⭐️ ${link(userToAdmin)} is already admin..`, + replyOptions); } if (await getWarns(userToAdmin)) { @@ -46,7 +47,7 @@ const adminHandler = async ({ message, reply }) => { logError(process.env.DEBUG)(err); } - return reply(`${link(userToAdmin)} is now admin.`, replyOptions); + return reply(`⭐️ ${link(userToAdmin)} is now admin..`, replyOptions); }; module.exports = adminHandler; diff --git a/handlers/commands/ban.js b/handlers/commands/ban.js index 223fbb7..531e46b 100644 --- a/handlers/commands/ban.js +++ b/handlers/commands/ban.js @@ -22,21 +22,22 @@ const banHandler = async ({ chat, message, reply, telegram }) => { const reason = message.text.split(' ').slice(1).join(' ').trim(); if (reason.length === 0) { - return reply('Need a reason to ban'); + return reply('ℹ️ Need a reason to ban.', replyOptions); } if (!message.reply_to_message) { - return reply('Reply to a message'); + return reply('ℹ️ Reply to a message.', replyOptions); } bot.telegram.deleteMessage(chat.id, message.reply_to_message.message_id); if (await isAdmin(userToBan)) { - return reply('Can\'t ban other admin'); + return reply('ℹ️ Can\'t ban other admins.', replyOptions); } if (await isBanned(userToBan)) { - return reply('User is already banned.'); + return reply(`🚫 ${link(userToBan)} is already banned.`, + replyOptions); } try { @@ -56,7 +57,7 @@ const banHandler = async ({ chat, message, reply, telegram }) => { logError(process.env.DEBUG)(err); } - return reply(`${link(userToBan)} has been banned.\n\n` + + return reply(`🚫 ${link(userToBan)} got banned.\n\n` + `Reason: ${reason}`, replyOptions); }; diff --git a/handlers/commands/getwarns.js b/handlers/commands/getwarns.js index ff27ab6..9f88b5e 100644 --- a/handlers/commands/getwarns.js +++ b/handlers/commands/getwarns.js @@ -15,13 +15,13 @@ const getWarnsHandler = async ({ message, reply }) => { return null; } if (!message.reply_to_message) { - return reply('Reply to a message'); + return reply('ℹ️ Reply to a message.', replyOptions); } let i = 0; const theUser = message.reply_to_message.from; - return reply('Warns for ' + link(theUser) + ':\n\n' + + return reply(`⚠️ Warns for ${link(theUser)}:\n\n` + (await Warn.getWarns(theUser)) - .map(x => ++i + '. ' + x) + .map(warn => ++i + '. ' + warn) .join('\n\n'), replyOptions); }; diff --git a/handlers/commands/nowarns.js b/handlers/commands/nowarns.js index f101b23..85d4c0b 100644 --- a/handlers/commands/nowarns.js +++ b/handlers/commands/nowarns.js @@ -16,7 +16,7 @@ const nowarnsHandler = async ({ message, reply }) => { return null; } if (!message.reply_to_message) { - return reply('Reply to a message'); + return reply('ℹ️ Reply to a message.', replyOptions); } const messageToUnwarn = message.reply_to_message; @@ -29,7 +29,8 @@ const nowarnsHandler = async ({ message, reply }) => { } return reply( - `${link(userToUnwarn)} was pardoned for all of their warnings.`, + `♻️ ${link(userToUnwarn)} was pardoned for ` + + 'all of their warnings.', replyOptions); }; diff --git a/handlers/commands/unadmin.js b/handlers/commands/unadmin.js index 39d7117..3aed381 100644 --- a/handlers/commands/unadmin.js +++ b/handlers/commands/unadmin.js @@ -20,13 +20,14 @@ const unAdminHandler = async ({ message, reply }) => { } if (!message.reply_to_message) { - return reply('Reply to a message'); + return reply('ℹ️ Reply to a message.', replyOptions); } const userToUnadmin = message.reply_to_message.from; if (!await isAdmin(userToUnadmin)) { - return reply(`${link(userToUnadmin)} is not admin.`, replyOptions); + return reply(`ℹ️ ${link(userToUnadmin)} is not admin.`, + replyOptions); } try { @@ -35,7 +36,8 @@ const unAdminHandler = async ({ message, reply }) => { logError(process.env.DEBUG)(err); } - return reply(`${link(userToUnadmin)} is no longer admin.`, replyOptions); + return reply(`❗️ ${link(userToUnadmin)} is no longer admin.`, + replyOptions); }; module.exports = unAdminHandler; diff --git a/handlers/commands/unban.js b/handlers/commands/unban.js index 28d2a1f..ed84edc 100644 --- a/handlers/commands/unban.js +++ b/handlers/commands/unban.js @@ -18,13 +18,13 @@ const unbanHandler = async ({ message, reply, telegram }) => { } if (!message.reply_to_message) { - return reply('Reply to a message'); + return reply('ℹ️ Reply to a message.', replyOptions); } const userToUnban = message.reply_to_message.from; if (!await isBanned(userToUnban)) { - return reply('User is not banned.'); + return reply('ℹ️ User is not banned.', replyOptions); } const groups = await listGroups(); @@ -44,7 +44,8 @@ const unbanHandler = async ({ message, reply, telegram }) => { logError(process.env.DEBUG)(err); } - return reply(`${link(userToUnban)} has been unbanned.`, replyOptions); + return reply(`♻️ ${link(userToUnban)} is unbanned.`, + replyOptions); }; module.exports = unbanHandler; diff --git a/handlers/commands/unwarn.js b/handlers/commands/unwarn.js index c29d78d..97fe048 100644 --- a/handlers/commands/unwarn.js +++ b/handlers/commands/unwarn.js @@ -15,7 +15,7 @@ const unwarnHandler = async ({ message, reply }) => { return null; } if (!message.reply_to_message) { - return reply('Reply to a message'); + return reply('ℹ️ Reply to a message.', replyOptions); } const messageToUnwarn = message.reply_to_message; @@ -25,7 +25,7 @@ const unwarnHandler = async ({ message, reply }) => { const warn = await Warn.unwarn(userToUnwarn); return reply( - `${link(userToUnwarn)} was pardoned for: ${warn}\n` + + `❎ ${link(userToUnwarn)} was pardoned for:\n\n${warn}` + `(${allWarns.length}/3)`, replyOptions); }; diff --git a/handlers/commands/warn.js b/handlers/commands/warn.js index d4c01ba..c24080b 100644 --- a/handlers/commands/warn.js +++ b/handlers/commands/warn.js @@ -22,7 +22,7 @@ const warnHandler = async ({ message, chat, reply }) => { return null; } if (!message.reply_to_message) { - return reply('Reply to a message'); + return reply('ℹ️ Reply to a message.', replyOptions); } const messageToWarn = message.reply_to_message; @@ -30,11 +30,11 @@ const warnHandler = async ({ message, chat, reply }) => { const reason = message.text.split(' ').slice(1).join(' ').trim(); if (reason.length === 0) { - return reply('Need a reason to warn'); + return reply('ℹ️ Need a reason to warn.', replyOptions); } if (await isAdmin(userToWarn)) { - return reply('Can\'t warn other admin'); + return reply('ℹ️ Can\'t warn other admins.', replyOptions); } const warnCount = await warn(userToWarn, reason); @@ -45,14 +45,14 @@ const warnHandler = async ({ message, chat, reply }) => { if (warnCount < numberOfWarnsToBan) { promises.push(reply( - `${link(userToWarn)} got warned! (${warnCount}/3)\n\n` + + `⚠️ ${link(userToWarn)} got warned! (${warnCount}/3)\n\n` + `Reason: ${reason}`, replyOptions)); } else { promises.push(bot.telegram.kickChatMember(chat.id, userToWarn.id)); promises.push(ban(userToWarn, 'Reached max number of warnings')); promises.push(reply( - `${link(userToWarn)} banned! (${warnCount}/3)\n` + + `🚫 ${link(userToWarn)} got banned! (${warnCount}/3)\n\n` + 'Reason: Reached max number of warnings', replyOptions)); } diff --git a/handlers/middlewares/addedToGroup.js b/handlers/middlewares/addedToGroup.js index 74896e9..f2226de 100644 --- a/handlers/middlewares/addedToGroup.js +++ b/handlers/middlewares/addedToGroup.js @@ -1,5 +1,8 @@ 'use strict'; +// Bot +const { replyOptions } = require('../../bot/options'); + const { addGroup } = require('../../stores/groups'); const { masterID } = require('../../config.json'); @@ -10,7 +13,8 @@ const addedToGroupHandler = (ctx, next) => { user.username === ctx.me); if (wasAdded && ctx.from.id === masterID) { addGroup(ctx.chat); - ctx.reply('Ok, I\'ll help you manage this group from now.'); + ctx.reply('🛠 Ok, I\'ll help you manage this group from now.', + replyOptions); } return next(); diff --git a/handlers/middlewares/antibot.js b/handlers/middlewares/antibot.js index 313783d..38b2b01 100644 --- a/handlers/middlewares/antibot.js +++ b/handlers/middlewares/antibot.js @@ -1,5 +1,8 @@ 'use strict'; +// Bot +const { replyOptions } = require('../../bot/options'); + // DB const { isAdmin } = require('../../stores/admin'); @@ -24,7 +27,8 @@ const antibotHandler = async (ctx, next) => { ctx.telegram.kickChatMember(ctx.chat.id, bot.id); } - ctx.reply(`Kicked bot(s): ${bots.map(link).join(', ')}`); + ctx.reply(`🚫 Kicked bot(s): ${bots.map(link).join(', ')}`, + replyOptions); return next(); }; diff --git a/handlers/middlewares/middleware.js b/handlers/middlewares/middleware.js index 8db238c..268c56f 100644 --- a/handlers/middlewares/middleware.js +++ b/handlers/middlewares/middleware.js @@ -37,7 +37,7 @@ const middlewareHandler = async ({ chat, from, message, reply }, next) => { if (banned) { return bot.telegram.kickChatMember(chat.id, from.id) .then(() => reply( - `${link(from)} banned!\n` + + `🚫 ${link(from)} is banned!\n\n` + `Reason: ${banned}`, replyOptions)) .catch(logError(process.env.DEBUG)) diff --git a/handlers/middlewares/removeLinks.js b/handlers/middlewares/removeLinks.js index 4208e67..f8d95dc 100644 --- a/handlers/middlewares/removeLinks.js +++ b/handlers/middlewares/removeLinks.js @@ -36,24 +36,23 @@ const removeLinks = async ({ message, chat, reply }, next) => { if (await isAdmin(userToWarn)) { return next(); } - const reason = 'Sent a message which was forwarded ' + - 'from other channels or included their link'; + const reason = 'Channel forward/link'; const warnCount = await warn(userToWarn, reason); const promises = [ bot.telegram.deleteMessage(chat.id, message.message_id) ]; if (warnCount < numberOfWarnsToBan) { promises.push(reply( - `${link(userToWarn)} warned! (${warnCount}/3)\n` + - `Reason: ${reason}`, + `⚠️ ${link(userToWarn)} got warned! (${warnCount}/3)` + + `\n\nReason: ${reason}`, replyOptions)); } else { promises.push(bot.telegram.kickChatMember(chat.id, userToWarn.id)); promises.push(ban(userToWarn, 'Reached max number of warnings')); promises.push(reply( - `${link(userToWarn)} banned! (${warnCount}/3)\n` + - 'Reason: Reached max number of warnings', + `🚫 ${link(userToWarn)} got banned! (${warnCount}/3)` + + '\n\nReason: Reached max number of warnings', replyOptions)); } try {