-
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.
Parsed Guilds into Map for Client.guilds property
- Loading branch information
Showing
19 changed files
with
287 additions
and
77 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.env | ||
.denon.json |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# What is Katana? | ||
|
||
Katana is an unofficial Discord library that allows you to build Discord Bots. | ||
|
||
# Usage | ||
|
||
```TS | ||
import { Client } from 'https://deno.land/x/katana/mod.ts' | ||
|
||
const client = new Client(); | ||
|
||
client.on('ready', () => { | ||
console.log('Bot has logged in!'); | ||
}); | ||
``` | ||
|
||
# Features | ||
|
||
# Contributing | ||
|
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
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,39 @@ | ||
import EventEmitter from 'https://deno.land/[email protected]/node/events.ts'; | ||
import WebSocketManager from '../ws/Websocket.ts'; | ||
import ClientUser from './ClientUser.ts'; | ||
import Guild from '../models/Guild.ts'; | ||
|
||
export default class Client extends EventEmitter { | ||
export class Client extends EventEmitter { | ||
|
||
private _user!: ClientUser; | ||
private _token!: string; | ||
private _guilds: Map<string, Guild> = new Map(); | ||
|
||
private socket: WebSocketManager = new WebSocketManager(this); | ||
async login(token: string): Promise<void> { | ||
try { | ||
this._token = token; | ||
await this.socket.connect(token); | ||
console.log(this.token); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
|
||
get user() { | ||
return this._user; | ||
} | ||
|
||
set user(user: ClientUser) { | ||
this._user = user; | ||
} | ||
|
||
get token() { | ||
return this._token; | ||
} | ||
|
||
get guilds() { | ||
return this._guilds; | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -9,6 +9,6 @@ export default class ClientUser { | |
private bot: boolean, | ||
private avatar: string, | ||
) { | ||
|
||
} | ||
} |
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_SESSION', | ||
CHANNEL_CREATE = 'CHANNEL_CREATE', | ||
CHANNEL_UPDATE = 'CHANNEL_UPDATE', | ||
CHANNEL_DELETE = 'CHANNEL_DELETE', | ||
CHANNEL_PINS_UPDATE = 'CHANNEL_PINS_UPDATE', | ||
GUILD_CREATE = 'GUILD_CREATE', | ||
GUILD_UPDATE = 'GUILD_UPDATE', | ||
GUILD_DELETE = 'GUILD_DELETE', | ||
GUILD_BAN_ADD = 'GUILD_BAN_ADD', | ||
GUILD_BAN_REMOVE = 'GUILD_BAN_REMOVE', | ||
GUILD_EMOJIS_UPDATE = 'GUILD_EMOJIS_UPDATE', | ||
GUILD_INTEGRATIONS_UPDATE = 'GUILD_INTEGRATIONS_UPDATE', | ||
GUILD_MEMBER_ADD = 'GUILD_MEMBER_ADD', | ||
GUILD_MEMBER_REMOVE = 'GUILD_MEMBER_REMOVE', | ||
GUILD_MEMBER_UPDATE = 'GUILD_MEMBER_UPDATE', | ||
GUILD_MEMBERS_CHUNK = 'GUILD_MEMBERS_CHUNK', | ||
GUILD_ROLE_CREATE = 'GUILD_ROLE_CREATE', | ||
GUILD_ROLE_UPDATE = 'GUILD_ROLE_UPDATE', | ||
GUILD_ROLE_DELETE = 'GUILD_ROLE_DELETE', | ||
INVITE_CREATE = 'INVITE_CREATE', | ||
INVITE_DELETE = 'INVITE_DELETE', | ||
MESSAGE_CREATE = 'MESSAGE_CREATE', | ||
MESSAGE_UPDATE = 'MESSAGE_UPDATE', | ||
MESSAGE_DELETE = 'MESSAGE_DELETE', | ||
MESSAGE_DELETE_BULK = 'MESSAGE_DELETE_BULK', | ||
MESSAGE_REACTION_ADD = 'MESSAGE_REACTION_ADD', | ||
MESSAGE_REACTION_REMOVE = 'MESSAGE_REACTION_REMOVE', | ||
MESSAGE_REACTION_REMOVE_ALL = 'MESSAGE_REACTION_REMOVE_ALL', | ||
MESSAGE_REACTION_REMOVE_EMOJI = 'MESSAGE_REACTION_REMOVE_EMOJI', | ||
PRESENCE_UPDATE = 'PRESENCE_UPDATE', | ||
TYPING_START = 'TYPING_START', | ||
USER_UPDATE = 'USER_UPDATE', | ||
VOICE_STATE_UPDATE = 'VOICE_STATE_UPDATE', | ||
VOICE_SERVER_UPDATE = 'VOICE_SERVER_UPDATE', | ||
WEBHOOKS_UPDATE = 'WEBHOOKS_UPDATE', | ||
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 = 'messageCreate', | ||
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', | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Client from "../client/Client.ts"; | ||
import { Payload } from "../interfaces/Payload.ts"; | ||
import { Events } from '../constants/Events.ts'; | ||
|
||
export default function(client: Client, payload: Payload) { | ||
client.emit(Events.MESSAGE_CREATE); | ||
} |
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,7 +1,85 @@ | ||
import Client from "../client/Client.ts"; | ||
import { Payload } from "../interfaces/Payload.ts"; | ||
import { Events } from '../constants/Events.ts'; | ||
import RestAPIHandler from '../rest/RestAPIHandler.ts'; | ||
import ClientUser from "../client/ClientUser.ts"; | ||
import Guild from "../models/Guild.ts"; | ||
import Role from "../models/Role.ts"; | ||
|
||
export default async function (client: Client, payload: Payload) { | ||
|
||
const { user, guilds } = payload.d; | ||
|
||
client.user = new ClientUser( | ||
user.username, | ||
user.discriminator, | ||
user.verified, | ||
user.id, | ||
user.flags, | ||
user.email, | ||
user.bot, | ||
user.avatar | ||
); | ||
|
||
const now = performance.now(); | ||
|
||
for (const g of guilds) { | ||
const guild: any = await RestAPIHandler.fetchGuild(client.token, g.id); | ||
const rolesArray = guild.roles; | ||
const roles = new Map(); | ||
for (const role of rolesArray) { | ||
roles.set(role.id, new Role( | ||
role.id, | ||
role.name, | ||
role.color, | ||
role.hoist, | ||
role.position, | ||
role.permissions, | ||
role.managed, | ||
role.mentionable | ||
)); | ||
} | ||
|
||
const newGuild = new Guild( | ||
guild.id, | ||
guild.name, | ||
guild.icon, | ||
guild.description, | ||
guild.splash, | ||
guild.discovery_splash, | ||
guild.features, | ||
guild.emojis, | ||
guild.banner, | ||
guild.owner_id, | ||
guild.application_id, | ||
guild.region, | ||
guild.afk_channel_id, | ||
guild.afk_timeout, | ||
guild.system_channel_id, | ||
guild.widget_enabled, | ||
guild.widget_channel_id, | ||
guild.verification_level, | ||
roles, | ||
guild.default_message_notifications, | ||
guild.mfa_level, | ||
guild.explicit_content_filter, | ||
guild.max_presences, | ||
guild.max_members, | ||
guild.max_video_channel_users, | ||
guild.vanity_url_code, | ||
guild.premium_tier, | ||
guild.premium_subscription_count, | ||
guild.system_channel_flags, | ||
guild.preferred_locale, | ||
guild.rules_channel_id, | ||
guild.public_updates_channel_id, | ||
guild.embed_enabled, | ||
guild.embed_channel_id, | ||
); | ||
client.guilds.set(newGuild.id, newGuild); | ||
} | ||
const end = performance.now(); | ||
|
||
console.log(`Duration: ${end-now}ms`) | ||
client.emit(Events.READY); | ||
} |
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,6 +1,9 @@ | ||
import Client from '../src/client/Client.ts'; | ||
import EventQueue from './structures/EventQueue.ts'; | ||
import { Client } from '../src/client/Client.ts'; | ||
import "https://deno.land/x/dotenv/load.ts"; | ||
|
||
const client = new Client(); | ||
client.login(Deno.env.get('BOT_TOKEN')!.toString()); | ||
|
||
client.login('token'); | ||
client.on('ready', () => { | ||
console.log('Bot has logged in.'); | ||
}); |
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Role from "./Role.ts"; | ||
|
||
export default class Guild { | ||
|
||
constructor( | ||
private _id: string, | ||
private name: string, | ||
private icon: string, | ||
private description: string, | ||
private splash: string, | ||
private discoverySplash: string, | ||
private features: Array<any>, | ||
private emojis: Array<any>, | ||
private banner: string, | ||
private ownerId: string, | ||
private applicationId: string, | ||
private region: string, | ||
private afkChannelId: string, | ||
private afkTimeout: string, | ||
private systemChannelId: string, | ||
private widgetEnabled: boolean, | ||
private widgetChannelId: string, | ||
private verificationLevel: number, | ||
private _roles: Map<string, Role> = new Map(), | ||
private defaultMessageNotifications: number, | ||
private mfaLevel: number, | ||
private explicitContentFilter: number, | ||
private maxPresences: number, | ||
private maxMembers: number, | ||
private maxVideoChannelUsers: number, | ||
private vanityUrl: string, | ||
private premiumTier: number, | ||
private premiumSubscriptionCount: number, | ||
private systemChannelFlags: number, | ||
private preferredLocale: string, | ||
private rulesChannelId: string, | ||
private publicUpdatesChannelId: string, | ||
private embedEnabled: boolean, | ||
private embedChannelId: string | ||
) { | ||
|
||
} | ||
|
||
public get id(): string { | ||
return this._id; | ||
} | ||
|
||
public get roles(): Map<string, Role> { | ||
return this._roles; | ||
} | ||
} |
Oops, something went wrong.