]> git.puffer.fish Git - matthieu/gru.git/commitdiff
add a bit of documentation
authorMatthieuCoder <matthieu@matthieu-dev.xyz>
Tue, 3 Jan 2023 10:28:40 +0000 (14:28 +0400)
committerMatthieuCoder <matthieu@matthieu-dev.xyz>
Tue, 3 Jan 2023 10:28:40 +0000 (14:28 +0400)
src/handler/builder.ts
src/handler/index.ts
src/index.ts
src/register.ts
src/rest.ts

index 148542aca96dd3ff4d35fd1cc371c0f4ba24957c..feb57803fd91200cbdfbbf122ed9020a62d238d8 100644 (file)
@@ -1,6 +1,9 @@
 import { SlashCommandBuilder } from "@discordjs/builders";
 import { Command, HandlerFn } from ".";
 
+/**
+ * Simple wrapper around the SlashCommandBuilder provided by Discord.js 
+ */
 export class CommandBuilder extends SlashCommandBuilder {
   private _handler: HandlerFn;
 
index 81267174d3852d549e5a66a7c7c469fbd9ab07ea..16a56ed8f6e87c8a7e967a3f991008a7218f3a39 100644 (file)
@@ -6,22 +6,30 @@ import {
   InteractionType,
   RESTPostAPIApplicationCommandsJSONBody,
   RESTPostAPIChatInputApplicationCommandsJSONBody,
-  RESTPostAPIWebhookWithTokenJSONBody,
   Routes,
 } from "discord-api-types/v10";
-import { rest } from "../rest";
 
 export * from "./builder";
 
+export type PromiseLike<T> = T | Promise<T>;
+/**
+ * A simple function that executes a slash command.
+ */
 export type HandlerFn = (
   data: APIApplicationCommandInteraction
 ) => PromiseLike<APIInteractionResponse>;
-export type PromiseLike<T> = T | Promise<T>;
+
 export type Command = {
   json: RESTPostAPIChatInputApplicationCommandsJSONBody;
   handler: HandlerFn;
 };
 
+/**
+ * Register all the commands to discord
+ * @param commands List of commands to register
+ * @param rest Rest api instance
+ * @param applicationId Current application id
+ */
 export const registerCommands = async (
   commands: Iterable<Command>,
   rest: REST,
@@ -34,6 +42,11 @@ export const registerCommands = async (
   }
 };
 
+/**
+ * Creates a new handler to handle the slash commands.
+ * @param commands List of commands to handle
+ * @returns Handler function
+ */
 export const buildHandler = (commands: Iterable<Command>) => {
   let internal: Map<String, Command> = new Map();
   for (const command of commands) {
index eb8707f00e16a01510c5f8cef253d1ad1a670d3c..7e5a5db7cf6ce17a976e29538fbbb7ee56143a30 100644 (file)
@@ -1,46 +1,16 @@
 import { EventClient } from "./events/index";
-import {
-  RESTPostAPIChannelMessageResult,
-  Routes,
-} from "discord-api-types/v10";
-import { rest } from "./rest";
 import { buildHandler } from "./handler";
 import { commands } from "./commands";
 
+/**
+ * We instanciate our nova broken client.
+ */
 const emitter = new EventClient();
-emitter.on("interactionCreate", buildHandler(commands));
-
-emitter.on("messageCreate", async (message) => {
-  console.log(message);
-  if (message.content.toLowerCase() == "salut") {
-    await rest.post(Routes.channelMessages(message.channel_id), {
-      body: {
-        content: `Salut <@${message.author.id}> :wink:`,
-      },
-    });
-  } else if (message.content.toLocaleLowerCase() == "~ping") {
-    let t1 = new Date().getTime();
-    let sentMessage = <RESTPostAPIChannelMessageResult>await rest.post(
-      Routes.channelMessages(message.channel_id),
-      {
-        body: {
-          content: `Calcul du ping...`,
-        },
-      }
-    );
-    let time = new Date().getTime() - t1;
 
-    await rest.patch(
-      Routes.channelMessage(message.channel_id, sentMessage.id),
-      {
-        body: {
-          content: `Le ping de <@${sentMessage.author.id}> est de \`${time}ms\``,
-        },
-      }
-    );
-  }
-});
+// We register our slash command handler.
+emitter.on("interactionCreate", buildHandler(commands));
 
+// We connect ourselves to the nova nats broker.
 emitter
   .start({
     additionalEvents: [],
index 46725855853c42f270829d355c1e684536565f6d..af01e762b9cefb0aa0e219c616bbaa0f15f11444 100644 (file)
@@ -2,4 +2,7 @@ import { commands } from "./commands";
 import { registerCommands } from "./handler";
 import { rest } from "./rest";
 
+/**
+ * We register the commands with discord
+ */
 registerCommands(commands, rest, "807188335717384212");
\ No newline at end of file
index 9bee0cb7762d7036d26f603932c803dc9c2b2d3d..ab9ff5421b50ecc30e8eb2d7e7801ff2517e9381 100644 (file)
@@ -1,6 +1,9 @@
 require('source-map-support').install();
 import { REST } from "@discordjs/rest";
 
+/**
+ * Rest client used to communicate with discord
+ */
 export const rest = new REST({
   version: "10",
   headers: { Authorization: "" },