-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
174 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/Events/BotEvents/channelEvents/channelStatusUpdate/channelStatusUpdate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { BaseGuildVoiceChannel } from 'discord.js'; | ||
|
||
import log from './log.js'; | ||
|
||
export default async ( | ||
channel: BaseGuildVoiceChannel, | ||
oldStatus: string, | ||
newStatus: string, | ||
internal: boolean, | ||
) => { | ||
if (!internal) throw new Error('ChannelStatusUpdate received from unknown source'); | ||
|
||
log(channel, oldStatus, newStatus); | ||
}; |
75 changes: 75 additions & 0 deletions
75
src/Events/BotEvents/channelEvents/channelStatusUpdate/log.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import type { APIEmbed, AuditLogEvent, BaseGuildVoiceChannel } from 'discord.js'; | ||
import { Colors, type AcceptedMergingTypes } from '../../../../Typings/Typings.js'; | ||
|
||
export default async (channel: BaseGuildVoiceChannel, oldStatus: string, newStatus: string) => { | ||
const channels = await channel.client.util.getLogChannels('channelevents', channel.guild); | ||
if (!channels) return; | ||
|
||
const language = await channel.client.util.getLanguage(channel.guild.id); | ||
const lan = language.events.logs.channel; | ||
const con = channel.client.util.constants.events.logs.channel; | ||
|
||
const audit = await channel.client.util.request.guilds.getAuditLogs(channel.guild, { | ||
action_type: (newStatus.length ? 192 : 193) as AuditLogEvent, | ||
limit: 50, | ||
}); | ||
|
||
const relevantAudit = | ||
'message' in audit | ||
? undefined | ||
: audit.entries | ||
.filter((e) => | ||
e.targetId === channel.id && e.action === (192 as AuditLogEvent) | ||
? (e.extra as { status: string } | null)?.status === newStatus | ||
: true, | ||
) | ||
.sort((a, b) => b.createdTimestamp - a.createdTimestamp) | ||
.first(); | ||
|
||
const getTitle = () => { | ||
if (!newStatus.length) return lan.nameStatusDelete; | ||
if (!oldStatus.length) return lan.nameStatusCreate; | ||
return lan.nameStatusUpdate; | ||
}; | ||
|
||
const getColor = () => { | ||
if (!newStatus.length) return Colors.Danger; | ||
if (!oldStatus.length) return Colors.Success; | ||
return Colors.Loading; | ||
}; | ||
|
||
const getType = (): 'Delete' | 'Create' | 'Update' => { | ||
if (!newStatus.length) return 'Delete'; | ||
if (!oldStatus.length) return 'Create'; | ||
return 'Update'; | ||
}; | ||
|
||
const embed: APIEmbed = { | ||
author: { | ||
icon_url: con[`${channel.client.util.getTrueChannelType(channel, channel.guild)}${getType()}`], | ||
name: getTitle(), | ||
}, | ||
description: | ||
relevantAudit && relevantAudit.executor | ||
? lan.descStatusUpdateAudit( | ||
relevantAudit.executor, | ||
channel, | ||
language.channelTypes[channel.type], | ||
) | ||
: lan.descStatusUpdate(channel, language.channelTypes[channel.type]), | ||
fields: [], | ||
color: getColor(), | ||
timestamp: new Date().toISOString(), | ||
}; | ||
|
||
const merge = (before: unknown, after: unknown, type: AcceptedMergingTypes, name: string) => | ||
channel.client.util.mergeLogging(before, after, type, embed, language, name); | ||
|
||
if (oldStatus !== newStatus) { | ||
merge(oldStatus || language.t.None, newStatus || language.t.None, 'string', lan.channelStatus); | ||
} | ||
|
||
if (!embed.fields?.length) return; | ||
|
||
channel.client.util.send({ id: channels, guildId: channel.guild.id }, { embeds: [embed] }, 10000); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
import client from '../../../BaseClient/Bot/Client.js'; | ||
import channelStatusUpdate from '../channelEvents/channelStatusUpdate/channelStatusUpdate.js'; | ||
|
||
export default async (data: { status: string; id: string; guild_id: string }) => { | ||
const oldStatus = client.util.cache.voiceChannelStatus.get(data.id); | ||
client.util.cache.voiceChannelStatus.set(data.id, data.status); | ||
|
||
const channel = client.channels.cache.get(data.id); | ||
if (!channel) return; | ||
if (channel.isDMBased()) return; | ||
if (!channel.isVoiceBased()) return; | ||
|
||
channelStatusUpdate(channel, oldStatus || '', data.status, true); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters