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 { DiscordPayload } from "../types/discord.ts";
import { GuildBanPayload } from "../types/guild.ts";
import { DiscordPayload, GuildBanPayload } from "../types/types.ts";
import { cacheHandlers } from "./cache.ts";
export async function handleInternalGuildBanAdd(data: DiscordPayload) {
+2 -5
View File
@@ -1,8 +1,5 @@
import { Channel } from "../structures/channel.ts";
import { Guild } from "../structures/guild.ts";
import { Member } from "../structures/member.ts";
import { Message } from "../structures/message.ts";
import { PresenceUpdatePayload } from "../types/discord.ts";
import { Channel, Guild, Member, Message } from "../structures/structures.ts";
import { PresenceUpdatePayload } from "../types/types.ts";
import { cache } from "../utils/cache.ts";
import { Collection } from "../utils/collection.ts";
+6 -3
View File
@@ -1,7 +1,10 @@
import { eventHandlers } from "../module/client.ts";
import { structures } from "../structures/mod.ts";
import { ChannelCreatePayload, ChannelTypes } from "../types/channel.ts";
import { DiscordPayload } from "../types/discord.ts";
import { structures } from "../structures/structures.ts";
import {
ChannelCreatePayload,
ChannelTypes,
DiscordPayload,
} from "../types/types.ts";
import { cacheHandlers } from "./cache.ts";
export async function handleInternalChannelCreate(data: DiscordPayload) {
+4 -4
View File
@@ -1,13 +1,13 @@
import { eventHandlers } from "../module/client.ts";
import { structures } from "../structures/mod.ts";
import { DiscordPayload } from "../types/discord.ts";
import { structures } from "../structures/structures.ts";
import {
CreateGuildPayload,
DiscordPayload,
GuildDeletePayload,
GuildEmojisUpdatePayload,
GuildUpdateChange,
UpdateGuildPayload,
} from "../types/guild.ts";
import { GuildUpdateChange } from "../types/options.ts";
} from "../types/types.ts";
import { cache } from "../utils/cache.ts";
import { cacheHandlers } from "./cache.ts";
+3 -3
View File
@@ -1,12 +1,12 @@
import { eventHandlers } from "../module/client.ts";
import { structures } from "../structures/mod.ts";
import { DiscordPayload } from "../types/discord.ts";
import { structures } from "../structures/structures.ts";
import {
DiscordPayload,
GuildBanPayload,
GuildMemberAddPayload,
GuildMemberChunkPayload,
GuildMemberUpdatePayload,
} from "../types/guild.ts";
} from "../types/types.ts";
import { cache } from "../utils/cache.ts";
import { cacheHandlers } from "./cache.ts";
+3 -3
View File
@@ -1,11 +1,11 @@
import { eventHandlers } from "../module/client.ts";
import { structures } from "../structures/mod.ts";
import { DiscordPayload } from "../types/discord.ts";
import { structures } from "../structures/structures.ts";
import {
DiscordPayload,
MessageCreateOptions,
MessageDeleteBulkPayload,
MessageDeletePayload,
} from "../types/message.ts";
} from "../types/types.ts";
import { cacheHandlers } from "./cache.ts";
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 { eventHandlers, setBotID } from "../module/client.ts";
import { allowNextShard } from "../module/shardingManager.ts";
import { structures } from "../structures/mod.ts";
import { structures } from "../structures/structures.ts";
import {
DiscordPayload,
PresenceUpdatePayload,
ReadyPayload,
TypingStartPayload,
UserPayload,
VoiceStateUpdatePayload,
WebhookUpdatePayload,
} from "../types/discord.ts";
import { UserPayload } from "../types/guild.ts";
} from "../types/types.ts";
import { cache } from "../utils/cache.ts";
import { cacheHandlers } from "./cache.ts";
+3 -3
View File
@@ -1,11 +1,11 @@
import { botID, eventHandlers } from "../module/client.ts";
import { structures } from "../structures/mod.ts";
import { DiscordPayload } from "../types/discord.ts";
import { structures } from "../structures/structures.ts";
import {
BaseMessageReactionPayload,
DiscordPayload,
MessageReactionPayload,
MessageReactionRemoveEmojiPayload,
} from "../types/message.ts";
} from "../types/types.ts";
import { cacheHandlers } from "./cache.ts";
export async function handleInternalMessageReactionAdd(data: DiscordPayload) {
+6 -3
View File
@@ -1,7 +1,10 @@
import { eventHandlers } from "../module/client.ts";
import { structures } from "../structures/mod.ts";
import { DiscordPayload } from "../types/discord.ts";
import { GuildRoleDeletePayload, GuildRolePayload } from "../types/guild.ts";
import { structures } from "../structures/structures.ts";
import {
DiscordPayload,
GuildRoleDeletePayload,
GuildRolePayload,
} from "../types/types.ts";
import { cacheHandlers } from "./cache.ts";
export async function handleInternalGuildRoleCreate(data: DiscordPayload) {
+8 -7
View File
@@ -1,22 +1,23 @@
import { cacheHandlers } from "../controllers/cache.ts";
import { RequestManager } from "../module/requestManager.ts";
import { structures } from "../structures/mod.ts";
import { structures } from "../structures/structures.ts";
import {
ChannelEditOptions,
ChannelTypes,
CreateInviteOptions,
Errors,
FollowedChannelPayload,
GetMessages,
GetMessagesAfter,
GetMessagesAround,
GetMessagesBefore,
MessageContent,
} from "../types/channel.ts";
import { Errors } from "../types/errors.ts";
import { RawOverwrite } from "../types/guild.ts";
import { MessageCreateOptions } from "../types/message.ts";
import { Permission, Permissions } from "../types/permission.ts";
import { WebhookPayload } from "../types/webhook.ts";
MessageCreateOptions,
Permission,
Permissions,
RawOverwrite,
WebhookPayload,
} from "../types/types.ts";
import { endpoints } from "../utils/constants.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 { RequestManager } from "../module/requestManager.ts";
import { requestAllMembers } from "../module/shardingManager.ts";
import { Guild } from "../structures/guild.ts";
import { Member } from "../structures/member.ts";
import { structures } from "../structures/mod.ts";
import { Template } from "../structures/template.ts";
import { ImageFormats, ImageSize } from "../types/cdn.ts";
import { ChannelCreatePayload, ChannelTypes } from "../types/channel.ts";
import { Errors } from "../types/errors.ts";
import {
Guild,
Member,
structures,
Template,
} from "../structures/structures.ts";
import {
AuditLogs,
BannedUser,
BanOptions,
ChannelCreateOptions,
ChannelCreatePayload,
ChannelTypes,
CreateEmojisOptions,
CreateGuildFromTemplate,
CreateGuildPayload,
@@ -23,20 +24,23 @@ import {
EditEmojisOptions,
EditGuildTemplate,
EditIntegrationOptions,
Errors,
FetchMembersOptions,
GetAuditLogsOptions,
GuildEditOptions,
GuildTemplate,
ImageFormats,
ImageSize,
Intents,
MemberCreatePayload,
Permissions,
PositionSwap,
PruneOptions,
PrunePayload,
RoleData,
UpdateGuildPayload,
UserPayload,
} from "../types/guild.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";
} from "../types/types.ts";
import { formatImageURL } from "../utils/cdn.ts";
import { Collection } from "../utils/collection.ts";
import { endpoints } from "../utils/constants.ts";
+9 -6
View File
@@ -1,12 +1,15 @@
import { cacheHandlers } from "../controllers/cache.ts";
import { botID } from "../module/client.ts";
import { RequestManager } from "../module/requestManager.ts";
import { Member } from "../structures/member.ts";
import { structures } from "../structures/mod.ts";
import { ImageFormats, ImageSize } from "../types/cdn.ts";
import { DMChannelCreatePayload, MessageContent } from "../types/channel.ts";
import { Errors } from "../types/errors.ts";
import { EditMemberOptions } from "../types/member.ts";
import { Member, structures } from "../structures/structures.ts";
import {
DMChannelCreatePayload,
EditMemberOptions,
Errors,
ImageFormats,
ImageSize,
MessageContent,
} from "../types/types.ts";
import { formatImageURL } from "../utils/cdn.ts";
import { endpoints } from "../utils/constants.ts";
import {
+7 -6
View File
@@ -2,12 +2,13 @@ import { delay } from "../../deps.ts";
import { cacheHandlers } from "../controllers/cache.ts";
import { botID } from "../module/client.ts";
import { RequestManager } from "../module/requestManager.ts";
import { Message } from "../structures/message.ts";
import { structures } from "../structures/mod.ts";
import { MessageContent } from "../types/channel.ts";
import { Errors } from "../types/errors.ts";
import { UserPayload } from "../types/guild.ts";
import { MessageCreateOptions } from "../types/message.ts";
import { Message, structures } from "../structures/structures.ts";
import {
Errors,
MessageContent,
MessageCreateOptions,
UserPayload,
} from "../types/types.ts";
import { endpoints } from "../utils/constants.ts";
import { botHasChannelPermissions } from "../utils/permissions.ts";
+4 -4
View File
@@ -1,12 +1,12 @@
import { RequestManager } from "../module/requestManager.ts";
import { structures } from "../structures/mod.ts";
import { Errors } from "../types/errors.ts";
import { MessageCreateOptions } from "../types/message.ts";
import { structures } from "../structures/structures.ts";
import {
Errors,
ExecuteWebhookOptions,
MessageCreateOptions,
WebhookCreateOptions,
WebhookPayload,
} from "../types/webhook.ts";
} from "../types/types.ts";
import { endpoints } from "../utils/constants.ts";
import { botHasChannelPermissions } from "../utils/permissions.ts";
import { urlToBase64 } from "../utils/utils.ts";
+5 -2
View File
@@ -1,5 +1,8 @@
import { DiscordBotGatewayData } from "../types/discord.ts";
import { ClientOptions, EventHandlers } from "../types/options.ts";
import {
ClientOptions,
DiscordBotGatewayData,
EventHandlers,
} from "../types/types.ts";
import { baseEndpoints, endpoints } from "../utils/constants.ts";
import { RequestManager } from "./requestManager.ts";
import { spawnShards } from "./shardingManager.ts";
+1 -3
View File
@@ -1,7 +1,5 @@
import { delay } from "../../deps.ts";
import { HttpResponseCode } from "../types/discord.ts";
import { Errors } from "../types/errors.ts";
import { RequestMethods } from "../types/fetch.ts";
import { Errors, HttpResponseCode, RequestMethods } from "../types/types.ts";
import { baseEndpoints, discordAPIURLS } from "../utils/constants.ts";
import { authorization, eventHandlers } from "./client.ts";
+2 -2
View File
@@ -3,10 +3,10 @@ import { eventHandlers } from "../../mod.ts";
import {
DiscordBotGatewayData,
DiscordHeartbeatPayload,
FetchMembersOptions,
GatewayOpcode,
ReadyPayload,
} from "../types/discord.ts";
import { FetchMembersOptions } from "../types/guild.ts";
} from "../types/types.ts";
import { BotStatusRequest } from "../utils/utils.ts";
import { IdentifyPayload, proxyWSURL } from "./client.ts";
import { handleDiscordPayload } from "./shardingManager.ts";
+3 -3
View File
@@ -1,12 +1,12 @@
import { delay } from "../../deps.ts";
import { controllers } from "../controllers/mod.ts";
import { Guild } from "../structures/guild.ts";
import { Guild } from "../structures/structures.ts";
import {
DiscordBotGatewayData,
DiscordPayload,
FetchMembersOptions,
GatewayOpcode,
} from "../types/discord.ts";
import { FetchMembersOptions } from "../types/guild.ts";
} from "../types/types.ts";
import { cache } from "../utils/cache.ts";
import { BotStatusRequest } from "../utils/utils.ts";
import {
+1 -2
View File
@@ -1,6 +1,5 @@
import { cacheHandlers } from "../controllers/cache.ts";
import { ChannelCreatePayload } from "../types/channel.ts";
import { Unpromise } from "../types/misc.ts";
import { ChannelCreatePayload, Unpromise } from "../types/types.ts";
export async function createChannel(
data: ChannelCreatePayload,
+5 -3
View File
@@ -1,6 +1,8 @@
import { CreateGuildPayload } from "../types/guild.ts";
import { MemberCreatePayload } from "../types/member.ts";
import { Unpromise } from "../types/misc.ts";
import {
CreateGuildPayload,
MemberCreatePayload,
Unpromise,
} from "../types/types.ts";
import { Collection } from "../utils/collection.ts";
import { structures } from "./mod.ts";
+1 -2
View File
@@ -1,6 +1,5 @@
import { cacheHandlers } from "../controllers/cache.ts";
import { GuildMember, MemberCreatePayload } from "../types/member.ts";
import { Unpromise } from "../types/misc.ts";
import { GuildMember, MemberCreatePayload, Unpromise } from "../types/types.ts";
import { Collection } from "../utils/collection.ts";
export async function createMember(data: MemberCreatePayload, guildID: string) {
+1 -2
View File
@@ -1,5 +1,4 @@
import { MessageCreateOptions } from "../types/message.ts";
import { Unpromise } from "../types/misc.ts";
import { MessageCreateOptions, Unpromise } from "../types/types.ts";
export async function createMessage(data: MessageCreateOptions) {
const {
+1 -2
View File
@@ -1,5 +1,4 @@
import { Unpromise } from "../types/misc.ts";
import { RoleData } from "../types/role.ts";
import { RoleData, Unpromise } from "../types/types.ts";
export async function createRole(data: RoleData) {
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(
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 { Emoji, StatusType } from "./discord.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 { UserPayload } from "./guild.ts";
import { MemberCreatePayload } from "./member.ts";
+7 -5
View File
@@ -1,8 +1,10 @@
import { Channel } from "../structures/channel.ts";
import { Guild } from "../structures/guild.ts";
import { Member } from "../structures/member.ts";
import { Message } from "../structures/message.ts";
import { Role } from "../structures/role.ts";
import {
Channel,
Guild,
Member,
Message,
Role,
} from "../structures/structures.ts";
import {
DiscordPayload,
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 { Guild } from "../structures/guild.ts";
import { Member } from "../structures/member.ts";
import { Message } from "../structures/message.ts";
import { PresenceUpdatePayload } from "../types/discord.ts";
import { Channel, Guild, Member, Message } from "../structures/structures.ts";
import { PresenceUpdatePayload } from "../types/types.ts";
import { Collection } from "./collection.ts";
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 = (
url: string,
+2 -4
View File
@@ -1,9 +1,7 @@
import { cacheHandlers } from "../controllers/cache.ts";
import { botID } from "../module/client.ts";
import { Guild } from "../structures/guild.ts";
import { Role } from "../structures/role.ts";
import { RawOverwrite } from "../types/guild.ts";
import { Permission, Permissions } from "../types/permission.ts";
import { Guild, Role } from "../structures/structures.ts";
import { Permission, Permissions, RawOverwrite } from "../types/types.ts";
/** 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(
+1 -2
View File
@@ -1,7 +1,6 @@
import { encode } from "../../deps.ts";
import { sendGatewayCommand } from "../module/shardingManager.ts";
import { ActivityType } from "../types/activity.ts";
import { StatusType } from "../types/discord.ts";
import { ActivityType, StatusType } from "../types/types.ts";
export const sleep = (timeout: number) => {
return new Promise((resolve) => setTimeout(resolve, timeout));