aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/extensions/discord-akairo/BushClient.ts15
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts56
-rw-r--r--src/lib/extensions/discord.js/BushClientEvents.d.ts5
-rw-r--r--src/lib/extensions/discord.js/BushGuildMember.ts5
-rw-r--r--src/lib/models/ActivePunishment.ts2
-rw-r--r--src/lib/utils/BushLogger.ts2
6 files changed, 60 insertions, 25 deletions
diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts
index 7d84b5e..48ba90d 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'
});
}
@@ -337,9 +336,9 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re
inhibitors: this.inhibitorHandler,
tasks: this.taskHandler
};
- for (const loader of Object.keys(loaders)) {
+ for (const loader in loaders) {
try {
- loaders[loader as keyof typeof loaders].loadAll();
+ await loaders[loader as keyof typeof loaders].loadAll();
void this.logger.success('startup', `Successfully loaded <<${loader}>>.`, false);
} catch (e) {
void this.logger.error('startup', `Unable to load loader <<${loader}>> with error:\n${e?.stack || e}`, false);
@@ -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..c15ca1c 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,28 @@ 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<D extends Date | undefined | null>(
+ date: D,
+ style: 't' | 'T' | 'd' | 'D' | 'f' | 'F' | 'R' = 'f'
+ ): D extends Date ? string : undefined {
+ if (!date) return date as unknown as D extends Date ? string : undefined;
+ return `<t:${Math.round(date.getTime() / 1000)}:${style}>` as unknown as D extends Date ? string : undefined;
+ }
+
public dateDelta(date: Date, largest?: number) {
return this.humanizeDuration(moment(date).diff(moment()), largest ?? 3);
}
diff --git a/src/lib/extensions/discord.js/BushClientEvents.d.ts b/src/lib/extensions/discord.js/BushClientEvents.d.ts
index 96dc4c5..eb36153 100644
--- a/src/lib/extensions/discord.js/BushClientEvents.d.ts
+++ b/src/lib/extensions/discord.js/BushClientEvents.d.ts
@@ -85,7 +85,10 @@ export interface BushClientEvents extends ClientEvents {
inviteDelete: [invite: Invite];
messageCreate: [message: BushMessage];
messageDelete: [message: BushMessage | PartialBushMessage];
- messageReactionRemoveAll: [message: BushMessage | PartialBushMessage];
+ messageReactionRemoveAll: [
+ message: BushMessage | PartialBushMessage,
+ reactions: Collection<string, BushMessageReaction>
+ ];
messageReactionRemoveEmoji: [
reaction: BushMessageReaction | PartialBushMessageReaction
];
diff --git a/src/lib/extensions/discord.js/BushGuildMember.ts b/src/lib/extensions/discord.js/BushGuildMember.ts
index b5bc407..8e855f7 100644
--- a/src/lib/extensions/discord.js/BushGuildMember.ts
+++ b/src/lib/extensions/discord.js/BushGuildMember.ts
@@ -199,7 +199,7 @@ export class BushGuildMember extends GuildMember {
const ret = await (async () => {
if (options.addToModlog) {
const { log: modlog } = await util.createModLogEntry({
- type: ModLogType.PERM_PUNISHMENT_ROLE,
+ type: ModLogType.REMOVE_PUNISHMENT_ROLE,
guild: this.guild,
moderator: moderator.id,
user: this,
@@ -212,7 +212,8 @@ export class BushGuildMember extends GuildMember {
const punishmentEntrySuccess = await util.removePunishmentEntry({
type: 'role',
user: this,
- guild: this.guild
+ guild: this.guild,
+ extraInfo: options.role.id
});
if (!punishmentEntrySuccess) return 'error removing role entry';
diff --git a/src/lib/models/ActivePunishment.ts b/src/lib/models/ActivePunishment.ts
index f453426..12b0cab 100644
--- a/src/lib/models/ActivePunishment.ts
+++ b/src/lib/models/ActivePunishment.ts
@@ -131,7 +131,7 @@ export class ActivePunishment
}
},
extraInfo: {
- type: DataTypes.DATE,
+ type: DataTypes.STRING,
allowNull: true
},
expires: {
diff --git a/src/lib/utils/BushLogger.ts b/src/lib/utils/BushLogger.ts
index c2a9989..f00c19c 100644
--- a/src/lib/utils/BushLogger.ts
+++ b/src/lib/utils/BushLogger.ts
@@ -156,7 +156,7 @@ export class BushLogger {
.setDescription(`**[${header}]** ${this.#parseFormatting(this.#stripColor(newContent), '', true)}`)
.setColor(util.colors.warn)
.setTimestamp();
- await this.channelLog({ embeds: [embed] });
+ await this.channelError({ embeds: [embed] });
}
/**