aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/extensions/discord-akairo/BushClient.ts11
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts52
2 files changed, 45 insertions, 18 deletions
diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts
index 7d84b5e..4c877f3 100644
--- a/src/lib/extensions/discord-akairo/BushClient.ts
+++ b/src/lib/extensions/discord-akairo/BushClient.ts
@@ -1,4 +1,3 @@
-import chalk from 'chalk';
import { AkairoClient, ContextMenuCommandHandler } from 'discord-akairo';
import {
Awaited,
@@ -21,7 +20,6 @@ import eventsIntercept from 'events-intercept';
import JSON5 from 'json5';
import 'json5/lib/register';
import path from 'path';
-import { exit } from 'process';
import readline from 'readline';
import { Sequelize } from 'sequelize';
import { abbreviatedNumberTypeCaster } from '../../../arguments/abbreviatedNumber';
@@ -292,7 +290,8 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
dialect: 'postgres',
host: this.config.db.host,
port: this.config.db.port,
- logging: this.config.logging.db ? (sql) => this.logger.debug(sql) : false
+ logging: this.config.logging.db ? (sql) => this.logger.debug(sql) : false,
+ timezone: 'America/New_York'
});
}
@@ -367,9 +366,10 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
} catch (e) {
await this.console.error(
'startup',
- `Failed to connect to <<database>> with error:\n${typeof e}` === 'object' ? e?.stack : e,
+ `Failed to connect to <<database>> with error:\n${util.inspect(e, { colors: true, depth: 1 })}`,
false
);
+ process.exit(2);
}
}
@@ -397,8 +397,7 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
await this.#init();
await this.login(this.token!);
} catch (e) {
- await this.console.error('start', chalk.red(e?.stack || e), false);
- exit(2);
+ await this.console.error('start', util.inspect(e, { colors: true, depth: 1 }), false);
}
}
diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts
index 38e1a06..77ded3b 100644
--- a/src/lib/extensions/discord-akairo/BushClientUtil.ts
+++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts
@@ -925,11 +925,12 @@ export class BushClientUtil extends ClientUtil {
#mapCredential(old: string): string {
const mapping = {
- ['token']: 'Main Token',
- ['devToken']: 'Dev Token',
- ['betaToken']: 'Beta Token',
- ['hypixelApiKey']: 'Hypixel Api Key',
- ['wolframAlphaAppId']: 'Wolfram|Alpha App ID'
+ token: 'Main Token',
+ devToken: 'Dev Token',
+ betaToken: 'Beta Token',
+ hypixelApiKey: 'Hypixel Api Key',
+ wolframAlphaAppId: 'Wolfram|Alpha App ID',
+ dbPassword: 'Database Password'
};
return mapping[old as keyof typeof mapping] || old;
}
@@ -938,8 +939,10 @@ export class BushClientUtil extends ClientUtil {
* Redacts credentials from a string
*/
public redact(text: string) {
- for (const credentialName in client.config.credentials) {
- const credential = client.config.credentials[credentialName as keyof typeof client.config.credentials];
+ for (const credentialName in { ...client.config.credentials, dbPassword: client.config.db.password }) {
+ const credential = { ...client.config.credentials, dbPassword: client.config.db.password }[
+ credentialName as keyof typeof client.config.credentials
+ ];
const replacement = this.#mapCredential(credentialName);
const escapeRegex = /[.*+?^${}()|[\]\\]/g;
text = text.replace(new RegExp(credential.toString().replace(escapeRegex, '\\$&'), 'g'), `[${replacement} Omitted]`);
@@ -1182,14 +1185,18 @@ export class BushClientUtil extends ClientUtil {
modlog: string;
extraInfo?: Snowflake;
}): Promise<ActivePunishment | null> {
- const expires = options.duration ? new Date(new Date().getTime() + options.duration ?? 0) : undefined;
+ const expires = options.duration ? new Date(+new Date() + options.duration ?? 0) : undefined;
const user = (await util.resolveNonCachedUser(options.user))!.id;
const guild = client.guilds.resolveId(options.guild)!;
const type = this.#findTypeEnum(options.type)!;
- const entry = options.extraInfo
- ? ActivePunishment.build({ user, type, guild, expires, modlog: options.modlog, extraInfo: options.extraInfo })
- : ActivePunishment.build({ user, type, guild, expires, modlog: options.modlog });
+ console.debug(expires);
+
+ const entry = ActivePunishment.build(
+ options.extraInfo
+ ? { user, type, guild, expires, modlog: options.modlog, extraInfo: options.extraInfo }
+ : { user, type, guild, expires, modlog: options.modlog }
+ );
return await entry.save().catch(async (e) => {
await util.handleError('createPunishmentEntry', e);
return null;
@@ -1200,6 +1207,7 @@ export class BushClientUtil extends ClientUtil {
type: 'mute' | 'ban' | 'role' | 'block';
user: BushGuildMemberResolvable;
guild: BushGuildResolvable;
+ extraInfo?: Snowflake;
}): Promise<boolean> {
const user = await util.resolveNonCachedUser(options.user);
const guild = client.guilds.resolveId(options.guild);
@@ -1211,7 +1219,9 @@ export class BushClientUtil extends ClientUtil {
const entries = await ActivePunishment.findAll({
// finding all cases of a certain type incase there were duplicates or something
- where: { user: user.id, guild: guild, type }
+ where: options.extraInfo
+ ? { user: user.id, guild: guild, type, extraInfo: options.extraInfo }
+ : { user: user.id, guild: guild, type }
}).catch(async (e) => {
await util.handleError('removePunishmentEntry', e);
success = false;
@@ -1243,6 +1253,24 @@ export class BushClientUtil extends ClientUtil {
else return humanizeDuration(duration, { language: 'en', maxDecimalPoints: 2 });
}
+ public timestampDuration(duration: number): string {
+ return `<t:${Math.round(duration / 1000)}:R>`;
+ }
+
+ /**
+ * **Styles:**
+ * - **t**: Short Time
+ * - **T**: Long Time
+ * - **d**: Short Date
+ * - **D**: Long Date
+ * - **f**: Short Date/Time
+ * - **F**: Long Date/Time
+ * - **R**: Relative Time
+ */
+ public timestamp(date: Date, style: 't' | 'T' | 'd' | 'D' | 'f' | 'F' | 'R' = 'f'): string {
+ return `<t:${Math.round(date.getTime() / 1000)}:${style}>`;
+ }
+
public dateDelta(date: Date, largest?: number) {
return this.humanizeDuration(moment(date).diff(moment()), largest ?? 3);
}