ref: replace "ctx.from.language_code" with a function to get the language code and fix ts implementation for "reply_to_message_id"
This commit is contained in:
parent
f8298dcf53
commit
b085b62f43
17 changed files with 193 additions and 160 deletions
|
@ -4,135 +4,129 @@ 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, Telegraf } from 'telegraf';
|
import { Context, Telegraf } from 'telegraf';
|
||||||
|
import { replyToMessageId } from '../utils/reply-to-message-id';
|
||||||
|
import { languageCode } from '../utils/language-code';
|
||||||
|
|
||||||
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
||||||
|
|
||||||
export default (bot: Telegraf<Context>) => {
|
export default (bot: Telegraf<Context>) => {
|
||||||
bot.command("duck", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
bot.command("duck", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from?.language_code);
|
const reply_to_message_id = replyToMessageId(ctx);
|
||||||
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
|
...({ reply_to_message_id })
|
||||||
// @ts-ignore
|
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
const Strings = getStrings(languageCode(ctx));
|
||||||
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 })
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command("fox", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
bot.command("fox", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from?.language_code);
|
const Strings = getStrings(languageCode(ctx));
|
||||||
|
const reply_to_message_id = replyToMessageId(ctx);
|
||||||
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 })
|
||||||
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 })
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command("dog", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
bot.command("dog", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from?.language_code);
|
const Strings = getStrings(languageCode(ctx));
|
||||||
|
const reply_to_message_id = replyToMessageId(ctx);
|
||||||
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 })
|
||||||
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 })
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command("cat", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
bot.command("cat", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from?.language_code);
|
const Strings = getStrings(languageCode(ctx));
|
||||||
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;
|
||||||
const imageUrl = `${data.url}`;
|
const imageUrl = `${data.url}`;
|
||||||
|
const reply_to_message_id = replyToMessageId(ctx);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await ctx.replyWithPhoto(imageUrl, {
|
await ctx.replyWithPhoto(imageUrl, {
|
||||||
caption: `🐱`,
|
caption: `🐱`,
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
// @ts-ignore
|
...({ reply_to_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 })
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command(['soggy', 'soggycat'], spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
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];
|
||||||
|
const reply_to_message_id = replyToMessageId(ctx);
|
||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case (userInput === "2" || userInput === "thumb"):
|
case (userInput === "2" || userInput === "thumb"):
|
||||||
ctx.replyWithPhoto(
|
ctx.replyWithPhoto(
|
||||||
Resources.soggyCat2, {
|
Resources.soggyCat2, {
|
||||||
caption: Resources.soggyCat2,
|
caption: Resources.soggyCat2,
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
// @ts-ignore
|
...({ reply_to_message_id })
|
||||||
reply_to_message_id: ctx.message.message_id
|
});
|
||||||
});
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case (userInput === "3" || userInput === "sticker"):
|
case (userInput === "3" || userInput === "sticker"):
|
||||||
ctx.replyWithSticker(
|
ctx.replyWithSticker(
|
||||||
Resources.soggyCatSticker, {
|
Resources.soggyCatSticker, {
|
||||||
// @ts-ignore
|
// ...({ reply_to_message_id }) // to-do: fix this
|
||||||
reply_to_message_id: ctx.message.message_id
|
});
|
||||||
});
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case (userInput === "4" || userInput === "alt"):
|
case (userInput === "4" || userInput === "alt"):
|
||||||
ctx.replyWithPhoto(
|
ctx.replyWithPhoto(
|
||||||
Resources.soggyCatAlt, {
|
Resources.soggyCatAlt, {
|
||||||
caption: Resources.soggyCatAlt,
|
caption: Resources.soggyCatAlt,
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
// @ts-ignore
|
...({ reply_to_message_id })
|
||||||
reply_to_message_id: ctx.message.message_id
|
});
|
||||||
});
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ctx.replyWithPhoto(
|
ctx.replyWithPhoto(
|
||||||
Resources.soggyCat, {
|
Resources.soggyCat, {
|
||||||
caption: Resources.soggyCat,
|
caption: Resources.soggyCat,
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
// @ts-ignore
|
...({ reply_to_message_id })
|
||||||
reply_to_message_id: ctx.message.message_id
|
});
|
||||||
});
|
break;
|
||||||
break;
|
};
|
||||||
};
|
});
|
||||||
});
|
|
||||||
}
|
}
|
|
@ -5,10 +5,19 @@ 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';
|
import { Context, Telegraf } from 'telegraf';
|
||||||
|
import { languageCode } from '../utils/language-code';
|
||||||
|
import { replyToMessageId } from '../utils/reply-to-message-id';
|
||||||
|
|
||||||
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
||||||
|
|
||||||
|
interface Device {
|
||||||
|
brand: string;
|
||||||
|
codename: string;
|
||||||
|
model: string;
|
||||||
|
}
|
||||||
|
|
||||||
async function getDeviceList({ Strings, ctx }: { Strings: any, ctx: Context & { message: { text: string } } }) {
|
async function getDeviceList({ Strings, ctx }: { Strings: any, ctx: Context & { message: { text: string } } }) {
|
||||||
|
const reply_to_message_id = replyToMessageId(ctx);
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(Resources.codenameApi);
|
const response = await axios.get(Resources.codenameApi);
|
||||||
return response.data
|
return response.data
|
||||||
|
@ -18,8 +27,7 @@ async function getDeviceList({ Strings, ctx }: { Strings: any, ctx: Context & {
|
||||||
|
|
||||||
return ctx.reply(message, {
|
return ctx.reply(message, {
|
||||||
parse_mode: "Markdown",
|
parse_mode: "Markdown",
|
||||||
// @ts-ignore
|
...({ reply_to_message_id })
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,10 +35,11 @@ async function getDeviceList({ Strings, ctx }: { Strings: any, ctx: Context & {
|
||||||
export default (bot: Telegraf<Context>) => {
|
export default (bot: Telegraf<Context>) => {
|
||||||
bot.command(['codename', 'whatis'], spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
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(languageCode(ctx));
|
||||||
const { noCodename } = Strings.codenameCheck
|
const { noCodename } = Strings.codenameCheck;
|
||||||
|
const reply_to_message_id = replyToMessageId(ctx);
|
||||||
|
|
||||||
if(verifyInput(ctx, userInput, noCodename)){
|
if (verifyInput(ctx, userInput, noCodename)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,13 +49,12 @@ export default (bot: Telegraf<Context>) => {
|
||||||
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 })
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const deviceDetails = jsonRes[phoneSearch];
|
const deviceDetails = jsonRes[phoneSearch];
|
||||||
const device = deviceDetails.find((item) => item.brand) || deviceDetails[0];
|
const device = deviceDetails.find((item: Device) => item.brand) || deviceDetails[0];
|
||||||
const message = Strings.codenameCheck.resultMsg
|
const message = Strings.codenameCheck.resultMsg
|
||||||
.replace('{brand}', device.brand)
|
.replace('{brand}', device.brand)
|
||||||
.replace('{codename}', userInput)
|
.replace('{codename}', userInput)
|
||||||
|
@ -55,8 +63,7 @@ export default (bot: Telegraf<Context>) => {
|
||||||
|
|
||||||
return ctx.reply(message, {
|
return ctx.reply(message, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
// @ts-ignore
|
...({ reply_to_message_id })
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
|
@ -5,6 +5,7 @@ import os from 'os';
|
||||||
import { exec } from 'child_process';
|
import { exec } from 'child_process';
|
||||||
import { error } from 'console';
|
import { error } from 'console';
|
||||||
import { Context, Telegraf } from 'telegraf';
|
import { Context, Telegraf } from 'telegraf';
|
||||||
|
import { languageCode } from '../utils/language-code';
|
||||||
|
|
||||||
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ function getSystemInfo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleAdminCommand(ctx: Context & { message: { text: string } }, action: () => Promise<void>, successMessage: string, errorMessage: string) {
|
async function handleAdminCommand(ctx: Context & { message: { text: string } }, action: () => Promise<void>, successMessage: string, errorMessage: string) {
|
||||||
const Strings = getStrings(ctx.from?.language_code);
|
const Strings = getStrings(languageCode(ctx));
|
||||||
const userId = ctx.from?.id;
|
const userId = ctx.from?.id;
|
||||||
const adminArray = process.env.botAdmins ? process.env.botAdmins.split(',').map(id => parseInt(id.trim())) : [];
|
const adminArray = process.env.botAdmins ? process.env.botAdmins.split(',').map(id => parseInt(id.trim())) : [];
|
||||||
if (userId && adminArray.includes(userId)) {
|
if (userId && adminArray.includes(userId)) {
|
||||||
|
@ -84,7 +85,7 @@ async function handleAdminCommand(ctx: Context & { message: { text: string } },
|
||||||
|
|
||||||
export default (bot: Telegraf<Context>) => {
|
export default (bot: Telegraf<Context>) => {
|
||||||
bot.command('getbotstats', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
bot.command('getbotstats', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from?.language_code);
|
const Strings = getStrings(languageCode(ctx));
|
||||||
handleAdminCommand(ctx, async () => {
|
handleAdminCommand(ctx, async () => {
|
||||||
const stats = getSystemInfo();
|
const stats = getSystemInfo();
|
||||||
await ctx.reply(stats, {
|
await ctx.reply(stats, {
|
||||||
|
@ -96,7 +97,7 @@ export default (bot: Telegraf<Context>) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command('getbotcommit', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
bot.command('getbotcommit', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from?.language_code);
|
const Strings = getStrings(languageCode(ctx));
|
||||||
handleAdminCommand(ctx, async () => {
|
handleAdminCommand(ctx, async () => {
|
||||||
try {
|
try {
|
||||||
const commitHash = await getGitCommitHash();
|
const commitHash = await getGitCommitHash();
|
||||||
|
@ -116,7 +117,7 @@ export default (bot: Telegraf<Context>) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command('updatebot', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
bot.command('updatebot', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from?.language_code);
|
const Strings = getStrings(languageCode(ctx));
|
||||||
handleAdminCommand(ctx, async () => {
|
handleAdminCommand(ctx, async () => {
|
||||||
try {
|
try {
|
||||||
const result = await updateBot();
|
const result = await updateBot();
|
||||||
|
@ -136,7 +137,7 @@ export default (bot: Telegraf<Context>) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command('setbotname', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
bot.command('setbotname', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from?.language_code);
|
const Strings = getStrings(languageCode(ctx));
|
||||||
const botName = ctx.message.text.split(' ').slice(1).join(' ');
|
const botName = ctx.message.text.split(' ').slice(1).join(' ');
|
||||||
handleAdminCommand(ctx, async () => {
|
handleAdminCommand(ctx, async () => {
|
||||||
await ctx.telegram.setMyName(botName);
|
await ctx.telegram.setMyName(botName);
|
||||||
|
@ -144,7 +145,7 @@ export default (bot: Telegraf<Context>) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command('setbotdesc', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
bot.command('setbotdesc', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from?.language_code);
|
const Strings = getStrings(languageCode(ctx));
|
||||||
const botDesc = ctx.message.text.split(' ').slice(1).join(' ');
|
const botDesc = ctx.message.text.split(' ').slice(1).join(' ');
|
||||||
handleAdminCommand(ctx, async () => {
|
handleAdminCommand(ctx, async () => {
|
||||||
await ctx.telegram.setMyDescription(botDesc);
|
await ctx.telegram.setMyDescription(botDesc);
|
||||||
|
@ -152,7 +153,7 @@ export default (bot: Telegraf<Context>) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command('botkickme', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
bot.command('botkickme', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from?.language_code);
|
const Strings = getStrings(languageCode(ctx));
|
||||||
handleAdminCommand(ctx, async () => {
|
handleAdminCommand(ctx, async () => {
|
||||||
if (!ctx.chat) {
|
if (!ctx.chat) {
|
||||||
ctx.reply(Strings.chatNotFound, {
|
ctx.reply(Strings.chatNotFound, {
|
||||||
|
@ -172,7 +173,7 @@ export default (bot: Telegraf<Context>) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command('getfile', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
bot.command('getfile', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from?.language_code);
|
const Strings = getStrings(languageCode(ctx));
|
||||||
const botFile = ctx.message.text.split(' ').slice(1).join(' ');
|
const botFile = ctx.message.text.split(' ').slice(1).join(' ');
|
||||||
|
|
||||||
if (!botFile) {
|
if (!botFile) {
|
||||||
|
|
|
@ -3,11 +3,12 @@ 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';
|
import { Context, Telegraf } from 'telegraf';
|
||||||
|
import { languageCode } from '../utils/language-code';
|
||||||
|
|
||||||
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
||||||
|
|
||||||
function sendRandomReply(ctx: Context & { message: { text: string } }, gifUrl: string, textKey: string) {
|
function sendRandomReply(ctx: Context & { message: { text: string } }, gifUrl: string, textKey: string) {
|
||||||
const Strings = getStrings(ctx.from?.language_code);
|
const Strings = getStrings(languageCode(ctx));
|
||||||
const randomNumber = Math.floor(Math.random() * 100);
|
const randomNumber = Math.floor(Math.random() * 100);
|
||||||
const shouldSendGif = randomNumber > 50;
|
const shouldSendGif = randomNumber > 50;
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ function sendRandomReply(ctx: Context & { message: { text: string } }, gifUrl: s
|
||||||
|
|
||||||
|
|
||||||
async function handleDiceCommand(ctx: Context & { message: { text: string } }, emoji: string, delay: number) {
|
async function handleDiceCommand(ctx: Context & { message: { text: string } }, emoji: string, delay: number) {
|
||||||
const Strings = getStrings(ctx.from?.language_code);
|
const Strings = getStrings(languageCode(ctx));
|
||||||
|
|
||||||
// @ts-ignore
|
// @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 });
|
||||||
|
@ -55,13 +56,13 @@ async function handleDiceCommand(ctx: Context & { message: { text: string } }, e
|
||||||
}, delay);
|
}, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRandomInt(max) {
|
function getRandomInt(max: number) {
|
||||||
return Math.floor(Math.random() * (max + 1));
|
return Math.floor(Math.random() * (max + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (bot: Telegraf<Context>) => {
|
export default (bot: Telegraf<Context>) => {
|
||||||
bot.command('random', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
bot.command('random', spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from?.language_code);
|
const Strings = getStrings(languageCode(ctx));
|
||||||
const randomValue = getRandomInt(11);
|
const randomValue = getRandomInt(11);
|
||||||
const randomVStr = Strings.randomNum.replace('{number}', randomValue);
|
const randomVStr = Strings.randomNum.replace('{number}', randomValue);
|
||||||
|
|
||||||
|
|
|
@ -127,7 +127,7 @@ function formatPhone(phone: PhoneDetails) {
|
||||||
return `<b>\n\nName: </b><code>${formattedPhone.name}</code>\n\n${attributes}\n\n${deviceImage}\n\n${deviceUrl}`;
|
return `<b>\n\nName: </b><code>${formattedPhone.name}</code>\n\n${attributes}\n\n${deviceImage}\n\n${deviceUrl}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchHtml(url) {
|
async function fetchHtml(url: string) {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(url, { headers: HEADERS });
|
const response = await axios.get(url, { headers: HEADERS });
|
||||||
return response.data;
|
return response.data;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
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 { languageCode } from '../utils/language-code';
|
||||||
|
|
||||||
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ interface MessageOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendHelpMessage(ctx, isEditing) {
|
async function sendHelpMessage(ctx, isEditing) {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(languageCode(ctx));
|
||||||
const botInfo = await ctx.telegram.getMe();
|
const botInfo = await ctx.telegram.getMe();
|
||||||
const helpText = Strings.botHelp
|
const helpText = Strings.botHelp
|
||||||
.replace(/{botName}/g, botInfo.first_name)
|
.replace(/{botName}/g, botInfo.first_name)
|
||||||
|
@ -56,7 +57,7 @@ export default (bot) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command("about", spamwatchMiddleware, async (ctx) => {
|
bot.command("about", spamwatchMiddleware, async (ctx) => {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(languageCode(ctx));
|
||||||
const aboutMsg = Strings.botAbout.replace(/{sourceLink}/g, `${process.env.botSource}`);
|
const aboutMsg = Strings.botAbout.replace(/{sourceLink}/g, `${process.env.botSource}`);
|
||||||
ctx.reply(aboutMsg, {
|
ctx.reply(aboutMsg, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
|
@ -67,7 +68,7 @@ export default (bot) => {
|
||||||
|
|
||||||
bot.on('callback_query', async (ctx) => {
|
bot.on('callback_query', async (ctx) => {
|
||||||
const callbackData = ctx.callbackQuery.data;
|
const callbackData = ctx.callbackQuery.data;
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(languageCode(ctx));
|
||||||
const options = {
|
const options = {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
disable_web_page_preview: true,
|
disable_web_page_preview: true,
|
||||||
|
|
|
@ -5,12 +5,14 @@ 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';
|
import { Context, Telegraf } from 'telegraf';
|
||||||
|
import { languageCode } from '../utils/language-code';
|
||||||
|
|
||||||
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
||||||
|
|
||||||
export default (bot: Telegraf<Context>) => {
|
export default (bot: Telegraf<Context>) => {
|
||||||
bot.command("http", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
bot.command("http", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from?.language_code || 'en');
|
const reply_to_message_id = ctx.message.message_id;
|
||||||
|
const Strings = getStrings(languageCode(ctx));
|
||||||
const userInput = ctx.message.text.split(' ')[1];
|
const userInput = ctx.message.text.split(' ')[1];
|
||||||
const apiUrl = Resources.httpApi;
|
const apiUrl = Resources.httpApi;
|
||||||
const { invalidCode } = Strings.httpCodes
|
const { invalidCode } = Strings.httpCodes
|
||||||
|
@ -32,28 +34,26 @@ export default (bot: Telegraf<Context>) => {
|
||||||
.replace("{description}", codeInfo.description);
|
.replace("{description}", codeInfo.description);
|
||||||
await ctx.reply(message, {
|
await ctx.reply(message, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
// @ts-ignore
|
...({ reply_to_message_id })
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await ctx.reply(Strings.httpCodes.notFound, {
|
await ctx.reply(Strings.httpCodes.notFound, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
// @ts-ignore
|
...({ reply_to_message_id })
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = Strings.httpCodes.fetchErr.replace("{error}", error);
|
const message = Strings.httpCodes.fetchErr.replace("{error}", error);
|
||||||
ctx.reply(message, {
|
ctx.reply(message, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
// @ts-ignore
|
...({ reply_to_message_id })
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command("httpcat", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
bot.command("httpcat", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from?.language_code || 'en');
|
const Strings = getStrings(languageCode(ctx));
|
||||||
|
const reply_to_message_id = ctx.message.message_id;
|
||||||
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(/\s+/g, '');
|
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(/\s+/g, '');
|
||||||
const { invalidCode } = Strings.httpCodes
|
const { invalidCode } = Strings.httpCodes
|
||||||
|
|
||||||
|
@ -67,14 +67,12 @@ export default (bot: Telegraf<Context>) => {
|
||||||
await ctx.replyWithPhoto(apiUrl, {
|
await ctx.replyWithPhoto(apiUrl, {
|
||||||
caption: `🐱 ${apiUrl}`,
|
caption: `🐱 ${apiUrl}`,
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
// @ts-ignore
|
...({ reply_to_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 })
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,18 +1,22 @@
|
||||||
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';
|
||||||
|
import { replyToMessageId } from '../utils/reply-to-message-id';
|
||||||
|
import { languageCode } from '../utils/language-code';
|
||||||
|
|
||||||
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
||||||
|
|
||||||
export default (bot: any) => {
|
export default (bot: Telegraf<Context>) => {
|
||||||
bot.start(spamwatchMiddleware, async (ctx: any) => {
|
bot.start(spamwatchMiddleware, async (ctx: Context) => {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(languageCode(ctx));
|
||||||
const botInfo = await ctx.telegram.getMe();
|
const botInfo = await ctx.telegram.getMe();
|
||||||
|
const reply_to_message_id = replyToMessageId(ctx)
|
||||||
const startMsg = Strings.botWelcome.replace(/{botName}/g, botInfo.first_name);
|
const startMsg = Strings.botWelcome.replace(/{botName}/g, botInfo.first_name);
|
||||||
|
|
||||||
ctx.reply(startMsg, {
|
ctx.reply(startMsg, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
reply_to_message_id: ctx.message.message_id
|
...({ reply_to_message_id })
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,9 @@ import path from 'path';
|
||||||
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 { languageCode } from '../utils/language-code';
|
||||||
|
import { Context, Telegraf } from 'telegraf';
|
||||||
|
import { replyToMessageId } from '../utils/reply-to-message-id';
|
||||||
|
|
||||||
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
||||||
|
|
||||||
|
@ -46,15 +49,16 @@ async function downloadModule(moduleId: string): Promise<ModuleResult | null> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (bot) => {
|
export default (bot: Telegraf<Context>) => {
|
||||||
bot.command(['modarchive', 'tma'], spamwatchMiddleware, async (ctx) => {
|
bot.command(['modarchive', 'tma'], spamwatchMiddleware, async (ctx) => {
|
||||||
const Strings = getStrings(ctx.from.language_code);
|
const Strings = getStrings(languageCode(ctx));
|
||||||
const moduleId = ctx.message.text.split(' ')[1];
|
const reply_to_message_id = replyToMessageId(ctx);
|
||||||
|
const moduleId = ctx.message?.text.split(' ')[1];
|
||||||
|
|
||||||
if (Number.isNaN(moduleId) || null) {
|
if (Number.isNaN(moduleId) || null) {
|
||||||
return ctx.reply(Strings.maInvalidModule, {
|
return ctx.reply(Strings.maInvalidModule, {
|
||||||
parse_mode: "Markdown",
|
parse_mode: "Markdown",
|
||||||
reply_to_message_id: ctx.message.message_id
|
...({ reply_to_message_id })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,14 +69,14 @@ export default (bot) => {
|
||||||
|
|
||||||
await ctx.replyWithDocument({ source: filePath }, {
|
await ctx.replyWithDocument({ source: filePath }, {
|
||||||
caption: fileName,
|
caption: fileName,
|
||||||
reply_to_message_id: ctx.message.message_id
|
...({ reply_to_message_id })
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.unlinkSync(filePath);
|
fs.unlinkSync(filePath);
|
||||||
} else {
|
} else {
|
||||||
ctx.reply(Strings.maDownloadError, {
|
ctx.reply(Strings.maDownloadError, {
|
||||||
parse_mode: "Markdown",
|
parse_mode: "Markdown",
|
||||||
reply_to_message_id: ctx.message.message_id
|
...({ reply_to_message_id })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,6 +5,8 @@ import spamwatchMiddlewareModule from '../spamwatch/Middleware';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import verifyInput from '../plugins/verifyInput';
|
import verifyInput from '../plugins/verifyInput';
|
||||||
import { Telegraf, Context } from 'telegraf';
|
import { Telegraf, Context } from 'telegraf';
|
||||||
|
import { languageCode } from '../utils/language-code';
|
||||||
|
import { replyToMessageId } from '../utils/reply-to-message-id';
|
||||||
|
|
||||||
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
||||||
|
|
||||||
|
@ -47,24 +49,24 @@ interface Comic {
|
||||||
editor: string;
|
editor: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function capitalizeFirstLetter(string) {
|
function capitalizeFirstLetter(letter: string) {
|
||||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
return letter.charAt(0).toUpperCase() + letter.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (bot: Telegraf<Context>) => {
|
export default (bot: Telegraf<Context>) => {
|
||||||
bot.command("mlp", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
bot.command("mlp", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from?.language_code || 'en');
|
const Strings = getStrings(languageCode(ctx));
|
||||||
|
const reply_to_message_id = replyToMessageId(ctx);
|
||||||
|
|
||||||
ctx.reply(Strings.ponyApi.helpDesc, {
|
ctx.reply(Strings.ponyApi.helpDesc, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
// @ts-ignore
|
...({ reply_to_message_id, disable_web_page_preview: true })
|
||||||
disable_web_page_preview: true,
|
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command("mlpchar", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
bot.command("mlpchar", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from?.language_code || 'en');
|
const reply_to_message_id = replyToMessageId(ctx);
|
||||||
|
const Strings = getStrings(languageCode(ctx) || 'en');
|
||||||
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(" ", "+");
|
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(" ", "+");
|
||||||
const { noCharName } = Strings.ponyApi
|
const { noCharName } = Strings.ponyApi
|
||||||
|
|
||||||
|
@ -118,30 +120,27 @@ export default (bot: Telegraf<Context>) => {
|
||||||
ctx.replyWithPhoto(charactersArray[0].image[0], {
|
ctx.replyWithPhoto(charactersArray[0].image[0], {
|
||||||
caption: `${result}`,
|
caption: `${result}`,
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
// @ts-ignore
|
...({ reply_to_message_id, disable_web_page_preview: true })
|
||||||
disable_web_page_preview: true,
|
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
ctx.reply(Strings.ponyApi.noCharFound, {
|
ctx.reply(Strings.ponyApi.noCharFound, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
// @ts-ignore
|
...({ reply_to_message_id })
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = Strings.ponyApi.apiErr.replace('{error}', error.message);
|
const message = Strings.ponyApi.apiErr.replace('{error}', error.message);
|
||||||
ctx.reply(message, {
|
ctx.reply(message, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
// @ts-ignore
|
...({ reply_to_message_id })
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command("mlpep", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
bot.command("mlpep", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from?.language_code || 'en');
|
const Strings = getStrings(languageCode(ctx) || 'en');
|
||||||
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(" ", "+");
|
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(" ", "+");
|
||||||
|
const reply_to_message_id = replyToMessageId(ctx);
|
||||||
|
|
||||||
const { noEpisodeNum } = Strings.ponyApi
|
const { noEpisodeNum } = Strings.ponyApi
|
||||||
|
|
||||||
|
@ -156,7 +155,7 @@ export default (bot: Telegraf<Context>) => {
|
||||||
const episodeArray: Episode[] = [];
|
const episodeArray: Episode[] = [];
|
||||||
|
|
||||||
if (Array.isArray(response.data.data)) {
|
if (Array.isArray(response.data.data)) {
|
||||||
response.data.data.forEach(episode => {
|
response.data.data.forEach((episode: Episode) => {
|
||||||
episodeArray.push({
|
episodeArray.push({
|
||||||
id: episode.id,
|
id: episode.id,
|
||||||
name: episode.name,
|
name: episode.name,
|
||||||
|
@ -189,30 +188,29 @@ export default (bot: Telegraf<Context>) => {
|
||||||
ctx.replyWithPhoto(episodeArray[0].image, {
|
ctx.replyWithPhoto(episodeArray[0].image, {
|
||||||
caption: `${result}`,
|
caption: `${result}`,
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
// @ts-ignore
|
...({ reply_to_message_id, disable_web_page_preview: true })
|
||||||
disable_web_page_preview: true,
|
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
ctx.reply(Strings.ponyApi.noEpisodeFound, {
|
ctx.reply(Strings.ponyApi.noEpisodeFound, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
// @ts-ignore
|
|
||||||
reply_to_message_id: ctx.message.message_id
|
...({ reply_to_message_id })
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = Strings.ponyApi.apiErr.replace('{error}', error.message);
|
const message = Strings.ponyApi.apiErr.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 })
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.command("mlpcomic", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
bot.command("mlpcomic", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from?.language_code || 'en');
|
const Strings = getStrings(languageCode(ctx) || 'en');
|
||||||
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(" ", "+");
|
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(" ", "+");
|
||||||
|
const reply_to_message_id = replyToMessageId(ctx);
|
||||||
|
|
||||||
const { noComicName } = Strings.ponyApi
|
const { noComicName } = Strings.ponyApi
|
||||||
|
|
||||||
|
@ -265,23 +263,21 @@ export default (bot: Telegraf<Context>) => {
|
||||||
ctx.replyWithPhoto(comicArray[0].image, {
|
ctx.replyWithPhoto(comicArray[0].image, {
|
||||||
caption: `${result}`,
|
caption: `${result}`,
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
// @ts-ignore
|
...({ reply_to_message_id, disable_web_page_preview: true })
|
||||||
disable_web_page_preview: true,
|
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
ctx.reply(Strings.ponyApi.noComicFound, {
|
ctx.reply(Strings.ponyApi.noComicFound, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
// @ts-ignore
|
|
||||||
reply_to_message_id: ctx.message.message_id
|
...({ reply_to_message_id })
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = Strings.ponyApi.apiErr.replace('{error}', error.message);
|
const message = Strings.ponyApi.apiErr.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 })
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,13 +4,16 @@ import { isOnSpamWatch } from '../spamwatch/spamwatch';
|
||||||
import spamwatchMiddlewareModule from '../spamwatch/Middleware';
|
import spamwatchMiddlewareModule from '../spamwatch/Middleware';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { Telegraf, Context } from 'telegraf';
|
import { Telegraf, Context } from 'telegraf';
|
||||||
|
import { languageCode } from '../utils/language-code';
|
||||||
|
import { replyToMessageId } from '../utils/reply-to-message-id';
|
||||||
|
|
||||||
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
||||||
|
|
||||||
export default (bot: Telegraf<Context>) => {
|
export default (bot: Telegraf<Context>) => {
|
||||||
// TODO: this would greatly benefit from a loading message
|
// TODO: this would greatly benefit from a loading message
|
||||||
bot.command(["rpony", "randompony", "mlpart"], spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
bot.command(["rpony", "randompony", "mlpart"], spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||||
const Strings = getStrings(ctx.from?.language_code || 'en');
|
const Strings = getStrings(languageCode(ctx));
|
||||||
|
const reply_to_message_id = replyToMessageId(ctx);
|
||||||
try {
|
try {
|
||||||
const response = await axios(Resources.randomPonyApi);
|
const response = await axios(Resources.randomPonyApi);
|
||||||
let tags: string[] = [];
|
let tags: string[] = [];
|
||||||
|
@ -26,15 +29,13 @@ export default (bot: Telegraf<Context>) => {
|
||||||
ctx.replyWithPhoto(response.data.pony.representations.full, {
|
ctx.replyWithPhoto(response.data.pony.representations.full, {
|
||||||
caption: `${response.data.pony.sourceURL}\n\n${tags.length > 0 ? tags.join(', ') : ''}`,
|
caption: `${response.data.pony.sourceURL}\n\n${tags.length > 0 ? tags.join(', ') : ''}`,
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
// @ts-ignore
|
...({ reply_to_message_id })
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = Strings.ponyApi.apiErr.replace('{error}', error.message);
|
const message = Strings.ponyApi.apiErr.replace('{error}', error.message);
|
||||||
ctx.reply(message, {
|
ctx.reply(message, {
|
||||||
parse_mode: 'Markdown',
|
parse_mode: 'Markdown',
|
||||||
// @ts-ignore
|
...({ reply_to_message_id })
|
||||||
reply_to_message_id: ctx.message.message_id
|
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ 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 verifyInput from '../plugins/verifyInput';
|
import verifyInput from '../plugins/verifyInput';
|
||||||
|
import { Context, Telegraf } from 'telegraf';
|
||||||
|
|
||||||
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
||||||
|
|
||||||
|
@ -33,8 +34,9 @@ function getLocaleUnit(countryCode: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (bot) => {
|
export default (bot: Telegraf<Context>) => {
|
||||||
bot.command(['clima', 'weather'], spamwatchMiddleware, async (ctx) => {
|
bot.command(['clima', 'weather'], spamwatchMiddleware, async (ctx) => {
|
||||||
|
const reply_to_message_id = ctx.message.message_id;
|
||||||
const userLang = ctx.from.language_code || "en-US";
|
const userLang = ctx.from.language_code || "en-US";
|
||||||
const Strings = getStrings(userLang);
|
const Strings = getStrings(userLang);
|
||||||
const userInput = ctx.message.text.split(' ').slice(1).join(' ');
|
const userInput = ctx.message.text.split(' ').slice(1).join(' ');
|
||||||
|
@ -50,7 +52,7 @@ export default (bot) => {
|
||||||
if (!apiKey || apiKey === "InsertYourWeatherDotComApiKeyHere") {
|
if (!apiKey || apiKey === "InsertYourWeatherDotComApiKeyHere") {
|
||||||
return ctx.reply(Strings.weatherStatus.apiKeyErr, {
|
return ctx.reply(Strings.weatherStatus.apiKeyErr, {
|
||||||
parse_mode: "Markdown",
|
parse_mode: "Markdown",
|
||||||
reply_to_message_id: ctx.message.message_id
|
...({ reply_to_message_id })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +71,7 @@ export default (bot) => {
|
||||||
if (!locationData || !locationData.address) {
|
if (!locationData || !locationData.address) {
|
||||||
return ctx.reply(Strings.weatherStatus.invalidLocation, {
|
return ctx.reply(Strings.weatherStatus.invalidLocation, {
|
||||||
parse_mode: "Markdown",
|
parse_mode: "Markdown",
|
||||||
reply_to_message_id: ctx.message.message_id
|
...({ reply_to_message_id })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,13 +108,13 @@ export default (bot) => {
|
||||||
|
|
||||||
ctx.reply(weatherMessage, {
|
ctx.reply(weatherMessage, {
|
||||||
parse_mode: "Markdown",
|
parse_mode: "Markdown",
|
||||||
reply_to_message_id: ctx.message.message_id
|
...({ reply_to_message_id })
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = Strings.weatherStatus.apiErr.replace('{error}', error.message);
|
const message = Strings.weatherStatus.apiErr.replace('{error}', error.message);
|
||||||
ctx.reply(message, {
|
ctx.reply(message, {
|
||||||
parse_mode: "Markdown",
|
parse_mode: "Markdown",
|
||||||
reply_to_message_id: ctx.message.message_id
|
...({ reply_to_message_id })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
/*
|
/*
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { Context, Telegraf } from "telegraf";
|
||||||
|
import { replyToMessageId } from "../utils/reply-to-message-id";
|
||||||
|
|
||||||
function capitalizeFirstLetter(string: string) {
|
function capitalizeFirstLetter(string: string) {
|
||||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||||
|
@ -23,7 +25,7 @@ function mediaWikiToMarkdown(input: string) {
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (bot) => {
|
export default (bot: Telegraf<Context>) => {
|
||||||
bot.command("wiki", async (ctx) => {
|
bot.command("wiki", async (ctx) => {
|
||||||
const userInput = capitalizeFirstLetter(ctx.message.text.split(' ')[1]);
|
const userInput = capitalizeFirstLetter(ctx.message.text.split(' ')[1]);
|
||||||
const apiUrl = `https://en.wikipedia.org/w/index.php?title=${userInput}&action=raw`;
|
const apiUrl = `https://en.wikipedia.org/w/index.php?title=${userInput}&action=raw`;
|
||||||
|
@ -31,8 +33,9 @@ export default (bot) => {
|
||||||
const convertedResponse = response.data.replace(/<\/?div>/g, "").replace(/{{Infobox.*?}}/s, "");
|
const convertedResponse = response.data.replace(/<\/?div>/g, "").replace(/{{Infobox.*?}}/s, "");
|
||||||
|
|
||||||
const result = mediaWikiToMarkdown(convertedResponse).slice(0, 2048);
|
const result = mediaWikiToMarkdown(convertedResponse).slice(0, 2048);
|
||||||
|
const reply_to_message_id = replyToMessageId(ctx);
|
||||||
|
|
||||||
ctx.reply(result, { parse_mode: 'Markdown', disable_web_page_preview: true, reply_to_message_id: ctx.message.message_id });
|
ctx.reply(result, { parse_mode: 'Markdown', ...({ reply_to_message_id, disable_web_page_preview: true }) });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
*/
|
*/
|
|
@ -7,7 +7,10 @@ const languageFiles = {
|
||||||
'en-gb': '../locales/english.json'
|
'en-gb': '../locales/english.json'
|
||||||
};
|
};
|
||||||
|
|
||||||
function getStrings(languageCode: string) {
|
function getStrings(languageCode?: string) {
|
||||||
|
if (!languageCode) {
|
||||||
|
return require(languageFiles['en']);
|
||||||
|
}
|
||||||
const filePath: string = languageFiles[languageCode] || languageFiles['en'];
|
const filePath: string = languageFiles[languageCode] || languageFiles['en'];
|
||||||
try {
|
try {
|
||||||
return require(filePath);
|
return require(filePath);
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
export default function verifyInput(ctx: any, userInput: string, message: string, verifyNaN = false) {
|
import { Context } from "telegraf";
|
||||||
if (!userInput || (verifyNaN && isNaN(Number(userInput)))) { // not sure why isNaN is used here, but the input should be a number
|
import { replyToMessageId } from "../utils/reply-to-message-id";
|
||||||
|
|
||||||
|
export default function verifyInput(ctx: Context, userInput: string, message: string, verifyNaN = false) {
|
||||||
|
const reply_to_message_id = replyToMessageId(ctx);
|
||||||
|
if (!userInput || (verifyNaN && isNaN(Number(userInput)))) {
|
||||||
ctx.reply(message, {
|
ctx.reply(message, {
|
||||||
parse_mode: "Markdown",
|
parse_mode: "Markdown",
|
||||||
reply_to_message_id: ctx.message.message_id
|
...({ reply_to_message_id })
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
9
src/utils/language-code.ts
Normal file
9
src/utils/language-code.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import { Context } from "telegraf";
|
||||||
|
|
||||||
|
export const languageCode = (ctx: Context) => {
|
||||||
|
if(ctx.from) {
|
||||||
|
return ctx.from.language_code
|
||||||
|
} else {
|
||||||
|
return 'en'
|
||||||
|
}
|
||||||
|
}
|
5
src/utils/reply-to-message-id.ts
Normal file
5
src/utils/reply-to-message-id.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { Context } from "telegraf"
|
||||||
|
|
||||||
|
export const replyToMessageId = (ctx: Context) => {
|
||||||
|
return ctx.message?.message_id
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue