-
-
Notifications
You must be signed in to change notification settings - Fork 46
Adds ping-protection module. #168
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
Open
Kevinking500
wants to merge
36
commits into
ScootKit:beta-discordjs14
Choose a base branch
from
Kevinking500:main
base: beta-discordjs14
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
3502113
Added the base module folders and module.json
9bd863d
Added all folders necessary and the configuration files for each folder
804ceed
Added a test command
13733f7
removed the manage file
88322e3
Added, renamed and deleted some files as necessary and coded the models.
843ebbd
Renamed action.js to moderation.js, coded multiple things, added a ne…
225abb7
Forgot to update module.json, now updated aswell
1602a16
Added additional information in ping-protection.js
Kevinking500 d285aee
Disabled allowing reply pings, added the enable moderation and enable…
cdf6f70
Added support for actually correct parameters and those parameters ad…
0e4cafb
Added proper support for localization, and coded the events
24dc3b2
Completed the full module and fixed some critical bugs that caused th…
01660ad
Cleaned up some code notes I used for debugging
93eb5a3
Completely finished the module and worked tirelessly for many hours t…
f464555
Debugged absolutely everything, removed like 300 lines of code for po…
35afa5a
Added the option to lower mod actions history
9cf2c36
Made the deault value of pings to trigger action 10 instead of 5 in b…
b5ca02f
Added the commands warnings for most commands
Kevinking500 edaa5d1
Almost completely rewrote the module to make sure the modules works a…
84c2634
Merge branch 'main' of github.com:Kevinking500/CustomDCBot
0b4d87b
Added "automod" abilities - Will now delete the original message by d…
347b674
(not working correctly) added automod integration and some small changes
bc3737a
Fixed the
d1d0271
Removed the feature that didn't work (reposting), adds a custom messa…
aa79dd4
Fixed the bug of the bot still sending the warning and punishing if l…
3244371
Added a funny easter egg
7267711
Added a funny easter egg
Kevinking500 e310ac8
Some QOL improvements, including merging the list commands
9e83962
Some QOL improvements, including merging list commands and allowing …
Kevinking500 b61c31b
Added some new options in the config
84a1bbc
Added some new options in the config
Kevinking500 34f3459
Update configuration.json
Kevinking500 f8427da
Fix self-ping condition to allow self-pinging
Kevinking500 9e6af40
Update to Discord.js V14 from ScootKit BETA
Kevinking500 b75f228
New updates from BETA fixes
Kevinking500 c2d3cad
Ping protection V1, in Discord.JS V14
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,206 @@ | ||
| const { | ||
| fetchModHistory, | ||
| getPingCountInWindow, | ||
| generateHistoryResponse, | ||
| generateActionsResponse | ||
| } = require('../ping-protection'); | ||
| const { localize } = require('../../../src/functions/localize'); | ||
| const { ActionRowBuilder, ButtonBuilder, EmbedBuilder, ButtonStyle, MessageFlags } = require('discord.js'); | ||
|
|
||
| module.exports.run = async function (interaction) { | ||
| const group = interaction.options.getSubcommandGroup(false); | ||
| const sub = interaction.options.getSubcommand(false); | ||
|
|
||
| if (group) { | ||
| return module.exports.subcommands[group][sub](interaction); | ||
| } | ||
| return module.exports.subcommands[sub](interaction); | ||
| }; | ||
|
|
||
| // Handles subcommands | ||
| module.exports.subcommands = { | ||
| 'user': { | ||
| 'history': async function (interaction) { | ||
| const user = interaction.options.getUser('user'); | ||
| const payload = await generateHistoryResponse(interaction.client, user.id, 1); | ||
| await interaction.reply(payload); | ||
| }, | ||
| 'actions-history': async function (interaction) { | ||
| const user = interaction.options.getUser('user'); | ||
| const payload = await generateActionsResponse(interaction.client, user.id, 1); | ||
| await interaction.reply(payload); | ||
| }, | ||
| 'panel': async function (interaction) { | ||
| const isAdmin = interaction.member.permissions.has('Administrator') || | ||
| (interaction.client.config.admins || []).includes(interaction.user.id); | ||
|
|
||
| if (!isAdmin) return interaction.reply({ | ||
| content: localize('ping-protection', 'no-permission'), | ||
| flags: MessageFlags.Ephemeral | ||
| }); | ||
|
|
||
| const user = interaction.options.getUser('user'); | ||
| const pingerId = user.id; | ||
| const storageConfig = interaction.client.configurations['ping-protection']['storage']; | ||
| const retentionWeeks = (storageConfig && storageConfig.pingHistoryRetention) | ||
| ? storageConfig.pingHistoryRetention | ||
| : 12; | ||
| const timeframeDays = retentionWeeks * 7; | ||
|
|
||
| const pingCount = await getPingCountInWindow(interaction.client, pingerId, timeframeDays); | ||
| const modData = await fetchModHistory(interaction.client, pingerId, 1, 1000); | ||
|
|
||
| const row = new ActionRowBuilder().addComponents( | ||
| new ButtonBuilder() | ||
| .setCustomId(`ping-protection_history_${user.id}`) | ||
| .setLabel(localize('ping-protection', 'btn-history')) | ||
| .setStyle(ButtonStyle.Secondary), | ||
| new ButtonBuilder() | ||
| .setCustomId(`ping-protection_actions_${user.id}`) | ||
| .setLabel(localize('ping-protection', 'btn-actions')) | ||
| .setStyle(ButtonStyle.Secondary), | ||
| new ButtonBuilder() | ||
| .setCustomId(`ping-protection_delete_${user.id}`) | ||
| .setLabel(localize('ping-protection', 'btn-delete')) | ||
| .setStyle(ButtonStyle.Danger) | ||
| ); | ||
|
|
||
| const embed = new EmbedBuilder() | ||
| .setTitle(localize('ping-protection', 'panel-title', { u: user.tag })) | ||
| .setDescription(localize('ping-protection', 'panel-description', { u: user.toString(), i: user.id })) | ||
| .setColor('Blue') | ||
| .setThumbnail(user.displayAvatarURL({ dynamic: true })) | ||
| .addFields([{ | ||
| name: localize('ping-protection', 'field-quick-history', { w: retentionWeeks }), | ||
| value: localize('ping-protection', 'field-quick-desc', { p: pingCount, m: modData.total }), | ||
| inline: false | ||
| }]); | ||
|
|
||
| await interaction.reply({ embeds: [embed.toJSON()], components: [row.toJSON()] }); | ||
| } | ||
| }, | ||
| 'list': { | ||
| 'protected': async function (interaction) { | ||
| await listHandler(interaction, 'protected'); | ||
| }, | ||
| 'whitelisted': async function (interaction) { | ||
| await listHandler(interaction, 'whitelisted'); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| // Handles list subcommands | ||
| async function listHandler(interaction, type) { | ||
| const config = interaction.client.configurations['ping-protection']['configuration']; | ||
| const embed = new EmbedBuilder() | ||
| .setColor('Green') | ||
| .setFooter({ | ||
| text: interaction.client.strings.footer, | ||
| iconURL: interaction.client.strings.footerImgUrl | ||
| }); | ||
|
|
||
| if (!interaction.client.strings.disableFooterTimestamp) embed.setTimestamp(); | ||
|
|
||
| if (type === 'protected') { | ||
| embed.setTitle(localize('ping-protection', 'list-protected-title')); | ||
| embed.setDescription(localize('ping-protection', 'list-protected-desc')); | ||
|
|
||
| const usersList = config.protectedUsers.length > 0 | ||
| ? config.protectedUsers.map(id => `<@${id}>`).join('\n') | ||
| : localize('ping-protection', 'list-none'); | ||
|
|
||
| const rolesList = config.protectedRoles.length > 0 | ||
| ? config.protectedRoles.map(id => `<@&${id}>`).join('\n') | ||
| : localize('ping-protection', 'list-none'); | ||
|
|
||
| embed.addFields([ | ||
| { name: localize('ping-protection', 'field-prot-users'), value: usersList, inline: true }, | ||
| { name: localize('ping-protection', 'field-prot-roles'), value: rolesList, inline: true } | ||
| ]); | ||
|
|
||
| } else if (type === 'whitelisted') { | ||
| embed.setTitle(localize('ping-protection', 'list-whitelist-title')); | ||
| embed.setDescription(localize('ping-protection', 'list-whitelist-desc')); | ||
|
|
||
| const rolesList = config.ignoredRoles.length > 0 | ||
| ? config.ignoredRoles.map(id => `<@&${id}>`).join('\n') | ||
| : localize('ping-protection', 'list-none'); | ||
|
|
||
| const channelsList = config.ignoredChannels.length > 0 | ||
| ? config.ignoredChannels.map(id => `<#${id}>`).join('\n') | ||
| : localize('ping-protection', 'list-none'); | ||
|
|
||
| embed.addFields([ | ||
| { name: localize('ping-protection', 'field-wl-roles'), value: rolesList, inline: true }, | ||
| { name: localize('ping-protection', 'field-wl-channels'), value: channelsList, inline: true } | ||
| ]); | ||
| } | ||
|
|
||
| await interaction.reply({ embeds: [embed.toJSON()] }); | ||
| } | ||
|
|
||
| module.exports.config = { | ||
| name: 'ping-protection', | ||
| description: localize('ping-protection', 'cmd-desc-module'), | ||
| usage: '/ping-protection', | ||
| type: 'slash', | ||
| options: [ | ||
| { | ||
| type: 'SUB_COMMAND_GROUP', | ||
| name: 'user', | ||
| description: localize('ping-protection', 'cmd-desc-group-user'), | ||
| options: [ | ||
| { | ||
| type: 'SUB_COMMAND', | ||
| name: 'history', | ||
| description: localize('ping-protection', 'cmd-desc-history'), | ||
| options: [{ | ||
| type: 'USER', | ||
| name: 'user', | ||
| description: localize('ping-protection', 'cmd-opt-user'), | ||
| required: true | ||
| }] | ||
| }, | ||
| { | ||
| type: 'SUB_COMMAND', | ||
| name: 'actions-history', | ||
| description: localize('ping-protection', 'cmd-desc-actions'), | ||
| options: [{ | ||
| type: 'USER', | ||
| name: 'user', | ||
| description: localize('ping-protection', 'cmd-opt-user'), | ||
| required: true | ||
| }] | ||
| }, | ||
| { | ||
| type: 'SUB_COMMAND', | ||
| name: 'panel', | ||
| description: localize('ping-protection', 'cmd-desc-panel'), | ||
| options: [{ | ||
| type: 'USER', | ||
| name: 'user', | ||
| description: localize('ping-protection', 'cmd-opt-user'), | ||
| required: true | ||
| }] | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| type: 'SUB_COMMAND_GROUP', | ||
| name: 'list', | ||
| description: localize('ping-protection', 'cmd-desc-group-list'), | ||
| options: [ | ||
| { | ||
| type: 'SUB_COMMAND', | ||
| name: 'protected', | ||
| description: localize('ping-protection', 'cmd-desc-list-protected') | ||
| }, | ||
| { | ||
| type: 'SUB_COMMAND', | ||
| name: 'whitelisted', | ||
| description: localize('ping-protection', 'cmd-desc-list-wl') | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| }; |
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.