v3.1.0 #317
17 changed files with 361 additions and 379 deletions
|
@ -1,10 +1,10 @@
|
|||
import { Client } from "discord.js";
|
||||
import * as dotenv from "dotenv";
|
||||
import { createConnection } from "typeorm";
|
||||
import { EventType } from "../constants/EventType";
|
||||
import ICommandItem from "../contracts/ICommandItem";
|
||||
import IEventItem from "../contracts/IEventItem";
|
||||
import { Command } from "../type/command";
|
||||
import { Event } from "../type/event";
|
||||
|
||||
import { Events } from "./events";
|
||||
import { Util } from "./util";
|
||||
|
@ -65,9 +65,10 @@ export class CoreClient extends Client {
|
|||
CoreClient._commandItems.push(item);
|
||||
}
|
||||
|
||||
public static RegisterEvent(event: Event) {
|
||||
public static RegisterEvent(eventType: EventType, func: Function) {
|
||||
const item: IEventItem = {
|
||||
Event: event,
|
||||
EventType: eventType,
|
||||
ExecutionFunction: func,
|
||||
};
|
||||
|
||||
CoreClient._eventItems.push(item);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { Client, REST, Routes, SlashCommandBuilder } from "discord.js";
|
||||
import { EventType } from "../constants/EventType";
|
||||
import IEventItem from "../contracts/IEventItem";
|
||||
import { CoreClient } from "./client";
|
||||
|
||||
|
@ -49,19 +50,46 @@ export class Util {
|
|||
// Load the events
|
||||
loadEvents(client: Client, events: IEventItem[]) {
|
||||
events.forEach((e) => {
|
||||
client.on('channelCreate', e.Event.channelCreate);
|
||||
client.on('channelDelete', e.Event.channelDelete);
|
||||
client.on('channelUpdate', e.Event.channelUpdate);
|
||||
client.on('guildBanAdd', e.Event.guildBanAdd);
|
||||
client.on('guildBanRemove', e.Event.guildBanRemove);
|
||||
client.on('guildCreate', e.Event.guildCreate);
|
||||
client.on('guildMemberAdd', e.Event.guildMemberAdd);
|
||||
client.on('guildMemberRemove', e.Event.guildMemberRemove);
|
||||
client.on('guildMemberUpdate', e.Event.guildMemberUpdate);
|
||||
client.on('messageCreate', e.Event.messageCreate);
|
||||
client.on('messageDelete', e.Event.messageDelete);
|
||||
client.on('messageUpdate', e.Event.messageUpdate);
|
||||
client.on('ready', e.Event.ready);
|
||||
switch(e.EventType) {
|
||||
case EventType.ChannelCreate:
|
||||
client.on('channelCreate', (channel) => e.ExecutionFunction(channel));
|
||||
break;
|
||||
case EventType.ChannelDelete:
|
||||
client.on('channelDelete', (channel) => e.ExecutionFunction(channel));
|
||||
break;
|
||||
case EventType.ChannelUpdate:
|
||||
client.on('channelUpdate', (channel) => e.ExecutionFunction(channel));
|
||||
break;
|
||||
case EventType.GuildBanAdd:
|
||||
client.on('guildBanAdd', (ban) => e.ExecutionFunction(ban));
|
||||
break;
|
||||
case EventType.GuildBanRemove:
|
||||
client.on('guildBanRemove', (ban) => e.ExecutionFunction(ban));
|
||||
break;
|
||||
case EventType.GuildCreate:
|
||||
client.on('guildCreate', (guild) => e.ExecutionFunction(guild));
|
||||
break;
|
||||
case EventType.GuildMemberAdd:
|
||||
client.on('guildMemberAdd', (member) => e.ExecutionFunction(member));
|
||||
break;
|
||||
case EventType.GuildMemberRemove:
|
||||
client.on('guildMemberRemove', (member) => e.ExecutionFunction(member));
|
||||
break;
|
||||
case EventType.GuildMemberUpdate:
|
||||
client.on('guildMemberUpdate', (oldMember, newMember) => e.ExecutionFunction(oldMember, newMember));
|
||||
break;
|
||||
case EventType.MessageCreate:
|
||||
client.on('messageCreate', (message) => e.ExecutionFunction(message));
|
||||
break;
|
||||
case EventType.MessageDelete:
|
||||
client.on('messageDelete', (message) => e.ExecutionFunction(message));
|
||||
break;
|
||||
case EventType.MessageUpdate:
|
||||
client.on('messageUpdate', (oldMessage, newMessage) => e.ExecutionFunction(oldMessage, newMessage));
|
||||
break;
|
||||
default:
|
||||
console.error('Event not implemented.');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
15
src/constants/EventType.ts
Normal file
15
src/constants/EventType.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
export enum EventType {
|
||||
ChannelCreate,
|
||||
ChannelDelete,
|
||||
ChannelUpdate,
|
||||
GuildBanAdd,
|
||||
GuildBanRemove,
|
||||
GuildCreate,
|
||||
GuildMemberAdd,
|
||||
GuildMemberRemove,
|
||||
GuildMemberUpdate,
|
||||
MessageCreate,
|
||||
MessageDelete,
|
||||
MessageUpdate,
|
||||
Ready,
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
import { Event } from "../type/event";
|
||||
import { EventType } from "../constants/EventType";
|
||||
|
||||
export default interface IEventItem {
|
||||
Event: Event,
|
||||
EventType: EventType,
|
||||
ExecutionFunction: Function,
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
import { Event } from "../type/event";
|
||||
import { EmbedBuilder, GuildMember, TextChannel } from "discord.js";
|
||||
import GuildMemberUpdate from "./MemberEvents/GuildMemberUpdate";
|
||||
import SettingsHelper from "../helpers/SettingsHelper";
|
||||
import EmbedColours from "../constants/EmbedColours";
|
||||
|
||||
export default class MemberEvents extends Event {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public override async guildMemberAdd(member: GuildMember) {
|
||||
if (!member.guild) return;
|
||||
|
||||
const enabled = await SettingsHelper.GetSetting("event.member.add.enabled", member.guild.id);
|
||||
if (!enabled || enabled.toLowerCase() != "true") return;
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(EmbedColours.Ok)
|
||||
.setTitle('Member Joined')
|
||||
.setDescription(`${member.user} \`${member.user.tag}\``)
|
||||
.setFooter({ text: `Id: ${member.user.id}` })
|
||||
.addFields([
|
||||
{
|
||||
name: 'Created',
|
||||
value: member.user.createdAt.toISOString(),
|
||||
}
|
||||
]);
|
||||
|
||||
const channelSetting = await SettingsHelper.GetSetting("event.member.add.channel", member.guild.id);
|
||||
|
||||
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) {
|
||||
if (!member.guild) return;
|
||||
|
||||
const enabled = await SettingsHelper.GetSetting("event.member.remove.enabled", member.guild.id);
|
||||
if (!enabled || enabled.toLowerCase() != "true") return;
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(EmbedColours.Ok)
|
||||
.setTitle('Member Left')
|
||||
.setDescription(`${member.user} \`${member.user.tag}\``)
|
||||
.setFooter({ text: `Id: ${member.user.id}` })
|
||||
.addFields([
|
||||
{
|
||||
name: 'Joined',
|
||||
value: member.joinedAt ? member.joinedAt.toISOString() : "*none*",
|
||||
}
|
||||
]);
|
||||
|
||||
const channelSetting = await SettingsHelper.GetSetting("event.member.remove.channel", member.guild.id);
|
||||
|
||||
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) {
|
||||
const handler = new GuildMemberUpdate(oldMember, newMember);
|
||||
|
||||
if (oldMember.nickname != newMember.nickname) { // Nickname change
|
||||
await handler.NicknameChanged();
|
||||
}
|
||||
}
|
||||
}
|
34
src/events/MemberEvents/GuildMemberAdd.ts
Normal file
34
src/events/MemberEvents/GuildMemberAdd.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import { EmbedBuilder, GuildMember, TextChannel } from "discord.js";
|
||||
import EmbedColours from "../../constants/EmbedColours";
|
||||
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||
|
||||
export default async function GuildMemberAdd(member: GuildMember) {
|
||||
if (!member.guild) return;
|
||||
|
||||
const enabled = await SettingsHelper.GetSetting("event.member.add.enabled", member.guild.id);
|
||||
if (!enabled || enabled.toLowerCase() != "true") return;
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(EmbedColours.Ok)
|
||||
.setTitle('Member Joined')
|
||||
.setDescription(`${member.user} \`${member.user.tag}\``)
|
||||
.setFooter({ text: `Id: ${member.user.id}` })
|
||||
.addFields([
|
||||
{
|
||||
name: 'Created',
|
||||
value: member.user.createdAt.toISOString(),
|
||||
}
|
||||
]);
|
||||
|
||||
const channelSetting = await SettingsHelper.GetSetting("event.member.add.channel", member.guild.id);
|
||||
|
||||
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 ]});
|
||||
}
|
34
src/events/MemberEvents/GuildMemberRemove.ts
Normal file
34
src/events/MemberEvents/GuildMemberRemove.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import { EmbedBuilder, GuildMember, TextChannel } from "discord.js";
|
||||
import EmbedColours from "../../constants/EmbedColours";
|
||||
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||
|
||||
export default async function GuildMemberRemove(member: GuildMember) {
|
||||
if (!member.guild) return;
|
||||
|
||||
const enabled = await SettingsHelper.GetSetting("event.member.remove.enabled", member.guild.id);
|
||||
if (!enabled || enabled.toLowerCase() != "true") return;
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(EmbedColours.Ok)
|
||||
.setTitle('Member Left')
|
||||
.setDescription(`${member.user} \`${member.user.tag}\``)
|
||||
.setFooter({ text: `Id: ${member.user.id}` })
|
||||
.addFields([
|
||||
{
|
||||
name: 'Joined',
|
||||
value: member.joinedAt ? member.joinedAt.toISOString() : "*none*",
|
||||
}
|
||||
]);
|
||||
|
||||
const channelSetting = await SettingsHelper.GetSetting("event.member.remove.channel", member.guild.id);
|
||||
|
||||
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 ]});
|
||||
}
|
|
@ -1,49 +1,8 @@
|
|||
import { EmbedBuilder, GuildMember, TextChannel } from "discord.js";
|
||||
import EmbedColours from "../../constants/EmbedColours";
|
||||
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||
import { GuildMember } from "discord.js";
|
||||
import NicknameChanged from "./GuildMemberUpdate/NicknameChanged";
|
||||
|
||||
export default class GuildMemberUpdate {
|
||||
public oldMember: GuildMember;
|
||||
public newMember: GuildMember;
|
||||
|
||||
constructor(oldMember: GuildMember, newMember: GuildMember) {
|
||||
this.oldMember = oldMember;
|
||||
this.newMember = newMember;
|
||||
}
|
||||
|
||||
public async NicknameChanged() {
|
||||
const enabled = await SettingsHelper.GetSetting("event.member.update.enabled", this.newMember.guild.id);
|
||||
if (!enabled || enabled.toLowerCase() != "true") return;
|
||||
|
||||
const oldNickname = this.oldMember.nickname || "*none*";
|
||||
const newNickname = this.newMember.nickname || "*none*";
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(EmbedColours.Ok)
|
||||
.setTitle('Nickname Changed')
|
||||
.setDescription(`${this.newMember.user} \`${this.newMember.user.tag}\``)
|
||||
.setFooter({ text: `Id: ${this.newMember.user.id}` })
|
||||
.addFields([
|
||||
{
|
||||
name: 'Before',
|
||||
value: oldNickname,
|
||||
},
|
||||
{
|
||||
name: 'After',
|
||||
value: newNickname,
|
||||
},
|
||||
]);
|
||||
|
||||
const channelSetting = await SettingsHelper.GetSetting("event.member.update.channel", this.newMember.guild.id);
|
||||
|
||||
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 ]});
|
||||
export default async function GuildMemberUpdate(oldMember: GuildMember, newMember: GuildMember) {
|
||||
if (oldMember.nickname != newMember.nickname) { // Nickname change
|
||||
await NicknameChanged(oldMember, newMember);
|
||||
}
|
||||
}
|
39
src/events/MemberEvents/GuildMemberUpdate/NicknameChanged.ts
Normal file
39
src/events/MemberEvents/GuildMemberUpdate/NicknameChanged.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
import { EmbedBuilder, GuildMember, TextChannel } from "discord.js";
|
||||
import EmbedColours from "../../../constants/EmbedColours";
|
||||
import SettingsHelper from "../../../helpers/SettingsHelper";
|
||||
|
||||
export default async function NicknameChanged(oldMember: GuildMember, newMember: GuildMember) {
|
||||
const enabled = await SettingsHelper.GetSetting("event.member.update.enabled", newMember.guild.id);
|
||||
if (!enabled || enabled.toLowerCase() != "true") return;
|
||||
|
||||
const oldNickname = oldMember.nickname || "*none*";
|
||||
const newNickname = newMember.nickname || "*none*";
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(EmbedColours.Ok)
|
||||
.setTitle('Nickname Changed')
|
||||
.setDescription(`${newMember.user} \`${newMember.user.tag}\``)
|
||||
.setFooter({ text: `Id: ${newMember.user.id}` })
|
||||
.addFields([
|
||||
{
|
||||
name: 'Before',
|
||||
value: oldNickname,
|
||||
},
|
||||
{
|
||||
name: 'After',
|
||||
value: newNickname,
|
||||
},
|
||||
]);
|
||||
|
||||
const channelSetting = await SettingsHelper.GetSetting("event.member.update.channel", newMember.guild.id);
|
||||
|
||||
if (!channelSetting) return;
|
||||
|
||||
const channel = newMember.guild.channels.cache.find(x => x.name == channelSetting);
|
||||
|
||||
if (!channel) return;
|
||||
|
||||
const guildChannel = channel as TextChannel;
|
||||
|
||||
await guildChannel.send({ embeds: [embed ]});
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
import { Event } from "../type/event";
|
||||
import { EmbedBuilder, Message, TextChannel } from "discord.js";
|
||||
import SettingsHelper from "../helpers/SettingsHelper";
|
||||
import OnMessage from "./MessageEvents/OnMessage";
|
||||
import IgnoredChannel from "../entity/IgnoredChannel";
|
||||
import EmbedColours from "../constants/EmbedColours";
|
||||
|
||||
export default class MessageEvents extends Event {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public override async messageDelete(message: Message) {
|
||||
if (!message.guild) return;
|
||||
if (message.author.bot) return;
|
||||
|
||||
const enabled = await SettingsHelper.GetSetting("event.message.delete.enabled", message.guild.id);
|
||||
if (!enabled || enabled.toLowerCase() != "true") return;
|
||||
|
||||
const ignored = await IgnoredChannel.IsChannelIgnored(message.channel.id);
|
||||
if (ignored) return;
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(EmbedColours.Ok)
|
||||
.setTitle("Message Deleted")
|
||||
.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) {
|
||||
embed.addFields([
|
||||
{
|
||||
name: "Attachments",
|
||||
value: `\`\`\`${message.attachments.map(x => x.url).join("\n")}\`\`\``
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
const channelSetting = await SettingsHelper.GetSetting("event.message.delete.channel", message.guild.id);
|
||||
|
||||
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) {
|
||||
if (!newMessage.guild) return;
|
||||
if (newMessage.author.bot) return;
|
||||
if (oldMessage.content == newMessage.content) return;
|
||||
|
||||
const enabled = await SettingsHelper.GetSetting("event.message.update.enabled", newMessage.guild.id);
|
||||
if (!enabled || enabled.toLowerCase() != "true") return;
|
||||
|
||||
const ignored = await IgnoredChannel.IsChannelIgnored(newMessage.channel.id);
|
||||
if (ignored) return;
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(EmbedColours.Ok)
|
||||
.setTitle("Message Deleted")
|
||||
.setDescription(`${newMessage.author} \`${newMessage.author.tag}\``)
|
||||
.addFields([
|
||||
{
|
||||
name: "Channel",
|
||||
value: newMessage.channel.toString(),
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "Before",
|
||||
value: `\`\`\`${oldMessage.content || "*none*"}\`\`\``,
|
||||
},
|
||||
{
|
||||
name: "After",
|
||||
value: `\`\`\`${newMessage.content || "*none*"}\`\`\``,
|
||||
}
|
||||
]);
|
||||
|
||||
const channelSetting = await SettingsHelper.GetSetting("event.message.delete.channel", newMessage.guild.id);
|
||||
|
||||
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) {
|
||||
if (!message.guild) return;
|
||||
if (message.author.bot) return;
|
||||
|
||||
const isVerificationEnabled = await SettingsHelper.GetSetting("verification.enabled", message.guild.id);
|
||||
|
||||
if (isVerificationEnabled && isVerificationEnabled.toLocaleLowerCase() == "true") {
|
||||
await OnMessage.VerificationCheck(message);
|
||||
}
|
||||
}
|
||||
}
|
14
src/events/MessageEvents/MessageCreate.ts
Normal file
14
src/events/MessageEvents/MessageCreate.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { Message } from "discord.js";
|
||||
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||
import VerificationCheck from "./MessageCreate/VerificationCheck";
|
||||
|
||||
export default async function MessageCreate(message: Message) {
|
||||
if (!message.guild) return;
|
||||
if (message.author.bot) return;
|
||||
|
||||
const isVerificationEnabled = await SettingsHelper.GetSetting("verification.enabled", message.guild.id);
|
||||
|
||||
if (isVerificationEnabled && isVerificationEnabled.toLocaleLowerCase() == "true") {
|
||||
await VerificationCheck(message);
|
||||
}
|
||||
}
|
57
src/events/MessageEvents/MessageCreate/VerificationCheck.ts
Normal file
57
src/events/MessageEvents/MessageCreate/VerificationCheck.ts
Normal file
|
@ -0,0 +1,57 @@
|
|||
import { Message } from "discord.js";
|
||||
import SettingsHelper from "../../../helpers/SettingsHelper";
|
||||
|
||||
export default async function VerificationCheck(message: Message) {
|
||||
if (!message.guild) return;
|
||||
|
||||
const verificationChannel = await SettingsHelper.GetSetting("verification.channel", message.guild.id);
|
||||
|
||||
if (!verificationChannel) {
|
||||
return;
|
||||
}
|
||||
|
||||
const channel = message.guild.channels.cache.find(x => x.name == verificationChannel);
|
||||
|
||||
if (!channel) {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentChannel = message.guild.channels.cache.find(x => x == message.channel);
|
||||
|
||||
if (!currentChannel || currentChannel.name != verificationChannel) {
|
||||
return;
|
||||
}
|
||||
|
||||
const verificationCode = await SettingsHelper.GetSetting("verification.code", message.guild.id);
|
||||
|
||||
if (!verificationCode || verificationCode == "") {
|
||||
await message.reply("`verification.code` is not set inside of the server's config. Please contact the server's mod team.");
|
||||
await message.delete();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const verificationRoleName = await SettingsHelper.GetSetting("verification.role", message.guild.id);
|
||||
|
||||
if (!verificationRoleName) {
|
||||
await message.reply("`verification.role` is not set inside of the server's config. Please contact the server's mod team.");
|
||||
await message.delete();
|
||||
return;
|
||||
}
|
||||
|
||||
const role = message.guild.roles.cache.find(x => x.name == verificationRoleName);
|
||||
|
||||
if (!role) {
|
||||
await message.reply("The entry role configured for this server does not exist. Please contact the server's mod team.");
|
||||
await message.delete();
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.content.toLocaleLowerCase() != verificationCode.toLocaleLowerCase()) {
|
||||
await message.delete();
|
||||
return;
|
||||
}
|
||||
|
||||
await message.member?.roles.add(role);
|
||||
await message.delete();
|
||||
}
|
52
src/events/MessageEvents/MessageDelete.ts
Normal file
52
src/events/MessageEvents/MessageDelete.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
import { EmbedBuilder, Message, TextChannel } from "discord.js";
|
||||
import EmbedColours from "../../constants/EmbedColours";
|
||||
import IgnoredChannel from "../../entity/IgnoredChannel";
|
||||
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||
|
||||
export default async function MessageDelete(message: Message) {
|
||||
if (!message.guild) return;
|
||||
if (message.author.bot) return;
|
||||
|
||||
const enabled = await SettingsHelper.GetSetting("event.message.delete.enabled", message.guild.id);
|
||||
if (!enabled || enabled.toLowerCase() != "true") return;
|
||||
|
||||
const ignored = await IgnoredChannel.IsChannelIgnored(message.channel.id);
|
||||
if (ignored) return;
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(EmbedColours.Ok)
|
||||
.setTitle("Message Deleted")
|
||||
.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) {
|
||||
embed.addFields([
|
||||
{
|
||||
name: "Attachments",
|
||||
value: `\`\`\`${message.attachments.map(x => x.url).join("\n")}\`\`\``
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
const channelSetting = await SettingsHelper.GetSetting("event.message.delete.channel", message.guild.id);
|
||||
|
||||
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 ]});
|
||||
}
|
48
src/events/MessageEvents/MessageUpdate.ts
Normal file
48
src/events/MessageEvents/MessageUpdate.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
import { EmbedBuilder, Message, TextChannel } from "discord.js";
|
||||
import EmbedColours from "../../constants/EmbedColours";
|
||||
import IgnoredChannel from "../../entity/IgnoredChannel";
|
||||
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||
|
||||
export default async function MessageUpdate(oldMessage: Message, newMessage: Message) {
|
||||
if (!newMessage.guild) return;
|
||||
if (newMessage.author.bot) return;
|
||||
if (oldMessage.content == newMessage.content) return;
|
||||
|
||||
const enabled = await SettingsHelper.GetSetting("event.message.update.enabled", newMessage.guild.id);
|
||||
if (!enabled || enabled.toLowerCase() != "true") return;
|
||||
|
||||
const ignored = await IgnoredChannel.IsChannelIgnored(newMessage.channel.id);
|
||||
if (ignored) return;
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(EmbedColours.Ok)
|
||||
.setTitle("Message Edited")
|
||||
.setDescription(`${newMessage.author} \`${newMessage.author.tag}\``)
|
||||
.addFields([
|
||||
{
|
||||
name: "Channel",
|
||||
value: newMessage.channel.toString(),
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: "Before",
|
||||
value: `\`\`\`${oldMessage.content || "*none*"}\`\`\``,
|
||||
},
|
||||
{
|
||||
name: "After",
|
||||
value: `\`\`\`${newMessage.content || "*none*"}\`\`\``,
|
||||
}
|
||||
]);
|
||||
|
||||
const channelSetting = await SettingsHelper.GetSetting("event.message.delete.channel", newMessage.guild.id);
|
||||
|
||||
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 ]});
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
import { Message as Message } from "discord.js";
|
||||
import SettingsHelper from "../../helpers/SettingsHelper";
|
||||
|
||||
export default class OnMessage {
|
||||
public static async VerificationCheck(message: Message) {
|
||||
if (!message.guild) return;
|
||||
|
||||
const verificationChannel = await SettingsHelper.GetSetting("verification.channel", message.guild.id);
|
||||
|
||||
if (!verificationChannel) {
|
||||
return;
|
||||
}
|
||||
|
||||
const channel = message.guild.channels.cache.find(x => x.name == verificationChannel);
|
||||
|
||||
if (!channel) {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentChannel = message.guild.channels.cache.find(x => x == message.channel);
|
||||
|
||||
if (!currentChannel || currentChannel.name != verificationChannel) {
|
||||
return;
|
||||
}
|
||||
|
||||
const verificationCode = await SettingsHelper.GetSetting("verification.code", message.guild.id);
|
||||
|
||||
if (!verificationCode || verificationCode == "") {
|
||||
await message.reply("`verification.code` is not set inside of the server's config. Please contact the server's mod team.");
|
||||
await message.delete();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const verificationRoleName = await SettingsHelper.GetSetting("verification.role", message.guild.id);
|
||||
|
||||
if (!verificationRoleName) {
|
||||
await message.reply("`verification.role` is not set inside of the server's config. Please contact the server's mod team.");
|
||||
await message.delete();
|
||||
return;
|
||||
}
|
||||
|
||||
const role = message.guild.roles.cache.find(x => x.name == verificationRoleName);
|
||||
|
||||
if (!role) {
|
||||
await message.reply("The entry role configured for this server does not exist. Please contact the server's mod team.");
|
||||
await message.delete();
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.content.toLocaleLowerCase() != verificationCode.toLocaleLowerCase()) {
|
||||
await message.delete();
|
||||
return;
|
||||
}
|
||||
|
||||
await message.member?.roles.add(role);
|
||||
await message.delete();
|
||||
}
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
import { CoreClient } from "./client/client";
|
||||
import { EventType } from "./constants/EventType";
|
||||
|
||||
// Command Imports
|
||||
import About from "./commands/about";
|
||||
import Audits from "./commands/audits";
|
||||
import Ban from "./commands/ban";
|
||||
import Bunny from "./commands/bunny";
|
||||
import Clear from "./commands/clear";
|
||||
import Code from "./commands/code";
|
||||
import Config from "./commands/config";
|
||||
|
@ -25,9 +27,12 @@ import AddLobby from "./commands/501231711271780357/Lobby/add";
|
|||
import RemoveLobby from "./commands/501231711271780357/Lobby/remove";
|
||||
|
||||
// Event Imports
|
||||
import MemberEvents from "./events/MemberEvents";
|
||||
import MessageEvents from "./events/MessageEvents";
|
||||
import Bunny from "./commands/bunny";
|
||||
import GuildMemberAdd from "./events/MemberEvents/GuildMemberAdd";
|
||||
import GuildMemberRemove from "./events/MemberEvents/GuildMemberRemove";
|
||||
import GuildMemberUpdate from "./events/MemberEvents/GuildMemberUpdate";
|
||||
import MessageDelete from "./events/MessageEvents/MessageDelete";
|
||||
import MessageUpdate from "./events/MessageEvents/MessageUpdate";
|
||||
import MessageCreate from "./events/MessageEvents/MessageCreate";
|
||||
|
||||
export default class Registry {
|
||||
public static RegisterCommands() {
|
||||
|
@ -64,7 +69,12 @@ export default class Registry {
|
|||
}
|
||||
|
||||
public static RegisterEvents() {
|
||||
CoreClient.RegisterEvent(new MemberEvents());
|
||||
CoreClient.RegisterEvent(new MessageEvents());
|
||||
CoreClient.RegisterEvent(EventType.GuildMemberAdd, GuildMemberAdd);
|
||||
CoreClient.RegisterEvent(EventType.GuildMemberRemove, GuildMemberRemove);
|
||||
CoreClient.RegisterEvent(EventType.GuildMemberUpdate, GuildMemberUpdate);
|
||||
|
||||
CoreClient.RegisterEvent(EventType.MessageDelete, MessageDelete);
|
||||
CoreClient.RegisterEvent(EventType.MessageUpdate, MessageUpdate);
|
||||
CoreClient.RegisterEvent(EventType.MessageCreate, MessageCreate);
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
import { Channel, Guild, GuildMember, Message, PartialDMChannel, PartialGuildMember, PartialMessage, GuildBan } from "discord.js";
|
||||
|
||||
export class Event {
|
||||
public channelCreate(channel: Channel) {
|
||||
|
||||
}
|
||||
|
||||
public channelDelete(channel: Channel | PartialDMChannel) {
|
||||
|
||||
}
|
||||
|
||||
public channelUpdate(oldChannel: Channel, newChannel: Channel) {
|
||||
|
||||
}
|
||||
|
||||
public guildBanAdd(ban: GuildBan) {
|
||||
|
||||
}
|
||||
|
||||
public guildBanRemove(ban: GuildBan) {
|
||||
|
||||
}
|
||||
|
||||
public guildCreate(guild: Guild) {
|
||||
|
||||
}
|
||||
|
||||
public guildMemberAdd(member: GuildMember) {
|
||||
|
||||
}
|
||||
|
||||
public guildMemberRemove(member: GuildMember | PartialGuildMember) {
|
||||
|
||||
}
|
||||
|
||||
public guildMemberUpdate(oldMember: GuildMember | PartialGuildMember, newMember: GuildMember) {
|
||||
|
||||
}
|
||||
|
||||
public messageCreate(message: Message) {
|
||||
|
||||
}
|
||||
|
||||
public messageDelete(message: Message | PartialMessage) {
|
||||
|
||||
}
|
||||
|
||||
public messageUpdate(oldMessage: Message | PartialMessage, newMessage: Message | PartialMessage) {
|
||||
|
||||
}
|
||||
|
||||
public ready() {
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue