mirror of
https://github.com/ahmadk953/poixpixel-discord-bot.git
synced 2025-04-02 09:44:14 +00:00
Updated Event Types
This commit is contained in:
parent
3762e554b4
commit
e59415ac62
7 changed files with 54 additions and 24 deletions
|
@ -1,13 +1,15 @@
|
||||||
import {
|
import {
|
||||||
AuditLogEvent,
|
AuditLogEvent,
|
||||||
|
ChannelType,
|
||||||
|
DMChannel,
|
||||||
Events,
|
Events,
|
||||||
GuildChannel,
|
GuildChannel,
|
||||||
PermissionOverwrites,
|
PermissionOverwrites,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
|
|
||||||
import logAction from '../util/logging/logAction.js';
|
|
||||||
import { ChannelLogAction } from '../util/logging/types.js';
|
import { ChannelLogAction } from '../util/logging/types.js';
|
||||||
import { Event } from '../types/EventTypes.js';
|
import { Event } from '../types/EventTypes.js';
|
||||||
|
import logAction from '../util/logging/logAction.js';
|
||||||
|
|
||||||
function arePermissionsEqual(
|
function arePermissionsEqual(
|
||||||
oldPerms: Map<string, PermissionOverwrites>,
|
oldPerms: Map<string, PermissionOverwrites>,
|
||||||
|
@ -93,7 +95,7 @@ function getPermissionChanges(
|
||||||
return changes;
|
return changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const channelCreate = {
|
export const channelCreate: Event<typeof Events.ChannelCreate> = {
|
||||||
name: Events.ChannelCreate,
|
name: Events.ChannelCreate,
|
||||||
execute: async (channel: GuildChannel) => {
|
execute: async (channel: GuildChannel) => {
|
||||||
try {
|
try {
|
||||||
|
@ -119,10 +121,12 @@ export const channelCreate = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const channelDelete = {
|
export const channelDelete: Event<typeof Events.ChannelDelete> = {
|
||||||
name: Events.ChannelDelete,
|
name: Events.ChannelDelete,
|
||||||
execute: async (channel: GuildChannel) => {
|
execute: async (channel: GuildChannel | DMChannel) => {
|
||||||
try {
|
try {
|
||||||
|
if (channel.type === ChannelType.DM) return;
|
||||||
|
|
||||||
const { guild } = channel;
|
const { guild } = channel;
|
||||||
const auditLogs = await guild.fetchAuditLogs({
|
const auditLogs = await guild.fetchAuditLogs({
|
||||||
type: AuditLogEvent.ChannelDelete,
|
type: AuditLogEvent.ChannelDelete,
|
||||||
|
@ -145,10 +149,19 @@ export const channelDelete = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const channelUpdate = {
|
export const channelUpdate: Event<typeof Events.ChannelUpdate> = {
|
||||||
name: Events.ChannelUpdate,
|
name: Events.ChannelUpdate,
|
||||||
execute: async (oldChannel: GuildChannel, newChannel: GuildChannel) => {
|
execute: async (
|
||||||
|
oldChannel: GuildChannel | DMChannel,
|
||||||
|
newChannel: GuildChannel | DMChannel,
|
||||||
|
) => {
|
||||||
try {
|
try {
|
||||||
|
if (
|
||||||
|
oldChannel.type === ChannelType.DM ||
|
||||||
|
newChannel.type === ChannelType.DM
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
oldChannel.name === newChannel.name &&
|
oldChannel.name === newChannel.name &&
|
||||||
oldChannel.type === newChannel.type &&
|
oldChannel.type === newChannel.type &&
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { Events, Interaction } from 'discord.js';
|
import { Events, Interaction } from 'discord.js';
|
||||||
|
|
||||||
import { ExtendedClient } from '../structures/ExtendedClient.js';
|
import { ExtendedClient } from '../structures/ExtendedClient.js';
|
||||||
|
import { Event } from '../types/EventTypes.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: Events.InteractionCreate,
|
name: Events.InteractionCreate,
|
||||||
|
@ -35,4 +37,4 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
} as Event<typeof Events.InteractionCreate>;
|
||||||
|
|
|
@ -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 { updateMember, setMembers } from '../db/db.js';
|
||||||
import { generateMemberBanner } from '../util/helpers.js';
|
import { generateMemberBanner } from '../util/helpers.js';
|
||||||
import { loadConfig } from '../util/configLoader.js';
|
import { loadConfig } from '../util/configLoader.js';
|
||||||
|
import { Event } from '../types/EventTypes.js';
|
||||||
import logAction from '../util/logging/logAction.js';
|
import logAction from '../util/logging/logAction.js';
|
||||||
|
|
||||||
export const memberJoin = {
|
export const memberJoin: Event<typeof Events.GuildMemberAdd> = {
|
||||||
name: Events.GuildMemberAdd,
|
name: Events.GuildMemberAdd,
|
||||||
execute: async (member: GuildMember) => {
|
execute: async (member: GuildMember) => {
|
||||||
const { guild } = member;
|
const { guild } = member;
|
||||||
|
@ -54,9 +56,9 @@ export const memberJoin = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const memberLeave = {
|
export const memberLeave: Event<typeof Events.GuildMemberRemove> = {
|
||||||
name: Events.GuildMemberRemove,
|
name: Events.GuildMemberRemove,
|
||||||
execute: async (member: GuildMember) => {
|
execute: async (member: GuildMember | PartialGuildMember) => {
|
||||||
const { guild } = member;
|
const { guild } = member;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -68,7 +70,7 @@ export const memberLeave = {
|
||||||
logAction({
|
logAction({
|
||||||
guild,
|
guild,
|
||||||
action: 'memberLeave',
|
action: 'memberLeave',
|
||||||
member,
|
member: member as GuildMember,
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -77,9 +79,12 @@ export const memberLeave = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const memberUpdate = {
|
export const memberUpdate: Event<typeof Events.GuildMemberUpdate> = {
|
||||||
name: Events.GuildMemberUpdate,
|
name: Events.GuildMemberUpdate,
|
||||||
execute: async (oldMember: GuildMember, newMember: GuildMember) => {
|
execute: async (
|
||||||
|
oldMember: GuildMember | PartialGuildMember,
|
||||||
|
newMember: GuildMember,
|
||||||
|
) => {
|
||||||
const { guild } = newMember;
|
const { guild } = newMember;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -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';
|
import logAction from '../util/logging/logAction.js';
|
||||||
|
|
||||||
export const messageDelete = {
|
export const messageDelete: Event<typeof Events.MessageDelete> = {
|
||||||
name: Events.MessageDelete,
|
name: Events.MessageDelete,
|
||||||
execute: async (message: Message) => {
|
execute: async (
|
||||||
|
message: Omit<Partial<Message<boolean> | PartialMessage>, 'channel'>,
|
||||||
|
) => {
|
||||||
try {
|
try {
|
||||||
if (!message.guild || message.author?.bot) return;
|
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,
|
name: Events.MessageUpdate,
|
||||||
execute: async (oldMessage: Message, newMessage: Message) => {
|
execute: async (
|
||||||
|
oldMessage: Omit<Partial<Message<boolean> | PartialMessage>, 'channel'>,
|
||||||
|
newMessage: Message,
|
||||||
|
) => {
|
||||||
try {
|
try {
|
||||||
if (
|
if (
|
||||||
!oldMessage.guild ||
|
!oldMessage.guild ||
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { Client, Events } from 'discord.js';
|
||||||
|
|
||||||
import { setMembers } from '../db/db.js';
|
import { setMembers } from '../db/db.js';
|
||||||
import { loadConfig } from '../util/configLoader.js';
|
import { loadConfig } from '../util/configLoader.js';
|
||||||
|
import { Event } from '../types/EventTypes.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: Events.ClientReady,
|
name: Events.ClientReady,
|
||||||
|
@ -16,4 +17,4 @@ export default {
|
||||||
|
|
||||||
console.log(`Ready! Logged in as ${client.user?.tag}`);
|
console.log(`Ready! Logged in as ${client.user?.tag}`);
|
||||||
},
|
},
|
||||||
};
|
} as Event<typeof Events.ClientReady>;
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import { AuditLogEvent, Events, Role } from 'discord.js';
|
import { AuditLogEvent, Events, Role } from 'discord.js';
|
||||||
|
|
||||||
|
import { Event } from '../types/EventTypes.js';
|
||||||
import logAction from '../util/logging/logAction.js';
|
import logAction from '../util/logging/logAction.js';
|
||||||
|
|
||||||
const convertRoleProperties = (role: Role) => ({
|
const convertRoleProperties = (role: Role) => ({
|
||||||
|
@ -8,7 +10,7 @@ const convertRoleProperties = (role: Role) => ({
|
||||||
mentionable: role.mentionable,
|
mentionable: role.mentionable,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const roleCreate = {
|
export const roleCreate: Event<typeof Events.GuildRoleCreate> = {
|
||||||
name: Events.GuildRoleCreate,
|
name: Events.GuildRoleCreate,
|
||||||
execute: async (role: Role) => {
|
execute: async (role: Role) => {
|
||||||
try {
|
try {
|
||||||
|
@ -34,7 +36,7 @@ export const roleCreate = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const roleDelete = {
|
export const roleDelete: Event<typeof Events.GuildRoleDelete> = {
|
||||||
name: Events.GuildRoleDelete,
|
name: Events.GuildRoleDelete,
|
||||||
execute: async (role: Role) => {
|
execute: async (role: Role) => {
|
||||||
try {
|
try {
|
||||||
|
@ -60,7 +62,7 @@ export const roleDelete = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const roleUpdate = {
|
export const roleUpdate: Event<typeof Events.GuildRoleUpdate> = {
|
||||||
name: Events.GuildRoleUpdate,
|
name: Events.GuildRoleUpdate,
|
||||||
execute: async (oldRole: Role, newRole: Role) => {
|
execute: async (oldRole: Role, newRole: Role) => {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -376,7 +376,7 @@ export default async function logAction(payload: LogActionPayload) {
|
||||||
case 'channelCreate':
|
case 'channelCreate':
|
||||||
case 'channelDelete': {
|
case 'channelDelete': {
|
||||||
fields.push(
|
fields.push(
|
||||||
{ name: 'Channel', value: `<#${payload.channel.id}>`, inline: true },
|
{ name: 'Channel', value: `<#${payload.channel.id}> (#${payload.channel.name})`, inline: true },
|
||||||
{
|
{
|
||||||
name: 'Type',
|
name: 'Type',
|
||||||
value:
|
value:
|
||||||
|
|
Loading…
Add table
Reference in a new issue