Updated Event Types

This commit is contained in:
Ahmad 2025-03-01 00:32:51 -05:00
parent 3762e554b4
commit e59415ac62
No known key found for this signature in database
GPG key ID: 8FD8A93530D182BF
7 changed files with 54 additions and 24 deletions

View file

@ -1,13 +1,15 @@
import {
AuditLogEvent,
ChannelType,
DMChannel,
Events,
GuildChannel,
PermissionOverwrites,
} from 'discord.js';
import logAction from '../util/logging/logAction.js';
import { ChannelLogAction } from '../util/logging/types.js';
import { Event } from '../types/EventTypes.js';
import logAction from '../util/logging/logAction.js';
function arePermissionsEqual(
oldPerms: Map<string, PermissionOverwrites>,
@ -93,7 +95,7 @@ function getPermissionChanges(
return changes;
}
export const channelCreate = {
export const channelCreate: Event<typeof Events.ChannelCreate> = {
name: Events.ChannelCreate,
execute: async (channel: GuildChannel) => {
try {
@ -119,10 +121,12 @@ export const channelCreate = {
},
};
export const channelDelete = {
export const channelDelete: Event<typeof Events.ChannelDelete> = {
name: Events.ChannelDelete,
execute: async (channel: GuildChannel) => {
execute: async (channel: GuildChannel | DMChannel) => {
try {
if (channel.type === ChannelType.DM) return;
const { guild } = channel;
const auditLogs = await guild.fetchAuditLogs({
type: AuditLogEvent.ChannelDelete,
@ -145,10 +149,19 @@ export const channelDelete = {
},
};
export const channelUpdate = {
export const channelUpdate: Event<typeof Events.ChannelUpdate> = {
name: Events.ChannelUpdate,
execute: async (oldChannel: GuildChannel, newChannel: GuildChannel) => {
execute: async (
oldChannel: GuildChannel | DMChannel,
newChannel: GuildChannel | DMChannel,
) => {
try {
if (
oldChannel.type === ChannelType.DM ||
newChannel.type === ChannelType.DM
) {
return;
}
if (
oldChannel.name === newChannel.name &&
oldChannel.type === newChannel.type &&

View file

@ -1,5 +1,7 @@
import { Events, Interaction } from 'discord.js';
import { ExtendedClient } from '../structures/ExtendedClient.js';
import { Event } from '../types/EventTypes.js';
export default {
name: Events.InteractionCreate,
@ -35,4 +37,4 @@ export default {
}
}
},
};
} as Event<typeof Events.InteractionCreate>;

View file

@ -1,10 +1,12 @@
import { Events, GuildMember } from 'discord.js';
import { Events, Guild, GuildMember, PartialGuildMember } from 'discord.js';
import { updateMember, setMembers } from '../db/db.js';
import { generateMemberBanner } from '../util/helpers.js';
import { loadConfig } from '../util/configLoader.js';
import { Event } from '../types/EventTypes.js';
import logAction from '../util/logging/logAction.js';
export const memberJoin = {
export const memberJoin: Event<typeof Events.GuildMemberAdd> = {
name: Events.GuildMemberAdd,
execute: async (member: GuildMember) => {
const { guild } = member;
@ -54,9 +56,9 @@ export const memberJoin = {
},
};
export const memberLeave = {
export const memberLeave: Event<typeof Events.GuildMemberRemove> = {
name: Events.GuildMemberRemove,
execute: async (member: GuildMember) => {
execute: async (member: GuildMember | PartialGuildMember) => {
const { guild } = member;
try {
@ -68,7 +70,7 @@ export const memberLeave = {
logAction({
guild,
action: 'memberLeave',
member,
member: member as GuildMember,
}),
]);
} catch (error) {
@ -77,9 +79,12 @@ export const memberLeave = {
},
};
export const memberUpdate = {
export const memberUpdate: Event<typeof Events.GuildMemberUpdate> = {
name: Events.GuildMemberUpdate,
execute: async (oldMember: GuildMember, newMember: GuildMember) => {
execute: async (
oldMember: GuildMember | PartialGuildMember,
newMember: GuildMember,
) => {
const { guild } = newMember;
try {

View file

@ -1,9 +1,13 @@
import { AuditLogEvent, Events, Message } from 'discord.js';
import { AuditLogEvent, Events, Message, PartialMessage } from 'discord.js';
import { Event } from '../types/EventTypes.js';
import logAction from '../util/logging/logAction.js';
export const messageDelete = {
export const messageDelete: Event<typeof Events.MessageDelete> = {
name: Events.MessageDelete,
execute: async (message: Message) => {
execute: async (
message: Omit<Partial<Message<boolean> | PartialMessage>, 'channel'>,
) => {
try {
if (!message.guild || message.author?.bot) return;
@ -30,9 +34,12 @@ export const messageDelete = {
},
};
export const messageUpdate = {
export const messageUpdate: Event<typeof Events.MessageUpdate> = {
name: Events.MessageUpdate,
execute: async (oldMessage: Message, newMessage: Message) => {
execute: async (
oldMessage: Omit<Partial<Message<boolean> | PartialMessage>, 'channel'>,
newMessage: Message,
) => {
try {
if (
!oldMessage.guild ||

View file

@ -2,6 +2,7 @@ import { Client, Events } from 'discord.js';
import { setMembers } from '../db/db.js';
import { loadConfig } from '../util/configLoader.js';
import { Event } from '../types/EventTypes.js';
export default {
name: Events.ClientReady,
@ -16,4 +17,4 @@ export default {
console.log(`Ready! Logged in as ${client.user?.tag}`);
},
};
} as Event<typeof Events.ClientReady>;

View file

@ -1,4 +1,6 @@
import { AuditLogEvent, Events, Role } from 'discord.js';
import { Event } from '../types/EventTypes.js';
import logAction from '../util/logging/logAction.js';
const convertRoleProperties = (role: Role) => ({
@ -8,7 +10,7 @@ const convertRoleProperties = (role: Role) => ({
mentionable: role.mentionable,
});
export const roleCreate = {
export const roleCreate: Event<typeof Events.GuildRoleCreate> = {
name: Events.GuildRoleCreate,
execute: async (role: Role) => {
try {
@ -34,7 +36,7 @@ export const roleCreate = {
},
};
export const roleDelete = {
export const roleDelete: Event<typeof Events.GuildRoleDelete> = {
name: Events.GuildRoleDelete,
execute: async (role: Role) => {
try {
@ -60,7 +62,7 @@ export const roleDelete = {
},
};
export const roleUpdate = {
export const roleUpdate: Event<typeof Events.GuildRoleUpdate> = {
name: Events.GuildRoleUpdate,
execute: async (oldRole: Role, newRole: Role) => {
try {

View file

@ -376,7 +376,7 @@ export default async function logAction(payload: LogActionPayload) {
case 'channelCreate':
case 'channelDelete': {
fields.push(
{ name: 'Channel', value: `<#${payload.channel.id}>`, inline: true },
{ name: 'Channel', value: `<#${payload.channel.id}> (#${payload.channel.name})`, inline: true },
{
name: 'Type',
value: