generated from lucxjo/template
Compare commits
No commits in common. "530e99a7d03e14dc1d54ca9ce48cbb985a663680" and "6e1e54da1bbc03f970b2debd4117375c63ff1906" have entirely different histories.
530e99a7d0
...
6e1e54da1b
|
@ -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");
|
|
@ -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"
|
|
@ -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])
|
||||
}
|
||||
|
|
|
@ -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<CommandInteraction> = 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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
10
src/events/common.ts
Normal file
10
src/events/common.ts
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
22
src/main.ts
22
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
|
||||
//
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"noImplicitAny": false,
|
||||
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue