diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-03-08 20:37:25 -0500 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-03-08 20:37:25 -0500 |
commit | 293fc2c5f86ea6aaa1ef19e784241b8a6656a166 (patch) | |
tree | caf7a51b0f5c1340321f67626b29e45ce89bb866 | |
parent | 6bc15403e1f1c3bc7042bb8066172b0f6a312ac5 (diff) | |
download | tanzanite-293fc2c5f86ea6aaa1ef19e784241b8a6656a166.tar.gz tanzanite-293fc2c5f86ea6aaa1ef19e784241b8a6656a166.tar.bz2 tanzanite-293fc2c5f86ea6aaa1ef19e784241b8a6656a166.zip |
feat: use short date format in guild and user commands
-rw-r--r-- | src/commands/info/guildInfo.ts | 2 | ||||
-rw-r--r-- | src/commands/info/userInfo.ts | 7 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClientUtil.ts | 23 |
3 files changed, 22 insertions, 10 deletions
diff --git a/src/commands/info/guildInfo.ts b/src/commands/info/guildInfo.ts index 7f82e92..e026d1c 100644 --- a/src/commands/info/guildInfo.ts +++ b/src/commands/info/guildInfo.ts @@ -127,7 +127,7 @@ export default class GuildInfoCommand extends BushCommand { guildAbout.push( `**Owner:** ${util.discord.escapeMarkdown(guild.members.cache.get(guild.ownerId)?.user.tag ?? '¯\\_(ツ)_/¯')}`, - `**Created** ${util.timestamp(guild.createdAt)} (${util.dateDelta(guild.createdAt)})`, + `**Created** ${util.timestampAndDelta(guild.createdAt, 'd')}`, `**Members:** ${guild.memberCount.toLocaleString() ?? 0} (${util.emojis.onlineCircle} ${ guild.approximatePresenceCount?.toLocaleString() ?? 0 }, ${util.emojis.offlineCircle} ${(guild.memberCount - (guild.approximatePresenceCount ?? 0)).toLocaleString() ?? 0})`, diff --git a/src/commands/info/userInfo.ts b/src/commands/info/userInfo.ts index 66c0e00..edf2b6d 100644 --- a/src/commands/info/userInfo.ts +++ b/src/commands/info/userInfo.ts @@ -124,7 +124,7 @@ export default class UserInfoCommand extends BushCommand { const generalInfo = [ `**Mention:** <@${user.id}>`, `**ID:** ${user.id}`, - `**Created:** ${util.timestampAndDelta(user.createdAt)}` + `**Created:** ${util.timestampAndDelta(user.createdAt, 'd')}` ]; if (user.accentColor !== null) generalInfo.push(`**Accent Color:** ${user.hexAccentColor}`); if (user.banner) generalInfo.push(`**Banner:** [link](${user.bannerURL({ extension: 'png', size: 4096 })})`); @@ -144,10 +144,11 @@ export default class UserInfoCommand extends BushCommand { if (member.joinedTimestamp) serverUserInfo.push( `**${member.guild!.ownerId == member.user.id ? 'Created Server' : 'Joined'}:** ${util.timestampAndDelta( - member.joinedAt! + member.joinedAt!, + 'd' )}` ); - if (member.premiumSince) serverUserInfo.push(`**Boosting Since:** ${util.timestampAndDelta(member.premiumSince)}`); + if (member.premiumSince) serverUserInfo.push(`**Booster Since:** ${util.timestampAndDelta(member.premiumSince, 'd')}`); if (member.displayHexColor) serverUserInfo.push(`**Display Color:** ${member.displayHexColor}`); if (member.user.id == '322862723090219008' && member.guild?.id == client.consts.mappings.guilds.bush) serverUserInfo.push(`**General Deletions:** 1⅓`); diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index 83ab45e..51daf70 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -608,10 +608,7 @@ export class BushClientUtil extends ClientUtil { * - **F**: Long Date/Time ex. `Tuesday, 20 April 2021 16:20` * - **R**: Relative Time ex. `2 months ago` */ - public timestamp<D extends Date | undefined | null>( - date: D, - style: 't' | 'T' | 'd' | 'D' | 'f' | 'F' | 'R' = 'f' - ): D extends Date ? string : undefined { + public timestamp<D extends Date | undefined | null>(date: D, style: TimestampStyle = 'f'): D extends Date ? string : undefined { if (!date) return date as unknown as D extends Date ? string : undefined; return `<t:${Math.round(date.getTime() / 1_000)}:${style}>` as unknown as D extends Date ? string : undefined; } @@ -629,9 +626,21 @@ export class BushClientUtil extends ClientUtil { /** * Combines {@link timestamp} and {@link dateDelta} * @param date The date to be compared with the current time. + * @param style The style of the timestamp. + * @returns The formatted timestamp. + * + * @see + * **Styles:** + * - **t**: Short Time ex. `16:20` + * - **T**: Long Time ex. `16:20:30 ` + * - **d**: Short Date ex. `20/04/2021` + * - **D**: Long Date ex. `20 April 2021` + * - **f**: Short Date/Time ex. `20 April 2021 16:20` + * - **F**: Long Date/Time ex. `Tuesday, 20 April 2021 16:20` + * - **R**: Relative Time ex. `2 months ago` */ - public timestampAndDelta(date: Date): string { - return `${this.timestamp(date, 'D')} (${this.dateDelta(date)} ago)`; + public timestampAndDelta(date: Date, style: TimestampStyle = 'D'): string { + return `${this.timestamp(date, style)} (${this.dateDelta(date)} ago)`; } /** @@ -1025,3 +1034,5 @@ export interface ParsedDurationRes { duration: number; content: string; } + +export type TimestampStyle = 't' | 'T' | 'd' | 'D' | 'f' | 'F' | 'R'; |