diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-08-25 16:16:44 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-08-25 16:16:44 -0400 |
commit | 4364f1d344e75d23728ce951fc768bc9c8405bed (patch) | |
tree | 47dbdb0482fc16842271c44e3736ba86e0064351 | |
parent | 95dc4c4a4abeed75f419c9ccd5b3f072609c5035 (diff) | |
download | tanzanite-4364f1d344e75d23728ce951fc768bc9c8405bed.tar.gz tanzanite-4364f1d344e75d23728ce951fc768bc9c8405bed.tar.bz2 tanzanite-4364f1d344e75d23728ce951fc768bc9c8405bed.zip |
cleaned up, wolfram alpha command, a few fixes
-rw-r--r-- | package.json | 6 | ||||
-rw-r--r-- | src/commands/config/autoPublishChannel.ts | 2 | ||||
-rw-r--r-- | src/commands/config/joinRoles.ts | 19 | ||||
-rw-r--r-- | src/commands/info/guildInfo.ts | 6 | ||||
-rw-r--r-- | src/commands/info/pronouns.ts | 5 | ||||
-rw-r--r-- | src/commands/info/snowflakeInfo.ts | 4 | ||||
-rw-r--r-- | src/commands/info/userInfo.ts | 6 | ||||
-rw-r--r-- | src/commands/moderation/removeReactionEmoji.ts | 8 | ||||
-rw-r--r-- | src/commands/utilities/calculator.ts | 3 | ||||
-rw-r--r-- | src/commands/utilities/wolframAlpha.ts | 59 | ||||
-rw-r--r-- | src/config/example-options.ts | 3 | ||||
-rw-r--r-- | src/context-menu-commands/user/userInfo.ts | 1 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClientUtil.ts | 3 | ||||
-rw-r--r-- | src/lib/utils/Config.ts | 4 | ||||
-rw-r--r-- | src/listeners/guild/guildCreate.ts | 2 | ||||
-rw-r--r-- | src/listeners/guild/guildDelete.ts | 2 | ||||
-rw-r--r-- | src/listeners/guild/guildMemberAdd.ts | 4 | ||||
-rw-r--r-- | src/listeners/message/supportThreads.ts | 5 | ||||
-rw-r--r-- | yarn.lock | 14 |
19 files changed, 115 insertions, 41 deletions
diff --git a/package.json b/package.json index d471f9a..4b4158f 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,8 @@ "source-map-support": "^0.5.19", "tinycolor2": "^1.4.2", "typescript": "^4.3.5", - "uuid": "^8.3.2" + "uuid": "^8.3.2", + "wolfram-alpha-api": "https://products.wolframalpha.com/api/libraries/javascript/wolfram-alpha-api-1.0.0-rc.1.tgz" }, "eslintConfig": { "env": { @@ -144,6 +145,9 @@ }, "discord.js@13.2.0-dev": { "unplugged": true + }, + "wolfram-alpha-api@1.0.0-rc.1": { + "unplugged": true } } } diff --git a/src/commands/config/autoPublishChannel.ts b/src/commands/config/autoPublishChannel.ts index 10c4ab6..a58f32f 100644 --- a/src/commands/config/autoPublishChannel.ts +++ b/src/commands/config/autoPublishChannel.ts @@ -51,7 +51,7 @@ export default class AutoPublishChannelCommand extends BushCommand { client.logger.debugRaw(autoPublishChannels.includes(channel.id)); return await message.util.reply({ content: `${util.emojis.success} Successfully ${ - autoPublishChannels.includes(channel.id) ? 'disabled' : 'enabled' + autoPublishChannels.includes(channel.id) ? 'enabled' : 'disabled' } auto publishing in <#${channel.id}>.`, allowedMentions: AllowedMentions.none() }); diff --git a/src/commands/config/joinRoles.ts b/src/commands/config/joinRoles.ts index ee2ce75..89a2421 100644 --- a/src/commands/config/joinRoles.ts +++ b/src/commands/config/joinRoles.ts @@ -1,5 +1,5 @@ import { AllowedMentions, BushCommand, BushMessage, BushSlashMessage } from '@lib'; -import { Channel } from 'discord.js'; +import { Role } from 'discord.js'; export default class JoinRolesCommand extends BushCommand { public constructor() { @@ -36,18 +36,15 @@ export default class JoinRolesCommand extends BushCommand { userPermissions: ['SEND_MESSAGES', 'MANAGE_GUILD'] }); } - public override async exec(message: BushMessage | BushSlashMessage, { channel }: { channel: Channel }): Promise<unknown> { - const autoPublishChannels = await message.guild!.getSetting('joinRoles'); - const newValue = util.addOrRemoveFromArray( - autoPublishChannels.includes(channel.id) ? 'remove' : 'add', - autoPublishChannels, - channel.id - ); + + public override async exec(message: BushMessage | BushSlashMessage, { role }: { role: Role }): Promise<unknown> { + const joinRoles = await message.guild!.getSetting('joinRoles'); + const newValue = util.addOrRemoveFromArray(joinRoles.includes(role.id) ? 'remove' : 'add', joinRoles, role.id); await message.guild!.setSetting('joinRoles', newValue); return await message.util.reply({ - content: `${util.emojis.success} Successfully ${ - autoPublishChannels.includes(channel.id) ? 'disabled' : 'enabled' - } auto publishing in <#${channel.id}>.`, + content: `${util.emojis.success} Successfully ${joinRoles.includes(role.id) ? 'removed' : 'added'} <@&${ + role.id + }> from being assigned to members when they join the server.`, allowedMentions: AllowedMentions.none() }); } diff --git a/src/commands/info/guildInfo.ts b/src/commands/info/guildInfo.ts index 431b8bd..0aa5fc0 100644 --- a/src/commands/info/guildInfo.ts +++ b/src/commands/info/guildInfo.ts @@ -14,7 +14,7 @@ export default class GuildInfoCommand extends BushCommand { args: [ { id: 'guild', - customType: util.arg.union('guild', 'bigint'), + customType: util.arg.union('guild', 'snowflake'), prompt: { start: 'What server would you like to find information about?', retry: '{error} Choose a valid server to find information about.', @@ -38,7 +38,7 @@ export default class GuildInfoCommand extends BushCommand { public override async exec( message: BushMessage | BushSlashMessage, - args: { guild: Guild | bigint | GuildPreview } + args: { guild: Guild | Snowflake | GuildPreview } ): Promise<unknown> { if (!args?.guild && !message.guild) { return await message.util.reply( @@ -46,7 +46,7 @@ export default class GuildInfoCommand extends BushCommand { ); } let isPreview = false; - if (['bigint', 'number', 'string'].includes(typeof args?.guild)) { + if (['number', 'string'].includes(typeof args?.guild)) { const preview = await client.fetchGuildPreview(`${args.guild}` as Snowflake).catch(() => {}); if (preview) { args.guild = preview; diff --git a/src/commands/info/pronouns.ts b/src/commands/info/pronouns.ts index 96040c0..ea20d41 100644 --- a/src/commands/info/pronouns.ts +++ b/src/commands/info/pronouns.ts @@ -1,4 +1,5 @@ import { BushCommand, BushMessage, BushSlashMessage } from '@lib'; +import { Snowflake } from 'discord-api-types'; import { MessageEmbed, User } from 'discord.js'; import got, { HTTPError } from 'got'; @@ -40,7 +41,7 @@ export default class PronounsCommand extends BushCommand { args: [ { id: 'user', - customType: util.arg.union('user', 'bigint'), + customType: util.arg.union('user', 'snowflake'), prompt: { start: 'Who would you like to view the pronouns of?', retry: '{error} Choose a valid user to view the pronouns of.', @@ -60,7 +61,7 @@ export default class PronounsCommand extends BushCommand { slash: true }); } - override async exec(message: BushMessage | BushSlashMessage, args: { user?: User | string }): Promise<unknown> { + override async exec(message: BushMessage | BushSlashMessage, args: { user?: User | Snowflake }): Promise<unknown> { const user = args?.user === undefined || args?.user === null ? message.author diff --git a/src/commands/info/snowflakeInfo.ts b/src/commands/info/snowflakeInfo.ts index 02c8d39..603993a 100644 --- a/src/commands/info/snowflakeInfo.ts +++ b/src/commands/info/snowflakeInfo.ts @@ -32,7 +32,7 @@ export default class SnowflakeInfoCommand extends BushCommand { args: [ { id: 'snowflake', - type: 'bigint', + type: 'snowflake', prompt: { start: 'Enter the snowflake you would like to get information about.', retry: '{error} Choose a valid snowflake.', @@ -52,7 +52,7 @@ export default class SnowflakeInfoCommand extends BushCommand { ] }); } - public override async exec(message: BushMessage | BushSlashMessage, args: { snowflake: bigint }): Promise<unknown> { + public override async exec(message: BushMessage | BushSlashMessage, args: { snowflake: Snowflake }): Promise<unknown> { const snowflake = `${args.snowflake}` as Snowflake; const snowflakeEmbed = new MessageEmbed().setTitle('Unknown :snowflake:').setColor(util.colors.default); diff --git a/src/commands/info/userInfo.ts b/src/commands/info/userInfo.ts index 7b8d7d8..ae204f7 100644 --- a/src/commands/info/userInfo.ts +++ b/src/commands/info/userInfo.ts @@ -1,5 +1,5 @@ import { BushCommand, BushMessage, BushSlashMessage, BushUser } from '@lib'; -import { MessageEmbed } from 'discord.js'; +import { MessageEmbed, Snowflake } from 'discord.js'; // TODO: Add bot information export default class UserInfoCommand extends BushCommand { @@ -15,7 +15,7 @@ export default class UserInfoCommand extends BushCommand { args: [ { id: 'user', - customType: util.arg.union('user', 'bigint'), + customType: util.arg.union('user', 'snowflake'), prompt: { start: 'What user would you like to find information about?', retry: '{error} Choose a valid user to find information about.', @@ -38,7 +38,7 @@ export default class UserInfoCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage, args: { user: BushUser | bigint }): Promise<unknown> { + public override async exec(message: BushMessage | BushSlashMessage, args: { user: BushUser | Snowflake }): Promise<unknown> { const user = args?.user === undefined || args?.user === null ? message.author diff --git a/src/commands/moderation/removeReactionEmoji.ts b/src/commands/moderation/removeReactionEmoji.ts index 4dfd074..34073e6 100644 --- a/src/commands/moderation/removeReactionEmoji.ts +++ b/src/commands/moderation/removeReactionEmoji.ts @@ -1,5 +1,5 @@ import { BushCommand, BushMessage } from '@lib'; -import { Emoji } from 'discord.js'; +import { Emoji, Snowflake } from 'discord.js'; export default class RemoveReactionEmojiCommand extends BushCommand { public constructor() { @@ -24,7 +24,7 @@ export default class RemoveReactionEmojiCommand extends BushCommand { }, { id: 'emoji', - customType: util.arg.union('emoji', 'bigint'), + customType: util.arg.union('emoji', 'snowflake'), match: 'restContent', prompt: { start: 'What emoji would you like to remove?', @@ -38,9 +38,9 @@ export default class RemoveReactionEmojiCommand extends BushCommand { public override async exec( message: BushMessage, - { messageToRemoveFrom, emoji }: { messageToRemoveFrom: BushMessage; emoji: Emoji | BigInt } + { messageToRemoveFrom, emoji }: { messageToRemoveFrom: BushMessage; emoji: Emoji | Snowflake } ): Promise<unknown> { - const id = !['bigint', 'string'].includes(typeof emoji); + const id = !['string'].includes(typeof emoji); const emojiID = !id ? `${emoji}` : (emoji as Emoji).id; const success = await messageToRemoveFrom.reactions.cache ?.get(emojiID!) diff --git a/src/commands/utilities/calculator.ts b/src/commands/utilities/calculator.ts index d845aaa..a2c91e4 100644 --- a/src/commands/utilities/calculator.ts +++ b/src/commands/utilities/calculator.ts @@ -10,7 +10,7 @@ export default class CalculatorCommand extends BushCommand { description: { content: 'Calculates math expressions.', usage: 'calculator <expression>', - examples: ['calculator '] + examples: ['calculator 9+10'] }, args: [ { @@ -33,7 +33,6 @@ export default class CalculatorCommand extends BushCommand { required: true } ], - hidden: true, clientPermissions: ['SEND_MESSAGES'], userPermissions: ['SEND_MESSAGES'] }); diff --git a/src/commands/utilities/wolframAlpha.ts b/src/commands/utilities/wolframAlpha.ts new file mode 100644 index 0000000..c18646c --- /dev/null +++ b/src/commands/utilities/wolframAlpha.ts @@ -0,0 +1,59 @@ +import { AllowedMentions, BushCommand, BushMessage, BushSlashMessage } from '@lib'; +import { MessageEmbed } from 'discord.js'; +// @ts-expect-error: no types :( +import WolframAlphaAPI from 'wolfram-alpha-api'; + +export default class WolframAlphaCommand extends BushCommand { + public constructor() { + super('wolframAlpha', { + aliases: ['wolframalpha', 'wolfram', 'alpha', 'wolf', 'wa'], + category: 'utilities', + description: { + content: 'Queries Wolfram|Alpha for a result.', + usage: 'wolframalpha <expression>', + examples: ['wolframalpha what is the population of france'] + }, + args: [ + { + id: 'expression', + type: 'string', + match: 'rest', + prompt: { + start: 'What would you like to look up?', + retry: '{error} Pick something to look up.', + optional: false + } + } + ], + slash: true, + slashOptions: [ + { + name: 'expression', + description: 'What would you like to look up?', + type: 'STRING', + required: true + } + ], + clientPermissions: ['SEND_MESSAGES'], + userPermissions: ['SEND_MESSAGES'] + }); + } + public override async exec(message: BushMessage | BushSlashMessage, args: { expression: string }): Promise<unknown> { + const waApi = WolframAlphaAPI(this.client.config.credentials.wolframAlphaAppId); + + const decodedEmbed = new MessageEmbed().addField('📥 Input', await util.inspectCleanRedactCodeblock(args.expression)); + try { + const calculated = await waApi.getShort(args.expression); + decodedEmbed + .setTitle(`${util.emojis.successFull} Successfully Queried Expression`) + .setColor(util.colors.success) + .addField('📤 Output', await util.inspectCleanRedactCodeblock(calculated.toString())); + } catch (error) { + decodedEmbed + .setTitle(`${util.emojis.errorFull} Unable to Query Expression`) + .setColor(util.colors.error) + .addField(`📤 Error`, await util.inspectCleanRedactCodeblock(`${error.name}: ${error.message}`, 'js')); + } + return await message.util.reply({ embeds: [decodedEmbed], allowedMentions: AllowedMentions.none() }); + } +} diff --git a/src/config/example-options.ts b/src/config/example-options.ts index b9a9d28..c7838ab 100644 --- a/src/config/example-options.ts +++ b/src/config/example-options.ts @@ -5,7 +5,8 @@ export default new Config({ token: '[TOKEN]', betaToken: '[TOKEN]', devToken: '[TOKEN]', - hypixelApiKey: '[API_KEY]' + hypixelApiKey: '[API_KEY]', + wolframAlphaAppId: '[APP_ID]' }, environment: 'development', owners: [ diff --git a/src/context-menu-commands/user/userInfo.ts b/src/context-menu-commands/user/userInfo.ts new file mode 100644 index 0000000..2ab265a --- /dev/null +++ b/src/context-menu-commands/user/userInfo.ts @@ -0,0 +1 @@ +// todo: make context interaction for user command diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index 17f7d32..29be84c 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -883,7 +883,8 @@ export class BushClientUtil extends ClientUtil { ['token']: 'Main Token', ['devToken']: 'Dev Token', ['betaToken']: 'Beta Token', - ['hypixelApiKey']: 'Hypixel Api Key' + ['hypixelApiKey']: 'Hypixel Api Key', + ['wolframAlphaAppId']: 'Wolfram|Alpha App ID' }; return mapping[old as keyof typeof mapping] || old; } diff --git a/src/lib/utils/Config.ts b/src/lib/utils/Config.ts index 663fe95..ed73d40 100644 --- a/src/lib/utils/Config.ts +++ b/src/lib/utils/Config.ts @@ -1,7 +1,7 @@ import { Snowflake } from 'discord.js'; export interface ConfigOptions { - credentials: { token: string; betaToken: string; devToken: string; hypixelApiKey: string }; + credentials: { token: string; betaToken: string; devToken: string; hypixelApiKey: string; wolframAlphaAppId: string }; environment: 'production' | 'beta' | 'development'; owners: Snowflake[]; prefix: string; @@ -12,7 +12,7 @@ export interface ConfigOptions { } export class Config { - public credentials: { token: string; betaToken: string; devToken: string; hypixelApiKey: string }; + public credentials: { token: string; betaToken: string; devToken: string; hypixelApiKey: string; wolframAlphaAppId: string }; public environment: 'production' | 'beta' | 'development'; public owners: Snowflake[]; public prefix: string; diff --git a/src/listeners/guild/guildCreate.ts b/src/listeners/guild/guildCreate.ts index 21a7ab0..bc5694a 100644 --- a/src/listeners/guild/guildCreate.ts +++ b/src/listeners/guild/guildCreate.ts @@ -6,7 +6,7 @@ export default class GuildCreateListener extends BushListener { super('guildCreate', { emitter: 'client', event: 'guildCreate', // when the bot joins a guild - category: 'client' + category: 'guild' }); } diff --git a/src/listeners/guild/guildDelete.ts b/src/listeners/guild/guildDelete.ts index a59f45e..3126bd6 100644 --- a/src/listeners/guild/guildDelete.ts +++ b/src/listeners/guild/guildDelete.ts @@ -6,7 +6,7 @@ export default class GuildDeleteListener extends BushListener { super('guildDelete', { emitter: 'client', event: 'guildDelete', //when the bot leaves a guild - category: 'client' + category: 'guild' }); } diff --git a/src/listeners/guild/guildMemberAdd.ts b/src/listeners/guild/guildMemberAdd.ts index bf6e0b6..7bef6b8 100644 --- a/src/listeners/guild/guildMemberAdd.ts +++ b/src/listeners/guild/guildMemberAdd.ts @@ -7,7 +7,7 @@ export default class GuildMemberAddListener extends BushListener { super('guildMemberAdd', { emitter: 'client', event: 'guildMemberAdd', - category: 'client' + category: 'guild' }); } @@ -85,7 +85,7 @@ export default class GuildMemberAddListener extends BushListener { } } else { const joinRoles = await member.guild.getSetting('joinRoles'); - if (!joinRoles) return; + if (!joinRoles || !joinRoles.length) return; await member.roles .add(joinRoles, 'Join roles.') .then(() => diff --git a/src/listeners/message/supportThreads.ts b/src/listeners/message/supportThreads.ts index ce2aa0d..9b3ea3e 100644 --- a/src/listeners/message/supportThreads.ts +++ b/src/listeners/message/supportThreads.ts @@ -3,7 +3,7 @@ import { MessageEmbed } from 'discord.js'; import { BushListener, BushTextChannel } from '../../lib'; import { BushClientEvents } from '../../lib/extensions/discord.js/BushClientEvents'; -export default class MessageVerboseListener extends BushListener { +export default class SupportThreadListener extends BushListener { public constructor() { super('supportThreads', { emitter: 'client', @@ -13,6 +13,7 @@ export default class MessageVerboseListener extends BushListener { } public override async exec(...[message]: BushClientEvents['messageCreate']): Promise<Promise<void> | undefined> { + if (client.config.isDevelopment) return; if (!message.guild || !message.channel) return; // todo: make these configurable etc... if (message.guild.id !== '516977525906341928') return; // mb @@ -20,7 +21,7 @@ export default class MessageVerboseListener extends BushListener { if (!(message.channel as BushTextChannel).permissionsFor(message.guild.me!).has('USE_PUBLIC_THREADS')) return; const thread = await message.startThread({ name: `Support - ${message.author.username}#${message.author.discriminator}`, - autoArchiveDuration: 1440, + autoArchiveDuration: 60, reason: 'Support Thread' }); const embed = new MessageEmbed() @@ -770,11 +770,14 @@ __metadata: tinycolor2: ^1.4.2 typescript: ^4.3.5 uuid: ^8.3.2 + wolfram-alpha-api: "https://products.wolframalpha.com/api/libraries/javascript/wolfram-alpha-api-1.0.0-rc.1.tgz" dependenciesMeta: discord-akairo@8.2.2: unplugged: true discord.js@13.2.0-dev: unplugged: true + wolfram-alpha-api@1.0.0-rc.1: + unplugged: true languageName: unknown linkType: soft @@ -1081,12 +1084,12 @@ discord-akairo-message-util@NotEnoughUpdates/discord-akairo-message-util: discord-akairo@NotEnoughUpdates/discord-akairo: version: 8.2.2 - resolution: "discord-akairo@https://github.com/NotEnoughUpdates/discord-akairo.git#commit=26e248e3e427d9f68500b151294c6bbb59efc48d" + resolution: "discord-akairo@https://github.com/NotEnoughUpdates/discord-akairo.git#commit=ed56a656199c15af8b857a45dba5516c9d6ca713" dependencies: discord-akairo-message-util: NotEnoughUpdates/discord-akairo-message-util lodash: ^4.17.21 source-map-support: ^0.5.19 - checksum: c2435ae6c0bcbd0fec0756ff9b34cd164a713e2fae8d2dd1cc80d6761ef3049d390b4bda1ecef1fb862d979474559422289b5728d6822509e8f6f42c18f9b4ad + checksum: b19ac29568e7bd3ecc3daaca50a7558689fb36bf6bed51b7e736d5e168fb807c2b731c84e31c6f9c8c39a9c096a1db712a72602eb724e46cf478dc5774967f6a languageName: node linkType: hard @@ -3312,6 +3315,13 @@ typescript@^4.3.5: languageName: node linkType: hard +"wolfram-alpha-api@https://products.wolframalpha.com/api/libraries/javascript/wolfram-alpha-api-1.0.0-rc.1.tgz": + version: 1.0.0-rc.1 + resolution: "wolfram-alpha-api@https://products.wolframalpha.com/api/libraries/javascript/wolfram-alpha-api-1.0.0-rc.1.tgz" + checksum: ca1e49c5a5e977ac1e5e9759972daeac6f50755d2abb785f631bf76845f1cfce25198d092066b63990a540e1c0ba8bfdee64032f782f9c71a76dc0c134317e8d + languageName: node + linkType: hard + "word-wrap@npm:^1.2.3": version: 1.2.3 resolution: "word-wrap@npm:1.2.3" |