diff --git a/mod.ts b/mod.ts index fa626f6..a768b65 100644 --- a/mod.ts +++ b/mod.ts @@ -1,19 +1,19 @@ export * from './src/gateway/index.ts' export * from './src/models/client.ts' export * from './src/models/rest.ts' -export * from './src/models/CacheAdapter.ts' +export * from './src/models/cacheAdapter.ts' export * from './src/models/shard.ts' -export * from './src/managers/BaseManager.ts' -export * from './src/managers/BaseChildManager.ts' -export * from './src/managers/ChannelsManager.ts' -export * from './src/managers/EmojisManager.ts' -export * from './src/managers/GatewayCache.ts' -export * from './src/managers/GuildChannelsManager.ts' -export * from './src/managers/GuildsManager.ts' -export * from './src/managers/MembersManager.ts' -export * from './src/managers/MessagesManager.ts' -export * from './src/managers/RolesManager.ts' -export * from './src/managers/UsersManager.ts' +export * from './src/managers/baseManager.ts' +export * from './src/managers/baseChildManager.ts' +export * from './src/managers/channelsManager.ts' +export * from './src/managers/emojisManager.ts' +export * from './src/managers/gatewayCache.ts' +export * from './src/managers/guildChannelsManager.ts' +export * from './src/managers/guildsManager.ts' +export * from './src/managers/membersManager.ts' +export * from './src/managers/messagesManager.ts' +export * from './src/managers/rolesManager.ts' +export * from './src/managers/usersManager.ts' export * from './src/structures/base.ts' export * from './src/structures/cdn.ts' export * from './src/structures/channel.ts' @@ -29,7 +29,7 @@ export * from './src/structures/guildVoiceChannel.ts' export * from './src/structures/invite.ts' export * from './src/structures/member.ts' export * from './src/structures/message.ts' -export * from './src/structures/MessageMentions.ts' +export * from './src/structures/messageMentions.ts' export * from './src/structures/presence.ts' export * from './src/structures/role.ts' export * from './src/structures/snowflake.ts' diff --git a/src/gateway/handlers/channelPinsUpdate.ts b/src/gateway/handlers/channelPinsUpdate.ts index da12344..3a7a0fd 100644 --- a/src/gateway/handlers/channelPinsUpdate.ts +++ b/src/gateway/handlers/channelPinsUpdate.ts @@ -6,7 +6,7 @@ export const channelPinsUpdate: GatewayEventHandler = async ( gateway: Gateway, d: ChannelPinsUpdatePayload ) => { - const after: TextChannel | void = await gateway.client.channels.get(d.channel_id) + const after: TextChannel | undefined = await gateway.client.channels.get(d.channel_id) if (after !== undefined) { const before = after.refreshFromData({ last_pin_timestamp: d.last_pin_timestamp diff --git a/src/gateway/handlers/channelUpdate.ts b/src/gateway/handlers/channelUpdate.ts index 869290b..d77777c 100644 --- a/src/gateway/handlers/channelUpdate.ts +++ b/src/gateway/handlers/channelUpdate.ts @@ -1,6 +1,6 @@ import { Channel } from '../../structures/channel.ts' import { Guild } from "../../structures/guild.ts" -import { ChannelPayload } from '../../types/channel.ts' +import { ChannelPayload, GuildChannelPayload } from '../../types/channel.ts' import getChannelByType from '../../utils/getChannelByType.ts' import { Gateway, GatewayEventHandler } from '../index.ts' @@ -13,8 +13,9 @@ export const channelUpdate: GatewayEventHandler = async ( if (oldChannel !== undefined) { await gateway.client.channels.set(d.id, d) let guild: undefined | Guild; - if((d as any).guild_id !== undefined) { - guild = await gateway.client.guilds.get((d as any).guild_id) as Guild | undefined + if('guild_id' in d) { + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + guild = await gateway.client.guilds.get((d as GuildChannelPayload).guild_id) as Guild | undefined } if (oldChannel.type !== d.type) { const channel: Channel = getChannelByType(gateway.client, d, guild) ?? oldChannel diff --git a/src/gateway/handlers/guildCreate.ts b/src/gateway/handlers/guildCreate.ts index edb858d..eb128f2 100644 --- a/src/gateway/handlers/guildCreate.ts +++ b/src/gateway/handlers/guildCreate.ts @@ -1,30 +1,30 @@ import { Gateway, GatewayEventHandler } from '../index.ts' import { Guild } from '../../structures/guild.ts' import { GuildPayload, MemberPayload } from "../../types/guild.ts" -import { MembersManager } from "../../managers/MembersManager.ts" -import { ChannelPayload } from "../../types/channel.ts" +import { MembersManager } from "../../managers/membersManager.ts" +import { GuildChannelPayload } from "../../types/channel.ts" import { RolePayload } from "../../types/role.ts" -import { RolesManager } from "../../managers/RolesManager.ts" +import { RolesManager } from "../../managers/rolesManager.ts" export const guildCreate: GatewayEventHandler = async(gateway: Gateway, d: GuildPayload) => { let guild: Guild | undefined = await gateway.client.guilds.get(d.id) if (guild !== undefined) { // It was just lazy load, so we don't fire the event as its gonna fire for every guild bot is in await gateway.client.guilds.set(d.id, d) - if ((d as any).members !== undefined) { + if (d.members !== undefined) { const members = new MembersManager(gateway.client, guild) - await members.fromPayload((d as any).members as MemberPayload[]) + await members.fromPayload(d.members as MemberPayload[]) guild.members = members } - if ((d as any).channels !== undefined) { - for (const ch of (d as any).channels as ChannelPayload[]) { - (ch as any).guild_id = d.id + if (d.channels !== undefined) { + for (const ch of d.channels as GuildChannelPayload[]) { + ch.guild_id = d.id await gateway.client.channels.set(ch.id, ch) } } - if ((d as any).roles !== undefined) { + if (d.roles !== undefined) { const roles = new RolesManager(gateway.client, guild) - await roles.fromPayload((d as any).roles as RolePayload[]) + await roles.fromPayload(d.roles as RolePayload[]) guild.roles = roles } guild.refreshFromData(d) @@ -33,18 +33,18 @@ export const guildCreate: GatewayEventHandler = async(gateway: Gateway, d: Guild guild = new Guild(gateway.client, d) if ((d as any).members !== undefined) { const members = new MembersManager(gateway.client, guild) - await members.fromPayload((d as any).members as MemberPayload[]) + await members.fromPayload(d.members as MemberPayload[]) guild.members = members } - if ((d as any).channels !== undefined) { - for (const ch of (d as any).channels as ChannelPayload[]) { + if (d.channels !== undefined) { + for (const ch of d.channels as GuildChannelPayload[]) { (ch as any).guild_id = d.id await gateway.client.channels.set(ch.id, ch) } } - if ((d as any).roles !== undefined) { + if (d.roles !== undefined) { const roles = new RolesManager(gateway.client, guild) - await roles.fromPayload((d as any).roles as RolePayload[]) + await roles.fromPayload(d.roles) guild.roles = roles } await guild.roles.fromPayload(d.roles) diff --git a/src/gateway/handlers/messageCreate.ts b/src/gateway/handlers/messageCreate.ts index 3e124fa..5e485ac 100644 --- a/src/gateway/handlers/messageCreate.ts +++ b/src/gateway/handlers/messageCreate.ts @@ -1,5 +1,5 @@ import { Message } from '../../structures/message.ts' -import { MessageMentions } from '../../structures/MessageMentions.ts' +import { MessageMentions } from '../../structures/messageMentions.ts' import { TextChannel } from '../../structures/textChannel.ts' import { User } from '../../structures/user.ts' import { MessagePayload } from '../../types/channel.ts' @@ -12,7 +12,8 @@ export const messageCreate: GatewayEventHandler = async ( let channel = await gateway.client.channels.get(d.channel_id) // Fetch the channel if not cached if (channel === undefined) - channel = (await gateway.client.channels.fetch(d.channel_id)) as any + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion + channel = (await gateway.client.channels.fetch(d.channel_id)) as TextChannel const user = new User(gateway.client, d.author) await gateway.client.users.set(d.author.id, d.author) let guild diff --git a/src/gateway/handlers/reconnect.ts b/src/gateway/handlers/reconnect.ts index 149a3ee..db3d070 100644 --- a/src/gateway/handlers/reconnect.ts +++ b/src/gateway/handlers/reconnect.ts @@ -1,5 +1,4 @@ -import { Gateway } from "../index.ts" -import { GatewayEventHandler } from "../index.ts" +import { Gateway , GatewayEventHandler } from "../index.ts" export const reconnect: GatewayEventHandler = async (gateway: Gateway, d: any) => { gateway.reconnect() diff --git a/src/gateway/handlers/resume.ts b/src/gateway/handlers/resume.ts index f4948d9..4fe58f1 100644 --- a/src/gateway/handlers/resume.ts +++ b/src/gateway/handlers/resume.ts @@ -5,6 +5,6 @@ import { Gateway, GatewayEventHandler } from '../index.ts' export const resume: GatewayEventHandler = async (gateway: Gateway, d: any) => { gateway.debug(`Session Resumed!`) gateway.client.emit('resume') - if (gateway.client.user === undefined) gateway.client.user = new User(gateway.client, await gateway.client.rest.get(CLIENT_USER()) as any) + if (gateway.client.user === undefined) gateway.client.user = new User(gateway.client, await gateway.client.rest.get(CLIENT_USER())) gateway.client.emit('ready') } \ No newline at end of file diff --git a/src/gateway/index.ts b/src/gateway/index.ts index f3de6b8..b2002d2 100644 --- a/src/gateway/index.ts +++ b/src/gateway/index.ts @@ -227,7 +227,7 @@ class Gateway { token: this.token, properties: { $os: Deno.build.os, - $browser: 'discord.deno', //TODO: Change lib name + $browser: 'discord.deno', // TODO: Change lib name $device: 'discord.deno' }, compress: true, diff --git a/src/managers/GatewayCache.ts b/src/managers/_gatewayCache.ts similarity index 100% rename from src/managers/GatewayCache.ts rename to src/managers/_gatewayCache.ts diff --git a/src/managers/BaseManager.ts b/src/managers/base.ts similarity index 100% rename from src/managers/BaseManager.ts rename to src/managers/base.ts diff --git a/src/managers/BaseChildManager.ts b/src/managers/baseChild.ts similarity index 95% rename from src/managers/BaseChildManager.ts rename to src/managers/baseChild.ts index 6f6c51e..ae4a973 100644 --- a/src/managers/BaseChildManager.ts +++ b/src/managers/baseChild.ts @@ -1,6 +1,6 @@ import { Client } from "../models/client.ts"; import { Collection } from "../utils/collection.ts"; -import { BaseManager } from "./BaseManager.ts"; +import { BaseManager } from "./base.ts"; export class BaseChildManager { client: Client diff --git a/src/managers/ChannelsManager.ts b/src/managers/channels.ts similarity index 97% rename from src/managers/ChannelsManager.ts rename to src/managers/channels.ts index 159cefd..a8a3261 100644 --- a/src/managers/ChannelsManager.ts +++ b/src/managers/channels.ts @@ -3,7 +3,7 @@ import { Channel } from "../structures/channel.ts"; import { ChannelPayload } from "../types/channel.ts"; import { CHANNEL } from "../types/endpoint.ts"; import getChannelByType from "../utils/getChannelByType.ts"; -import { BaseManager } from "./BaseManager.ts"; +import { BaseManager } from "./base.ts"; export class ChannelsManager extends BaseManager { constructor(client: Client) { diff --git a/src/managers/EmojisManager.ts b/src/managers/emojis.ts similarity index 93% rename from src/managers/EmojisManager.ts rename to src/managers/emojis.ts index c05912a..af6c83f 100644 --- a/src/managers/EmojisManager.ts +++ b/src/managers/emojis.ts @@ -2,7 +2,7 @@ import { Client } from '../models/client.ts' import { Emoji } from '../structures/emoji.ts' import { EmojiPayload } from '../types/emoji.ts' import { CHANNEL } from '../types/endpoint.ts' -import { BaseManager } from './BaseManager.ts' +import { BaseManager } from './base.ts' export class EmojisManager extends BaseManager { constructor (client: Client) { diff --git a/src/managers/GuildChannelsManager.ts b/src/managers/guildChannels.ts similarity index 93% rename from src/managers/GuildChannelsManager.ts rename to src/managers/guildChannels.ts index a7405b8..281379f 100644 --- a/src/managers/GuildChannelsManager.ts +++ b/src/managers/guildChannels.ts @@ -6,8 +6,8 @@ import { GuildTextChannel } from "../structures/guildTextChannel.ts"; import { VoiceChannel } from "../structures/guildVoiceChannel.ts"; import { GuildChannelCategoryPayload, GuildTextChannelPayload, GuildVoiceChannelPayload } from "../types/channel.ts"; import { CHANNEL } from "../types/endpoint.ts"; -import { BaseChildManager } from "./BaseChildManager.ts"; -import { ChannelsManager } from "./ChannelsManager.ts"; +import { BaseChildManager } from "./baseChild.ts"; +import { ChannelsManager } from "./channels.ts"; export type GuildChannelPayloads = GuildTextChannelPayload | GuildVoiceChannelPayload | GuildChannelCategoryPayload export type GuildChannel = GuildTextChannel | VoiceChannel | CategoryChannel diff --git a/src/managers/GuildsManager.ts b/src/managers/guilds.ts similarity index 89% rename from src/managers/GuildsManager.ts rename to src/managers/guilds.ts index 6d29571..ac298e1 100644 --- a/src/managers/GuildsManager.ts +++ b/src/managers/guilds.ts @@ -2,8 +2,8 @@ import { Client } from "../models/client.ts"; import { Guild } from "../structures/guild.ts"; import { GUILD } from "../types/endpoint.ts"; import { GuildPayload, MemberPayload } from "../types/guild.ts"; -import { BaseManager } from "./BaseManager.ts"; -import { MembersManager } from "./MembersManager.ts"; +import { BaseManager } from "./base.ts"; +import { MembersManager } from "./members.ts"; export class GuildManager extends BaseManager { constructor (client: Client) { diff --git a/src/managers/MembersManager.ts b/src/managers/members.ts similarity index 95% rename from src/managers/MembersManager.ts rename to src/managers/members.ts index 964749a..a659333 100644 --- a/src/managers/MembersManager.ts +++ b/src/managers/members.ts @@ -3,7 +3,7 @@ import { Guild } from "../structures/guild.ts"; import { Member } from "../structures/member.ts"; import { GUILD_MEMBER } from "../types/endpoint.ts"; import { MemberPayload } from "../types/guild.ts"; -import { BaseManager } from "./BaseManager.ts"; +import { BaseManager } from "./base.ts"; export class MembersManager extends BaseManager { guild: Guild diff --git a/src/managers/MessagesManager.ts b/src/managers/messages.ts similarity index 94% rename from src/managers/MessagesManager.ts rename to src/managers/messages.ts index 0e6aa5e..7364d91 100644 --- a/src/managers/MessagesManager.ts +++ b/src/managers/messages.ts @@ -1,11 +1,11 @@ import { Client } from "../models/client.ts"; import { Message } from "../structures/message.ts"; -import { MessageMentions } from "../structures/MessageMentions.ts"; +import { MessageMentions } from "../structures/messageMentions.ts"; import { TextChannel } from "../structures/textChannel.ts"; import { User } from "../structures/user.ts"; import { MessagePayload } from "../types/channel.ts"; import { CHANNEL_MESSAGE } from "../types/endpoint.ts"; -import { BaseManager } from "./BaseManager.ts"; +import { BaseManager } from "./base.ts"; export class MessagesManager extends BaseManager { constructor (client: Client) { diff --git a/src/managers/RolesManager.ts b/src/managers/roles.ts similarity index 95% rename from src/managers/RolesManager.ts rename to src/managers/roles.ts index a6e1d44..9e88a9c 100644 --- a/src/managers/RolesManager.ts +++ b/src/managers/roles.ts @@ -3,7 +3,7 @@ import { Guild } from '../structures/guild.ts' import { Role } from '../structures/role.ts' import { GUILD_ROLE } from '../types/endpoint.ts' import { RolePayload } from '../types/role.ts' -import { BaseManager } from './BaseManager.ts' +import { BaseManager } from './base.ts' export class RolesManager extends BaseManager { guild: Guild diff --git a/src/managers/UsersManager.ts b/src/managers/users.ts similarity index 93% rename from src/managers/UsersManager.ts rename to src/managers/users.ts index e96b0a8..8a428b1 100644 --- a/src/managers/UsersManager.ts +++ b/src/managers/users.ts @@ -2,7 +2,7 @@ import { Client } from '../models/client.ts' import { User } from '../structures/user.ts' import { USER } from '../types/endpoint.ts' import { UserPayload } from '../types/user.ts' -import { BaseManager } from './BaseManager.ts' +import { BaseManager } from './base.ts' export class UserManager extends BaseManager { constructor (client: Client) { diff --git a/src/models/client.ts b/src/models/client.ts index 09d1750..5c2f63a 100644 --- a/src/models/client.ts +++ b/src/models/client.ts @@ -3,12 +3,12 @@ import { GatewayIntents } from '../types/gateway.ts' import { Gateway } from '../gateway/index.ts' import { RESTManager } from './rest.ts' import EventEmitter from 'https://deno.land/std@0.74.0/node/events.ts' -import { DefaultCacheAdapter, ICacheAdapter } from "./CacheAdapter.ts" -import { UserManager } from "../managers/UsersManager.ts" -import { GuildManager } from "../managers/GuildsManager.ts" -import { EmojisManager } from "../managers/EmojisManager.ts" -import { ChannelsManager } from "../managers/ChannelsManager.ts" -import { MessagesManager } from "../managers/MessagesManager.ts" +import { DefaultCacheAdapter, ICacheAdapter } from "./cacheAdapter.ts" +import { UserManager } from "../managers/usersManager.ts" +import { GuildManager } from "../managers/guildsManager.ts" +import { EmojisManager } from "../managers/emojisManager.ts" +import { ChannelsManager } from "../managers/channelsManager.ts" +import { MessagesManager } from "../managers/messagesManager.ts" import { ActivityGame, ClientActivity, ClientPresence } from "../structures/presence.ts" /** Some Client Options to modify behaviour */ diff --git a/src/structures/guild.ts b/src/structures/guild.ts index 7dc629f..480292e 100644 --- a/src/structures/guild.ts +++ b/src/structures/guild.ts @@ -6,8 +6,8 @@ import { Emoji } from './emoji.ts' import { VoiceState } from './voiceState.ts' import cache from '../models/cache.ts' import { RolesManager } from "../managers/RolesManager.ts" -import { GuildChannelsManager } from "../managers/GuildChannelsManager.ts" -import { MembersManager } from "../managers/MembersManager.ts" +import { GuildChannelsManager } from "../managers/guildChannelsManager.ts" +import { MembersManager } from "../managers/membersManager.ts" export class Guild extends Base { id: string diff --git a/src/structures/message.ts b/src/structures/message.ts index aea39bc..cccaf3c 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -14,7 +14,7 @@ import { User } from './user.ts' import { Member } from './member.ts' import { Embed } from './embed.ts' import { CHANNEL_MESSAGE } from '../types/endpoint.ts' -import { MessageMentions } from "./MessageMentions.ts" +import { MessageMentions } from "./messageMentions.ts" import { TextChannel } from "./textChannel.ts" import { DMChannel } from "./dmChannel.ts" import { Guild } from "./guild.ts" diff --git a/src/structures/textChannel.ts b/src/structures/textChannel.ts index ee06f28..3955fa2 100644 --- a/src/structures/textChannel.ts +++ b/src/structures/textChannel.ts @@ -3,7 +3,7 @@ import { MessageOption, TextChannelPayload } from '../types/channel.ts' import { CHANNEL_MESSAGE, CHANNEL_MESSAGES } from '../types/endpoint.ts' import { Channel } from './channel.ts' import { Message } from './message.ts' -import { MessageMentions } from './MessageMentions.ts' +import { MessageMentions } from './messageMentions.ts' export class TextChannel extends Channel { lastMessageID?: string @@ -24,7 +24,7 @@ export class TextChannel extends Channel { } async send (text?: string, option?: MessageOption): Promise { - if (text !== undefined && option !== undefined) { + if (text === undefined && option === undefined) { throw new Error('Either text or option is necessary.') } const resp = await this.client.rest.post(CHANNEL_MESSAGES(this.id), { diff --git a/src/test/index.ts b/src/test/index.ts index a928838..dc925ec 100644 --- a/src/test/index.ts +++ b/src/test/index.ts @@ -2,11 +2,14 @@ import { Client } from '../models/client.ts' import { GatewayIntents } from '../types/gateway.ts' import { TOKEN } from './config.ts' import { Message } from "../structures/message.ts" -import { RedisCacheAdapter } from "../models/CacheAdapter.ts" +import { DefaultCacheAdapter } from "../models/cacheAdapter.ts" import { ClientPresence } from "../structures/presence.ts" import { Member } from "../structures/member.ts" import { Role } from "../structures/role.ts" -import { GuildChannel } from "../managers/GuildChannelsManager.ts" +import { GuildChannel } from "../managers/guildChannels.ts" +import { TextChannel } from "../structures/textChannel.ts" +import { Embed } from "../structures/embed.ts" +import { Guild } from "../structures/guild.ts" const bot = new Client({ presence: new ClientPresence({ @@ -17,10 +20,7 @@ const bot = new Client({ }), }) -bot.setAdapter(new RedisCacheAdapter(bot, { - hostname: "127.0.0.1", - port: 6379 -})) +bot.setAdapter(new DefaultCacheAdapter(bot)) bot.on('ready', () => { console.log(`[Login] Logged in as ${bot.user?.tag}!`) @@ -32,6 +32,15 @@ bot.on('ready', () => { bot.on('debug', console.log) +bot.on('channelPinsUpdate', (before: TextChannel, after: TextChannel) => { + console.log(before.send('', { + embed: new Embed({ + title: 'Test', + description: 'Test Embed' + }) + })) +}) + bot.on('messageCreate', async (msg: Message) => { if (msg.author.bot === true) return if (msg.content === "!ping") { @@ -44,7 +53,7 @@ bot.on('messageCreate', async (msg: Message) => { msg.channel.send("Member List:\n" + data) } else if (msg.content === "!guilds") { const guilds = await msg.client.guilds.collection() - msg.channel.send("Guild List:\n" + (guilds.array().map((c, i: number) => { + msg.channel.send("Guild List:\n" + (guilds.array().map((c: Guild, i: number) => { return `${i + 1}. ${c.name} - ${c.memberCount} members` }).join("\n") as string)) } else if (msg.content === "!roles") { diff --git a/src/types/channel.ts b/src/types/channel.ts index 01aa041..58ba24d 100644 --- a/src/types/channel.ts +++ b/src/types/channel.ts @@ -99,9 +99,9 @@ export interface MessagePayload { } export interface MessageOption { - tts: boolean + tts?: boolean embed: Embed - file: Attachment + file?: Attachment allowedMention?: { parse: ['everyone', 'users', 'roles'] roles: string[]