mirror of
https://github.com/abocn/TelegramBot.git
synced 2025-04-29 09:25:58 +00:00
fix: add types for context to animal commands
This commit is contained in:
parent
a5d1e0cd9c
commit
9ad6501e66
@ -3,66 +3,74 @@ 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 axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import { Context } from 'telegraf';
|
||||||
|
|
||||||
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
||||||
|
|
||||||
export default (bot) => {
|
export default (bot) => {
|
||||||
bot.command("duck", spamwatchMiddleware, async (ctx) => {
|
bot.command("duck", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from?.language_code);
|
||||||
try {
|
try {
|
||||||
const response = await axios(Resources.duckApi);
|
const response = await axios(Resources.duckApi);
|
||||||
ctx.replyWithPhoto(response.data.url, {
|
ctx.replyWithPhoto(response.data.url, {
|
||||||
caption: "🦆",
|
caption: "🦆",
|
||||||
|
// reply_to_message_id works fine, using this for now to avoid errors
|
||||||
|
// @ts-ignore
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = Strings.duckApiErr.replace('{error}', error.message);
|
const message = Strings.duckApiErr.replace('{error}', error.message);
|
||||||
ctx.reply(message, {
|
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
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command("fox", spamwatchMiddleware, async (ctx) => {
|
bot.command("fox", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from?.language_code);
|
||||||
try {
|
try {
|
||||||
const response = await axios(Resources.foxApi);
|
const response = await axios(Resources.foxApi);
|
||||||
ctx.replyWithPhoto(response.data.image, {
|
ctx.replyWithPhoto(response.data.image, {
|
||||||
caption: "🦊",
|
caption: "🦊",
|
||||||
|
// @ts-ignore
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = Strings.foxApiErr.replace('{error}', error.message);
|
const message = Strings.foxApiErr.replace('{error}', error.message);
|
||||||
ctx.reply(message, {
|
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
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command("dog", spamwatchMiddleware, async (ctx) => {
|
bot.command("dog", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from?.language_code);
|
||||||
try {
|
try {
|
||||||
const response = await axios(Resources.dogApi);
|
const response = await axios(Resources.dogApi);
|
||||||
ctx.replyWithPhoto(response.data.message, {
|
ctx.replyWithPhoto(response.data.message, {
|
||||||
caption: "🐶",
|
caption: "🐶",
|
||||||
|
// @ts-ignore
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = Strings.foxApiErr.replace('{error}', error.message);
|
const message = Strings.foxApiErr.replace('{error}', error.message);
|
||||||
ctx.reply(message, {
|
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
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command("cat", spamwatchMiddleware, async (ctx) => {
|
bot.command("cat", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(ctx.from?.language_code);
|
||||||
const apiUrl = `${Resources.catApi}?json=true`;
|
const apiUrl = `${Resources.catApi}?json=true`;
|
||||||
const response = await axios.get(apiUrl);
|
const response = await axios.get(apiUrl);
|
||||||
const data = response.data;
|
const data = response.data;
|
||||||
@ -72,17 +80,19 @@ export default (bot) => {
|
|||||||
await ctx.replyWithPhoto(imageUrl, {
|
await ctx.replyWithPhoto(imageUrl, {
|
||||||
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 (error) {
|
} catch (error) {
|
||||||
ctx.reply(Strings.catImgErr, {
|
ctx.reply(Strings.catImgErr, {
|
||||||
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(['soggy', 'soggycat'], spamwatchMiddleware, async (ctx) => {
|
bot.command(['soggy', 'soggycat'], spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const userInput = ctx.message.text.split(' ')[1];
|
const userInput = ctx.message.text.split(' ')[1];
|
||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
@ -91,6 +101,7 @@ export default (bot) => {
|
|||||||
Resources.soggyCat2, {
|
Resources.soggyCat2, {
|
||||||
caption: Resources.soggyCat2,
|
caption: Resources.soggyCat2,
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
|
// @ts-ignore
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@ -98,6 +109,7 @@ export default (bot) => {
|
|||||||
case (userInput === "3" || userInput === "sticker"):
|
case (userInput === "3" || userInput === "sticker"):
|
||||||
ctx.replyWithSticker(
|
ctx.replyWithSticker(
|
||||||
Resources.soggyCatSticker, {
|
Resources.soggyCatSticker, {
|
||||||
|
// @ts-ignore
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@ -107,6 +119,7 @@ export default (bot) => {
|
|||||||
Resources.soggyCatAlt, {
|
Resources.soggyCatAlt, {
|
||||||
caption: Resources.soggyCatAlt,
|
caption: Resources.soggyCatAlt,
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
|
// @ts-ignore
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@ -116,6 +129,7 @@ export default (bot) => {
|
|||||||
Resources.soggyCat, {
|
Resources.soggyCat, {
|
||||||
caption: Resources.soggyCat,
|
caption: Resources.soggyCat,
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
|
// @ts-ignore
|
||||||
reply_to_message_id: ctx.message.message_id
|
reply_to_message_id: ctx.message.message_id
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user