mirror of
https://github.com/ahmadk953/poixpixel-discord-bot.git
synced 2025-05-10 10:43:06 +00:00
Added Warn and Ban Commands, Added Logging, and Much More
This commit is contained in:
parent
d89de72e08
commit
86adac3f08
33 changed files with 2200 additions and 204 deletions
93
src/events/roleEvents.ts
Normal file
93
src/events/roleEvents.ts
Normal file
|
@ -0,0 +1,93 @@
|
|||
import { AuditLogEvent, Events, Role } from 'discord.js';
|
||||
import logAction from '../util/logging/logAction.js';
|
||||
|
||||
const convertRoleProperties = (role: Role) => ({
|
||||
name: role.name,
|
||||
color: role.hexColor,
|
||||
hoist: role.hoist,
|
||||
mentionable: role.mentionable,
|
||||
});
|
||||
|
||||
export const roleCreate = {
|
||||
name: Events.GuildRoleCreate,
|
||||
execute: async (role: Role) => {
|
||||
try {
|
||||
const { guild } = role;
|
||||
const auditLogs = await guild.fetchAuditLogs({
|
||||
type: AuditLogEvent.RoleCreate,
|
||||
limit: 1,
|
||||
});
|
||||
const executor = auditLogs.entries.first()?.executor;
|
||||
const moderator = executor
|
||||
? await guild.members.fetch(executor.id)
|
||||
: undefined;
|
||||
|
||||
await logAction({
|
||||
guild,
|
||||
action: 'roleCreate',
|
||||
role,
|
||||
moderator,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error handling role create:', error);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export const roleDelete = {
|
||||
name: Events.GuildRoleDelete,
|
||||
execute: async (role: Role) => {
|
||||
try {
|
||||
const { guild } = role;
|
||||
const auditLogs = await guild.fetchAuditLogs({
|
||||
type: AuditLogEvent.RoleDelete,
|
||||
limit: 1,
|
||||
});
|
||||
const executor = auditLogs.entries.first()?.executor;
|
||||
const moderator = executor
|
||||
? await guild.members.fetch(executor.id)
|
||||
: undefined;
|
||||
|
||||
await logAction({
|
||||
guild,
|
||||
action: 'roleDelete',
|
||||
role,
|
||||
moderator,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error handling role delete:', error);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export const roleUpdate = {
|
||||
name: Events.GuildRoleUpdate,
|
||||
execute: async (oldRole: Role, newRole: Role) => {
|
||||
try {
|
||||
const { guild } = newRole;
|
||||
const auditLogs = await guild.fetchAuditLogs({
|
||||
type: AuditLogEvent.RoleUpdate,
|
||||
limit: 1,
|
||||
});
|
||||
const executor = auditLogs.entries.first()?.executor;
|
||||
const moderator = executor
|
||||
? await guild.members.fetch(executor.id)
|
||||
: undefined;
|
||||
|
||||
await logAction({
|
||||
guild,
|
||||
action: 'roleUpdate',
|
||||
role: newRole,
|
||||
oldRole: convertRoleProperties(oldRole),
|
||||
newRole: convertRoleProperties(newRole),
|
||||
moderator,
|
||||
oldPermissions: oldRole.permissions,
|
||||
newPermissions: newRole.permissions,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error handling role update:', error);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default [roleCreate, roleDelete, roleUpdate];
|
Loading…
Add table
Add a link
Reference in a new issue