@somehiddenkey/discord-command-utils 1.0.2 → 1.1.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/README.md CHANGED
@@ -1,20 +1,12 @@
1
1
  # DiscordUtilsLibrary
2
2
  The purpose of this Library is to hide and abstract many of the common aspects that comes with coding discord bots in javascript. The main focus is configurations as well as registering all types of commands and interactions between different guilds.
3
- ## Installation
4
- ### SSH Installation
5
- Use this if your GitHub account already has SSH access -> requires SSH key set up
3
+ ## Setup
4
+ 1. Installation
6
5
  ```bash
7
- npm install git+ssh://git@github.com/studytogether-discord/DiscordUtilsLibrary.git
6
+ npm install @somehiddenkey/discord-command-utils --registry=https://registry.npmjs.org/
8
7
  ```
9
8
 
10
- ### HTTPS Installation
11
- If you want to use HTTPS instead, you must use a GitHub Personal Access Token (classic) with repo permissions (replace "TOKEN" with your PAT)
12
- ```bash
13
- npm install "https://TOKEN@github.com/studytogether-discord/DiscordUtilsLibrary.git"
14
- ```
15
-
16
- ### Libary Import
17
- Then import it in your code
9
+ 2. Libary Import
18
10
  ```c#
19
11
  import { Something } from "DiscordUtilsLibrary";
20
12
  // or
@@ -137,7 +129,7 @@ bot.on(Events.MessageCreate, async (message) => {
137
129
  });
138
130
 
139
131
  bot.on(Events.InteractionCreate, async (interaction) =>
140
- await interactionContainer.call_interaction(message, e => consola.error(e))
132
+ await interactionContainer.call_interaction(interaction, e => consola.error(e))
141
133
  );
142
134
  ```
143
135
  ### Register slash commands to REST
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@somehiddenkey/discord-command-utils",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "A utility library for building Discord bot commands using discord.js",
5
5
  "author": {
6
6
  "email": "k3y.throwaway@gmail.com",
@@ -1,8 +1,6 @@
1
- class ConfigError extends Error {
1
+ export default class ConfigError extends Error {
2
2
  constructor(message) {
3
3
  super(message);
4
4
  this.name = "ConfigError";
5
5
  }
6
- }
7
-
8
- export default ConfigError;
6
+ }
@@ -3,9 +3,9 @@
3
3
  */
4
4
 
5
5
  import fs from 'fs';
6
- import ConfigError from "./ConfigError";
6
+ import ConfigError from "./ConfigError.js";
7
7
  import consola from 'consola';
8
- import { InteractionScope } from "../Utils/enums";
8
+ import { InteractionScope } from "../Utils/enums.js";
9
9
 
10
10
  export default class GlobalConfig {
11
11
  /** @type {Guilds} */
@@ -1,10 +1,11 @@
1
+ import fs from 'fs';
2
+ import ConfigError from "./ConfigError.js";
3
+ import consola from 'consola';
4
+
1
5
  /**
2
6
  * @typedef {string} Snowflake
3
7
  */
4
8
 
5
- import { RESTOptions } from '@discordjs/rest';
6
- import { ActivitiesOptions } from 'discord.js';
7
-
8
9
  export default class LocalConfig {
9
10
  /** @type {string?} */
10
11
  prefix;
@@ -13,9 +14,9 @@ export default class LocalConfig {
13
14
 
14
15
  /** @type {object} */
15
16
  local;
16
- /** @type {Partial<RESTOptions>} */
17
+ /** @type {object} */
17
18
  restOptions;
18
- /** @type {ActivitiesOptions} */
19
+ /** @type {object} */
19
20
  activity;
20
21
 
21
22
  constructor(data) {
@@ -25,7 +26,7 @@ export default class LocalConfig {
25
26
  this.restOptions = data.rest_options || {};
26
27
  this.activity = data.activity || {};
27
28
 
28
- if(!this.client_id)
29
+ if(!this.clientId)
29
30
  throw new ConfigError('No client_id initialized for LocalConfig');
30
31
  }
31
32
 
@@ -33,7 +34,7 @@ export default class LocalConfig {
33
34
  * Loads the JSON file and returns a GlobalConfig instance.
34
35
  * @param {string} path
35
36
  * @param {string} environment
36
- * @returns {GlobalConfig}
37
+ * @returns {LocalConfig}
37
38
  */
38
39
  static async load(path, environment) {
39
40
  var json
@@ -41,12 +42,12 @@ export default class LocalConfig {
41
42
  const raw = fs.readFileSync(path, { encoding: 'utf8', flag: 'r' });
42
43
  json = JSON.parse(raw);
43
44
  } catch (error) {
44
- consola.error(`Failed to load GlobalConfig from path: ${path}`, error);
45
+ consola.error(`Failed to load LocalConfig from path: ${path}`, error);
45
46
  throw error;
46
47
  }
47
48
  if (environment == "production")
48
- return new GlobalConfig({...json.production || json.activity});
49
+ return new LocalConfig({...json.production || json.activity});
49
50
  else
50
- return new GlobalConfig({...json.development || json.activity});
51
+ return new LocalConfig({...json.development || json.activity});
51
52
  }
52
53
  }
@@ -1,5 +1,5 @@
1
1
  import consola from "consola";
2
- import ConfigError from "./ConfigError";
2
+ import ConfigError from "./ConfigError.js";
3
3
 
4
4
  /**
5
5
  * @typedef {{client: string, connection: {host: string, user: string, password: string, database: string}}} DatabaseConfig
@@ -1,4 +1,5 @@
1
- import { Interaction as DiscordBaseInteraction, MessageFlags } from "discord.js";
1
+ import pkg from 'discord.js';
2
+ const { Interaction: DiscordBaseInteraction } = pkg;
2
3
 
3
4
  export default class CommandError extends Error {
4
5
  constructor(message) {
@@ -1,15 +1,16 @@
1
- import {
2
- Interaction as DiscordBaseInteraction,
1
+ import InteractionContainer from "./InteractionContainer.js";
2
+ import { InteractionType, InteractionScope } from "../Utils/enums.js";
3
+ import pkg from 'discord.js';
4
+
5
+ const {
6
+ Interaction: DiscordBaseInteraction,
3
7
  OmitPartialGroupDMChannel,
4
8
  Message,
5
9
  ModalSubmitInteraction,
6
10
  ButtonInteraction,
7
11
  AnySelectMenuInteraction,
8
12
  ChatInputCommandInteraction,
9
- CacheType
10
- } from 'discord.js';
11
- import InteractionContainer from "./InteractionContainer";
12
- import { InteractionType, InteractionScope } from "../Utils/enums";
13
+ CacheType } = pkg;
13
14
 
14
15
  /**
15
16
  * @typedef { (interaction: DiscordBaseInteraction<CacheType>) => Promise<any> } InteractionFunction
@@ -1,16 +1,17 @@
1
- import {
2
- Interaction as DiscordBaseInteraction,
1
+ import Interaction from "./Interaction.js";
2
+ import { InteractionScope, InteractionType } from "../Utils/enums.js";
3
+ import GlobalConfig from "../Configs/GlobalConfig.js";
4
+ import LocalConfig from "../Configs/LocalConfig.js";
5
+ import consola from "consola";
6
+ import CommandError from "./CommandError.js";
7
+ import RestCommands from './RestCommands.js';
8
+ import pkg from 'discord.js';
9
+ const {
10
+ Interaction: DiscordBaseInteraction,
3
11
  OmitPartialGroupDMChannel,
4
12
  Message,
5
13
  CacheType
6
- } from 'discord.js';
7
- import Interaction from "./Interaction";
8
- import { InteractionScope, InteractionType } from "../Utils/enums";
9
- import GlobalConfig from "../Configs/GlobalConfig";
10
- import LocalConfig from "../Configs/LocalConfig";
11
- import consola from "consola";
12
- import CommandError from "./CommandError";
13
- import RestCommands from './RestCommands';
14
+ } = pkg;
14
15
 
15
16
  /**
16
17
  * @typedef { (interaction: DiscordBaseInteraction<CacheType>) => Promise<any> } InteractionFunction
@@ -1,6 +1,5 @@
1
- import { InteractionScope } from "../Utils/enums";
2
- import GlobalConfig from "../Configs/GlobalConfig";
3
- import LocalConfig from "../Configs/LocalConfig";
1
+ import GlobalConfig from "../Configs/GlobalConfig.js";
2
+ import LocalConfig from "../Configs/LocalConfig.js";
4
3
  import { REST } from "discord.js";
5
4
 
6
5
  export default class RestCommands {
@@ -1,5 +1,5 @@
1
1
  import { BaseInteraction } from "discord.js";
2
- import { Modlevel } from "./enums";
2
+ import { Modlevel } from "./enums.js";
3
3
 
4
4
 
5
5
  /**