create-discord-https 1.0.6 → 2.0.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,7 +1,7 @@
1
1
  {
2
2
  "name": "create-discord-https",
3
3
  "description": "Create Discord.https-powered bots with one command.",
4
- "version": "1.0.6",
4
+ "version": "2.0.0",
5
5
  "bin": {
6
6
  "create-discord-https": "index.js"
7
7
  },
@@ -3,7 +3,7 @@
3
3
  "private": true,
4
4
  "version": "1.0.0",
5
5
  "description": "Discord HTTPS interaction callback bot powered by discord.https",
6
- "main": "index.js",
6
+ "main": "src/index.js",
7
7
  "scripts": {
8
8
  "dev": "node src/spawner.js",
9
9
  "deploy": "npx wrangler deploy --env production",
@@ -0,0 +1,14 @@
1
+ import { InteractionRouterCollector } from "discord.https/router";
2
+
3
+ // Recommend using PascalCase and ending with the 'Route' suffix
4
+ // for variable naming convention
5
+
6
+ import JokeRoute from "./fun/joke.js";
7
+ import PingRoute from "./reply/ping.js";
8
+ import UtilityRoute from "./utility/index.js";
9
+
10
+ export default new InteractionRouterCollector().register(
11
+ JokeRoute,
12
+ PingRoute,
13
+ UtilityRoute
14
+ );
@@ -0,0 +1,14 @@
1
+ import { InteractionRouterCollector } from "discord.https/router";
2
+
3
+ // Recommend using PascalCase and ending with the 'Route' suffix
4
+ // for variable naming convention
5
+
6
+ import HelpRoute from "./help.js";
7
+ import InfoRoute from "./info.js";
8
+ import ProfileRoute from "./profile.js";
9
+
10
+ export default new InteractionRouterCollector().register(
11
+ HelpRoute,
12
+ InfoRoute,
13
+ ProfileRoute
14
+ );
@@ -0,0 +1,59 @@
1
+ import Client from "discord.https";
2
+ import CloudflareAdapter from "@discordhttps/cloudflare-adapter";
3
+
4
+ import commands from "./commands/index.js";
5
+
6
+ const adapter = new CloudflareAdapter();
7
+
8
+ export default {
9
+ // Cloudflare Workers entry point
10
+ async fetch(request, env, ctx) {
11
+ const client = new Client({
12
+ token: "PUT_YOUR_TOKEN_HERE",
13
+ publicKey: "PUT_YOUR_PUBLIC_KEY_HERE",
14
+ httpAdapter: adapter,
15
+ debug: true,
16
+ });
17
+
18
+ // client.middleware() creates a global middleware, which is always executed before
19
+ // route middleware/handlers.
20
+
21
+ // https://discordhttps.js.org/classes/index.default.html#middleware
22
+ client.middleware(async (interaction) => {
23
+ const username = interaction.inGuild()
24
+ ? interaction.member.user.username
25
+ : interaction.user.username;
26
+ console.log(
27
+ "[Global Middleware]: A command has been invoked by: ",
28
+ username
29
+ );
30
+ });
31
+
32
+ // Everything here is middleware. A middleware can be defined as a function that takes a parameter
33
+ // and transforms the output in our case.
34
+
35
+ // client.register() mounts a middleware. This means that if the client receives a request from Discord
36
+ // and the corresponding middleware exists, the client will pass it to the appropriate middleware
37
+ // one by one in the order they were registered.
38
+
39
+ // simply, .register() lets the client know that these are the handlers.
40
+ client.register(commands);
41
+
42
+ if (env.NODE_ENV !== "production") {
43
+ const { commandRegistrarLayer, tunnelLayer } = await import(
44
+ "./DevLayer.js"
45
+ );
46
+ // Used to tunnel stuff
47
+
48
+ if (!globalThis.__TUNNEL_LAYER__)
49
+ globalThis.__TUNNEL_LAYER__ = await tunnelLayer();
50
+
51
+ // automatic command registration to discord.
52
+ // The first parameter is the guild ID. If a guild ID is provided, the command will be registered for that guild; otherwise, it will be registered globally.
53
+ // await commandRegistrarLayer(client, undefined);
54
+ }
55
+
56
+ // Handle Discord interactions on the "/interactions" endpoint
57
+ return await client.listen("interactions", request);
58
+ },
59
+ };
@@ -3,7 +3,7 @@
3
3
  "private": true,
4
4
  "version": "1.0.0",
5
5
  "description": "Discord HTTPS interaction callback bot powered by discord.https",
6
- "main": "index.js",
6
+ "main": "src/index.ts",
7
7
  "scripts": {
8
8
  "dev": "node src/spawner.js",
9
9
  "deploy": "npx wrangler deploy --env production",
@@ -3,7 +3,7 @@
3
3
  "private": true,
4
4
  "version": "1.0.0",
5
5
  "description": "Discord HTTPS interaction callback bot powered by discord.https",
6
- "main": "index.js",
6
+ "main": "src/index.js",
7
7
  "scripts": {
8
8
  "dev": "node src/index.js",
9
9
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -0,0 +1,14 @@
1
+ import { InteractionRouterCollector } from "discord.https/router";
2
+
3
+ // Recommend using PascalCase and ending with the 'Route' suffix
4
+ // for variable naming convention
5
+
6
+ import JokeRoute from "./fun/joke.js";
7
+ import PingRoute from "./reply/ping.js";
8
+ import UtilityRoute from "./utility/index.js";
9
+
10
+ export default new InteractionRouterCollector().register(
11
+ JokeRoute,
12
+ PingRoute,
13
+ UtilityRoute
14
+ );
@@ -0,0 +1,14 @@
1
+ import { InteractionRouterCollector } from "discord.https/router";
2
+
3
+ // Recommend using PascalCase and ending with the 'Route' suffix
4
+ // for variable naming convention
5
+
6
+ import HelpRoute from "./help.js";
7
+ import InfoRoute from "./info.js";
8
+ import ProfileRoute from "./profile.js";
9
+
10
+ export default new InteractionRouterCollector().register(
11
+ HelpRoute,
12
+ InfoRoute,
13
+ ProfileRoute
14
+ );
@@ -0,0 +1,50 @@
1
+ import Client from "discord.https";
2
+ import NodeHttpAdapter from "@discordhttps/nodejs-adapter";
3
+
4
+ import commands from "./commands/index.js";
5
+
6
+ const adapter = new NodeHttpAdapter();
7
+
8
+ const client = new Client({
9
+ token: "PUT_YOUR_TOKEN_HERE",
10
+ publicKey: "PUT_YOUR_PUBLIC_KEY_HERE",
11
+ httpAdapter: adapter,
12
+ });
13
+
14
+ // client.middleware() creates a global middleware, which is always executed before
15
+ // route middleware/handlers.
16
+
17
+ // https://discordhttps.js.org/classes/index.default.html#middleware
18
+ client.middleware(async (interaction) => {
19
+ const username = interaction.inGuild()
20
+ ? interaction.member.user.username
21
+ : interaction.user.username;
22
+ console.log("[Global Middleware]: A command has been invoked by: ", username);
23
+ });
24
+
25
+ // Everything here is middleware. A middleware can be defined as a function that takes a parameter
26
+ // and transforms the output in our case.
27
+
28
+ // client.register() mounts a middleware. This means that if the client receives a request from Discord
29
+ // and the corresponding middleware exists, the client will pass it to the appropriate middleware
30
+ // one by one in the order they were registered.
31
+
32
+ // simply, .register() lets the client know that these are the handlers.
33
+
34
+ client.register(commands);
35
+
36
+ if (process.env.NODE_ENV !== "production") {
37
+ const { commandRegistrarLayer, tunnelLayer } = await import("./DevLayer.js");
38
+ // Used to tunnel stuff
39
+ await tunnelLayer();
40
+
41
+ // automatic command registration to discord.
42
+ // The first parameter is the guild ID. If a guild ID is provided, the command will be registered for that guild; otherwise, it will be registered globally.
43
+ await commandRegistrarLayer(client, undefined);
44
+ }
45
+
46
+ client.listen("interactions", 8080, () => {
47
+ console.log(
48
+ "Listening for interactions at http://localhost:8080/interactions"
49
+ );
50
+ });
@@ -3,7 +3,6 @@
3
3
  "private": true,
4
4
  "version": "1.0.0",
5
5
  "description": "Discord HTTPS interaction callback bot powered by discord.https",
6
- "main": "index.js",
7
6
  "scripts": {
8
7
  "test": "echo \"Error: no test specified\" && exit 1"
9
8
  },
@@ -3,7 +3,11 @@
3
3
  "private": true,
4
4
  "version": "1.0.0",
5
5
  "description": "Discord HTTPS interaction callback bot powered by discord.https",
6
- "main": "index.js",
6
+ "main": "api/interaction.js",
7
+ "files": [
8
+ "api",
9
+ "src"
10
+ ],
7
11
  "scripts": {
8
12
  "dev": "node src/spawner.js",
9
13
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -0,0 +1,14 @@
1
+ import { InteractionRouterCollector } from "discord.https/router";
2
+
3
+ // Recommend using PascalCase and ending with the 'Route' suffix
4
+ // for variable naming convention
5
+
6
+ import JokeRoute from "./fun/joke.js";
7
+ import PingRoute from "./reply/ping.js";
8
+ import UtilityRoute from "./utility/index.js";
9
+
10
+ export default new InteractionRouterCollector().register(
11
+ JokeRoute,
12
+ PingRoute,
13
+ UtilityRoute
14
+ );
@@ -0,0 +1,14 @@
1
+ import { InteractionRouterCollector } from "discord.https/router";
2
+
3
+ // Recommend using PascalCase and ending with the 'Route' suffix
4
+ // for variable naming convention
5
+
6
+ import HelpRoute from "./help.js";
7
+ import InfoRoute from "./info.js";
8
+ import ProfileRoute from "./profile.js";
9
+
10
+ export default new InteractionRouterCollector().register(
11
+ HelpRoute,
12
+ InfoRoute,
13
+ ProfileRoute
14
+ );
@@ -0,0 +1,49 @@
1
+ import Client from "discord.https";
2
+ import VercelAdapter from "@discordhttps/vercel-adapter";
3
+
4
+ import commands from "./commands/index.js";
5
+
6
+ const adapter = new VercelAdapter();
7
+
8
+ const client = new Client({
9
+ token: "PUT_YOUR_TOKEN_HERE",
10
+ publicKey: "PUT_YOUR_PUBLIC_KEY_HERE",
11
+ httpAdapter: adapter,
12
+ });
13
+
14
+ // client.middleware() creates a global middleware, which is always executed before
15
+ // route middleware/handlers.
16
+
17
+ // https://discordhttps.js.org/classes/index.default.html#middleware
18
+ client.middleware(async (interaction) => {
19
+ const username = interaction.inGuild()
20
+ ? interaction.member.user.username
21
+ : interaction.user.username;
22
+ console.log("[Global Middleware]: A command has been invoked by: ", username);
23
+ });
24
+
25
+ // Everything here is middleware. A middleware can be defined as a function that takes a parameter
26
+ // and transforms the output in our case.
27
+
28
+ // client.register() mounts a middleware. This means that if the client receives a request from Discord
29
+ // and the corresponding middleware exists, the client will pass it to the appropriate middleware
30
+ // one by one in the order they were registered.
31
+
32
+ // simply, .register() lets the client know that these are the handlers.
33
+
34
+ client.register(commands);
35
+
36
+ if (process.env.NODE_ENV !== "production") {
37
+ const { commandRegistrarLayer } = await import("./DevLayer.js");
38
+
39
+ // if (!globalThis.__TUNNEL_LAYER__)
40
+ // globalThis.__TUNNEL_LAYER__ = await tunnelLayer();
41
+
42
+ // automatic command registration to discord.
43
+ // The first parameter is the guild ID. If a guild ID is provided, the command will be registered for that guild; otherwise, it will be registered globally.
44
+ await commandRegistrarLayer(client, undefined);
45
+ }
46
+
47
+ // Only api/<file.js/ts> can be serverless function, exporting it for api/interaction
48
+ // so, it cloud be imported from api/interaction.js and use there due to vercel way of serverless
49
+ export default client;
@@ -0,0 +1,5 @@
1
+ import client from "../src/index.js";
2
+ import type { VercelRequest, VercelResponse } from "@vercel/functions";
3
+ export default async function handler(req: VercelRequest, res: VercelResponse) {
4
+ return await client.listen("api/interactions", req, res);
5
+ }
@@ -3,7 +3,7 @@
3
3
  "private": true,
4
4
  "version": "1.0.0",
5
5
  "description": "Discord HTTPS interaction callback bot powered by discord.https",
6
- "main": "index.js",
6
+ "main": "api/interactions.ts",
7
7
  "scripts": {
8
8
  "dev": "node src/spawner.js",
9
9
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -1,5 +0,0 @@
1
- import client from "../src/index.js";
2
-
3
- export default async function handler(req, res) {
4
- return await client.listen("api/interactions", req, res);
5
- }