Compare commits

..

No commits in common. "07237b82aa63d519fdcdb5a59b1b7d1b006a6c81" and "fcd6ecf06b679e02aded134a282bc5591146d780" have entirely different histories.

28 changed files with 1268 additions and 1383 deletions

View file

@ -7,7 +7,7 @@
# any secret values. # any secret values.
BOT_TOKEN= BOT_TOKEN=
BOT_VER=3.2 DEV BOT_VER=3.1.3
BOT_AUTHOR=Vylpes BOT_AUTHOR=Vylpes
BOT_OWNERID=147392775707426816 BOT_OWNERID=147392775707426816
BOT_CLIENTID=682942374040961060 BOT_CLIENTID=682942374040961060

View file

@ -54,11 +54,11 @@ steps:
- yarn install --frozen-lockfile - yarn install --frozen-lockfile
- yarn build - yarn build
# - name: test - name: test
# image: node image: node
# commands: commands:
# - yarn install --frozen-lockfile - yarn install --frozen-lockfile
# - yarn test - yarn test
trigger: trigger:
branch: branch:

View file

@ -24,6 +24,6 @@ Please describe the tests that you ran to verify the changes. Provide instructio
- [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation - [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings - [ ] My changes generate no new warnings
- [ ] I have added tests that provide my fix is effective or that my feature works - [ ] I have added tests that provde my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes - [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules - [ ] Any dependent changes have been merged and published in downstream modules

View file

@ -7,7 +7,7 @@
# any secret values. # any secret values.
BOT_TOKEN= BOT_TOKEN=
BOT_VER=3.2 BOT_VER=3.1.3
BOT_AUTHOR=Vylpes BOT_AUTHOR=Vylpes
BOT_OWNERID=147392775707426816 BOT_OWNERID=147392775707426816
BOT_CLIENTID=680083120896081954 BOT_CLIENTID=680083120896081954

View file

@ -7,7 +7,7 @@
# any secret values. # any secret values.
BOT_TOKEN= BOT_TOKEN=
BOT_VER=3.2 BETA BOT_VER=3.1.3
BOT_AUTHOR=Vylpes BOT_AUTHOR=Vylpes
BOT_OWNERID=147392775707426816 BOT_OWNERID=147392775707426816
BOT_CLIENTID=1016767908740857949 BOT_CLIENTID=1016767908740857949

View file

@ -26,11 +26,11 @@ event.message.delete.channel: Sets the channel the bot will log message delete e
event.message.update.enabled: Enables/Disables the message delete log event (Default: "false") event.message.update.enabled: Enables/Disables the message delete log event (Default: "false")
event.message.update.channel: Sets the channel the bot will log message delete events to (Default: "message-logs") event.message.update.channel: Sets the channel the bot will log message delete events to (Default: "message-logs")
event.member.add.enabled: Enables/Disables the member join log event (Default: "false") event.member.add.enabled: Enables/Disables the message delete log event (Default: "false")
event.member.add.channel: Sets the channel the bot will log member join events to (Default: "member-logs") event.member.add.channel: Sets the channel the bot will log message delete events to (Default: "member-logs")
event.member.remove.enabled: Enables/Disables the member leave log event (Default: "false") event.member.remove.enabled: Enables/Disables the message delete log event (Default: "false")
event.member.remove.channel: Sets the channel the bot will log member leave events to (Default: "member-logs") event.member.remove.channel: Sets the channel the bot will log message delete events to (Default: "member-logs")
event.member.update.enabled: Enables/Disables the member update log event (Default: "false") event.member.update.enabled: Enables/Disables the message delete log event (Default: "false")
event.member.update.channel: Sets the channel the bot will log member update events to (Default: "member-logs") event.member.update.channel: Sets the channel the bot will log message delete events to (Default: "member-logs")

View file

@ -1,6 +1,6 @@
{ {
"name": "vylbot-app", "name": "vylbot-app",
"version": "3.2.0", "version": "3.1.3",
"description": "A discord bot made for Vylpes' Den", "description": "A discord bot made for Vylpes' Den",
"main": "./dist/vylbot", "main": "./dist/vylbot",
"typings": "./dist", "typings": "./dist",
@ -26,7 +26,7 @@
"homepage": "https://github.com/Vylpes/vylbot-app", "homepage": "https://github.com/Vylpes/vylbot-app",
"funding": "https://ko-fi.com/vylpes", "funding": "https://ko-fi.com/vylpes",
"dependencies": { "dependencies": {
"@discordjs/rest": "^2.0.0", "@discordjs/rest": "^1.1.0",
"@types/jest": "^29.0.0", "@types/jest": "^29.0.0",
"@types/uuid": "^9.0.0", "@types/uuid": "^9.0.0",
"discord.js": "^14.3.0", "discord.js": "^14.3.0",
@ -34,7 +34,7 @@
"emoji-regex": "^10.0.0", "emoji-regex": "^10.0.0",
"jest": "^29.0.0", "jest": "^29.0.0",
"jest-mock-extended": "^3.0.0", "jest-mock-extended": "^3.0.0",
"minimatch": "9.0.3", "minimatch": "9.0.2",
"mysql": "^2.18.1", "mysql": "^2.18.1",
"random-bunny": "^2.0.5", "random-bunny": "^2.0.5",
"ts-jest": "^29.0.0", "ts-jest": "^29.0.0",
@ -45,7 +45,7 @@
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^20.0.0", "@types/node": "^20.0.0",
"np": "^9.0.0", "np": "^8.0.4",
"typescript": "^5.0.0" "typescript": "^5.0.0"
} }
} }

View file

@ -1,42 +0,0 @@
import { ButtonInteraction, CacheType } from "discord.js";
import { ButtonEvent } from "../type/buttonEvent";
import SettingsHelper from "../helpers/SettingsHelper";
export default class Verify extends ButtonEvent {
public override async execute(interaction: ButtonInteraction<CacheType>) {
if (!interaction.guildId || !interaction.guild) return;
const roleName = await SettingsHelper.GetSetting("verification.role", interaction.guildId);
if (!roleName) return;
const role = interaction.guild.roles.cache.find(x => x.name == roleName);
if (!role) {
await interaction.reply({
content: `Unable to find the role, ${roleName}`,
ephemeral: true,
});
return;
}
const member = interaction.guild.members.cache.find(x => x.id == interaction.user.id);
if (!member || !member.manageable) {
await interaction.reply({
content: "Unable to give role to user",
ephemeral: true,
});
return;
}
await member.roles.add(role);
await interaction.reply({
content: "Given role",
ephemeral: true,
});
}
}

View file

@ -1,4 +1,4 @@
import { Client, Partials } from "discord.js"; import { Client } from "discord.js";
import * as dotenv from "dotenv"; import * as dotenv from "dotenv";
import { createConnection } from "typeorm"; import { createConnection } from "typeorm";
import { EventType } from "../constants/EventType"; import { EventType } from "../constants/EventType";
@ -9,13 +9,10 @@ import { Command } from "../type/command";
import { Events } from "./events"; import { Events } from "./events";
import { Util } from "./util"; import { Util } from "./util";
import AppDataSource from "../database/dataSources/appDataSource"; import AppDataSource from "../database/dataSources/appDataSource";
import ButtonEventItem from "../contracts/ButtonEventItem";
import { ButtonEvent } from "../type/buttonEvent";
export class CoreClient extends Client { export class CoreClient extends Client {
private static _commandItems: ICommandItem[]; private static _commandItems: ICommandItem[];
private static _eventItems: IEventItem[]; private static _eventItems: IEventItem[];
private static _buttonEvents: ButtonEventItem[];
private _events: Events; private _events: Events;
private _util: Util; private _util: Util;
@ -28,17 +25,12 @@ export class CoreClient extends Client {
return this._eventItems; return this._eventItems;
} }
public static get buttonEvents(): ButtonEventItem[] { constructor(intents: number[]) {
return this._buttonEvents; super({ intents: intents });
}
constructor(intents: number[], partials: Partials[]) {
super({ intents: intents, partials: partials });
dotenv.config(); dotenv.config();
CoreClient._commandItems = []; CoreClient._commandItems = [];
CoreClient._eventItems = []; CoreClient._eventItems = [];
CoreClient._buttonEvents = [];
this._events = new Events(); this._events = new Events();
this._util = new Util(); this._util = new Util();
@ -81,13 +73,4 @@ export class CoreClient extends Client {
CoreClient._eventItems.push(item); CoreClient._eventItems.push(item);
} }
public static RegisterButtonEvent(buttonId: string, event: ButtonEvent) {
const item: ButtonEventItem = {
ButtonId: buttonId,
Event: event,
};
CoreClient._buttonEvents.push(item);
}
} }

View file

@ -1,18 +1,40 @@
import { Interaction } from "discord.js"; import { Interaction } from "discord.js";
import ChatInputCommand from "./interactionCreate/chatInputCommand"; import ICommandItem from "../contracts/ICommandItem";
import Button from "./interactionCreate/button"; import SettingsHelper from "../helpers/SettingsHelper";
import { CoreClient } from "./client";
export class Events { export class Events {
public async onInteractionCreate(interaction: Interaction) { public async onInteractionCreate(interaction: Interaction) {
if (!interaction.isChatInputCommand()) return;
if (!interaction.guildId) return; if (!interaction.guildId) return;
if (interaction.isChatInputCommand()) { const disabledCommandsString = await SettingsHelper.GetSetting("commands.disabled", interaction.guildId);
ChatInputCommand.onChatInput(interaction); const disabledCommands = disabledCommandsString?.split(",");
const disabledCommandsMessage = await SettingsHelper.GetSetting("commands.disabled.message", interaction.guildId);
if (disabledCommands?.find(x => x == interaction.commandName)) {
await interaction.reply(disabledCommandsMessage || "This command is disabled.");
return;
} }
if (interaction.isButton()) { const item = CoreClient.commandItems.find(x => x.Name == interaction.commandName && !x.ServerId);
Button.onButtonClicked(interaction); const itemForServer = CoreClient.commandItems.find(x => x.Name == interaction.commandName && x.ServerId == interaction.guildId);
let itemToUse: ICommandItem;
if (!itemForServer) {
if (!item) {
await interaction.reply('Command not found');
return;
} }
itemToUse = item;
} else {
itemToUse = itemForServer;
}
itemToUse.Command.execute(interaction);
} }
// Emit when bot is logged in and ready to use // Emit when bot is logged in and ready to use

View file

@ -1,17 +0,0 @@
import { ButtonInteraction } from "discord.js";
import { CoreClient } from "../client";
export default class Button {
public static async onButtonClicked(interaction: ButtonInteraction) {
if (!interaction.isButton) return;
const item = CoreClient.buttonEvents.find(x => x.ButtonId == interaction.customId.split(" ")[0]);
if (!item) {
await interaction.reply("Event not found.");
return;
}
item.Event.execute(interaction);
}
}

View file

@ -1,27 +0,0 @@
import { Interaction } from "discord.js";
import { CoreClient } from "../client";
import ICommandItem from "../../contracts/ICommandItem";
export default class ChatInputCommand {
public static async onChatInput(interaction: Interaction) {
if (!interaction.isChatInputCommand()) return;
const item = CoreClient.commandItems.find(x => x.Name == interaction.commandName && !x.ServerId);
const itemForServer = CoreClient.commandItems.find(x => x.Name == interaction.commandName && x.ServerId == interaction.guildId);
let itemToUse: ICommandItem;
if (!itemForServer) {
if (!item) {
await interaction.reply("Command not found.");
return;
}
itemToUse = item;
} else {
itemToUse = itemForServer;
}
itemToUse.Command.execute(interaction);
}
}

View file

@ -44,7 +44,6 @@ export default class Ban extends Command {
.setColor(EmbedColours.Ok) .setColor(EmbedColours.Ok)
.setTitle("Member Banned") .setTitle("Member Banned")
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``) .setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
.setThumbnail(targetUser.user.avatarURL())
.addFields([ .addFields([
{ {
name: "Moderator", name: "Moderator",

View file

@ -116,15 +116,9 @@ export default class Config extends Command {
const setting = server.Settings.filter(x => x.Key == key.value)[0]; const setting = server.Settings.filter(x => x.Key == key.value)[0];
if (setting) { if (setting) {
await interaction.reply(`\`${key.value}\`: \`${setting.Value}\``); await interaction.reply(`\`${key}\`: \`${setting.Value}\``);
} else { } else {
var defaultValue = DefaultValues.GetValue(key.value.toString()); await interaction.reply(`\`${key}\`: \`${DefaultValues.GetValue(key.value.toString())}\` <DEFAULT>`);
if (defaultValue) {
await interaction.reply(`\`${key.value}\`: \`${defaultValue}\` <DEFAULT>`);
} else {
await interaction.reply(`\`${key.value}\`: <NONE>`);
}
} }
} }

View file

@ -44,7 +44,6 @@ export default class Kick extends Command {
.setColor(EmbedColours.Ok) .setColor(EmbedColours.Ok)
.setTitle("Member Kicked") .setTitle("Member Kicked")
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``) .setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
.setThumbnail(targetUser.user.avatarURL())
.addFields([ .addFields([
{ {
name: "Moderator", name: "Moderator",

View file

@ -42,7 +42,6 @@ export default class Mute extends Command {
.setColor(EmbedColours.Ok) .setColor(EmbedColours.Ok)
.setTitle("Member Muted") .setTitle("Member Muted")
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``) .setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
.setThumbnail(targetUser.user.avatarURL())
.addFields([ .addFields([
{ {
name: "Moderator", name: "Moderator",
@ -54,14 +53,7 @@ export default class Mute extends Command {
}, },
]); ]);
const mutedRoleName = await SettingsHelper.GetSetting('role.muted', interaction.guildId); const mutedRole = interaction.guild.roles.cache.find(role => role.name == process.env.ROLES_MUTED);
if (!mutedRoleName) {
await interaction.reply('Unable to find configuration. Please contact the bot author.');
return;
}
const mutedRole = interaction.guild.roles.cache.find(role => role.name == mutedRoleName);
if (!mutedRole) { if (!mutedRole) {
await interaction.reply('Muted role not found.'); await interaction.reply('Muted role not found.');

View file

@ -1,8 +1,7 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js"; import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import { existsSync, readFileSync } from "fs"; import { existsSync, readFileSync } from "fs";
import EmbedColours from "../constants/EmbedColours"; import EmbedColours from "../constants/EmbedColours";
import { Command } from "../type/command"; import { Command } from "../type/command";
import SettingsHelper from "../helpers/SettingsHelper";
interface IRules { interface IRules {
title?: string; title?: string;
@ -15,36 +14,13 @@ export default class Rules extends Command {
constructor() { constructor() {
super(); super();
this.CommandBuilder = new SlashCommandBuilder() super.CommandBuilder = new SlashCommandBuilder()
.setName('rules') .setName("rules")
.setDescription("Rules-related commands") .setDescription("Send the rules embeds for this server")
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator) .setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator);
.addSubcommand(x =>
x
.setName('embeds')
.setDescription('Send the rules embeds for this server'))
.addSubcommand(x =>
x
.setName('access')
.setDescription('Send the server verification embed button'));
} }
public override async execute(interaction: CommandInteraction) { public override async execute(interaction: CommandInteraction) {
if (!interaction.isChatInputCommand()) return;
switch (interaction.options.getSubcommand()) {
case "embeds":
await this.SendEmbeds(interaction);
break;
case "access":
await this.SendAccessButton(interaction);
break;
default:
await interaction.reply("Subcommand doesn't exist.");
}
}
private async SendEmbeds(interaction: CommandInteraction) {
if (!interaction.guildId) return; if (!interaction.guildId) return;
if (!existsSync(`${process.cwd()}/data/rules/${interaction.guildId}.json`)) { if (!existsSync(`${process.cwd()}/data/rules/${interaction.guildId}.json`)) {
@ -95,27 +71,4 @@ export default class Rules extends Command {
await interaction.reply({ embeds: [ successEmbed ], ephemeral: true }); await interaction.reply({ embeds: [ successEmbed ], ephemeral: true });
} }
private async SendAccessButton(interaction: CommandInteraction) {
if (!interaction.guildId) return;
const buttonLabel = await SettingsHelper.GetSetting("rules.access.label", interaction.guildId);
const row = new ActionRowBuilder<ButtonBuilder>()
.addComponents([
new ButtonBuilder()
.setCustomId('verify')
.setStyle(ButtonStyle.Primary)
.setLabel(buttonLabel || "Verify")
]);
await interaction.channel?.send({
components: [ row ]
});
await interaction.reply({
content: "Success",
ephemeral: true,
});
}
} }

View file

@ -64,7 +64,6 @@ export default class Timeout extends Command {
.setColor(EmbedColours.Ok) .setColor(EmbedColours.Ok)
.setTitle("Member Timed Out") .setTitle("Member Timed Out")
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``) .setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
.setThumbnail(targetUser.user.avatarURL())
.addFields([ .addFields([
{ {
name: "Moderator", name: "Moderator",

View file

@ -40,7 +40,6 @@ export default class Unmute extends Command {
.setColor(EmbedColours.Ok) .setColor(EmbedColours.Ok)
.setTitle("Member Unmuted") .setTitle("Member Unmuted")
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``) .setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
.setThumbnail(targetUser.user.avatarURL())
.addFields([ .addFields([
{ {
name: "Moderator", name: "Moderator",
@ -52,14 +51,7 @@ export default class Unmute extends Command {
}, },
]); ]);
const mutedRoleName = await SettingsHelper.GetSetting('role.muted', interaction.guildId); const mutedRole = interaction.guild.roles.cache.find(role => role.name == process.env.ROLES_MUTED);
if (!mutedRoleName) {
await interaction.reply('Unable to find configuration. Please contact the bot author.');
return;
}
const mutedRole = interaction.guild.roles.cache.find(role => role.name == mutedRoleName);
if (!mutedRole) { if (!mutedRole) {
await interaction.reply('Muted role not found.'); await interaction.reply('Muted role not found.');

View file

@ -41,7 +41,6 @@ export default class Warn extends Command {
.setColor(EmbedColours.Ok) .setColor(EmbedColours.Ok)
.setTitle("Member Warned") .setTitle("Member Warned")
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``) .setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
.setThumbnail(targetUser.user.avatarURL())
.addFields([ .addFields([
{ {
name: "Moderator", name: "Moderator",

View file

@ -31,7 +31,6 @@ export default class DefaultValues {
// Rules (Command) // Rules (Command)
this.values.push({ Key: "rules.file", Value: "data/rules/rules" }); this.values.push({ Key: "rules.file", Value: "data/rules/rules" });
this.values.push({ Key: "rules.access.label", Value: "Verify" });
// Channels // Channels
this.values.push({ Key: "channels.logs.message", Value: "message-logs" }); this.values.push({ Key: "channels.logs.message", Value: "message-logs" });
@ -58,7 +57,7 @@ export default class DefaultValues {
this.values.push({ Key: "event.member.remove.channel", Value: "member-logs" }); this.values.push({ Key: "event.member.remove.channel", Value: "member-logs" });
this.values.push({ Key: "event.member.update.enabled", Value: "false" }); this.values.push({ Key: "event.member.update.enabled", Value: "false" });
this.values.push({ Key: "event.member.update.channel", Value: "member-logs" }); this.values.push({ Key: "event.member.remove.channel", Value: "member-logs" });
} }
} }

View file

@ -1,8 +0,0 @@
import { ButtonEvent } from "../type/buttonEvent";
interface ButtonEventItem {
ButtonId: string,
Event: ButtonEvent,
}
export default ButtonEventItem;

View file

@ -33,8 +33,8 @@ export default async function MessageDelete(message: Message) {
if (message.attachments.size > 0) { if (message.attachments.size > 0) {
embed.addFields([ embed.addFields([
{ {
name: `Attachments (${message.attachments.size})`, name: "Attachments",
value: `\`\`\`${message.attachments.map(x => x.name).join("\n")}\`\`\`` value: `\`\`\`${message.attachments.map(x => x.url).join("\n")}\`\`\``
} }
]); ]);
} }

View file

@ -37,9 +37,6 @@ import MessageDelete from "./events/MessageEvents/MessageDelete";
import MessageUpdate from "./events/MessageEvents/MessageUpdate"; import MessageUpdate from "./events/MessageEvents/MessageUpdate";
import MessageCreate from "./events/MessageEvents/MessageCreate"; import MessageCreate from "./events/MessageEvents/MessageCreate";
// Button Event Imports
import Verify from "./buttonEvents/verify";
export default class Registry { export default class Registry {
public static RegisterCommands() { public static RegisterCommands() {
CoreClient.RegisterCommand("about", new About()); CoreClient.RegisterCommand("about", new About());
@ -87,8 +84,4 @@ export default class Registry {
CoreClient.RegisterEvent(EventType.MessageUpdate, MessageUpdate); CoreClient.RegisterEvent(EventType.MessageUpdate, MessageUpdate);
CoreClient.RegisterEvent(EventType.MessageCreate, MessageCreate); CoreClient.RegisterEvent(EventType.MessageCreate, MessageCreate);
} }
public static RegisterButtonEvents() {
CoreClient.RegisterButtonEvent("verify", new Verify());
}
} }

View file

@ -1,5 +0,0 @@
import { ButtonInteraction } from "discord.js";
export abstract class ButtonEvent {
abstract execute(interaction: ButtonInteraction): Promise<void>;
}

View file

@ -1,7 +1,7 @@
import { CoreClient } from "./client/client"; import { CoreClient } from "./client/client";
import * as dotenv from "dotenv"; import * as dotenv from "dotenv";
import registry from "./registry"; import registry from "./registry";
import { IntentsBitField, Partials } from "discord.js"; import { IntentsBitField } from "discord.js";
dotenv.config(); dotenv.config();
@ -30,13 +30,9 @@ const client = new CoreClient([
IntentsBitField.Flags.GuildMessages, IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.GuildMembers, IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.MessageContent, IntentsBitField.Flags.MessageContent,
], [
Partials.GuildMember,
Partials.User,
]); ]);
registry.RegisterCommands(); registry.RegisterCommands();
registry.RegisterEvents(); registry.RegisterEvents();
registry.RegisterButtonEvents();
client.start(); client.start();

2332
yarn.lock

File diff suppressed because it is too large Load diff