-
Notifications
You must be signed in to change notification settings - Fork 48
feat: auto-delete in voice-chat feature #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SCDerox
merged 32 commits into
ScootKit:main
from
torbenprobst:auto-delete-inVoiceFeature
Sep 9, 2022
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
752f228
added new config file to module config
39107d5
fixed text description
10f8308
added example config for voice-channel feature
ef8b0c8
added in-voice chat purgeOnStart functionality;
880ad82
added filtering of channels (no duplicates in config); Added overwrit…
ca84a1b
added reusing of botReady unique channels to reduce work load
c427d7a
[auto-delete] added new event and feature functionality in-voice chats
0864a7f
[auto-delete] added "could-not-fetch-messages" locale
dceb45b
[auto-delete] fixed missing import of localize function
4cedf55
[auto-delete] deleted unnecessary object cloning
21cddc7
[auto-delete] added catch functionality on channel.fetch
0d812ec
[auto-delete] fixed if statement to be more readable
d758c4f
[auto-delete] added channel message catch functionality
7a3bae1
[auto-delete] added early exit on no messages in channel
869c4bf
[auto-delete] added now using variable for message parameter
5d62998
[auto-delete] fixed unnecessary new line
64470bf
[auto-delete] added channel message catch functionality + early return
f1eb904
[auto-delete] added usage of channelMessage variable in bulkDelete
0cc109f
[auto-delete] fixed if statement to be more readable
4472a56
[auto-delete] added channel.messages catch functionality + early return
0708359
[auto-delete] added usage of channelMessage variable in Bulkdelete
04f3dbb
[auto-delete] fixed order of if statements to fit logically
9355290
fixed eslint errors
1bb6a32
[auto-delete] fixed logic errors and restructured code
b4d83c8
fix(auto-delete): only parsing not int valus as int
9bc3afc
fix(auto-delete): changed early return statement
193fe2e
fix(auto-delete): added check for Voice channel Type
2d50b73
feat(auto-delete:config): added more detailed bilingual description a…
3339504
fix(auto-delete): changed from "Zeit" to Timeout
5ef8c2d
Merge branch 'upstream/main' into auto-delete-inVoiceFeature
d044c80
feat(auto-delete): added locale entries for could-not-fetch-messages
563f64c
fix(auto-delete): translated text to locale language
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,11 +1,60 @@ | ||
| const {localize} = require('../../../src/functions/localize'); | ||
| module.exports.run = async function (client) { | ||
| const channels = client.configurations['auto-delete']['channels']; | ||
| for (const channel of channels) { | ||
| const voiceChannels = client.configurations['auto-delete']['voice-channels']; | ||
|
|
||
| const uniqueConfigChannels = findUniqueChannels(channels); | ||
| const uniqueConfigVoiceChannels = findUniqueChannels(voiceChannels); | ||
|
|
||
| client.modules['auto-delete'].uniqueChannels = uniqueConfigChannels.filter((channel) => { | ||
| const channelConfigObject = uniqueConfigVoiceChannels.find((voiceChannel) => voiceChannel.channelID === channel.channelID); | ||
| return !channelConfigObject; | ||
| }); | ||
|
|
||
| for (const channel of client.modules['auto-delete'].uniqueChannels) { | ||
| if (!channel.purgeOnStart) continue; | ||
| const dcChannel = await client.channels.fetch(channel.channelID).catch(() => { | ||
| }); | ||
|
|
||
| const dcChannel = await client.channels.fetch(channel.channelID).catch(() => {}); | ||
| if (!dcChannel) return client.logger.error(`[auto-delete] ${localize('auto-delete', 'could-not-fetch-channel', {c: channel.channelID})}`); | ||
| dcChannel.bulkDelete((await dcChannel.messages.fetch()).filter(m => !m.pinned && m.deletable), true); | ||
|
|
||
| const channelMessages = await dcChannel.messages.fetch().catch(() => {}); | ||
| if (!channelMessages) { | ||
| return client.logger.error(`[auto-delete] ${localize('auto-delete', 'could-not-fetch-messages', {c: channel.channelID})}`); | ||
| } | ||
| if (channelMessages.size === 0) continue; | ||
|
|
||
| dcChannel.bulkDelete(channelMessages.filter(m => !m.pinned && m.deletable), true); | ||
| } | ||
| }; | ||
|
|
||
| for (const voiceChannel of uniqueConfigVoiceChannels) { | ||
| if (!voiceChannel.purgeOnStart) continue; | ||
|
|
||
| const dcVoiceChannel = await client.channels.fetch(voiceChannel.channelID).catch(() => {}); | ||
| if (!dcVoiceChannel) return client.logger.error(`[auto-delete] ${localize('auto-delete', 'could-not-fetch-channel', {c: voiceChannel.channelID})}`); | ||
| if (dcVoiceChannel.members.size > 0) continue; | ||
|
|
||
| const channelMessages = await dcVoiceChannel.messages.fetch().catch(() => {}); | ||
| if (!channelMessages) { | ||
| return client.logger.error(`[auto-delete] ${localize('auto-delete', 'could-not-fetch-messages', {c: voiceChannel.channelID})}`); | ||
| } | ||
| if (channelMessages.size === 0) continue; | ||
|
|
||
| dcVoiceChannel.bulkDelete(channelMessages, true); | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Finds and deletes duplicates in Array (Last Writer wins) | ||
| * @param {String} arrayToFilter Array of Channels | ||
| * @returns {Array} Filtered Array of Channels | ||
| * @private | ||
| */ | ||
| function findUniqueChannels(arrayToFilter) { | ||
| const uniqueConfigChannelIds = {}; | ||
|
|
||
| for (let i = 0; i < arrayToFilter.length; i++) { | ||
| uniqueConfigChannelIds[arrayToFilter[i].channelID] = i; | ||
| } | ||
|
|
||
| return arrayToFilter.filter((channel, index) => uniqueConfigChannelIds[channel.channelID] === index); | ||
| } |
This file contains hidden or 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 hidden or 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,26 @@ | ||
| const {localize} = require('../../../src/functions/localize'); | ||
| module.exports.run = async function (client, oldState) { | ||
| if (!client.botReadyAt) return; | ||
|
|
||
| const voiceChannels = client.configurations['auto-delete']['voice-channels']; | ||
|
|
||
| const channelConfigEntry = voiceChannels.find((vc) => oldState.channelId === vc.channelID); | ||
| if (!channelConfigEntry) return; | ||
|
|
||
| const channel = await client.channels.fetch(channelConfigEntry.channelID).catch(() => {}); | ||
| if (!channel) { | ||
| return client.logger.error(`[auto-delete] ${localize('auto-delete', 'could-not-fetch-channel', {c: channelConfigEntry.channelID})}`); | ||
| } | ||
| if (channel.type !== 'GUILD_VOICE') return; | ||
| if (channel.members.size > 0) return; | ||
|
|
||
| const channelMessages = await channel.messages.fetch().catch(() => {}); | ||
| if (!channelMessages) { | ||
| return client.logger.error(`[auto-delete] ${localize('auto-delete', 'could-not-fetch-messages', {c: channelConfigEntry.channelID})}`); | ||
| } | ||
| if (channelMessages.size === 0) return; | ||
|
|
||
| setTimeout(async() => { | ||
| channel.bulkDelete(channelMessages, true).catch(() => {}); | ||
| }, parseInt(channelConfigEntry.timeout) * 1000 * 60); | ||
| }; | ||
This file contains hidden or 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 hidden or 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,36 @@ | ||
| { | ||
| "filename": "voice-channels.json", | ||
| "humanname-de": "Voice-Channel", | ||
| "humanname-en": "Voice-Channels", | ||
| "configElements": true, | ||
| "content": [ | ||
torbenprobst marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| "field_name": "channelID", | ||
| "default": "", | ||
| "type": "channelID", | ||
| "content": "GUILD_VOICE", | ||
| "humanname-de": "Sprachkanal", | ||
| "humanname-en": "Voice-Channel", | ||
| "description-en": "The Voice-Channel you want the auto-deleter to clear if there are no channel members left.", | ||
| "description-de": "Wähle den Sprachkanal aus, den der Bot leeren soll, sobald keine Mitglieder mehr im Sprachkanal sind." | ||
| }, | ||
| { | ||
| "field_name": "timeout", | ||
| "default": "5", | ||
| "type": "integer", | ||
| "humanname-de": "Timeout", | ||
| "humanname-en": "Timeout", | ||
| "description-en": "Timeout (in minutes) after which the messages in a Voice-Channel are deleted after the last member left the channel. Entering '0' will result in an instant deletion.", | ||
| "description-de": "Timeout (in Minuten), nachdem die Nachrichten gelöscht werden, wenn das letzte Mitglied den Sprachkanal verlassen hat. Wenn du eine '0' verwendest, werden die Nachrichten sofort gelöscht." | ||
| }, | ||
| { | ||
| "field_name": "purgeOnStart", | ||
| "default": false, | ||
| "type": "boolean", | ||
| "humanname-de": "Kanal leeren beim Bot Start", | ||
| "humanname-en": "Purge On Start", | ||
| "description-en": "If enabled every message (max 100) in this channel gets deleted when the bot starts and no members are left in the channel", | ||
| "description-de": "Wenn aktiviert, werden alle Nachrichten (max 100) aus dem gewälten Sprachkanal gelöscht (beim Start des Bots), sofern keine Mitglieder in dem Sprachkanal sind." | ||
| } | ||
| ] | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.