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
|
||||
}
|
||||
|
||||
export default AnonymousGuild;
|
||||
|
@ -34,3 +34,5 @@ export class Attachment implements Model {
|
||||
width?: number;
|
||||
ephemeral: boolean;
|
||||
}
|
||||
|
||||
export default Attachment;
|
||||
|
@ -37,3 +37,5 @@ export abstract class BaseGuild implements Model {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
||||
export default BaseGuild;
|
||||
|
@ -1,5 +1,7 @@
|
||||
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 {
|
||||
constructor(session: Session, data: DiscordChannel) {
|
||||
@ -17,3 +19,5 @@ export abstract class Channel implements Model {
|
||||
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 { User } from "./User.ts";
|
||||
import { DiscordChannel, Routes, Session, Snowflake } from "../mod.ts";
|
||||
|
||||
export class DMChannel extends Channel {
|
||||
constructor(session: Session, data: DiscordChannel) {
|
||||
@ -17,6 +18,9 @@ export class DMChannel extends Channel {
|
||||
"DELETE",
|
||||
Routes.CHANNEL(this.id),
|
||||
);
|
||||
|
||||
return new DMChannel(this.session, channel);
|
||||
}
|
||||
}
|
||||
|
||||
export default DMChannel;
|
||||
|
@ -16,3 +16,5 @@ export class Emoji {
|
||||
available: 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 { Session } from "../session/Session.ts";
|
||||
import type { DiscordGuild, DiscordRole } from "../vendor/external.ts";
|
||||
@ -26,7 +25,7 @@ export interface CreateRole {
|
||||
* Represents a guild
|
||||
* @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) {
|
||||
super(session, data);
|
||||
|
||||
@ -39,7 +38,7 @@ export class Guild extends BaseGuild implements Model {
|
||||
this.defaultMessageNotificationLevel = data.default_message_notifications;
|
||||
this.explicitContentFilterLevel = data.explicit_content_filter;
|
||||
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;
|
||||
@ -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> {
|
||||
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 { Guild } from "./Guild.ts";
|
||||
import { DiscordChannel, Routes, Session, Snowflake } from "../mod.ts";
|
||||
import { Routes } from "../util/mod.ts";
|
||||
|
||||
export abstract class GuildChannel extends Channel {
|
||||
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 {
|
||||
constructor(session: Session, data: DiscordEmoji, guildId: Snowflake) {
|
||||
@ -13,3 +17,5 @@ export class GuildEmoji extends Emoji {
|
||||
user?: User;
|
||||
managed?: boolean;
|
||||
}
|
||||
|
||||
export default GuildEmoji;
|
||||
|
@ -113,3 +113,5 @@ export class Member implements Model {
|
||||
return `<@!${this.user.id}>`;
|
||||
}
|
||||
}
|
||||
|
||||
export default Member;
|
||||
|
@ -145,7 +145,9 @@ export class Message implements Model {
|
||||
return message;
|
||||
}
|
||||
|
||||
inGuild(): this is { guildId: string } & Message {
|
||||
return Boolean(this.guildId);
|
||||
inGuild(): this is { guildId: Snowflake } & Message {
|
||||
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 {
|
||||
constructor(session: Session, data: DiscordChannel, guildId: Guild["id"]) {
|
||||
constructor(session: Session, data: DiscordChannel, guildId: Snowflake) {
|
||||
super(session, data, guildId);
|
||||
this.defaultAutoArchiveDuration = data.default_auto_archive_duration;
|
||||
}
|
||||
defaultAutoArchiveDuration?: number;
|
||||
}
|
||||
|
||||
export default NewsChannel;
|
||||
|
@ -1,13 +1,13 @@
|
||||
import type { Model } from "./Base.ts";
|
||||
import type { Session } from "../session/Session.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 { Permissions } from "./Permissions.ts";
|
||||
import { Guild } from "./Guild.ts";
|
||||
|
||||
export class Role implements Model {
|
||||
constructor(session: Session, guildId: Snowflake, data: DiscordRole) {
|
||||
constructor(session: Session, data: DiscordRole, guildId: Snowflake) {
|
||||
this.session = session;
|
||||
this.id = data.id;
|
||||
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 { Guild } from "./Guild.ts";
|
||||
import { ThreadChannel } from "./ThreadChannel.ts";
|
||||
import { Message } from "./Message.ts";
|
||||
import { DiscordChannel, DiscordInviteCreate, DiscordMessage, Routes, Session, Snowflake } from "../mod.ts";
|
||||
import { GetMessagesOptions } from "../util/Routes.ts";
|
||||
import { Routes } from "../util/mod.ts";
|
||||
|
||||
/**
|
||||
* Represents the options object to create an invitation
|
||||
* @link https://discord.com/developers/docs/resources/channel#create-channel-invite-json-params
|
||||
*/
|
||||
|
||||
export interface DiscordInviteOptions {
|
||||
max_age?: number;
|
||||
max_uses?: number;
|
||||
@ -22,7 +24,6 @@ export interface DiscordInviteOptions {
|
||||
* Represent the options object to create a Thread Channel
|
||||
* @link https://discord.com/developers/docs/resources/channel#start-thread-without-message
|
||||
*/
|
||||
|
||||
export interface ThreadCreateOptions {
|
||||
name: string;
|
||||
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)) : [];
|
||||
}
|
||||
|
||||
sendTyping() {
|
||||
this.session.rest.runMethod<undefined>(
|
||||
async sendTyping() {
|
||||
await this.session.rest.runMethod<undefined>(
|
||||
this.session.rest,
|
||||
"POST",
|
||||
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 { Guild } from "./Guild.ts";
|
||||
import { DiscordChannel, Session, Snowflake } from "../mod.ts";
|
||||
|
||||
export class ThreadChannel extends GuildChannel {
|
||||
constructor(session: Session, data: DiscordChannel, guildId: Guild["id"]) {
|
||||
constructor(session: Session, data: DiscordChannel, guildId: Snowflake) {
|
||||
super(session, data, guildId);
|
||||
this.archived = !!data.thread_metadata?.archived;
|
||||
this.archiveTimestamp = data.thread_metadata?.archive_timestamp;
|
||||
@ -21,3 +22,5 @@ export class ThreadChannel extends GuildChannel {
|
||||
memberCount?: number;
|
||||
ownerId?: Snowflake;
|
||||
}
|
||||
|
||||
export default ThreadChannel;
|
||||
|
@ -57,3 +57,5 @@ export class User implements Model {
|
||||
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 { Guild } from "./Guild.ts";
|
||||
import { DiscordChannel, Session, Snowflake, VideoQualityModes } from "../mod.ts";
|
||||
|
||||
export class VoiceChannel extends GuildChannel {
|
||||
constructor(session: Session, data: DiscordChannel, guildId: Guild["id"]) {
|
||||
constructor(session: Session, guildId: Snowflake, data: DiscordChannel) {
|
||||
super(session, data, guildId);
|
||||
this.bitRate = data.bitrate;
|
||||
this.userLimit = data.user_limit ?? 0;
|
||||
@ -16,5 +17,7 @@ export class VoiceChannel extends GuildChannel {
|
||||
rtcRegion?: Snowflake;
|
||||
|
||||
videoQuality?: VideoQualityModes;
|
||||
nsfw?: boolean;
|
||||
nsfw: boolean;
|
||||
}
|
||||
|
||||
export default VoiceChannel;
|
||||
|
Loading…
x
Reference in New Issue
Block a user