Compare commits
1 commit
4aa3d28bd0
...
7c96333ba2
Author | SHA1 | Date | |
---|---|---|---|
7c96333ba2 |
13 changed files with 342 additions and 490 deletions
|
@ -38,14 +38,14 @@
|
|||
"mysql": "^2.18.1",
|
||||
"random-bunny": "^2.0.5",
|
||||
"ts-jest": "^29.0.0",
|
||||
"typeorm": "0.3.20"
|
||||
"typeorm": "0.3.19"
|
||||
},
|
||||
"resolutions": {
|
||||
"**/semver": "^7.5.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.0.0",
|
||||
"np": "^9.0.0",
|
||||
"np": "^8.0.4",
|
||||
"typescript": "^5.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
import { ButtonInteraction, CacheType } from "discord.js";
|
||||
import { ButtonEvent } from "../type/buttonEvent";
|
||||
import SettingsHelper from "../helpers/SettingsHelper";
|
||||
|
||||
export default class Verify extends ButtonEvent {
|
||||
public override async execute(interaction: ButtonInteraction<CacheType>) {
|
||||
if (!interaction.guildId || !interaction.guild) return;
|
||||
|
||||
const roleName = await SettingsHelper.GetSetting("verification.role", interaction.guildId);
|
||||
|
||||
if (!roleName) return;
|
||||
|
||||
const role = interaction.guild.roles.cache.find(x => x.name == roleName);
|
||||
|
||||
if (!role) {
|
||||
await interaction.reply({
|
||||
content: `Unable to find the role, ${roleName}`,
|
||||
ephemeral: true,
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const member = interaction.guild.members.cache.find(x => x.id == interaction.user.id);
|
||||
|
||||
if (!member || !member.manageable) {
|
||||
await interaction.reply({
|
||||
content: "Unable to give role to user",
|
||||
ephemeral: true,
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
await member.roles.add(role);
|
||||
|
||||
await interaction.reply({
|
||||
content: "Given role",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
}
|
|
@ -9,13 +9,10 @@ import { Command } from "../type/command";
|
|||
import { Events } from "./events";
|
||||
import { Util } from "./util";
|
||||
import AppDataSource from "../database/dataSources/appDataSource";
|
||||
import ButtonEventItem from "../contracts/ButtonEventItem";
|
||||
import { ButtonEvent } from "../type/buttonEvent";
|
||||
|
||||
export class CoreClient extends Client {
|
||||
private static _commandItems: ICommandItem[];
|
||||
private static _eventItems: IEventItem[];
|
||||
private static _buttonEvents: ButtonEventItem[];
|
||||
|
||||
private _events: Events;
|
||||
private _util: Util;
|
||||
|
@ -28,17 +25,12 @@ export class CoreClient extends Client {
|
|||
return this._eventItems;
|
||||
}
|
||||
|
||||
public static get buttonEvents(): ButtonEventItem[] {
|
||||
return this._buttonEvents;
|
||||
}
|
||||
|
||||
constructor(intents: number[], partials: Partials[]) {
|
||||
super({ intents: intents, partials: partials });
|
||||
dotenv.config();
|
||||
|
||||
CoreClient._commandItems = [];
|
||||
CoreClient._eventItems = [];
|
||||
CoreClient._buttonEvents = [];
|
||||
|
||||
this._events = new Events();
|
||||
this._util = new Util();
|
||||
|
@ -81,13 +73,4 @@ export class CoreClient extends Client {
|
|||
|
||||
CoreClient._eventItems.push(item);
|
||||
}
|
||||
|
||||
public static RegisterButtonEvent(buttonId: string, event: ButtonEvent) {
|
||||
const item: ButtonEventItem = {
|
||||
ButtonId: buttonId,
|
||||
Event: event,
|
||||
};
|
||||
|
||||
CoreClient._buttonEvents.push(item);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,40 @@
|
|||
import { Interaction } from "discord.js";
|
||||
import ChatInputCommand from "./interactionCreate/chatInputCommand";
|
||||
import Button from "./interactionCreate/button";
|
||||
import ICommandItem from "../contracts/ICommandItem";
|
||||
import SettingsHelper from "../helpers/SettingsHelper";
|
||||
import { CoreClient } from "./client";
|
||||
|
||||
export class Events {
|
||||
public async onInteractionCreate(interaction: Interaction) {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
if (!interaction.guildId) return;
|
||||
|
||||
if (interaction.isChatInputCommand()) {
|
||||
ChatInputCommand.onChatInput(interaction);
|
||||
const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", interaction.guildId);
|
||||
const disabledCommands = disabledCommandsString?.split(",");
|
||||
|
||||
const disabledCommandsMessage = await SettingsHelper.GetSetting("commands.disabled.message", interaction.guildId);
|
||||
|
||||
if (disabledCommands?.find(x => x == interaction.commandName)) {
|
||||
await interaction.reply(disabledCommandsMessage || "This command is disabled.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (interaction.isButton()) {
|
||||
Button.onButtonClicked(interaction);
|
||||
const item = CoreClient.commandItems.find(x => x.Name == interaction.commandName && !x.ServerId);
|
||||
const itemForServer = CoreClient.commandItems.find(x => x.Name == interaction.commandName && x.ServerId == interaction.guildId);
|
||||
|
||||
let itemToUse: ICommandItem;
|
||||
|
||||
if (!itemForServer) {
|
||||
if (!item) {
|
||||
await interaction.reply('Command not found');
|
||||
return;
|
||||
}
|
||||
|
||||
itemToUse = item;
|
||||
} else {
|
||||
itemToUse = itemForServer;
|
||||
}
|
||||
|
||||
itemToUse.Command.execute(interaction);
|
||||
}
|
||||
|
||||
// Emit when bot is logged in and ready to use
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
import { ButtonInteraction } from "discord.js";
|
||||
import { CoreClient } from "../client";
|
||||
|
||||
export default class Button {
|
||||
public static async onButtonClicked(interaction: ButtonInteraction) {
|
||||
if (!interaction.isButton) return;
|
||||
|
||||
const item = CoreClient.buttonEvents.find(x => x.ButtonId == interaction.customId.split(" ")[0]);
|
||||
|
||||
if (!item) {
|
||||
await interaction.reply("Event not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
item.Event.execute(interaction);
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
import { Interaction } from "discord.js";
|
||||
import { CoreClient } from "../client";
|
||||
import ICommandItem from "../../contracts/ICommandItem";
|
||||
|
||||
export default class ChatInputCommand {
|
||||
public static async onChatInput(interaction: Interaction) {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
const item = CoreClient.commandItems.find(x => x.Name == interaction.commandName && !x.ServerId);
|
||||
const itemForServer = CoreClient.commandItems.find(x => x.Name == interaction.commandName && x.ServerId == interaction.guildId);
|
||||
|
||||
let itemToUse: ICommandItem;
|
||||
|
||||
if (!itemForServer) {
|
||||
if (!item) {
|
||||
await interaction.reply("Command not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
itemToUse = item;
|
||||
} else {
|
||||
itemToUse = itemForServer;
|
||||
}
|
||||
|
||||
itemToUse.Command.execute(interaction);
|
||||
}
|
||||
}
|
|
@ -1,8 +1,7 @@
|
|||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
||||
import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
||||
import { existsSync, readFileSync } from "fs";
|
||||
import EmbedColours from "../constants/EmbedColours";
|
||||
import { Command } from "../type/command";
|
||||
import SettingsHelper from "../helpers/SettingsHelper";
|
||||
|
||||
interface IRules {
|
||||
title?: string;
|
||||
|
@ -15,36 +14,13 @@ export default class Rules extends Command {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
this.CommandBuilder = new SlashCommandBuilder()
|
||||
.setName('rules')
|
||||
.setDescription("Rules-related commands")
|
||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator)
|
||||
.addSubcommand(x =>
|
||||
x
|
||||
.setName('embeds')
|
||||
.setDescription('Send the rules embeds for this server'))
|
||||
.addSubcommand(x =>
|
||||
x
|
||||
.setName('access')
|
||||
.setDescription('Send the server verification embed button'));
|
||||
super.CommandBuilder = new SlashCommandBuilder()
|
||||
.setName("rules")
|
||||
.setDescription("Send the rules embeds for this server")
|
||||
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator);
|
||||
}
|
||||
|
||||
public override async execute(interaction: CommandInteraction) {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
switch (interaction.options.getSubcommand()) {
|
||||
case "embeds":
|
||||
await this.SendEmbeds(interaction);
|
||||
break;
|
||||
case "access":
|
||||
await this.SendAccessButton(interaction);
|
||||
break;
|
||||
default:
|
||||
await interaction.reply("Subcommand doesn't exist.");
|
||||
}
|
||||
}
|
||||
|
||||
private async SendEmbeds(interaction: CommandInteraction) {
|
||||
if (!interaction.guildId) return;
|
||||
|
||||
if (!existsSync(`${process.cwd()}/data/rules/${interaction.guildId}.json`)) {
|
||||
|
@ -95,27 +71,4 @@ export default class Rules extends Command {
|
|||
|
||||
await interaction.reply({ embeds: [ successEmbed ], ephemeral: true });
|
||||
}
|
||||
|
||||
private async SendAccessButton(interaction: CommandInteraction) {
|
||||
if (!interaction.guildId) return;
|
||||
|
||||
const buttonLabel = await SettingsHelper.GetSetting("rules.access.label", interaction.guildId);
|
||||
|
||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||
.addComponents([
|
||||
new ButtonBuilder()
|
||||
.setCustomId('verify')
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
.setLabel(buttonLabel || "Verify")
|
||||
]);
|
||||
|
||||
await interaction.channel?.send({
|
||||
components: [ row ]
|
||||
});
|
||||
|
||||
await interaction.reply({
|
||||
content: "Success",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
}
|
|
@ -31,7 +31,6 @@ export default class DefaultValues {
|
|||
|
||||
// Rules (Command)
|
||||
this.values.push({ Key: "rules.file", Value: "data/rules/rules" });
|
||||
this.values.push({ Key: "rules.access.label", Value: "Verify" });
|
||||
|
||||
// Channels
|
||||
this.values.push({ Key: "channels.logs.message", Value: "message-logs" });
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
import { ButtonEvent } from "../type/buttonEvent";
|
||||
|
||||
interface ButtonEventItem {
|
||||
ButtonId: string,
|
||||
Event: ButtonEvent,
|
||||
}
|
||||
|
||||
export default ButtonEventItem;
|
|
@ -37,9 +37,6 @@ import MessageDelete from "./events/MessageEvents/MessageDelete";
|
|||
import MessageUpdate from "./events/MessageEvents/MessageUpdate";
|
||||
import MessageCreate from "./events/MessageEvents/MessageCreate";
|
||||
|
||||
// Button Event Imports
|
||||
import Verify from "./buttonEvents/verify";
|
||||
|
||||
export default class Registry {
|
||||
public static RegisterCommands() {
|
||||
CoreClient.RegisterCommand("about", new About());
|
||||
|
@ -87,8 +84,4 @@ export default class Registry {
|
|||
CoreClient.RegisterEvent(EventType.MessageUpdate, MessageUpdate);
|
||||
CoreClient.RegisterEvent(EventType.MessageCreate, MessageCreate);
|
||||
}
|
||||
|
||||
public static RegisterButtonEvents() {
|
||||
CoreClient.RegisterButtonEvent("verify", new Verify());
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
import { ButtonInteraction } from "discord.js";
|
||||
|
||||
export abstract class ButtonEvent {
|
||||
abstract execute(interaction: ButtonInteraction): Promise<void>;
|
||||
}
|
|
@ -37,6 +37,5 @@ const client = new CoreClient([
|
|||
|
||||
registry.RegisterCommands();
|
||||
registry.RegisterEvents();
|
||||
registry.RegisterButtonEvents();
|
||||
|
||||
client.start();
|
||||
|
|
Loading…
Reference in a new issue