mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
fix: fmt
This commit is contained in:
parent
dca91be86e
commit
c76982541e
@ -6,7 +6,7 @@ import type { DiscordAttachment } from "../vendor/external.ts";
|
|||||||
/**
|
/**
|
||||||
* Represents an attachment
|
* Represents an attachment
|
||||||
* @link https://discord.com/developers/docs/resources/channel#attachment-object
|
* @link https://discord.com/developers/docs/resources/channel#attachment-object
|
||||||
* */
|
*/
|
||||||
export class Attachment implements Model {
|
export class Attachment implements Model {
|
||||||
constructor(session: Session, data: DiscordAttachment) {
|
constructor(session: Session, data: DiscordAttachment) {
|
||||||
this.session = session;
|
this.session = session;
|
||||||
@ -19,7 +19,7 @@ export class Attachment implements Model {
|
|||||||
this.size = data.size;
|
this.size = data.size;
|
||||||
this.height = data.height ? data.height : undefined;
|
this.height = data.height ? data.height : undefined;
|
||||||
this.width = data.width ? data.width : undefined;
|
this.width = data.width ? data.width : undefined;
|
||||||
this.ephemeral = !!data.ephemeral
|
this.ephemeral = !!data.ephemeral;
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly session: Session;
|
readonly session: Session;
|
||||||
|
@ -6,7 +6,7 @@ import { iconHashToBigInt } from "../util/hash.ts";
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for {@link Guild} and {@link AnonymousGuild}
|
* Class for {@link Guild} and {@link AnonymousGuild}
|
||||||
* */
|
*/
|
||||||
export abstract class BaseGuild implements Model {
|
export abstract class BaseGuild implements Model {
|
||||||
constructor(session: Session, data: DiscordGuild) {
|
constructor(session: Session, data: DiscordGuild) {
|
||||||
this.session = session;
|
this.session = session;
|
||||||
@ -37,4 +37,3 @@ export abstract class BaseGuild implements Model {
|
|||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import type { Model } from "./Base.ts";
|
import type { Model } from "./Base.ts";
|
||||||
import { Snowflake, Session, DiscordChannel, ChannelTypes } from "../mod.ts";
|
import { ChannelTypes, DiscordChannel, Session, Snowflake } from "../mod.ts";
|
||||||
|
|
||||||
export abstract class Channel implements Model {
|
export abstract class Channel implements Model {
|
||||||
constructor(session: Session, data: DiscordChannel) {
|
constructor(session: Session, data: DiscordChannel) {
|
||||||
@ -12,5 +12,4 @@ export abstract class Channel implements Model {
|
|||||||
readonly session: Session;
|
readonly session: Session;
|
||||||
readonly name: string | undefined;
|
readonly name: string | undefined;
|
||||||
readonly type: ChannelTypes;
|
readonly type: ChannelTypes;
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
import { Channel } from "./Channel.ts";
|
import { Channel } from "./Channel.ts";
|
||||||
//import { User } from "./User.ts";
|
//import { User } from "./User.ts";
|
||||||
import { Session, DiscordChannel, Snowflake, Routes } from "../mod.ts";
|
import { DiscordChannel, Routes, Session, Snowflake } from "../mod.ts";
|
||||||
|
|
||||||
export class DMChannel extends Channel {
|
export class DMChannel extends Channel {
|
||||||
constructor(session: Session, data: DiscordChannel) {
|
constructor(session: Session, data: DiscordChannel) {
|
||||||
@ -15,8 +15,8 @@ export class DMChannel extends Channel {
|
|||||||
const channel = await this.session.rest.runMethod<DiscordChannel>(
|
const channel = await this.session.rest.runMethod<DiscordChannel>(
|
||||||
this.session.rest,
|
this.session.rest,
|
||||||
"DELETE",
|
"DELETE",
|
||||||
Routes.CHANNEL(this.id)
|
Routes.CHANNEL(this.id),
|
||||||
)
|
);
|
||||||
return new DMChannel(this.session, channel);
|
return new DMChannel(this.session, channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,8 +2,12 @@ import type { Model } from "./Base.ts";
|
|||||||
import type { Snowflake } from "../util/Snowflake.ts";
|
import type { Snowflake } from "../util/Snowflake.ts";
|
||||||
import type { Session } from "../session/Session.ts";
|
import type { Session } from "../session/Session.ts";
|
||||||
import type { DiscordGuild, DiscordRole } from "../vendor/external.ts";
|
import type { DiscordGuild, DiscordRole } from "../vendor/external.ts";
|
||||||
import { DefaultMessageNotificationLevels, ExplicitContentFilterLevels, VerificationLevels } from "../vendor/external.ts";
|
import {
|
||||||
import { iconHashToBigInt, iconBigintToHash } from "../util/hash.ts";
|
DefaultMessageNotificationLevels,
|
||||||
|
ExplicitContentFilterLevels,
|
||||||
|
VerificationLevels,
|
||||||
|
} from "../vendor/external.ts";
|
||||||
|
import { iconBigintToHash, iconHashToBigInt } from "../util/hash.ts";
|
||||||
import { Member } from "./Member.ts";
|
import { Member } from "./Member.ts";
|
||||||
import { BaseGuild } from "./BaseGuild.ts";
|
import { BaseGuild } from "./BaseGuild.ts";
|
||||||
import { Role } from "./Role.ts";
|
import { Role } from "./Role.ts";
|
||||||
@ -21,7 +25,7 @@ export interface CreateRole {
|
|||||||
/**
|
/**
|
||||||
* Represents a guild
|
* Represents a guild
|
||||||
* @link https://discord.com/developers/docs/resources/guild#guild-object
|
* @link https://discord.com/developers/docs/resources/guild#guild-object
|
||||||
* */
|
*/
|
||||||
export class Guild extends BaseGuild implements Model {
|
export class Guild extends BaseGuild implements Model {
|
||||||
constructor(session: Session, data: DiscordGuild) {
|
constructor(session: Session, data: DiscordGuild) {
|
||||||
super(session, data);
|
super(session, data);
|
||||||
@ -55,8 +59,7 @@ export class Guild extends BaseGuild implements Model {
|
|||||||
if (options.iconHash) {
|
if (options.iconHash) {
|
||||||
if (typeof options.iconHash === "string") {
|
if (typeof options.iconHash === "string") {
|
||||||
icon = options.iconHash;
|
icon = options.iconHash;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
icon = iconBigintToHash(options.iconHash);
|
icon = iconBigintToHash(options.iconHash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -72,7 +75,7 @@ export class Guild extends BaseGuild implements Model {
|
|||||||
unicode_emoji: options.unicodeEmoji,
|
unicode_emoji: options.unicodeEmoji,
|
||||||
hoist: options.hoist,
|
hoist: options.hoist,
|
||||||
mentionable: options.mentionable,
|
mentionable: options.mentionable,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
return new Role(this.session, this, role);
|
return new Role(this.session, this, role);
|
||||||
|
@ -2,7 +2,6 @@ import { Channel } from "./Channel.ts";
|
|||||||
import { Guild } from "./Guild.ts";
|
import { Guild } from "./Guild.ts";
|
||||||
import { DiscordChannel, Routes, Session, Snowflake } from "../mod.ts";
|
import { DiscordChannel, Routes, Session, Snowflake } from "../mod.ts";
|
||||||
|
|
||||||
|
|
||||||
export class GuildChannel extends Channel {
|
export class GuildChannel extends Channel {
|
||||||
constructor(session: Session, data: DiscordChannel, guildId: Guild["id"]) {
|
constructor(session: Session, data: DiscordChannel, guildId: Guild["id"]) {
|
||||||
super(session, data);
|
super(session, data);
|
||||||
|
@ -9,7 +9,7 @@ import { User } from "./User.ts";
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @link https://discord.com/developers/docs/resources/guild#create-guild-ban
|
* @link https://discord.com/developers/docs/resources/guild#create-guild-ban
|
||||||
* */
|
*/
|
||||||
export interface CreateGuildBan {
|
export interface CreateGuildBan {
|
||||||
/** Number of days to delete messages for (0-7) */
|
/** Number of days to delete messages for (0-7) */
|
||||||
deleteMessageDays?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
deleteMessageDays?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
||||||
@ -21,7 +21,7 @@ export interface CreateGuildBan {
|
|||||||
* Represents a guild member
|
* Represents a guild member
|
||||||
* TODO: add a `guild` property somehow
|
* TODO: add a `guild` property somehow
|
||||||
* @link https://discord.com/developers/docs/resources/guild#guild-member-object
|
* @link https://discord.com/developers/docs/resources/guild#guild-member-object
|
||||||
* */
|
*/
|
||||||
export class Member implements Model {
|
export class Member implements Model {
|
||||||
constructor(session: Session, data: MakeRequired<DiscordMember, "user">) {
|
constructor(session: Session, data: MakeRequired<DiscordMember, "user">) {
|
||||||
this.session = session;
|
this.session = session;
|
||||||
@ -33,7 +33,9 @@ export class Member implements Model {
|
|||||||
this.deaf = !!data.deaf;
|
this.deaf = !!data.deaf;
|
||||||
this.mute = !!data.mute;
|
this.mute = !!data.mute;
|
||||||
this.pending = !!data.pending;
|
this.pending = !!data.pending;
|
||||||
this.communicationDisabledUntilTimestamp = data.communication_disabled_until ? Number.parseInt(data.communication_disabled_until) : undefined;
|
this.communicationDisabledUntilTimestamp = data.communication_disabled_until
|
||||||
|
? Number.parseInt(data.communication_disabled_until)
|
||||||
|
: undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly session: Session;
|
readonly session: Session;
|
||||||
@ -63,16 +65,18 @@ export class Member implements Model {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Bans the member
|
* Bans the member
|
||||||
* */
|
*/
|
||||||
async ban(guildId: Snowflake, options: CreateGuildBan): Promise<Member> {
|
async ban(guildId: Snowflake, options: CreateGuildBan): Promise<Member> {
|
||||||
await this.session.rest.runMethod<undefined>(
|
await this.session.rest.runMethod<undefined>(
|
||||||
this.session.rest,
|
this.session.rest,
|
||||||
"PUT",
|
"PUT",
|
||||||
Routes.GUILD_BAN(guildId, this.id),
|
Routes.GUILD_BAN(guildId, this.id),
|
||||||
options ? {
|
options
|
||||||
|
? {
|
||||||
delete_message_days: options.deleteMessageDays,
|
delete_message_days: options.deleteMessageDays,
|
||||||
reason: options.reason
|
reason: options.reason,
|
||||||
} : {}
|
}
|
||||||
|
: {},
|
||||||
);
|
);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -80,13 +84,13 @@ export class Member implements Model {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Kicks the member
|
* Kicks the member
|
||||||
* */
|
*/
|
||||||
async kick(guildId: Snowflake, { reason }: { reason?: string }): Promise<Member> {
|
async kick(guildId: Snowflake, { reason }: { reason?: string }): Promise<Member> {
|
||||||
await this.session.rest.runMethod<undefined>(
|
await this.session.rest.runMethod<undefined>(
|
||||||
this.session.rest,
|
this.session.rest,
|
||||||
"DELETE",
|
"DELETE",
|
||||||
Routes.GUILD_MEMBER(guildId, this.id),
|
Routes.GUILD_MEMBER(guildId, this.id),
|
||||||
{ reason }
|
{ reason },
|
||||||
);
|
);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -55,10 +55,12 @@ export class Message implements Model {
|
|||||||
this.attachments = data.attachments.map((attachment) => new Attachment(session, attachment));
|
this.attachments = data.attachments.map((attachment) => new Attachment(session, attachment));
|
||||||
|
|
||||||
// user is always null on MessageCreate and its replaced with author
|
// user is always null on MessageCreate and its replaced with author
|
||||||
this.member = data.member ? new Member(session, {
|
this.member = data.member
|
||||||
|
? new Member(session, {
|
||||||
...data.member,
|
...data.member,
|
||||||
user: data.author,
|
user: data.author,
|
||||||
}) : undefined;
|
})
|
||||||
|
: undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly session: Session;
|
readonly session: Session;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Guild } from "./Guild.ts";
|
import { Guild } from "./Guild.ts";
|
||||||
import { TextChannel } from "./TextChannel.ts"
|
import { TextChannel } from "./TextChannel.ts";
|
||||||
import { Session, DiscordChannel } from "../mod.ts";
|
import { DiscordChannel, Session } from "../mod.ts";
|
||||||
|
|
||||||
export class NewsChannel extends TextChannel {
|
export class NewsChannel extends TextChannel {
|
||||||
constructor(session: Session, data: DiscordChannel, guildId: Guild["id"]) {
|
constructor(session: Session, data: DiscordChannel, guildId: Guild["id"]) {
|
||||||
|
@ -39,7 +39,7 @@ export class Role implements Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get hexColor() {
|
get hexColor() {
|
||||||
return `#${this.color.toString(16).padStart(6, '0')}`;
|
return `#${this.color.toString(16).padStart(6, "0")}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2,15 +2,8 @@ import { GuildChannel } from "./GuildChannel.ts";
|
|||||||
import { Guild } from "./Guild.ts";
|
import { Guild } from "./Guild.ts";
|
||||||
import { ThreadChannel } from "./ThreadChannel.ts";
|
import { ThreadChannel } from "./ThreadChannel.ts";
|
||||||
import { Message } from "./Message.ts";
|
import { Message } from "./Message.ts";
|
||||||
import {
|
import { DiscordChannel, DiscordInviteCreate, DiscordMessage, Routes, Session, Snowflake } from "../mod.ts";
|
||||||
DiscordChannel,
|
import { GetMessagesOptions } from "../util/Routes.ts";
|
||||||
DiscordInviteCreate,
|
|
||||||
Routes,
|
|
||||||
Session,
|
|
||||||
Snowflake,
|
|
||||||
DiscordMessage
|
|
||||||
} from "../mod.ts";
|
|
||||||
import { GetMessagesOptions } from "../util/Routes.ts"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the options object to create an invitation
|
* Represents the options object to create an invitation
|
||||||
@ -81,12 +74,12 @@ export class TextChannel extends GuildChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fetchMessages(options?: GetMessagesOptions): Promise<Message[] | []> {
|
async fetchMessages(options?: GetMessagesOptions): Promise<Message[] | []> {
|
||||||
if (options?.limit! > 100) throw Error("Values must be between 0-100")
|
if (options?.limit! > 100) throw Error("Values must be between 0-100");
|
||||||
const messages = await this.session.rest.runMethod<DiscordMessage[]>(
|
const messages = await this.session.rest.runMethod<DiscordMessage[]>(
|
||||||
this.session.rest,
|
this.session.rest,
|
||||||
"GET",
|
"GET",
|
||||||
Routes.CHANNEL_MESSAGES(this.id, options)
|
Routes.CHANNEL_MESSAGES(this.id, options),
|
||||||
)
|
);
|
||||||
return messages[0] ? messages.map((x) => new Message(this.session, x)) : [];
|
return messages[0] ? messages.map((x) => new Message(this.session, x)) : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { GuildChannel } from "./GuildChannel.ts";
|
import { GuildChannel } from "./GuildChannel.ts";
|
||||||
import { Guild } from "./Guild.ts";
|
import { Guild } from "./Guild.ts";
|
||||||
import { DiscordChannel, Session, VideoQualityModes, Snowflake } from "../mod.ts";
|
import { DiscordChannel, Session, Snowflake, VideoQualityModes } from "../mod.ts";
|
||||||
|
|
||||||
export class VoiceChannel extends GuildChannel {
|
export class VoiceChannel extends GuildChannel {
|
||||||
constructor(session: Session, data: DiscordChannel, guild: Guild) {
|
constructor(session: Session, data: DiscordChannel, guild: Guild) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user