From e84a16eb031642e9ce55875a85d9c28532fc64b5 Mon Sep 17 00:00:00 2001 From: lucmsilva651 Date: Sun, 28 Jul 2024 13:31:04 -0300 Subject: [PATCH] Implement SpamWatch API banlist with Middleware and submodules --- bot.js | 5 +++-- commands/admin.js | 6 ++++-- commands/crew.js | 8 +++++--- commands/fun.js | 10 ++++++---- commands/getinfo.js | 6 ++++-- commands/help.js | 4 +++- commands/privacy.js | 4 +++- commands/random.js | 4 +++- commands/start.js | 4 +++- 9 files changed, 34 insertions(+), 17 deletions(-) diff --git a/bot.js b/bot.js index 80402da..64e7984 100644 --- a/bot.js +++ b/bot.js @@ -1,5 +1,6 @@ const { Telegraf } = require('telegraf'); const Config = require('./props/config.json'); +const { isOnSpamWatch } = require('./plugins/lib-spamwatch/spamwatch.js'); const bot = new Telegraf(Config.botToken); @@ -11,8 +12,8 @@ const loadCommands = () => { fs.readdirSync(commandsPath).forEach((file) => { const command = require(path.join(commandsPath, file)); if (typeof command === 'function') { - command(bot); - }; + command(bot, isOnSpamWatch); + } }); }; diff --git a/commands/admin.js b/commands/admin.js index f632d14..1bc54ea 100644 --- a/commands/admin.js +++ b/commands/admin.js @@ -1,5 +1,7 @@ const Config = require('../props/config.json'); const { getStrings } = require('../plugins/checklang.js'); +const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); +const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch); async function collectInfo(ctx) { const Strings = getStrings(ctx.from.language_code); @@ -14,7 +16,7 @@ async function collectInfo(ctx) { } module.exports = (bot) => { - bot.command('ban', async (ctx) => { + bot.command('ban', spamwatchMiddleware, async (ctx) => { const info = await collectInfo(ctx); const { Strings, chatId, userId, isAdmin, onCrew } = info; @@ -56,7 +58,7 @@ module.exports = (bot) => { }; }); - bot.command('unban', async (ctx) => { + bot.command('unban', spamwatchMiddleware, async (ctx) => { const info = await collectInfo(ctx); const { Strings, chatId, userId, isAdmin, onCrew } = info; diff --git a/commands/crew.js b/commands/crew.js index 7e97f5b..0ec5d5b 100644 --- a/commands/crew.js +++ b/commands/crew.js @@ -1,6 +1,8 @@ // specific commands to the crew const Config = require('../props/config.json'); const { getStrings } = require('../plugins/checklang.js'); +const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); +const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch); const os = require('os'); function formatUptime(uptime) { @@ -34,7 +36,7 @@ function getSystemInfo() { } module.exports = (bot) => { - bot.command('getbotstats', (ctx) => { + bot.command('getbotstats', spamwatchMiddleware, async (ctx) => { const Strings = getStrings(ctx.from.language_code); const userId = ctx.from.id || Strings.unKnown; if (Config.admins.includes(userId)) { @@ -56,7 +58,7 @@ module.exports = (bot) => { } }); - bot.command('setbotname', (ctx) => { + bot.command('setbotname', spamwatchMiddleware, async (ctx) => { const Strings = getStrings(ctx.from.language_code); const userId = ctx.from.id || Strings.unKnown; if (Config.admins.includes(userId)) { @@ -73,7 +75,7 @@ module.exports = (bot) => { } }); - bot.command('setbotdesc', (ctx) => { + bot.command('setbotdesc', spamwatchMiddleware, async (ctx) => { const Strings = getStrings(ctx.from.language_code); const userId = ctx.from.id || Strings.unKnown; if (Config.admins.includes(userId)) { diff --git a/commands/fun.js b/commands/fun.js index 52bfc5a..f700fbd 100644 --- a/commands/fun.js +++ b/commands/fun.js @@ -1,5 +1,7 @@ const resources = require('../props/resources.json'); const { getStrings } = require('../plugins/checklang.js'); +const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); +const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch); function furryFunction(ctx) { const Strings = getStrings(ctx.from.language_code); @@ -42,7 +44,7 @@ function gayFunction(ctx) { } module.exports = (bot) => { - bot.command('dice', async (ctx) => { + bot.command('dice', spamwatchMiddleware, async (ctx) => { ctx.telegram.sendDice( ctx.chat.id, { reply_to_message_id: ctx.message.message_id @@ -50,7 +52,7 @@ module.exports = (bot) => { ); }); - bot.command('slot', async (ctx) => { + bot.command('slot', spamwatchMiddleware, async (ctx) => { ctx.telegram.sendDice( ctx.chat.id, { emoji: '🎰', @@ -59,11 +61,11 @@ module.exports = (bot) => { ); }); - bot.command('furry', (ctx) => { + bot.command('furry', spamwatchMiddleware, async (ctx) => { furryFunction(ctx); }); - bot.command('gay', (ctx) => { + bot.command('gay', spamwatchMiddleware, async (ctx) => { gayFunction(ctx); }); }; \ No newline at end of file diff --git a/commands/getinfo.js b/commands/getinfo.js index e2b6414..8874a2c 100644 --- a/commands/getinfo.js +++ b/commands/getinfo.js @@ -1,4 +1,6 @@ const { getStrings } = require('../plugins/checklang.js'); +const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); +const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch); async function getUserInfo(ctx) { const Strings = getStrings(ctx.from.language_code); @@ -54,7 +56,7 @@ async function getChatInfo(ctx) { } module.exports = (bot) => { - bot.command('chatinfo', async (ctx) => { + bot.command('chatinfo', spamwatchMiddleware, async (ctx) => { const chatInfo = await getChatInfo(ctx); ctx.reply( chatInfo, { @@ -64,7 +66,7 @@ module.exports = (bot) => { ); }); - bot.command('userinfo', async (ctx) => { + bot.command('userinfo', spamwatchMiddleware, async (ctx) => { const userInfo = await getUserInfo(ctx); ctx.reply( userInfo, { diff --git a/commands/help.js b/commands/help.js index 90a3952..09c703c 100644 --- a/commands/help.js +++ b/commands/help.js @@ -1,8 +1,10 @@ const { getStrings } = require('../plugins/checklang.js'); const resources = require('../props/resources.json'); +const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); +const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch); module.exports = (bot) => { - bot.help((ctx) => { + bot.help(spamwatchMiddleware, async (ctx) => { const Strings = getStrings(ctx.from.language_code); ctx.replyWithPhoto( resources.lunaCat2, { diff --git a/commands/privacy.js b/commands/privacy.js index da76ac4..e439558 100644 --- a/commands/privacy.js +++ b/commands/privacy.js @@ -1,7 +1,9 @@ const { getStrings } = require('../plugins/checklang.js'); +const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); +const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch); module.exports = (bot) => { - bot.command('privacy', (ctx) => { + bot.command('privacy', spamwatchMiddleware, async (ctx) => { const Strings = getStrings(ctx.from.language_code); ctx.reply( Strings.lynxPrivacy, { diff --git a/commands/random.js b/commands/random.js index 543532e..750dbc2 100644 --- a/commands/random.js +++ b/commands/random.js @@ -1,11 +1,13 @@ const { getStrings } = require('../plugins/checklang.js'); +const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); +const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch); function getRandomInt(max) { return Math.floor(Math.random() * max); } module.exports = (bot) => { - bot.command('random', (ctx) => { + bot.command('random', spamwatchMiddleware, async (ctx) => { const Strings = getStrings(ctx.from.language_code); const randomValue = getRandomInt(11); const randomVStr = Strings.randomNum.replace('{number}', randomValue); diff --git a/commands/start.js b/commands/start.js index 38c849f..ab8d9a9 100644 --- a/commands/start.js +++ b/commands/start.js @@ -1,8 +1,10 @@ const resources = require('../props/resources.json'); const { getStrings } = require('../plugins/checklang.js'); +const { isOnSpamWatch } = require('../plugins/lib-spamwatch/spamwatch.js'); +const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(isOnSpamWatch); module.exports = (bot) => { - bot.start((ctx) => { + bot.start(spamwatchMiddleware, async (ctx) => { const Strings = getStrings(ctx.from.language_code); ctx.replyWithPhoto( resources.lunaCat, {