Migrate to slash commands
This commit is contained in:
parent
1dc7bb2f38
commit
5758cbd7f0
38 changed files with 1192 additions and 1415 deletions
2
.dev.env
2
.dev.env
|
@ -9,8 +9,8 @@
|
||||||
BOT_TOKEN=
|
BOT_TOKEN=
|
||||||
BOT_VER=3.1
|
BOT_VER=3.1
|
||||||
BOT_AUTHOR=Vylpes
|
BOT_AUTHOR=Vylpes
|
||||||
BOT_DATE=06 Sep 2022
|
|
||||||
BOT_OWNERID=147392775707426816
|
BOT_OWNERID=147392775707426816
|
||||||
|
BOT_CLIENTID=682942374040961060
|
||||||
BOT_PREFIX=d!
|
BOT_PREFIX=d!
|
||||||
|
|
||||||
ABOUT_FUNDING=https://ko-fi.com/vylpes
|
ABOUT_FUNDING=https://ko-fi.com/vylpes
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
BOT_TOKEN=
|
BOT_TOKEN=
|
||||||
BOT_VER=3.1
|
BOT_VER=3.1
|
||||||
BOT_AUTHOR=Vylpes
|
BOT_AUTHOR=Vylpes
|
||||||
BOT_DATE=06 Sep 2022
|
|
||||||
BOT_OWNERID=147392775707426816
|
BOT_OWNERID=147392775707426816
|
||||||
|
BOT_CLIENTID=680083120896081954
|
||||||
BOT_PREFIX=v!
|
BOT_PREFIX=v!
|
||||||
|
|
||||||
ABOUT_FUNDING=https://ko-fi.com/vylpes
|
ABOUT_FUNDING=https://ko-fi.com/vylpes
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
BOT_TOKEN=
|
BOT_TOKEN=
|
||||||
BOT_VER=3.1
|
BOT_VER=3.1
|
||||||
BOT_AUTHOR=Vylpes
|
BOT_AUTHOR=Vylpes
|
||||||
BOT_DATE=06 Sep 2022
|
|
||||||
BOT_OWNERID=147392775707426816
|
BOT_OWNERID=147392775707426816
|
||||||
|
BOT_CLIENTID=1016767908740857949
|
||||||
BOT_PREFIX=s!
|
BOT_PREFIX=s!
|
||||||
|
|
||||||
ABOUT_FUNDING=https://ko-fi.com/vylpes
|
ABOUT_FUNDING=https://ko-fi.com/vylpes
|
||||||
|
|
|
@ -47,14 +47,13 @@ export class CoreClient extends Client {
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
|
||||||
super.on("messageCreate", (message) => {
|
super.on("interactionCreate", this._events.onInteractionCreate);
|
||||||
this._events.onMessageCreate(message, CoreClient._commandItems)
|
|
||||||
});
|
|
||||||
super.on("ready", this._events.onReady);
|
super.on("ready", this._events.onReady);
|
||||||
|
|
||||||
super.login(process.env.BOT_TOKEN);
|
super.login(process.env.BOT_TOKEN);
|
||||||
|
|
||||||
this._util.loadEvents(this, CoreClient._eventItems);
|
this._util.loadEvents(this, CoreClient._eventItems);
|
||||||
|
this._util.loadSlashCommands(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RegisterCommand(name: string, command: Command, serverId?: string) {
|
public static RegisterCommand(name: string, command: Command, serverId?: string) {
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
import { Message } from "discord.js";
|
import { CommandInteraction, GuildMemberRoleManager, Interaction, Message, messageLink } from "discord.js";
|
||||||
|
import { CommandResponse } from "../constants/CommandResponse";
|
||||||
|
import ErrorMessages from "../constants/ErrorMessages";
|
||||||
import ICommandItem from "../contracts/ICommandItem";
|
import ICommandItem from "../contracts/ICommandItem";
|
||||||
import SettingsHelper from "../helpers/SettingsHelper";
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
|
import StringTools from "../helpers/StringTools";
|
||||||
|
import { CoreClient } from "./client";
|
||||||
import { Util } from "./util";
|
import { Util } from "./util";
|
||||||
|
|
||||||
export class Events {
|
export class Events {
|
||||||
|
@ -10,24 +14,70 @@ export class Events {
|
||||||
this._util = new Util();
|
this._util = new Util();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit when a message is sent
|
public async onInteractionCreate(interaction: Interaction) {
|
||||||
// Used to check for commands
|
if (!interaction.isChatInputCommand()) return;
|
||||||
public async onMessageCreate(message: Message, commands: ICommandItem[]) {
|
if (!interaction.guild) return;
|
||||||
if (!message.guild) return;
|
if (!interaction.member) return;
|
||||||
if (message.author.bot) return;
|
|
||||||
|
|
||||||
const prefix = await SettingsHelper.GetSetting("bot.prefix", message.guild.id);
|
const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", interaction.guild.id);
|
||||||
|
const disabledCommands = disabledCommandsString?.split(",");
|
||||||
|
|
||||||
if (!prefix) return;
|
if (disabledCommands?.find(x => x == interaction.commandName)) {
|
||||||
|
interaction.reply(process.env.COMMANDS_DISABLED_MESSAGE || "This command is disabled.");
|
||||||
|
|
||||||
if (message.content.substring(0, prefix.length).toLowerCase() == prefix.toLowerCase()) {
|
return;
|
||||||
const args = message.content.substring(prefix.length).split(" ");
|
|
||||||
const name = args.shift();
|
|
||||||
|
|
||||||
if (!name) return;
|
|
||||||
|
|
||||||
await this._util.loadCommand(name, args, message, commands);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
interaction.reply('Command not found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemToUse = item;
|
||||||
|
} else {
|
||||||
|
itemToUse = itemForServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
const requiredRoles = itemToUse.Command.Roles;
|
||||||
|
|
||||||
|
if (interaction.member.user.id != process.env.BOT_OWNERID && interaction.member.user.id != interaction.guild.ownerId) {
|
||||||
|
for (const i in requiredRoles) {
|
||||||
|
const setting = await SettingsHelper.GetSetting(`role.${requiredRoles[i]}`, interaction.guildId!);
|
||||||
|
|
||||||
|
if (!setting) {
|
||||||
|
interaction.reply("Unable to verify if you have this role, please contact your bot administrator");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const roles = interaction.member.roles as GuildMemberRoleManager;
|
||||||
|
|
||||||
|
if (!roles.cache.find(role => role.name == setting)) {
|
||||||
|
interaction.reply(`You require the \`${StringTools.Capitalise(setting)}\` role to run this command`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const precheckResponse = itemToUse.Command.precheck(interaction);
|
||||||
|
const precheckAsyncResponse = await itemToUse.Command.precheckAsync(interaction);
|
||||||
|
|
||||||
|
if (precheckResponse != CommandResponse.Ok) {
|
||||||
|
interaction.reply(ErrorMessages.GetErrorMessage(precheckResponse));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (precheckAsyncResponse != CommandResponse.Ok) {
|
||||||
|
interaction.reply(ErrorMessages.GetErrorMessage(precheckAsyncResponse));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemToUse.Command.execute(interaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit when bot is logged in and ready to use
|
// Emit when bot is logged in and ready to use
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Required Components
|
// Required Components
|
||||||
import { Client, Message } from "discord.js";
|
import { Client, Message, REST, Routes, SlashCommandBuilder } from "discord.js";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { ICommandContext } from "../contracts/ICommandContext";
|
||||||
import ICommandItem from "../contracts/ICommandItem";
|
import ICommandItem from "../contracts/ICommandItem";
|
||||||
import IEventItem from "../contracts/IEventItem";
|
import IEventItem from "../contracts/IEventItem";
|
||||||
|
@ -7,77 +7,51 @@ import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
import StringTools from "../helpers/StringTools";
|
import StringTools from "../helpers/StringTools";
|
||||||
import { CommandResponse } from "../constants/CommandResponse";
|
import { CommandResponse } from "../constants/CommandResponse";
|
||||||
import ErrorMessages from "../constants/ErrorMessages";
|
import ErrorMessages from "../constants/ErrorMessages";
|
||||||
|
import { CoreClient } from "./client";
|
||||||
|
|
||||||
// Util Class
|
// Util Class
|
||||||
export class Util {
|
export class Util {
|
||||||
public async loadCommand(name: string, args: string[], message: Message, commands: ICommandItem[]) {
|
public loadSlashCommands(client: Client) {
|
||||||
if (!message.member) return;
|
const registeredCommands = CoreClient.commandItems;
|
||||||
if (!message.guild) return;
|
|
||||||
|
|
||||||
const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", message.guild?.id);
|
const globalCommands = registeredCommands.filter(x => !x.ServerId);
|
||||||
const disabledCommands = disabledCommandsString?.split(",");
|
const guildCommands = registeredCommands.filter(x => x.ServerId);
|
||||||
|
|
||||||
if (disabledCommands?.find(x => x == name)) {
|
const globalCommandData: SlashCommandBuilder[] = globalCommands
|
||||||
message.reply(process.env.COMMANDS_DISABLED_MESSAGE || "This command is disabled.");
|
.filter(x => x.Command.CommandBuilder)
|
||||||
return;
|
.flatMap(x => x.Command.CommandBuilder);
|
||||||
}
|
|
||||||
|
|
||||||
const item = commands.find(x => x.Name == name && !x.ServerId);
|
const guildIds: string[] = [];
|
||||||
const itemForServer = commands.find(x => x.Name == name && x.ServerId == message.guild?.id);
|
|
||||||
|
|
||||||
let itemToUse: ICommandItem;
|
for (let command of guildCommands) {
|
||||||
|
if (!guildIds.find(x => x == command.ServerId)) {
|
||||||
if (!itemForServer) {
|
guildIds.push(command.ServerId!);
|
||||||
if (!item) {
|
|
||||||
message.reply('Command not found');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
itemToUse = item;
|
|
||||||
} else {
|
|
||||||
itemToUse = itemForServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
const requiredRoles = itemToUse.Command.Roles;
|
|
||||||
|
|
||||||
if (message.author.id != process.env.BOT_OWNERID && message.author.id != message.guild.ownerId) {
|
|
||||||
for (const i in requiredRoles) {
|
|
||||||
if (message.guild) {
|
|
||||||
const setting = await SettingsHelper.GetSetting(`role.${requiredRoles[i]}`, message.guild?.id);
|
|
||||||
|
|
||||||
if (!setting) {
|
|
||||||
message.reply("Unable to verify if you have this role, please contact your bot administrator");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!message.member.roles.cache.find(role => role.name == setting)) {
|
|
||||||
message.reply(`You require the \`${StringTools.Capitalise(setting)}\` role to run this command`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const context: ICommandContext = {
|
const rest = new REST({ version: '10' }).setToken(process.env.BOT_TOKEN!);
|
||||||
name: name,
|
|
||||||
args: args,
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
|
|
||||||
const precheckResponse = itemToUse.Command.precheck(context);
|
rest.put(
|
||||||
const precheckAsyncResponse = await itemToUse.Command.precheckAsync(context);
|
Routes.applicationCommands(process.env.BOT_CLIENTID!),
|
||||||
|
{
|
||||||
if (precheckResponse != CommandResponse.Ok) {
|
body: globalCommandData
|
||||||
message.reply(ErrorMessages.GetErrorMessage(precheckResponse));
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
|
||||||
if (precheckAsyncResponse != CommandResponse.Ok) {
|
for (let guild of guildIds) {
|
||||||
message.reply(ErrorMessages.GetErrorMessage(precheckAsyncResponse));
|
const guildCommandData = guildCommands.filter(x => x.ServerId == guild)
|
||||||
return;
|
.filter(x => x.Command.CommandBuilder)
|
||||||
|
.flatMap(x => x.Command.CommandBuilder);
|
||||||
|
|
||||||
|
if (!client.guilds.cache.has(guild)) continue;
|
||||||
|
|
||||||
|
rest.put(
|
||||||
|
Routes.applicationGuildCommands(process.env.BOT_CLIENTID!, guild),
|
||||||
|
{
|
||||||
|
body: guildCommandData
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
itemToUse.Command.execute(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the events
|
// Load the events
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
import { CommandInteraction, EmbedBuilder, SlashCommandBuilder } from "discord.js";
|
||||||
|
import EmbedColours from "../../constants/EmbedColours";
|
||||||
import { ICommandContext } from "../../contracts/ICommandContext";
|
import { ICommandContext } from "../../contracts/ICommandContext";
|
||||||
import PublicEmbed from "../../helpers/embeds/PublicEmbed";
|
|
||||||
import SettingsHelper from "../../helpers/SettingsHelper";
|
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||||
import { Command } from "../../type/command";
|
import { Command } from "../../type/command";
|
||||||
|
|
||||||
|
@ -11,15 +12,23 @@ export default class Entry extends Command {
|
||||||
super.Roles = [
|
super.Roles = [
|
||||||
"moderator"
|
"moderator"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName('entry')
|
||||||
|
.setDescription('Sends the entry embed');
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
if (!context.message.guild) return;
|
if (!interaction.guildId) return;
|
||||||
|
if (!interaction.channel) return;
|
||||||
|
|
||||||
const rulesChannelId = await SettingsHelper.GetSetting("channels.rules", context.message.guild.id) || "rules";
|
const rulesChannelId = await SettingsHelper.GetSetting("channels.rules", interaction.guildId) || "rules";
|
||||||
|
|
||||||
const embedInfo = new PublicEmbed(context, "", `Welcome to the server! Please make sure to read the rules in the <#${rulesChannelId}> channel and type the code found there in here to proceed to the main part of the server.`);
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle("Welcome")
|
||||||
|
.setDescription(`Welcome to the server! Please make sure to read the rules in the <#${rulesChannelId}> channel and type the code found there in here to proceed to the main part of the server.`);
|
||||||
|
|
||||||
await embedInfo.SendToCurrentChannel();
|
await interaction.channel.send({ embeds: [ embed ]});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,11 +1,9 @@
|
||||||
import { TextChannel } from "discord.js";
|
import { CommandInteraction, GuildMemberRoleManager, SlashCommandBuilder, TextChannel } from "discord.js";
|
||||||
import { ICommandContext } from "../../contracts/ICommandContext";
|
import { ICommandContext } from "../../contracts/ICommandContext";
|
||||||
import { Command } from "../../type/command";
|
import { Command } from "../../type/command";
|
||||||
import { default as eLobby } from "../../entity/501231711271780357/Lobby";
|
import { default as eLobby } from "../../entity/501231711271780357/Lobby";
|
||||||
import SettingsHelper from "../../helpers/SettingsHelper";
|
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||||
import PublicEmbed from "../../helpers/embeds/PublicEmbed";
|
|
||||||
import { readFileSync } from "fs";
|
import { readFileSync } from "fs";
|
||||||
import ErrorEmbed from "../../helpers/embeds/ErrorEmbed";
|
|
||||||
import BaseEntity from "../../contracts/BaseEntity";
|
import BaseEntity from "../../contracts/BaseEntity";
|
||||||
|
|
||||||
export default class Lobby extends Command {
|
export default class Lobby extends Command {
|
||||||
|
@ -13,32 +11,60 @@ export default class Lobby extends Command {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.Category = "General";
|
super.Category = "General";
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName('lobby')
|
||||||
|
.setDescription('Attempt to organise a lobby')
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('config')
|
||||||
|
.setDescription('Configure the lobby command (mods only)')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('action')
|
||||||
|
.setDescription('Add or remove a channel to the lobby list')
|
||||||
|
.addChoices(
|
||||||
|
{ name: 'add', value: 'add' },
|
||||||
|
{ name: 'remove', value: 'remove' },
|
||||||
|
))
|
||||||
|
.addChannelOption(option =>
|
||||||
|
option
|
||||||
|
.setName('channel')
|
||||||
|
.setDescription('The channel'))
|
||||||
|
.addRoleOption(option =>
|
||||||
|
option
|
||||||
|
.setName('role')
|
||||||
|
.setDescription('The role to ping on request'))
|
||||||
|
.addNumberOption(option =>
|
||||||
|
option
|
||||||
|
.setName('cooldown')
|
||||||
|
.setDescription('The cooldown in minutes'))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('name')
|
||||||
|
.setDescription('The game name')));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
if (!context.message.guild) return;
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
switch (context.args[0]) {
|
switch (interaction.options.getSubcommand()) {
|
||||||
case "config":
|
case "config":
|
||||||
await this.UseConfig(context);
|
await this.Configure(interaction);
|
||||||
|
break;
|
||||||
|
case "request":
|
||||||
|
await this.Request(interaction);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
await this.UseDefault(context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// =======
|
private async Request(interaction: CommandInteraction) {
|
||||||
// Default
|
if (!interaction.channelId) return;
|
||||||
// =======
|
|
||||||
|
|
||||||
private async UseDefault(context: ICommandContext) {
|
const lobby = await eLobby.FetchOneByChannelId(interaction.channelId);
|
||||||
const channel = context.message.channel as TextChannel;
|
|
||||||
const channelId = channel.id;
|
|
||||||
|
|
||||||
const lobby = await eLobby.FetchOneByChannelId(channelId);
|
|
||||||
|
|
||||||
if (!lobby) {
|
if (!lobby) {
|
||||||
this.SendDisabled(context);
|
await interaction.reply('This channel is disabled from using the lobby command.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,112 +74,91 @@ export default class Lobby extends Command {
|
||||||
|
|
||||||
// If it was less than x minutes ago
|
// If it was less than x minutes ago
|
||||||
if (lobby.LastUsed.getTime() > timeAgo) {
|
if (lobby.LastUsed.getTime() > timeAgo) {
|
||||||
this.SendOnCooldown(context, timeLength, new Date(timeNow), lobby.LastUsed);
|
const timeLeft = Math.ceil((timeLength - (timeNow - lobby.LastUsed.getTime())) / 1000 / 60);
|
||||||
|
|
||||||
|
await interaction.reply(`Requesting a lobby for this game is on cooldown! Please try again in **${timeLeft} minutes**.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.RequestLobby(context, lobby);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async RequestLobby(context: ICommandContext, lobby: eLobby) {
|
|
||||||
lobby.MarkAsUsed();
|
lobby.MarkAsUsed();
|
||||||
await lobby.Save(eLobby, lobby);
|
await lobby.Save(eLobby, lobby);
|
||||||
|
|
||||||
context.message.channel.send(`${context.message.author} would like to organise a lobby of **${lobby.Name}**! <@&${lobby.RoleId}>`);
|
await interaction.reply(`${interaction.user} would like to organise a lobby of **${lobby.Name}**! <@${lobby.RoleId}>`);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SendOnCooldown(context: ICommandContext, timeLength: number, timeNow: Date, timeUsed: Date) {
|
private async Configure(interaction: CommandInteraction) {
|
||||||
const timeLeft = Math.ceil((timeLength - (timeNow.getTime() - timeUsed.getTime())) / 1000 / 60);
|
if (!interaction.guildId) return;
|
||||||
|
if (!interaction.member) return;
|
||||||
|
|
||||||
context.message.reply(`Requesting a lobby for this game is on cooldown! Please try again in **${timeLeft} minutes**.`);
|
const moderatorRole = await SettingsHelper.GetSetting("role.moderator", interaction.guildId);
|
||||||
}
|
|
||||||
|
|
||||||
private SendDisabled(context: ICommandContext) {
|
const roleManager = interaction.member.roles as GuildMemberRoleManager;
|
||||||
context.message.reply("This channel hasn't been setup for lobbies.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// ======
|
|
||||||
// Config
|
|
||||||
// ======
|
|
||||||
private async UseConfig(context: ICommandContext) {
|
|
||||||
const moderatorRole = await SettingsHelper.GetSetting("role.moderator", context.message.guild!.id);
|
|
||||||
|
|
||||||
if (!context.message.member?.roles.cache.find(x => x.name == moderatorRole)) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "Sorry, you must be a moderator to be able to configure this command");
|
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
|
if (!roleManager.cache.find(x => x.name == moderatorRole)) {
|
||||||
|
await interaction.reply('Sorry, you must be a moderator to be able to configure this command.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (context.args[1]) {
|
const action = interaction.options.get('action');
|
||||||
|
|
||||||
|
if (!action || !action.value) {
|
||||||
|
await interaction.reply('Action is required.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (action.value) {
|
||||||
case "add":
|
case "add":
|
||||||
await this.AddLobbyConfig(context);
|
await this.AddLobbyConfig(interaction);
|
||||||
break;
|
break;
|
||||||
case "remove":
|
case "remove":
|
||||||
await this.RemoveLobbyConfig(context);
|
await this.RemoveLobbyConfig(interaction);
|
||||||
break;
|
break;
|
||||||
case "help":
|
|
||||||
default:
|
default:
|
||||||
await this.SendConfigHelp(context);
|
await interaction.reply('Action not found.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async SendConfigHelp(context: ICommandContext) {
|
private async AddLobbyConfig(interaction: CommandInteraction) {
|
||||||
const helpText = readFileSync(`${process.cwd()}/data/usage/lobby.txt`).toString();
|
const channel = interaction.options.get('channel');
|
||||||
|
const role = interaction.options.get('role');
|
||||||
const embed = new PublicEmbed(context, "Configure Lobby Command", helpText);
|
const cooldown = interaction.options.get('cooldown');
|
||||||
await embed.SendToCurrentChannel();
|
const gameName = interaction.options.get('name');
|
||||||
}
|
|
||||||
|
|
||||||
private async AddLobbyConfig(context: ICommandContext) {
|
|
||||||
const channel = context.message.guild!.channels.cache.find(x => x.id == context.args[2]);
|
|
||||||
const role = context.message.guild!.roles.cache.find(x => x.id == context.args[3]);
|
|
||||||
const cooldown = Number(context.args[4]) || 30;
|
|
||||||
const gameName = context.args.splice(5).join(" ");
|
|
||||||
|
|
||||||
if (!channel) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "The channel id you provided is invalid or channel does not exist.");
|
|
||||||
errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
|
if (!channel || !channel.channel || !role || !role.role || !cooldown || !cooldown.value || !gameName || !gameName.value) {
|
||||||
|
await interaction.reply('Fields are required.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!role) {
|
const lobby = await eLobby.FetchOneByChannelId(channel.channel.id);
|
||||||
const errorEmbed = new ErrorEmbed(context, "The role id you provided is invalid or role does not exist.");
|
|
||||||
errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const lobby = await eLobby.FetchOneByChannelId(channel.id);
|
|
||||||
|
|
||||||
if (lobby) {
|
if (lobby) {
|
||||||
const errorEmbed = new ErrorEmbed(context, "This channel has already been setup.");
|
await interaction.reply('This channel has already been setup.');
|
||||||
errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const entity = new eLobby(channel.id, role.id, cooldown, gameName);
|
const entity = new eLobby(channel.channel.id, role.role.id, cooldown.value as number, gameName.value as string);
|
||||||
await entity.Save(eLobby, entity);
|
await entity.Save(eLobby, entity);
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", `Added \`${channel.name}\` as a new lobby channel with a cooldown of \`${cooldown} minutes\` and will ping \`${role.name}\` on use`);
|
await interaction.reply(`Added \`${channel.name}\` as a new lobby channel with a cooldown of \`${cooldown} minutes \` and will ping \`${role.name}\` on use`);
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async RemoveLobbyConfig(context: ICommandContext) {
|
private async RemoveLobbyConfig(interaraction: CommandInteraction) {
|
||||||
const entity = await eLobby.FetchOneByChannelId(context.args[2]);
|
const channel = interaraction.options.get('channel');
|
||||||
|
|
||||||
|
if (!channel || !channel.channel) {
|
||||||
|
await interaraction.reply('Channel is required.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const entity = await eLobby.FetchOneByChannelId(channel.channel.id);
|
||||||
|
|
||||||
if (!entity) {
|
if (!entity) {
|
||||||
const errorEmbed = new ErrorEmbed(context, "The channel id you provided has not been setup as a lobby, unable to remove.");
|
await interaraction.reply('Channel not found.');
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await BaseEntity.Remove<eLobby>(eLobby, entity);
|
await BaseEntity.Remove<eLobby>(eLobby, entity);
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", `Removed <#${context.args[2]}> from the list of lobby channels`);
|
await interaraction.reply(`Removed <#${channel.channel.name}> from the list of lobby channels`);
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,23 +1,39 @@
|
||||||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
|
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, EmbedBuilder, Interaction, SlashCommandBuilder } from "discord.js";
|
||||||
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { ICommandContext } from "../contracts/ICommandContext";
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
|
|
||||||
export default class About extends Command {
|
export default class About extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
super.Category = "General";
|
super.Category = "General";
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName('about')
|
||||||
|
.setDescription('About VylBot');
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
const fundingLink = process.env.ABOUT_FUNDING;
|
const fundingLink = process.env.ABOUT_FUNDING;
|
||||||
const repoLink = process.env.ABOUT_REPO;
|
const repoLink = process.env.ABOUT_REPO;
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "About", "Discord Bot made by Vylpes");
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle("About")
|
||||||
|
.setDescription("Discord Bot made by Vylpes");
|
||||||
|
|
||||||
embed.AddField("Version", process.env.BOT_VER!, true);
|
embed.addFields([
|
||||||
embed.AddField("Author", process.env.BOT_AUTHOR!, true);
|
{
|
||||||
embed.AddField("Date", process.env.BOT_DATE!, true);
|
name: "Version",
|
||||||
|
value: process.env.BOT_VER!,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Author",
|
||||||
|
value: process.env.BOT_AUTHOR!,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
const row = new ActionRowBuilder<ButtonBuilder>();
|
const row = new ActionRowBuilder<ButtonBuilder>();
|
||||||
|
|
||||||
|
@ -37,6 +53,6 @@ export default class About extends Command {
|
||||||
.setStyle(ButtonStyle.Link));
|
.setStyle(ButtonStyle.Link));
|
||||||
}
|
}
|
||||||
|
|
||||||
await embed.SendToCurrentChannel({ components: [ row ] });
|
await interaction.reply({ embeds: [ embed ]});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,10 +1,11 @@
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { ICommandContext } from "../contracts/ICommandContext";
|
||||||
import Audit from "../entity/Audit";
|
import Audit from "../entity/Audit";
|
||||||
import AuditTools from "../helpers/AuditTools";
|
import AuditTools from "../helpers/AuditTools";
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
import SettingsHelper from "../helpers/SettingsHelper";
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
import { CommandInteraction, EmbedBuilder, SlashCommandBuilder } from "discord.js";
|
||||||
|
import { AuditType } from "../constants/AuditType";
|
||||||
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
|
|
||||||
export default class Audits extends Command {
|
export default class Audits extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -14,131 +15,203 @@ export default class Audits extends Command {
|
||||||
super.Roles = [
|
super.Roles = [
|
||||||
"moderator"
|
"moderator"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName("audits")
|
||||||
|
.setDescription("View audits of a particular user in the server")
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('user')
|
||||||
|
.setDescription('View all audits done against a user')
|
||||||
|
.addUserOption(option =>
|
||||||
|
option
|
||||||
|
.setName('target')
|
||||||
|
.setDescription('The user')
|
||||||
|
.setRequired(true)))
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('view')
|
||||||
|
.setDescription('View a particular audit')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('auditid')
|
||||||
|
.setDescription('The audit id in caps')
|
||||||
|
.setRequired(true)))
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('clear')
|
||||||
|
.setDescription('Clears an audit from a user')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('auditid')
|
||||||
|
.setDescription('The audit id in caps')
|
||||||
|
.setRequired(true)))
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('add')
|
||||||
|
.setDescription('Manually add an audit')
|
||||||
|
.addUserOption(option =>
|
||||||
|
option
|
||||||
|
.setName('target')
|
||||||
|
.setDescription('The user')
|
||||||
|
.setRequired(true))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('type')
|
||||||
|
.setDescription('The type of audit')
|
||||||
|
.setRequired(true)
|
||||||
|
.addChoices(
|
||||||
|
{ name: 'General', value: AuditType.General.toString() },
|
||||||
|
{ name: 'Warn', value: AuditType.Warn.toString() },
|
||||||
|
{ name: 'Mute', value: AuditType.Mute.toString() },
|
||||||
|
{ name: 'Kick', value: AuditType.Kick.toString() },
|
||||||
|
{ name: 'Ban', value: AuditType.Ban.toString() },
|
||||||
|
))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('reason')
|
||||||
|
.setDescription('The reason')));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
if (!context.message.guild) return;
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
switch (context.args[0]) {
|
switch (interaction.options.getSubcommand()) {
|
||||||
case "user":
|
case "user":
|
||||||
await this.SendAuditForUser(context);
|
await this.SendAuditForUser(interaction);
|
||||||
break;
|
break;
|
||||||
case "view":
|
case "view":
|
||||||
await this.SendAudit(context);
|
await this.SendAudit(interaction);
|
||||||
break;
|
break;
|
||||||
case "clear":
|
case "clear":
|
||||||
await this.ClearAudit(context);
|
await this.ClearAudit(interaction);
|
||||||
break;
|
break;
|
||||||
case "add":
|
case "add":
|
||||||
await this.AddAudit(context);
|
await this.AddAudit(interaction);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
await this.SendUsage(context);
|
await interaction.reply("Subcommand doesn't exist.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async SendUsage(context: ICommandContext) {
|
private async SendAuditForUser(interaction: CommandInteraction) {
|
||||||
const prefix = await SettingsHelper.GetServerPrefix(context.message.guild!.id);
|
if (!interaction.guildId) return;
|
||||||
|
|
||||||
const description = [
|
const user = interaction.options.getUser('target');
|
||||||
`\`${prefix}audits user <id>\` - Send the audits for this user`,
|
|
||||||
`\`${prefix}audits view <id>\` - Send information about an audit`,
|
|
||||||
`\`${prefix}audits clear <id>\` - Clears an audit for a user by audit id`,
|
|
||||||
`\`${prefix}audits add <userid> <type> [reason]\` - Manually add an audit for a user`,
|
|
||||||
]
|
|
||||||
|
|
||||||
const publicEmbed = new PublicEmbed(context, "Usage", description.join("\n"));
|
if (!user) {
|
||||||
await publicEmbed.SendToCurrentChannel();
|
await interaction.reply("User not found.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async SendAuditForUser(context: ICommandContext) {
|
const audits = await Audit.FetchAuditsByUserId(user.id, interaction.guildId);
|
||||||
const userId = context.args[1];
|
|
||||||
|
|
||||||
const audits = await Audit.FetchAuditsByUserId(userId, context.message.guild!.id);
|
|
||||||
|
|
||||||
if (!audits || audits.length == 0) {
|
if (!audits || audits.length == 0) {
|
||||||
const publicEmbed = new PublicEmbed(context, "Audits", "There are no audits logged for this user.");
|
await interaction.reply("There are no audits for this user.");
|
||||||
await publicEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const publicEmbed = new PublicEmbed(context, "Audit Log", `Audits: ${audits.length}`);
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle("Audits")
|
||||||
|
.setDescription(`Audits: ${audits.length}`);
|
||||||
|
|
||||||
for (let audit of audits) {
|
for (let audit of audits) {
|
||||||
publicEmbed.AddField(`${audit.AuditId} // ${AuditTools.TypeToFriendlyText(audit.AuditType)}`, audit.WhenCreated.toString());
|
embed.addFields([
|
||||||
|
{
|
||||||
|
name: `${audit.AuditId} // ${AuditTools.TypeToFriendlyText(audit.AuditType)}`,
|
||||||
|
value: audit.WhenCreated.toString(),
|
||||||
|
}
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
await publicEmbed.SendToCurrentChannel();
|
await interaction.reply({ embeds: [ embed ]});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async SendAudit(context: ICommandContext) {
|
private async SendAudit(interaction: CommandInteraction) {
|
||||||
const auditId = context.args[1];
|
if (!interaction.guildId) return;
|
||||||
|
|
||||||
if (!auditId) {
|
const auditId = interaction.options.get('auditid');
|
||||||
await this.SendUsage(context);
|
|
||||||
|
if (!auditId || !auditId.value) {
|
||||||
|
await interaction.reply("AuditId not found.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const audit = await Audit.FetchAuditByAuditId(auditId.toUpperCase(), context.message.guild!.id);
|
const audit = await Audit.FetchAuditByAuditId(auditId.value.toString().toUpperCase(), interaction.guildId);
|
||||||
|
|
||||||
if (!audit) {
|
if (!audit) {
|
||||||
const errorEmbed = new ErrorEmbed(context, "This audit can not be found.");
|
await interaction.reply("Audit not found.");
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const publicEmbed = new PublicEmbed(context, "Audit", audit.AuditId.toUpperCase());
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle("Audit")
|
||||||
|
.setDescription(audit.AuditId.toUpperCase())
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: "Reason",
|
||||||
|
value: audit.Reason || "*none*",
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Type",
|
||||||
|
value: AuditTools.TypeToFriendlyText(audit.AuditType),
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Moderator",
|
||||||
|
value: `<@${audit.ModeratorId}>`,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
publicEmbed.AddField("Reason", audit.Reason || "*none*", true);
|
await interaction.reply({ embeds: [ embed ]});
|
||||||
publicEmbed.AddField("Type", AuditTools.TypeToFriendlyText(audit.AuditType), true);
|
|
||||||
publicEmbed.AddField("Moderator", `<@${audit.ModeratorId}>`, true);
|
|
||||||
|
|
||||||
await publicEmbed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async ClearAudit(context: ICommandContext) {
|
private async ClearAudit(interaction: CommandInteraction) {
|
||||||
const auditId = context.args[1];
|
if (!interaction.guildId) return;
|
||||||
|
|
||||||
if (!auditId) {
|
const auditId = interaction.options.get('auditid');
|
||||||
await this.SendUsage(context);
|
|
||||||
|
if (!auditId || !auditId.value) {
|
||||||
|
await interaction.reply("AuditId not found.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const audit = await Audit.FetchAuditByAuditId(auditId.toUpperCase(), context.message.guild!.id);
|
const audit = await Audit.FetchAuditByAuditId(auditId.value.toString().toUpperCase(), interaction.guildId);
|
||||||
|
|
||||||
if (!audit) {
|
if (!audit) {
|
||||||
const errorEmbed = new ErrorEmbed(context, "This audit can not be found.");
|
await interaction.reply("Audit not found.");
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Audit.Remove(Audit, audit);
|
await Audit.Remove(Audit, audit);
|
||||||
|
|
||||||
const publicEmbed = new PublicEmbed(context, "Audit", "Audit cleared");
|
await interaction.reply("Audit cleared.");
|
||||||
await publicEmbed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async AddAudit(context: ICommandContext) {
|
private async AddAudit(interaction: CommandInteraction) {
|
||||||
const userId = context.args[1];
|
if (!interaction.guildId) return;
|
||||||
const typeString = context.args[2];
|
|
||||||
const reason = context.args.splice(3)
|
|
||||||
.join(" ");
|
|
||||||
|
|
||||||
if (!userId || !typeString) {
|
const user = interaction.options.getUser('target');
|
||||||
await this.SendUsage(context);
|
const auditType = interaction.options.get('type');
|
||||||
|
const reasonInput = interaction.options.get('reason');
|
||||||
|
|
||||||
|
if (!user || !auditType || !auditType.value) {
|
||||||
|
await interaction.reply("Invalid input.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const type = AuditTools.StringToType(typeString);
|
const type = auditType.value as AuditType;
|
||||||
|
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : "";
|
||||||
|
|
||||||
const audit = new Audit(userId, type, reason, context.message.author.id, context.message.guild!.id);
|
const audit = new Audit(user.id, type, reason, interaction.user.id, interaction.guildId);
|
||||||
|
|
||||||
await audit.Save(Audit, audit);
|
await audit.Save(Audit, audit);
|
||||||
|
|
||||||
const publicEmbed = new PublicEmbed(context, "Audit", `Created new audit with ID \`${audit.AuditId}\``);
|
await interaction.reply(`Created new audit with ID \`${audit.AuditId}\``);
|
||||||
await publicEmbed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,11 +1,11 @@
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
||||||
import ErrorMessages from "../constants/ErrorMessages";
|
import ErrorMessages from "../constants/ErrorMessages";
|
||||||
import LogEmbed from "../helpers/embeds/LogEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { ICommandContext } from "../contracts/ICommandContext";
|
||||||
import Audit from "../entity/Audit";
|
import Audit from "../entity/Audit";
|
||||||
import { AuditType } from "../constants/AuditType";
|
import { AuditType } from "../constants/AuditType";
|
||||||
|
import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
|
||||||
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
|
|
||||||
export default class Ban extends Command {
|
export default class Ban extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -15,57 +15,67 @@ export default class Ban extends Command {
|
||||||
super.Roles = [
|
super.Roles = [
|
||||||
"moderator"
|
"moderator"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName("ban")
|
||||||
|
.setDescription("Ban a member from the server with an optional reason")
|
||||||
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.BanMembers)
|
||||||
|
.addUserOption(option =>
|
||||||
|
option
|
||||||
|
.setName('target')
|
||||||
|
.setDescription('The user')
|
||||||
|
.setRequired(true))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('reason')
|
||||||
|
.setDescription('The reason'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
const targetUser = context.message.mentions.users.first();
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
if (!interaction.guildId) return;
|
||||||
|
if (!interaction.guild) return;
|
||||||
|
|
||||||
if (!targetUser) {
|
const targetUser = interaction.options.get('target');
|
||||||
const embed = new ErrorEmbed(context, "User does not exist");
|
const reasonInput = interaction.options.get('reason');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
|
if (!targetUser || !targetUser.user || !targetUser.member) {
|
||||||
|
await interaction.reply("User not found.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetMember = context.message.guild?.members.cache.find(x => x.user.id == targetUser.id);
|
const member = targetUser.member as GuildMember;
|
||||||
|
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : "*none*";
|
||||||
|
|
||||||
if (!targetMember) {
|
const logEmbed = new EmbedBuilder()
|
||||||
const embed = new ErrorEmbed(context, "User is not in this server");
|
.setColor(EmbedColours.Ok)
|
||||||
await embed.SendToCurrentChannel();
|
.setTitle("Member Banned")
|
||||||
|
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: "Moderator",
|
||||||
|
value: `<@${interaction.user.id}>`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Reason",
|
||||||
|
value: reason,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
return;
|
await member.ban();
|
||||||
|
await interaction.reply(`\`${targetUser.user.tag}\` has been banned.`);
|
||||||
|
|
||||||
|
const channelName = await SettingsHelper.GetSetting('channels.logs.mod', interaction.guildId);
|
||||||
|
|
||||||
|
if (!channelName) return;
|
||||||
|
|
||||||
|
const channel = interaction.guild.channels.cache.find(x => x.name == channelName) as TextChannel;
|
||||||
|
|
||||||
|
if (channel) {
|
||||||
|
await channel.send({ embeds: [ logEmbed ]});
|
||||||
}
|
}
|
||||||
|
|
||||||
const reasonArgs = context.args;
|
const audit = new Audit(targetUser.user.id, AuditType.Ban, reason, interaction.user.id, interaction.guildId);
|
||||||
reasonArgs.splice(0, 1)
|
|
||||||
|
|
||||||
const reason = reasonArgs.join(" ");
|
|
||||||
|
|
||||||
if (!context.message.guild?.available) return;
|
|
||||||
|
|
||||||
if (!targetMember.bannable) {
|
|
||||||
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const logEmbed = new LogEmbed(context, "Member Banned");
|
|
||||||
logEmbed.AddUser("User", targetUser, true);
|
|
||||||
logEmbed.AddUser("Moderator", context.message.author);
|
|
||||||
logEmbed.AddReason(reason);
|
|
||||||
|
|
||||||
const publicEmbed = new PublicEmbed(context, "", `${targetUser} has been banned`);
|
|
||||||
|
|
||||||
await targetMember.ban({ reason: `Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}` });
|
|
||||||
|
|
||||||
await logEmbed.SendToModLogsChannel();
|
|
||||||
await publicEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
if (context.message.guild) {
|
|
||||||
const audit = new Audit(targetUser.id, AuditType.Ban, reason, context.message.author.id, context.message.guild.id);
|
|
||||||
|
|
||||||
await audit.Save(Audit, audit);
|
await audit.Save(Audit, audit);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,17 +1,23 @@
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { ICommandContext } from "../contracts/ICommandContext";
|
||||||
import randomBunny from "random-bunny";
|
import randomBunny from "random-bunny";
|
||||||
|
import { CommandInteraction, EmbedBuilder, SlashCommandBuilder } from "discord.js";
|
||||||
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
|
|
||||||
export default class Bunny extends Command {
|
export default class Bunny extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.Category = "Fun";
|
super.Category = "Fun";
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName("bunny")
|
||||||
|
.setDescription("Get a random picture of a rabbit.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
const subreddits = [
|
const subreddits = [
|
||||||
'rabbits',
|
'rabbits',
|
||||||
'bunnieswithhats',
|
'bunnieswithhats',
|
||||||
|
@ -26,16 +32,17 @@ export default class Bunny extends Command {
|
||||||
const result = await randomBunny(selectedSubreddit, 'hot');
|
const result = await randomBunny(selectedSubreddit, 'hot');
|
||||||
|
|
||||||
if (result.IsSuccess) {
|
if (result.IsSuccess) {
|
||||||
const embed = new PublicEmbed(context, result.Result!.Title, "");
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle(result.Result!.Title)
|
||||||
|
.setDescription(result.Result!.Permalink)
|
||||||
|
.setImage(result.Result!.Url)
|
||||||
|
.setURL(`https://reddit.com${result.Result!.Permalink}`)
|
||||||
|
.setFooter({ text: `r/${selectedSubreddit} · ${result.Result!.Ups} upvotes`});
|
||||||
|
|
||||||
embed.SetImage(result.Result!.Url)
|
await interaction.reply({ embeds: [ embed ]});
|
||||||
embed.SetURL(`https://reddit.com${result.Result!.Permalink}`)
|
|
||||||
embed.SetFooter(`r/${selectedSubreddit} · ${result.Result!.Ups} upvotes`);
|
|
||||||
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
} else {
|
} else {
|
||||||
const errorEmbed = new ErrorEmbed(context, "There was an error using this command.");
|
await interaction.reply("There was an error running this command.");
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,4 @@
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
import { CommandInteraction, SlashCommandBuilder, TextChannel } from "discord.js";
|
||||||
import { TextChannel } from "discord.js";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { ICommandContext } from "../contracts/ICommandContext";
|
||||||
|
|
||||||
|
@ -12,28 +10,31 @@ export default class Clear extends Command {
|
||||||
super.Roles = [
|
super.Roles = [
|
||||||
"moderator"
|
"moderator"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName("clear")
|
||||||
|
.setDescription("Clears the channel of messages")
|
||||||
|
.addNumberOption(option =>
|
||||||
|
option
|
||||||
|
.setName('count')
|
||||||
|
.setDescription('The amount to delete')
|
||||||
|
.setMinValue(1)
|
||||||
|
.setMaxValue(100));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
if (context.args.length == 0) {
|
if (!interaction.isChatInputCommand()) return;
|
||||||
const errorEmbed = new ErrorEmbed(context, "Please specify an amount between 1 and 100");
|
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
const totalToClear = interaction.options.getNumber('count');
|
||||||
}
|
|
||||||
|
|
||||||
const totalToClear = Number.parseInt(context.args[0]);
|
|
||||||
|
|
||||||
if (!totalToClear || totalToClear <= 0 || totalToClear > 100) {
|
if (!totalToClear || totalToClear <= 0 || totalToClear > 100) {
|
||||||
const errorEmbed = new ErrorEmbed(context, "Please specify an amount between 1 and 100");
|
await interaction.reply('Please specify an amount between 1 and 100.');
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await (context.message.channel as TextChannel).bulkDelete(totalToClear);
|
const channel = interaction.channel as TextChannel;
|
||||||
|
await channel.bulkDelete(totalToClear);
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", `${totalToClear} message(s) were removed`);
|
await interaction.reply(`${totalToClear} message(s) were removed.`);
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
|
import { CommandInteraction, EmbedBuilder, SlashCommandBuilder, SlashCommandSubcommandBuilder } from "discord.js";
|
||||||
import { CommandResponse } from "../constants/CommandResponse";
|
import { CommandResponse } from "../constants/CommandResponse";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { ICommandContext } from "../contracts/ICommandContext";
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import SettingsHelper from "../helpers/SettingsHelper";
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
import StringTools from "../helpers/StringTools";
|
import StringTools from "../helpers/StringTools";
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
|
@ -14,14 +13,25 @@ export default class Code extends Command {
|
||||||
super.Roles = [
|
super.Roles = [
|
||||||
"moderator"
|
"moderator"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName('code')
|
||||||
|
.setDescription('Manage the verification code of the server')
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('randomise')
|
||||||
|
.setDescription('Regenerates the verification code for this server'))
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('embed')
|
||||||
|
.setDescription('Sends the embed with the current code to the current channel'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async precheckAsync(context: ICommandContext): Promise<CommandResponse> {
|
public override async precheckAsync(interaction: CommandInteraction): Promise<CommandResponse> {
|
||||||
if (!context.message.guild){
|
if (!interaction.isChatInputCommand()) return CommandResponse.NotInServer;
|
||||||
return CommandResponse.NotInServer;
|
if (!interaction.guild || !interaction.guildId) return CommandResponse.NotInServer;
|
||||||
}
|
|
||||||
|
|
||||||
const isEnabled = await SettingsHelper.GetSetting("verification.enabled", context.message.guild?.id);
|
const isEnabled = await SettingsHelper.GetSetting("verification.enabled", interaction.guildId);
|
||||||
|
|
||||||
if (!isEnabled) {
|
if (!isEnabled) {
|
||||||
return CommandResponse.FeatureDisabled;
|
return CommandResponse.FeatureDisabled;
|
||||||
|
@ -34,61 +44,44 @@ export default class Code extends Command {
|
||||||
return CommandResponse.Ok;
|
return CommandResponse.Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
const action = context.args[0];
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
switch (action) {
|
switch (interaction.options.getSubcommand()) {
|
||||||
case "randomise":
|
case "randomise":
|
||||||
await this.Randomise(context);
|
await this.Randomise(interaction);
|
||||||
break;
|
break;
|
||||||
case "embed":
|
case "embed":
|
||||||
await this.SendEmbed(context);
|
await this.SendEmbed(interaction);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
await this.SendUsage(context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async SendUsage(context: ICommandContext) {
|
private async Randomise(interaction: CommandInteraction) {
|
||||||
const description = [
|
if (!interaction.guildId) return;
|
||||||
"USAGE: <randomise|embed>",
|
|
||||||
"",
|
|
||||||
"randomise: Sets the server's entry code to a random code",
|
|
||||||
"embed: Sends an embed with the server's entry code"
|
|
||||||
].join("\n");
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", description);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Randomise(context: ICommandContext) {
|
|
||||||
if (!context.message.guild) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const randomCode = StringTools.RandomString(5);
|
const randomCode = StringTools.RandomString(5);
|
||||||
|
|
||||||
await SettingsHelper.SetSetting("verification.code", context.message.guild.id, randomCode);
|
await SettingsHelper.SetSetting("verification.code", interaction.guildId, randomCode);
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "Code", `Entry code has been set to \`${randomCode}\``);
|
await interaction.reply(`Entry code has been set to \`${randomCode}\``);
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async SendEmbed(context: ICommandContext) {
|
private async SendEmbed(interaction: CommandInteraction) {
|
||||||
if (!context.message.guild) {
|
if (!interaction.guildId) return;
|
||||||
return;
|
if (!interaction.channel) return;
|
||||||
}
|
|
||||||
|
|
||||||
const code = await SettingsHelper.GetSetting("verification.code", context.message.guild.id);
|
const code = await SettingsHelper.GetSetting("verification.code", interaction.guildId);
|
||||||
|
|
||||||
if (!code || code == "") {
|
if (!code || code == "") {
|
||||||
const errorEmbed = new ErrorEmbed(context, "There is no code for this server setup.");
|
await interaction.reply("There is no code for this server setup.");
|
||||||
errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "Entry Code", code!);
|
const embed = new EmbedBuilder()
|
||||||
await embed.SendToCurrentChannel();
|
.setTitle("Entry Code")
|
||||||
|
.setDescription(code);
|
||||||
|
|
||||||
|
await interaction.channel.send({ embeds: [ embed ]});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,11 +1,11 @@
|
||||||
|
import { CommandInteraction, EmbedBuilder, SlashCommandBuilder } from "discord.js";
|
||||||
import { readFileSync } from "fs";
|
import { readFileSync } from "fs";
|
||||||
import { CommandResponse } from "../constants/CommandResponse";
|
import { CommandResponse } from "../constants/CommandResponse";
|
||||||
import DefaultValues from "../constants/DefaultValues";
|
import DefaultValues from "../constants/DefaultValues";
|
||||||
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { ICommandContext } from "../contracts/ICommandContext";
|
||||||
import Server from "../entity/Server";
|
import Server from "../entity/Server";
|
||||||
import Setting from "../entity/Setting";
|
import Setting from "../entity/Setting";
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
|
|
||||||
export default class Config extends Command {
|
export default class Config extends Command {
|
||||||
|
@ -15,14 +15,48 @@ export default class Config extends Command {
|
||||||
super.Roles = [
|
super.Roles = [
|
||||||
"administrator"
|
"administrator"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName('config')
|
||||||
|
.setDescription('Configure the current server')
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('reset')
|
||||||
|
.setDescription('Reset a setting to the default')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('key')
|
||||||
|
.setDescription('The key')))
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('get')
|
||||||
|
.setDescription('Gets a setting for the server')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('key')
|
||||||
|
.setDescription('The key')))
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('set')
|
||||||
|
.setDescription('Sets a setting to a specified value')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('key')
|
||||||
|
.setDescription('The key'))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('value')
|
||||||
|
.setDescription('The value')))
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('list')
|
||||||
|
.setDescription('Lists all settings'))
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async precheckAsync(context: ICommandContext): Promise<CommandResponse> {
|
public override async precheckAsync(interaction: CommandInteraction): Promise<CommandResponse> {
|
||||||
if (!context.message.guild) {
|
if (!interaction.guildId) return CommandResponse.ServerNotSetup;
|
||||||
return CommandResponse.ServerNotSetup;
|
|
||||||
}
|
|
||||||
|
|
||||||
const server = await Server.FetchOneById<Server>(Server, context.message.guild?.id, [
|
const server = await Server.FetchOneById<Server>(Server, interaction.guildId, [
|
||||||
"Settings",
|
"Settings",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -33,94 +67,125 @@ export default class Config extends Command {
|
||||||
return CommandResponse.Ok;
|
return CommandResponse.Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
if (!context.message.guild) {
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
|
switch (interaction.options.getSubcommand()) {
|
||||||
|
case 'list':
|
||||||
|
await this.SendHelpText(interaction);
|
||||||
|
break;
|
||||||
|
case 'reset':
|
||||||
|
await this.ResetValue(interaction);
|
||||||
|
break;
|
||||||
|
case 'get':
|
||||||
|
await this.GetValue(interaction);
|
||||||
|
break;
|
||||||
|
case 'set':
|
||||||
|
await this.SetValue(interaction);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
await interaction.reply('Subcommand not found.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async SendHelpText(interaction: CommandInteraction) {
|
||||||
|
const description = readFileSync(`${process.cwd()}/data/usage/config.txt`).toString();
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle("Config")
|
||||||
|
.setDescription(description);
|
||||||
|
|
||||||
|
await interaction.reply({ embeds: [ embed ]});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async GetValue(interaction: CommandInteraction) {
|
||||||
|
if (!interaction.guildId) return;
|
||||||
|
|
||||||
|
const key = interaction.options.get('key');
|
||||||
|
|
||||||
|
if (!key || !key.value) {
|
||||||
|
await interaction.reply('Fields are required.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const server = await Server.FetchOneById<Server>(Server, context.message.guild?.id, [
|
const server = await Server.FetchOneById<Server>(Server, interaction.guildId, [
|
||||||
"Settings",
|
"Settings",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!server) {
|
if (!server) {
|
||||||
|
await interaction.reply('Server not found.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const key = context.args[0];
|
const setting = server.Settings.filter(x => x.Key == key.value)[0];
|
||||||
const action = context.args[1];
|
|
||||||
const value = context.args.splice(2).join(" ");
|
|
||||||
|
|
||||||
if (!key) {
|
|
||||||
this.SendHelpText(context);
|
|
||||||
} else if (!action) {
|
|
||||||
this.GetValue(context, server, key);
|
|
||||||
} else {
|
|
||||||
switch(action) {
|
|
||||||
case 'reset':
|
|
||||||
this.ResetValue(context, server, key);
|
|
||||||
break;
|
|
||||||
case 'set':
|
|
||||||
if (!value) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "Value is required when setting");
|
|
||||||
errorEmbed.SendToCurrentChannel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.SetValue(context, server, key, value);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "Action must be either set or reset");
|
|
||||||
errorEmbed.SendToCurrentChannel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async SendHelpText(context: ICommandContext) {
|
|
||||||
const description = readFileSync(`${process.cwd()}/data/usage/config.txt`).toString();
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "Config", description);
|
|
||||||
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async GetValue(context: ICommandContext, server: Server, key: string) {
|
|
||||||
const setting = server.Settings.filter(x => x.Key == key)[0];
|
|
||||||
|
|
||||||
if (setting) {
|
if (setting) {
|
||||||
const embed = new PublicEmbed(context, "", `${key}: ${setting.Value}`);
|
await interaction.reply(`\`${key}\`: \`${setting.Value}\``);
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
} else {
|
} else {
|
||||||
const embed = new PublicEmbed(context, "", `${key}: ${DefaultValues.GetValue(key)} <DEFAULT>`);
|
await interaction.reply(`\`${key}\`: \`${DefaultValues.GetValue(key.value.toString())}\` <DEFAULT>`);
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async ResetValue(context: ICommandContext, server: Server, key: string) {
|
private async ResetValue(interaction: CommandInteraction) {
|
||||||
const setting = server.Settings.filter(x => x.Key == key)[0];
|
if (!interaction.guildId) return;
|
||||||
|
|
||||||
|
const key = interaction.options.get('key');
|
||||||
|
|
||||||
|
if (!key || !key.value) {
|
||||||
|
await interaction.reply('Fields are required.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const server = await Server.FetchOneById<Server>(Server, interaction.guildId, [
|
||||||
|
"Settings",
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!server) {
|
||||||
|
await interaction.reply('Server not found.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const setting = server.Settings.filter(x => x.Key == key.value)[0];
|
||||||
|
|
||||||
if (!setting) {
|
if (!setting) {
|
||||||
const embed = new PublicEmbed(context, "", "Setting has been reset");
|
await interaction.reply('Setting not found.');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Setting.Remove(Setting, setting);
|
await Setting.Remove(Setting, setting);
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", "Setting has been reset");
|
await interaction.reply('The setting has been reset to the default.');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async SetValue(context: ICommandContext, server: Server, key: string, value: string) {
|
private async SetValue(interaction: CommandInteraction) {
|
||||||
const setting = server.Settings.filter(x => x.Key == key)[0];
|
if (!interaction.guildId) return;
|
||||||
|
|
||||||
|
const key = interaction.options.get('key');
|
||||||
|
const value = interaction.options.get('value');
|
||||||
|
|
||||||
|
if (!key || !key.value || !value || !value.value) {
|
||||||
|
await interaction.reply('Fields are required.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const server = await Server.FetchOneById<Server>(Server, interaction.guildId, [
|
||||||
|
"Settings",
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!server) {
|
||||||
|
await interaction.reply('Server not found.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const setting = server.Settings.filter(x => x.Key == key.value)[0];
|
||||||
|
|
||||||
if (setting) {
|
if (setting) {
|
||||||
setting.UpdateBasicDetails(key, value);
|
setting.UpdateBasicDetails(key.value.toString(), value.value.toString());
|
||||||
|
|
||||||
await setting.Save(Setting, setting);
|
await setting.Save(Setting, setting);
|
||||||
} else {
|
} else {
|
||||||
const newSetting = new Setting(key, value);
|
const newSetting = new Setting(key.value.toString(), value.value.toString());
|
||||||
|
|
||||||
await newSetting.Save(Setting, newSetting);
|
await newSetting.Save(Setting, newSetting);
|
||||||
|
|
||||||
|
@ -129,7 +194,6 @@ export default class Config extends Command {
|
||||||
await server.Save(Server, server);
|
await server.Save(Server, server);
|
||||||
}
|
}
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", "Setting has been set");
|
await interaction.reply('Setting has been set.');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
|
import { CommandInteraction, SlashCommandBuilder } from "discord.js";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { ICommandContext } from "../contracts/ICommandContext";
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import SettingsHelper from "../helpers/SettingsHelper";
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
|
|
||||||
|
@ -11,83 +11,86 @@ export default class Disable extends Command {
|
||||||
super.Roles = [
|
super.Roles = [
|
||||||
"moderator"
|
"moderator"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName('disable')
|
||||||
|
.setDescription('Disables a command')
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('add')
|
||||||
|
.setDescription('Disables a command for the server')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('name')
|
||||||
|
.setDescription('The name of the command')
|
||||||
|
.setRequired(true)))
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('remove')
|
||||||
|
.setDescription('Enables a command for the server')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('name')
|
||||||
|
.setDescription('The name of the command')
|
||||||
|
.setRequired(true)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
const action = context.args[0];
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
switch (action) {
|
switch (interaction.options.getSubcommand()) {
|
||||||
case "add":
|
case "add":
|
||||||
await this.Add(context);
|
await this.Add(interaction);
|
||||||
break;
|
break;
|
||||||
case "remove":
|
case "remove":
|
||||||
await this.Remove(context);
|
await this.Remove(interaction);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
await this.SendUsage(context);
|
await interaction.reply('Subcommand not found.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async SendUsage(context: ICommandContext) {
|
private async Add(interaction: CommandInteraction) {
|
||||||
const description = [
|
if (!interaction.guildId) return;
|
||||||
"USAGE: <add|remove> <name>",
|
|
||||||
"",
|
|
||||||
"add: Adds the command name to the server's disabled command string",
|
|
||||||
"remove: Removes the command name from the server's disabled command string",
|
|
||||||
"name: The name of the command to enable/disable"
|
|
||||||
].join("\n");
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", description);
|
const commandName = interaction.options.get('name');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Add(context: ICommandContext) {
|
if (!commandName || !commandName.value) {
|
||||||
if (!context.message.guild) {
|
await interaction.reply('Fields are required.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const commandName = context.args[1];
|
const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", interaction.guildId);
|
||||||
|
|
||||||
if (!commandName) {
|
|
||||||
this.SendUsage(context);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", context.message.guild.id);
|
|
||||||
const disabledCommands = disabledCommandsString != "" ? disabledCommandsString?.split(",") : [];
|
const disabledCommands = disabledCommandsString != "" ? disabledCommandsString?.split(",") : [];
|
||||||
|
|
||||||
disabledCommands?.push(commandName);
|
disabledCommands?.push(commandName.value.toString());
|
||||||
|
|
||||||
await SettingsHelper.SetSetting("commands.disabled", context.message.guild.id, disabledCommands!.join(","));
|
await SettingsHelper.SetSetting("commands.disabled", interaction.guildId, disabledCommands!.join(","));
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", `Disabled command: ${commandName}`);
|
await interaction.reply(`Disabled command ${commandName.value}`);
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Remove(context: ICommandContext) {
|
private async Remove(interaction: CommandInteraction) {
|
||||||
if (!context.message.guild) {
|
if (!interaction.guildId) return;
|
||||||
|
|
||||||
|
const commandName = interaction.options.get('name');
|
||||||
|
|
||||||
|
if (!commandName || !commandName.value) {
|
||||||
|
await interaction.reply('Fields are required.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const commandName = context.args[1];
|
const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", interaction.guildId);
|
||||||
|
|
||||||
if (!commandName) {
|
|
||||||
this.SendUsage(context);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", context.message.guild.id);
|
|
||||||
const disabledCommands = disabledCommandsString != "" ? disabledCommandsString?.split(",") : [];
|
const disabledCommands = disabledCommandsString != "" ? disabledCommandsString?.split(",") : [];
|
||||||
|
|
||||||
const disabledCommandsInstance = disabledCommands?.findIndex(x => x == commandName);
|
const disabledCommandsInstance = disabledCommands?.findIndex(x => x == commandName.value!.toString());
|
||||||
|
|
||||||
if (disabledCommandsInstance! > -1) {
|
if (disabledCommandsInstance! > -1) {
|
||||||
disabledCommands?.splice(disabledCommandsInstance!, 1);
|
disabledCommands?.splice(disabledCommandsInstance!, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
await SettingsHelper.SetSetting("commands.disabled", context.message.guild.id, disabledCommands!.join(","));
|
await SettingsHelper.SetSetting("commands.disabled", interaction.guildId, disabledCommands!.join(","));
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", `Enabled command: ${commandName}`);
|
await interaction.reply(`Enabled command ${commandName.value}`);
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,67 +0,0 @@
|
||||||
import { CoreClient } from "../client/client";
|
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import StringTools from "../helpers/StringTools";
|
|
||||||
import { Command } from "../type/command";
|
|
||||||
|
|
||||||
export interface ICommandData {
|
|
||||||
Exists: boolean;
|
|
||||||
Name?: string;
|
|
||||||
Category?: string;
|
|
||||||
Roles?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class Help extends Command {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
super.Category = "General";
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
|
||||||
if (context.args.length == 0) {
|
|
||||||
await this.SendAll(context);
|
|
||||||
} else {
|
|
||||||
await this.SendSingle(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async SendAll(context: ICommandContext) {
|
|
||||||
const allCommands = CoreClient.commandItems
|
|
||||||
.filter(x => !x.ServerId || x.ServerId == context.message.guild?.id);
|
|
||||||
const cateogries = [...new Set(allCommands.map(x => x.Command.Category))];
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "Commands", `Commands: ${allCommands.length}`);
|
|
||||||
|
|
||||||
cateogries.forEach(category => {
|
|
||||||
let filtered = allCommands.filter(x => x.Command.Category == category);
|
|
||||||
|
|
||||||
embed.AddField(StringTools.Capitalise(category || "Uncategorised"), StringTools.CapitaliseArray(filtered.flatMap(x => x.Name)).join(", "));
|
|
||||||
});
|
|
||||||
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async SendSingle(context: ICommandContext) {
|
|
||||||
const command = CoreClient.commandItems.find(x => x.Name == context.args[0] && !x.ServerId);
|
|
||||||
const exclusiveCommand = CoreClient.commandItems.find(x => x.Name == context.args[0] && x.ServerId == context.message.guild?.id);
|
|
||||||
|
|
||||||
if (exclusiveCommand) {
|
|
||||||
const embed = new PublicEmbed(context, StringTools.Capitalise(exclusiveCommand.Name), "Coming Soon");
|
|
||||||
embed.AddField("Category", StringTools.Capitalise(exclusiveCommand.Command.Category || "Uncategorised"));
|
|
||||||
embed.AddField("Required Roles", StringTools.Capitalise(exclusiveCommand.Command.Roles.join(", ")) || "Everyone");
|
|
||||||
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
} else if (command) {
|
|
||||||
const embed = new PublicEmbed(context, StringTools.Capitalise(command.Name), "Coming Soon");
|
|
||||||
embed.AddField("Category", StringTools.Capitalise(command.Command.Category || "Uncategorised"));
|
|
||||||
embed.AddField("Required Roles", StringTools.Capitalise(command.Command.Roles.join(", ")) || "Everyone");
|
|
||||||
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
} else {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "Command does not exist");
|
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
import { CommandInteraction, SlashCommandBuilder } from "discord.js";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { ICommandContext } from "../contracts/ICommandContext";
|
||||||
import IgnoredChannel from "../entity/IgnoredChannel";
|
import IgnoredChannel from "../entity/IgnoredChannel";
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
|
|
||||||
export default class Ignore extends Command {
|
export default class Ignore extends Command {
|
||||||
|
@ -11,27 +11,29 @@ export default class Ignore extends Command {
|
||||||
super.Roles = [
|
super.Roles = [
|
||||||
"moderator"
|
"moderator"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName('ignore')
|
||||||
|
.setDescription('Ignore events in this channel');
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
if (!context.message.guild) return;
|
if (!interaction.guildId) return;
|
||||||
|
|
||||||
const isChannelIgnored = await IgnoredChannel.IsChannelIgnored(context.message.channel.id);
|
const isChannelIgnored = await IgnoredChannel.IsChannelIgnored(interaction.guildId);
|
||||||
|
|
||||||
if (isChannelIgnored) {
|
if (isChannelIgnored) {
|
||||||
const entity = await IgnoredChannel.FetchOneById(IgnoredChannel, context.message.channel.id);
|
const entity = await IgnoredChannel.FetchOneById(IgnoredChannel, interaction.guildId);
|
||||||
|
|
||||||
await IgnoredChannel.Remove(IgnoredChannel, entity);
|
await IgnoredChannel.Remove(IgnoredChannel, entity);
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "Success", "This channel will start being logged again.");
|
await interaction.reply('This channel will start being logged again.');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
} else {
|
} else {
|
||||||
const entity = new IgnoredChannel(context.message.channel.id);
|
const entity = new IgnoredChannel(interaction.guildId);
|
||||||
|
|
||||||
await entity.Save(IgnoredChannel, entity);
|
await entity.Save(IgnoredChannel, entity);
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "Success", "This channel will now be ignored from logging.");
|
await interaction.reply('This channel will now be ignored from logging.');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,11 +1,11 @@
|
||||||
import { AuditType } from "../constants/AuditType";
|
|
||||||
import ErrorMessages from "../constants/ErrorMessages";
|
import ErrorMessages from "../constants/ErrorMessages";
|
||||||
|
import { Command } from "../type/command";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { ICommandContext } from "../contracts/ICommandContext";
|
||||||
import Audit from "../entity/Audit";
|
import Audit from "../entity/Audit";
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
import { AuditType } from "../constants/AuditType";
|
||||||
import LogEmbed from "../helpers/embeds/LogEmbed";
|
import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
import { Command } from "../type/command";
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
|
|
||||||
export default class Kick extends Command {
|
export default class Kick extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -15,57 +15,67 @@ export default class Kick extends Command {
|
||||||
super.Roles = [
|
super.Roles = [
|
||||||
"moderator"
|
"moderator"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName("kick")
|
||||||
|
.setDescription("Kick a member from the server with an optional reason")
|
||||||
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.KickMembers)
|
||||||
|
.addUserOption(option =>
|
||||||
|
option
|
||||||
|
.setName('target')
|
||||||
|
.setDescription('The user')
|
||||||
|
.setRequired(true))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('reason')
|
||||||
|
.setDescription('The reason'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
const targetUser = context.message.mentions.users.first();
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
if (!interaction.guildId) return;
|
||||||
|
if (!interaction.guild) return;
|
||||||
|
|
||||||
if (!targetUser) {
|
const targetUser = interaction.options.get('target');
|
||||||
const embed = new ErrorEmbed(context, "User does not exist");
|
const reasonInput = interaction.options.get('reason');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
|
if (!targetUser || !targetUser.user || !targetUser.member) {
|
||||||
|
await interaction.reply("User not found.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetMember = context.message.guild?.members.cache.find(x => x.user.id == targetUser.id);
|
const member = targetUser.member as GuildMember;
|
||||||
|
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : "*none*";
|
||||||
|
|
||||||
if (!targetMember) {
|
const logEmbed = new EmbedBuilder()
|
||||||
const embed = new ErrorEmbed(context, "User is not in this server");
|
.setColor(EmbedColours.Ok)
|
||||||
await embed.SendToCurrentChannel();
|
.setTitle("Member Kicked")
|
||||||
|
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: "Moderator",
|
||||||
|
value: `<@${interaction.user.id}>`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Reason",
|
||||||
|
value: reason,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
return;
|
await member.kick();
|
||||||
|
await interaction.reply(`\`${targetUser.user.tag}\` has been kicked.`);
|
||||||
|
|
||||||
|
const channelName = await SettingsHelper.GetSetting('channels.logs.mod', interaction.guildId);
|
||||||
|
|
||||||
|
if (!channelName) return;
|
||||||
|
|
||||||
|
const channel = interaction.guild.channels.cache.find(x => x.name == channelName) as TextChannel;
|
||||||
|
|
||||||
|
if (channel) {
|
||||||
|
await channel.send({ embeds: [ logEmbed ]});
|
||||||
}
|
}
|
||||||
|
|
||||||
const reasonArgs = context.args;
|
const audit = new Audit(targetUser.user.id, AuditType.Kick, reason, interaction.user.id, interaction.guildId);
|
||||||
reasonArgs.splice(0, 1)
|
|
||||||
|
|
||||||
const reason = reasonArgs.join(" ");
|
|
||||||
|
|
||||||
if (!context.message.guild?.available) return;
|
|
||||||
|
|
||||||
if (!targetMember.kickable) {
|
|
||||||
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const logEmbed = new LogEmbed(context, "Member Kicked");
|
|
||||||
logEmbed.AddUser("User", targetUser, true);
|
|
||||||
logEmbed.AddUser("Moderator", context.message.author);
|
|
||||||
logEmbed.AddReason(reason);
|
|
||||||
|
|
||||||
const publicEmbed = new PublicEmbed(context, "", `${targetUser} has been kicked`);
|
|
||||||
|
|
||||||
await targetMember.kick(`Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}`);
|
|
||||||
|
|
||||||
await logEmbed.SendToModLogsChannel();
|
|
||||||
await publicEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
if (context.message.guild) {
|
|
||||||
const audit = new Audit(targetUser.id, AuditType.Kick, reason, context.message.author.id, context.message.guild.id);
|
|
||||||
|
|
||||||
await audit.Save(Audit, audit);
|
await audit.Save(Audit, audit);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
|
import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
|
||||||
import { AuditType } from "../constants/AuditType";
|
import { AuditType } from "../constants/AuditType";
|
||||||
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
import ErrorMessages from "../constants/ErrorMessages";
|
import ErrorMessages from "../constants/ErrorMessages";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { ICommandContext } from "../contracts/ICommandContext";
|
||||||
import Audit from "../entity/Audit";
|
import Audit from "../entity/Audit";
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
import LogEmbed from "../helpers/embeds/LogEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
|
|
||||||
export default class Mute extends Command {
|
export default class Mute extends Command {
|
||||||
|
@ -15,67 +15,71 @@ export default class Mute extends Command {
|
||||||
super.Roles = [
|
super.Roles = [
|
||||||
"moderator"
|
"moderator"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName("mute")
|
||||||
|
.setDescription("Mute a member in the server with an optional reason")
|
||||||
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.KickMembers)
|
||||||
|
.addUserOption(option =>
|
||||||
|
option
|
||||||
|
.setName('target')
|
||||||
|
.setDescription('The user')
|
||||||
|
.setRequired(true))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('reason')
|
||||||
|
.setDescription('The reason'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
const targetUser = context.message.mentions.users.first();
|
if (!interaction.guild || !interaction.guildId) return;
|
||||||
|
|
||||||
if (!targetUser) {
|
const targetUser = interaction.options.get('target');
|
||||||
const embed = new ErrorEmbed(context, "User does not exist");
|
const reasonInput = interaction.options.get('reason');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
|
if (!targetUser || !targetUser.user || !targetUser.member) {
|
||||||
|
await interaction.reply('Fields are required.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetMember = context.message.guild?.members.cache.find(x => x.user.id == targetUser.id);
|
const targetMember = targetUser.member as GuildMember;
|
||||||
|
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : "*none*";
|
||||||
|
|
||||||
if (!targetMember) {
|
const logEmbed = new EmbedBuilder()
|
||||||
const embed = new ErrorEmbed(context, "User is not in this server");
|
.setColor(EmbedColours.Ok)
|
||||||
await embed.SendToCurrentChannel();
|
.setTitle("Member Muted")
|
||||||
|
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: "Moderator",
|
||||||
|
value: `<@${interaction.user.id}>`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Reason",
|
||||||
|
value: reason,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
return;
|
const mutedRole = interaction.guild.roles.cache.find(role => role.name == process.env.ROLES_MUTED);
|
||||||
}
|
|
||||||
|
|
||||||
const reasonArgs = context.args;
|
|
||||||
reasonArgs.splice(0, 1);
|
|
||||||
|
|
||||||
const reason = reasonArgs.join(" ");
|
|
||||||
|
|
||||||
if (!context.message.guild?.available) return;
|
|
||||||
|
|
||||||
if (!targetMember.manageable) {
|
|
||||||
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const logEmbed = new LogEmbed(context, "Member Muted");
|
|
||||||
logEmbed.AddUser("User", targetUser, true)
|
|
||||||
logEmbed.AddUser("Moderator", context.message.author);
|
|
||||||
logEmbed.AddReason(reason);
|
|
||||||
|
|
||||||
const publicEmbed = new PublicEmbed(context, "", `${targetUser} has been muted`);
|
|
||||||
publicEmbed.AddReason(reason);
|
|
||||||
|
|
||||||
const mutedRole = context.message.guild.roles.cache.find(role => role.name == process.env.ROLES_MUTED);
|
|
||||||
|
|
||||||
if (!mutedRole) {
|
if (!mutedRole) {
|
||||||
const embed = new ErrorEmbed(context, ErrorMessages.RoleNotFound);
|
await interaction.reply('Muted role not found.');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await targetMember.roles.add(mutedRole, `Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}`);
|
await targetMember.roles.add(mutedRole);
|
||||||
|
|
||||||
await logEmbed.SendToModLogsChannel();
|
const channelName = await SettingsHelper.GetSetting('channels.logs.mod', interaction.guildId);
|
||||||
await publicEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
if (context.message.guild) {
|
if (!channelName) return;
|
||||||
const audit = new Audit(targetUser.id, AuditType.Mute, reason, context.message.author.id, context.message.guild.id);
|
|
||||||
|
|
||||||
|
const channel = interaction.guild.channels.cache.find(x => x.name == channelName) as TextChannel;
|
||||||
|
|
||||||
|
if (channel) {
|
||||||
|
await channel.send({ embeds: [ logEmbed ]});
|
||||||
|
}
|
||||||
|
|
||||||
|
const audit = new Audit(targetUser.user.id, AuditType.Mute, reason, interaction.user.id, interaction.guildId);
|
||||||
await audit.Save(Audit, audit);
|
await audit.Save(Audit, audit);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,68 +0,0 @@
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
|
||||||
|
|
||||||
export default class Poll extends Command {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
super.Category = "General";
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
|
||||||
const argsJoined = context.args.join(" ");
|
|
||||||
const argsSplit = argsJoined.split(";");
|
|
||||||
|
|
||||||
if (argsSplit.length < 3 || argsSplit.length > 10) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "Usage: <title>;<option 1>;<option 2>... (separate options with semicolons), maximum of 9 options");
|
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: [errorEmbed]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const title = argsSplit[0];
|
|
||||||
|
|
||||||
const arrayOfNumbers = [
|
|
||||||
':one:',
|
|
||||||
':two:',
|
|
||||||
':three:',
|
|
||||||
':four:',
|
|
||||||
':five:',
|
|
||||||
':six:',
|
|
||||||
':seven:',
|
|
||||||
':eight:',
|
|
||||||
':nine:'
|
|
||||||
];
|
|
||||||
|
|
||||||
const reactionEmojis = ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣"];
|
|
||||||
|
|
||||||
const description = arrayOfNumbers.splice(0, argsSplit.length - 1);
|
|
||||||
|
|
||||||
description.forEach((value, index) => {
|
|
||||||
description[index] = `${value} ${argsSplit[index + 1]}`;
|
|
||||||
});
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, title, description.join("\n"));
|
|
||||||
|
|
||||||
const message = await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
if (!message) return;
|
|
||||||
|
|
||||||
description.forEach(async (value, index) => {
|
|
||||||
await message.react(reactionEmojis[index]);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (context.message.deletable) {
|
|
||||||
await context.message.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
commandContext: context,
|
|
||||||
embeds: [embed]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,205 +1,164 @@
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
import { CommandInteraction, EmbedBuilder, GuildMemberRoleManager, Role as DiscordRole, SlashCommandBuilder } from "discord.js";
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Role as DiscordRole } from "discord.js";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { ICommandContext } from "../contracts/ICommandContext";
|
||||||
import SettingsHelper from "../helpers/SettingsHelper";
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
import { readFileSync } from "fs";
|
import { readFileSync } from "fs";
|
||||||
import { default as eRole } from "../entity/Role";
|
import { default as eRole } from "../entity/Role";
|
||||||
import Server from "../entity/Server";
|
import Server from "../entity/Server";
|
||||||
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
|
|
||||||
export default class Role extends Command {
|
export default class Role extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.Category = "General";
|
super.Category = "General";
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName('role')
|
||||||
|
.setDescription('Toggle your roles')
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('config')
|
||||||
|
.setDescription('Configure the roles')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('role')
|
||||||
|
.setDescription('The role name')
|
||||||
|
.setRequired(true)))
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('toggle')
|
||||||
|
.setDescription('Toggle your role')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('role')
|
||||||
|
.setDescription('The role name')
|
||||||
|
.setRequired(true)))
|
||||||
|
.addSubcommand(subcommand =>
|
||||||
|
subcommand
|
||||||
|
.setName('list')
|
||||||
|
.setDescription('List togglable roles'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
if (!context.message.guild) return;
|
if (!interaction.isChatInputCommand()) return;
|
||||||
|
|
||||||
switch (context.args[0]) {
|
switch (interaction.options.getSubcommand()) {
|
||||||
case "config":
|
case 'config':
|
||||||
await this.UseConfig(context);
|
await this.Configure(interaction);
|
||||||
|
break;
|
||||||
|
case 'toggle':
|
||||||
|
await this.ToggleRole(interaction);
|
||||||
|
break;
|
||||||
|
case 'list':
|
||||||
|
await this.SendRolesList(interaction);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
await this.UseDefault(context);
|
await interaction.reply('Subcommand not found.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// =======
|
private async SendRolesList(interaction: CommandInteraction) {
|
||||||
// Default
|
const roles = await this.GetRolesList(interaction);
|
||||||
// =======
|
|
||||||
|
|
||||||
private async UseDefault(context: ICommandContext) {
|
const embed = new EmbedBuilder()
|
||||||
if (context.args.length == 0) {
|
.setColor(EmbedColours.Ok)
|
||||||
await this.SendRolesList(context, context.message.guild!.id);
|
.setTitle("Roles")
|
||||||
} else {
|
.setDescription(`Roles: ${roles.length}\n\n${roles.join("\n")}`);
|
||||||
await this.ToggleRole(context);
|
|
||||||
}
|
await interaction.reply({ embeds: [ embed ]});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async GetRolesList(context: ICommandContext): Promise<string[]> {
|
private async ToggleRole(interaction: CommandInteraction) {
|
||||||
const rolesArray = await eRole.FetchAllByServerId(context.message.guild!.id);
|
if (!interaction.guild) return;
|
||||||
|
if (!interaction.member) return;
|
||||||
|
|
||||||
const stringArray: string[] = [];
|
const roles = await this.GetRolesList(interaction);
|
||||||
|
const requestedRole = interaction.options.get('role');
|
||||||
for (let i = 0; i < rolesArray.length; i++) {
|
|
||||||
const serverRole = context.message.guild!.roles.cache.find(x => x.id == rolesArray[i].RoleId);
|
|
||||||
|
|
||||||
if (serverRole) {
|
|
||||||
stringArray.push(serverRole.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return stringArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async SendRolesList(context: ICommandContext, serverId: string) {
|
|
||||||
const roles = await this.GetRolesList(context);
|
|
||||||
|
|
||||||
const botPrefix = await SettingsHelper.GetServerPrefix(serverId);
|
|
||||||
const description = roles.length == 0 ? "*no roles*" : `Do ${botPrefix}role <role> to get the role!\n\n${roles.join('\n')}`;
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "Roles", description);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async ToggleRole(context: ICommandContext) {
|
|
||||||
const roles = await this.GetRolesList(context);
|
|
||||||
const requestedRole = context.args.join(" ");
|
|
||||||
|
|
||||||
if (!roles.includes(requestedRole)) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "This role isn't marked as assignable, to see a list of assignable roles, run this command without any parameters");
|
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
|
if (!requestedRole || !requestedRole.value) {
|
||||||
|
await interaction.reply('Fields are required.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const assignRole = context.message.guild?.roles.cache.find(x => x.name == requestedRole);
|
if (!roles.includes(requestedRole.value.toString())) {
|
||||||
|
await interaction.reply('This role isn\'t marked as assignable.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const assignRole = interaction.guild.roles.cache.find(x => x.name == requestedRole.value);
|
||||||
|
|
||||||
if (!assignRole) {
|
if (!assignRole) {
|
||||||
const errorEmbed = new ErrorEmbed(context, "The current server doesn't have this role. Please contact the server's moderators");
|
await interaction.reply('The current server doesn\'t have this role. Please contact the server\'s moderators');
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = context.message.member?.roles.cache.find(x => x.name == requestedRole)
|
const roleManager = interaction.member.roles as GuildMemberRoleManager;
|
||||||
|
|
||||||
|
const role = roleManager.cache.find(x => x.name == requestedRole.value);
|
||||||
|
|
||||||
if (!role) {
|
if (!role) {
|
||||||
await this.AddRole(context, assignRole);
|
await roleManager.add(assignRole);
|
||||||
|
await interaction.reply(`Gave role: \`${assignRole.name}\``);
|
||||||
} else {
|
} else {
|
||||||
await this.RemoveRole(context, assignRole);
|
await roleManager.remove(assignRole);
|
||||||
|
await interaction.reply(`Removed role: \`${assignRole.name}\``);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async AddRole(context: ICommandContext, role: DiscordRole) {
|
private async Configure(interaction: CommandInteraction) {
|
||||||
await context.message.member?.roles.add(role, "Toggled with role command");
|
if (!interaction.guildId || !interaction.guild) return;
|
||||||
|
if (!interaction.member) return;
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", `Gave role: \`${role.name}\``);
|
const roleName = interaction.options.get('role');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async RemoveRole(context: ICommandContext, role: DiscordRole) {
|
|
||||||
await context.message.member?.roles.remove(role, "Toggled with role command");
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", `Removed role: \`${role.name}\``);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ======
|
|
||||||
// Config
|
|
||||||
// ======
|
|
||||||
|
|
||||||
private async UseConfig(context: ICommandContext) {
|
|
||||||
const moderatorRole = await SettingsHelper.GetSetting("role.moderator", context.message.guild!.id);
|
|
||||||
|
|
||||||
if (!context.message.member?.roles.cache.find(x => x.name == moderatorRole)) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "Sorry, you must be a moderator to be able to configure this command");
|
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
|
if (!roleName || !roleName.value) {
|
||||||
|
await interaction.reply('Fields are required.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (context.args[1]) {
|
const roleManager = interaction.member.roles as GuildMemberRoleManager;
|
||||||
case "add":
|
|
||||||
await this.AddRoleConfig(context);
|
const moderatorRole = await SettingsHelper.GetSetting("role.moderator", interaction.guildId);
|
||||||
break;
|
|
||||||
case "remove":
|
if (!roleManager.cache.find(x => x.name == moderatorRole)) {
|
||||||
await this.RemoveRoleConfig(context);
|
await interaction.reply('Sorry, you must be a moderator to be able to configure this command.');
|
||||||
break;
|
return;
|
||||||
default:
|
|
||||||
await this.SendConfigHelp(context);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async SendConfigHelp(context: ICommandContext) {
|
const role = interaction.guild.roles.cache.find(x => x.name == roleName.value);
|
||||||
const helpText = readFileSync(`${process.cwd()}/data/usage/role.txt`).toString();
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "Configure Role Command", helpText);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async AddRoleConfig(context: ICommandContext) {
|
|
||||||
const role = context.message.guild!.roles.cache.find(x => x.id == context.args[2]);
|
|
||||||
|
|
||||||
if (!role) {
|
if (!role) {
|
||||||
this.SendConfigHelp(context);
|
await interaction.reply('Unable to find role.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const existingRole = await eRole.FetchOneByRoleId(role.id);
|
const existingRole = await eRole.FetchOneByRoleId(role.id);
|
||||||
|
|
||||||
if (existingRole) {
|
if (existingRole) {
|
||||||
const errorEmbed = new ErrorEmbed(context, "This role has already been setup");
|
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const server = await Server.FetchOneById(Server, context.message.guild!.id, [
|
|
||||||
"Roles",
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!server) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "Server not setup, please request the server owner runs the setup command.");
|
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const roleSetting = new eRole(role.id);
|
|
||||||
|
|
||||||
await roleSetting.Save(eRole, roleSetting);
|
|
||||||
|
|
||||||
server.AddRoleToServer(roleSetting);
|
|
||||||
await server.Save(Server, server);
|
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", `Added \`${role.name}\` as a new assignable role`);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async RemoveRoleConfig(context: ICommandContext) {
|
|
||||||
const role = context.message.guild!.roles.cache.find(x => x.id == context.args[2]);
|
|
||||||
|
|
||||||
if (!role) {
|
|
||||||
this.SendConfigHelp(context);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const existingRole = await eRole.FetchOneByRoleId(role.id);
|
|
||||||
|
|
||||||
if (!existingRole) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "Unable to find this role");
|
|
||||||
errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await eRole.Remove(eRole, existingRole);
|
await eRole.Remove(eRole, existingRole);
|
||||||
|
await interaction.reply('Removed role from configuration.');
|
||||||
|
} else {
|
||||||
|
const newRole = new eRole(role.id);
|
||||||
|
await newRole.Save(eRole, newRole);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "", `Removed \`${role.name}\` from the list of assignable roles`);
|
private async GetRolesList(interaction: CommandInteraction): Promise<string[]> {
|
||||||
await embed.SendToCurrentChannel();
|
if (!interaction.guildId || !interaction.guild) return [];
|
||||||
|
|
||||||
|
const rolesArray = await eRole.FetchAllByServerId(interaction.guildId);
|
||||||
|
|
||||||
|
const roles: string[] = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < rolesArray.length; i++) {
|
||||||
|
const serverRole = interaction.guild.roles.cache.find(x => x.id == rolesArray[i].RoleId);
|
||||||
|
|
||||||
|
if (serverRole) {
|
||||||
|
roles.push(serverRole.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return roles;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
import { CommandInteraction, EmbedBuilder, SlashCommandBuilder } from "discord.js";
|
||||||
import { existsSync, readFileSync } from "fs";
|
import { existsSync, readFileSync } from "fs";
|
||||||
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { ICommandContext } from "../contracts/ICommandContext";
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
|
|
||||||
interface IRules {
|
interface IRules {
|
||||||
|
@ -19,34 +19,48 @@ export default class Rules extends Command {
|
||||||
super.Roles = [
|
super.Roles = [
|
||||||
"administrator"
|
"administrator"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName("rules")
|
||||||
|
.setDescription("Send the rules embeds for this server");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
if (!existsSync(`${process.cwd()}/data/rules/${context.message.guild?.id}.json`)) {
|
if (!interaction.guildId) return;
|
||||||
const errorEmbed = new ErrorEmbed(context, "Rules file doesn't exist");
|
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
|
if (!existsSync(`${process.cwd()}/data/rules/${interaction.guildId}.json`)) {
|
||||||
|
await interaction.reply('Rules file doesn\'t exist.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rulesFile = readFileSync(`${process.cwd()}/data/rules/${context.message.guild?.id}.json`).toString();
|
const rulesFile = readFileSync(`${process.cwd()}/data/rules/${interaction.guildId}.json`).toString();
|
||||||
const rules = JSON.parse(rulesFile) as IRules[];
|
const rules = JSON.parse(rulesFile) as IRules[];
|
||||||
|
|
||||||
const embeds: PublicEmbed[] = [];
|
const embeds: EmbedBuilder[] = [];
|
||||||
|
|
||||||
rules.forEach(rule => {
|
rules.forEach(rule => {
|
||||||
const embed = new PublicEmbed(context, rule.title || "", rule.description?.join("\n") || "");
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(EmbedColours.Ok)
|
||||||
|
.setTitle(rule.title || "Rules")
|
||||||
|
.setDescription(rule.description ? rule.description.join("\n") : "*none*");
|
||||||
|
|
||||||
embed.SetImage(rule.image || "");
|
if (rule.image) {
|
||||||
embed.SetFooter(rule.footer || "");
|
embed.setImage(rule.image);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rule.footer) {
|
||||||
|
embed.setFooter({ text: rule.footer });
|
||||||
|
}
|
||||||
|
|
||||||
embeds.push(embed);
|
embeds.push(embed);
|
||||||
});
|
});
|
||||||
|
|
||||||
for (let i = 0; i < embeds.length; i++) {
|
const channel = interaction.channel;
|
||||||
const embed = embeds[i];
|
|
||||||
|
|
||||||
await embed.SendToCurrentChannel();
|
if (!channel) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await channel.send({ embeds: embeds });
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,26 +0,0 @@
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
||||||
import { Command } from "../type/command";
|
|
||||||
|
|
||||||
export default class Say extends Command {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
super.Category = "Misc";
|
|
||||||
super.Roles = [
|
|
||||||
"moderator"
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
|
||||||
const input = context.args.join(" ");
|
|
||||||
|
|
||||||
if (input.length == 0) {
|
|
||||||
const errorEmbed = new ErrorEmbed(context, "You must supply a message.");
|
|
||||||
|
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
context.message.channel.send(input);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +1,6 @@
|
||||||
|
import { CommandInteraction, SlashCommandBuilder } from "discord.js";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { ICommandContext } from "../contracts/ICommandContext";
|
||||||
import Server from "../entity/Server";
|
import Server from "../entity/Server";
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
|
|
||||||
export default class Setup extends Command {
|
export default class Setup extends Command {
|
||||||
|
@ -11,27 +10,26 @@ export default class Setup extends Command {
|
||||||
super.Roles = [
|
super.Roles = [
|
||||||
"moderator"
|
"moderator"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName('setup')
|
||||||
|
.setDescription('Makes the server ready to be configured');
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
if (!context.message.guild) {
|
if (!interaction.guildId) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const server = await Server.FetchOneById(Server, context.message.guild?.id);
|
const server = await Server.FetchOneById(Server, interaction.guildId);
|
||||||
|
|
||||||
if (server) {
|
if (server) {
|
||||||
const embed = new ErrorEmbed(context, "This server has already been setup, please configure using the config command");
|
await interaction.reply('This server has already been setup, please configure using the config command.');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newServer = new Server(context.message.guild?.id);
|
const newServer = new Server(interaction.guildId);
|
||||||
|
|
||||||
await newServer.Save(Server, newServer);
|
await newServer.Save(Server, newServer);
|
||||||
|
|
||||||
const embed = new PublicEmbed(context, "Success", "Please configure using the config command");
|
await interaction.reply('Success, please configure using the configure command.');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,8 +1,10 @@
|
||||||
|
import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
|
||||||
|
import { AuditType } from "../constants/AuditType";
|
||||||
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
import ErrorMessages from "../constants/ErrorMessages";
|
import ErrorMessages from "../constants/ErrorMessages";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { ICommandContext } from "../contracts/ICommandContext";
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
import Audit from "../entity/Audit";
|
||||||
import LogEmbed from "../helpers/embeds/LogEmbed";
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
|
|
||||||
export default class Unmute extends Command {
|
export default class Unmute extends Command {
|
||||||
|
@ -13,61 +15,68 @@ export default class Unmute extends Command {
|
||||||
super.Roles = [
|
super.Roles = [
|
||||||
"moderator"
|
"moderator"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName("unmute")
|
||||||
|
.setDescription("Unmute a member in the server with an optional reason")
|
||||||
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.KickMembers)
|
||||||
|
.addUserOption(option =>
|
||||||
|
option
|
||||||
|
.setName('target')
|
||||||
|
.setDescription('The user')
|
||||||
|
.setRequired(true))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('reason')
|
||||||
|
.setDescription('The reason'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
const targetUser = context.message.mentions.users.first();
|
if (!interaction.guild || !interaction.guildId) return;
|
||||||
|
|
||||||
if (!targetUser) {
|
const targetUser = interaction.options.get('target');
|
||||||
const embed = new ErrorEmbed(context, "User does not exist");
|
const reasonInput = interaction.options.get('reason');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
|
if (!targetUser || !targetUser.user || !targetUser.member) {
|
||||||
|
await interaction.reply('Fields are required.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const targetMember = context.message.guild?.members.cache.find(x => x.user.id == targetUser.id);
|
const targetMember = targetUser.member as GuildMember;
|
||||||
|
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : "*none*";
|
||||||
|
|
||||||
if (!targetMember) {
|
const logEmbed = new EmbedBuilder()
|
||||||
const embed = new ErrorEmbed(context, "User is not in this server");
|
.setColor(EmbedColours.Ok)
|
||||||
await embed.SendToCurrentChannel();
|
.setTitle("Member Unmuted")
|
||||||
|
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: "Moderator",
|
||||||
|
value: `<@${interaction.user.id}>`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Reason",
|
||||||
|
value: reason,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
return;
|
const mutedRole = interaction.guild.roles.cache.find(role => role.name == process.env.ROLES_MUTED);
|
||||||
}
|
|
||||||
|
|
||||||
const reasonArgs = context.args;
|
|
||||||
reasonArgs.splice(0, 1);
|
|
||||||
|
|
||||||
const reason = reasonArgs.join(" ");
|
|
||||||
|
|
||||||
if (!context.message.guild?.available) return;
|
|
||||||
|
|
||||||
if (!targetMember.manageable) {
|
|
||||||
const embed = new ErrorEmbed(context, ErrorMessages.InsufficientBotPermissions);
|
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const logEmbed = new LogEmbed(context, "Member Unmuted");
|
|
||||||
logEmbed.AddUser("User", targetUser, true)
|
|
||||||
logEmbed.AddUser("Moderator", context.message.author);
|
|
||||||
logEmbed.AddReason(reason);
|
|
||||||
|
|
||||||
const publicEmbed = new PublicEmbed(context, "", `${targetUser} has been unmuted`);
|
|
||||||
publicEmbed.AddReason(reason);
|
|
||||||
|
|
||||||
const mutedRole = context.message.guild.roles.cache.find(role => role.name == process.env.ROLES_MUTED);
|
|
||||||
|
|
||||||
if (!mutedRole) {
|
if (!mutedRole) {
|
||||||
const embed = new ErrorEmbed(context, ErrorMessages.RoleNotFound);
|
await interaction.reply('Muted role not found.');
|
||||||
await embed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await targetMember.roles.remove(mutedRole, `Moderator: ${context.message.author.tag}, Reason: ${reason || "*none*"}`);
|
await targetMember.roles.remove(mutedRole);
|
||||||
|
|
||||||
await logEmbed.SendToModLogsChannel();
|
const channelName = await SettingsHelper.GetSetting('channels.logs.mod', interaction.guildId);
|
||||||
await publicEmbed.SendToCurrentChannel();
|
|
||||||
|
if (!channelName) return;
|
||||||
|
|
||||||
|
const channel = interaction.guild.channels.cache.find(x => x.name == channelName) as TextChannel;
|
||||||
|
|
||||||
|
if (channel) {
|
||||||
|
await channel.send({ embeds: [ logEmbed ]});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,9 +1,10 @@
|
||||||
|
import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
|
||||||
import { AuditType } from "../constants/AuditType";
|
import { AuditType } from "../constants/AuditType";
|
||||||
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
|
import ErrorMessages from "../constants/ErrorMessages";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { ICommandContext } from "../contracts/ICommandContext";
|
||||||
import Audit from "../entity/Audit";
|
import Audit from "../entity/Audit";
|
||||||
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
import LogEmbed from "../helpers/embeds/LogEmbed";
|
|
||||||
import PublicEmbed from "../helpers/embeds/PublicEmbed";
|
|
||||||
import { Command } from "../type/command";
|
import { Command } from "../type/command";
|
||||||
|
|
||||||
export default class Warn extends Command {
|
export default class Warn extends Command {
|
||||||
|
@ -14,49 +15,62 @@ export default class Warn extends Command {
|
||||||
super.Roles = [
|
super.Roles = [
|
||||||
"moderator"
|
"moderator"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
super.CommandBuilder = new SlashCommandBuilder()
|
||||||
|
.setName("warn")
|
||||||
|
.setDescription("Warns a member in the server with an optional reason")
|
||||||
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.KickMembers)
|
||||||
|
.addUserOption(option =>
|
||||||
|
option
|
||||||
|
.setName('target')
|
||||||
|
.setDescription('The user')
|
||||||
|
.setRequired(true))
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('reason')
|
||||||
|
.setDescription('The reason'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async execute(context: ICommandContext) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
const user = context.message.mentions.users.first();
|
if (!interaction.guild || !interaction.guildId) return;
|
||||||
|
|
||||||
if (!user) {
|
const targetUser = interaction.options.get('target');
|
||||||
const errorEmbed = new ErrorEmbed(context, "User does not exist");
|
const reasonInput = interaction.options.get('reason');
|
||||||
await errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
|
if (!targetUser || !targetUser.user || !targetUser.member) {
|
||||||
|
await interaction.reply('Fields are required.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const member = context.message.guild?.members.cache.find(x => x.user.id == user.id);
|
const targetMember = targetUser.member as GuildMember;
|
||||||
|
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : "*none*";
|
||||||
|
|
||||||
if (!member) {
|
const logEmbed = new EmbedBuilder()
|
||||||
const errorEmbed = new ErrorEmbed(context, "User is not in this server");
|
.setColor(EmbedColours.Ok)
|
||||||
await errorEmbed.SendToCurrentChannel();
|
.setTitle("Member Warned")
|
||||||
|
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: "Moderator",
|
||||||
|
value: `<@${interaction.user.id}>`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Reason",
|
||||||
|
value: reason,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
return;
|
const channelName = await SettingsHelper.GetSetting('channels.logs.mod', interaction.guildId);
|
||||||
|
|
||||||
|
if (!channelName) return;
|
||||||
|
|
||||||
|
const channel = interaction.guild.channels.cache.find(x => x.name == channelName) as TextChannel;
|
||||||
|
|
||||||
|
if (channel) {
|
||||||
|
await channel.send({ embeds: [ logEmbed ]});
|
||||||
}
|
}
|
||||||
|
|
||||||
const reasonArgs = context.args;
|
const audit = new Audit(targetUser.user.id, AuditType.Warn, reason, interaction.user.id, interaction.guildId);
|
||||||
reasonArgs.splice(0, 1);
|
|
||||||
|
|
||||||
const reason = reasonArgs.join(" ");
|
|
||||||
|
|
||||||
if (!context.message.guild?.available) return;
|
|
||||||
|
|
||||||
const logEmbed = new LogEmbed(context, "Member Warned");
|
|
||||||
logEmbed.AddUser("User", user, true);
|
|
||||||
logEmbed.AddUser("Moderator", context.message.author);
|
|
||||||
logEmbed.AddReason(reason);
|
|
||||||
|
|
||||||
const publicEmbed = new PublicEmbed(context, "", `${user} has been warned`);
|
|
||||||
publicEmbed.AddReason(reason);
|
|
||||||
|
|
||||||
await logEmbed.SendToModLogsChannel();
|
|
||||||
await publicEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
if (context.message.guild) {
|
|
||||||
const audit = new Audit(user.id, AuditType.Warn, reason, context.message.author.id, context.message.guild.id);
|
|
||||||
|
|
||||||
await audit.Save(Audit, audit);
|
await audit.Save(Audit, audit);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
3
src/constants/EmbedColours.ts
Normal file
3
src/constants/EmbedColours.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export default class EmbedColours {
|
||||||
|
public static readonly Ok = 0x3050ba;
|
||||||
|
}
|
|
@ -1,8 +1,8 @@
|
||||||
import { Event } from "../type/event";
|
import { Event } from "../type/event";
|
||||||
import { GuildMember } from "discord.js";
|
import { EmbedBuilder, GuildChannel, GuildMember, TextChannel } from "discord.js";
|
||||||
import EventEmbed from "../helpers/embeds/EventEmbed";
|
|
||||||
import GuildMemberUpdate from "./MemberEvents/GuildMemberUpdate";
|
import GuildMemberUpdate from "./MemberEvents/GuildMemberUpdate";
|
||||||
import SettingsHelper from "../helpers/SettingsHelper";
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
|
|
||||||
export default class MemberEvents extends Event {
|
export default class MemberEvents extends Event {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -15,15 +15,29 @@ export default class MemberEvents extends Event {
|
||||||
const enabled = await SettingsHelper.GetSetting("event.member.add.enabled", member.guild.id);
|
const enabled = await SettingsHelper.GetSetting("event.member.add.enabled", member.guild.id);
|
||||||
if (!enabled || enabled.toLowerCase() != "true") return;
|
if (!enabled || enabled.toLowerCase() != "true") return;
|
||||||
|
|
||||||
const embed = new EventEmbed(member.client, member.guild, "Member Joined");
|
const embed = new EmbedBuilder()
|
||||||
embed.AddUser("User", member.user, true);
|
.setColor(EmbedColours.Ok)
|
||||||
embed.AddField("Created", member.user.createdAt.toISOString());
|
.setTitle('Member Joined')
|
||||||
embed.SetFooter(`Id: ${member.user.id}`);
|
.setDescription(`${member.user} \`${member.user.tag}\``)
|
||||||
|
.setFooter({ text: `Id: ${member.user.id}` })
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: 'Created',
|
||||||
|
value: member.user.createdAt.toISOString(),
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
const channel = await SettingsHelper.GetSetting("event.member.add.channel", member.guild.id);
|
const channelSetting = await SettingsHelper.GetSetting("event.member.add.channel", member.guild.id);
|
||||||
if (!channel || !member.guild.channels.cache.find(x => x.name == channel)) return;
|
|
||||||
|
|
||||||
await embed.SendToChannel(channel);
|
if (!channelSetting) return;
|
||||||
|
|
||||||
|
const channel = member.guild.channels.cache.find(x => x.name == channelSetting);
|
||||||
|
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
|
const guildChannel = channel as TextChannel;
|
||||||
|
|
||||||
|
await guildChannel.send({ embeds: [embed ]});
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async guildMemberRemove(member: GuildMember) {
|
public override async guildMemberRemove(member: GuildMember) {
|
||||||
|
@ -32,15 +46,29 @@ export default class MemberEvents extends Event {
|
||||||
const enabled = await SettingsHelper.GetSetting("event.member.remove.enabled", member.guild.id);
|
const enabled = await SettingsHelper.GetSetting("event.member.remove.enabled", member.guild.id);
|
||||||
if (!enabled || enabled.toLowerCase() != "true") return;
|
if (!enabled || enabled.toLowerCase() != "true") return;
|
||||||
|
|
||||||
const embed = new EventEmbed(member.client, member.guild, "Member Left");
|
const embed = new EmbedBuilder()
|
||||||
embed.AddUser("User", member.user, true);
|
.setColor(EmbedColours.Ok)
|
||||||
embed.AddField("Joined", member.joinedAt?.toISOString() || "n/a");
|
.setTitle('Member Left')
|
||||||
embed.SetFooter(`Id: ${member.user.id}`);
|
.setDescription(`${member.user} \`${member.user.tag}\``)
|
||||||
|
.setFooter({ text: `Id: ${member.user.id}` })
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: 'Joined',
|
||||||
|
value: member.joinedAt ? member.joinedAt.toISOString() : "*none*",
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
const channel = await SettingsHelper.GetSetting("event.member.remove.channel", member.guild.id);
|
const channelSetting = await SettingsHelper.GetSetting("event.member.remove.channel", member.guild.id);
|
||||||
if (!channel || !member.guild.channels.cache.find(x => x.name == channel)) return;
|
|
||||||
|
|
||||||
await embed.SendToChannel(channel);
|
if (!channelSetting) return;
|
||||||
|
|
||||||
|
const channel = member.guild.channels.cache.find(x => x.name == channelSetting);
|
||||||
|
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
|
const guildChannel = channel as TextChannel;
|
||||||
|
|
||||||
|
await guildChannel.send({ embeds: [embed ]});
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async guildMemberUpdate(oldMember: GuildMember, newMember: GuildMember) {
|
public override async guildMemberUpdate(oldMember: GuildMember, newMember: GuildMember) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { GuildMember } from "discord.js";
|
import { EmbedBuilder, GuildMember, TextChannel } from "discord.js";
|
||||||
import EventEmbed from "../../helpers/embeds/EventEmbed";
|
import EmbedColours from "../../constants/EmbedColours";
|
||||||
import SettingsHelper from "../../helpers/SettingsHelper";
|
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||||
|
|
||||||
export default class GuildMemberUpdate {
|
export default class GuildMemberUpdate {
|
||||||
|
@ -18,15 +18,32 @@ export default class GuildMemberUpdate {
|
||||||
const oldNickname = this.oldMember.nickname || "*none*";
|
const oldNickname = this.oldMember.nickname || "*none*";
|
||||||
const newNickname = this.newMember.nickname || "*none*";
|
const newNickname = this.newMember.nickname || "*none*";
|
||||||
|
|
||||||
const embed = new EventEmbed(this.oldMember.client, this.newMember.guild, "Nickname Changed");
|
const embed = new EmbedBuilder()
|
||||||
embed.AddUser("User", this.newMember.user, true);
|
.setColor(EmbedColours.Ok)
|
||||||
embed.AddField("Before", oldNickname, true);
|
.setTitle('Nickname Changed')
|
||||||
embed.AddField("After", newNickname, true);
|
.setDescription(`${this.newMember.user} \`${this.newMember.user.tag}\``)
|
||||||
embed.SetFooter(`Id: ${this.newMember.user.id}`);
|
.setFooter({ text: `Id: ${this.newMember.user.id}` })
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: 'Before',
|
||||||
|
value: oldNickname,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'After',
|
||||||
|
value: newNickname,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
const channel = await SettingsHelper.GetSetting("event.member.update.channel", this.newMember.guild.id);
|
const channelSetting = await SettingsHelper.GetSetting("event.member.update.channel", this.newMember.guild.id);
|
||||||
if (!channel || channel.toLowerCase() != "true") return;
|
|
||||||
|
|
||||||
await embed.SendToChannel(channel);
|
if (!channelSetting) return;
|
||||||
|
|
||||||
|
const channel = this.newMember.guild.channels.cache.find(x => x.name == channelSetting);
|
||||||
|
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
|
const guildChannel = channel as TextChannel;
|
||||||
|
|
||||||
|
await guildChannel.send({ embeds: [embed ]});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
import { Event } from "../type/event";
|
import { Event } from "../type/event";
|
||||||
import { Message } from "discord.js";
|
import { EmbedBuilder, Message, TextChannel } from "discord.js";
|
||||||
import EventEmbed from "../helpers/embeds/EventEmbed";
|
|
||||||
import SettingsHelper from "../helpers/SettingsHelper";
|
import SettingsHelper from "../helpers/SettingsHelper";
|
||||||
import OnMessage from "./MessageEvents/OnMessage";
|
import OnMessage from "./MessageEvents/OnMessage";
|
||||||
import IgnoredChannel from "../entity/IgnoredChannel";
|
import IgnoredChannel from "../entity/IgnoredChannel";
|
||||||
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
|
|
||||||
export default class MessageEvents extends Event {
|
export default class MessageEvents extends Event {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -20,19 +20,42 @@ export default class MessageEvents extends Event {
|
||||||
const ignored = await IgnoredChannel.IsChannelIgnored(message.channel.id);
|
const ignored = await IgnoredChannel.IsChannelIgnored(message.channel.id);
|
||||||
if (ignored) return;
|
if (ignored) return;
|
||||||
|
|
||||||
const embed = new EventEmbed(message.client, message.guild, "Message Deleted");
|
const embed = new EmbedBuilder()
|
||||||
embed.AddUser("User", message.author, true);
|
.setColor(EmbedColours.Ok)
|
||||||
embed.AddField("Channel", message.channel.toString(), true);
|
.setTitle("Message Deleted")
|
||||||
embed.AddField("Content", `\`\`\`${message.content || "*none*"}\`\`\``);
|
.setDescription(`${message.author} \`${message.author.tag}\``)
|
||||||
|
.addFields([
|
||||||
|
{
|
||||||
|
name: "Channel",
|
||||||
|
value: message.channel.toString(),
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Content",
|
||||||
|
value: `\`\`\`${message.content || "*none*"}\`\`\``,
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
if (message.attachments.size > 0) {
|
if (message.attachments.size > 0) {
|
||||||
embed.AddField("Attachments", `\`\`\`${message.attachments.map(x => x.url).join("\n")}\`\`\``);
|
embed.addFields([
|
||||||
|
{
|
||||||
|
name: "Attachments",
|
||||||
|
value: `\`\`\`${message.attachments.map(x => x.url).join("\n")}\`\`\``
|
||||||
|
}
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const channel = await SettingsHelper.GetSetting("event.message.delete.channel", message.guild.id);
|
const channelSetting = await SettingsHelper.GetSetting("event.message.delete.channel", message.guild.id);
|
||||||
if (!channel || !message.guild.channels.cache.find(x => x.name == channel)) return;
|
|
||||||
|
|
||||||
await embed.SendToChannel(channel);
|
if (!channelSetting) return;
|
||||||
|
|
||||||
|
const channel = message.guild.channels.cache.find(x => x.name == channelSetting);
|
||||||
|
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
|
const guildChannel = channel as TextChannel;
|
||||||
|
|
||||||
|
await guildChannel.send({ embeds: [ embed ]});
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async messageUpdate(oldMessage: Message, newMessage: Message) {
|
public override async messageUpdate(oldMessage: Message, newMessage: Message) {
|
||||||
|
@ -46,16 +69,37 @@ export default class MessageEvents extends Event {
|
||||||
const ignored = await IgnoredChannel.IsChannelIgnored(newMessage.channel.id);
|
const ignored = await IgnoredChannel.IsChannelIgnored(newMessage.channel.id);
|
||||||
if (ignored) return;
|
if (ignored) return;
|
||||||
|
|
||||||
const embed = new EventEmbed(newMessage.client, newMessage.guild, "Message Edited");
|
const embed = new EmbedBuilder()
|
||||||
embed.AddUser("User", newMessage.author, true);
|
.setColor(EmbedColours.Ok)
|
||||||
embed.AddField("Channel", newMessage.channel.toString(), true);
|
.setTitle("Message Deleted")
|
||||||
embed.AddField("Before", `\`\`\`${oldMessage.content || "*none*"}\`\`\``);
|
.setDescription(`${newMessage.author} \`${newMessage.author.tag}\``)
|
||||||
embed.AddField("After", `\`\`\`${newMessage.content || "*none*"}\`\`\``);
|
.addFields([
|
||||||
|
{
|
||||||
|
name: "Channel",
|
||||||
|
value: newMessage.channel.toString(),
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Before",
|
||||||
|
value: `\`\`\`${oldMessage.content || "*none*"}\`\`\``,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "After",
|
||||||
|
value: `\`\`\`${newMessage.content || "*none*"}\`\`\``,
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
const channel = await SettingsHelper.GetSetting("event.message.update.channel", newMessage.guild.id);
|
const channelSetting = await SettingsHelper.GetSetting("event.message.delete.channel", newMessage.guild.id);
|
||||||
if (!channel || !newMessage.guild.channels.cache.find(x => x.name == channel)) return;
|
|
||||||
|
|
||||||
await embed.SendToChannel(channel);
|
if (!channelSetting) return;
|
||||||
|
|
||||||
|
const channel = newMessage.guild.channels.cache.find(x => x.name == channelSetting);
|
||||||
|
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
|
const guildChannel = channel as TextChannel;
|
||||||
|
|
||||||
|
await guildChannel.send({ embeds: [ embed ]});
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async messageCreate(message: Message) {
|
public override async messageCreate(message: Message) {
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
import { EmbedBuilder, Message, PermissionsBitField, TextChannel } from "discord.js";
|
|
||||||
import { ICommandContext } from "../../contracts/ICommandContext";
|
|
||||||
|
|
||||||
export default class ErrorEmbed {
|
|
||||||
public context: ICommandContext;
|
|
||||||
|
|
||||||
private _embedBuilder: EmbedBuilder;
|
|
||||||
|
|
||||||
constructor(context: ICommandContext, message: string) {
|
|
||||||
this._embedBuilder = new EmbedBuilder()
|
|
||||||
.setColor(0xd52803)
|
|
||||||
.setDescription(message);
|
|
||||||
|
|
||||||
this.context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Detail Methods
|
|
||||||
public AddField(name: string, value: string, inline: boolean = false) {
|
|
||||||
this._embedBuilder.addFields([
|
|
||||||
{
|
|
||||||
name,
|
|
||||||
value,
|
|
||||||
inline
|
|
||||||
}
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
public SetFooter(text: string) {
|
|
||||||
this._embedBuilder.setFooter({
|
|
||||||
text
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public SetImage(imageUrl: string) {
|
|
||||||
this._embedBuilder.setImage(imageUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SetURL(url: string) {
|
|
||||||
this._embedBuilder.setURL(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send Methods
|
|
||||||
public async SendToCurrentChannel(): Promise<Message | undefined> {
|
|
||||||
const channel = this.context.message.channel as TextChannel;
|
|
||||||
const botMember = await this.context.message.guild?.members.fetch({ user: this.context.message.client.user! });
|
|
||||||
|
|
||||||
if (!botMember) return;
|
|
||||||
|
|
||||||
const permissions = channel.permissionsFor(botMember);
|
|
||||||
|
|
||||||
if (!permissions.has(PermissionsBitField.Flags.SendMessages)) return;
|
|
||||||
|
|
||||||
return this.context.message.channel.send({ embeds: [ this._embedBuilder ]});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,117 +0,0 @@
|
||||||
import { EmbedBuilder, TextChannel, User, Guild, Client, PermissionsBitField, Message } from "discord.js";
|
|
||||||
import SettingsHelper from "../SettingsHelper";
|
|
||||||
|
|
||||||
export default class EventEmbed {
|
|
||||||
public guild: Guild;
|
|
||||||
|
|
||||||
private client: Client;
|
|
||||||
private _embedBuilder: EmbedBuilder;
|
|
||||||
|
|
||||||
constructor(client: Client, guild: Guild, title: string) {
|
|
||||||
this._embedBuilder = new EmbedBuilder()
|
|
||||||
.setColor(0x3050ba)
|
|
||||||
.setTitle(title);
|
|
||||||
|
|
||||||
this.guild = guild;
|
|
||||||
this.client = client;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Detail methods
|
|
||||||
public AddField(name: string, value: string, inline: boolean = false) {
|
|
||||||
this._embedBuilder.addFields([
|
|
||||||
{
|
|
||||||
name,
|
|
||||||
value,
|
|
||||||
inline
|
|
||||||
}
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
public SetFooter(text: string) {
|
|
||||||
this._embedBuilder.setFooter({
|
|
||||||
text
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public SetImage(imageUrl: string) {
|
|
||||||
this._embedBuilder.setImage(imageUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
public AddUser(title: string, user: User, setThumbnail: boolean = false) {
|
|
||||||
this._embedBuilder.addFields([
|
|
||||||
{
|
|
||||||
name: title,
|
|
||||||
value: `${user} \`${user.tag}\``,
|
|
||||||
inline: true,
|
|
||||||
}
|
|
||||||
])
|
|
||||||
|
|
||||||
if (setThumbnail) {
|
|
||||||
this._embedBuilder.setThumbnail(user.displayAvatarURL());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public AddReason(message: string) {
|
|
||||||
this._embedBuilder.addFields([
|
|
||||||
{
|
|
||||||
name: "Reason",
|
|
||||||
value: message || "*none*",
|
|
||||||
}
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
public SetURL(url: string) {
|
|
||||||
this._embedBuilder.setURL(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send methods
|
|
||||||
public async SendToChannel(name: string): Promise<Message | undefined> {
|
|
||||||
const channel = this.guild.channels.cache
|
|
||||||
.find(channel => channel.name == name) as TextChannel;
|
|
||||||
|
|
||||||
if (!channel) {
|
|
||||||
console.error(`Unable to find channel ${name}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const botMember = await this.guild.members.fetch({ user: this.client.user! });
|
|
||||||
|
|
||||||
if (!botMember) return;
|
|
||||||
|
|
||||||
const permissions = channel.permissionsFor(botMember);
|
|
||||||
|
|
||||||
if (!permissions.has(PermissionsBitField.Flags.SendMessages)) return;
|
|
||||||
|
|
||||||
return channel.send({embeds: [ this._embedBuilder ]});
|
|
||||||
}
|
|
||||||
|
|
||||||
public async SendToMessageLogsChannel(): Promise<Message | undefined> {
|
|
||||||
const channelName = await SettingsHelper.GetSetting("channels.logs.message", this.guild.id);
|
|
||||||
|
|
||||||
if (!channelName) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.SendToChannel(channelName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async SendToMemberLogsChannel(): Promise<Message | undefined> {
|
|
||||||
const channelName = await SettingsHelper.GetSetting("channels.logs.member", this.guild.id);
|
|
||||||
|
|
||||||
if (!channelName) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.SendToChannel(channelName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async SendToModLogsChannel(): Promise<Message | undefined> {
|
|
||||||
const channelName = await SettingsHelper.GetSetting("channels.logs.mod", this.guild.id);
|
|
||||||
|
|
||||||
if (!channelName) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.SendToChannel(channelName);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,125 +0,0 @@
|
||||||
import { TextChannel, User, EmbedBuilder, PermissionsBitField, Message } from "discord.js";
|
|
||||||
import ErrorMessages from "../../constants/ErrorMessages";
|
|
||||||
import { ICommandContext } from "../../contracts/ICommandContext";
|
|
||||||
import SettingsHelper from "../SettingsHelper";
|
|
||||||
import ErrorEmbed from "./ErrorEmbed";
|
|
||||||
|
|
||||||
export default class LogEmbed {
|
|
||||||
public context: ICommandContext;
|
|
||||||
|
|
||||||
private _embedBuilder: EmbedBuilder;
|
|
||||||
|
|
||||||
constructor(context: ICommandContext, title: string) {
|
|
||||||
this._embedBuilder = new EmbedBuilder()
|
|
||||||
.setColor(0x3050ba)
|
|
||||||
.setTitle(title);
|
|
||||||
|
|
||||||
this.context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Detail methods
|
|
||||||
public AddField(name: string, value: string, inline: boolean = false) {
|
|
||||||
this._embedBuilder.addFields([
|
|
||||||
{
|
|
||||||
name,
|
|
||||||
value,
|
|
||||||
inline
|
|
||||||
}
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
public SetFooter(text: string) {
|
|
||||||
this._embedBuilder.setFooter({
|
|
||||||
text
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public SetImage(imageUrl: string) {
|
|
||||||
this._embedBuilder.setImage(imageUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
public AddUser(title: string, user: User, setThumbnail: boolean = false) {
|
|
||||||
this._embedBuilder.addFields([
|
|
||||||
{
|
|
||||||
name: title,
|
|
||||||
value: `${user} \`${user.tag}\``,
|
|
||||||
inline: true,
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (setThumbnail) {
|
|
||||||
this._embedBuilder.setThumbnail(user.displayAvatarURL());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public AddReason(message: string) {
|
|
||||||
this._embedBuilder.addFields([
|
|
||||||
{
|
|
||||||
name: "Reason",
|
|
||||||
value: message || "*none*",
|
|
||||||
}
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
public SetURL(url: string) {
|
|
||||||
this._embedBuilder.setURL(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send methods
|
|
||||||
public async SendToCurrentChannel(): Promise<Message | undefined> {
|
|
||||||
const channel = this.context.message.channel as TextChannel;
|
|
||||||
const botMember = await this.context.message.guild?.members.fetch({ user: this.context.message.client.user! });
|
|
||||||
|
|
||||||
if (!botMember) return;
|
|
||||||
|
|
||||||
const permissions = channel.permissionsFor(botMember);
|
|
||||||
|
|
||||||
if (!permissions.has(PermissionsBitField.Flags.SendMessages)) return;
|
|
||||||
|
|
||||||
return this.context.message.channel.send({ embeds: [ this._embedBuilder ]});
|
|
||||||
}
|
|
||||||
|
|
||||||
public async SendToChannel(name: string): Promise<Message | undefined> {
|
|
||||||
const channel = this.context.message.guild?.channels.cache
|
|
||||||
.find(channel => channel.name == name) as TextChannel;
|
|
||||||
|
|
||||||
if (!channel) {
|
|
||||||
const errorEmbed = new ErrorEmbed(this.context, ErrorMessages.ChannelNotFound);
|
|
||||||
errorEmbed.SendToCurrentChannel();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return await channel.send({ embeds: [ this._embedBuilder ]});
|
|
||||||
}
|
|
||||||
|
|
||||||
public async SendToMessageLogsChannel(): Promise<Message | undefined> {
|
|
||||||
const channelName = await SettingsHelper.GetSetting("channels.logs.message", this.context.message.guild?.id!);
|
|
||||||
|
|
||||||
if (!channelName) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.SendToChannel(channelName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async SendToMemberLogsChannel(): Promise<Message | undefined> {
|
|
||||||
const channelName = await SettingsHelper.GetSetting("channels.logs.member", this.context.message.guild?.id!);
|
|
||||||
|
|
||||||
if (!channelName) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.SendToChannel(channelName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async SendToModLogsChannel(): Promise<Message | undefined> {
|
|
||||||
const channelName = await SettingsHelper.GetSetting("channels.logs.mod", this.context.message.guild?.id!);
|
|
||||||
|
|
||||||
if (!channelName) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.SendToChannel(channelName);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,65 +0,0 @@
|
||||||
import { EmbedBuilder, Message, MessageOptions, PermissionsBitField, TextChannel } from "discord.js";
|
|
||||||
import { ICommandContext } from "../../contracts/ICommandContext";
|
|
||||||
|
|
||||||
export default class PublicEmbed {
|
|
||||||
public context: ICommandContext;
|
|
||||||
|
|
||||||
private _embedBuilder: EmbedBuilder;
|
|
||||||
|
|
||||||
constructor(context: ICommandContext, title: string, description: string) {
|
|
||||||
this._embedBuilder = new EmbedBuilder()
|
|
||||||
.setColor(0x3050ba)
|
|
||||||
.setTitle(title)
|
|
||||||
.setDescription(description);
|
|
||||||
|
|
||||||
this.context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Detail methods
|
|
||||||
public AddField(name: string, value: string, inline: boolean = false) {
|
|
||||||
this._embedBuilder.addFields([
|
|
||||||
{
|
|
||||||
name,
|
|
||||||
value,
|
|
||||||
inline
|
|
||||||
}
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
public SetFooter(text: string) {
|
|
||||||
this._embedBuilder.setFooter({
|
|
||||||
text
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public SetImage(imageUrl: string) {
|
|
||||||
this._embedBuilder.setImage(imageUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
public AddReason(message: string) {
|
|
||||||
this._embedBuilder.addFields([
|
|
||||||
{
|
|
||||||
name: "Reason",
|
|
||||||
value: message || "*none*",
|
|
||||||
}
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
public SetURL(url: string) {
|
|
||||||
this._embedBuilder.setURL(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send methods
|
|
||||||
public async SendToCurrentChannel(options?: MessageOptions): Promise<Message | undefined> {
|
|
||||||
const channel = this.context.message.channel as TextChannel;
|
|
||||||
const botMember = await this.context.message.guild?.members.fetch({ user: this.context.message.client.user! });
|
|
||||||
|
|
||||||
if (!botMember) return;
|
|
||||||
|
|
||||||
const permissions = channel.permissionsFor(botMember);
|
|
||||||
|
|
||||||
if (!permissions.has(PermissionsBitField.Flags.SendMessages)) return;
|
|
||||||
|
|
||||||
return this.context.message.channel.send({ embeds: [ this._embedBuilder ], ...options});
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -8,14 +8,11 @@ import Clear from "./commands/clear";
|
||||||
import Code from "./commands/code";
|
import Code from "./commands/code";
|
||||||
import Config from "./commands/config";
|
import Config from "./commands/config";
|
||||||
import Disable from "./commands/disable";
|
import Disable from "./commands/disable";
|
||||||
import Help from "./commands/help";
|
|
||||||
import Ignore from "./commands/ignore";
|
import Ignore from "./commands/ignore";
|
||||||
import Kick from "./commands/kick";
|
import Kick from "./commands/kick";
|
||||||
import Mute from "./commands/mute";
|
import Mute from "./commands/mute";
|
||||||
import Poll from "./commands/poll";
|
|
||||||
import Role from "./commands/role";
|
import Role from "./commands/role";
|
||||||
import Rules from "./commands/rules";
|
import Rules from "./commands/rules";
|
||||||
import Say from "./commands/say";
|
|
||||||
import Setup from "./commands/setup";
|
import Setup from "./commands/setup";
|
||||||
import Unmute from "./commands/unmute";
|
import Unmute from "./commands/unmute";
|
||||||
import Warn from "./commands/warn";
|
import Warn from "./commands/warn";
|
||||||
|
@ -38,17 +35,14 @@ export default class Registry {
|
||||||
CoreClient.RegisterCommand("code", new Code());
|
CoreClient.RegisterCommand("code", new Code());
|
||||||
CoreClient.RegisterCommand("config", new Config());
|
CoreClient.RegisterCommand("config", new Config());
|
||||||
CoreClient.RegisterCommand("disable", new Disable());
|
CoreClient.RegisterCommand("disable", new Disable());
|
||||||
CoreClient.RegisterCommand("help", new Help());
|
|
||||||
CoreClient.RegisterCommand("ignore", new Ignore());
|
CoreClient.RegisterCommand("ignore", new Ignore());
|
||||||
CoreClient.RegisterCommand("kick", new Kick());
|
CoreClient.RegisterCommand("kick", new Kick());
|
||||||
CoreClient.RegisterCommand("mute", new Mute());
|
CoreClient.RegisterCommand("mute", new Mute());
|
||||||
CoreClient.RegisterCommand("poll", new Poll());
|
|
||||||
CoreClient.RegisterCommand("role", new Role());
|
CoreClient.RegisterCommand("role", new Role());
|
||||||
CoreClient.RegisterCommand("rules", new Rules());
|
CoreClient.RegisterCommand("rules", new Rules());
|
||||||
CoreClient.RegisterCommand("unmute", new Unmute());
|
CoreClient.RegisterCommand("unmute", new Unmute());
|
||||||
CoreClient.RegisterCommand("warn", new Warn());
|
CoreClient.RegisterCommand("warn", new Warn());
|
||||||
CoreClient.RegisterCommand("setup", new Setup());
|
CoreClient.RegisterCommand("setup", new Setup());
|
||||||
CoreClient.RegisterCommand("say", new Say());
|
|
||||||
CoreClient.RegisterCommand("audits", new Audits());
|
CoreClient.RegisterCommand("audits", new Audits());
|
||||||
|
|
||||||
// Exclusive Commands: MankBot
|
// Exclusive Commands: MankBot
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import { CommandResponse } from "../constants/CommandResponse";
|
import { CommandResponse } from "../constants/CommandResponse";
|
||||||
import { ICommandContext } from "../contracts/ICommandContext";
|
import { ICommandContext } from "../contracts/ICommandContext";
|
||||||
import { SlashCommandBuilder } from "discord.js";
|
import { CommandInteraction, Interaction, SlashCommandBuilder } from "discord.js";
|
||||||
|
|
||||||
export class Command {
|
export class Command {
|
||||||
public SlashCommandBuilder: SlashCommandBuilder;
|
public CommandBuilder: any;
|
||||||
|
|
||||||
public Roles: string[];
|
public Roles: string[];
|
||||||
public Category?: string;
|
public Category?: string;
|
||||||
|
@ -12,15 +12,15 @@ export class Command {
|
||||||
this.Roles = [];
|
this.Roles = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public precheck(context: ICommandContext): CommandResponse {
|
public precheck(interation: CommandInteraction): CommandResponse {
|
||||||
return CommandResponse.Ok;
|
return CommandResponse.Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async precheckAsync(context: ICommandContext): Promise<CommandResponse> {
|
public async precheckAsync(interation: CommandInteraction): Promise<CommandResponse> {
|
||||||
return CommandResponse.Ok;
|
return CommandResponse.Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
public execute(context: ICommandContext) {
|
public execute(interaction: CommandInteraction) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ const requiredConfigs: string[] = [
|
||||||
"BOT_TOKEN",
|
"BOT_TOKEN",
|
||||||
"BOT_VER",
|
"BOT_VER",
|
||||||
"BOT_AUTHOR",
|
"BOT_AUTHOR",
|
||||||
"BOT_DATE",
|
|
||||||
"BOT_OWNERID",
|
"BOT_OWNERID",
|
||||||
|
"BOT_CLIENTID",
|
||||||
];
|
];
|
||||||
|
|
||||||
requiredConfigs.forEach(config => {
|
requiredConfigs.forEach(config => {
|
||||||
|
|
Loading…
Reference in a new issue