From de34034ecce8ae4c335ad1b85cc89ac1c0421f19 Mon Sep 17 00:00:00 2001 From: Yuzu Date: Mon, 27 Jun 2022 22:00:39 -0500 Subject: [PATCH] refactor: imports --- handlers/{HandlerManager.ts => Actions.ts} | 0 mod.ts | 49 ++++++++++++++-------- session/Session.ts | 6 ++- session/mod.ts | 2 - structures/AnonymousGuild.ts | 2 +- structures/Base.ts | 4 +- structures/Channel.ts | 2 +- structures/DMChannel.ts | 4 +- structures/Emoji.ts | 2 +- structures/Guild.ts | 12 +++--- structures/GuildChannel.ts | 4 +- structures/GuildEmoji.ts | 8 ++-- structures/Member.ts | 4 +- structures/Message.ts | 11 ++--- structures/NewsChannel.ts | 2 +- structures/Role.ts | 14 ++++--- structures/TextChannel.ts | 12 +++--- structures/ThreadChannel.ts | 2 +- structures/User.ts | 4 +- structures/VoiceChannel.ts | 2 +- tests/mod.ts | 2 +- util/mod.ts | 6 --- 22 files changed, 82 insertions(+), 72 deletions(-) rename handlers/{HandlerManager.ts => Actions.ts} (100%) delete mode 100644 session/mod.ts delete mode 100644 util/mod.ts diff --git a/handlers/HandlerManager.ts b/handlers/Actions.ts similarity index 100% rename from handlers/HandlerManager.ts rename to handlers/Actions.ts diff --git a/mod.ts b/mod.ts index 867286f..fc4e693 100644 --- a/mod.ts +++ b/mod.ts @@ -1,24 +1,37 @@ -export * from "./session/mod.ts"; -export * from "./util/mod.ts"; -export * from "./vendor/external.ts"; -export * from "./structures/User.ts"; -export * from "./structures/Role.ts"; -export * from "./structures/Base.ts"; -export * from "./structures/Guild.ts"; -export * from "./structures/Member.ts"; -export * from "./structures/Message.ts"; -export * from "./structures/BaseGuild.ts"; -export * from "./structures/Attachment.ts"; export * from "./structures/AnonymousGuild.ts"; +export * from "./structures/Attachment.ts"; +export * from "./structures/Base.ts"; +export * from "./structures/BaseGuild.ts"; +export * from "./structures/Channel.ts"; export * from "./structures/DMChannel.ts"; -export * from "./structures/TextChannel.ts"; -export * from "./structures/VoiceChannel.ts"; -export * from "./structures/ThreadChannel.ts"; -export * from "./structures/NewsChannel.ts"; export * from "./structures/Emoji.ts"; -export * from "./structures/VoiceChannel.ts"; +export * from "./structures/Guild.ts"; +export * from "./structures/GuildChannel.ts"; export * from "./structures/GuildEmoji.ts"; -export * from "./structures/WelcomeChannel.ts"; -export * from "./structures/WelcomeScreen.ts"; export * from "./structures/Invite.ts"; export * from "./structures/InviteGuild.ts"; +export * from "./structures/Member.ts"; +export * from "./structures/Message.ts"; +export * from "./structures/NewsChannel.ts"; +export * from "./structures/Permissions.ts"; +export * from "./structures/Role.ts"; +export * from "./structures/TextChannel.ts"; +export * from "./structures/ThreadChannel.ts"; +export * from "./structures/User.ts"; +export * from "./structures/VoiceChannel.ts"; +export * from "./structures/WelcomeChannel.ts"; +export * from "./structures/WelcomeScreen.ts"; + +export * from "./session/Session.ts"; +export * from "./session/Events.ts"; + +export * from "./util/shared/flags.ts"; +export * from "./util/shared/images.ts"; +export * from "./util/Snowflake.ts"; +export * from "./util/urlToBase64.ts"; +export * from "./util/EventEmmiter.ts"; +export * from "./util/hash.ts"; +export * as Routes from "./util/Routes.ts"; +export * as Cdn from "./util/Cdn.ts"; + +export * from "./vendor/external.ts"; diff --git a/session/Session.ts b/session/Session.ts index c519560..cce960e 100644 --- a/session/Session.ts +++ b/session/Session.ts @@ -1,10 +1,12 @@ import type { DiscordGetGatewayBot, GatewayBot, GatewayIntents } from "../vendor/external.ts"; import type { DiscordRawEventHandler, Events } from "./Events.ts"; -import { EventEmitter, Routes, Snowflake } from "../util/mod.ts"; +import { Snowflake } from "../util/Snowflake.ts"; +import { EventEmitter } from "../util/EventEmmiter.ts"; import { createGatewayManager, createRestManager } from "../vendor/external.ts"; -import * as Actions from "../handlers/HandlerManager.ts"; +import * as Routes from "../util/Routes.ts"; +import * as Actions from "../handlers/Actions.ts"; export interface RestOptions { secretKey?: string; diff --git a/session/mod.ts b/session/mod.ts deleted file mode 100644 index 13b35eb..0000000 --- a/session/mod.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./Session.ts"; -export * from "./Events.ts"; diff --git a/structures/AnonymousGuild.ts b/structures/AnonymousGuild.ts index f675669..6e92ae3 100644 --- a/structures/AnonymousGuild.ts +++ b/structures/AnonymousGuild.ts @@ -2,7 +2,7 @@ import type { Model } from "./Base.ts"; import type { Session } from "../session/Session.ts"; import type { DiscordGuild, GuildNsfwLevel, VerificationLevels } from "../vendor/external.ts"; import { iconHashToBigInt } from "../util/hash.ts"; -import { BaseGuild } from "./BaseGuild.ts"; +import BaseGuild from "./BaseGuild.ts"; export class AnonymousGuild extends BaseGuild implements Model { constructor(session: Session, data: Partial); // TODO: Improve this type (name and id are required) diff --git a/structures/Base.ts b/structures/Base.ts index 1d79680..a999f5b 100644 --- a/structures/Base.ts +++ b/structures/Base.ts @@ -1,5 +1,5 @@ -import type { Snowflake } from "../util/mod.ts"; -import type { Session } from "../session/mod.ts"; +import type { Snowflake } from "../util/Snowflake.ts"; +import type { Session } from "../session/Session.ts"; /** * Represents a Discord data model diff --git a/structures/Channel.ts b/structures/Channel.ts index ccb45dc..a0f3d50 100644 --- a/structures/Channel.ts +++ b/structures/Channel.ts @@ -1,7 +1,7 @@ import type { Model } from "./Base.ts"; import type { Snowflake } from "../util/Snowflake.ts"; import type { Session } from "../session/Session.ts"; -import { ChannelTypes, DiscordChannel } from "../mod.ts"; +import type { ChannelTypes, DiscordChannel } from "../vendor/external.ts"; export abstract class Channel implements Model { constructor(session: Session, data: DiscordChannel) { diff --git a/structures/DMChannel.ts b/structures/DMChannel.ts index 9fb2879..077514f 100644 --- a/structures/DMChannel.ts +++ b/structures/DMChannel.ts @@ -1,8 +1,8 @@ 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 { Routes } from "../util/mod.ts"; +import Channel from "./Channel.ts"; +import * as Routes from "../util/Routes.ts"; export class DMChannel extends Channel { constructor(session: Session, data: DiscordChannel) { diff --git a/structures/Emoji.ts b/structures/Emoji.ts index 19ad7ed..fe3a321 100644 --- a/structures/Emoji.ts +++ b/structures/Emoji.ts @@ -1,6 +1,6 @@ import type { Session } from "../session/Session.ts"; import type { Snowflake } from "../util/Snowflake.ts"; -import type { DiscordEmoji } from "../mod.ts"; +import type { DiscordEmoji } from "../vendor/external.ts"; export class Emoji { constructor(session: Session, data: DiscordEmoji) { diff --git a/structures/Guild.ts b/structures/Guild.ts index 9cf0064..448b6b6 100644 --- a/structures/Guild.ts +++ b/structures/Guild.ts @@ -9,12 +9,12 @@ import { } from "../vendor/external.ts"; import { iconBigintToHash, iconHashToBigInt } from "../util/hash.ts"; import { urlToBase64 } from "../util/urlToBase64.ts"; -import { Member } from "./Member.ts"; -import { BaseGuild } from "./BaseGuild.ts"; -import { Role } from "./Role.ts"; -import { GuildEmoji } from "./GuildEmoji.ts"; -import { Invite } from "./Invite.ts"; -import { Routes } from "../util/mod.ts"; +import Member from "./Member.ts"; +import BaseGuild from "./BaseGuild.ts"; +import Role from "./Role.ts"; +import GuildEmoji from "./GuildEmoji.ts"; +import Invite from "./Invite.ts"; +import * as Routes from "../util/Routes.ts"; export interface CreateRole { name?: string; diff --git a/structures/GuildChannel.ts b/structures/GuildChannel.ts index a878474..e101f82 100644 --- a/structures/GuildChannel.ts +++ b/structures/GuildChannel.ts @@ -1,8 +1,8 @@ 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 { Routes } from "../util/mod.ts"; +import Channel from "./Channel.ts"; +import * as Routes from "../util/Routes.ts"; export abstract class GuildChannel extends Channel { constructor(session: Session, data: DiscordChannel, guildId: Snowflake) { diff --git a/structures/GuildEmoji.ts b/structures/GuildEmoji.ts index a0cac18..3466319 100644 --- a/structures/GuildEmoji.ts +++ b/structures/GuildEmoji.ts @@ -2,10 +2,10 @@ import type { Snowflake } from "../util/Snowflake.ts"; import type { Session } from "../session/Session.ts"; import type { DiscordEmoji } from "../vendor/external.ts"; import type { ModifyGuildEmoji } from "./Guild.ts"; -import { Guild } from "./Guild.ts"; -import { Emoji } from "./Emoji.ts"; -import { User } from "./User.ts"; -import { Routes } from "../util/mod.ts"; +import Guild from "./Guild.ts"; +import Emoji from "./Emoji.ts"; +import User from "./User.ts"; +import * as Routes from "../util/Routes.ts"; export class GuildEmoji extends Emoji { constructor(session: Session, data: DiscordEmoji, guildId: Snowflake) { diff --git a/structures/Member.ts b/structures/Member.ts index 5e04ac7..355d9d4 100644 --- a/structures/Member.ts +++ b/structures/Member.ts @@ -4,8 +4,8 @@ import type { Session } from "../session/Session.ts"; import type { DiscordMember, MakeRequired } from "../vendor/external.ts"; import type { ImageFormat, ImageSize } from "../util/shared/images.ts"; import { iconBigintToHash, iconHashToBigInt } from "../util/hash.ts"; -import { Routes } from "../util/mod.ts"; -import { User } from "./User.ts"; +import User from "./User.ts"; +import * as Routes from "../util/Routes.ts"; /** * @link https://discord.com/developers/docs/resources/guild#create-guild-ban diff --git a/structures/Message.ts b/structures/Message.ts index f900eb7..9b000c3 100644 --- a/structures/Message.ts +++ b/structures/Message.ts @@ -1,11 +1,12 @@ import type { Model } from "./Base.ts"; import type { Snowflake } from "../util/Snowflake.ts"; -import type { Session } from "../session/mod.ts"; +import type { Session } from "../session/Session.ts"; import type { AllowedMentionsTypes, DiscordMessage } from "../vendor/external.ts"; -import { User } from "./User.ts"; -import { Member } from "./Member.ts"; -import { Attachment } from "./Attachment.ts"; -import { MessageFlags, Routes } from "../util/mod.ts"; +import { MessageFlags } from "../util/shared/flags.ts"; +import User from "./User.ts"; +import Member from "./Member.ts"; +import Attachment from "./Attachment.ts"; +import * as Routes from "../util/Routes.ts"; /** * @link https://discord.com/developers/docs/resources/channel#allowed-mentions-object diff --git a/structures/NewsChannel.ts b/structures/NewsChannel.ts index 5be27c8..fcd15aa 100644 --- a/structures/NewsChannel.ts +++ b/structures/NewsChannel.ts @@ -1,7 +1,7 @@ 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"; +import TextChannel from "./TextChannel.ts"; export class NewsChannel extends TextChannel { constructor(session: Session, data: DiscordChannel, guildId: Snowflake) { diff --git a/structures/Role.ts b/structures/Role.ts index a4c9b02..64365e5 100644 --- a/structures/Role.ts +++ b/structures/Role.ts @@ -1,10 +1,10 @@ import type { Model } from "./Base.ts"; import type { DiscordRole } from "../vendor/external.ts"; +import type { Session } from "../session/Session.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"; +import Permissions from "./Permissions.ts"; +import Guild from "./Guild.ts"; export class Role implements Model { constructor(session: Session, data: DiscordRole, guildId: Snowflake) { @@ -21,9 +21,11 @@ export class Role implements Model { this.permissions = new Permissions(BigInt(data.permissions)); } - session: Session; - id: Snowflake; - guildId: Snowflake; + readonly session: Session; + readonly id: Snowflake; + + readonly guildId: Snowflake; + hoist: boolean; iconHash?: bigint; color: number; diff --git a/structures/TextChannel.ts b/structures/TextChannel.ts index 63cfda1..a24dc29 100644 --- a/structures/TextChannel.ts +++ b/structures/TextChannel.ts @@ -2,12 +2,12 @@ import type { Session } from "../session/Session.ts"; import type { Snowflake } from "../util/Snowflake.ts"; import type { GetMessagesOptions } from "../util/Routes.ts"; import type { DiscordChannel, DiscordInvite, DiscordMessage, TargetTypes } 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 { Invite } from "./Invite.ts"; -import { Routes } from "../util/mod.ts"; +import GuildChannel from "./GuildChannel.ts"; +import Guild from "./Guild.ts"; +import ThreadChannel from "./ThreadChannel.ts"; +import Message from "./Message.ts"; +import Invite from "./Invite.ts"; +import * as Routes from "../util/Routes.ts"; /** * Represents the options object to create an invitation diff --git a/structures/ThreadChannel.ts b/structures/ThreadChannel.ts index d52b54c..deaa23a 100644 --- a/structures/ThreadChannel.ts +++ b/structures/ThreadChannel.ts @@ -1,7 +1,7 @@ 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"; export class ThreadChannel extends GuildChannel { constructor(session: Session, data: DiscordChannel, guildId: Snowflake) { diff --git a/structures/User.ts b/structures/User.ts index 7ed47a4..551d58f 100644 --- a/structures/User.ts +++ b/structures/User.ts @@ -1,10 +1,10 @@ import type { Model } from "./Base.ts"; import type { Snowflake } from "../util/Snowflake.ts"; -import type { Session } from "../session/mod.ts"; +import type { Session } from "../session/Session.ts"; import type { DiscordUser } from "../vendor/external.ts"; import type { ImageFormat, ImageSize } from "../util/shared/images.ts"; import { iconBigintToHash, iconHashToBigInt } from "../util/hash.ts"; -import { Routes } from "../util/mod.ts"; +import * as Routes from "../util/Routes.ts"; /** * Represents a user diff --git a/structures/VoiceChannel.ts b/structures/VoiceChannel.ts index 56f682f..30a4d50 100644 --- a/structures/VoiceChannel.ts +++ b/structures/VoiceChannel.ts @@ -1,7 +1,7 @@ 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"; export class VoiceChannel extends GuildChannel { constructor(session: Session, guildId: Snowflake, data: DiscordChannel) { diff --git a/tests/mod.ts b/tests/mod.ts index 402cd5a..75ed69d 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -12,7 +12,7 @@ session.on("ready", (_shardId, payload) => { }); session.on("messageCreate", (message) => { - if (message.content.startsWith("!ping")) { + if (message.content.startsWith("&ping")) { message.reply({ content: "pong!" }); } }); diff --git a/util/mod.ts b/util/mod.ts deleted file mode 100644 index 45354dc..0000000 --- a/util/mod.ts +++ /dev/null @@ -1,6 +0,0 @@ -export * from "./EventEmmiter.ts"; -export * from "./Snowflake.ts"; -export * from "./hash.ts"; -export * from "./shared/flags.ts"; -export * from "./shared/images.ts"; -export * as Routes from "./Routes.ts";