aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/arguments/abbreviatedNumber.ts2
-rw-r--r--src/arguments/contentWithDuration.ts2
-rw-r--r--src/arguments/discordEmoji.ts2
-rw-r--r--src/arguments/duration.ts2
-rw-r--r--src/arguments/durationSeconds.ts2
-rw-r--r--src/arguments/globalUser.ts2
-rw-r--r--src/arguments/permission.ts2
-rw-r--r--src/arguments/roleWithDuration.ts2
-rw-r--r--src/arguments/snowflake.ts2
-rw-r--r--src/commands/config/config.ts1
-rw-r--r--src/commands/config/features.ts27
-rw-r--r--src/commands/utilities/uuid.ts2
-rw-r--r--src/commands/utilities/wolframAlpha.ts2
-rw-r--r--src/lib/common/typings/BushInspectOptions.d.ts10
-rw-r--r--src/lib/extensions/discord-akairo/BushClient.ts92
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts3
-rw-r--r--src/lib/extensions/discord.js/BushGuild.ts2
-rw-r--r--src/lib/utils/BushCache.ts18
18 files changed, 80 insertions, 95 deletions
diff --git a/src/arguments/abbreviatedNumber.ts b/src/arguments/abbreviatedNumber.ts
index 4dae2ff..3a447d7 100644
--- a/src/arguments/abbreviatedNumber.ts
+++ b/src/arguments/abbreviatedNumber.ts
@@ -1,7 +1,7 @@
import { type BushArgumentTypeCaster } from '#lib';
import numeral from 'numeral';
-export const abbreviatedNumberTypeCaster: BushArgumentTypeCaster = (_, phrase): number | null => {
+export const abbreviatedNumber: BushArgumentTypeCaster = (_, phrase): number | null => {
if (!phrase) return null;
const num = numeral(phrase?.toLowerCase()).value();
diff --git a/src/arguments/contentWithDuration.ts b/src/arguments/contentWithDuration.ts
index 9bebaef..a9a7c23 100644
--- a/src/arguments/contentWithDuration.ts
+++ b/src/arguments/contentWithDuration.ts
@@ -1,6 +1,6 @@
import { type BushArgumentTypeCaster } from '#lib';
-export const contentWithDurationTypeCaster: BushArgumentTypeCaster = async (
+export const contentWithDuration: BushArgumentTypeCaster = async (
_,
phrase
): Promise<{ duration: number | null; contentWithoutTime: string | null }> => {
diff --git a/src/arguments/discordEmoji.ts b/src/arguments/discordEmoji.ts
index 6fb971a..8648f7f 100644
--- a/src/arguments/discordEmoji.ts
+++ b/src/arguments/discordEmoji.ts
@@ -1,7 +1,7 @@
import { type BushArgumentTypeCaster } from '#lib';
import { type Snowflake } from 'discord-api-types';
-export const discordEmojiTypeCaster: BushArgumentTypeCaster = (_, phrase): { name: string; id: Snowflake } | null => {
+export const discordEmoji: BushArgumentTypeCaster = (_, phrase): { name: string; id: Snowflake } | null => {
if (!phrase) return null;
const validEmoji: RegExpExecArray | null = client.consts.regex.discordEmoji.exec(phrase);
if (!validEmoji || !validEmoji.groups) return null;
diff --git a/src/arguments/duration.ts b/src/arguments/duration.ts
index e369ddd..9cb1d03 100644
--- a/src/arguments/duration.ts
+++ b/src/arguments/duration.ts
@@ -1,5 +1,5 @@
import { type BushArgumentTypeCaster } from '#lib';
-export const durationTypeCaster: BushArgumentTypeCaster = (_, phrase): number | null => {
+export const duration: BushArgumentTypeCaster = (_, phrase): number | null => {
return client.util.parseDuration(phrase).duration;
};
diff --git a/src/arguments/durationSeconds.ts b/src/arguments/durationSeconds.ts
index 78be1ce..8cbfa21 100644
--- a/src/arguments/durationSeconds.ts
+++ b/src/arguments/durationSeconds.ts
@@ -1,6 +1,6 @@
import { type BushArgumentTypeCaster } from '#lib';
-export const durationSecondsTypeCaster: BushArgumentTypeCaster = (_, phrase): number | null => {
+export const durationSeconds: BushArgumentTypeCaster = (_, phrase): number | null => {
phrase += 's';
return client.util.parseDuration(phrase).duration;
};
diff --git a/src/arguments/globalUser.ts b/src/arguments/globalUser.ts
index 344fe78..081eabf 100644
--- a/src/arguments/globalUser.ts
+++ b/src/arguments/globalUser.ts
@@ -1,7 +1,7 @@
import { BushUser, type BushArgumentTypeCaster } from '#lib';
// resolve non-cached users
-export const globalUserTypeCaster: BushArgumentTypeCaster = async (_, phrase): Promise<BushUser | null> => {
+export const globalUser: BushArgumentTypeCaster = async (_, phrase): Promise<BushUser | null> => {
return client.users.cache.has(phrase)
? client.users.cache.get(`${phrase}`) ?? null
: await client.users.fetch(`${phrase}`).catch(() => null);
diff --git a/src/arguments/permission.ts b/src/arguments/permission.ts
index 4f335dc..36c8fcb 100644
--- a/src/arguments/permission.ts
+++ b/src/arguments/permission.ts
@@ -1,7 +1,7 @@
import { type BushArgumentTypeCaster } from '#lib';
import { Permissions } from 'discord.js';
-export const permissionTypeCaster: BushArgumentTypeCaster = (_, phrase) => {
+export const permission: BushArgumentTypeCaster = (_, phrase) => {
if (!phrase) return null;
phrase = phrase.toUpperCase().replace(/ /g, '_');
if (!Reflect.has(Permissions.FLAGS, phrase)) {
diff --git a/src/arguments/roleWithDuration.ts b/src/arguments/roleWithDuration.ts
index 455ad76..9bf4bb2 100644
--- a/src/arguments/roleWithDuration.ts
+++ b/src/arguments/roleWithDuration.ts
@@ -1,6 +1,6 @@
import { type BushArgumentTypeCaster } from '#lib';
-export const roleWithDurationTypeCaster: BushArgumentTypeCaster = async (
+export const roleWithDuration: BushArgumentTypeCaster = async (
message,
phrase
): Promise<{ duration: number | null; role: string | null } | null> => {
diff --git a/src/arguments/snowflake.ts b/src/arguments/snowflake.ts
index 03d78c2..455ed63 100644
--- a/src/arguments/snowflake.ts
+++ b/src/arguments/snowflake.ts
@@ -1,7 +1,7 @@
import { type BushArgumentTypeCaster } from '#lib';
import { type Snowflake } from 'discord.js';
-export const snowflakeTypeCaster: BushArgumentTypeCaster = (_, phrase): Snowflake | null => {
+export const snowflake: BushArgumentTypeCaster = (_, phrase): Snowflake | null => {
if (!phrase) return null;
if (client.consts.regex.snowflake.test(phrase)) return phrase;
return null;
diff --git a/src/commands/config/config.ts b/src/commands/config/config.ts
index 7811663..00c6a69 100644
--- a/src/commands/config/config.ts
+++ b/src/commands/config/config.ts
@@ -101,7 +101,6 @@ export default class SettingsCommand extends BushCommand {
});
}
- // I make very readable code :)
override *args(message: BushMessage): Generator<ArgumentOptions | Flag> {
const optional = message.util.parsed!.alias === 'settings';
const setting = yield {
diff --git a/src/commands/config/features.ts b/src/commands/config/features.ts
index 7f9ffc9..8c9351d 100644
--- a/src/commands/config/features.ts
+++ b/src/commands/config/features.ts
@@ -74,21 +74,20 @@ export default class FeaturesCommand extends BushCommand {
);
}
- public generateComponents(guildFeatures: GuildFeatures[], disable: boolean): MessageActionRow {
+ public generateComponents(guildFeatures: GuildFeatures[], disable: boolean) {
return new MessageActionRow().addComponents(
- new MessageSelectMenu()
- .addOptions(
- ...guildFeatures.map((f) => ({
- label: guildFeaturesObj[f].name,
- value: f,
- description: guildFeaturesObj[f].description
- }))
- )
- .setPlaceholder('Select A Feature to Toggle')
- .setMaxValues(1)
- .setMinValues(1)
- .setCustomId('command_selectFeature')
- .setDisabled(disable)
+ new MessageSelectMenu({
+ customId: 'command_selectFeature',
+ disabled: disable,
+ maxValues: 1,
+ minValues: 2,
+ options: guildFeatures.map((f) => ({
+ label: guildFeaturesObj[f].name,
+ value: f,
+ description: guildFeaturesObj[f].description
+ })),
+ placeholder: 'Select A Feature to Toggle'
+ })
);
}
}
diff --git a/src/commands/utilities/uuid.ts b/src/commands/utilities/uuid.ts
index 556a4de..1be6079 100644
--- a/src/commands/utilities/uuid.ts
+++ b/src/commands/utilities/uuid.ts
@@ -2,7 +2,7 @@ import { BushCommand, type BushMessage } from '#lib';
export default class UuidCommand extends BushCommand {
public constructor() {
- super('uuid', {
+ super('uuid', {
aliases: ['uuid'],
category: 'utilities',
description: {
diff --git a/src/commands/utilities/wolframAlpha.ts b/src/commands/utilities/wolframAlpha.ts
index aba0f57..13512bb 100644
--- a/src/commands/utilities/wolframAlpha.ts
+++ b/src/commands/utilities/wolframAlpha.ts
@@ -1,6 +1,6 @@
import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage } from '#lib';
import { MessageEmbed, type MessageOptions } from 'discord.js';
-const {default: WolframAlphaAPI} = (await import("wolfram-alpha-api")).default as unknown as typeof import( "wolfram-alpha-api")
+const { default: WolframAlphaAPI } = (await import("@notenoughupdates/wolfram-alpha-api")).default as unknown as typeof import("@notenoughupdates/wolfram-alpha-api")
export default class WolframAlphaCommand extends BushCommand {
public constructor() {
diff --git a/src/lib/common/typings/BushInspectOptions.d.ts b/src/lib/common/typings/BushInspectOptions.d.ts
index 11c2dc1..e51e758 100644
--- a/src/lib/common/typings/BushInspectOptions.d.ts
+++ b/src/lib/common/typings/BushInspectOptions.d.ts
@@ -12,6 +12,7 @@ export interface BushInspectOptions extends InspectOptions {
* **Default**: `false`.
*/
showHidden?: boolean | undefined;
+
/**
* Specifies the number of times to recurse while formatting `object`. This is useful
* for inspecting large objects. To recurse up to the maximum call stack size pass
@@ -20,24 +21,28 @@ export interface BushInspectOptions extends InspectOptions {
* **Default**: `2`.
*/
depth?: number | null | undefined;
+
/**
* If `true`, the output is styled with ANSI color codes. Colors are customizable. See [Customizing util.inspect colors](https://nodejs.org/api/util.html#util_customizing_util_inspect_colors).
*
* **Default**: `false`.
*/
colors?: boolean | undefined;
+
/**
* If `false`, `[util.inspect.custom](depth, opts)` functions are not invoked.
*
* **Default**: `true`.
*/
customInspect?: boolean | undefined;
+
/**
* If `true`, `Proxy` inspection includes the [`target` and `handler`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#Terminology) objects.
*
* **Default**: `false`.
*/
showProxy?: boolean | undefined;
+
/**
* Specifies the maximum number of `Array`, [`TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), [`WeakMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap) and
* [`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) elements to include when formatting. Set to `null` or `Infinity` to
@@ -46,6 +51,7 @@ export interface BushInspectOptions extends InspectOptions {
* **Default**: `100`.
*/
maxArrayLength?: number | null | undefined;
+
/**
* Specifies the maximum number of characters to include when formatting. Set to
* `null` or `Infinity` to show all elements. Set to `0` or negative to show no
@@ -54,6 +60,7 @@ export interface BushInspectOptions extends InspectOptions {
* **Default**: `10000`.
*/
maxStringLength?: number | null | undefined;
+
/**
* The length at which input values are split across multiple lines. Set to
* `Infinity` to format the input as a single line (in combination with compact set
@@ -62,6 +69,7 @@ export interface BushInspectOptions extends InspectOptions {
* **Default**: `80`.
*/
breakLength?: number | undefined;
+
/**
* Setting this to `false` causes each object key to be displayed on a new line. It
* will break on new lines in text that is longer than `breakLength`. If set to a
@@ -71,6 +79,7 @@ export interface BushInspectOptions extends InspectOptions {
* **Default**: `3`
*/
compact?: boolean | number | undefined;
+
/**
* If set to `true` or a function, all properties of an object, and `Set` and `Map`
* entries are sorted in the resulting string. If set to `true` the [default sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) is used.
@@ -79,6 +88,7 @@ export interface BushInspectOptions extends InspectOptions {
* **Default**: `false`.
*/
sorted?: boolean | ((a: string, b: string) => number) | undefined;
+
/**
* If set to `true`, getters are inspected. If set to `'get'`, only getters without a
* corresponding setter are inspected. If set to `'set'`, only getters with a
diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts
index 39eff3b..93ed9d7 100644
--- a/src/lib/extensions/discord-akairo/BushClient.ts
+++ b/src/lib/extensions/discord-akairo/BushClient.ts
@@ -34,15 +34,15 @@ import path from 'path';
import readline from 'readline';
import type { Sequelize as SequelizeType } from 'sequelize';
import { fileURLToPath } from 'url';
-import { abbreviatedNumberTypeCaster } from '../../../arguments/abbreviatedNumber.js';
-import { contentWithDurationTypeCaster } from '../../../arguments/contentWithDuration.js';
-import { discordEmojiTypeCaster } from '../../../arguments/discordEmoji.js';
-import { durationTypeCaster } from '../../../arguments/duration.js';
-import { durationSecondsTypeCaster } from '../../../arguments/durationSeconds.js';
-import { globalUserTypeCaster } from '../../../arguments/globalUser.js';
-import { permissionTypeCaster } from '../../../arguments/permission.js';
-import { roleWithDurationTypeCaster } from '../../../arguments/roleWithDuration.js';
-import { snowflakeTypeCaster } from '../../../arguments/snowflake.js';
+import { abbreviatedNumber } from '../../../arguments/abbreviatedNumber.js';
+import { contentWithDuration } from '../../../arguments/contentWithDuration.js';
+import { discordEmoji } from '../../../arguments/discordEmoji.js';
+import { duration } from '../../../arguments/duration.js';
+import { durationSeconds } from '../../../arguments/durationSeconds.js';
+import { globalUser } from '../../../arguments/globalUser.js';
+import { permission } from '../../../arguments/permission.js';
+import { roleWithDuration } from '../../../arguments/roleWithDuration.js';
+import { snowflake } from '../../../arguments/snowflake.js';
import UpdateCacheTask from '../../../tasks/updateCache.js';
import UpdateStatsTask from '../../../tasks/updateStats.js';
import { ActivePunishment } from '../../models/ActivePunishment.js';
@@ -136,7 +136,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
public db: SequelizeType;
public logger = BushLogger;
public constants = BushConstants;
- public cache = BushCache;
+ public cache = new BushCache();
public sentry!: typeof Sentry;
public constructor(config: Config) {
@@ -279,15 +279,15 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
gateway: this.ws
});
this.commandHandler.resolver.addTypes({
- duration: durationTypeCaster,
- contentWithDuration: contentWithDurationTypeCaster,
- permission: permissionTypeCaster,
- snowflake: snowflakeTypeCaster,
- discordEmoji: discordEmojiTypeCaster,
- roleWithDuration: roleWithDurationTypeCaster,
- abbreviatedNumber: abbreviatedNumberTypeCaster,
- durationSeconds: durationSecondsTypeCaster,
- globalUser: globalUserTypeCaster
+ duration,
+ contentWithDuration,
+ permission,
+ snowflake,
+ discordEmoji,
+ roleWithDuration,
+ abbreviatedNumber,
+ durationSeconds,
+ globalUser
});
this.sentry = Sentry;
@@ -384,49 +384,25 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
}
public override isSuperUser(user: BushUserResolvable): boolean {
const userID = this.users.resolveId(user)!;
- return !!BushCache?.global?.superUsers?.includes(userID) || this.config.owners.includes(userID);
+ return !!client.cache?.global?.superUsers?.includes(userID) || this.config.owners.includes(userID);
}
- public override on<K extends keyof BushClientEvents>(
- event: K,
- listener: (...args: BushClientEvents[K]) => Awaitable<void>
- ): this;
- public override on<S extends string | symbol>(
- event: Exclude<S, keyof BushClientEvents>,
- listener: (...args: any[]) => Awaitable<void>
- ): this {
- return super.on(event as any, listener);
- }
- public override once<K extends keyof BushClientEvents>(
- event: K,
- listener: (...args: BushClientEvents[K]) => Awaitable<void>
- ): this;
- public override once<S extends string | symbol>(
- event: Exclude<S, keyof BushClientEvents>,
- listener: (...args: any[]) => Awaitable<void>
- ): this {
- return super.once(event as any, listener);
- }
+}
- public override emit<K extends keyof BushClientEvents>(event: K, ...args: BushClientEvents[K]): boolean;
- public override emit<S extends string | symbol>(event: Exclude<S, keyof BushClientEvents>, ...args: unknown[]): boolean {
- return super.emit(event as any, ...args);
- }
+export interface BushClient {
+ on<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this;
+ on<S extends string | symbol>(event: Exclude<S, keyof BushClientEvents>, listener: (...args: any[]) => Awaitable<void>): this
- public override off<K extends keyof BushClientEvents>(
- event: K,
- listener: (...args: BushClientEvents[K]) => Awaitable<void>
- ): this;
- public override off<S extends string | symbol>(
- event: Exclude<S, keyof BushClientEvents>,
- listener: (...args: any[]) => Awaitable<void>
- ): this {
- return super.off(event as any, listener);
- }
+ once<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this;
+ once<S extends string | symbol>(event: Exclude<S, keyof BushClientEvents>, listener: (...args: any[]) => Awaitable<void>): this
- public override removeAllListeners<K extends keyof BushClientEvents>(event?: K): this;
- public override removeAllListeners<S extends string | symbol>(event?: Exclude<S, keyof BushClientEvents>): this {
- return super.removeAllListeners(event as any);
- }
+ emit<K extends keyof BushClientEvents>(event: K, ...args: BushClientEvents[K]): boolean;
+ emit<S extends string | symbol>(event: Exclude<S, keyof BushClientEvents>, ...args: unknown[]): boolean
+
+ off<K extends keyof BushClientEvents>(event: K, listener: (...args: BushClientEvents[K]) => Awaitable<void>): this;
+ off<S extends string | symbol>(event: Exclude<S, keyof BushClientEvents>, listener: (...args: any[]) => Awaitable<void>): this
+
+ removeAllListeners<K extends keyof BushClientEvents>(event?: K): this;
+ removeAllListeners<S extends string | symbol>(event?: Exclude<S, keyof BushClientEvents>): this
}
diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts
index f619b4b..4b68b2e 100644
--- a/src/lib/extensions/discord-akairo/BushClientUtil.ts
+++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts
@@ -2,7 +2,6 @@ import {
Arg,
BushConstants,
Global,
- type BushCache,
type BushClient,
type BushInspectOptions,
type BushMessage,
@@ -388,7 +387,7 @@ export class BushClientUtil extends ClientUtil {
public async insertOrRemoveFromGlobal(
action: 'add' | 'remove',
- key: keyof typeof BushCache['global'],
+ key: keyof typeof client['cache']['global'],
value: any
): Promise<Global | void> {
const row =
diff --git a/src/lib/extensions/discord.js/BushGuild.ts b/src/lib/extensions/discord.js/BushGuild.ts
index dd01c55..5849749 100644
--- a/src/lib/extensions/discord.js/BushGuild.ts
+++ b/src/lib/extensions/discord.js/BushGuild.ts
@@ -191,7 +191,7 @@ export class BushGuild extends Guild {
const userObject = client.users.cache.get(user.id);
const dmSuccess = await userObject
- ?.send(`You have been unbanned from **${this}** for **${options.reason ?? 'No reason provided'}**.`)
+ ?.send(`You have been unbanned from **${util.discord.escapeMarkdown(this.toString())}** for **${options.reason ?? 'No reason provided'}**.`)
.catch(() => false);
dmSuccessEvent = !!dmSuccess;
diff --git a/src/lib/utils/BushCache.ts b/src/lib/utils/BushCache.ts
index d633898..3808538 100644
--- a/src/lib/utils/BushCache.ts
+++ b/src/lib/utils/BushCache.ts
@@ -2,12 +2,14 @@ import { Collection, type Snowflake } from 'discord.js';
import { Guild } from '../models/Guild.js';
export class BushCache {
- public static global = {
- superUsers: new Array<Snowflake>(),
- disabledCommands: new Array<string>(),
- blacklistedChannels: new Array<Snowflake>(),
- blacklistedGuilds: new Array<Snowflake>(),
- blacklistedUsers: new Array<Snowflake>()
- };
- public static guilds = new Collection<Snowflake, Guild>();
+ public global = new GlobalCache();
+ public guilds = new Collection<Snowflake, Guild>();
+}
+
+export class GlobalCache {
+ public superUsers: Snowflake[] = [];
+ public disabledCommands: string[] = []
+ public blacklistedChannels: Snowflake[] = [];
+ public blacklistedGuilds: Snowflake[] = [];
+ public blacklistedUsers: Snowflake[] = [];
}