Skip to content

Commit 75779bd

Browse files
committed
Support for forum channels
### UPDATED - Dependencies will now be manually updated per version due to unknown incompatibilities - Documentation for Map Webhooks ### ADDED - Support to toggle permissions for forum channels
1 parent 953bfcf commit 75779bd

5 files changed

Lines changed: 82 additions & 37 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ Convert external webhooks (JSON-based) and send them as Discord messages. Use Di
449449
| `web-applications.map-webhooks[x].variables` | `object[]` | | yes | |
450450
| `web-applications.map-webhooks[x].variables[x].id` | `string` | Variable identifier | yes | Capital letters and underscores. Underscores are not allowed in the beginning or end of the identifier |
451451
| `web-applications.map-webhooks[x].variables[x].type` | `string` | Variable type | yes | `string`, `boolean`, `ts-seconds`, `ts-millis`, `usd-dollars`, or `usd-cents` |
452-
| `web-applications.map-webhooks[x].variables[x].path` | `string` | Variable path | yes | Access the value from the `path` of the object. If the value is not supported, it will return a stringified value |
452+
| `web-applications.map-webhooks[x].variables[x].path` | `string` | Variable path | yes | Access the value from the `path` of the object. If the value is not supported, it will return a string value |
453453
| `web-applications.map-webhooks[x].payload` | `object` | Message content to send for each webhook request | yes | `BaseMessageOptions` in [discord.js Documentation](https://discord.js.org/#/docs/main/stable/typedef/BaseMessageOptions). Variables include `%YEAR%`. To access incoming variables, define them like `@SAMPLE@`. `SAMPLE` is the value of `web-applications.map-webhooks[x].variables[x].id` |
454454
| `web-applications.map-webhooks[x].channel` | `object` | | yes | |
455455
| `web-applications.map-webhooks[x].channel.description` | `string` | Description of the channel used to send message content | no | |

package.json

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "discord-stocker-bot",
33
"displayName": "Discord Stonker Bot",
4-
"version": "3.4.2",
4+
"version": "3.4.3",
55
"description": "An advanced business-ready bot built for finance-related Discord servers",
66
"exports": "./build/src/index.js",
77
"type": "module",
@@ -53,41 +53,41 @@
5353
"node": "^18.12.1"
5454
},
5555
"dependencies": {
56-
"axios": "^1.1.3",
57-
"bottleneck": "^2.19.5",
58-
"chalk": "^5.1.2",
59-
"discord.js": "^14.6.0",
60-
"ejs": "^3.1.8",
61-
"express": "^4.18.2",
62-
"form-data": "^4.0.0",
63-
"html-entities": "^2.3.3",
64-
"latinize": "^0.5.0",
65-
"lodash": "^4.17.21",
66-
"luxon": "^3.1.0",
67-
"markdown-table": "^3.0.2",
68-
"node-cron": "^3.0.2",
69-
"numeral": "^2.0.6",
70-
"rss-parser": "^3.12.0",
71-
"serialize-error": "^11.0.0",
72-
"twitter-api-v2": "^1.12.2"
56+
"axios": "1.3.2",
57+
"bottleneck": "2.19.5",
58+
"chalk": "5.2.0",
59+
"discord.js": "14.7.1",
60+
"ejs": "3.1.8",
61+
"express": "4.18.2",
62+
"form-data": "4.0.0",
63+
"html-entities": "2.3.3",
64+
"latinize": "0.5.0",
65+
"lodash": "4.17.21",
66+
"luxon": "3.2.1",
67+
"markdown-table": "3.0.3",
68+
"node-cron": "3.0.2",
69+
"numeral": "2.0.6",
70+
"rss-parser": "3.12.0",
71+
"serialize-error": "11.0.0",
72+
"twitter-api-v2": "1.14.1"
7373
},
7474
"devDependencies": {
75-
"@types/express": "^4.17.13",
76-
"@types/latinize": "^0.2.15",
77-
"@types/lodash": "^4.14.188",
78-
"@types/luxon": "^3.1.0",
79-
"@types/node-cron": "^3.0.5",
80-
"@types/numeral": "^2.0.2",
81-
"@types/xml2js": "^0.4.11",
82-
"@typescript-eslint/eslint-plugin": "^5.42.1",
83-
"@typescript-eslint/parser": "^5.42.1",
84-
"copyfiles": "^2.4.1",
85-
"discord-api-types": "0.37.14",
86-
"eslint": "^8.26.0",
87-
"eslint-config-airbnb-base": "^15.0.0",
88-
"eslint-plugin-import": "^2.26.0",
89-
"npm-run-all": "^4.1.5",
90-
"ts-node": "^10.8.0",
91-
"typescript": "^4.8.4"
75+
"@types/express": "4.17.17",
76+
"@types/latinize": "0.2.15",
77+
"@types/lodash": "4.14.191",
78+
"@types/luxon": "3.2.0",
79+
"@types/node-cron": "3.0.7",
80+
"@types/numeral": "2.0.2",
81+
"@types/xml2js": "0.4.11",
82+
"@typescript-eslint/eslint-plugin": "5.51.0",
83+
"@typescript-eslint/parser": "5.51.0",
84+
"copyfiles": "2.4.1",
85+
"discord-api-types": "0.37.32",
86+
"eslint": "8.34.0",
87+
"eslint-config-airbnb-base": "15.0.0",
88+
"eslint-plugin-import": "2.27.5",
89+
"npm-run-all": "4.1.5",
90+
"ts-node": "10.9.1",
91+
"typescript": "4.9.5"
9292
}
9393
}

src/lib/utility.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ import {
3535
GetCategoryChannelReturns,
3636
GetCollectionItemsCollection,
3737
GetCollectionItemsReturns,
38+
GetForumChannelGuild,
39+
GetForumChannelId,
40+
GetForumChannelReturns,
3841
GetTextBasedChannelGuild,
3942
GetTextBasedChannelId,
4043
GetTextBasedChannelReturns,
@@ -552,6 +555,35 @@ export function getCollectionItems<Key, Value>(collection: GetCollectionItemsCol
552555
return [...collection.values()];
553556
}
554557

558+
/**
559+
* Get forum channel.
560+
*
561+
* @param {GetForumChannelGuild} guild - Guild.
562+
* @param {GetForumChannelId} id - Id.
563+
*
564+
* @returns {GetForumChannelReturns}
565+
*
566+
* @since 1.0.0
567+
*/
568+
export function getForumChannel(guild: GetForumChannelGuild, id: GetForumChannelId): GetForumChannelReturns {
569+
const guildChannels = guild.channels;
570+
571+
if (id === undefined) {
572+
return undefined;
573+
}
574+
575+
const forumChannel = guildChannels.resolve(id);
576+
577+
if (
578+
forumChannel !== null
579+
&& forumChannel.type === ChannelType.GuildForum
580+
) {
581+
return forumChannel;
582+
}
583+
584+
return null;
585+
}
586+
555587
/**
556588
* Get text-based channel.
557589
*

src/modules/permission.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
generateCron,
1010
generateLogMessage,
1111
getCategoryChannel,
12+
getForumChannel,
1213
getTextBasedNonThreadChannel,
1314
getVoiceBasedChannel,
1415
isTimeZoneValid,
@@ -89,7 +90,7 @@ export function togglePerms(message: TogglePermsMessage, guild: TogglePermsGuild
8990
const theChannelChannelId = <TogglePermsEventToggleChannelChannelId>_.get(eventToggle, ['channel', 'channel-id']);
9091
const thePermissions = <TogglePermsEventTogglePermissions>_.get(eventToggle, ['permissions']);
9192

92-
const channel = getCategoryChannel(guild, theChannelChannelId) ?? getTextBasedNonThreadChannel(guild, theChannelChannelId) ?? getVoiceBasedChannel(guild, theChannelChannelId);
93+
const channel = getCategoryChannel(guild, theChannelChannelId) ?? getForumChannel(guild, theChannelChannelId) ?? getTextBasedNonThreadChannel(guild, theChannelChannelId) ?? getVoiceBasedChannel(guild, theChannelChannelId);
9394

9495
// If "toggle-perms[${eventKey}].toggles[${eventToggleKey}].channel.channel-id" is not configured properly.
9596
if (

src/types/index.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
EmbedBuilder,
1212
EmbedField,
1313
EmojiIdentifierResolvable,
14+
ForumChannel,
1415
Guild,
1516
GuildEmoji,
1617
GuildMember,
@@ -1261,6 +1262,17 @@ export type GetCategoryChannelId = Snowflake | undefined;
12611262

12621263
export type GetCategoryChannelReturns = CategoryChannel | null | undefined;
12631264

1265+
/**
1266+
* Get forum channel.
1267+
*
1268+
* @since 1.0.0
1269+
*/
1270+
export type GetForumChannelGuild = Guild;
1271+
1272+
export type GetForumChannelId = Snowflake | undefined;
1273+
1274+
export type GetForumChannelReturns = ForumChannel | null | undefined;
1275+
12641276
/**
12651277
* Get text-based channel.
12661278
*

0 commit comments

Comments
 (0)