aboutsummaryrefslogtreecommitdiff
path: root/src/lib/extensions/discord-akairo/BushClientUtil.ts
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-09-09 21:51:12 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-09-09 21:51:12 -0400
commit7635ccdbda1bbf14dd0cca52cd0e8e00e1194d62 (patch)
tree5e0c01f54e91ad4be2fc9e22cc001ab72dc6d23d /src/lib/extensions/discord-akairo/BushClientUtil.ts
parent3ea8f98128d81bcd03df6699d46804b38ddcc294 (diff)
downloadtanzanite-7635ccdbda1bbf14dd0cca52cd0e8e00e1194d62.tar.gz
tanzanite-7635ccdbda1bbf14dd0cca52cd0e8e00e1194d62.tar.bz2
tanzanite-7635ccdbda1bbf14dd0cca52cd0e8e00e1194d62.zip
make db password redacted
Diffstat (limited to 'src/lib/extensions/discord-akairo/BushClientUtil.ts')
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts52
1 files changed, 40 insertions, 12 deletions
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);
}