mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
refactor: remove (most) circular dependencies
This commit is contained in:
parent
ac77337a81
commit
8baae836cb
@ -29,3 +29,5 @@ export abstract class AnonymousGuild extends BaseGuild implements Model {
|
|||||||
|
|
||||||
// TODO: bannerUrl and splashUrl
|
// TODO: bannerUrl and splashUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default AnonymousGuild;
|
||||||
|
@ -34,3 +34,5 @@ export class Attachment implements Model {
|
|||||||
width?: number;
|
width?: number;
|
||||||
ephemeral: boolean;
|
ephemeral: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Attachment;
|
||||||
|
@ -37,3 +37,5 @@ export abstract class BaseGuild implements Model {
|
|||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default BaseGuild;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import type { Model } from "./Base.ts";
|
import type { Model } from "./Base.ts";
|
||||||
import { ChannelTypes, DiscordChannel, Session, Snowflake } from "../mod.ts";
|
import type { Snowflake } from "../util/Snowflake.ts";
|
||||||
|
import type { Session } from "../session/Session.ts";
|
||||||
|
import { ChannelTypes, DiscordChannel } 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) {
|
||||||
@ -17,3 +19,5 @@ export abstract class Channel implements Model {
|
|||||||
return `<#${this.id}>`;
|
return `<#${this.id}>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Channel;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
import type { Snowflake } from "../util/Snowflake.ts";
|
||||||
|
import type { Session } from "../session/Session.ts";
|
||||||
|
import type { DiscordChannel } from "../vendor/external.ts";
|
||||||
import { Channel } from "./Channel.ts";
|
import { Channel } from "./Channel.ts";
|
||||||
//import { User } from "./User.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) {
|
||||||
@ -17,6 +18,9 @@ export class DMChannel extends Channel {
|
|||||||
"DELETE",
|
"DELETE",
|
||||||
Routes.CHANNEL(this.id),
|
Routes.CHANNEL(this.id),
|
||||||
);
|
);
|
||||||
|
|
||||||
return new DMChannel(this.session, channel);
|
return new DMChannel(this.session, channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default DMChannel;
|
||||||
|
@ -16,3 +16,5 @@ export class Emoji {
|
|||||||
available: boolean;
|
available: boolean;
|
||||||
requireColons: boolean;
|
requireColons: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Emoji;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
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";
|
||||||
@ -26,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 {
|
||||||
constructor(session: Session, data: DiscordGuild) {
|
constructor(session: Session, data: DiscordGuild) {
|
||||||
super(session, data);
|
super(session, data);
|
||||||
|
|
||||||
@ -39,7 +38,7 @@ export class Guild extends BaseGuild implements Model {
|
|||||||
this.defaultMessageNotificationLevel = data.default_message_notifications;
|
this.defaultMessageNotificationLevel = data.default_message_notifications;
|
||||||
this.explicitContentFilterLevel = data.explicit_content_filter;
|
this.explicitContentFilterLevel = data.explicit_content_filter;
|
||||||
this.members = data.members?.map((member) => new Member(session, { ...member, user: member.user! })) ?? [];
|
this.members = data.members?.map((member) => new Member(session, { ...member, user: member.user! })) ?? [];
|
||||||
this.roles = data.roles.map((role) => new Role(session, data.id, role));
|
this.roles = data.roles.map((role) => new Role(session, role, data.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
splashHash?: bigint;
|
splashHash?: bigint;
|
||||||
@ -78,10 +77,12 @@ export class Guild extends BaseGuild implements Model {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
return new Role(this.session, this.id, role);
|
return new Role(this.session, role, this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteRole(roleId: Snowflake): Promise<void> {
|
async deleteRole(roleId: Snowflake): Promise<void> {
|
||||||
await this.session.rest.runMethod<undefined>(this.session.rest, "DELETE", Routes.GUILD_ROLE(this.id, roleId));
|
await this.session.rest.runMethod<undefined>(this.session.rest, "DELETE", Routes.GUILD_ROLE(this.id, roleId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Guild;
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
import type { Snowflake } from "../util/Snowflake.ts";
|
||||||
|
import type { Session } from "../session/Session.ts";
|
||||||
|
import type { DiscordChannel } from "../vendor/external.ts";
|
||||||
import { Channel } from "./Channel.ts";
|
import { Channel } from "./Channel.ts";
|
||||||
import { Guild } from "./Guild.ts";
|
import { Guild } from "./Guild.ts";
|
||||||
import { DiscordChannel, Routes, Session, Snowflake } from "../mod.ts";
|
import { Routes } from "../util/mod.ts";
|
||||||
|
|
||||||
export abstract class GuildChannel extends Channel {
|
export abstract class GuildChannel extends Channel {
|
||||||
constructor(session: Session, data: DiscordChannel, guildId: Guild["id"]) {
|
constructor(session: Session, data: DiscordChannel, guildId: Guild["id"]) {
|
||||||
@ -27,3 +30,5 @@ export abstract class GuildChannel extends Channel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default GuildChannel;
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
import { DiscordEmoji, Emoji, Session, Snowflake, User } from "../mod.ts";
|
import type { Snowflake } from "../util/Snowflake.ts";
|
||||||
|
import type { Session } from "../session/Session.ts";
|
||||||
|
import type { DiscordEmoji } from "../vendor/external.ts";
|
||||||
|
import { Emoji } from "./Emoji.ts";
|
||||||
|
import { User } from "./User.ts";
|
||||||
|
|
||||||
export class GuildEmoji extends Emoji {
|
export class GuildEmoji extends Emoji {
|
||||||
constructor(session: Session, data: DiscordEmoji, guildId: Snowflake) {
|
constructor(session: Session, data: DiscordEmoji, guildId: Snowflake) {
|
||||||
@ -13,3 +17,5 @@ export class GuildEmoji extends Emoji {
|
|||||||
user?: User;
|
user?: User;
|
||||||
managed?: boolean;
|
managed?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default GuildEmoji;
|
||||||
|
@ -113,3 +113,5 @@ export class Member implements Model {
|
|||||||
return `<@!${this.user.id}>`;
|
return `<@!${this.user.id}>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Member;
|
||||||
|
@ -145,7 +145,9 @@ export class Message implements Model {
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
inGuild(): this is { guildId: string } & Message {
|
inGuild(): this is { guildId: Snowflake } & Message {
|
||||||
return Boolean(this.guildId);
|
return !!this.guildId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Message;
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
import { DiscordChannel, Guild, Session, TextChannel } from "../mod.ts";
|
import type { Snowflake } from "../util/Snowflake.ts";
|
||||||
|
import type { Session } from "../session/Session.ts";
|
||||||
|
import type { DiscordChannel } from "../vendor/external.ts";
|
||||||
|
import { TextChannel } from "./TextChannel.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: Snowflake) {
|
||||||
super(session, data, guildId);
|
super(session, data, guildId);
|
||||||
this.defaultAutoArchiveDuration = data.default_auto_archive_duration;
|
this.defaultAutoArchiveDuration = data.default_auto_archive_duration;
|
||||||
}
|
}
|
||||||
defaultAutoArchiveDuration?: number;
|
defaultAutoArchiveDuration?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default NewsChannel;
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
import type { Model } from "./Base.ts";
|
import type { Model } from "./Base.ts";
|
||||||
import type { Session } from "../session/Session.ts";
|
|
||||||
import type { DiscordRole } from "../vendor/external.ts";
|
import type { DiscordRole } from "../vendor/external.ts";
|
||||||
import { Snowflake } from "../mod.ts";
|
import { Snowflake } from "../util/Snowflake.ts";
|
||||||
|
import { Session } from "../session/Session.ts";
|
||||||
import { iconHashToBigInt } from "../util/hash.ts";
|
import { iconHashToBigInt } from "../util/hash.ts";
|
||||||
import { Permissions } from "./Permissions.ts";
|
import { Permissions } from "./Permissions.ts";
|
||||||
import { Guild } from "./Guild.ts";
|
import { Guild } from "./Guild.ts";
|
||||||
|
|
||||||
export class Role implements Model {
|
export class Role implements Model {
|
||||||
constructor(session: Session, guildId: Snowflake, data: DiscordRole) {
|
constructor(session: Session, data: DiscordRole, guildId: Snowflake) {
|
||||||
this.session = session;
|
this.session = session;
|
||||||
this.id = data.id;
|
this.id = data.id;
|
||||||
this.guildId = guildId;
|
this.guildId = guildId;
|
||||||
@ -59,3 +59,5 @@ export class Role implements Model {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Role;
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
|
import type { Session } from "../session/Session.ts";
|
||||||
|
import type { Snowflake } from "../util/Snowflake.ts";
|
||||||
|
import type { GetMessagesOptions } from "../util/Routes.ts";
|
||||||
|
import type { DiscordChannel, DiscordInviteCreate, DiscordMessage } from "../vendor/external.ts";
|
||||||
import { GuildChannel } from "./GuildChannel.ts";
|
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 { DiscordChannel, DiscordInviteCreate, DiscordMessage, Routes, Session, Snowflake } from "../mod.ts";
|
import { Routes } from "../util/mod.ts";
|
||||||
import { GetMessagesOptions } from "../util/Routes.ts";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the options object to create an invitation
|
* Represents the options object to create an invitation
|
||||||
* @link https://discord.com/developers/docs/resources/channel#create-channel-invite-json-params
|
* @link https://discord.com/developers/docs/resources/channel#create-channel-invite-json-params
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export interface DiscordInviteOptions {
|
export interface DiscordInviteOptions {
|
||||||
max_age?: number;
|
max_age?: number;
|
||||||
max_uses?: number;
|
max_uses?: number;
|
||||||
@ -22,7 +24,6 @@ export interface DiscordInviteOptions {
|
|||||||
* Represent the options object to create a Thread Channel
|
* Represent the options object to create a Thread Channel
|
||||||
* @link https://discord.com/developers/docs/resources/channel#start-thread-without-message
|
* @link https://discord.com/developers/docs/resources/channel#start-thread-without-message
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export interface ThreadCreateOptions {
|
export interface ThreadCreateOptions {
|
||||||
name: string;
|
name: string;
|
||||||
autoArchiveDuration: 60 | 1440 | 4320 | 10080;
|
autoArchiveDuration: 60 | 1440 | 4320 | 10080;
|
||||||
@ -83,11 +84,13 @@ export class TextChannel extends GuildChannel {
|
|||||||
return messages[0] ? messages.map((x) => new Message(this.session, x)) : [];
|
return messages[0] ? messages.map((x) => new Message(this.session, x)) : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
sendTyping() {
|
async sendTyping() {
|
||||||
this.session.rest.runMethod<undefined>(
|
await this.session.rest.runMethod<undefined>(
|
||||||
this.session.rest,
|
this.session.rest,
|
||||||
"POST",
|
"POST",
|
||||||
Routes.CHANNEL_TYPING(this.id),
|
Routes.CHANNEL_TYPING(this.id),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default TextChannel;
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
|
import type { Snowflake } from "../util/Snowflake.ts";
|
||||||
|
import type { Session } from "../session/Session.ts";
|
||||||
|
import type { DiscordChannel } from "../vendor/external.ts";
|
||||||
import { GuildChannel } from "./GuildChannel.ts";
|
import { GuildChannel } from "./GuildChannel.ts";
|
||||||
import { Guild } from "./Guild.ts";
|
|
||||||
import { DiscordChannel, Session, Snowflake } from "../mod.ts";
|
|
||||||
|
|
||||||
export class ThreadChannel extends GuildChannel {
|
export class ThreadChannel extends GuildChannel {
|
||||||
constructor(session: Session, data: DiscordChannel, guildId: Guild["id"]) {
|
constructor(session: Session, data: DiscordChannel, guildId: Snowflake) {
|
||||||
super(session, data, guildId);
|
super(session, data, guildId);
|
||||||
this.archived = !!data.thread_metadata?.archived;
|
this.archived = !!data.thread_metadata?.archived;
|
||||||
this.archiveTimestamp = data.thread_metadata?.archive_timestamp;
|
this.archiveTimestamp = data.thread_metadata?.archive_timestamp;
|
||||||
@ -21,3 +22,5 @@ export class ThreadChannel extends GuildChannel {
|
|||||||
memberCount?: number;
|
memberCount?: number;
|
||||||
ownerId?: Snowflake;
|
ownerId?: Snowflake;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default ThreadChannel;
|
||||||
|
@ -57,3 +57,5 @@ export class User implements Model {
|
|||||||
return `<@${this.id}>`;
|
return `<@${this.id}>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default User;
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
|
import type { Snowflake } from "../util/Snowflake.ts";
|
||||||
|
import type { Session } from "../session/Session.ts";
|
||||||
|
import type { DiscordChannel, VideoQualityModes } from "../vendor/external.ts";
|
||||||
import { GuildChannel } from "./GuildChannel.ts";
|
import { GuildChannel } from "./GuildChannel.ts";
|
||||||
import { Guild } from "./Guild.ts";
|
|
||||||
import { DiscordChannel, Session, Snowflake, VideoQualityModes } from "../mod.ts";
|
|
||||||
|
|
||||||
export class VoiceChannel extends GuildChannel {
|
export class VoiceChannel extends GuildChannel {
|
||||||
constructor(session: Session, data: DiscordChannel, guildId: Guild["id"]) {
|
constructor(session: Session, guildId: Snowflake, data: DiscordChannel) {
|
||||||
super(session, data, guildId);
|
super(session, data, guildId);
|
||||||
this.bitRate = data.bitrate;
|
this.bitRate = data.bitrate;
|
||||||
this.userLimit = data.user_limit ?? 0;
|
this.userLimit = data.user_limit ?? 0;
|
||||||
@ -16,5 +17,7 @@ export class VoiceChannel extends GuildChannel {
|
|||||||
rtcRegion?: Snowflake;
|
rtcRegion?: Snowflake;
|
||||||
|
|
||||||
videoQuality?: VideoQualityModes;
|
videoQuality?: VideoQualityModes;
|
||||||
nsfw?: boolean;
|
nsfw: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default VoiceChannel;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user