-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
580 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ client.on('message', (message) => { | |
}); | ||
} | ||
}); | ||
|
||
client.login('token'); | ||
``` | ||
|
||
# Features | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
|
||
export { GuildChannel } from './src/models/channels/GuildChannel.ts'; | ||
export { Client } from './src/client/Client.ts'; | ||
export { GuildChannel } from "./src/models/channels/GuildChannel.ts"; | ||
export { Client } from "./src/client/Client.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import EventEmitter from 'https://deno.land/[email protected]/node/events.ts'; | ||
import WebSocketManager from '../client/ws/WebSocket.ts'; | ||
import ClientUser from './ClientUser.ts'; | ||
import Guild from '../models/Guild.ts'; | ||
import RestAPIHandler from '../client/rest/RestAPIHandler.ts'; | ||
import Collection from '../models/Collection.ts'; | ||
import { BaseChannel } from '../models/channels/BaseChannel.ts'; | ||
import { GuildChannel } from '../models/channels/GuildChannel.ts'; | ||
import { TextChannel } from '../models/channels/TextChannel.ts'; | ||
import Message from '../models/Message.ts'; | ||
import User from '../models/User.ts'; | ||
import EventEmitter from "https://deno.land/[email protected]/node/events.ts"; | ||
import WebSocketManager from "../client/ws/WebSocket.ts"; | ||
import ClientUser from "./ClientUser.ts"; | ||
import Guild from "../models/Guild.ts"; | ||
import RestAPIHandler from "../client/rest/RestAPIHandler.ts"; | ||
import Collection from "../models/Collection.ts"; | ||
import { BaseChannel } from "../models/channels/BaseChannel.ts"; | ||
import { GuildChannel } from "../models/channels/GuildChannel.ts"; | ||
import { TextChannel } from "../models/channels/TextChannel.ts"; | ||
import Message from "../models/Message.ts"; | ||
import User from "../models/User.ts"; | ||
|
||
interface ClientEvents { | ||
channelCreate: (channel: GuildChannel) => void; | ||
|
@@ -25,12 +25,17 @@ interface ClientEvents { | |
} | ||
|
||
export declare interface Client { | ||
on<Event extends keyof ClientEvents>(event: Event, listener: ClientEvents[Event]): this; | ||
emit<Event extends keyof ClientEvents>(event: Event, ...args: Parameters<ClientEvents[Event]>): boolean; | ||
on<Event extends keyof ClientEvents>( | ||
event: Event, | ||
listener: ClientEvents[Event], | ||
): this; | ||
emit<Event extends keyof ClientEvents>( | ||
event: Event, | ||
...args: Parameters<ClientEvents[Event]> | ||
): boolean; | ||
} | ||
|
||
export class Client extends EventEmitter { | ||
|
||
private _user!: ClientUser; | ||
private _guilds: Collection<string, Guild> = new Collection(); | ||
private _channels: Collection<string, BaseChannel> = new Collection(); | ||
|
@@ -67,10 +72,10 @@ export class Client extends EventEmitter { | |
get channels(): Collection<string, BaseChannel> { | ||
return this._channels; | ||
} | ||
|
||
get users(): Collection<string, User> { | ||
return this._users; | ||
} | ||
} | ||
|
||
export default Client; | ||
export default Client; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,88 @@ | ||
import Client from '../Client.ts'; | ||
import { headers } from '../../constants/Payloads.ts'; | ||
import { Constants, ENDPOINTS } from '../../constants/Constants.ts'; | ||
import Message from '../../models/Message.ts'; | ||
import { MessageOptions } from '../../typedefs/MessageOptions.ts'; | ||
import Client from "../Client.ts"; | ||
import { headers } from "../../constants/Payloads.ts"; | ||
import { Constants, ENDPOINTS } from "../../constants/Constants.ts"; | ||
import Message from "../../models/Message.ts"; | ||
import { MessageOptions } from "../../typedefs/MessageOptions.ts"; | ||
|
||
export default class RestAPIHandler { | ||
|
||
private _token: string = ''; | ||
private _token: string = ""; | ||
|
||
constructor(private client: Client) { | ||
Object.defineProperty(this, '_token', { | ||
enumerable: false | ||
}) | ||
Object.defineProperty(this, "_token", { | ||
enumerable: false, | ||
}); | ||
} | ||
|
||
async fetchGuilds() { | ||
const response = await fetch(`${Constants.API}/${ENDPOINTS.USER_GUILDS}`, { headers }); | ||
const response = await fetch( | ||
`${Constants.API}/${ENDPOINTS.USER_GUILDS}`, | ||
{ headers }, | ||
); | ||
return response.json(); | ||
} | ||
|
||
async fetchGuild(id: string) { | ||
const response = await fetch(`${Constants.API}/${ENDPOINTS.GUILDS}/${id}?with_counts=true`, { headers }); | ||
const response = await fetch( | ||
`${Constants.API}/${ENDPOINTS.GUILDS}/${id}?with_counts=true`, | ||
{ headers }, | ||
); | ||
return response.json(); | ||
} | ||
|
||
async fetchChannels(id: string) { | ||
const response = await fetch(`${Constants.API}/${ENDPOINTS.GUILDS}/${id}/${ENDPOINTS.CHANNELS}`, { headers }); | ||
const response = await fetch( | ||
`${Constants.API}/${ENDPOINTS.GUILDS}/${id}/${ENDPOINTS.CHANNELS}`, | ||
{ headers }, | ||
); | ||
return response.json(); | ||
} | ||
|
||
async fetchChannel(id: string) { | ||
const response = await fetch(`${Constants.API}/${ENDPOINTS.CHANNELS}/${id}`, { headers }); | ||
const response = await fetch( | ||
`${Constants.API}/${ENDPOINTS.CHANNELS}/${id}`, | ||
{ headers }, | ||
); | ||
return response.json(); | ||
} | ||
|
||
async fetchGuildMember(guildId: string, userId: string) { | ||
const response = await fetch(`${Constants.API}/${ENDPOINTS.GUILDS}/${guildId}/${ENDPOINTS.MEMBERS}/${userId}`, { headers }); | ||
const response = await fetch( | ||
`${Constants.API}/${ENDPOINTS.GUILDS}/${guildId}/${ENDPOINTS.MEMBERS}/${userId}`, | ||
{ headers }, | ||
); | ||
return response.json(); | ||
} | ||
|
||
async fetchGuildMembers(guildId: string, count: number) { | ||
const response = await fetch(`${Constants.API}/${ENDPOINTS.GUILDS}/${guildId}/${ENDPOINTS.MEMBERS}?limit=${count}`, { headers }); | ||
const response = await fetch( | ||
`${Constants.API}/${ENDPOINTS.GUILDS}/${guildId}/${ENDPOINTS.MEMBERS}?limit=${count}`, | ||
{ headers }, | ||
); | ||
return response.json(); | ||
} | ||
|
||
async fetchUser(userId: string) { | ||
const response = await fetch(`${Constants.API}/${ENDPOINTS.USERS}/${userId}`, { headers }); | ||
const response = await fetch( | ||
`${Constants.API}/${ENDPOINTS.USERS}/${userId}`, | ||
{ headers }, | ||
); | ||
return response.json(); | ||
} | ||
|
||
async createMessage(options: MessageOptions, id: string) { | ||
const response = await fetch(`${Constants.API}/${ENDPOINTS.CHANNELS}/${id}/${ENDPOINTS.MESSAGES}`, { | ||
method: 'POST', | ||
headers, | ||
body: JSON.stringify(options), | ||
}); | ||
const response = await fetch( | ||
`${Constants.API}/${ENDPOINTS.CHANNELS}/${id}/${ENDPOINTS.MESSAGES}`, | ||
{ | ||
method: "POST", | ||
headers, | ||
body: JSON.stringify(options), | ||
}, | ||
); | ||
return response.json(); | ||
} | ||
|
||
|
||
set token(token: string) { | ||
this._token = token; | ||
headers.Authorization = `Bot ${this._token}`; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
|
||
import { connectWebSocket, WebSocket } from "https://deno.land/std/ws/mod.ts"; | ||
import EventEmitter from 'https://deno.land/[email protected]/node/events.ts'; | ||
import { Constants, OPCODE } from '../../constants/Constants.ts'; | ||
import { Identify, Heartbeat } from '../../constants/Payloads.ts'; | ||
import { Payload } from '../../constants/Payloads.ts'; | ||
import EventEmitter from "https://deno.land/[email protected]/node/events.ts"; | ||
import { Constants, OPCODE } from "../../constants/Constants.ts"; | ||
import { Identify, Heartbeat } from "../../constants/Payloads.ts"; | ||
import { Payload } from "../../constants/Payloads.ts"; | ||
import Client from "../Client.ts"; | ||
|
||
export default class WebSocketManager extends EventEmitter { | ||
|
||
private interval: number = 0; | ||
private socket!: WebSocket; | ||
private ackReceived: boolean = false; | ||
|
@@ -32,12 +30,14 @@ export default class WebSocketManager extends EventEmitter { | |
this.ackReceived = true; | ||
break; | ||
case OPCODE.NINE: | ||
console.log('Invalid gateway session'); | ||
console.log("Invalid gateway session"); | ||
break; | ||
} | ||
if (event) { | ||
try { | ||
const { default: module } = await import(`../../handlers/${event}.ts`); | ||
const { default: module } = await import( | ||
`../../handlers/${event}.ts` | ||
); | ||
module(this.client, payload); | ||
} catch (err) { | ||
// console.log(err); | ||
|
@@ -60,4 +60,4 @@ export default class WebSocketManager extends EventEmitter { | |
Identify.d.token = token; | ||
this.socket.send(JSON.stringify(Identify)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
export enum Events { | ||
READY = 'ready', | ||
RESUMED = 'resumed', | ||
RECONNECT = 'reconnect', | ||
INVALID_SESSION = 'invalid', | ||
CHANNEL_CREATE = 'channelCreate', | ||
CHANNEL_UPDATE = 'channelUpdate', | ||
CHANNEL_DELETE = 'channelDelete', | ||
CHANNEL_PINS_UPDATE = 'channelPinsUpdate', | ||
GUILD_CREATE = 'guildCreate', | ||
GUILD_UPDATE = 'guildUpdate', | ||
GUILD_DELETE = 'guildDelete', | ||
GUILD_BAN_ADD = 'guildBanAdd', | ||
GUILD_BAN_REMOVE = 'guildBanRemove', | ||
GUILD_EMOJIS_UPDATE = 'guildEmojisUpdate', | ||
GUILD_INTEGRATIONS_UPDATE = 'guildIntegrationsUpdate', | ||
GUILD_MEMBER_ADD = 'guildMemberAdd', | ||
GUILD_MEMBER_REMOVE = 'guildMemberRemove', | ||
GUILD_MEMBER_UPDATE = 'guildMemberUpdate', | ||
GUILD_MEMBERS_CHUNK = 'guildMemberAdd', | ||
GUILD_ROLE_CREATE = 'guildRoleCreate', | ||
GUILD_ROLE_UPDATE = 'guildRoleUpdate', | ||
GUILD_ROLE_DELETE = 'guildRoleDelete', | ||
INVITE_CREATE = 'inviteCreate', | ||
INVITE_DELETE = 'inviteDelete', | ||
MESSAGE_CREATE = 'message', | ||
MESSAGE_UPDATE = 'messageUpdate', | ||
MESSAGE_DELETE = 'messageDelete', | ||
MESSAGE_DELETE_BULK = 'messageDeleteBulk', | ||
MESSAGE_REACTION_ADD = 'messageReactionAdd', | ||
MESSAGE_REACTION_REMOVE = 'messageReactionRemove', | ||
MESSAGE_REACTION_REMOVE_ALL = 'messageReactionRemoveAll', | ||
MESSAGE_REACTION_REMOVE_EMOJI = 'messageReactionRemoveEmoji', | ||
PRESENCE_UPDATE = 'presenceUpdate', | ||
TYPING_START = 'typingStart', | ||
USER_UPDATE = 'userUpdate', | ||
VOICE_STATE_UPDATE = 'voiceStateUpdate', | ||
VOICE_SERVER_UPDATE = 'voiceStateUpdate', | ||
WEBHOOKS_UPDATE = 'webhooksUpdate', | ||
} | ||
READY = "ready", | ||
RESUMED = "resumed", | ||
RECONNECT = "reconnect", | ||
INVALID_SESSION = "invalid", | ||
CHANNEL_CREATE = "channelCreate", | ||
CHANNEL_UPDATE = "channelUpdate", | ||
CHANNEL_DELETE = "channelDelete", | ||
CHANNEL_PINS_UPDATE = "channelPinsUpdate", | ||
GUILD_CREATE = "guildCreate", | ||
GUILD_UPDATE = "guildUpdate", | ||
GUILD_DELETE = "guildDelete", | ||
GUILD_BAN_ADD = "guildBanAdd", | ||
GUILD_BAN_REMOVE = "guildBanRemove", | ||
GUILD_EMOJIS_UPDATE = "guildEmojisUpdate", | ||
GUILD_INTEGRATIONS_UPDATE = "guildIntegrationsUpdate", | ||
GUILD_MEMBER_ADD = "guildMemberAdd", | ||
GUILD_MEMBER_REMOVE = "guildMemberRemove", | ||
GUILD_MEMBER_UPDATE = "guildMemberUpdate", | ||
GUILD_MEMBERS_CHUNK = "guildMemberAdd", | ||
GUILD_ROLE_CREATE = "guildRoleCreate", | ||
GUILD_ROLE_UPDATE = "guildRoleUpdate", | ||
GUILD_ROLE_DELETE = "guildRoleDelete", | ||
INVITE_CREATE = "inviteCreate", | ||
INVITE_DELETE = "inviteDelete", | ||
MESSAGE_CREATE = "message", | ||
MESSAGE_UPDATE = "messageUpdate", | ||
MESSAGE_DELETE = "messageDelete", | ||
MESSAGE_DELETE_BULK = "messageDeleteBulk", | ||
MESSAGE_REACTION_ADD = "messageReactionAdd", | ||
MESSAGE_REACTION_REMOVE = "messageReactionRemove", | ||
MESSAGE_REACTION_REMOVE_ALL = "messageReactionRemoveAll", | ||
MESSAGE_REACTION_REMOVE_EMOJI = "messageReactionRemoveEmoji", | ||
PRESENCE_UPDATE = "presenceUpdate", | ||
TYPING_START = "typingStart", | ||
USER_UPDATE = "userUpdate", | ||
VOICE_STATE_UPDATE = "voiceStateUpdate", | ||
VOICE_SERVER_UPDATE = "voiceStateUpdate", | ||
WEBHOOKS_UPDATE = "webhooksUpdate", | ||
} |
Oops, something went wrong.