diff options
| author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-06-24 00:56:16 -0400 |
|---|---|---|
| committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-06-24 00:56:16 -0400 |
| commit | 4176b6258e44e4a095376aaf0f4c687244243a69 (patch) | |
| tree | 3b9144be9a2045483c90d92fff05b3ca0b288e52 | |
| parent | e80446e23060c0325bbd6db620920d86694ec3ce (diff) | |
| download | tanzanite-4176b6258e44e4a095376aaf0f4c687244243a69.tar.gz tanzanite-4176b6258e44e4a095376aaf0f4c687244243a69.tar.bz2 tanzanite-4176b6258e44e4a095376aaf0f4c687244243a69.zip | |
feat(*): Began working on other punishment commands etc
68 files changed, 1408 insertions, 536 deletions
@@ -47,7 +47,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { ["body-parser", "npm:1.19.0"], ["chalk", "npm:4.1.1"], ["common-tags", "npm:1.8.0"], - ["discord-akairo", "https://github.com/NotEnoughUpdates/discord-akairo.git#commit=5669013a0bae41f6b49a12feef0ab1cfe4e2f31c"], + ["discord-akairo", "https://github.com/NotEnoughUpdates/discord-akairo.git#commit=7e34ecf33356a51f575a9dab036aa25d02a1e4ec"], ["discord-api-types", "npm:0.18.1"], ["discord.js", "npm:13.0.0-dev.c850ae10270076c4b2e10b130dd8f88eed4ed201"], ["esbuild", "npm:0.12.1"], @@ -786,7 +786,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { ["body-parser", "npm:1.19.0"], ["chalk", "npm:4.1.1"], ["common-tags", "npm:1.8.0"], - ["discord-akairo", "https://github.com/NotEnoughUpdates/discord-akairo.git#commit=5669013a0bae41f6b49a12feef0ab1cfe4e2f31c"], + ["discord-akairo", "https://github.com/NotEnoughUpdates/discord-akairo.git#commit=7e34ecf33356a51f575a9dab036aa25d02a1e4ec"], ["discord-api-types", "npm:0.18.1"], ["discord.js", "npm:13.0.0-dev.c850ae10270076c4b2e10b130dd8f88eed4ed201"], ["esbuild", "npm:0.12.1"], @@ -1060,10 +1060,10 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { }] ]], ["discord-akairo", [ - ["https://github.com/NotEnoughUpdates/discord-akairo.git#commit=5669013a0bae41f6b49a12feef0ab1cfe4e2f31c", { - "packageLocation": "./.yarn/cache/discord-akairo-https-2bb7a0235e-4b14e896bc.zip/node_modules/discord-akairo/", + ["https://github.com/NotEnoughUpdates/discord-akairo.git#commit=7e34ecf33356a51f575a9dab036aa25d02a1e4ec", { + "packageLocation": "./.yarn/cache/discord-akairo-https-b859ac6ed7-039c205d19.zip/node_modules/discord-akairo/", "packageDependencies": [ - ["discord-akairo", "https://github.com/NotEnoughUpdates/discord-akairo.git#commit=5669013a0bae41f6b49a12feef0ab1cfe4e2f31c"] + ["discord-akairo", "https://github.com/NotEnoughUpdates/discord-akairo.git#commit=7e34ecf33356a51f575a9dab036aa25d02a1e4ec"] ], "linkType": "HARD", }] diff --git a/.vscode/settings.json b/.vscode/settings.json index b91434b..31f0057 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,7 +6,8 @@ "**/CVS": true, "**/.DS_Store": true, "node_modules": true, - "dist": true + // "dist": true, + ".pnp.js": true }, "javascript.preferences.importModuleSpecifier": "project-relative", "typescript.preferences.importModuleSpecifier": "project-relative", @@ -31,5 +32,63 @@ "prettier.useEditorConfig": false, "eslint.nodePath": ".yarn/sdks", "typescript.tsdk": ".yarn/sdks/typescript/lib", - "typescript.enablePromptUseWorkspaceTsdk": true + "typescript.enablePromptUseWorkspaceTsdk": true, + "better-comments.highlightPlainText": false, + "better-comments.multilineComments": true, + "better-comments.tags": [ + { + "tag": "!", + "color": "#FF2D00", + "strikethrough": false, + "underline": false, + "backgroundColor": "transparent", + "bold": false, + "italic": false + }, + { + "tag": "?", + "color": "#3498DB", + "strikethrough": false, + "underline": false, + "backgroundColor": "transparent", + "bold": false, + "italic": false + }, + { + "tag": "#", + "color": "#f003fc", + "strikethrough": false, + "underline": false, + "backgroundColor": "transparent", + "bold": false, + "italic": false + }, + { + "tag": "//", + "color": "#474747", + "strikethrough": true, + "underline": false, + "backgroundColor": "transparent", + "bold": false, + "italic": false + }, + { + "tag": "todo", + "color": "#FF8C00", + "strikethrough": false, + "underline": false, + "backgroundColor": "transparent", + "bold": false, + "italic": false + }, + { + "tag": "*", + "color": "#98C379", + "strikethrough": false, + "underline": false, + "backgroundColor": "transparent", + "bold": false, + "italic": false + } + ] } diff --git a/src/arguments/duration.ts b/src/arguments/duration.ts new file mode 100644 index 0000000..a2f7751 --- /dev/null +++ b/src/arguments/duration.ts @@ -0,0 +1,55 @@ +import { BushArgumentTypeCaster } from '../lib/extensions/BushArgumentTypeCaster'; +import { BushMessage } from '../lib/extensions/BushMessage'; + +// Stolen from @Mzato0001 (pr to discord akairo that hasn't been merged yet) +const TimeUnits = { + years: { + label: '(?:years?|y)', + value: 1000 * 60 * 60 * 24 * 365 + }, + months: { + label: '(?:months?|mo)', + value: 1000 * 60 * 60 * 24 * 30 + }, + weeks: { + label: '(?:weeks?|w)', + value: 1000 * 60 * 60 * 24 * 7 + }, + days: { + label: '(?:days?|d)', + value: 1000 * 60 * 60 * 24 + }, + hours: { + label: '(?:hours?|hrs?|h)', + value: 1000 * 60 * 60 + }, + minutes: { + label: '(?:minutes?|mins?|m)', + value: 1000 * 60 + }, + seconds: { + label: '(?:seconds?|secs?|s)', + value: 1000 + }, + milliseconds: { + label: '(?:milliseconds?|msecs?|ms)', + value: 1 + } +}; +export const durationTypeCaster: BushArgumentTypeCaster = async (_message: BushMessage, phrase): Promise<number> => { + if (!phrase) return null; + + const regexString = Object.entries(TimeUnits) + .map(([name, { label }]) => String.raw`(?:(?<${name}>-?(?:\d+)?\.?\d+) *${label})?`) + .join('\\s*'); + const match = new RegExp(`^${regexString}$`, 'i').exec(phrase); + if (!match) return null; + + let milliseconds = 0; + for (const key in match.groups) { + const value = Number(match.groups[key] || 0); + milliseconds += value * TimeUnits[key].value; + } + + return milliseconds; +}; diff --git a/src/commands/config/muteRole.ts b/src/commands/config/muteRole.ts new file mode 100644 index 0000000..f51c5ce --- /dev/null +++ b/src/commands/config/muteRole.ts @@ -0,0 +1,57 @@ +import { Role } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; +import { BushMessage } from '../../lib/extensions/BushMessage'; +import { Guild } from '../../lib/models'; +import AllowedMentions from '../../lib/utils/AllowedMentions'; + +export default class MuteRoleCommand extends BushCommand { + constructor() { + super('muteRole', { + aliases: ['muterole'], + category: 'config', + description: { + content: 'Set the prefix of the current server (resets to default if prefix is not given)', + usage: 'prefix [prefix]', + examples: ['prefix', 'prefix +'] + }, + clientPermissions: ['SEND_MESSAGES'], + userPermissions: ['SEND_MESSAGES', 'MANAGE_GUILD'], + args: [ + { + id: 'role', + type: 'role', + prompt: { + start: "What would you like to set the server's mute role to?", + retry: '{error} Choose a valid role.', + optional: false + } + } + ], + slash: true, + slashOptions: [ + { + type: 'ROLE', + name: 'role', + description: 'The mute role for this server.', + required: true + } + ] + }); + } + + async exec(message: BushMessage | BushSlashMessage, args: { role: Role }): Promise<void> { + let row = await Guild.findByPk(message.guild.id); + if (!row) { + row = Guild.build({ + id: message.guild.id + }); + } + row.muteRole = args.role.id; + await row.save(); + await message.util.send({ + content: `${this.client.util.emojis.success} Changed the mute role to <@&${args.role.id}>.`, + allowedMentions: AllowedMentions.none() + }); + } +} diff --git a/src/commands/config/prefix.ts b/src/commands/config/prefix.ts index 1326426..5b73a1a 100644 --- a/src/commands/config/prefix.ts +++ b/src/commands/config/prefix.ts @@ -1,6 +1,6 @@ -import { Message } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; +import { BushMessage } from '../../lib/extensions/BushMessage'; import { Guild } from '../../lib/models'; export default class PrefixCommand extends BushCommand { @@ -11,10 +11,16 @@ export default class PrefixCommand extends BushCommand { args: [ { id: 'prefix', - type: 'string' + type: 'string', + prompt: { + start: 'What would you like the new prefix to be?', + retry: '{error} Choose a valid prefix', + optional: true + } } ], - userPermissions: ['MANAGE_GUILD'], + clientPermissions: ['SEND_MESSAGES'], + userPermissions: ['SEND_MESSAGES', 'MANAGE_GUILD'], description: { content: 'Set the prefix of the current server (resets to default if prefix is not given)', usage: 'prefix [prefix]', @@ -32,7 +38,7 @@ export default class PrefixCommand extends BushCommand { }); } - async exec(message: Message | BushSlashMessage, { prefix }: { prefix?: string }): Promise<void> { + async exec(message: BushMessage | BushSlashMessage, { prefix }: { prefix?: string }): Promise<void> { let row = await Guild.findByPk(message.guild.id); if (!row) { row = Guild.build({ @@ -41,7 +47,7 @@ export default class PrefixCommand extends BushCommand { } await row.update({ prefix: prefix || this.client.config.prefix }); if (prefix) { - await message.util.send(`${this.client.util.emojis.success} changed prefix from \`${prefix}\``); + await message.util.send(`${this.client.util.emojis.success} changed prefix from \`${prefix}\` to `); } else { await message.util.send(`${this.client.util.emojis.success} reset prefix to \`${this.client.config.prefix}\``); } diff --git a/src/commands/config/welcomeChannel.ts b/src/commands/config/welcomeChannel.ts new file mode 100644 index 0000000..72e55f1 --- /dev/null +++ b/src/commands/config/welcomeChannel.ts @@ -0,0 +1,49 @@ +import { User } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushMessage } from '../../lib/extensions/BushMessage'; +import { Global } from '../../lib/models'; + +export default class WelcomeChannelCommand extends BushCommand { + public constructor() { + super('welcomeChannel', { + aliases: ['welcomechannel', 'wc'], + category: 'config', + description: { + content: 'Configure the what channel you want the bot to send a message in when someone joins the server.', + usage: 'welcomechannel [channel]', + examples: ['welcomechannel #welcome'] + }, + clientPermissions: ['SEND_MESSAGES'], + ownerOnly: true + }); + } + public async exec(message: BushMessage, args: { action: 'add' | 'remove'; user: User }): Promise<unknown> { + if (!this.client.config.owners.includes(message.author.id)) + return await message.util.reply(`${this.client.util.emojis.error} Only my developers can run this command...`); + + const superUsers = (await Global.findByPk(this.client.config.dev ? 'development' : 'production')).superUsers; + let success; + if (args.action === 'add') { + if (superUsers.includes(args.user.id)) { + return message.util.reply(`${this.client.util.emojis.warn} \`${args.user.tag}\` is already a superuser.`); + } + success = await this.client.util.insertOrRemoveFromGlobal('add', 'superUsers', args.user.id).catch(() => false); + } else { + if (!superUsers.includes(args.user.id)) { + return message.util.reply(`${this.client.util.emojis.warn} \`${args.user.tag}\` is not superuser.`); + } + success = await this.client.util.insertOrRemoveFromGlobal('remove', 'superUsers', args.user.id).catch(() => false); + } + if (success) { + const responses = [args.action == 'remove' ? `` : 'made', args.action == 'remove' ? 'is no longer' : '']; + return message.util.reply( + `${this.client.util.emojis.success} ${responses[0]} \`${args.user.tag}\` ${responses[1]} a superuser.` + ); + } else { + const response = [args.action == 'remove' ? `removing` : 'making', args.action == 'remove' ? `from` : 'to']; + return message.util.reply( + `${this.client.util.emojis.error} There was an error ${response[0]} \`${args.user.tag}\` ${response[1]} the superuser list.` + ); + } + } +} diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts index d2fe432..310a2c5 100644 --- a/src/commands/dev/eval.ts +++ b/src/commands/dev/eval.ts @@ -10,7 +10,7 @@ import { BushMessage } from '../../lib/extensions/BushMessage'; const clean = (text) => { if (typeof text === 'string') { - return (text = Util.cleanCodeBlockContent(text)); + return Util.cleanCodeBlockContent(text); } else return text; }; const sh = promisify(exec); @@ -186,7 +186,7 @@ export default class EvalCommand extends BushCommand { { Global } = await import('../../lib/models/Global'), { Guild } = await import('../../lib/models/Guild'), { Level } = await import('../../lib/models/Level'), - { Modlog } = await import('../../lib/models/Modlog'), + { ModLog } = await import('../../lib/models/ModLog'), { StickyRole } = await import('../../lib/models/StickyRole'); if (code[code.lang].replace(/ /g, '').includes('9+10' || '10+9')) { output = 21; diff --git a/src/commands/dev/reload.ts b/src/commands/dev/reload.ts index 94e31b0..f5fee88 100644 --- a/src/commands/dev/reload.ts +++ b/src/commands/dev/reload.ts @@ -1,6 +1,5 @@ import { stripIndent } from 'common-tags'; import { Message } from 'discord.js'; -import { SlashCommandOption } from '../../lib/extensions/BushClientUtil'; import { BushCommand } from '../../lib/extensions/BushCommand'; import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; @@ -51,11 +50,7 @@ export default class ReloadCommand extends BushCommand { } } - public async exec(message: Message, { fast }: { fast: boolean }): Promise<void> { + public async exec(message: Message | BushSlashMessage, { fast }: { fast: boolean }): Promise<void> { await message.util.send(await this.getResponse(fast)); } - - public async execSlash(message: BushSlashMessage, { fast }: { fast: SlashCommandOption<boolean> }): Promise<void> { - await message.interaction.reply(await this.getResponse(fast?.value)); - } } diff --git a/src/commands/dev/setLevel.ts b/src/commands/dev/setLevel.ts index ca555db..f536109 100644 --- a/src/commands/dev/setLevel.ts +++ b/src/commands/dev/setLevel.ts @@ -1,7 +1,5 @@ import { Message, User } from 'discord.js'; -import { SlashCommandOption } from '../../lib/extensions/BushClientUtil'; import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; import { Level } from '../../lib/models'; import AllowedMentions from '../../lib/utils/AllowedMentions'; @@ -71,14 +69,4 @@ export default class SetLevelCommand extends BushCommand { allowedMentions: AllowedMentions.none() }); } - - async execSlash( - message: BushSlashMessage, - { user, level }: { user: SlashCommandOption<void>; level: SlashCommandOption<number> } - ): Promise<void> { - await message.interaction.reply({ - content: await this.setLevel(user.user, level.value), - allowedMentions: AllowedMentions.none() - }); - } } diff --git a/src/commands/dev/superUser.ts b/src/commands/dev/superUser.ts index c3ed0b0..4562e6f 100644 --- a/src/commands/dev/superUser.ts +++ b/src/commands/dev/superUser.ts @@ -2,7 +2,7 @@ import { Constants } from 'discord-akairo'; import { User } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; import { BushMessage } from '../../lib/extensions/BushMessage'; -import { Global } from '../../lib/models/Global'; +import { Global } from '../../lib/models'; export default class SuperUserCommand extends BushCommand { public constructor() { diff --git a/src/commands/info/botInfo.ts b/src/commands/info/botInfo.ts index 120527d..3db4151 100644 --- a/src/commands/info/botInfo.ts +++ b/src/commands/info/botInfo.ts @@ -1,7 +1,6 @@ import { Message, MessageEmbed } from 'discord.js'; import { duration } from 'moment'; import { BushCommand } from '../../lib/extensions/BushCommand'; -import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; export default class BotInfoCommand extends BushCommand { constructor() { @@ -13,11 +12,13 @@ export default class BotInfoCommand extends BushCommand { usage: 'botinfo', examples: ['botinfo'] }, - slash: true + slash: true, + clientPermissions: ['SEND_MESSAGES', 'EMBED_LINKS'], + userPermissions: ['SEND_MESSAGES'] }); } - private async generateEmbed(): Promise<MessageEmbed> { + public async exec(message: Message): Promise<void> { const owners = (await this.client.util.mapIDs(this.client.ownerID)).map((u) => u.tag).join('\n'); const currentCommit = (await this.client.util.shell('git rev-parse HEAD')).stdout.replace('\n', ''); const repoUrl = (await this.client.util.shell('git remote get-url origin')).stdout.replace('\n', ''); @@ -44,14 +45,6 @@ export default class BotInfoCommand extends BushCommand { } ]) .setTimestamp(); - return embed; - } - - public async exec(message: Message): Promise<void> { - await message.util.send({ embeds: [await this.generateEmbed()] }); - } - - public async execSlash(message: BushSlashMessage): Promise<void> { - await message.interaction.reply({ embeds: [await this.generateEmbed()] }); + await message.util.reply({ embeds: [embed] }); } } |
