Skip to content

Commit

Permalink
Added global-blacklist, moved grab, Minor bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMonDon committed Jul 20, 2024
1 parent 34a266e commit 96b1095
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 26 deletions.
106 changes: 106 additions & 0 deletions commands/Bot Admin/global-blacklist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
const Command = require('../../base/Command.js');
const { EmbedBuilder } = require('discord.js');
const { QuickDB } = require('quick.db');
const db = new QuickDB();

class Blacklist extends Command {
constructor(client) {
super(client, {
name: 'global-blacklist',
description: 'Blacklist someone from using the bot',
usage: 'global-blacklist <Add | Remove | Check> <User> <Reason>',
requiredArgs: 1,
category: 'Bot Admin',
permLevel: 'Bot Admin',
aliases: ['gbl', 'g-blacklist', 'gblacklist'],
guildOnly: true,
});
}

async run(msg, args) {
let mem;
let type;

if (args[0] && args[1]) {
if (!['add', 'remove', 'check'].includes(args[0].toLowerCase())) {
return this.client.util.errorEmbed(msg, msg.settings.prefix + this.help.usage, 'Incorrect Usage');
} else {
type = args[0].toLowerCase();
}
} else if (args[0]) {
mem = await this.client.util.getMember(msg, args[0]);
type = 'check';

if (!mem) return this.client.util.errorEmbed(msg, msg.settings.prefix + this.help.usage, 'Incorrect Usage');
}

if (!mem && args[1]) {
mem = await this.client.util.getMember(msg, args[1]);

if (!mem) return this.client.util.errorEmbed(msg, msg.settings.prefix + this.help.usage, 'Invalid Member');
}

args.shift();
args.shift();
const reason = args.join(' ') || false;

const blacklist = await db.get(`users.${mem.id}.blacklist`);

const embed = new EmbedBuilder()
.setAuthor({ name: mem.user.tag, iconURL: msg.author.displayAvatarURL() })
.setColor(msg.settings.embedColor)
.setTimestamp();

switch (type) {
case 'add': {
if (blacklist) {
return msg.channel.send('That user is already blacklisted.');
}
if (!reason) return this.client.util.errorEmbed(msg, msg.settings.prefix + this.help.usage, 'Invalid Reason');

await db.set(`users.${mem.id}.blacklist`, true);
await db.set(`users.${mem.id}.blacklistReason`, reason);

embed.setTitle(`${mem.user.tag} has been added to the global blacklist.`).addFields([
{ name: 'Reason:', value: reason },
{ name: 'Member:', value: `${mem.displayName} \n(${mem.id})` },
{ name: 'Server:', value: `${msg.guild.name} \n(${msg.guild.id})` },
]);

msg.channel.send({ embeds: [embed] });
return mem.send({ embeds: [embed] });
}

case 'remove': {
if (!blacklist) return msg.channel.send('That user is not blacklisted');
if (!reason) return this.client.util.errorEmbed(msg, msg.settings.prefix + this.help.usage, 'Invalid Reason');

await db.set(`users.${mem.id}.blacklist`, false);
await db.set(`users.${mem.id}.blacklistReason`, reason);

embed.setTitle(`${mem.user.tag} has been removed from the global blacklist.`).addFields([
{ name: 'Reason:', value: reason },
{ name: 'Member:', value: `${mem.displayName} \n(${mem.id})` },
{ name: 'Server:', value: `${msg.guild.name} \n(${msg.guild.id})` },
]);

msg.channel.send({ embeds: [embed] });
return mem.send({ embeds: [embed] });
}

case 'check': {
const reason = (await db.get(`users.${mem.id}.blacklistReason`)) || false;

embed.setTitle(`${mem.user.tag} blacklist check`).addFields([
{ name: 'Member:', value: `${mem.user.tag} (${mem.id})`, inline: true },
{ name: 'Is Blacklisted?', value: blacklist ? 'True' : 'False' },
]);
if (reason) embed.addFields([{ name: 'Reason', value: reason, inline: true }]);

return msg.channel.send({ embeds: [embed] });
}
}
}
}

module.exports = Blacklist;
6 changes: 3 additions & 3 deletions commands/Economy/balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ class Balance extends Command {
try {
const user = await this.client.users.cache.get(userId);
if (user) {
const userCash = BigInt(parseInt(usersData[userId].economy.cash || 0, 10));
const userBank = BigInt(parseInt(usersData[userId].economy.bank || 0, 10));
const userCash = BigInt(parseInt(usersData[userId]?.economy?.cash || 0, 10));
const userBank = BigInt(parseInt(usersData[userId]?.economy?.bank || 0, 10));
const userMoney = userCash + userBank;
leaderboard.push({ user: user.tag, userId: user.id, money: userMoney });
}
} catch (err) {
this.client.logger.error(`Leaderboard: ${err}`);
this.client.logger.error(`Balance Leaderboard: ${err}`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion commands/Economy/clean-leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CleanLeaderboard extends Command {

if (verified) {
toRemove.forEach(async (i) => {
await db.delete(`servers.${msg.guild.id}.users.${i}`);
await db.delete(`servers.${msg.guild.id}.users.${i}.economy`);
});
return msg.channel.send(`${toRemove.length} users have been removed from the leaderboard.`);
} else {
Expand Down
4 changes: 2 additions & 2 deletions commands/Economy/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class Leaderboard extends Command {
try {
const user = await this.client.users.cache.get(userId);
if (user) {
const cash = parseInt(usersData[userId].economy.cash || 0, 10);
const bank = parseInt(usersData[userId].economy.bank || 0, 10);
const cash = parseInt(usersData[userId]?.economy?.cash || 0, 10);
const bank = parseInt(usersData[userId]?.economy?.bank || 0, 10);
const money = BigInt(cash) + BigInt(bank);
leaderboard.push({ user: user.tag, userId: user.id, money });
}
Expand Down
3 changes: 1 addition & 2 deletions commands/Economy/remove-money-role.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ class RemoveMoneyRole extends Command {
let role;
let amount;

const currencySymbol = (await db.get(`servers.${msg.guild.id}.economy.symbol`)) || '$';

if (args.length === 2) {
role = this.client.util.getRole(msg, args[0]);
amount = args[1].replace(/[^0-9\\.]/g, '');
Expand Down Expand Up @@ -71,6 +69,7 @@ class RemoveMoneyRole extends Command {
}
});

const currencySymbol = (await db.get(`servers.${msg.guild.id}.economy.symbol`)) || '$';
let csAmount = currencySymbol + amount.toLocaleString();
csAmount = csAmount.length > 1024 ? `${csAmount.slice(0, 1021) + '...'}` : csAmount;

Expand Down
8 changes: 4 additions & 4 deletions commands/Economy/reset-money.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ class ResetMoney extends Command {
});
}

async run(msg, text, level) {
async run(msg, args, level) {
async function resetBalance(msg, mem) {
const amount = (await db.get(`servers.${msg.guild.id}.economy.startBalance`)) || 0;
await db.set(`servers.${msg.guild.id}.users.${mem.id}.economy.cash`, amount);
await db.set(`servers.${msg.guild.id}.users.${mem.id}.economy.bank`, 0);
return true;
}

if (!text || text.length < 1) {
if (!args || args.length < 1) {
await msg.channel.send('Are you sure you want to reset your money? (yes/no)');
const verification = await this.client.util.verify(msg.channel, msg.author);
if (verification) {
Expand All @@ -42,10 +42,10 @@ This command requires level ${this.client.levelCache.Moderator} (Moderator)`);
}
}

let mem = await this.client.util.getMember(msg, text.join(' '));
let mem = await this.client.util.getMember(msg, args.join(' '));

if (!mem) {
const fid = text.join(' ').replace(/<@|>/g, '');
const fid = args.join(' ').replace(/<@|>/g, '');
try {
mem = await this.client.users.fetch(fid);
} catch (err) {
Expand Down
3 changes: 1 addition & 2 deletions commands/Owner/grab.js → commands/General/grab.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ class Grab extends Command {
super(client, {
name: 'grab',
description: 'Get the source code of a command.',
category: 'Owner',
permLevel: 'Bot Owner',
category: 'General',
usage: 'grab [-i] <commandName>',
requiredArgs: 1,
});
Expand Down
12 changes: 4 additions & 8 deletions commands/Moderator/blacklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Blacklist extends Command {
constructor(client) {
super(client, {
name: 'blacklist',
description: 'Blacklist someone from using the bot',
description: 'Blacklist someone from using the bot in your server',
usage: 'blacklist <Add | Remove | Check> <User> <Reason>',
requiredArgs: 1,
category: 'Moderator',
Expand Down Expand Up @@ -53,7 +53,6 @@ class Blacklist extends Command {

switch (type) {
case 'add': {
// Add member to blacklist
if (blacklist) {
return msg.channel.send('That user is already blacklisted.');
}
Expand All @@ -73,14 +72,13 @@ class Blacklist extends Command {
}

case 'remove': {
// remove member from blacklist
if (!blacklist) return msg.channel.send('That user is not blacklisted');
if (!reason) return this.client.util.errorEmbed(msg, msg.settings.prefix + this.help.usage, 'Invalid Reason');

await db.set(`servers.${msg.guild.id}.users.${mem.id}.blacklist`, false);
await db.set(`servers.${msg.guild.id}.users.${mem.id}.blacklistReason`, reason);

embed.setTitle(`${mem.user.tag} has been removed to the blacklist.`).addFields([
embed.setTitle(`${mem.user.tag} has been removed from the blacklist.`).addFields([
{ name: 'Reason:', value: reason },
{ name: 'Member:', value: `${mem.displayName} \n(${mem.id})` },
{ name: 'Server:', value: `${msg.guild.name} \n(${msg.guild.id})` },
Expand All @@ -91,15 +89,13 @@ class Blacklist extends Command {
}

case 'check': {
// check if member is blacklisted
const reason = (await db.get(`servers.${msg.guild.id}.users.${mem.id}.blacklistReason`)) || false;

const bl = blacklist ? 'is' : 'is not';
embed.setTitle(`${mem.user.tag} blacklist check`).addFields([
{ name: 'Member:', value: `${mem.user.tag} (${mem.id})`, inline: true },
{ name: 'Is Blacklisted?', value: `That user ${bl} blacklisted.` },
{ name: 'Is Blacklisted?', value: blacklist ? 'True' : 'False' },
]);
if (reason) embed.addFields([{ name: 'reason', value: reason, inline: true }]);
if (reason) embed.addFields([{ name: 'Reason', value: reason, inline: true }]);

return msg.channel.send({ embeds: [embed] });
}
Expand Down
28 changes: 26 additions & 2 deletions events/Interaction/interactionCreate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,36 @@ import { QuickDB } from 'quick.db';
const db = new QuickDB();

export async function run(client, interaction) {
interaction.settings = client.getSettings(interaction.guild);

const globalBlacklisted = db.get(`users.${interaction.user.id}.blacklist`);
if (globalBlacklisted) {
const embed = new EmbedBuilder()
.setTitle('Blacklisted')
.setAuthor({ name: interaction.user.tag, iconURL: interaction.user.displayAvatarURL() })
.setColor(interaction.settings.embedErrorColor)
.setDescription(`Sorry ${interaction.user.username}, you are currently blacklisted from using commands.`);
return interaction.reply({ embeds: [embed], ephemeral: true });
}

if (interaction.guild) {
const blacklisted = db.get(`servers.${interaction.guild.id}.users.${interaction.user.id}.blacklist`);
if (blacklisted) {
const embed = new EmbedBuilder()
.setTitle('Blacklisted')
.setAuthor({ name: interaction.user.tag, iconURL: interaction.user.displayAvatarURL() })
.setColor(interaction.settings.embedErrorColor)
.setDescription(
`Sorry ${interaction.user.username}, you are currently blacklisted from using commands in this server.`,
);
return interaction.reply({ embeds: [embed], ephemeral: true });
}
}

if (interaction.isCommand()) {
const slashCommand = client.slashCommands.get(interaction.commandName);
if (!slashCommand) return;

interaction.settings = client.getSettings(interaction.guild);

const level = client.permlevel(interaction);
if (level < client.levelCache[slashCommand.conf.permLevel]) {
const embed = new EmbedBuilder()
Expand Down
7 changes: 6 additions & 1 deletion events/Message/messageCreate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,18 @@ export async function run(client, message) {

if (message.guild) {
const isBlacklisted = await db.get(`servers.${message.guild.id}.users.${message.member.id}.blacklist`);
if (isBlacklisted && level < 4 && command.help.name !== 'blacklist') {
if (isBlacklisted && level < 4 && (command.help.name !== 'blacklist' || command.help.name !== 'global-blacklist')) {
return message.channel.send(
`Sorry ${message.member.displayName}, you are currently blacklisted from using commands in this server.`,
);
}
}

const globalBlacklisted = await db.get(`users.${message.member.id}.blacklist`);
if (globalBlacklisted) {
return message.channel.send(`Sorry ${message.author.username}, you are currently blacklisted from using commands.`);
}

if (!message.guild && command.conf.guildOnly) {
return message.channel.send('This command is unavailable via private message. Please run this command in a guild.');
}
Expand Down
7 changes: 7 additions & 0 deletions events/Message/messageUpdate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ export async function run(client, oldMessage, newMessage) {
}
}

const globalBlacklisted = await db.get(`users.${newMessage.member.id}.blacklist`);
if (globalBlacklisted) {
return newMessage.channel.send(
`Sorry ${newMessage.author.username}, you are currently blacklisted from using commands.`,
);
}

// Some commands may not be useable in DMs. This check prevents those commands from running
// and return a friendly error message.
if (!newMessage.guild && cmd.conf.guildOnly) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mythical",
"version": "5.2.1",
"version": "5.3.0",
"description": "Mythical Bot",
"owner": "themondon",
"main": "index.js",
Expand Down

0 comments on commit 96b1095

Please sign in to comment.