Skip to content
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

Better Embeds, Pardons + Purges #11

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3b21377
embed-overhaul
DirectorReiuji Nov 25, 2022
c429f4a
purge-command
DirectorReiuji Nov 28, 2022
43c75a8
pardon-and-misc
DirectorReiuji Nov 29, 2022
7f0bbe6
log-unbans-and-consistency
DirectorReiuji Nov 29, 2022
4a35b85
bugfixes
DirectorReiuji Dec 1, 2022
6133180
Joke Regexes
DirectorReiuji Dec 2, 2022
24e2ccd
Fix switch function
DirectorReiuji Dec 2, 2022
29db884
Fixed broken regex
DirectorReiuji Dec 2, 2022
3f14f4c
Minor fixes
DirectorReiuji Dec 2, 2022
637cc2c
Fixes critical issue
DirectorReiuji Dec 16, 2022
afc8adb
Replaces settings-which
DirectorReiuji Dec 18, 2022
51419ab
Added Warnings
DirectorReiuji Dec 27, 2022
791a73f
Fixed issues (minus spacing)
DirectorReiuji Mar 6, 2024
5ec875c
Added fixes and fixed spacing
DirectorReiuji Mar 7, 2024
f22dfec
Added README banner
DirectorReiuji Mar 7, 2024
e2b6b39
Updated README to be more inline with Bandwidth's branding
DirectorReiuji Mar 7, 2024
05e4770
Added view kicks function
DirectorReiuji Mar 7, 2024
11f336c
Added poll deletion
DirectorReiuji Apr 10, 2024
4606c5c
Added poll deletion info
DirectorReiuji Apr 10, 2024
cfbdc86
Added attachment fix
DirectorReiuji Apr 10, 2024
560d2e2
Resolve hunting part one
DirectorReiuji Apr 12, 2024
a55e42d
Accidentally blocked package-lock
DirectorReiuji Apr 12, 2024
c94428d
Actual Resolve hunting
DirectorReiuji Apr 12, 2024
00fce5c
Merge branch 'chubby-overhaul' of https://github.com/DirectorReiuji/c…
DirectorReiuji Apr 12, 2024
6555d29
Even more resolve hunting
DirectorReiuji Apr 12, 2024
147a211
Reworked remove punishment command and made Poll Delete function
DirectorReiuji Apr 13, 2024
489cdaa
Removed useless check from pollDelete
DirectorReiuji Apr 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Chubby
Discord moderation bot for Pretendo
![Chubby Banner](./src/images/misc/chubby-banner.png)
---
Chubby, the official Pretendo Network Discord moderation bot.

Features:

- `/warn` command for warning users. Supports multiple users per warning. 3 warnings results in a kick. 4 warnings results in a ban
- `/kick` command for kicking users. Supports multiple users per kick. 3 kicks results in a ban
- `/ban` command for banning users. Supports multiple users per warning
- NSFW content detection
Chubby can:
- Detect and remove NSFW content
- Warn, kick, and ban multiple users at once
- Pardon warns and kicks from multiple users
- Purge messages from a channel or from a specified user
- Log user and moderation events
- Remove Discord polls
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You removed the names of the commands for these features?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, re-added them in the next commit.

5 changes: 5 additions & 0 deletions src/bot.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const Discord = require('discord.js');
const guildMemberRemoveHandler = require('./events/guildMemberRemove');
const guildMemberUpdateHandler = require('./events/guildMemberUpdate');
const guildMemberAddHandler = require('./events/guildMemberAdd');
const guildBanRemoveHandler = require('./events/guildBanRemove');
const interactionCreateHandler = require('./events/interactionCreate');
const messageCreateHandler = require('./events/messageCreate');
const messageDeleteHandler = require('./events/messageDelete');
Expand All @@ -13,6 +15,7 @@ const client = new Discord.Client({
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MESSAGES,
Discord.Intents.FLAGS.GUILD_MEMBERS,
Discord.Intents.FLAGS.GUILD_BANS,
]
});

Expand All @@ -21,6 +24,8 @@ client.commands = new Discord.Collection();
client.on('ready', readyHandler);
client.on('guildMemberRemove', guildMemberRemoveHandler);
client.on('guildMemberUpdate', guildMemberUpdateHandler);
client.on('guildMemberAdd', guildMemberAddHandler);
client.on('guildBanRemove', guildBanRemoveHandler);
client.on('interactionCreate', interactionCreateHandler);
client.on('messageCreate', messageCreateHandler);
client.on('messageDelete', messageDeleteHandler);
Expand Down
5 changes: 3 additions & 2 deletions src/check-nsfw.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ async function punishUserNSFW(message, suspectedUrls, suspectedFiles, prediction
console.log('Missing NSFW log channel!');
} else {
const embed = new Discord.MessageEmbed();
embed.setTitle(`Suspected NSFW Material sent by ${message.author.tag}`);
embed.setColor(0xffa500);
embed.setTitle('_NSFW Blocked_');
embed.setDescription(`Suspected NSFW Material sent by ${message.author.tag}`);
embed.setColor(0xdf005d);
embed.addFields([
{
name: 'Suspected URLs',
Expand Down
102 changes: 43 additions & 59 deletions src/commands/ban.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,33 @@ async function banHandler(interaction) {
const userIds = [...new Set(Array.from(users.matchAll(Discord.MessageMentions.USERS_PATTERN), match => match[1]))];

const bansListEmbed = new Discord.MessageEmbed();
bansListEmbed.setTitle('User Bans :thumbsdown:');
bansListEmbed.setColor(0xFFA500);
bansListEmbed.setTitle('User Bans');
bansListEmbed.setColor(0xa30000);
bansListEmbed.setThumbnail('attachment://mod-ban.png');

const image = new Discord.MessageAttachment('./src/images/mod/mod-ban.png');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly a nitpick, but please try to define variables like these close to where they will be used. Right now the way code like this reads, it's not clear right away where image is used when going top down. If going bottom up then it's not clear where image comes from

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I can't get as close as I wish I could, however I will rename them to be more specific.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No you're correct. I missed where this was used inside the loop. This placement is fine


for (const userId of userIds) {
const member = await interaction.guild.members.fetch(userId);
const user = member.user;

// Checks if they're above/equal to the executor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This goes for all comments. We use the syntax from Better Comments now. I've been migrating our older code to use it, but newer code should use it by default

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I use VS2022, so I'm not certain if I'll be able to see them, but nonetheless, I'll try implementing that after I resolve everything else.

if (member.roles.highest.position >= executingMember.roles.highest.position) {
await interaction.editReply(`You cannot ban ${user.username} as they have a higher role compared to you.`);
return;
}

// Creates mod logs
const eventLogEmbed = new Discord.MessageEmbed();

eventLogEmbed.setColor(0xF24E43);
eventLogEmbed.setDescription('――――――――――――――――――――――――――――――――――');
eventLogEmbed.setAuthor({
name: user.tag,
iconURL: user.avatarURL()
});
eventLogEmbed.setColor(0xa30000);
eventLogEmbed.setDescription(`${user.username} has been banned by ${executor.username}`);
eventLogEmbed.setTimestamp(Date.now());
eventLogEmbed.setTitle('Event Type: _Member Banned_');
eventLogEmbed.setTitle('_Member Banned_');
eventLogEmbed.setFields(
{
name: 'User',
Expand All @@ -44,96 +58,59 @@ async function banHandler(interaction) {
value: user.id
},
{
name: 'Executor',
name: 'Moderator',
value: `<@${executor.id}>`
},
{
name: 'Executor User ID',
name: 'Moderator User ID',
value: executor.id
},
{
name: 'Reason',
value: reason
},
{
name: 'From bot /ban command',
name: 'From Bot',
value: 'true'
}
);
eventLogEmbed.setFooter({
text: 'Pretendo Network',
iconURL: guild.iconURL()
});
eventLogEmbed.setThumbnail('attachment://mod-ban.png');

await util.sendEventLogMessage(guild, null, eventLogEmbed);
await util.sendEventLogMessage('channels.mod-logs', guild, null, eventLogEmbed, image, null);

const { count, rows } = await Bans.findAndCountAll({
const { count } = await Bans.findAndCountAll({
where: {
user_id: member.id
}
});

const sendMemberEmbeds = [];


const banEmbed = new Discord.MessageEmbed();

banEmbed.setTitle('Punishment Details');
banEmbed.setTitle('_Member Banned_');
banEmbed.setDescription('You have been banned from the Pretendo Network server. You may not rejoin at this time, and an appeal may not be possible\nYou may review the details of your ban below');
banEmbed.setColor(0xF24E43);
banEmbed.setThumbnail('attachment://mod-ban.png');
banEmbed.setColor(0xa30000);
banEmbed.setTimestamp(Date.now());
banEmbed.setAuthor({
name: `Banned by: ${executingMember.user.tag}`,
iconURL: executingMember.user.avatarURL()
});
banEmbed.setFooter({
text: 'Pretendo Network',
iconURL: guild.iconURL()
});
banEmbed.setFields({
name: 'Ban Reason',
value: reason
},
{
name: 'Amount Of Times Banned',
value: (count + 1).toString()
});

sendMemberEmbeds.push(banEmbed);

if (count > 0) {
const pastBansEmbed = new Discord.MessageEmbed();
pastBansEmbed.setTitle('Past Bans');
pastBansEmbed.setDescription('For clarifty purposes here is a list of your past bans');
pastBansEmbed.setColor(0xEF7F31);
pastBansEmbed.setTimestamp(Date.now());
pastBansEmbed.setFooter({
text: 'Pretendo Network',
iconURL: guild.iconURL()
});

for (let i = 0; i < rows.length; i++) {
const ban = rows[i];
const bannedBy = await interaction.client.users.fetch(ban.admin_user_id);

pastBansEmbed.addFields(
{
name: `${util.ordinal(i + 1)} Ban`,
value: ban.reason
},
{
name: 'Punished By',
value: bannedBy.tag,
inline: true
},
{
name: 'Date',
value: ban.timestamp.toLocaleDateString(),
inline: true
}
);
}

sendMemberEmbeds.push(pastBansEmbed);
}

Comment on lines -97 to -134
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for this removal?

Copy link
Author

@DirectorReiuji DirectorReiuji Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's due to possible errors with the new pardon system.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What possible errors? Can you be more specific?

await member.send({
embeds: sendMemberEmbeds
embeds: [banEmbed],
files: [image]
}).catch(() => console.log('Failed to DM user'));

await member.ban({
Expand All @@ -146,10 +123,17 @@ async function banHandler(interaction) {
reason: reason
});

bansListEmbed.setDescription(`${user.username} has been successfully banned`)
bansListEmbed.addField(`${member.user.username}'s bans`, (count + 1).toString(), true);
bansListEmbed.setFooter({
text: 'Pretendo Network',
iconURL: guild.iconURL()
});
bansListEmbed.setTimestamp(Date.now());

}

await interaction.editReply({ embeds: [bansListEmbed], ephemeral: true });
await interaction.editReply({ embeds: [bansListEmbed], files: [image], ephemeral: true });
}

const command = new SlashCommandBuilder()
Expand Down
Loading