From e6d8ff936aca13396bcc00a0e673f0422b5b6199 Mon Sep 17 00:00:00 2001 From: Sebastian Pietschner Date: Tue, 25 Oct 2022 23:43:27 +0000 Subject: [PATCH] change the filter for zac cause it's annoying me and he won't fix the nickname he added for chrome --- src/classes/Secondary.ts | 24 +++++++++++++++++------- src/events/VoiceStateUpdateEvent.ts | 25 ++++++++++++++++++++++--- src/utils/activity.ts | 3 ++- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/classes/Secondary.ts b/src/classes/Secondary.ts index d005c88..d344438 100644 --- a/src/classes/Secondary.ts +++ b/src/classes/Secondary.ts @@ -119,18 +119,28 @@ export default class DynamicaSecondary { emoji, locked, }); - + const oldName = discordChannel.name; if (discordChannel.name !== name) { - if (!discordChannel.manageable) { - throw new Error('Channel not manageable'); + try { + await discordChannel.edit({ + name, + }); + } catch (error) { + if (error instanceof DiscordAPIError) { + if (error.code === 50013) { + await this.delete(); + } else if (error.code === 10003) { + await this.delete(false, true); + } else { + this.logger.error(error); + } + } } - await discordChannel.edit({ - name, - }); + this.logger .scope('Secondary', this.id) .debug( - `Secondary channel ${discordChannel.name} in ${discordChannel.guild.name} name changed.` + `Secondary channel in ${discordChannel.guild.name} name changed from ${oldName} to ${name}.` ); } } catch (error) { diff --git a/src/events/VoiceStateUpdateEvent.ts b/src/events/VoiceStateUpdateEvent.ts index 092f505..fc30aeb 100644 --- a/src/events/VoiceStateUpdateEvent.ts +++ b/src/events/VoiceStateUpdateEvent.ts @@ -2,12 +2,17 @@ import Primaries from '@/classes/Primaries'; import Secondaries from '@/classes/Secondaries'; import updatePresence from '@/utils/presence'; import Event, { EventToken } from '@/classes/Event'; -import { VoiceState } from 'discord.js'; +import { DiscordAPIError, VoiceState } from 'discord.js'; import { Service } from 'typedi'; +import Logger from '@/services/Logger'; @Service({ id: EventToken, multiple: true }) export default class VoiceStateUpdateEvent extends Event<'voiceStateUpdate'> { - constructor(private secondaries: Secondaries, private primaries: Primaries) { + constructor( + private secondaries: Secondaries, + private primaries: Primaries, + private logger: Logger + ) { super(); } @@ -35,7 +40,21 @@ export default class VoiceStateUpdateEvent extends Event<'voiceStateUpdate'> { ); if (oldChannelSecondary) { - await oldChannelSecondary.update(); + try { + await oldChannelSecondary.update(); + } catch (error) { + if (error instanceof DiscordAPIError) { + if (error.code === 50001) { + await oldChannelSecondary.delete(); + } else if (error.code === 10003) { + await oldChannelSecondary.delete(false, true); + } else { + this.logger.error(error); + } + } else { + this.logger.error(error); + } + } } if (newChannelPrimary) { diff --git a/src/utils/activity.ts b/src/utils/activity.ts index 27a2022..15a3578 100644 --- a/src/utils/activity.ts +++ b/src/utils/activity.ts @@ -8,6 +8,7 @@ const channelActivities = (channel: VoiceBasedChannel) => .flat() .filter((activity) => activity.type !== ActivityType.Custom) .filter((activity) => activity.type !== ActivityType.Listening) - .map((activity) => activity.name) ?? []; + .map((activity) => activity.name) + .filter((activityName) => activityName !== 'With Yo Mamma') ?? []; export default channelActivities;