mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-02 21:16:09 +00:00
chore: improve toString output with newly added formatters (#209)
* chore: improve toString output with newly added formatters * fix(missingParameter): added emoji name as a parameter --------- Co-authored-by: NotAditya69 <90441096+NotAditya69@users.noreply.github.com>
This commit is contained in:
parent
88c800d9fd
commit
20bb778722
@ -200,4 +200,41 @@ export class Formatter {
|
|||||||
static timestamp(timestamp: Date, style: TimestampStyle = TimestampStyle.RelativeTime): Timestamp {
|
static timestamp(timestamp: Date, style: TimestampStyle = TimestampStyle.RelativeTime): Timestamp {
|
||||||
return `<t:${Math.floor(timestamp.getTime() / 1000)}:${style}>`;
|
return `<t:${Math.floor(timestamp.getTime() / 1000)}:${style}>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats a user mention.
|
||||||
|
* @param userId The ID of the user to mention.
|
||||||
|
* @returns The formatted user mention.
|
||||||
|
*/
|
||||||
|
static userMention(userId: string): `<@${string}>` {
|
||||||
|
return `<@${userId}>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats a role mention.
|
||||||
|
* @param roleId The ID of the role to mention.
|
||||||
|
* @returns The formatted role mention.
|
||||||
|
*/
|
||||||
|
static roleMention(roleId: string): `<@&${string}>` {
|
||||||
|
return `<@&${roleId}>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats a channel mention.
|
||||||
|
* @param channelId The ID of the channel to mention.
|
||||||
|
* @returns The formatted channel mention.
|
||||||
|
*/
|
||||||
|
static channelMention(channelId: string): `<#${string}>` {
|
||||||
|
return `<#${channelId}>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats an emoji.
|
||||||
|
* @param emojiId The ID of the emoji.
|
||||||
|
* @param animated Whether the emoji is animated. Defaults to false.
|
||||||
|
* @returns The formatted emoji.
|
||||||
|
*/
|
||||||
|
static emojiMention(emojiId: string, name: string | null, animated = false): string {
|
||||||
|
return `<${animated ? 'a' : ''}:${name ?? '_'}:${emojiId}>`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ export const GUILD_INTEGRATIONS_UPDATE = (_self: UsingClient, data: GatewayGuild
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const GUILD_MEMBER_ADD = (self: UsingClient, data: GatewayGuildMemberAddDispatchData) => {
|
export const GUILD_MEMBER_ADD = (self: UsingClient, data: GatewayGuildMemberAddDispatchData) => {
|
||||||
return new GuildMember(self, data, data.user, data.guild_id);
|
return new GuildMember(self, data, data.user!, data.guild_id);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const GUILD_MEMBER_REMOVE = (self: UsingClient, data: GatewayGuildMemberRemoveDispatchData) => {
|
export const GUILD_MEMBER_REMOVE = (self: UsingClient, data: GatewayGuildMemberRemoveDispatchData) => {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import type { APIBan, RESTGetAPIGuildBansQuery } from 'discord-api-types/v10';
|
import type { APIBan, RESTGetAPIGuildBansQuery } from 'discord-api-types/v10';
|
||||||
import type { UsingClient } from '../commands';
|
import type { UsingClient } from '../commands';
|
||||||
import type { MethodContext, ObjectToLower } from '../common';
|
import { Formatter, type MethodContext, type ObjectToLower } from '../common';
|
||||||
import { DiscordBase } from './extra/DiscordBase';
|
import { DiscordBase } from './extra/DiscordBase';
|
||||||
import type { BanShorter } from '../common/shorters/bans';
|
import type { BanShorter } from '../common/shorters/bans';
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ export class GuildBan extends DiscordBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
return `<@${this.id}>`;
|
return Formatter.userMention(this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static methods({ client, guildId }: MethodContext<{ guildId: string }>) {
|
static methods({ client, guildId }: MethodContext<{ guildId: string }>) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import type { APIEmoji, RESTPatchAPIChannelJSONBody, RESTPatchAPIGuildEmojiJSONBody } from 'discord-api-types/v10';
|
import type { APIEmoji, RESTPatchAPIChannelJSONBody, RESTPatchAPIGuildEmojiJSONBody } from 'discord-api-types/v10';
|
||||||
import type { BaseCDNUrlOptions } from '../api';
|
import type { BaseCDNUrlOptions } from '../api';
|
||||||
import type { UsingClient } from '../commands';
|
import type { UsingClient } from '../commands';
|
||||||
import type { EmojiShorter, MethodContext, ObjectToLower } from '../common';
|
import { Formatter, type EmojiShorter, type MethodContext, type ObjectToLower } from '../common';
|
||||||
import { DiscordBase } from './extra/DiscordBase';
|
import { DiscordBase } from './extra/DiscordBase';
|
||||||
|
|
||||||
export interface GuildEmoji extends DiscordBase, ObjectToLower<Omit<APIEmoji, 'id'>> {}
|
export interface GuildEmoji extends DiscordBase, ObjectToLower<Omit<APIEmoji, 'id'>> {}
|
||||||
@ -37,7 +37,7 @@ export class GuildEmoji extends DiscordBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
return `<${this.animated ? 'a' : ''}:${this.name}:${this.id}>`;
|
return Formatter.emojiMention(this.id, this.name, this.animated);
|
||||||
}
|
}
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
|
@ -20,7 +20,7 @@ import type {
|
|||||||
RESTPutAPIGuildMemberJSONBody,
|
RESTPutAPIGuildMemberJSONBody,
|
||||||
} from 'discord-api-types/v10';
|
} from 'discord-api-types/v10';
|
||||||
import type { UsingClient } from '../commands';
|
import type { UsingClient } from '../commands';
|
||||||
import type { MessageCreateBodyRequest, ObjectToLower, ToClass } from '../common';
|
import { Formatter, type MessageCreateBodyRequest, type ObjectToLower, type ToClass } from '../common';
|
||||||
import type { ImageOptions, MethodContext } from '../common/types/options';
|
import type { ImageOptions, MethodContext } from '../common/types/options';
|
||||||
import type { GuildMemberResolvable } from '../common/types/resolvables';
|
import type { GuildMemberResolvable } from '../common/types/resolvables';
|
||||||
import { User } from './User';
|
import { User } from './User';
|
||||||
@ -73,7 +73,7 @@ export class BaseGuildMember extends DiscordBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
return `<@${this.id}>`;
|
return Formatter.userMention(this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private patch(data: GuildMemberData) {
|
private patch(data: GuildMemberData) {
|
||||||
|
@ -5,7 +5,7 @@ import type {
|
|||||||
RESTPostAPIGuildRoleJSONBody,
|
RESTPostAPIGuildRoleJSONBody,
|
||||||
} from 'discord-api-types/v10';
|
} from 'discord-api-types/v10';
|
||||||
import type { UsingClient } from '../commands';
|
import type { UsingClient } from '../commands';
|
||||||
import type { MethodContext, ObjectToLower } from '../common';
|
import { Formatter, type MethodContext, type ObjectToLower } from '../common';
|
||||||
import { DiscordBase } from './extra/DiscordBase';
|
import { DiscordBase } from './extra/DiscordBase';
|
||||||
import { PermissionsBitField } from './extra/Permissions';
|
import { PermissionsBitField } from './extra/Permissions';
|
||||||
|
|
||||||
@ -35,6 +35,10 @@ export class GuildRole extends DiscordBase {
|
|||||||
return this.client.roles.delete(this.guildId, this.id, reason);
|
return this.client.roles.delete(this.guildId, this.id, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toString() {
|
||||||
|
return Formatter.roleMention(this.id);
|
||||||
|
}
|
||||||
|
|
||||||
static methods(ctx: MethodContext<{ guildId: string }>) {
|
static methods(ctx: MethodContext<{ guildId: string }>) {
|
||||||
return {
|
return {
|
||||||
create: (body: RESTPostAPIGuildRoleJSONBody) => ctx.client.roles.create(ctx.guildId, body),
|
create: (body: RESTPostAPIGuildRoleJSONBody) => ctx.client.roles.create(ctx.guildId, body),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import type { APIUser } from 'discord-api-types/v10';
|
import type { APIUser } from 'discord-api-types/v10';
|
||||||
import { calculateUserDefaultAvatarIndex } from '../api';
|
import { calculateUserDefaultAvatarIndex } from '../api';
|
||||||
import type { MessageCreateBodyRequest, ObjectToLower } from '../common';
|
import { Formatter, type MessageCreateBodyRequest, type ObjectToLower } from '../common';
|
||||||
import type { ImageOptions } from '../common/types/options';
|
import type { ImageOptions } from '../common/types/options';
|
||||||
import { DiscordBase } from './extra/DiscordBase';
|
import { DiscordBase } from './extra/DiscordBase';
|
||||||
|
|
||||||
@ -60,6 +60,6 @@ export class User extends DiscordBase<APIUser> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
return `<@${this.id}>`;
|
return Formatter.userMention(this.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ import type { GuildMember } from './GuildMember';
|
|||||||
import type { GuildRole } from './GuildRole';
|
import type { GuildRole } from './GuildRole';
|
||||||
import { DiscordBase } from './extra/DiscordBase';
|
import { DiscordBase } from './extra/DiscordBase';
|
||||||
import { channelLink } from './extra/functions';
|
import { channelLink } from './extra/functions';
|
||||||
import { Collection, type RawFile } from '..';
|
import { Collection, Formatter, type RawFile } from '..';
|
||||||
|
|
||||||
export class BaseChannel<T extends ChannelType> extends DiscordBase<APIChannelBase<ChannelType>> {
|
export class BaseChannel<T extends ChannelType> extends DiscordBase<APIChannelBase<ChannelType>> {
|
||||||
declare type: T;
|
declare type: T;
|
||||||
@ -77,7 +77,7 @@ export class BaseChannel<T extends ChannelType> extends DiscordBase<APIChannelBa
|
|||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
return `<#${this.id}>`;
|
return Formatter.channelMention(this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
isStage(): this is StageChannel {
|
isStage(): this is StageChannel {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user