i hyperfocused and here is v1

This commit is contained in:
Rose 2024-04-19 00:15:20 -04:00
parent 8f43e6a6a9
commit 4090fd621e
No known key found for this signature in database
34 changed files with 4135 additions and 22 deletions

View file

@ -0,0 +1,83 @@
import { database, Schema } from "@datamine/database";
import { Command } from "@sapphire/framework";
import { ChannelType } from "discord.js";
export class SubscribeCommand extends Command {
public constructor(
context: Command.LoaderContext,
options: Command.Options,
) {
super(context, { ...options });
}
public override registerApplicationCommands(
registry: Command.Registry,
) {
registry.registerChatInputCommand((builder) =>
builder
.setName("subscribe")
.setDescription("Subscribe to the Datamine updates.")
.addChannelOption((option) =>
option
.setName("channel")
.setDescription("The channel to send updates to.")
.addChannelTypes(ChannelType.GuildText),
)
.addRoleOption((option) =>
option
.setName("role")
.setDescription("The role to send updates to."),
),
);
}
public async chatInputRun(
interaction: Command.ChatInputCommandInteraction,
) {
if (!interaction.inGuild()) return;
if (!interaction.memberPermissions.has("ManageWebhooks")) {
return interaction.reply({
content: "You do not have permission to use this command.",
ephemeral: true,
});
}
const channel = interaction.options.getChannel("channel", false, [
ChannelType.GuildText,
]);
const role = interaction.options.getRole("role");
const data = {
channel: channel
? BigInt(channel.id)
: BigInt(interaction.channelId),
role: role ? BigInt(role.id) : undefined,
};
try {
await database
.insert(Schema.servers)
.values({
id: BigInt(interaction.guildId),
...data,
})
.onConflictDoUpdate({
target: Schema.servers.id,
set: data,
});
} catch (error) {
return interaction.reply({
content:
"An error occurred while subscribing to Datamine updates.",
ephemeral: true,
});
}
return interaction.reply({
content: `Datamine posts will now be posted into <#${
data.channel
}> ${data.role ? `and mention <@&${data.role}>` : ""}.`,
ephemeral: true,
});
}
}

View file

@ -0,0 +1,53 @@
import { Drizzle, Schema, database } from "@datamine/database";
import { Command } from "@sapphire/framework";
export class SubscribeCommand extends Command {
public constructor(
context: Command.LoaderContext,
options: Command.Options,
) {
super(context, { ...options });
}
public override registerApplicationCommands(
registry: Command.Registry,
) {
registry.registerChatInputCommand((builder) =>
builder
.setName("unsubscribe")
.setDescription("Unsubscribe from the Datamine updates."),
);
}
public async chatInputRun(
interaction: Command.ChatInputCommandInteraction,
) {
if (!interaction.inGuild()) return;
if (!interaction.memberPermissions.has("ManageWebhooks")) {
return interaction.reply({
content: "You do not have permission to use this command.",
ephemeral: true,
});
}
try {
await database
.delete(Schema.servers)
.where(
Drizzle.eq(Schema.servers.id, BigInt(interaction.guildId)),
);
} catch (error) {
return interaction.reply({
content:
"An error occurred while subscribing to Datamine updates.",
ephemeral: true,
});
}
return interaction.reply({
content:
"Datamine posts will no longer be posted in this server.",
ephemeral: true,
});
}
}

15
apps/bot/src/main.ts Normal file
View file

@ -0,0 +1,15 @@
import "dotenv/config";
import { SapphireClient } from "@sapphire/framework";
import { resolve } from "node:path";
if (!process.env.DISCORD_BOT_TOKEN) {
throw new Error("DISCORD_BOT_TOKEN is not defined");
}
const client = new SapphireClient({
intents: [],
baseUserDirectory: resolve(import.meta.dirname),
});
client.login(process.env.DISCORD_BOT_TOKEN);