cordo 2.0.2 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordo",
3
- "version": "2.0.2",
3
+ "version": "2.2.0",
4
4
  "description": "A framework for handling complex discord api interactions",
5
5
  "exports": {
6
6
  ".": "./src/index.ts",
@@ -8,7 +8,7 @@
8
8
  "./components": "./src/components/index.ts",
9
9
  "./errors": "./src/errors/index.ts",
10
10
  "./functions": "./src/functions/index.ts",
11
- "./http": "./src/http/index.ts"
11
+ "./plugin": "./src/plugin/index.ts"
12
12
  },
13
13
  "files": [
14
14
  "src/*",
@@ -33,11 +33,11 @@
33
33
  },
34
34
  "homepage": "https://github.com/Maanex/cordo#readme",
35
35
  "dependencies": {
36
+ "@types/bun": "^1.2.10",
36
37
  "axios": "^0.21.4",
37
38
  "defu": "^6.1.4",
38
39
  "discord-api-types": "^0.37.119",
39
40
  "discord-interactions": "^2.4.1",
40
- "express": "^4.17.3",
41
41
  "type-fest": "^4.34.1"
42
42
  },
43
43
  "devDependencies": {
@@ -46,8 +46,11 @@
46
46
  "@types/node": "^17.0.8",
47
47
  "@typescript-eslint/eslint-plugin": "^4.28.3",
48
48
  "@typescript-eslint/parser": "^4.28.3",
49
+ "discord.js": "^14.18.0",
49
50
  "eslint": "^7.30.0",
50
51
  "eslint-config-maanex": "^1.1.2",
52
+ "express": "^4.17.3",
53
+ "hono": "^4.7.7",
51
54
  "reflect-metadata": "^0.1.13",
52
55
  "typescript": "^5.7.3"
53
56
  }
@@ -0,0 +1,18 @@
1
+ import { Cordo } from '@core'
2
+ import { Client, Events } from 'discord.js'
3
+
4
+
5
+ export function useWithDiscordJs(client: Client) {
6
+ if (!client)
7
+ throw new Error('You must provide a discord.js client object');
8
+
9
+ client.on(Events.Raw, (event) => {
10
+ if (event.t === 'INTERACTION_CREATE')
11
+ Cordo.triggerInteraction(event.d)
12
+ })
13
+
14
+ setTimeout(() => {
15
+ if (client.listeners(Events.InteractionCreate).length)
16
+ console.warn('You are using both the Cordo and Discord.js interaction listeners. This may cause issues with your routes.')
17
+ }, 50)
18
+ }
@@ -0,0 +1,34 @@
1
+ import { verifyKey } from "discord-interactions"
2
+ import { Cordo } from '@core'
3
+ import { Hono } from "hono"
4
+
5
+
6
+ export function useWithHono(clientPublicKey: string) {
7
+ if (!clientPublicKey)
8
+ throw new Error('You must specify a Discord client public key');
9
+
10
+ const app = new Hono()
11
+
12
+ app.post('/', async (c) => {
13
+ const signature = c.req.header('x-signature-ed25519')
14
+ const timestamp = c.req.header('x-signature-timestamp')
15
+ const bodyStream = c.req.raw.body
16
+ if (!signature || !timestamp || !bodyStream)
17
+ return c.text('Bad Request', 400)
18
+
19
+ const body = await Bun.readableStreamToArrayBuffer(bodyStream)
20
+ const isValid = verifyKey(body, signature, timestamp, clientPublicKey)
21
+ if (!isValid)
22
+ return c.text('Bad Request', 401)
23
+
24
+ const parsedBody = JSON.parse(Buffer.from(body).toString('utf-8'))
25
+ const { promise, resolve } = Promise.withResolvers<any>()
26
+ Cordo.triggerInteraction(parsedBody, {
27
+ httpCallback: (payload: any) => resolve(payload),
28
+ })
29
+
30
+ return c.json(await promise, 200)
31
+ })
32
+
33
+ return app
34
+ }
@@ -0,0 +1,4 @@
1
+
2
+ export { useWithDiscordJs } from './djs'
3
+ export { useWithExpress } from './express'
4
+ export { useWithHono } from './hono'
package/tsconfig.json CHANGED
@@ -30,7 +30,7 @@
30
30
  "@components/*": [ "./src/components/*" ],
31
31
  "@core": [ "./src/core/index.ts" ],
32
32
  "@core/*": [ "./src/core/*" ],
33
- "@http/*": [ "./src/http/*" ],
33
+ "@plugin/*": [ "./src/plugin/*" ],
34
34
  "@lib/*": [ "./src/lib/*" ]
35
35
  }
36
36
  }
package/src/http/index.ts DELETED
@@ -1,2 +0,0 @@
1
-
2
- export { useWithExpress } from './express'
File without changes