* docs: linting, require bun for ts * rf: js -> ts * chore: bump * docs: add ts badge * chore: bump types * fix: add types for context to animal commands * [m] hf: add bot type * fix/types: add bot, ctx types, fix emoji on /dice cmd, add todo * fix/types: bot admin checking fixes, other misc fixes, add types --------- Co-authored-by: Lucas Gabriel <lucmsilva651@gmail.com>
38 lines
No EOL
1.3 KiB
TypeScript
38 lines
No EOL
1.3 KiB
TypeScript
import Resources from '../props/resources.json';
|
|
import { getStrings } from '../plugins/checklang';
|
|
import { isOnSpamWatch } from '../spamwatch/spamwatch';
|
|
import spamwatchMiddlewareModule from '../spamwatch/Middleware';
|
|
import axios from 'axios';
|
|
|
|
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
|
|
|
export default (bot) => {
|
|
bot.command(["rpony", "randompony", "mlpart"], spamwatchMiddleware, async (ctx) => {
|
|
const Strings = getStrings(ctx.from.language_code);
|
|
try {
|
|
const response = await axios(Resources.randomPonyApi);
|
|
let tags: string[] = [];
|
|
|
|
if (response.data.pony.tags) {
|
|
if (typeof response.data.pony.tags === 'string') {
|
|
tags.push(response.data.pony.tags);
|
|
} else if (Array.isArray(response.data.pony.tags)) {
|
|
tags = tags.concat(response.data.pony.tags);
|
|
}
|
|
}
|
|
|
|
ctx.replyWithPhoto(response.data.pony.representations.full, {
|
|
caption: `${response.data.pony.sourceURL}\n\n${tags.length > 0 ? tags.join(', ') : ''}`,
|
|
parse_mode: 'Markdown',
|
|
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',
|
|
reply_to_message_id: ctx.message.message_id
|
|
});
|
|
return;
|
|
}
|
|
});
|
|
} |