From b844a053e542342c30beba20a52d379ec06ecfc2 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 1 Feb 2021 14:07:54 +0530 Subject: [PATCH 1/2] remove opine and oak deps and start adding tests --- deps.ts | 2 +- examples/ping.ts | 29 +++++---------------- src/models/slashClient.ts | 15 ++++------- test/mod.ts | 55 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 33 deletions(-) create mode 100644 test/mod.ts diff --git a/deps.ts b/deps.ts index bb3a39d..f7c495c 100644 --- a/deps.ts +++ b/deps.ts @@ -1,6 +1,6 @@ export { EventEmitter } from 'https://deno.land/x/event@0.2.1/mod.ts' export { unzlib } from 'https://raw.githubusercontent.com/DjDeveloperr/denoflate/master/mod.ts' -export { fetchAuto } from 'https://raw.githubusercontent.com/DjDeveloperr/fetch-base64/main/mod.ts' +export { fetchAuto } from 'https://deno.land/x/fetchbase64@1.0.0/mod.ts' export { parse } from 'https://deno.land/x/mutil@0.1.2/mod.ts' export { connect } from 'https://deno.land/x/redis@v0.14.1/mod.ts' export type { diff --git a/examples/ping.ts b/examples/ping.ts index 15eafce..5f68a82 100644 --- a/examples/ping.ts +++ b/examples/ping.ts @@ -1,4 +1,4 @@ -import { Client, Message, Intents } from '../mod.ts' +import { Client, Message, GatewayIntents } from '../mod.ts' const client = new Client() @@ -13,7 +13,7 @@ client.on('messageCreate', (msg: Message) => { } }) -console.log('harmony - ping example') +console.log('Harmony - Ping Example') const token = prompt('Input Bot Token:') if (token === null) { @@ -21,23 +21,8 @@ if (token === null) { Deno.exit() } -const intents = prompt( - 'Input Intents (0 = All, 1 = Presence, 2 = Server Members, 3 = None):' -) -if (intents === null || !['0', '1', '2', '3'].includes(intents)) { - console.log('No intents provided') - Deno.exit() -} - -let ints -if (intents === '0') { - ints = Intents.All -} else if (intents === '1') { - ints = Intents.Presence -} else if (intents === '2') { - ints = Intents.GuildMembers -} else { - ints = Intents.None -} - -client.connect(token, ints) +client.connect(token, [ + GatewayIntents.GUILD_MESSAGES, + GatewayIntents.GUILDS, + GatewayIntents.DIRECT_MESSAGES +]) diff --git a/src/models/slashClient.ts b/src/models/slashClient.ts index 4a64eae..3318e05 100644 --- a/src/models/slashClient.ts +++ b/src/models/slashClient.ts @@ -14,11 +14,6 @@ import { RESTManager } from './rest.ts' import { SlashModule } from './slashModule.ts' import { verify as edverify } from 'https://deno.land/x/ed25519/mod.ts' import { Buffer } from 'https://deno.land/std@0.80.0/node/buffer.ts' -import type { - Request as ORequest, - Response as OResponse -} from 'https://deno.land/x/opine@1.0.0/src/types.ts' -import type { Context } from 'https://deno.land/x/oak@v6.4.0/mod.ts' export class SlashCommand { slash: SlashCommandsManager @@ -528,7 +523,7 @@ export class SlashClient { ).catch(() => false) } - async verifyOpineRequest(req: ORequest): Promise { + async verifyOpineRequest(req: any): Promise { const signature = req.headers.get('x-signature-ed25519') const timestamp = req.headers.get('x-signature-timestamp') const contentLength = req.headers.get('content-length') @@ -547,8 +542,8 @@ export class SlashClient { /** Middleware to verify request in Opine framework. */ async verifyOpineMiddleware( - req: ORequest, - res: OResponse, + req: any, + res: any, next: CallableFunction ): Promise { const verified = await this.verifyOpineRequest(req) @@ -560,7 +555,7 @@ export class SlashClient { // TODO: create verifyOakMiddleware too /** Method to verify Request from Oak server "Context". */ - async verifyOakRequest(ctx: Context): Promise { + async verifyOakRequest(ctx: any): Promise { const signature = ctx.request.headers.get('x-signature-ed25519') const timestamp = ctx.request.headers.get('x-signature-timestamp') const contentLength = ctx.request.headers.get('content-length') @@ -576,7 +571,7 @@ export class SlashClient { const body = await ctx.request.body().value - const verified = await this.verifyKey(body as any, signature, timestamp) + const verified = await this.verifyKey(body, signature, timestamp) if (!verified) return false return true } diff --git a/test/mod.ts b/test/mod.ts new file mode 100644 index 0000000..5395f69 --- /dev/null +++ b/test/mod.ts @@ -0,0 +1,55 @@ +/* eslint-disable spaced-comment */ +// TODO: Add tests +import { Client, GatewayIntents as GI, Embed } from '../mod.ts' +import { TOKEN } from '../src/test/config.ts' +import { + assertEquals, + assertExists +} from 'https://deno.land/std@0.84.0/testing/asserts.ts' + +//#region Lib Tests +Deno.test({ + name: '[Lib] Embed', + fn() { + const embed = new Embed() + .setTitle('Title') + .setDescription('Description') + .addField('F1N', 'F1V', false) + .addField('F2N', 'F2V', true) + .setColor(0xff0000) + .setFooter('Footer', 'https://google.com') + .setAuthor('Author', 'https://google.com') + + assertEquals( + JSON.stringify(embed.toJSON()), + `{"title":"Title","description":"Description","color":16711680,"footer":{"text":"Footer","icon_url":"https://google.com"},"author":{"name":"Author","icon_url":"https://google.com"},"fields":[{"name":"F1N","value":"F1V","inline":false},{"name":"F2N","value":"F2V","inline":true}]}` + ) + } +}) + +//#endregion + +//#region API Tests +const client = new Client({ + token: TOKEN, + intents: [GI.GUILDS, GI.GUILD_MESSAGES, GI.DIRECT_MESSAGES] +}) + +await client.connect() +Deno.test({ + name: '[API] Client Ready', + fn() { + assertExists(client.user) + } +}) +//#endregion + +Deno.test({ + name: '[API] Cleanup', + fn() { + setTimeout(() => { + client.destroy() + Deno.exit() + }, 100) + } +}) From fb609c18bfaf6f8b88ac0fddb4b2fc6f918644e0 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Mon, 1 Feb 2021 14:25:03 +0530 Subject: [PATCH 2/2] dont use github imports --- deps.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps.ts b/deps.ts index f7c495c..7a04e52 100644 --- a/deps.ts +++ b/deps.ts @@ -1,5 +1,5 @@ export { EventEmitter } from 'https://deno.land/x/event@0.2.1/mod.ts' -export { unzlib } from 'https://raw.githubusercontent.com/DjDeveloperr/denoflate/master/mod.ts' +export { unzlib } from 'https://denopkg.com/DjDeveloperr/denoflate@1.2/mod.ts' export { fetchAuto } from 'https://deno.land/x/fetchbase64@1.0.0/mod.ts' export { parse } from 'https://deno.land/x/mutil@0.1.2/mod.ts' export { connect } from 'https://deno.land/x/redis@v0.14.1/mod.ts'