-
Couldn't load subscription status.
- Fork 0
feat: add /repel command to timeout users and delete recent mesages #11
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
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
325ba93
🌟 feat: Add buildCommandString function to format command strings
hmd-ali 36feabb
🌟 feat: Implement getPublicChannels function to filter accessible tex…
hmd-ali b33014a
🌟 feat: Add fetchAndCachePublicChannelsMessages function to cache mes…
hmd-ali 9bd9c27
🌟 feat: Implement timeToString function to format milliseconds into r…
hmd-ali e4bc7cd
🌟 feat: Add cache-messages command to cache messages in all public te…
hmd-ali 10e6b4a
🌟 feat: Add force re-caching option to cache-messages command
hmd-ali e81a74e
🌟 feat: Add new config variables (repel, server Id, moderator role Id…
hmd-ali 0f8d354
🌟 feat: Fetch and cache messages on client ready event
hmd-ali 526a2fb
🌟 feat: Implement repel command to timeout users and delete recent me…
hmd-ali 4827b15
🌟 feat: Add cacheMessages and repelCommand to commands map
hmd-ali 64796e6
🔨 refactor: remove FETCH_AND_SYNC_MESSAGES from env and put it direct…
hmd-ali b962467
🔨 refactor: remove unnecessary `return` from cache-messages command h…
hmd-ali d0cb686
🌟 feat: add error logging for target fetching and timeout functions
hmd-ali db8930e
🌟 feat: replace Promis.all with Promise.allSettled and track/log fail…
hmd-ali 41ef4ce
🌟 feat: enhance message caching by tracking failed channels and using…
hmd-ali f6cccce
Merge branch 'main' into feat/repel
hmd-ali e33f680
🐛 fix: fix missing } after resolving merge conflicts
hmd-ali 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| DISCORD_TOKEN="" # Your bot token | ||
| CLIENT_ID="" # Your bot's application ID | ||
| GUIDES_CHANNEL_ID="" # The ID of the channel where guides will be posted | ||
|
|
||
| SERVER_ID= | ||
| MODERATORS_ROLE_IDS= # Comma separated list of role IDs that are Moderators(Mods, Admins, etc) | ||
|
|
||
| REPEL_LOG_CHANNEL_ID= # Channel ID where the bot will log repel actions | ||
| GUIDES_CHANNEL_ID="" # The ID of the channel where guides will be posted | ||
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,9 +1,13 @@ | ||
| import { docsCommands } from './docs/index.js'; | ||
| import { guidesCommand } from './guides/index.js'; | ||
| import cacheMessages from './moderation/cache-messages.js'; | ||
| import { repelCommand } from './moderation/repel.js'; | ||
| import { pingCommand } from './ping.js'; | ||
| import { tipsCommands } from './tips/index.js'; | ||
| import type { Command } from './types.js'; | ||
|
|
||
| export const commands = new Map<string, Command>( | ||
| [pingCommand, guidesCommand, docsCommands, tipsCommands].flat().map((cmd) => [cmd.data.name, cmd]) | ||
| [pingCommand, guidesCommand, docsCommands, tipsCommands, repelCommand, cacheMessages] | ||
| .flat() | ||
| .map((cmd) => [cmd.data.name, cmd]) | ||
| ); |
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,49 @@ | ||
| import { ApplicationCommandOptionType, PermissionFlagsBits, PermissionsBitField } from 'discord.js'; | ||
| import { fetchAndCachePublicChannelsMessages } from '../../util/cache.js'; | ||
| import { createCommand } from '../../util/commands.js'; | ||
|
|
||
| export default createCommand({ | ||
| data: { | ||
| name: 'cache-messages', | ||
| description: 'Cache messages in all text channels of the server', | ||
| default_member_permissions: new PermissionsBitField( | ||
| PermissionFlagsBits.ManageMessages | ||
| ).toJSON(), | ||
| options: [ | ||
| { | ||
| name: 'force', | ||
| description: 'Force re-caching even if messages are already cached', | ||
| type: ApplicationCommandOptionType.Boolean, | ||
| required: false, | ||
| }, | ||
| ], | ||
| }, | ||
| execute: async (interaction) => { | ||
| await interaction.deferReply(); | ||
| if (!interaction.guild || !interaction.isChatInputCommand()) { | ||
| await interaction.editReply('This command can only be used in a guild.'); | ||
| return; | ||
| } | ||
|
|
||
| if (!interaction.memberPermissions?.has(PermissionFlagsBits.ManageMessages)) { | ||
| await interaction.editReply('You do not have permission to use this command.'); | ||
| return; | ||
| } | ||
|
|
||
| const guild = interaction.guild; | ||
| const force = interaction.options.getBoolean('force') ?? false; | ||
|
|
||
| await interaction.editReply('Caching messages in all public text channels...'); | ||
|
|
||
| const { cachedChannels, totalChannels, failedChannels } = | ||
| await fetchAndCachePublicChannelsMessages(guild, force); | ||
|
|
||
| const failedMessage = failedChannels.length | ||
| ? `\nFailed to cache messages in the following channels: ${failedChannels.map((id) => `<#${id}>`).join(', ')}` | ||
| : ''; | ||
|
|
||
| await interaction.editReply( | ||
| `Cached messages in ${cachedChannels} out of ${totalChannels} text channels.${failedMessage}` | ||
| ); | ||
| }, | ||
| }); |
Oops, something went wrong.
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.