feat/fix/rf: add types, no api key handling in weather cmd, misc fixes
This commit is contained in:
parent
19ce5295b1
commit
8de4f4067e
8 changed files with 84 additions and 47 deletions
|
@ -3,12 +3,14 @@ import { getStrings } from '../plugins/checklang';
|
|||
import { isOnSpamWatch } from '../spamwatch/spamwatch';
|
||||
import spamwatchMiddlewareModule from '../spamwatch/Middleware';
|
||||
import axios from 'axios';
|
||||
import { Telegraf, Context } from 'telegraf';
|
||||
|
||||
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
||||
|
||||
export default (bot) => {
|
||||
bot.command(["rpony", "randompony", "mlpart"], spamwatchMiddleware, async (ctx) => {
|
||||
const Strings = getStrings(ctx.from.language_code);
|
||||
export default (bot: Telegraf<Context>) => {
|
||||
// TODO: this would greatly benefit from a loading message
|
||||
bot.command(["rpony", "randompony", "mlpart"], spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||
const Strings = getStrings(ctx.from?.language_code || 'en');
|
||||
try {
|
||||
const response = await axios(Resources.randomPonyApi);
|
||||
let tags: string[] = [];
|
||||
|
@ -24,12 +26,14 @@ export default (bot) => {
|
|||
ctx.replyWithPhoto(response.data.pony.representations.full, {
|
||||
caption: `${response.data.pony.sourceURL}\n\n${tags.length > 0 ? tags.join(', ') : ''}`,
|
||||
parse_mode: 'Markdown',
|
||||
// @ts-ignore
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
} catch (error) {
|
||||
const message = Strings.ponyApi.apiErr.replace('{error}', error.message);
|
||||
ctx.reply(message, {
|
||||
parse_mode: 'Markdown',
|
||||
// @ts-ignore
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue