remove opine and oak deps and start adding tests
This commit is contained in:
parent
b7fee5a41f
commit
b844a053e5
4 changed files with 68 additions and 33 deletions
2
deps.ts
2
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 {
|
||||
|
|
|
@ -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
|
||||
])
|
||||
|
|
|
@ -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<boolean> {
|
||||
async verifyOpineRequest(req: any): Promise<boolean> {
|
||||
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<any> {
|
||||
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<any> {
|
||||
async verifyOakRequest(ctx: any): Promise<any> {
|
||||
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
|
||||
}
|
||||
|
|
55
test/mod.ts
Normal file
55
test/mod.ts
Normal 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)
|
||||
}
|
||||
})
|
Loading…
Reference in a new issue