From 560ed31860a420dcc43571d2e12dd2f51bcee7a8 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Wed, 1 Sep 2021 22:19:41 -0400 Subject: cleanup --- src/bot.ts | 2 +- src/commands/admin/channelPermissions.ts | 2 +- src/commands/admin/roleAll.ts | 11 +--- src/commands/dev/__template.ts | 2 +- src/commands/dev/setLevel.ts | 77 ----------------------- src/commands/dev/test.ts | 39 ++++++------ src/commands/info/color.ts | 9 +-- src/commands/leveling/level.ts | 6 +- src/commands/leveling/setLevel.ts | 78 ++++++++++++++++++++++++ src/commands/moderation/_lockdown.ts | 3 +- src/commands/moulberry-bush/capes.ts | 12 ++-- src/commands/moulberry-bush/moulHammer.ts | 38 ++++++++++++ src/commands/moulberry-bush/moulHammerCommand.ts | 38 ------------ src/lib/utils/BushConstants.ts | 18 +++--- src/tasks/removeExpiredPunishements.ts | 10 +-- 15 files changed, 168 insertions(+), 177 deletions(-) delete mode 100644 src/commands/dev/setLevel.ts create mode 100644 src/commands/leveling/setLevel.ts create mode 100644 src/commands/moulberry-bush/moulHammer.ts delete mode 100644 src/commands/moulberry-bush/moulHammerCommand.ts (limited to 'src') diff --git a/src/bot.ts b/src/bot.ts index a04a4fc..46b857d 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -4,5 +4,5 @@ import config from './config/options'; import { BushClient } from './lib/'; BushClient.preStart(); -const client: BushClient = new BushClient(config); +const client = new BushClient(config); void client.start(); diff --git a/src/commands/admin/channelPermissions.ts b/src/commands/admin/channelPermissions.ts index ea97343..3b8c157 100644 --- a/src/commands/admin/channelPermissions.ts +++ b/src/commands/admin/channelPermissions.ts @@ -71,7 +71,7 @@ export default class ChannelPermissionsCommand extends BushCommand { await channel.permissionOverwrites.create( target.id, { [permission]: permissionState }, - { reason: 'Changing overwrites for mass channel channel perms command' } + { reason: 'Changing overwrites for mass channel perms command' } ); } catch (e) { client.console.debug(e.stack); diff --git a/src/commands/admin/roleAll.ts b/src/commands/admin/roleAll.ts index 2382a4b..7e60f40 100644 --- a/src/commands/admin/roleAll.ts +++ b/src/commands/admin/roleAll.ts @@ -5,7 +5,7 @@ export default class RoleAllCommand extends BushCommand { public constructor() { super('roleAll', { aliases: ['roleall', 'rall'], - category: 'Server Admin', + category: 'admin', description: { content: 'Give a role to every member on the server.', usage: 'roleAll [another role]... [--bots]', @@ -45,11 +45,8 @@ export default class RoleAllCommand extends BushCommand { ); } - console.time('roleAll1'); let members = await message.guild.members.fetch(); - console.timeEnd('roleAll1'); - console.time('roleAll2'); members = members.filter((member: GuildMember) => { try { if (member.user.bot && !args.bot) return false; @@ -59,21 +56,15 @@ export default class RoleAllCommand extends BushCommand { } return true; }); - console.timeEnd('roleAll2'); - console.time('roleAll3'); await message.util.reply(`${this.client.util.emojis.loading} adding roles to ${members.size} members`); console.timeEnd('roleAll3'); - console.time('roleAll4'); const promises = members.map((member: GuildMember) => { return member.roles.add(args.role, `RoleAll Command - triggered by ${message.author.tag} (${message.author.id})`); }); - console.timeEnd('roleAll4'); - console.time('roleAll5'); const failed = (await Promise.allSettled(promises)).filter((val) => val.status === 'rejected'); - console.timeEnd('roleAll5'); if (!failed.length) { await message.util.reply({ diff --git a/src/commands/dev/__template.ts b/src/commands/dev/__template.ts index 4cf407c..49549af 100644 --- a/src/commands/dev/__template.ts +++ b/src/commands/dev/__template.ts @@ -56,7 +56,7 @@ export default class TemplateCommand extends BushCommand { public override async exec( message: BushMessage | BushSlashMessage, - args: { required_argument: string; optional_argumen: string } + args: { required_argument: string; optional_argument: string } ): Promise { return await message.util.reply(`${util.emojis.error} Do not use the template command.`); args; diff --git a/src/commands/dev/setLevel.ts b/src/commands/dev/setLevel.ts deleted file mode 100644 index 777ef60..0000000 --- a/src/commands/dev/setLevel.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { AllowedMentions, BushCommand, BushMessage, BushSlashMessage, Level } from '@lib'; -import { User } from 'discord.js'; - -export default class SetLevelCommand extends BushCommand { - public constructor() { - super('setlevel', { - aliases: ['setlevel'], - category: 'dev', - description: { - content: 'Sets the level of a user', - usage: 'setlevel ', - examples: ['setlevel @Moulberry 69'] //nice - }, - args: [ - { - id: 'user', - type: 'user', - prompt: { - start: 'What user would you like to change the level of?', - retry: '{error} Choose a valid user to change the level of.' - } - }, - { - id: 'level', - type: 'number', - prompt: { - start: 'What level would you like to set the user to?', - retry: '{error} Choose a valid level to set the user to.' - } - } - ], - slashOptions: [ - { - name: 'user', - description: 'What user would you like to change the level of?', - type: 'USER', - required: true - }, - { - name: 'level', - description: 'What level would you like to set the user to?', - type: 'INTEGER', - required: true - } - ], - ownerOnly: true, - slash: true, - channel: 'guild' - }); - } - - public override async exec( - message: BushMessage | BushSlashMessage, - { user, level }: { user: User; level: number } - ): Promise { - if (!message.author.isOwner()) - return await message.util.reply(`${util.emojis.error} Only my developers can run this command.`); - if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be run in a guild.`); - if (!user.id) throw new Error('user.id is null'); - - const [levelEntry] = await Level.findOrBuild({ - where: { - user: user.id, - guild: message.guild.id - }, - defaults: { - user: user.id, - guild: message.guild.id - } - }); - await levelEntry.update({ xp: Level.convertLevelToXp(level) }); - return await message.util.send({ - content: `Successfully set level of <@${user.id}> to \`${level}\` (\`${levelEntry.xp}\` XP)`, - allowedMentions: AllowedMentions.none() - }); - } -} diff --git a/src/commands/dev/test.ts b/src/commands/dev/test.ts index bb0807b..104861f 100644 --- a/src/commands/dev/test.ts +++ b/src/commands/dev/test.ts @@ -1,5 +1,12 @@ import { BushCommand, BushMessage } from '@lib'; -import { Constants as jsConstants, MessageActionRow, MessageButton, MessageEmbed } from 'discord.js'; +import { + ApplicationCommand, + Collection, + Constants as jsConstants, + MessageActionRow, + MessageButton, + MessageEmbed +} from 'discord.js'; export default class TestCommand extends BushCommand { public constructor() { @@ -126,28 +133,18 @@ export default class TestCommand extends BushCommand { } return await message.util.reply({ content: 'this is content', components: ButtonRows, embeds }); } else if (['delete slash commands'].includes(args?.feature?.toLowerCase())) { - // let guildCommandCount = 0; - // client.guilds.cache.forEach(guild => - // guild.commands.fetch().then(commands => { - // commands.forEach(async command => { - // await command.delete(); - // guildCommandCount++; - // }); - // }) - // ); if (!message.guild) return await message.util.reply(`${util.emojis.error} This test can only be run in a guild.`); - const guildCommands = await message.guild.commands.fetch(); - // eslint-disable-next-line @typescript-eslint/no-misused-promises - guildCommands.forEach(async (command) => await command.delete()); - const globalCommands = await client.application!.commands.fetch(); - // eslint-disable-next-line @typescript-eslint/no-misused-promises - globalCommands.forEach(async (command) => await command.delete()); + await client.guilds.fetch(); + const promises: Promise>[] = []; + client.guilds.cache.each((guild) => { + promises.push(guild.commands.set([])); + }); + await Promise.all(promises); - return await message.util.reply( - `${util.emojis.success} Removed **${/* guildCommandCount */ guildCommands.size}** guild commands and **${ - globalCommands.size - }** global commands.` - ); + await client.application!.commands.fetch(); + await client.application!.commands.set([]); + + return await message.util.reply(`${util.emojis.success} Removed guild commands and global commands.`); } else if (['drop down', 'drop downs', 'select menu', 'select menus'].includes(args?.feature?.toLowerCase())) { } return await message.util.reply(responses[Math.floor(Math.random() * responses.length)]); diff --git a/src/commands/info/color.ts b/src/commands/info/color.ts index 350c23d..5268516 100644 --- a/src/commands/info/color.ts +++ b/src/commands/info/color.ts @@ -1,13 +1,13 @@ import { AllowedMentions, BushCommand, BushGuildMember, BushMessage, BushRole, BushSlashMessage } from '@lib'; import { Argument } from 'discord-akairo'; import { Message, MessageEmbed, Role } from 'discord.js'; -import { Constructor } from 'tinycolor2'; +import tinycolor from 'tinycolor2'; // this is the only way I got it to work consistently -// eslint-disable-next-line @typescript-eslint/no-var-requires -const tinycolor: Constructor = require('tinycolor2'); // this is the only way I got it to work consistently const isValidTinyColor = (_message: Message, phase: string) => { + console.dir(phase); // if the phase is a number it converts it to hex incase it could be representing a color in decimal - const newPhase = Number.isNaN(phase) ? phase : `#${Number(phase).toString(16)}`; + const newPhase = isNaN(phase as any) ? phase : `#${Number(phase).toString(16)}`; + console.dir(newPhase); return tinycolor(newPhase).isValid() ? newPhase : null; }; @@ -25,6 +25,7 @@ export default class ColorCommand extends BushCommand { { id: 'color', customType: Argument.union(isValidTinyColor, 'role', 'member'), + match: 'restContent', prompt: { start: 'What color code, role, or user would you like to find the color of?', retry: '{error} Choose a valid color, role, or member.' diff --git a/src/commands/leveling/level.ts b/src/commands/leveling/level.ts index f22ed8d..223a590 100644 --- a/src/commands/leveling/level.ts +++ b/src/commands/leveling/level.ts @@ -35,6 +35,7 @@ export default class LevelCommand extends BushCommand { } } ], + slash: true, slashOptions: [ { name: 'user', @@ -43,8 +44,9 @@ export default class LevelCommand extends BushCommand { required: false } ], - slash: true, - channel: 'guild' + channel: 'guild', + clientPermissions: ['SEND_MESSAGES'], + userPermissions: ['SEND_MESSAGES'] }); } diff --git a/src/commands/leveling/setLevel.ts b/src/commands/leveling/setLevel.ts new file mode 100644 index 0000000..be3700a --- /dev/null +++ b/src/commands/leveling/setLevel.ts @@ -0,0 +1,78 @@ +import { AllowedMentions, BushCommand, BushMessage, BushSlashMessage, Level } from '@lib'; +import { User } from 'discord.js'; + +export default class SetLevelCommand extends BushCommand { + public constructor() { + super('setlevel', { + aliases: ['setlevel'], + category: 'leveling', + description: { + content: 'Sets the level of a user', + usage: 'setlevel ', + examples: ['setlevel @Moulberry 69'] //nice + }, + args: [ + { + id: 'user', + type: 'user', + prompt: { + start: 'What user would you like to change the level of?', + retry: '{error} Choose a valid user to change the level of.' + } + }, + { + id: 'level', + type: 'number', + prompt: { + start: 'What level would you like to set the user to?', + retry: '{error} Choose a valid level to set the user to.' + } + } + ], + slashOptions: [ + { + name: 'user', + description: 'What user would you like to change the level of?', + type: 'USER', + required: true + }, + { + name: 'level', + description: 'What level would you like to set the user to?', + type: 'INTEGER', + required: true + } + ], + slash: true, + channel: 'guild', + clientPermissions: ['SEND_MESSAGES'], + userPermissions: ['SEND_MESSAGES', 'ADMINISTRATOR'] + }); + } + + public override async exec( + message: BushMessage | BushSlashMessage, + { user, level }: { user: User; level: number } + ): Promise { + if (!message.author.isOwner()) + return await message.util.reply(`${util.emojis.error} Only my developers can run this command.`); + if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be run in a guild.`); + if (!user.id) throw new Error('user.id is null'); + + const [levelEntry] = await Level.findOrBuild({ + where: { + user: user.id, + guild: message.guild.id + }, + defaults: { + user: user.id, + guild: message.guild.id + } + }); + await levelEntry.update({ xp: Level.convertLevelToXp(level) }); + return await message.util.send({ + content: `Successfully set level of <@${user.id}> to \`${level}\` (\`${levelEntry.xp}\` XP)`, + allowedMentions: AllowedMentions.none() + }); + } +} diff --git a/src/commands/moderation/_lockdown.ts b/src/commands/moderation/_lockdown.ts index b7bf4b2..68197df 100644 --- a/src/commands/moderation/_lockdown.ts +++ b/src/commands/moderation/_lockdown.ts @@ -28,7 +28,8 @@ export default class LockdownCommand extends BushCommand { ], channel: 'guild', clientPermissions: ['SEND_MESSAGES'], - userPermissions: ['SEND_MESSAGES'] + userPermissions: ['SEND_MESSAGES'], + hidden: true }); } diff --git a/src/commands/moulberry-bush/capes.ts b/src/commands/moulberry-bush/capes.ts index c8d1a05..447d604 100644 --- a/src/commands/moulberry-bush/capes.ts +++ b/src/commands/moulberry-bush/capes.ts @@ -49,7 +49,6 @@ export default class CapesCommand extends BushCommand { default: null } ], - clientPermissions: ['EMBED_LINKS', 'SEND_MESSAGES'], slash: true, slashOptions: [ { @@ -58,7 +57,9 @@ export default class CapesCommand extends BushCommand { type: 'STRING', required: false } - ] + ], + clientPermissions: ['EMBED_LINKS', 'SEND_MESSAGES'], + userPermissions: ['SEND_MESSAGES'] }); } @@ -73,17 +74,17 @@ export default class CapesCommand extends BushCommand { })) .filter((f) => f.match !== null); - const capes1: { name: string; url: string; index: number }[] = []; + const capes1: { name: string; url: string; index: number; purchasable?: boolean }[] = []; client.consts.mappings.capes.forEach((mapCape) => { if (!capes.some((gitCape) => gitCape.match!.groups!.name === mapCape.name) && mapCape.custom) { - capes1.push({ name: mapCape.name, url: mapCape.custom, index: mapCape.index }); + capes1.push({ name: mapCape.name, url: mapCape.custom, index: mapCape.index, purchasable: mapCape.purchasable }); } }); capes.forEach((gitCape) => { const mapCape = client.consts.mappings.capes.find((a) => a.name === gitCape.match!.groups!.name); const url = mapCape?.custom ?? `https://github.com/Moulberry/NotEnoughUpdates/raw/master/${gitCape.f.path}`; const index = mapCape?.index !== undefined ? mapCape.index : null; - capes1.push({ name: gitCape.match!.groups!.name, url, index: index! }); + capes1.push({ name: gitCape.match!.groups!.name, url, index: index!, purchasable: mapCape?.purchasable }); }); const sortedCapes = capes1.sort((a, b) => { @@ -123,6 +124,7 @@ export default class CapesCommand extends BushCommand { color: util.colors.default }).setTimestamp(); embed.setImage(capeObj.url); + if (capeObj.purchasable) embed.setDescription(':money_with_wings: **purchasable** :money_with_wings:'); embeds.push(embed); } await util.buttonPaginate(message, embeds, null); diff --git a/src/commands/moulberry-bush/moulHammer.ts b/src/commands/moulberry-bush/moulHammer.ts new file mode 100644 index 0000000..bc60372 --- /dev/null +++ b/src/commands/moulberry-bush/moulHammer.ts @@ -0,0 +1,38 @@ +import { MessageEmbed, User } from 'discord.js'; +import { BushCommand, BushMessage } from '../../lib'; + +export default class MoulHammerCommand extends BushCommand { + public constructor() { + super('moulHammer', { + aliases: ['moulhammer'], + category: "Moulberry's Bush", + description: { + content: 'A command to moul hammer members.', + usage: 'moulHammer ', + examples: ['moulHammer @IRONM00N'] + }, + clientPermissions: ['EMBED_LINKS', 'SEND_MESSAGES'], + userPermissions: ['SEND_MESSAGES'], + args: [ + { + id: 'user', + type: 'user', + prompt: { + start: 'What user would you like to moul hammer?', + retry: '{error} Choose a valid user to moul hammer' + } + } + ], + restrictedGuilds: ['516977525906341928'] + }); + } + + public override async exec(message: BushMessage, { user }: { user: User }): Promise { + await message.delete(); + const embed = new MessageEmbed() + .setTitle('L') + .setDescription(`${user.username} got moul'ed <:wideberry1:756223352598691942><:wideberry2:756223336832303154>`) + .setColor(this.client.util.colors.purple); + await message.util.send({ embeds: [embed] }); + } +} diff --git a/src/commands/moulberry-bush/moulHammerCommand.ts b/src/commands/moulberry-bush/moulHammerCommand.ts deleted file mode 100644 index bc60372..0000000 --- a/src/commands/moulberry-bush/moulHammerCommand.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { MessageEmbed, User } from 'discord.js'; -import { BushCommand, BushMessage } from '../../lib'; - -export default class MoulHammerCommand extends BushCommand { - public constructor() { - super('moulHammer', { - aliases: ['moulhammer'], - category: "Moulberry's Bush", - description: { - content: 'A command to moul hammer members.', - usage: 'moulHammer ', - examples: ['moulHammer @IRONM00N'] - }, - clientPermissions: ['EMBED_LINKS', 'SEND_MESSAGES'], - userPermissions: ['SEND_MESSAGES'], - args: [ - { - id: 'user', - type: 'user', - prompt: { - start: 'What user would you like to moul hammer?', - retry: '{error} Choose a valid user to moul hammer' - } - } - ], - restrictedGuilds: ['516977525906341928'] - }); - } - - public override async exec(message: BushMessage, { user }: { user: User }): Promise { - await message.delete(); - const embed = new MessageEmbed() - .setTitle('L') - .setDescription(`${user.username} got moul'ed <:wideberry1:756223352598691942><:wideberry2:756223336832303154>`) - .setColor(this.client.util.colors.purple); - await message.util.send({ embeds: [embed] }); - } -} diff --git a/src/lib/utils/BushConstants.ts b/src/lib/utils/BushConstants.ts index 17880cb..9eb96b3 100644 --- a/src/lib/utils/BushConstants.ts +++ b/src/lib/utils/BushConstants.ts @@ -333,15 +333,15 @@ export class BushConstants { // prettier-ignore capes: [ /* supporter capes */ - { name: 'patreon1', index: 0 }, - { name: 'patreon2', index: 1 }, - { name: 'fade', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/fade.gif', index: 2 }, - { name: 'lava', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/lava.gif', index: 3 }, - { name: 'mcworld', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/mcworld_compressed.gif', index: 4 }, - { name: 'negative', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/negative_compressed.gif', index: 5 }, - { name: 'space', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/space_compressed.gif', index: 6 }, - { name: 'void', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/void.gif', index: 7 }, - { name: 'tunnel', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/tunnel.gif', index: 8 }, + { name: 'patreon1', index: 0, purchasable: true }, + { name: 'patreon2', index: 1, purchasable: true }, + { name: 'fade', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/fade.gif', index: 2, purchasable: true }, + { name: 'lava', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/lava.gif', index: 3, purchasable: true }, + { name: 'mcworld', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/mcworld_compressed.gif', index: 4, purchasable: true }, + { name: 'negative', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/negative_compressed.gif', index: 5, purchasable: true }, + { name: 'space', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/space_compressed.gif', index: 6, purchasable: true }, + { name: 'void', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/void.gif', index: 7, purchasable: true }, + { name: 'tunnel', custom: 'https://raw.githubusercontent.com/NotEnoughUpdates/capes/master/tunnel.gif', index: 8, purchasable: true }, /* Staff capes */ { name: 'contrib', index: 9 }, { name: 'mbstaff', index: 10 }, diff --git a/src/tasks/removeExpiredPunishements.ts b/src/tasks/removeExpiredPunishements.ts index 69130ee..49267f5 100644 --- a/src/tasks/removeExpiredPunishements.ts +++ b/src/tasks/removeExpiredPunishements.ts @@ -12,13 +12,9 @@ export default class RemoveExpiredPunishmentsTask extends BushTask { public override async exec(): Promise { const expiredEntries = await ActivePunishment.findAll({ where: { - [Op.and]: [ - { - expires: { - [Op.lt]: new Date() // Find all rows with an expiry date before now - } - } - ] + expires: { + [Op.lt]: new Date() // Find all rows with an expiry date before now + } } }); -- cgit