diff --git a/src/commands/codename.ts b/src/commands/codename.ts index ed0844e..7f4a3e5 100644 --- a/src/commands/codename.ts +++ b/src/commands/codename.ts @@ -4,10 +4,11 @@ import { isOnSpamWatch } from '../spamwatch/spamwatch'; import spamwatchMiddlewareModule from '../spamwatch/Middleware'; import axios from 'axios'; import verifyInput from '../plugins/verifyInput'; +import { Context, Telegraf } from 'telegraf'; const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch); -async function getDeviceList({ Strings, ctx }) { +async function getDeviceList({ Strings, ctx }: { Strings: any, ctx: Context & { message: { text: string } } }) { try { const response = await axios.get(Resources.codenameApi); return response.data @@ -17,15 +18,16 @@ async function getDeviceList({ Strings, ctx }) { return ctx.reply(message, { parse_mode: "Markdown", + // @ts-ignore reply_to_message_id: ctx.message.message_id }); } } -export default (bot) => { - bot.command(['codename', 'whatis'], spamwatchMiddleware, async (ctx) => { +export default (bot: Telegraf) => { + bot.command(['codename', 'whatis'], spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => { const userInput = ctx.message.text.split(" ").slice(1).join(" "); - const Strings = getStrings(ctx.from.language_code); + const Strings = getStrings(ctx.from?.language_code); const { noCodename } = Strings.codenameCheck if(verifyInput(ctx, userInput, noCodename)){ @@ -38,6 +40,7 @@ export default (bot) => { if (!phoneSearch) { return ctx.reply(Strings.codenameCheck.notFound, { parse_mode: "Markdown", + // @ts-ignore reply_to_message_id: ctx.message.message_id }); } @@ -52,6 +55,7 @@ export default (bot) => { return ctx.reply(message, { parse_mode: 'Markdown', + // @ts-ignore reply_to_message_id: ctx.message.message_id }); }) diff --git a/src/commands/fun.ts b/src/commands/fun.ts index b4dcef8..b1437bf 100644 --- a/src/commands/fun.ts +++ b/src/commands/fun.ts @@ -2,11 +2,12 @@ import Resources from '../props/resources.json'; import { getStrings } from '../plugins/checklang'; import { isOnSpamWatch } from '../spamwatch/spamwatch'; import spamwatchMiddlewareModule from '../spamwatch/Middleware'; +import { Context, Telegraf } from 'telegraf'; const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch); -function sendRandomReply(ctx, gifUrl, textKey) { - const Strings = getStrings(ctx.from.language_code); +function sendRandomReply(ctx: Context & { message: { text: string } }, gifUrl: string, textKey: string) { + const Strings = getStrings(ctx.from?.language_code); const randomNumber = Math.floor(Math.random() * 100); const shouldSendGif = randomNumber > 50; @@ -16,26 +17,30 @@ function sendRandomReply(ctx, gifUrl, textKey) { ctx.replyWithAnimation(gifUrl, { caption, parse_mode: 'Markdown', + // @ts-ignore reply_to_message_id: ctx.message.message_id }).catch(err => { const gifErr = Strings.gifErr.replace('{err}', err); ctx.reply(gifErr, { parse_mode: 'Markdown', + // @ts-ignore reply_to_message_id: ctx.message.message_id }); }); } else { ctx.reply(caption, { parse_mode: 'Markdown', + // @ts-ignore reply_to_message_id: ctx.message.message_id }); } } -async function handleDiceCommand(ctx, emoji, delay) { - const Strings = getStrings(ctx.from.language_code); +async function handleDiceCommand(ctx: Context & { message: { text: string } }, emoji: string, delay: number) { + const Strings = getStrings(ctx.from?.language_code); + // @ts-ignore const result = await ctx.sendDice({ emoji, reply_to_message_id: ctx.message.message_id }); const botResponse = Strings.funEmojiResult .replace('{emoji}', result.dice.emoji) @@ -44,6 +49,7 @@ async function handleDiceCommand(ctx, emoji, delay) { setTimeout(() => { ctx.reply(botResponse, { parse_mode: 'Markdown', + // @ts-ignore reply_to_message_id: ctx.message.message_id }); }, delay); @@ -53,51 +59,54 @@ function getRandomInt(max) { return Math.floor(Math.random() * (max + 1)); } -export default (bot) => { - bot.command('random', spamwatchMiddleware, async (ctx) => { - const Strings = getStrings(ctx.from.language_code); +export default (bot: Telegraf) => { + bot.command('random', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => { + const Strings = getStrings(ctx.from?.language_code); const randomValue = getRandomInt(11); const randomVStr = Strings.randomNum.replace('{number}', randomValue); ctx.reply( randomVStr, { parse_mode: 'Markdown', + // @ts-ignore reply_to_message_id: ctx.message.message_id }); }); - bot.command('dice', spamwatchMiddleware, async (ctx) => { - await handleDiceCommand(ctx, undefined, 4000); + // TODO: maybe send custom stickers to match result of the roll? i think there are pre-existing ones + bot.command('dice', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => { + await handleDiceCommand(ctx, '🎲', 4000); }); - bot.command('slot', spamwatchMiddleware, async (ctx) => { + bot.command('slot', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => { await handleDiceCommand(ctx, '🎰', 3000); }); - bot.command('ball', spamwatchMiddleware, async (ctx) => { + bot.command('ball', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => { await handleDiceCommand(ctx, '⚽', 3000); }); - bot.command('dart', spamwatchMiddleware, async (ctx) => { + bot.command('dart', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => { await handleDiceCommand(ctx, '🎯', 3000); }); - bot.command('bowling', spamwatchMiddleware, async (ctx) => { + bot.command('bowling', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => { await handleDiceCommand(ctx, '🎳', 3000); }); - bot.command('idice', spamwatchMiddleware, async (ctx) => { + bot.command('idice', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => { ctx.replyWithSticker( Resources.infiniteDice, { + // @ts-ignore reply_to_message_id: ctx.message.message_id }); }); - bot.command('furry', spamwatchMiddleware, async (ctx) => { + bot.command('furry', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => { sendRandomReply(ctx, Resources.furryGif, 'furryAmount'); }); - bot.command('gay', spamwatchMiddleware, async (ctx) => { + bot.command('gay', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => { sendRandomReply(ctx, Resources.gayFlag, 'gayAmount'); }); }; \ No newline at end of file