discord-bot-shared 0.4.0 → 0.5.1

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
@@ -132,13 +132,13 @@ interface Command {
132
132
 
133
133
  ---
134
134
 
135
- #### `function getChannelByName`
135
+ #### `function getChannel`
136
136
 
137
- Returns a guild channel of the given name and type, otherwise returns `undefined`.
137
+ Returns the guild channel of the given name/ID and type, otherwise returns `undefined`.
138
138
 
139
139
  ```
140
- async function getChannelByName<T extends NonThreadGuildBasedChannel>(
141
- channelName: string,
140
+ async function getChannel<T extends NonThreadGuildBasedChannel>(
141
+ channelNameOrId: string,
142
142
  channelType: NonThreadGuildBasedChannelType,
143
143
  ): Promise<T | undefined>
144
144
  ```
@@ -149,5 +149,21 @@ async function getChannelByName<T extends NonThreadGuildBasedChannel>(
149
149
  - For example:
150
150
 
151
151
  ```
152
- const someTextChannel = await getChannelByName<TextChannel>('some-text-channel', ChannelType.GuildText)
152
+ const someTextChannel = await getChannel<TextChannel>('some-text-channel', ChannelType.GuildText)
153
153
  ```
154
+
155
+ ---
156
+
157
+ #### Channel Type Guards
158
+
159
+ These are channel type guards that you may need to use.
160
+
161
+ ```
162
+ function isTextChannel(channel: BaseChannel | APIPartialChannel): channel is TextChannel
163
+ ```
164
+
165
+ ```
166
+ function isCategoryChannel(channel: BaseChannel): channel is CategoryChannel
167
+ ```
168
+
169
+ - Almost every channel type in discord.js extends `BaseChannel`, so you should be able to pass in whatever channel you need to here.
package/dist/index.d.ts CHANGED
@@ -5,4 +5,4 @@ export default login;
5
5
  export { Command } from './commands.js';
6
6
  export { default as getGuildCache } from './guildCache.js';
7
7
  export { InteractionCheck } from './interactionCreate.js';
8
- export { getChannelByName, throwError } from './util.js';
8
+ export { getChannel, isCategoryChannel, isTextChannel, throwError } from './util.js';
package/dist/index.js CHANGED
@@ -19,5 +19,5 @@ async function login(botIntents, projectMetaURL, interactionCheck) {
19
19
  }
20
20
  export default login;
21
21
  export { default as getGuildCache } from './guildCache.js';
22
- export { getChannelByName, throwError } from './util.js';
22
+ export { getChannel, isCategoryChannel, isTextChannel, throwError } from './util.js';
23
23
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiB,MAAM,YAAY,CAAA;AAClD,OAAO,gBAAgB,MAAM,eAAe,CAAA;AAC5C,OAAO,cAAc,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,yBAA+C,MAAM,wBAAwB,CAAA;AACpF,OAAO,aAAa,MAAM,YAAY,CAAA;AAEtC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE,CAAA;AAC5C,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE,CAAA;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAA;AAE1C,KAAK,UAAU,KAAK,CAAC,UAAyB,EAAE,cAAsB,EAAE,gBAAmC;IACzG,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC,CAAA;IAClC,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,CAAC,CAAA;IAEpF,aAAa,CAAC,GAAG,CAAC,CAAA;IAClB,yBAAyB,CAAC,GAAG,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAA;IAC1D,KAAK,cAAc,CAAC,cAAc,CAAC,CAAA;IAEnC,MAAM,CAAC,GAAG,CAAC,CAAA;IAEX,KAAK,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IACxB,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,eAAe,KAAK,CAAA;AA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AE,MAAM,iBAAiB,CAAA;AAE1D,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA"}
package/dist/util.d.ts CHANGED
@@ -1,5 +1,7 @@
1
- import { ChannelType, NonThreadGuildBasedChannel } from 'discord.js';
1
+ import { APIPartialChannel, BaseChannel, CategoryChannel, ChannelType, NonThreadGuildBasedChannel, TextChannel } from 'discord.js';
2
2
  declare type NonThreadGuildBasedChannelType = ChannelType.GuildText | ChannelType.GuildVoice | ChannelType.GuildNews | ChannelType.GuildStageVoice | ChannelType.GuildCategory;
3
- declare function getChannelByName<T extends NonThreadGuildBasedChannel>(channelName: string, channelType: NonThreadGuildBasedChannelType): Promise<T | undefined>;
3
+ declare function getChannel<T extends NonThreadGuildBasedChannel>(channelNameOrId: string, channelType: NonThreadGuildBasedChannelType): Promise<T | undefined>;
4
+ declare function isTextChannel(channel: BaseChannel | APIPartialChannel): channel is TextChannel;
5
+ declare function isCategoryChannel(channel: BaseChannel): channel is CategoryChannel;
4
6
  declare function throwError(error: string): never;
5
- export { getChannelByName, throwError };
7
+ export { getChannel, isTextChannel, isCategoryChannel, throwError };
package/dist/util.js CHANGED
@@ -1,11 +1,23 @@
1
+ import { ChannelType } from 'discord.js';
1
2
  import getGuildCache from './guildCache.js';
2
- async function getChannelByName(channelName, channelType) {
3
+ async function getChannel(channelNameOrId, channelType) {
3
4
  const { channels } = (await getGuildCache()) || throwError('Unable to get guild cache.');
4
- const channel = channels.find((channel) => channel.name === channelName);
5
- return channel && channel.type === channelType ? channel : undefined;
5
+ let channel;
6
+ channel = channels.find((channel) => channel.name === channelNameOrId);
7
+ if (channel)
8
+ return channel.type === channelType ? channel : undefined;
9
+ channel = channels.get(channelNameOrId);
10
+ if (channel)
11
+ return channel.type === channelType ? channel : undefined;
12
+ }
13
+ function isTextChannel(channel) {
14
+ return channel.type === ChannelType.GuildText;
15
+ }
16
+ function isCategoryChannel(channel) {
17
+ return channel.type === ChannelType.GuildCategory;
6
18
  }
7
19
  function throwError(error) {
8
20
  throw new Error(error);
9
21
  }
10
- export { getChannelByName, throwError };
22
+ export { getChannel, isTextChannel, isCategoryChannel, throwError };
11
23
  //# sourceMappingURL=util.js.map
package/dist/util.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,MAAM,iBAAiB,CAAA;AAS3C,KAAK,UAAU,gBAAgB,CAC7B,WAAmB,EACnB,WAA2C;IAE3C,MAAM,EAAE,QAAQ,EAAE,GAAG,CAAC,MAAM,aAAa,EAAE,CAAC,IAAI,UAAU,CAAC,4BAA4B,CAAC,CAAA;IACxF,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,CAAA;IAExE,OAAO,OAAO,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAE,OAAa,CAAC,CAAC,CAAC,SAAS,CAAA;AAC7E,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAA;AACxB,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,CAAA"}
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmD,WAAW,EAA2C,MAAM,YAAY,CAAA;AAClI,OAAO,aAAa,MAAM,iBAAiB,CAAA;AAS3C,KAAK,UAAU,UAAU,CACvB,eAAuB,EACvB,WAA2C;IAE3C,MAAM,EAAE,QAAQ,EAAE,GAAG,CAAC,MAAM,aAAa,EAAE,CAAC,IAAI,UAAU,CAAC,4BAA4B,CAAC,CAAA;IAExF,IAAI,OAA+C,CAAA;IACnD,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,eAAe,CAAC,CAAA;IACtE,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAE,OAAa,CAAC,CAAC,CAAC,SAAS,CAAA;IAE7E,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;IACvC,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAE,OAAa,CAAC,CAAC,CAAC,SAAS,CAAA;AAC/E,CAAC;AAED,SAAS,aAAa,CAAC,OAAwC;IAC7D,OAAO,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,SAAS,CAAA;AAC/C,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAoB;IAC7C,OAAO,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,aAAa,CAAA;AACnD,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAA;AACxB,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,iBAAiB,EAAE,UAAU,EAAE,CAAA"}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "discord-bot-shared",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "type": "module",
5
5
  "description": "Modules for creating discord bots.",
6
6
  "repository": "github:adamhl8/discord-bot-shared",
7
7
  "author": "adamhl8",
8
8
  "license": "MIT",
9
- "main": "dist/index",
9
+ "main": "dist/index.js",
10
10
  "files": [
11
11
  "dist/",
12
12
  "README.md",
@@ -15,29 +15,29 @@
15
15
  "scripts": {
16
16
  "build": "tsc",
17
17
  "format": "prettier --write .",
18
- "lint": "eslint -f pretty --fix ."
18
+ "lint": "eslint -f pretty"
19
19
  },
20
20
  "dependencies": {
21
- "@discordjs/rest": "^1.0.1",
22
- "discord-api-types": "^0.37.3",
23
- "discord.js": "^14.2.0"
21
+ "@discordjs/rest": "^1.1.0",
22
+ "discord-api-types": "^0.37.9",
23
+ "discord.js": "^14.3.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/eslint": "^8.4.6",
27
- "@types/node": "^18.7.9",
27
+ "@types/node": "^18.7.16",
28
28
  "@types/prettier": "^2.7.0",
29
- "@typescript-eslint/eslint-plugin": "^5.33.1",
30
- "@typescript-eslint/parser": "^5.33.1",
31
- "eslint": "^8.22.0",
29
+ "@typescript-eslint/eslint-plugin": "^5.37.0",
30
+ "@typescript-eslint/parser": "^5.37.0",
31
+ "eslint": "^8.23.1",
32
32
  "eslint-config-prettier": "^8.5.0",
33
33
  "eslint-formatter-pretty": "^4.1.0",
34
34
  "eslint-plugin-eslint-comments": "^3.2.0",
35
35
  "eslint-plugin-sonarjs": "^0.15.0",
36
36
  "eslint-plugin-unicorn": "^43.0.2",
37
37
  "prettier": "^2.7.1",
38
- "prettier-plugin-organize-imports": "^3.1.0",
39
- "prettier-plugin-pkg": "^0.17.0",
38
+ "prettier-plugin-organize-imports": "^3.1.1",
39
+ "prettier-plugin-pkg": "^0.17.1",
40
40
  "prettier-plugin-sh": "^0.12.8",
41
- "typescript": "^4.7.4"
41
+ "typescript": "^4.8.3"
42
42
  }
43
43
  }