Migrate to TypeScript, minor changes and fixes (#46)
* 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>
This commit is contained in:
parent
6fd5652afa
commit
07045d8e09
32 changed files with 550 additions and 325 deletions
75
src/commands/http.ts
Normal file
75
src/commands/http.ts
Normal file
|
@ -0,0 +1,75 @@
|
|||
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';
|
||||
import verifyInput from '../plugins/verifyInput';
|
||||
|
||||
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
||||
|
||||
export default (bot) => {
|
||||
bot.command("http", spamwatchMiddleware, async (ctx) => {
|
||||
const Strings = getStrings(ctx.from.language_code);
|
||||
const userInput = ctx.message.text.split(' ')[1];
|
||||
const apiUrl = Resources.httpApi;
|
||||
const { invalidCode } = Strings.httpCodes
|
||||
|
||||
if (verifyInput(ctx, userInput, invalidCode, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await axios.get(apiUrl);
|
||||
const data = response.data;
|
||||
const codesArray = Array.isArray(data) ? data : Object.values(data);
|
||||
const codeInfo = codesArray.find(item => item.code === parseInt(userInput));
|
||||
|
||||
if (codeInfo) {
|
||||
const message = Strings.httpCodes.resultMsg
|
||||
.replace("{code}", codeInfo.code)
|
||||
.replace("{message}", codeInfo.message)
|
||||
.replace("{description}", codeInfo.description);
|
||||
await ctx.reply(message, {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
} else {
|
||||
await ctx.reply(Strings.httpCodes.notFound, {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
};
|
||||
} catch (error) {
|
||||
const message = Strings.httpCodes.fetchErr.replace("{error}", error);
|
||||
ctx.reply(message, {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
bot.command("httpcat", spamwatchMiddleware, async (ctx) => {
|
||||
const Strings = getStrings(ctx.from.language_code);
|
||||
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(/\s+/g, '');
|
||||
const { invalidCode } = Strings.httpCodes
|
||||
|
||||
if (verifyInput(ctx, userInput, invalidCode, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const apiUrl = `${Resources.httpCatApi}${userInput}`;
|
||||
|
||||
try {
|
||||
await ctx.replyWithPhoto(apiUrl, {
|
||||
caption: `🐱 ${apiUrl}`,
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
} catch (error) {
|
||||
ctx.reply(Strings.catImgErr, {
|
||||
parse_mode: 'Markdown',
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue