Skip to content

Commit 3d6e2fc

Browse files
authored
Thread enforcer module (#84)
* Improve module typing * Upgrade to node 16 * Adds thread enforcer module * Bumps chart version
1 parent 4a5d670 commit 3d6e2fc

28 files changed

+2200
-2594
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
FROM node:14-alpine as base
1+
FROM node:16-alpine as base
22
WORKDIR /app
33
COPY package.json yarn.lock ./
44
RUN yarn install --frozen-lockfile --network-timeout 600000
55
COPY tsconfig.json /app
66
COPY src/ /app/src/
77
RUN yarn build
88

9-
FROM node:14-alpine
9+
FROM node:16-alpine
1010
WORKDIR /app
1111
COPY package.json yarn.lock ./
1212
RUN yarn install --frozen-lockfile --network-timeout 600000 --prod

helm/citsbot/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
apiVersion: v2
22
description: UWA CSDS Discord Bot
33
name: citsbot
4-
version: 1.16.4
4+
version: 1.17.0

helm/citsbot/values.local.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,21 @@ instances:
6767
- anime
6868
- manga
6969
keywordCountThreshold: 5
70+
threadEnforcer:
71+
channels:
72+
- channelId: '957264516327018516'
73+
channelName: '#project-showcase'
74+
topicSingular: 'project'
75+
topicPlural: 'projects'
76+
- channelId: '957223775269703701'
77+
channelName: '#job-opportunities'
78+
topicSingular: 'job opportunity'
79+
topicPlural: 'job opportunities'
80+
ruleBreakDm: |-
81+
Hey {username} 👋, I deleted your message in {channelName} because all discussions about individual {topicPlural} should take place in threads 🧵.
82+
83+
ℹ️ Enforcing the use of threads ensures that the {topicPlural} you and everyone else share stay as visible as possible for as long as possible. You can create a new thread by right clicking or long pressing on a message and selecting "Create Thread". Please see this article for more about Discord's threads feature: https://support.discord.com/hc/en-us/articles/4403205878423.
84+
85+
💡 If you are trying to share a new {topicSingular}, please ensure you include a link to it in your message.
86+
87+
🚩 If you believe this action was taken in error, please reach out to one of the server moderators.

helm/citsbot/values.prod.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,3 +412,21 @@ instances:
412412
- anime
413413
- manga
414414
keywordCountThreshold: 5
415+
threadEnforcer:
416+
channels:
417+
- channelId: '862342865270472704'
418+
channelName: '#project-showcase'
419+
topicSingular: 'project'
420+
topicPlural: 'projects'
421+
- channelId: '910432145217028136'
422+
channelName: '#job-opportunities'
423+
topicSingular: 'job opportunity'
424+
topicPlural: 'job opportunities'
425+
ruleBreakDm: |-
426+
Hey {username} 👋, I deleted your message in {channelName} because all discussions about individual {topicPlural} should take place in threads 🧵.
427+
428+
ℹ️ Enforcing the use of threads ensures that the {topicPlural} you and everyone else share stay as visible as possible for as long as possible. You can create a new thread by right clicking or long pressing on a message and selecting "Create Thread". Please see this article for more about Discord's threads feature: https://support.discord.com/hc/en-us/articles/4403205878423.
429+
430+
💡 If you are trying to share a new {topicSingular}, please ensure you include a link to it in your message.
431+
432+
🚩 If you believe this action was taken in error, please reach out to one of the server moderators.

package.json

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,34 @@
1313
"lint": "eslint \"src/**/*.ts\" --fix"
1414
},
1515
"dependencies": {
16-
"cheerio": "1.0.0-rc.3",
17-
"discord.js": "12.3.1",
18-
"node-fetch": "2.6.1",
19-
"node-schedule": "1.3.2",
20-
"prom-client": "12.0.0",
21-
"winston": "3.3.3",
22-
"winston-transport": "4.4.0"
16+
"cheerio": "1.0.0-rc.10",
17+
"discord.js": "12.5.3",
18+
"node-fetch": "2.6.7",
19+
"node-schedule": "2.1.0",
20+
"prom-client": "14.0.1",
21+
"winston": "3.6.0",
22+
"winston-transport": "4.5.0"
2323
},
2424
"devDependencies": {
25-
"@tsconfig/node14": "1.0.0",
26-
"@types/cheerio": "0.22.22",
27-
"@types/jest": "26.0.14",
28-
"@types/node": "14.11.2",
29-
"@types/node-fetch": "2.5.7",
30-
"@types/node-schedule": "1.3.1",
31-
"@types/ws": "7.4.0",
32-
"@typescript-eslint/eslint-plugin": "4.2.0",
33-
"@typescript-eslint/parser": "4.2.0",
34-
"eslint": "7.9.0",
35-
"eslint-config-prettier": "6.15.0",
36-
"eslint-plugin-prettier": "3.1.4",
37-
"jest": "26.4.2",
38-
"nock": "13.0.5",
39-
"prettier-eslint": "11.0.0",
40-
"prettier-eslint-cli": "5.0.0",
41-
"ts-jest": "26.4.0",
42-
"ts-node": "9.0.0",
43-
"ts-node-dev": "1.0.0-pre.63",
44-
"typescript": "4.0.3"
25+
"@tsconfig/node16": "1.0.2",
26+
"@types/cheerio": "0.22.31",
27+
"@types/jest": "27.4.1",
28+
"@types/node": "17.0.23",
29+
"@types/node-fetch": "2.6.1",
30+
"@types/node-schedule": "1.3.2",
31+
"@types/ws": "8.5.3",
32+
"@typescript-eslint/eslint-plugin": "5.16.0",
33+
"@typescript-eslint/parser": "5.16.0",
34+
"eslint": "8.12.0",
35+
"eslint-config-prettier": "8.5.0",
36+
"eslint-plugin-prettier": "4.0.0",
37+
"jest": "27.5.1",
38+
"nock": "13.2.4",
39+
"prettier-eslint": "13.0.0",
40+
"prettier-eslint-cli": "5.0.1",
41+
"ts-jest": "27.1.4",
42+
"ts-node": "10.7.0",
43+
"ts-node-dev": "1.1.8",
44+
"typescript": "4.6.3"
4545
}
4646
}

src/discord/discord-bot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { discordEmitter, DiscordEmitter } from './metrics';
77
import { LoggingService } from '../utils/logging';
88
import { discordApi } from './discord-api';
99
import { DiscordBot, DiscordAPI, DiscordChannel, DiscordEmoji, DiscordMessage, DiscordMessageAttachment, DiscordReaction, DiscordUser } from './types';
10-
import { BotModule } from '../domain/module-types';
10+
import { BotModule } from '../domain/types';
1111

1212
const parseUser = (user: User | PartialUser): DiscordUser => ({
1313
id: user.id,

src/domain/anime-detector/module.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { DiscordMessage, DiscordMessageAttachment } from '../../discord/types';
22
import { LoggingService } from '../../utils/logging';
33
import { BotAction, BotActionType } from '../action-types';
4-
import { AnimeDetectorModule, ModuleType } from '../module-types';
4+
import { BotModule } from '../types';
55
import { AnimeDetectorEmitter } from './metrics';
66
import { AnimeDetectorService } from './detector-service';
77
import { ImageUploaderService } from './upload-image-service';
88

9+
export interface AnimeDetectorModule extends BotModule {
10+
onMessage: (message: DiscordMessage) => Promise<BotAction[]>;
11+
}
12+
913
export const animeDetectorModule = (
1014
{ log }: LoggingService,
1115
emitter: AnimeDetectorEmitter,
@@ -37,7 +41,7 @@ export const animeDetectorModule = (
3741
return [];
3842
};
3943

40-
return { type: ModuleType.AnimeDetector, onMessage };
44+
return { onMessage };
4145
};
4246

4347
const PATTERN_GENERIC_IMAGE = /\w*?(https?:\/\/[^ ]+?\.(jpg|jpeg|png|tif|bmp|gif|webp))\w*?/gi;

src/domain/anime-detector/upload-image-service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export const imgurImageUploaderService = (
1616

1717
if (!response.ok) throw Error(`Failed to upload image to imgur. Got non-200 response code: ${response.status}, ${await response.text()}`);
1818

19-
const data = await response.json();
19+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
20+
const data: any = await response.json();
2021
const imgurLink = data?.data?.link;
2122
if (typeof imgurLink !== `string`) throw Error(`Failed to upload image to imgur. Link not present in response body: ${JSON.stringify(data)}`);
2223

src/domain/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type BotConfig = {
1111
announcer?: Record<string, unknown>;
1212
reactRoles?: Record<string, unknown>;
1313
animeDetector?: Record<string, unknown>;
14+
threadEnforcer?: Record<string, unknown>;
1415
};
1516
}
1617

src/domain/cowsay/formatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const cowsayFormatter = (
88
config: CowsayConfig
99
): CowsayFormatter =>
1010
message => {
11-
const sanitizedMessage = message.replace(/`/g, `'`);
11+
const sanitizedMessage = message.replaceAll(`\``, `'`);
1212
const lines = wrapText(sanitizedMessage, config.lineMaxLen);
1313
let maxLineLen = -1;
1414
lines.forEach(line => {

0 commit comments

Comments
 (0)