Merge pull request #101 from DjDeveloperr/slash

Remove Opine and Oak deps
This commit is contained in:
DjDeveloper 2021-02-02 10:41:16 +05:30 committed by GitHub
commit 24c3ea45ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 34 deletions

View file

@ -1,6 +1,6 @@
export { EventEmitter } from 'https://deno.land/x/event@0.2.1/mod.ts' 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://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 { 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 { connect } from 'https://deno.land/x/redis@v0.14.1/mod.ts'
export type { export type {

View file

@ -1,4 +1,4 @@
import { Client, Message, Intents } from '../mod.ts' import { Client, Message, GatewayIntents } from '../mod.ts'
const client = new Client() 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:') const token = prompt('Input Bot Token:')
if (token === null) { if (token === null) {
@ -21,23 +21,8 @@ if (token === null) {
Deno.exit() Deno.exit()
} }
const intents = prompt( client.connect(token, [
'Input Intents (0 = All, 1 = Presence, 2 = Server Members, 3 = None):' GatewayIntents.GUILD_MESSAGES,
) GatewayIntents.GUILDS,
if (intents === null || !['0', '1', '2', '3'].includes(intents)) { GatewayIntents.DIRECT_MESSAGES
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)

View file

@ -14,11 +14,6 @@ import { RESTManager } from './rest.ts'
import { SlashModule } from './slashModule.ts' import { SlashModule } from './slashModule.ts'
import { verify as edverify } from 'https://deno.land/x/ed25519/mod.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 { 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 { export class SlashCommand {
slash: SlashCommandsManager slash: SlashCommandsManager
@ -528,7 +523,7 @@ export class SlashClient {
).catch(() => false) ).catch(() => false)
} }
async verifyOpineRequest(req: ORequest): Promise<boolean> { async verifyOpineRequest(req: any): Promise<boolean> {
const signature = req.headers.get('x-signature-ed25519') const signature = req.headers.get('x-signature-ed25519')
const timestamp = req.headers.get('x-signature-timestamp') const timestamp = req.headers.get('x-signature-timestamp')
const contentLength = req.headers.get('content-length') const contentLength = req.headers.get('content-length')
@ -547,8 +542,8 @@ export class SlashClient {
/** Middleware to verify request in Opine framework. */ /** Middleware to verify request in Opine framework. */
async verifyOpineMiddleware( async verifyOpineMiddleware(
req: ORequest, req: any,
res: OResponse, res: any,
next: CallableFunction next: CallableFunction
): Promise<any> { ): Promise<any> {
const verified = await this.verifyOpineRequest(req) const verified = await this.verifyOpineRequest(req)
@ -560,7 +555,7 @@ export class SlashClient {
// TODO: create verifyOakMiddleware too // TODO: create verifyOakMiddleware too
/** Method to verify Request from Oak server "Context". */ /** Method to verify Request from Oak server "Context". */
async verifyOakRequest(ctx: Context): Promise<any> { async verifyOakRequest(ctx: any): Promise<any> {
const signature = ctx.request.headers.get('x-signature-ed25519') const signature = ctx.request.headers.get('x-signature-ed25519')
const timestamp = ctx.request.headers.get('x-signature-timestamp') const timestamp = ctx.request.headers.get('x-signature-timestamp')
const contentLength = ctx.request.headers.get('content-length') const contentLength = ctx.request.headers.get('content-length')
@ -576,7 +571,7 @@ export class SlashClient {
const body = await ctx.request.body().value 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 if (!verified) return false
return true return true
} }

55
test/mod.ts Normal file
View file

@ -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)
}
})