refactor: centralize types (#235)

* Centralize types and structures

* Resolve Conflict

* Update cache.ts
This commit is contained in:
ITOH
2020-12-08 19:23:36 +01:00
committed by GitHub
parent bc73aeb632
commit 7bdbcb76d6
33 changed files with 133 additions and 105 deletions
+1 -2
View File
@@ -1,6 +1,5 @@
import { eventHandlers } from "../module/client.ts"; import { eventHandlers } from "../module/client.ts";
import { DiscordPayload } from "../types/discord.ts"; import { DiscordPayload, GuildBanPayload } from "../types/types.ts";
import { GuildBanPayload } from "../types/guild.ts";
import { cacheHandlers } from "./cache.ts"; import { cacheHandlers } from "./cache.ts";
export async function handleInternalGuildBanAdd(data: DiscordPayload) { export async function handleInternalGuildBanAdd(data: DiscordPayload) {
+2 -5
View File
@@ -1,8 +1,5 @@
import { Channel } from "../structures/channel.ts"; import { Channel, Guild, Member, Message } from "../structures/structures.ts";
import { Guild } from "../structures/guild.ts"; import { PresenceUpdatePayload } from "../types/types.ts";
import { Member } from "../structures/member.ts";
import { Message } from "../structures/message.ts";
import { PresenceUpdatePayload } from "../types/discord.ts";
import { cache } from "../utils/cache.ts"; import { cache } from "../utils/cache.ts";
import { Collection } from "../utils/collection.ts"; import { Collection } from "../utils/collection.ts";
+6 -3
View File
@@ -1,7 +1,10 @@
import { eventHandlers } from "../module/client.ts"; import { eventHandlers } from "../module/client.ts";
import { structures } from "../structures/mod.ts"; import { structures } from "../structures/structures.ts";
import { ChannelCreatePayload, ChannelTypes } from "../types/channel.ts"; import {
import { DiscordPayload } from "../types/discord.ts"; ChannelCreatePayload,
ChannelTypes,
DiscordPayload,
} from "../types/types.ts";
import { cacheHandlers } from "./cache.ts"; import { cacheHandlers } from "./cache.ts";
export async function handleInternalChannelCreate(data: DiscordPayload) { export async function handleInternalChannelCreate(data: DiscordPayload) {
+4 -4
View File
@@ -1,13 +1,13 @@
import { eventHandlers } from "../module/client.ts"; import { eventHandlers } from "../module/client.ts";
import { structures } from "../structures/mod.ts"; import { structures } from "../structures/structures.ts";
import { DiscordPayload } from "../types/discord.ts";
import { import {
CreateGuildPayload, CreateGuildPayload,
DiscordPayload,
GuildDeletePayload, GuildDeletePayload,
GuildEmojisUpdatePayload, GuildEmojisUpdatePayload,
GuildUpdateChange,
UpdateGuildPayload, UpdateGuildPayload,
} from "../types/guild.ts"; } from "../types/types.ts";
import { GuildUpdateChange } from "../types/options.ts";
import { cache } from "../utils/cache.ts"; import { cache } from "../utils/cache.ts";
import { cacheHandlers } from "./cache.ts"; import { cacheHandlers } from "./cache.ts";
+3 -3
View File
@@ -1,12 +1,12 @@
import { eventHandlers } from "../module/client.ts"; import { eventHandlers } from "../module/client.ts";
import { structures } from "../structures/mod.ts"; import { structures } from "../structures/structures.ts";
import { DiscordPayload } from "../types/discord.ts";
import { import {
DiscordPayload,
GuildBanPayload, GuildBanPayload,
GuildMemberAddPayload, GuildMemberAddPayload,
GuildMemberChunkPayload, GuildMemberChunkPayload,
GuildMemberUpdatePayload, GuildMemberUpdatePayload,
} from "../types/guild.ts"; } from "../types/types.ts";
import { cache } from "../utils/cache.ts"; import { cache } from "../utils/cache.ts";
import { cacheHandlers } from "./cache.ts"; import { cacheHandlers } from "./cache.ts";
+3 -3
View File
@@ -1,11 +1,11 @@
import { eventHandlers } from "../module/client.ts"; import { eventHandlers } from "../module/client.ts";
import { structures } from "../structures/mod.ts"; import { structures } from "../structures/structures.ts";
import { DiscordPayload } from "../types/discord.ts";
import { import {
DiscordPayload,
MessageCreateOptions, MessageCreateOptions,
MessageDeleteBulkPayload, MessageDeleteBulkPayload,
MessageDeletePayload, MessageDeletePayload,
} from "../types/message.ts"; } from "../types/types.ts";
import { cacheHandlers } from "./cache.ts"; import { cacheHandlers } from "./cache.ts";
export async function handleInternalMessageCreate(data: DiscordPayload) { export async function handleInternalMessageCreate(data: DiscordPayload) {
+3 -3
View File
@@ -2,16 +2,16 @@ import { delay } from "../../deps.ts";
import { initialMemberLoadQueue } from "../../mod.ts"; import { initialMemberLoadQueue } from "../../mod.ts";
import { eventHandlers, setBotID } from "../module/client.ts"; import { eventHandlers, setBotID } from "../module/client.ts";
import { allowNextShard } from "../module/shardingManager.ts"; import { allowNextShard } from "../module/shardingManager.ts";
import { structures } from "../structures/mod.ts"; import { structures } from "../structures/structures.ts";
import { import {
DiscordPayload, DiscordPayload,
PresenceUpdatePayload, PresenceUpdatePayload,
ReadyPayload, ReadyPayload,
TypingStartPayload, TypingStartPayload,
UserPayload,
VoiceStateUpdatePayload, VoiceStateUpdatePayload,
WebhookUpdatePayload, WebhookUpdatePayload,
} from "../types/discord.ts"; } from "../types/types.ts";
import { UserPayload } from "../types/guild.ts";
import { cache } from "../utils/cache.ts"; import { cache } from "../utils/cache.ts";
import { cacheHandlers } from "./cache.ts"; import { cacheHandlers } from "./cache.ts";
+3 -3
View File
@@ -1,11 +1,11 @@
import { botID, eventHandlers } from "../module/client.ts"; import { botID, eventHandlers } from "../module/client.ts";
import { structures } from "../structures/mod.ts"; import { structures } from "../structures/structures.ts";
import { DiscordPayload } from "../types/discord.ts";
import { import {
BaseMessageReactionPayload, BaseMessageReactionPayload,
DiscordPayload,
MessageReactionPayload, MessageReactionPayload,
MessageReactionRemoveEmojiPayload, MessageReactionRemoveEmojiPayload,
} from "../types/message.ts"; } from "../types/types.ts";
import { cacheHandlers } from "./cache.ts"; import { cacheHandlers } from "./cache.ts";
export async function handleInternalMessageReactionAdd(data: DiscordPayload) { export async function handleInternalMessageReactionAdd(data: DiscordPayload) {
+6 -3
View File
@@ -1,7 +1,10 @@
import { eventHandlers } from "../module/client.ts"; import { eventHandlers } from "../module/client.ts";
import { structures } from "../structures/mod.ts"; import { structures } from "../structures/structures.ts";
import { DiscordPayload } from "../types/discord.ts"; import {
import { GuildRoleDeletePayload, GuildRolePayload } from "../types/guild.ts"; DiscordPayload,
GuildRoleDeletePayload,
GuildRolePayload,
} from "../types/types.ts";
import { cacheHandlers } from "./cache.ts"; import { cacheHandlers } from "./cache.ts";
export async function handleInternalGuildRoleCreate(data: DiscordPayload) { export async function handleInternalGuildRoleCreate(data: DiscordPayload) {
+8 -7
View File
@@ -1,22 +1,23 @@
import { cacheHandlers } from "../controllers/cache.ts"; import { cacheHandlers } from "../controllers/cache.ts";
import { RequestManager } from "../module/requestManager.ts"; import { RequestManager } from "../module/requestManager.ts";
import { structures } from "../structures/mod.ts"; import { structures } from "../structures/structures.ts";
import { import {
ChannelEditOptions, ChannelEditOptions,
ChannelTypes, ChannelTypes,
CreateInviteOptions, CreateInviteOptions,
Errors,
FollowedChannelPayload, FollowedChannelPayload,
GetMessages, GetMessages,
GetMessagesAfter, GetMessagesAfter,
GetMessagesAround, GetMessagesAround,
GetMessagesBefore, GetMessagesBefore,
MessageContent, MessageContent,
} from "../types/channel.ts"; MessageCreateOptions,
import { Errors } from "../types/errors.ts"; Permission,
import { RawOverwrite } from "../types/guild.ts"; Permissions,
import { MessageCreateOptions } from "../types/message.ts"; RawOverwrite,
import { Permission, Permissions } from "../types/permission.ts"; WebhookPayload,
import { WebhookPayload } from "../types/webhook.ts"; } from "../types/types.ts";
import { endpoints } from "../utils/constants.ts"; import { endpoints } from "../utils/constants.ts";
import { botHasChannelPermissions } from "../utils/permissions.ts"; import { botHasChannelPermissions } from "../utils/permissions.ts";
+16 -12
View File
@@ -2,18 +2,19 @@ import { cacheHandlers } from "../controllers/cache.ts";
import { identifyPayload } from "../module/client.ts"; import { identifyPayload } from "../module/client.ts";
import { RequestManager } from "../module/requestManager.ts"; import { RequestManager } from "../module/requestManager.ts";
import { requestAllMembers } from "../module/shardingManager.ts"; import { requestAllMembers } from "../module/shardingManager.ts";
import { Guild } from "../structures/guild.ts"; import {
import { Member } from "../structures/member.ts"; Guild,
import { structures } from "../structures/mod.ts"; Member,
import { Template } from "../structures/template.ts"; structures,
import { ImageFormats, ImageSize } from "../types/cdn.ts"; Template,
import { ChannelCreatePayload, ChannelTypes } from "../types/channel.ts"; } from "../structures/structures.ts";
import { Errors } from "../types/errors.ts";
import { import {
AuditLogs, AuditLogs,
BannedUser, BannedUser,
BanOptions, BanOptions,
ChannelCreateOptions, ChannelCreateOptions,
ChannelCreatePayload,
ChannelTypes,
CreateEmojisOptions, CreateEmojisOptions,
CreateGuildFromTemplate, CreateGuildFromTemplate,
CreateGuildPayload, CreateGuildPayload,
@@ -23,20 +24,23 @@ import {
EditEmojisOptions, EditEmojisOptions,
EditGuildTemplate, EditGuildTemplate,
EditIntegrationOptions, EditIntegrationOptions,
Errors,
FetchMembersOptions, FetchMembersOptions,
GetAuditLogsOptions, GetAuditLogsOptions,
GuildEditOptions, GuildEditOptions,
GuildTemplate, GuildTemplate,
ImageFormats,
ImageSize,
Intents,
MemberCreatePayload,
Permissions,
PositionSwap, PositionSwap,
PruneOptions, PruneOptions,
PrunePayload, PrunePayload,
RoleData,
UpdateGuildPayload, UpdateGuildPayload,
UserPayload, UserPayload,
} from "../types/guild.ts"; } from "../types/types.ts";
import { MemberCreatePayload } from "../types/member.ts";
import { Intents } from "../types/options.ts";
import { Permissions } from "../types/permission.ts";
import { RoleData } from "../types/role.ts";
import { formatImageURL } from "../utils/cdn.ts"; import { formatImageURL } from "../utils/cdn.ts";
import { Collection } from "../utils/collection.ts"; import { Collection } from "../utils/collection.ts";
import { endpoints } from "../utils/constants.ts"; import { endpoints } from "../utils/constants.ts";
+9 -6
View File
@@ -1,12 +1,15 @@
import { cacheHandlers } from "../controllers/cache.ts"; import { cacheHandlers } from "../controllers/cache.ts";
import { botID } from "../module/client.ts"; import { botID } from "../module/client.ts";
import { RequestManager } from "../module/requestManager.ts"; import { RequestManager } from "../module/requestManager.ts";
import { Member } from "../structures/member.ts"; import { Member, structures } from "../structures/structures.ts";
import { structures } from "../structures/mod.ts"; import {
import { ImageFormats, ImageSize } from "../types/cdn.ts"; DMChannelCreatePayload,
import { DMChannelCreatePayload, MessageContent } from "../types/channel.ts"; EditMemberOptions,
import { Errors } from "../types/errors.ts"; Errors,
import { EditMemberOptions } from "../types/member.ts"; ImageFormats,
ImageSize,
MessageContent,
} from "../types/types.ts";
import { formatImageURL } from "../utils/cdn.ts"; import { formatImageURL } from "../utils/cdn.ts";
import { endpoints } from "../utils/constants.ts"; import { endpoints } from "../utils/constants.ts";
import { import {
+7 -6
View File
@@ -2,12 +2,13 @@ import { delay } from "../../deps.ts";
import { cacheHandlers } from "../controllers/cache.ts"; import { cacheHandlers } from "../controllers/cache.ts";
import { botID } from "../module/client.ts"; import { botID } from "../module/client.ts";
import { RequestManager } from "../module/requestManager.ts"; import { RequestManager } from "../module/requestManager.ts";
import { Message } from "../structures/message.ts"; import { Message, structures } from "../structures/structures.ts";
import { structures } from "../structures/mod.ts"; import {
import { MessageContent } from "../types/channel.ts"; Errors,
import { Errors } from "../types/errors.ts"; MessageContent,
import { UserPayload } from "../types/guild.ts"; MessageCreateOptions,
import { MessageCreateOptions } from "../types/message.ts"; UserPayload,
} from "../types/types.ts";
import { endpoints } from "../utils/constants.ts"; import { endpoints } from "../utils/constants.ts";
import { botHasChannelPermissions } from "../utils/permissions.ts"; import { botHasChannelPermissions } from "../utils/permissions.ts";
+4 -4
View File
@@ -1,12 +1,12 @@
import { RequestManager } from "../module/requestManager.ts"; import { RequestManager } from "../module/requestManager.ts";
import { structures } from "../structures/mod.ts"; import { structures } from "../structures/structures.ts";
import { Errors } from "../types/errors.ts";
import { MessageCreateOptions } from "../types/message.ts";
import { import {
Errors,
ExecuteWebhookOptions, ExecuteWebhookOptions,
MessageCreateOptions,
WebhookCreateOptions, WebhookCreateOptions,
WebhookPayload, WebhookPayload,
} from "../types/webhook.ts"; } from "../types/types.ts";
import { endpoints } from "../utils/constants.ts"; import { endpoints } from "../utils/constants.ts";
import { botHasChannelPermissions } from "../utils/permissions.ts"; import { botHasChannelPermissions } from "../utils/permissions.ts";
import { urlToBase64 } from "../utils/utils.ts"; import { urlToBase64 } from "../utils/utils.ts";
+5 -2
View File
@@ -1,5 +1,8 @@
import { DiscordBotGatewayData } from "../types/discord.ts"; import {
import { ClientOptions, EventHandlers } from "../types/options.ts"; ClientOptions,
DiscordBotGatewayData,
EventHandlers,
} from "../types/types.ts";
import { baseEndpoints, endpoints } from "../utils/constants.ts"; import { baseEndpoints, endpoints } from "../utils/constants.ts";
import { RequestManager } from "./requestManager.ts"; import { RequestManager } from "./requestManager.ts";
import { spawnShards } from "./shardingManager.ts"; import { spawnShards } from "./shardingManager.ts";
+1 -3
View File
@@ -1,7 +1,5 @@
import { delay } from "../../deps.ts"; import { delay } from "../../deps.ts";
import { HttpResponseCode } from "../types/discord.ts"; import { Errors, HttpResponseCode, RequestMethods } from "../types/types.ts";
import { Errors } from "../types/errors.ts";
import { RequestMethods } from "../types/fetch.ts";
import { baseEndpoints, discordAPIURLS } from "../utils/constants.ts"; import { baseEndpoints, discordAPIURLS } from "../utils/constants.ts";
import { authorization, eventHandlers } from "./client.ts"; import { authorization, eventHandlers } from "./client.ts";
+2 -2
View File
@@ -3,10 +3,10 @@ import { eventHandlers } from "../../mod.ts";
import { import {
DiscordBotGatewayData, DiscordBotGatewayData,
DiscordHeartbeatPayload, DiscordHeartbeatPayload,
FetchMembersOptions,
GatewayOpcode, GatewayOpcode,
ReadyPayload, ReadyPayload,
} from "../types/discord.ts"; } from "../types/types.ts";
import { FetchMembersOptions } from "../types/guild.ts";
import { BotStatusRequest } from "../utils/utils.ts"; import { BotStatusRequest } from "../utils/utils.ts";
import { IdentifyPayload, proxyWSURL } from "./client.ts"; import { IdentifyPayload, proxyWSURL } from "./client.ts";
import { handleDiscordPayload } from "./shardingManager.ts"; import { handleDiscordPayload } from "./shardingManager.ts";
+3 -3
View File
@@ -1,12 +1,12 @@
import { delay } from "../../deps.ts"; import { delay } from "../../deps.ts";
import { controllers } from "../controllers/mod.ts"; import { controllers } from "../controllers/mod.ts";
import { Guild } from "../structures/guild.ts"; import { Guild } from "../structures/structures.ts";
import { import {
DiscordBotGatewayData, DiscordBotGatewayData,
DiscordPayload, DiscordPayload,
FetchMembersOptions,
GatewayOpcode, GatewayOpcode,
} from "../types/discord.ts"; } from "../types/types.ts";
import { FetchMembersOptions } from "../types/guild.ts";
import { cache } from "../utils/cache.ts"; import { cache } from "../utils/cache.ts";
import { BotStatusRequest } from "../utils/utils.ts"; import { BotStatusRequest } from "../utils/utils.ts";
import { import {
+1 -2
View File
@@ -1,6 +1,5 @@
import { cacheHandlers } from "../controllers/cache.ts"; import { cacheHandlers } from "../controllers/cache.ts";
import { ChannelCreatePayload } from "../types/channel.ts"; import { ChannelCreatePayload, Unpromise } from "../types/types.ts";
import { Unpromise } from "../types/misc.ts";
export async function createChannel( export async function createChannel(
data: ChannelCreatePayload, data: ChannelCreatePayload,
+5 -3
View File
@@ -1,6 +1,8 @@
import { CreateGuildPayload } from "../types/guild.ts"; import {
import { MemberCreatePayload } from "../types/member.ts"; CreateGuildPayload,
import { Unpromise } from "../types/misc.ts"; MemberCreatePayload,
Unpromise,
} from "../types/types.ts";
import { Collection } from "../utils/collection.ts"; import { Collection } from "../utils/collection.ts";
import { structures } from "./mod.ts"; import { structures } from "./mod.ts";
+1 -2
View File
@@ -1,6 +1,5 @@
import { cacheHandlers } from "../controllers/cache.ts"; import { cacheHandlers } from "../controllers/cache.ts";
import { GuildMember, MemberCreatePayload } from "../types/member.ts"; import { GuildMember, MemberCreatePayload, Unpromise } from "../types/types.ts";
import { Unpromise } from "../types/misc.ts";
import { Collection } from "../utils/collection.ts"; import { Collection } from "../utils/collection.ts";
export async function createMember(data: MemberCreatePayload, guildID: string) { export async function createMember(data: MemberCreatePayload, guildID: string) {
+1 -2
View File
@@ -1,5 +1,4 @@
import { MessageCreateOptions } from "../types/message.ts"; import { MessageCreateOptions, Unpromise } from "../types/types.ts";
import { Unpromise } from "../types/misc.ts";
export async function createMessage(data: MessageCreateOptions) { export async function createMessage(data: MessageCreateOptions) {
const { const {
+1 -2
View File
@@ -1,5 +1,4 @@
import { Unpromise } from "../types/misc.ts"; import { RoleData, Unpromise } from "../types/types.ts";
import { RoleData } from "../types/role.ts";
export async function createRole(data: RoleData) { export async function createRole(data: RoleData) {
const { tags, ...rest } = data; const { tags, ...rest } = data;
+7
View File
@@ -0,0 +1,7 @@
export * from "./channel.ts";
export * from "./guild.ts";
export * from "./member.ts";
export * from "./message.ts";
export * from "./mod.ts";
export * from "./role.ts";
export * from "./template.ts";
+1 -1
View File
@@ -1,4 +1,4 @@
import { GuildTemplate } from "../types/guild.ts"; import { GuildTemplate } from "../types/types.ts";
export function createTemplate( export function createTemplate(
data: GuildTemplate, data: GuildTemplate,
+1 -1
View File
@@ -1,4 +1,4 @@
import { Guild } from "../structures/guild.ts"; import { Guild } from "../structures/structures.ts";
import { ChannelCreatePayload, ChannelTypes } from "./channel.ts"; import { ChannelCreatePayload, ChannelTypes } from "./channel.ts";
import { Emoji, StatusType } from "./discord.ts"; import { Emoji, StatusType } from "./discord.ts";
import { MemberCreatePayload } from "./member.ts"; import { MemberCreatePayload } from "./member.ts";
+1 -1
View File
@@ -1,4 +1,4 @@
import { Channel } from "../structures/channel.ts"; import { Channel } from "../structures/structures.ts";
import { ChannelType } from "./channel.ts"; import { ChannelType } from "./channel.ts";
import { UserPayload } from "./guild.ts"; import { UserPayload } from "./guild.ts";
import { MemberCreatePayload } from "./member.ts"; import { MemberCreatePayload } from "./member.ts";
+7 -5
View File
@@ -1,8 +1,10 @@
import { Channel } from "../structures/channel.ts"; import {
import { Guild } from "../structures/guild.ts"; Channel,
import { Member } from "../structures/member.ts"; Guild,
import { Message } from "../structures/message.ts"; Member,
import { Role } from "../structures/role.ts"; Message,
Role,
} from "../structures/structures.ts";
import { import {
DiscordPayload, DiscordPayload,
Emoji, Emoji,
+15
View File
@@ -0,0 +1,15 @@
export * from "./activity.ts";
export * from "./cdn.ts";
export * from "./channel.ts";
export * from "./discord.ts";
export * from "./errors.ts";
export * from "./fetch.ts";
export * from "./guild.ts";
export * from "./member.ts";
export * from "./message.ts";
export * from "./misc.ts";
export * from "./options.ts";
export * from "./permission.ts";
export * from "./presence.ts";
export * from "./role.ts";
export * from "./webhook.ts";
+2 -5
View File
@@ -1,8 +1,5 @@
import { Channel } from "../structures/channel.ts"; import { Channel, Guild, Member, Message } from "../structures/structures.ts";
import { Guild } from "../structures/guild.ts"; import { PresenceUpdatePayload } from "../types/types.ts";
import { Member } from "../structures/member.ts";
import { Message } from "../structures/message.ts";
import { PresenceUpdatePayload } from "../types/discord.ts";
import { Collection } from "./collection.ts"; import { Collection } from "./collection.ts";
export interface CacheData { export interface CacheData {
+1 -1
View File
@@ -1,4 +1,4 @@
import { ImageFormats, ImageSize } from "../types/cdn.ts"; import { ImageFormats, ImageSize } from "../types/types.ts";
export const formatImageURL = ( export const formatImageURL = (
url: string, url: string,
+2 -4
View File
@@ -1,9 +1,7 @@
import { cacheHandlers } from "../controllers/cache.ts"; import { cacheHandlers } from "../controllers/cache.ts";
import { botID } from "../module/client.ts"; import { botID } from "../module/client.ts";
import { Guild } from "../structures/guild.ts"; import { Guild, Role } from "../structures/structures.ts";
import { Role } from "../structures/role.ts"; import { Permission, Permissions, RawOverwrite } from "../types/types.ts";
import { RawOverwrite } from "../types/guild.ts";
import { Permission, Permissions } from "../types/permission.ts";
/** Checks if the member has this permission. If the member is an owner or has admin perms it will always be true. */ /** Checks if the member has this permission. If the member is an owner or has admin perms it will always be true. */
export async function memberIDHasPermission( export async function memberIDHasPermission(
+1 -2
View File
@@ -1,7 +1,6 @@
import { encode } from "../../deps.ts"; import { encode } from "../../deps.ts";
import { sendGatewayCommand } from "../module/shardingManager.ts"; import { sendGatewayCommand } from "../module/shardingManager.ts";
import { ActivityType } from "../types/activity.ts"; import { ActivityType, StatusType } from "../types/types.ts";
import { StatusType } from "../types/discord.ts";
export const sleep = (timeout: number) => { export const sleep = (timeout: number) => {
return new Promise((resolve) => setTimeout(resolve, timeout)); return new Promise((resolve) => setTimeout(resolve, timeout));