diff --git a/prisma/migrations/0_init/migration.sql b/prisma/migrations/0_init/migration.sql deleted file mode 100644 index 8886a04..0000000 --- a/prisma/migrations/0_init/migration.sql +++ /dev/null @@ -1,26 +0,0 @@ --- CreateTable -CREATE TABLE "guild" ( - "id" TEXT NOT NULL, - "name" TEXT NOT NULL, - "reports_channel_id" TEXT, - - CONSTRAINT "guild_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "member" ( - "id" UUID NOT NULL DEFAULT gen_random_uuid(), - "name" TEXT NOT NULL, - "booster_role_id" TEXT, - "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "dgid" TEXT NOT NULL, - "duid" TEXT NOT NULL, - - CONSTRAINT "member_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX "guild_id_key" ON "guild"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "member_dgid_duid_key" ON "member"("dgid", "duid"); diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml deleted file mode 100644 index fbffa92..0000000 --- a/prisma/migrations/migration_lock.toml +++ /dev/null @@ -1,3 +0,0 @@ -# Please do not edit this file manually -# It should be added in your version-control system (i.e. Git) -provider = "postgresql" \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 5463950..fc1e6d5 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -1,6 +1,5 @@ generator client { - provider = "prisma-client-js" - previewFeatures = ["postgresqlExtensions"] + provider = "prisma-client-js" } datasource db { @@ -13,16 +12,3 @@ model guild { name String reports_channel_id String? } - -model member { - id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid - name String - booster_role_id String? - created_at DateTime @default(now()) - /// Discord Guild ID - dgid String - /// Discord User ID - duid String - - @@unique([dgid, duid]) -} diff --git a/src/commands/admin.ts b/src/commands/admin.ts index 49cdfa4..405a3eb 100644 --- a/src/commands/admin.ts +++ b/src/commands/admin.ts @@ -4,19 +4,35 @@ import { CommandInteraction, GuildMember, PermissionsBitField, - Role, } from "discord.js"; -import { Discord, Slash, SlashGroup, SlashOption } from "discordx"; +import { + Discord, + Guard, + GuardFunction, + Slash, + SlashGroup, + SlashOption, +} from "discordx"; import { prisma } from "../main.js"; +const AdminOnly: GuardFunction = async ( + arg, + client, + next +) => { + const argObj = arg instanceof Array ? arg[0] : arg; + const user = argObj.user as GuildMember; + + if (user.permissions.has(PermissionsBitField.Flags.Administrator)) + await next(); +}; + @Discord() @SlashGroup({ name: "admin", description: "Admin commands" }) @SlashGroup("admin") -export class AdminCmds { - @Slash({ - description: "Set or get the configured channel for reports", - defaultMemberPermissions: PermissionsBitField.Flags.Administrator, - }) +@Guard(AdminOnly) +class AdminCmds { + @Slash({ description: "Set or get the configured channel for reports" }) async reports( @SlashOption({ description: "Set where the reports should be sent", @@ -76,61 +92,4 @@ export class AdminCmds { }); } } - - @Slash({ - description: "Link a user to their booster role", - name: "link_role", - defaultMemberPermissions: PermissionsBitField.Flags.ManageRoles, - }) - async link_role( - @SlashOption({ - description: "The user account to link", - name: "member", - required: true, - type: ApplicationCommandOptionType.User, - }) - member: GuildMember, - @SlashOption({ - description: "The role to link", - name: "role", - required: true, - type: ApplicationCommandOptionType.Role, - }) - role: Role, - interaction: CommandInteraction - ) { - let mem = await prisma.member.findUnique({ - where: { - dgid_duid: { - duid: member.id, - dgid: member.guild.id, - }, - }, - }); - - if (mem) { - await prisma.member.update({ - where: { - id: mem.id, - }, - data: { - booster_role_id: role.id, - name: member.displayName, - }, - }); - } else { - await prisma.member.create({ - data: { - duid: member.id, - dgid: interaction.guildId!, - name: member.displayName, - booster_role_id: role.id, - }, - }); - } - interaction.reply({ - content: "Member booster role updated!", - ephemeral: true, - }); - } } diff --git a/src/events/common.ts b/src/events/common.ts new file mode 100644 index 0000000..3a4e946 --- /dev/null +++ b/src/events/common.ts @@ -0,0 +1,10 @@ +import type { ArgsOf, Client } from "discordx"; +import { Discord, On } from "discordx"; + +@Discord() +export class Example { + @On() + messageDelete([message]: ArgsOf<"messageDelete">, client: Client): void { + console.log("Message Deleted", client.user?.username, message.content); + } +} diff --git a/src/events/guild_join.ts b/src/events/guild_join.ts deleted file mode 100644 index f6ac659..0000000 --- a/src/events/guild_join.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { ArgsOf, Discord, On } from "discordx"; -import { prisma } from "../main.js"; - -@Discord() -export class GuildJoin { - @On({ event: "guildCreate" }) - fn([guild]: ArgsOf<"guildCreate">) { - prisma.guild.create({ - data: { - id: guild.id, - name: guild.name, - }, - }); - } -} diff --git a/src/main.ts b/src/main.ts index a4b9038..9e8fa97 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,5 @@ import { dirname, importx } from "@discordx/importer"; -import type { Interaction } from "discord.js"; +import type { Guild, Interaction, Message } from "discord.js"; import { IntentsBitField } from "discord.js"; import * as dotenv from "dotenv"; import { Client } from "discordx"; @@ -23,11 +23,16 @@ export const bot = new Client({ // Debug logs are disabled in silent mode silent: false, + + // Configuration for @SimpleCommand + simpleCommand: { + prefix: "!", + }, }); bot.once("ready", async () => { // Make sure all guilds are cached - await bot.guilds.fetch(); + // await bot.guilds.fetch(); // Synchronize applications commands with Discord await bot.initApplicationCommands(); @@ -47,6 +52,19 @@ bot.on("interactionCreate", (interaction: Interaction) => { bot.executeInteraction(interaction); }); +bot.on("messageCreate", (message: Message) => { + bot.executeCommand(message); +}); + +bot.on("guildCreate", (guild: Guild) => { + prisma.guild.create({ + data: { + id: guild.id, + name: guild.name, + }, + }); +}); + async function run() { // The following syntax should be used in the commonjs environment // diff --git a/tsconfig.json b/tsconfig.json index 949e75a..646fe35 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,7 @@ "experimentalDecorators": true, "emitDecoratorMetadata": true, - "noImplicitAny": false, + "skipLibCheck": true, "forceConsistentCasingInFileNames": true },