mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-04 22:16:08 +00:00
refactor: separate api types (#71)
* refactor: better api types boundaries * fix: fmt
This commit is contained in:
parent
aff4bf2e92
commit
47d20cb6e0
2
mod.ts
2
mod.ts
@ -5,4 +5,6 @@ export default Session;
|
|||||||
export * from './packages/biscuit/mod.ts';
|
export * from './packages/biscuit/mod.ts';
|
||||||
export * from './packages/discordeno/mod.ts';
|
export * from './packages/discordeno/mod.ts';
|
||||||
export * from './packages/cache/mod.ts';
|
export * from './packages/cache/mod.ts';
|
||||||
|
export * from './packages/api-types/discord.ts';
|
||||||
|
export * from './packages/api-types/shared.ts';
|
||||||
export { default as enableCache } from './packages/cache/mod.ts';
|
export { default as enableCache } from './packages/cache/mod.ts';
|
||||||
|
@ -426,19 +426,19 @@ export function GUILD_STICKERS(guildId: Snowflake, stickerId?: Snowflake): strin
|
|||||||
return `/guilds/${guildId}/stickers`;
|
return `/guilds/${guildId}/stickers`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the widget for the guild.
|
* Return the widget for the guild.
|
||||||
* @link https://discord.com/developers/docs/resources/guild#get-guild-widget-settings
|
* @link https://discord.com/developers/docs/resources/guild#get-guild-widget-settings
|
||||||
*/
|
*/
|
||||||
export interface GetWidget {
|
export interface GetWidget {
|
||||||
get: 'json' | 'image' | 'settings';
|
get: 'json' | 'image' | 'settings';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* /guilds/{guildId}/widget
|
* /guilds/{guildId}/widget
|
||||||
* @link https://discord.com/developers/docs/resources/guild#get-guild-widget-settings
|
* @link https://discord.com/developers/docs/resources/guild#get-guild-widget-settings
|
||||||
*/
|
*/
|
||||||
export function GUILD_WIDGET(guildId: Snowflake, options: GetWidget = {get: 'settings'}): string {
|
export function GUILD_WIDGET(guildId: Snowflake, options: GetWidget = { get: 'settings' }): string {
|
||||||
let url = `/guilds/${guildId}/widget`;
|
let url = `/guilds/${guildId}/widget`;
|
||||||
if (options.get === 'json') {
|
if (options.get === 'json') {
|
||||||
url += '.json';
|
url += '.json';
|
||||||
@ -446,5 +446,5 @@ export function GUILD_WIDGET(guildId: Snowflake, options: GetWidget = {get: 'set
|
|||||||
url += '.png';
|
url += '.png';
|
||||||
}
|
}
|
||||||
|
|
||||||
return url
|
return url;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ import ThreadMember from './ThreadMember.ts';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class that represents the base for creating a new channel.
|
* Abstract class that represents the base for creating a new channel.
|
||||||
*/
|
*/
|
||||||
export abstract class BaseChannel implements Model {
|
export abstract class BaseChannel implements Model {
|
||||||
constructor(session: Session, data: DiscordChannel) {
|
constructor(session: Session, data: DiscordChannel) {
|
||||||
this.id = data.id;
|
this.id = data.id;
|
||||||
@ -93,7 +93,7 @@ export abstract class BaseChannel implements Model {
|
|||||||
/**
|
/**
|
||||||
* @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
|
||||||
* Represents the options object to create an invitation
|
* Represents the options object to create an invitation
|
||||||
*/
|
*/
|
||||||
export interface DiscordInviteOptions {
|
export interface DiscordInviteOptions {
|
||||||
/** duration of invite in seconds before expiry, or 0 for never. between 0 and 604800 (7 days) */
|
/** duration of invite in seconds before expiry, or 0 for never. between 0 and 604800 (7 days) */
|
||||||
maxAge?: number;
|
maxAge?: number;
|
||||||
@ -122,7 +122,7 @@ export interface CreateWebhook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Available text-channel-types list */
|
/** Available text-channel-types list */
|
||||||
export const textBasedChannels:ChannelTypes[] = [
|
export const textBasedChannels: ChannelTypes[] = [
|
||||||
ChannelTypes.DM,
|
ChannelTypes.DM,
|
||||||
ChannelTypes.GroupDm,
|
ChannelTypes.GroupDm,
|
||||||
ChannelTypes.GuildPrivateThread,
|
ChannelTypes.GuildPrivateThread,
|
||||||
@ -208,7 +208,7 @@ export class TextChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fetchPins makes an asynchronous request and gets the current channel pins.
|
* fetchPins makes an asynchronous request and gets the current channel pins.
|
||||||
* @returns A promise that resolves with an array of Message objects.
|
* @returns A promise that resolves with an array of Message objects.
|
||||||
*/
|
*/
|
||||||
@ -221,7 +221,7 @@ export class TextChannel {
|
|||||||
return messages[0] ? messages.map((x: DiscordMessage) => new Message(this.session, x)) : [];
|
return messages[0] ? messages.map((x: DiscordMessage) => new Message(this.session, x)) : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* createInvite makes an asynchronous request to create a new invitation.
|
* createInvite makes an asynchronous request to create a new invitation.
|
||||||
* @param options - The options to create the invitation
|
* @param options - The options to create the invitation
|
||||||
* @returns The created invite
|
* @returns The created invite
|
||||||
@ -247,10 +247,10 @@ export class TextChannel {
|
|||||||
return new Invite(this.session, invite);
|
return new Invite(this.session, invite);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fetchMessages makes an asynchronous request and gets the channel messages
|
* fetchMessages makes an asynchronous request and gets the channel messages
|
||||||
* @param options - The options to get the messages
|
* @param options - The options to get the messages
|
||||||
* @returns The messages
|
* @returns The messages
|
||||||
*/
|
*/
|
||||||
async fetchMessages(options?: Routes.GetMessagesOptions): Promise<Message[] | []> {
|
async fetchMessages(options?: Routes.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');
|
||||||
@ -271,7 +271,7 @@ export class TextChannel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pinMessage pins a channel message.
|
* pinMessage pins a channel message.
|
||||||
* Same as Message.pin().
|
* Same as Message.pin().
|
||||||
* @param messageId - The id of the message to pin
|
* @param messageId - The id of the message to pin
|
||||||
@ -281,7 +281,7 @@ export class TextChannel {
|
|||||||
await Message.prototype.pin.call({ id: messageId, channelId: this.id, session: this.session });
|
await Message.prototype.pin.call({ id: messageId, channelId: this.id, session: this.session });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unpinMessage unpin a channel message.
|
* unpinMessage unpin a channel message.
|
||||||
* Same as Message.unpin()
|
* Same as Message.unpin()
|
||||||
* @param messageId - The id of the message to unpin
|
* @param messageId - The id of the message to unpin
|
||||||
@ -291,7 +291,7 @@ export class TextChannel {
|
|||||||
await Message.prototype.unpin.call({ id: messageId, channelId: this.id, session: this.session });
|
await Message.prototype.unpin.call({ id: messageId, channelId: this.id, session: this.session });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* addReaction adds a reaction to the message.
|
* addReaction adds a reaction to the message.
|
||||||
* Same as Message.addReaction().
|
* Same as Message.addReaction().
|
||||||
* @param messageId - The message to add the reaction to
|
* @param messageId - The message to add the reaction to
|
||||||
@ -305,7 +305,7 @@ export class TextChannel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removeReaction removes a reaction from the message.
|
* removeReaction removes a reaction from the message.
|
||||||
* Same as Message.removeReaction().
|
* Same as Message.removeReaction().
|
||||||
* @param messageId - The id of the message to remove the reaction from
|
* @param messageId - The id of the message to remove the reaction from
|
||||||
@ -324,7 +324,7 @@ export class TextChannel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removeReactionEmoji removes an emoji reaction from the messageId provided.
|
* removeReactionEmoji removes an emoji reaction from the messageId provided.
|
||||||
* Same as Message.removeReactionEmoji().
|
* Same as Message.removeReactionEmoji().
|
||||||
* @param messageId - The message id to remove the reaction from.
|
* @param messageId - The message id to remove the reaction from.
|
||||||
@ -347,7 +347,7 @@ export class TextChannel {
|
|||||||
await Message.prototype.nukeReactions.call({ channelId: this.id, id: messageId });
|
await Message.prototype.nukeReactions.call({ channelId: this.id, id: messageId });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fetchReactions gets the users who reacted with this emoji on the message.
|
* fetchReactions gets the users who reacted with this emoji on the message.
|
||||||
* Same as Message.fetchReactions().
|
* Same as Message.fetchReactions().
|
||||||
* @param messageId - The message id to get the reactions from.
|
* @param messageId - The message id to get the reactions from.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { DiscordGatewayPayload } from '../../types/discord.ts';
|
import { DiscordGatewayPayload } from '../../../api-types/discord.ts';
|
||||||
import { GatewayBot, PickPartial } from '../../types/shared.ts';
|
import { GatewayBot, PickPartial } from '../../../api-types/shared.ts';
|
||||||
import { LeakyBucket } from '../../util/bucket.ts';
|
import { LeakyBucket } from '../../util/bucket.ts';
|
||||||
import { CreateShard, createShard } from '../shard/createShard.ts';
|
import { CreateShard, createShard } from '../shard/createShard.ts';
|
||||||
import { Shard, ShardGatewayConfig } from '../shard/types.ts';
|
import { Shard, ShardGatewayConfig } from '../shard/types.ts';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { DiscordGatewayPayload } from '../../types/discord.ts';
|
import { DiscordGatewayPayload } from '../../../api-types/discord.ts';
|
||||||
import { PickPartial } from '../../types/shared.ts';
|
import { PickPartial } from '../../../api-types/shared.ts';
|
||||||
import { CreateShard, createShard } from '../shard/createShard.ts';
|
import { CreateShard, createShard } from '../shard/createShard.ts';
|
||||||
import { Shard, ShardGatewayConfig } from '../shard/types.ts';
|
import { Shard, ShardGatewayConfig } from '../shard/types.ts';
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { GatewayIntents } from '../../types/shared.ts';
|
import { GatewayIntents } from '../../../api-types/shared.ts';
|
||||||
import { createLeakyBucket } from '../../util/bucket.ts';
|
import { createLeakyBucket } from '../../util/bucket.ts';
|
||||||
import { createShard } from '../shard/createShard.ts';
|
import { createShard } from '../shard/createShard.ts';
|
||||||
import { Shard } from '../shard/types.ts';
|
import { Shard } from '../shard/types.ts';
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { GatewayIntents } from '../../types/shared.ts';
|
import { GatewayIntents } from '../../../api-types/shared.ts';
|
||||||
import { createShard } from '../shard/createShard.ts';
|
import { createShard } from '../shard/createShard.ts';
|
||||||
import { GatewayManager } from './gatewayManager.ts';
|
import { GatewayManager } from './gatewayManager.ts';
|
||||||
|
|
||||||
|
@ -23,8 +23,8 @@ import { connect } from './connect.ts';
|
|||||||
import { close } from './close.ts';
|
import { close } from './close.ts';
|
||||||
import { shutdown } from './shutdown.ts';
|
import { shutdown } from './shutdown.ts';
|
||||||
import { isOpen } from './isOpen.ts';
|
import { isOpen } from './isOpen.ts';
|
||||||
import { DiscordGatewayPayload, DiscordStatusUpdate } from '../../types/discord.ts';
|
import { DiscordGatewayPayload, DiscordStatusUpdate } from '../../../api-types/discord.ts';
|
||||||
import { GatewayIntents, PickPartial } from '../../types/shared.ts';
|
import { GatewayIntents, PickPartial } from '../../../api-types/shared.ts';
|
||||||
import { API_VERSION } from '../../util/constants.ts';
|
import { API_VERSION } from '../../util/constants.ts';
|
||||||
|
|
||||||
// TODO: debug
|
// TODO: debug
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { GatewayCloseEventCodes } from '../../types/shared.ts';
|
import { GatewayCloseEventCodes } from '../../../api-types/shared.ts';
|
||||||
import { Shard, ShardSocketCloseCodes, ShardState } from './types.ts';
|
import { Shard, ShardSocketCloseCodes, ShardState } from './types.ts';
|
||||||
|
|
||||||
export async function handleClose(shard: Shard, close: CloseEvent): Promise<void> {
|
export async function handleClose(shard: Shard, close: CloseEvent): Promise<void> {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { DiscordGatewayPayload, DiscordHello, DiscordReady } from '../../types/discord.ts';
|
import { DiscordGatewayPayload, DiscordHello, DiscordReady } from '../../../api-types/discord.ts';
|
||||||
import { GatewayOpcodes } from '../../types/shared.ts';
|
import { GatewayOpcodes } from '../../../api-types/shared.ts';
|
||||||
import { createLeakyBucket } from '../../util/bucket.ts';
|
import { createLeakyBucket } from '../../util/bucket.ts';
|
||||||
import { delay } from '../../util/delay.ts';
|
import { delay } from '../../util/delay.ts';
|
||||||
import { decompressWith } from './deps.ts';
|
import { decompressWith } from './deps.ts';
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { GatewayOpcodes } from '../../types/shared.ts';
|
import { GatewayOpcodes } from '../../../api-types/shared.ts';
|
||||||
import { Shard, ShardSocketCloseCodes, ShardState } from './types.ts';
|
import { Shard, ShardSocketCloseCodes, ShardState } from './types.ts';
|
||||||
|
|
||||||
export async function identify(shard: Shard): Promise<void> {
|
export async function identify(shard: Shard): Promise<void> {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { GatewayOpcodes } from '../../types/shared.ts';
|
import { GatewayOpcodes } from '../../../api-types/shared.ts';
|
||||||
import { Shard, ShardSocketCloseCodes, ShardState } from './types.ts';
|
import { Shard, ShardSocketCloseCodes, ShardState } from './types.ts';
|
||||||
|
|
||||||
export async function resume(shard: Shard): Promise<void> {
|
export async function resume(shard: Shard): Promise<void> {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { GatewayOpcodes } from '../../types/shared.ts';
|
import { GatewayOpcodes } from '../../../api-types/shared.ts';
|
||||||
import { Shard, ShardSocketCloseCodes, ShardState } from './types.ts';
|
import { Shard, ShardSocketCloseCodes, ShardState } from './types.ts';
|
||||||
|
|
||||||
export function startHeartbeating(shard: Shard, interval: number) {
|
export function startHeartbeating(shard: Shard, interval: number) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { DiscordGatewayPayload } from '../../types/discord.ts';
|
import { DiscordGatewayPayload } from '../../../api-types/discord.ts';
|
||||||
import { GatewayOpcodes } from '../../types/shared.ts';
|
import { GatewayOpcodes } from '../../../api-types/shared.ts';
|
||||||
import { createShard } from './createShard.ts';
|
import { createShard } from './createShard.ts';
|
||||||
|
|
||||||
// TODO: think whether we also need an identifiedShard function
|
// TODO: think whether we also need an identifiedShard function
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
export * from './gateway/mod.ts';
|
export * from './gateway/mod.ts';
|
||||||
export * from './rest/mod.ts';
|
export * from './rest/mod.ts';
|
||||||
export * from './types/mod.ts';
|
|
||||||
export * from './util/constants.ts';
|
export * from './util/constants.ts';
|
||||||
export * from './util/token.ts';
|
export * from './util/token.ts';
|
||||||
|
export * from '../api-types/discord.ts';
|
||||||
|
export * from '../api-types/shared.ts';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { RestManager } from './restManager.ts';
|
import { RestManager } from './restManager.ts';
|
||||||
import { FileContent } from '../types/shared.ts';
|
import { FileContent } from '../../api-types/shared.ts';
|
||||||
import { USER_AGENT } from '../util/constants.ts';
|
import { USER_AGENT } from '../util/constants.ts';
|
||||||
import { RequestMethod, RestPayload, RestRequest } from './rest.ts';
|
import { RequestMethod, RestPayload, RestRequest } from './rest.ts';
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { RestManager } from './restManager.ts';
|
import { RestManager } from './restManager.ts';
|
||||||
import { HTTPResponseCodes } from '../types/shared.ts';
|
import { HTTPResponseCodes } from '../../api-types/shared.ts';
|
||||||
|
|
||||||
export async function processGlobalQueue(rest: RestManager) {
|
export async function processGlobalQueue(rest: RestManager) {
|
||||||
// IF QUEUE IS EMPTY EXIT
|
// IF QUEUE IS EMPTY EXIT
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { HTTPResponseCodes } from '../types/shared.ts';
|
import { HTTPResponseCodes } from '../../api-types/shared.ts';
|
||||||
import { BASE_URL } from '../util/constants.ts';
|
import { BASE_URL } from '../util/constants.ts';
|
||||||
import { RequestMethod } from './rest.ts';
|
import { RequestMethod } from './rest.ts';
|
||||||
import { RestManager } from './restManager.ts';
|
import { RestManager } from './restManager.ts';
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
export * from './discord.ts';
|
|
||||||
export * from './shared.ts';
|
|
@ -1,4 +1,4 @@
|
|||||||
import { PickPartial } from '../types/shared.ts';
|
import { PickPartial } from '../../api-types/shared.ts';
|
||||||
import { delay } from './delay.ts';
|
import { delay } from './delay.ts';
|
||||||
|
|
||||||
/** A Leaky Bucket.
|
/** A Leaky Bucket.
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
export * from './bucket.ts';
|
|
||||||
export * from './collection.ts';
|
|
||||||
export * from './constants.ts';
|
|
||||||
export * from './delay.ts';
|
|
||||||
export * from './token.ts';
|
|
Loading…
x
Reference in New Issue
Block a user