This commit is contained in:
cirroskais 2024-07-26 01:27:44 -04:00
parent ab612467cc
commit cecdf21657
No known key found for this signature in database
GPG key ID: 5FC73EBF2678E33D
13 changed files with 65 additions and 96 deletions

View file

@ -1,3 +1,5 @@
DISCORD_ID= DISCORD_ID=
DISCORD_TOKEN= DISCORD_TOKEN=
DISCORD_SECRET= DISCORD_SECRET=
OLLAMA_API=

View file

@ -1 +0,0 @@
{}

View file

@ -2,18 +2,15 @@ import { logger } from "@discordeno/utils";
import REST from "../src/lib/handlers/RESTHandler"; import REST from "../src/lib/handlers/RESTHandler";
import * as InteractionHandler from "../src/lib/handlers/InteractionHandler"; import * as InteractionHandler from "../src/lib/handlers/InteractionHandler";
import * as CommandHandler from "../src/lib/handlers/CommandHandler";
await InteractionHandler.load(); await InteractionHandler.load();
const registered = await REST.getGlobalApplicationCommands(); const registered = await REST.getGlobalApplicationCommands();
for (let { id, name, type } of registered) { const id = process.argv[2];
const cmd = CommandHandler.commands.get(name); const cmd = registered.find((_) => _.id === id);
if (cmd && cmd.type == type) continue; if (cmd) {
await REST.deleteGlobalApplicationCommand(id); await REST.deleteGlobalApplicationCommand(id);
logger.info(`Deleted ${cmd.name}(${id})`);
logger.info(`Deleted ${name}(${id})`);
} }
process.exit(); process.exit();

View file

@ -5,16 +5,16 @@ const registered = await REST.getGlobalApplicationCommands();
const TYPES = ["CHAT_INPUT", "USER", "MESSAGE"]; const TYPES = ["CHAT_INPUT", "USER", "MESSAGE"];
logger.info("┌" + "-".repeat(58) + "┐"); logger.info("┌" + "-".repeat(58 + 8) + "┐");
logger.info("| " + "ID".padEnd(24, " ") + " | " + "NAME".padEnd(16, " ") + " | " + "TYPE".padEnd(10, " ") + " |"); logger.info("| " + "ID".padEnd(24, " ") + " | " + "NAME".padEnd(24, " ") + " | " + "TYPE".padEnd(10, " ") + " |");
logger.info("├" + "-".repeat(58) + "┤"); logger.info("├" + "-".repeat(58 + 8) + "┤");
for (let { id, name, type } of registered) { for (let { id, name, type } of registered) {
logger.info( logger.info(
"| " + id.padEnd(24, " ") + " | " + name.padEnd(16, " ") + " | " + TYPES[type - 1].padEnd(10, " ") + " |", "| " + id.padEnd(24, " ") + " | " + name.padEnd(24, " ") + " | " + TYPES[type - 1].padEnd(10, " ") + " |",
); );
} }
logger.info("└" + "-".repeat(58) + "┘"); logger.info("└" + "-".repeat(58 + 8) + "┘");
process.exit(); process.exit();

View file

@ -11,7 +11,7 @@ for (let [key, value] of CommandHandler.commands.entries()) {
headers: { "Content-Type": "application/json", Authorization: "Bot " + process.env.DISCORD_TOKEN }, headers: { "Content-Type": "application/json", Authorization: "Bot " + process.env.DISCORD_TOKEN },
body: JSON.stringify({ body: JSON.stringify({
name: value.name, name: value.name,
type: value.type, type: value.commandType,
description: value?.description || "", description: value?.description || "",
options: value?.options, options: value?.options,
nsfw: value?.nsfw, nsfw: value?.nsfw,
@ -21,8 +21,11 @@ for (let [key, value] of CommandHandler.commands.entries()) {
}); });
const command = await response.json(); const command = await response.json();
if (command.id) logger.info(`Registered ${command.name}(${command.id})(type:${value.type})`);
logger.info(`Registered ${command.name}(${command.id})`); else {
logger.error(`Failed to register new command ${value.name}(type:${value.type})`);
console.log(JSON.stringify(command.errors, null, 4));
}
} }
process.exit(); process.exit();

20
src/interactions/bizz.ts Normal file
View file

@ -0,0 +1,20 @@
import type { Command } from "../lib/types/command";
import { InteractionResponseTypes } from "@discordeno/bot";
import UserCommand from "../lib/classes/UserCommand";
export default class extends UserCommand implements Command {
name = "Bizz";
description = "";
options = [];
constructor() {
super();
}
async run() {
return {
type: InteractionResponseTypes.ChannelMessageWithSource,
data: { content: "<:FvU757MaYAAb_G9:1265558339283320864>" },
};
}
}

View file

@ -3,8 +3,8 @@ import { InteractionResponseTypes } from "@discordeno/bot";
import SlashCommand from "../lib/classes/SlashCommand"; import SlashCommand from "../lib/classes/SlashCommand";
export default class extends SlashCommand implements Command { export default class extends SlashCommand implements Command {
name = "default"; name = "foo";
description = "default"; description = "Foo";
options = []; options = [];
constructor() { constructor() {
@ -14,7 +14,7 @@ export default class extends SlashCommand implements Command {
async run() { async run() {
return { return {
type: InteractionResponseTypes.ChannelMessageWithSource, type: InteractionResponseTypes.ChannelMessageWithSource,
data: { content: "my name is terry and im going to destroy thgis world" }, data: { content: "Bar" },
}; };
} }
} }

View file

@ -1,72 +0,0 @@
import type { Command } from "../lib/types/command";
import { MessageComponentTypes, TextStyles } from "@discordeno/bot";
import SlashCommand from "../lib/classes/SlashCommand";
import Modal from "../lib/classes/Modal";
import { collectModal } from "../lib/handlers/ModalHandler";
interface SendMailResponse {
success: boolean;
message: string;
}
export default class extends SlashCommand implements Command {
name = "send";
description = "Send mail to a user in the Enigmatica 9 server!";
options = [];
constructor() {
super();
}
async run() {
const modal = new Modal().setTitle("Send Mail").setComponents([
{
type: MessageComponentTypes.ActionRow,
components: [
{
type: MessageComponentTypes.InputText,
customId: "recipient",
style: TextStyles.Short,
label: "Recipient",
},
],
},
{
type: MessageComponentTypes.ActionRow,
components: [
{
type: MessageComponentTypes.InputText,
customId: "content",
style: TextStyles.Paragraph,
label: "Message",
},
],
},
]);
collectModal(modal)
.then(async ({ interaction, values }) => {
if (!interaction.data?.components) return;
const user = interaction?.member?.user || { username: "[unknown]" };
try {
const response = await fetch(process.env.MAIL_SERVER + "/send", {
method: "POST",
body: JSON.stringify({
author: user.username,
recipient: values.get("recipient"),
content: values.get("content"),
}),
});
const body = (await response.json()) as SendMailResponse;
interaction.respond(body.message);
} catch (e) {
return interaction.respond((e as Error).message);
}
})
.catch((_) => {});
return modal;
}
}

View file

@ -0,0 +1,20 @@
import type { Command } from "../lib/types/command";
import { InteractionResponseTypes } from "@discordeno/bot";
import MessageCommand from "../lib/classes/MessageCommand";
export default class extends MessageCommand implements Command {
name = "Upload to snep.lol";
description = "";
options = [];
constructor() {
super();
}
async run() {
return {
type: InteractionResponseTypes.ChannelMessageWithSource,
data: { content: "MY NUTS LMAO" },
};
}
}

View file

@ -1,5 +1,5 @@
import { InteractionTypes } from "@discordeno/types"; import { InteractionTypes } from "@discordeno/types";
export default class ApplicationCommand { export default class ApplicationCommand {
static type = InteractionTypes.ApplicationCommand; type = InteractionTypes.ApplicationCommand;
} }

View file

@ -2,5 +2,5 @@ import { ApplicationCommandTypes } from "@discordeno/types";
import ApplicationCommand from "./ApplicationCommand"; import ApplicationCommand from "./ApplicationCommand";
export default class SlashCommand extends ApplicationCommand { export default class SlashCommand extends ApplicationCommand {
static commandType = ApplicationCommandTypes.Message; commandType = ApplicationCommandTypes.Message;
} }

View file

@ -2,5 +2,5 @@ import { ApplicationCommandTypes } from "@discordeno/types";
import ApplicationCommand from "./ApplicationCommand"; import ApplicationCommand from "./ApplicationCommand";
export default class SlashCommand extends ApplicationCommand { export default class SlashCommand extends ApplicationCommand {
static commandType = ApplicationCommandTypes.ChatInput; commandType = ApplicationCommandTypes.ChatInput;
} }

View file

@ -2,5 +2,5 @@ import { ApplicationCommandTypes } from "@discordeno/types";
import ApplicationCommand from "./ApplicationCommand"; import ApplicationCommand from "./ApplicationCommand";
export default class SlashCommand extends ApplicationCommand { export default class SlashCommand extends ApplicationCommand {
static commandType = ApplicationCommandTypes.User; commandType = ApplicationCommandTypes.User;
} }