Added functionality to fetch command list from bot stats site api.
This commit is contained in:
@@ -3,19 +3,23 @@ import type { Context } from "#root/bot/context.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.js";
|
||||
import { urql } from "#root/main.js";
|
||||
import increment from "#root/lib/graphql/mutations/incrementMutation.js";
|
||||
import getCommandsList, { Commands } from "#root/lib/getCommandsList.js";
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
const feature = composer.chatType(["group", "supergroup", "private"]);
|
||||
|
||||
const mutationKey = process.env.GRAPHQL_MUTATION_KEY || "";
|
||||
|
||||
/**
|
||||
* What triggers this feature and adds to the log when it has been triggered.
|
||||
* The trigger is the command "/help"
|
||||
*/
|
||||
feature.hears(/^\/help/, logHandle("help"), async (ctx: Context) => {
|
||||
const apiKey = process.env.GRAPHQL_API_TOKEN || "";
|
||||
const mutationKey = process.env.GRAPHQL_MUTATION_KEY || "";
|
||||
const statsSite = process.env.STATS_SITE || "";
|
||||
|
||||
await urql.mutation(increment, { trigger: true, mutationKey });
|
||||
const commandsListArr = await getCommandsList(`${statsSite}api/bot`, apiKey);
|
||||
|
||||
// const GROUP_IDS = process.env.GROUP_IDS
|
||||
// ? process.env.GROUP_IDS.split(",")
|
||||
@@ -32,7 +36,7 @@ feature.hears(/^\/help/, logHandle("help"), async (ctx: Context) => {
|
||||
if (ctx.chat.type === "private") {
|
||||
// Responds with message.
|
||||
await ctx.reply(
|
||||
`Currently I have no commands for the public beta\\. I require no configuration\\. Simply add me to a group and make me an admin with the permission to delete messages\\. From there I will start deleting any Twitter\\/X and Meta links I detect\\. I also check embeds and forwards\\. Use /\\botInfo to learn more about my mission and why I was created\\.`,
|
||||
`I require no configuration\\. Simply add me to a group and make me an admin with the permission to delete messages\\. From there I will start deleting any Twitter\\/X and Meta links I detect\\. I also check embeds and forwards\\.`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
@@ -48,7 +52,7 @@ feature.hears(/^\/help/, logHandle("help"), async (ctx: Context) => {
|
||||
if (["creator", "administrator"].includes(chatMember.status)) {
|
||||
// Respond with message.
|
||||
await ctx.reply(
|
||||
`Currently I have no commands for the public beta\\. I require no configuration\\. If I am not working\\, make sure I have an admin role with the permission to delete messages\\. I should already be deleting any Twitter\\/X and Meta links I detect\\. I also check embeds and forwards\\. Use /\\botInfo to learn more about my mission and why I was created\\.`,
|
||||
`I require no configuration\\. If I am not working\\, make sure I have an admin role with the permission to delete messages\\. I should already be deleting any Twitter\\/X and Meta links I detect\\. I also check embeds and forwards\\.`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
@@ -63,6 +67,17 @@ feature.hears(/^\/help/, logHandle("help"), async (ctx: Context) => {
|
||||
}
|
||||
}
|
||||
|
||||
const commandsListStr = commandsListArr.reduce((prev, curr) => {
|
||||
const { command, description, groups } = curr;
|
||||
|
||||
return (prev += `**Command**: ${command} \\- ${description}\\.\nGroups: ${groups ? "✔️" : "❌"} \\| Private: ${curr.private ? "✔️" : "❌"}\n\n`);
|
||||
}, "Here are a list of my commands:\n\n");
|
||||
|
||||
await ctx.reply(commandsListStr, {
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
});
|
||||
|
||||
await ctx.reply(
|
||||
`In the future a public GitHub repo will be set up with a mirror of the private git that the bot code is stored on\\. That repo will be used to handle bug reports and feature requests\\. Including requests to check for more domains\\.`,
|
||||
{
|
||||
@@ -71,13 +86,13 @@ feature.hears(/^\/help/, logHandle("help"), async (ctx: Context) => {
|
||||
}
|
||||
);
|
||||
|
||||
return await ctx.reply(
|
||||
`Down with fascism\\! Fuck MAGA\\! Fuck Trump\\! Fuck Nazis\\! Trans rights are human rights\\! Trans women are women\\! Trans men are men\\! Never let them take away your happiness\\!`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
// return await ctx.reply(
|
||||
// `Down with fascism\\! Fuck MAGA\\! Fuck Trump\\! Fuck Nazis\\! Trans rights are human rights\\! Trans women are women\\! Trans men are men\\! Never let them take away your happiness\\!`,
|
||||
// {
|
||||
// parse_mode: "MarkdownV2",
|
||||
// reply_parameters: { message_id: ctx.msg.message_id }
|
||||
// }
|
||||
// );
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
30
src/lib/getCommandsList.ts
Normal file
30
src/lib/getCommandsList.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import axios from "axios";
|
||||
|
||||
export interface Commands {
|
||||
command: String;
|
||||
description: String;
|
||||
groups: boolean;
|
||||
private: boolean;
|
||||
}
|
||||
|
||||
const fetchCommandsList = async (
|
||||
url: string,
|
||||
apiKey: string
|
||||
): Promise<Commands[]> => {
|
||||
let commandsList = [] as Commands[];
|
||||
|
||||
await axios
|
||||
.get(url, {
|
||||
headers: { "x-api-key": apiKey }
|
||||
})
|
||||
.then(res => {
|
||||
commandsList = res.data;
|
||||
})
|
||||
.catch(res => {
|
||||
console.error(res);
|
||||
});
|
||||
|
||||
return commandsList;
|
||||
};
|
||||
|
||||
export default fetchCommandsList;
|
||||
Reference in New Issue
Block a user