mirror of
https://github.com/abocn/TelegramBot.git
synced 2025-04-28 17:15:57 +00:00
fix/types: add bot, ctx types, fix emoji on /dice cmd, add todo
This commit is contained in:
parent
64b5e28bf3
commit
a192681d18
@ -4,10 +4,11 @@ import { isOnSpamWatch } from '../spamwatch/spamwatch';
|
|||||||
import spamwatchMiddlewareModule from '../spamwatch/Middleware';
|
import spamwatchMiddlewareModule from '../spamwatch/Middleware';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import verifyInput from '../plugins/verifyInput';
|
import verifyInput from '../plugins/verifyInput';
|
||||||
|
import { Context, Telegraf } from 'telegraf';
|
||||||
|
|
||||||
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
||||||
|
|
||||||
async function getDeviceList({ Strings, ctx }) {
|
async function getDeviceList({ Strings, ctx }: { Strings: any, ctx: Context & { message: { text: string } } }) {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(Resources.codenameApi);
|
const response = await axios.get(Resources.codenameApi);
|
||||||
return response.data
|
return response.data
|
||||||
@ -17,15 +18,16 @@ async function getDeviceList({ Strings, ctx }) {
|
|||||||
|
|
||||||
return ctx.reply(message, {
|
return ctx.reply(message, {
|
||||||
parse_mode: "Markdown",
|
parse_mode: "Markdown",
|
||||||
|
// @ts-ignore
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (bot) => {
|
export default (bot: Telegraf<Context>) => {
|
||||||
bot.command(['codename', 'whatis'], spamwatchMiddleware, async (ctx) => {
|
bot.command(['codename', 'whatis'], spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const userInput = ctx.message.text.split(" ").slice(1).join(" ");
|
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
|
const { noCodename } = Strings.codenameCheck
|
||||||
|
|
||||||
if(verifyInput(ctx, userInput, noCodename)){
|
if(verifyInput(ctx, userInput, noCodename)){
|
||||||
@ -38,6 +40,7 @@ export default (bot) => {
|
|||||||
if (!phoneSearch) {
|
if (!phoneSearch) {
|
||||||
return ctx.reply(Strings.codenameCheck.notFound, {
|
return ctx.reply(Strings.codenameCheck.notFound, {
|
||||||
parse_mode: "Markdown",
|
parse_mode: "Markdown",
|
||||||
|
// @ts-ignore
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -52,6 +55,7 @@ export default (bot) => {
|
|||||||
|
|
||||||
return ctx.reply(message, {
|
return ctx.reply(message, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
|
// @ts-ignore
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -2,11 +2,12 @@ import Resources from '../props/resources.json';
|
|||||||
import { getStrings } from '../plugins/checklang';
|
import { getStrings } from '../plugins/checklang';
|
||||||
import { isOnSpamWatch } from '../spamwatch/spamwatch';
|
import { isOnSpamWatch } from '../spamwatch/spamwatch';
|
||||||
import spamwatchMiddlewareModule from '../spamwatch/Middleware';
|
import spamwatchMiddlewareModule from '../spamwatch/Middleware';
|
||||||
|
import { Context, Telegraf } from 'telegraf';
|
||||||
|
|
||||||
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
||||||
|
|
||||||
function sendRandomReply(ctx, gifUrl, textKey) {
|
function sendRandomReply(ctx: Context & { message: { text: string } }, gifUrl: string, textKey: string) {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from?.language_code);
|
||||||
const randomNumber = Math.floor(Math.random() * 100);
|
const randomNumber = Math.floor(Math.random() * 100);
|
||||||
const shouldSendGif = randomNumber > 50;
|
const shouldSendGif = randomNumber > 50;
|
||||||
|
|
||||||
@ -16,26 +17,30 @@ function sendRandomReply(ctx, gifUrl, textKey) {
|
|||||||
ctx.replyWithAnimation(gifUrl, {
|
ctx.replyWithAnimation(gifUrl, {
|
||||||
caption,
|
caption,
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
|
// @ts-ignore
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
const gifErr = Strings.gifErr.replace('{err}', err);
|
const gifErr = Strings.gifErr.replace('{err}', err);
|
||||||
ctx.reply(gifErr, {
|
ctx.reply(gifErr, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
|
// @ts-ignore
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
ctx.reply(caption, {
|
ctx.reply(caption, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
|
// @ts-ignore
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function handleDiceCommand(ctx, emoji, delay) {
|
async function handleDiceCommand(ctx: Context & { message: { text: string } }, emoji: string, delay: number) {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from?.language_code);
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
const result = await ctx.sendDice({ emoji, reply_to_message_id: ctx.message.message_id });
|
const result = await ctx.sendDice({ emoji, reply_to_message_id: ctx.message.message_id });
|
||||||
const botResponse = Strings.funEmojiResult
|
const botResponse = Strings.funEmojiResult
|
||||||
.replace('{emoji}', result.dice.emoji)
|
.replace('{emoji}', result.dice.emoji)
|
||||||
@ -44,6 +49,7 @@ async function handleDiceCommand(ctx, emoji, delay) {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
ctx.reply(botResponse, {
|
ctx.reply(botResponse, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
|
// @ts-ignore
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
});
|
});
|
||||||
}, delay);
|
}, delay);
|
||||||
@ -53,51 +59,54 @@ function getRandomInt(max) {
|
|||||||
return Math.floor(Math.random() * (max + 1));
|
return Math.floor(Math.random() * (max + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (bot) => {
|
export default (bot: Telegraf<Context>) => {
|
||||||
bot.command('random', spamwatchMiddleware, async (ctx) => {
|
bot.command('random', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from?.language_code);
|
||||||
const randomValue = getRandomInt(11);
|
const randomValue = getRandomInt(11);
|
||||||
const randomVStr = Strings.randomNum.replace('{number}', randomValue);
|
const randomVStr = Strings.randomNum.replace('{number}', randomValue);
|
||||||
|
|
||||||
ctx.reply(
|
ctx.reply(
|
||||||
randomVStr, {
|
randomVStr, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
|
// @ts-ignore
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command('dice', spamwatchMiddleware, async (ctx) => {
|
// TODO: maybe send custom stickers to match result of the roll? i think there are pre-existing ones
|
||||||
await handleDiceCommand(ctx, undefined, 4000);
|
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);
|
await handleDiceCommand(ctx, '🎰', 3000);
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command('ball', spamwatchMiddleware, async (ctx) => {
|
bot.command('ball', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
await handleDiceCommand(ctx, '⚽', 3000);
|
await handleDiceCommand(ctx, '⚽', 3000);
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command('dart', spamwatchMiddleware, async (ctx) => {
|
bot.command('dart', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
await handleDiceCommand(ctx, '🎯', 3000);
|
await handleDiceCommand(ctx, '🎯', 3000);
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command('bowling', spamwatchMiddleware, async (ctx) => {
|
bot.command('bowling', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
await handleDiceCommand(ctx, '🎳', 3000);
|
await handleDiceCommand(ctx, '🎳', 3000);
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command('idice', spamwatchMiddleware, async (ctx) => {
|
bot.command('idice', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
ctx.replyWithSticker(
|
ctx.replyWithSticker(
|
||||||
Resources.infiniteDice, {
|
Resources.infiniteDice, {
|
||||||
|
// @ts-ignore
|
||||||
reply_to_message_id: ctx.message.message_id
|
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');
|
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');
|
sendRandomReply(ctx, Resources.gayFlag, 'gayAmount');
|
||||||
});
|
});
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user