Migrate events to typescript
This commit is contained in:
parent
24818bcb44
commit
44571d735a
10 changed files with 155 additions and 142 deletions
|
@ -1,32 +0,0 @@
|
|||
// Required components
|
||||
const { event } = require('vylbot-core');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
// Event variables
|
||||
const embedColor = "0x3050ba";
|
||||
const logchannel = "member-logs";
|
||||
|
||||
// Event class
|
||||
class guildmemberadd extends event {
|
||||
constructor() {
|
||||
// Set the event's run method
|
||||
super("guildmemberadd");
|
||||
}
|
||||
|
||||
// Run method
|
||||
guildmemberadd(member) {
|
||||
// Create an embed with the user who joined's information
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle("Member Joined")
|
||||
.setColor(embedColor)
|
||||
.addField("User", `${member} \`${member.user.tag}\``)
|
||||
.addField("Created", `${member.user.createdAt}`)
|
||||
.setFooter(`User ID: ${member.user.id}`)
|
||||
.setThumbnail(member.user.displayAvatarURL({ type: 'png', dynamic: true }));
|
||||
|
||||
// Send the embed in the mod's log channel
|
||||
member.guild.channels.cache.find(channel => channel.name == logchannel).send(embed);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = guildmemberadd;
|
|
@ -1,32 +0,0 @@
|
|||
// Required components
|
||||
const { event } = require('vylbot-core');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
// Event variables
|
||||
const embedColor = "0x3050ba";
|
||||
const logchannel = "member-logs";
|
||||
|
||||
// Event class
|
||||
class guildmemberremove extends event {
|
||||
constructor() {
|
||||
// Set the event's run method
|
||||
super("guildmemberremove");
|
||||
}
|
||||
|
||||
// Run method
|
||||
guildmemberremove(member) {
|
||||
// Create an embed with the user's information
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle("Member Left")
|
||||
.setColor(embedColor)
|
||||
.addField("User", `${member} \`${member.user.tag}\``)
|
||||
.addField("Joined", `${member.joinedAt}`)
|
||||
.setFooter(`User ID: ${member.user.id}`)
|
||||
.setThumbnail(member.user.displayAvatarURL({ type: 'png', dynamic: true }));
|
||||
|
||||
// Send the embed in the log channel
|
||||
member.guild.channels.cache.find(channel => channel.name == logchannel).send(embed);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = guildmemberremove;
|
|
@ -1,41 +0,0 @@
|
|||
// Required components
|
||||
const { event } = require('vylbot-core');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
// Event variables
|
||||
const embedColor = "0x3050ba";
|
||||
const logchannel = "member-logs";
|
||||
|
||||
// Event class
|
||||
class guildmemberupdate extends event {
|
||||
constructor() {
|
||||
// Set the event's run method
|
||||
super("guildmemberupdate");
|
||||
}
|
||||
|
||||
// Run method
|
||||
guildmemberupdate(oldMember, newMember) {
|
||||
// If the user's nickname was changed
|
||||
if (oldMember.nickname != newMember.nickname) {
|
||||
// Get the user's name with tag, their old nickname and their new nickname
|
||||
// If they didn't have a nickname or they removed it, set it to "none" in italics
|
||||
const oldNickname = oldMember.nickname || "*none*";
|
||||
const newNickname = newMember.nickname || "*none*";
|
||||
|
||||
// Create the embed with the user's information
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle("Nickname Changed")
|
||||
.setColor(embedColor)
|
||||
.addField("User", `${newMember} \`${newMember.user.tag}\``)
|
||||
.addField("Before", oldNickname, true)
|
||||
.addField("After", newNickname, true)
|
||||
.setFooter(`User ID: ${newMember.user.id}`)
|
||||
.setThumbnail(newMember.user.displayAvatarURL({ type: 'png', dynamic: true }));
|
||||
|
||||
// Send the embed in the log channel
|
||||
newMember.guild.channels.cache.find(channel => channel.name == logchannel).send(embed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = guildmemberupdate;
|
|
@ -1,32 +0,0 @@
|
|||
// Required components
|
||||
const { event } = require('vylbot-core');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
// Event variables
|
||||
const embedColor = "0x3050ba";
|
||||
const logchannel = "message-logs";
|
||||
|
||||
// Event class
|
||||
class messagedelete extends event {
|
||||
constructor() {
|
||||
// The event's run method
|
||||
super("messagedelete");
|
||||
}
|
||||
|
||||
// Run method
|
||||
messagedelete(message) {
|
||||
// Create an embed with the message's information
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle("Message Deleted")
|
||||
.setColor(embedColor)
|
||||
.addField("User", `${message.author} \`${message.author.tag}\``)
|
||||
.addField("Channel", message.channel)
|
||||
.addField("Content", `\`\`\`${message.content || "*none*"}\`\`\``)
|
||||
.setThumbnail(message.author.displayAvatarURL({ type: 'png', dynamic: true }));
|
||||
|
||||
// Send the embed in the logging channel
|
||||
message.guild.channels.cache.find(channel => channel.name == logchannel).send(embed);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = messagedelete;
|
|
@ -20,7 +20,7 @@
|
|||
"dotenv": "^10.0.0",
|
||||
"emoji-regex": "^9.2.0",
|
||||
"random-bunny": "^2.0.0",
|
||||
"vylbot-core": "^2.0.2"
|
||||
"vylbot-core": "^2.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.11.10",
|
||||
|
|
36
src/events/MemberEvents.ts
Normal file
36
src/events/MemberEvents.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
import { Event } from "vylbot-core";
|
||||
import { GuildMember } from "discord.js";
|
||||
import EventEmbed from "../helpers/EventEmbed";
|
||||
import GuildMemberUpdate from "./MemberEvents/GuildMemberUpdate";
|
||||
|
||||
export default class MemberEvents extends Event {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public override guildMemberAdd(member: GuildMember) {
|
||||
const embed = new EventEmbed(member.guild, "Member Joined");
|
||||
embed.AddUser("User", member.user, true);
|
||||
embed.addField("Created", member.user.createdAt);
|
||||
embed.setFooter(`Id: ${member.user.id}`);
|
||||
|
||||
embed.SendToMemberLogsChannel();
|
||||
}
|
||||
|
||||
public override guildMemberRemove(member: GuildMember) {
|
||||
const embed = new EventEmbed(member.guild, "Member Left");
|
||||
embed.AddUser("User", member.user, true);
|
||||
embed.addField("Joined", member.joinedAt);
|
||||
embed.setFooter(`Id: ${member.user.id}`);
|
||||
|
||||
embed.SendToMemberLogsChannel();
|
||||
}
|
||||
|
||||
public override guildMemberUpdate(oldMember: GuildMember, newMember: GuildMember) {
|
||||
const handler = new GuildMemberUpdate(oldMember, newMember);
|
||||
|
||||
if (oldMember.nickname != newMember.nickname) { // Nickname change
|
||||
handler.NicknameChanged();
|
||||
}
|
||||
}
|
||||
}
|
25
src/events/MemberEvents/GuildMemberUpdate.ts
Normal file
25
src/events/MemberEvents/GuildMemberUpdate.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { GuildMember } from "discord.js";
|
||||
import EventEmbed from "../../helpers/EventEmbed";
|
||||
|
||||
export default class GuildMemberUpdate {
|
||||
private _oldMember: GuildMember;
|
||||
private _newMember: GuildMember;
|
||||
|
||||
constructor(oldMember: GuildMember, newMember: GuildMember) {
|
||||
this._oldMember = oldMember;
|
||||
this._newMember = newMember;
|
||||
}
|
||||
|
||||
public NicknameChanged() {
|
||||
const oldNickname = this._oldMember.nickname || "*none*";
|
||||
const newNickname = this._newMember.nickname || "*none*";
|
||||
|
||||
const embed = new EventEmbed(this._newMember.guild, "Nickname Changed");
|
||||
embed.AddUser("User", this._newMember.user, true);
|
||||
embed.addField("Before", oldNickname, true);
|
||||
embed.addField("After", newNickname, true);
|
||||
embed.setFooter(`Id: ${this._newMember.user.id}`);
|
||||
|
||||
embed.SendToMemberLogsChannel();
|
||||
}
|
||||
}
|
35
src/events/MessageEvents.ts
Normal file
35
src/events/MessageEvents.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
import { Event } from "vylbot-core";
|
||||
import { Message } from "discord.js";
|
||||
import EventEmbed from "../helpers/EventEmbed";
|
||||
|
||||
export default class MessageEvents extends Event {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public override messageDelete(message: Message) {
|
||||
if (!message.guild) return;
|
||||
|
||||
const embed = new EventEmbed(message.guild, "Message Deleted");
|
||||
embed.AddUser("User", message.author, true);
|
||||
embed.addField("Channel", message.channel, true);
|
||||
embed.addField("Content", `\`\`\`${message.content || "*none*"}\`\`\``);
|
||||
embed.addField("Attachments", `\`\`\`${message.attachments.map(x => x.url).join("\n")}`);
|
||||
|
||||
embed.SendToMessageLogsChannel();
|
||||
}
|
||||
|
||||
public override messageUpdate(oldMessage: Message, newMessage: Message) {
|
||||
if (!newMessage.guild) return;
|
||||
if (newMessage.author.bot) return;
|
||||
if (oldMessage.content == newMessage.content) return;
|
||||
|
||||
const embed = new EventEmbed(newMessage.guild, "Message Edited");
|
||||
embed.AddUser("User", newMessage.author, true);
|
||||
embed.addField("Channel", newMessage.channel, true);
|
||||
embed.addField("Before", `\`\`\`${oldMessage.content || "*none*"}\`\`\``);
|
||||
embed.addField("After", `\`\`\`${newMessage.content || "*none*"}\`\`\``);
|
||||
|
||||
embed.SendToMessageLogsChannel();
|
||||
}
|
||||
}
|
54
src/helpers/EventEmbed.ts
Normal file
54
src/helpers/EventEmbed.ts
Normal file
|
@ -0,0 +1,54 @@
|
|||
import { MessageEmbed, TextChannel, User, Guild } from "discord.js";
|
||||
import ErrorMessages from "../constants/ErrorMessages";
|
||||
import ErrorEmbed from "./ErrorEmbed";
|
||||
|
||||
export default class EventEmbed extends MessageEmbed {
|
||||
private _guild: Guild;
|
||||
|
||||
constructor(guild: Guild, title: string) {
|
||||
super();
|
||||
|
||||
super.setColor(process.env.EMBED_COLOUR!);
|
||||
super.setTitle(title);
|
||||
|
||||
this._guild = guild;
|
||||
}
|
||||
|
||||
// Detail methods
|
||||
public AddUser(title: string, user: User, setThumbnail: boolean = false) {
|
||||
super.addField(title, `${user} \`${user.tag}\``, true);
|
||||
|
||||
if (setThumbnail) {
|
||||
super.setThumbnail(user.displayAvatarURL());
|
||||
}
|
||||
}
|
||||
|
||||
public AddReason(message: String) {
|
||||
super.addField("Reason", message || "*none*");
|
||||
}
|
||||
|
||||
// Send methods
|
||||
public SendToChannel(name: string) {
|
||||
const channel = this._guild.channels.cache
|
||||
.find(channel => channel.name == name) as TextChannel;
|
||||
|
||||
if (!channel) {
|
||||
console.error(`Unable to find channel ${name}`);
|
||||
return;
|
||||
}
|
||||
|
||||
channel.send(this);
|
||||
}
|
||||
|
||||
public SendToMessageLogsChannel() {
|
||||
this.SendToChannel(process.env.CHANNELS_LOGS_MESSAGE!)
|
||||
}
|
||||
|
||||
public SendToMemberLogsChannel() {
|
||||
this.SendToChannel(process.env.CHANNELS_LOGS_MEMBER!)
|
||||
}
|
||||
|
||||
public SendToModLogsChannel() {
|
||||
this.SendToChannel(process.env.CHANNELS_LOGS_MOD!)
|
||||
}
|
||||
}
|
|
@ -1131,10 +1131,10 @@ v8-compile-cache@^2.0.3:
|
|||
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee"
|
||||
integrity sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==
|
||||
|
||||
vylbot-core@^2.0.2:
|
||||
version "2.0.2"
|
||||
resolved "https://registry.yarnpkg.com/vylbot-core/-/vylbot-core-2.0.2.tgz#8f83b836b423e9f0812abb86368672716dc1fa75"
|
||||
integrity sha512-Og+cdPG+ExjzjhqVDb1hac7pm6KfLvT85NMBoL7hfbSPsg11wFwLKI6toqVnbvbqMKzKnOpIvijo4jx+fdUDsA==
|
||||
vylbot-core@^2.0.3:
|
||||
version "2.0.3"
|
||||
resolved "https://registry.yarnpkg.com/vylbot-core/-/vylbot-core-2.0.3.tgz#e7d844bc54e72b14f06f14b63866854e3b846d55"
|
||||
integrity sha512-RxABRcwhVIVZcIssVP8yosLlUXzcdrNLiYJzcvkAIz4KeHfoARcxjsz2vG2x9GIzeFpfn/hjrPvjFC5lN6zclw==
|
||||
dependencies:
|
||||
discord.js "^12.3.1"
|
||||
dotenv "^10.0.0"
|
||||
|
|
Loading…
Reference in a new issue