MCPcopy Create free account
hub / github.com/RTByte/rtbyte / run

Method run

src/events/rtbyteRoleDelete.js:10–48  ·  view source on GitHub ↗
(role)

Source from the content-addressed store, hash-verified

8 }
9
10 async run(role) {
11 if (!role.guild) return;
12
13 let executor;
14 if (role.guild.me.hasPermission('VIEW_AUDIT_LOG')) {
15 const auditLog = await role.guild.fetchAuditLogs();
16 const logEntry = await auditLog.entries.first();
17
18 if (logEntry.action === 'ROLE_DELETE') executor = logEntry ? logEntry.executor : undefined;
19 }
20
21 if (role.guild.settings.get('channels.log') && role.guild.settings.get('logs.events.roleDelete')) await this.serverLog(role, executor);
22
23 // Config checks
24 // Checks server and client configs to see if the deleted role has been configured anywhere. If it has, resets or removes it.
25 if (role.id === role.guild.settings.get('roles.administrator')) await role.guild.settings.reset('roles.administrator');
26 if (role.id === role.guild.settings.get('roles.moderator')) await role.guild.settings.reset('roles.moderator');
27 if (role.id === role.guild.settings.get('roles.muted')) await role.guild.settings.reset('roles.muted');
28 if (role.id === role.guild.settings.get('roles.voiceBanned')) await role.guild.settings.reset('roles.voiceBanned');
29 if (role.id === role.guild.settings.get('twitch.twitchNotifsRole')) await role.guild.settings.reset('twitch.twitchNotifsRole');
30
31 // Reset won't work for arrays of role IDs, and we can't use update() with a deleted role.
32 if (role.guild.settings.get('roles.joinable').includes(role.id)) {
33 // Capture old list of roles
34 const oldList = role.guild.settings.get('roles.joinable');
35
36 // Reset current list
37 await role.guild.settings.reset('roles.joinable');
38
39 // Declare new list without the deleted role and re-add the other ones
40 const newList = oldList.filter(rl => rl !== role.id);
41 for (let i = 0; i < newList.length; i++) {
42 await role.guild.settings.sync();
43 await role.guild.settings.update('roles.joinable', newList[i]);
44 }
45 }
46
47 return;
48 }
49
50 async serverLog(role, executor) {
51 const embed = new MessageEmbed()

Callers

nothing calls this directly

Calls 3

updateMethod · 0.80
serverLogMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected