Skip to content

Commit 8596600

Browse files
authored
Feat repel (#959)
* chore: add docker commands to package.json and update package manager version * feat: add repel command and mini mod role support
1 parent 3b4d038 commit 8596600

File tree

8 files changed

+262
-24
lines changed

8 files changed

+262
-24
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ ONBOARDING_CHANNEL=
4040
JOIN_LOG_CHANNEL=
4141
INTRO_CHANNEL=
4242
INTRO_ROLE=
43+
REPEL_ROLE_NAME=MiniMod # The name of the role that is used for MiniMods
44+
REPEL_DELETE_COUNT=2 # The number of messages to delete when using the repel command

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,15 @@ cd webdev-support-bot
105105

106106
cp .env.example .env # and enter a token
107107

108+
108109
yarn install # or npm install
109110
code .
110111

112+
yarn docker:dev:up
111113
yarn dev # or npm dev
112114

113115
# or be fancy with a one-liner
114-
git clone https://github.com/ljosberinn/webdev-support-bot/ && cd webdev-support-bot && cp .env.example .env && yarn install && code . && yarn dev
116+
git clone https://github.com/ljosberinn/webdev-support-bot/ && cd webdev-support-bot && cp .env.example .env && yarn install && code . && yarn docker:dev:up && yarn dev
115117
```
116118

117119
## Environment variables

docker-compose.dev.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
services:
2+
mongodb:
3+
image: mongo:7.0
4+
container_name: webdev-support-bot-mongo-dev
5+
restart: unless-stopped
6+
environment:
7+
MONGO_INITDB_ROOT_USERNAME: admin
8+
MONGO_INITDB_ROOT_PASSWORD: password
9+
MONGO_INITDB_DATABASE: webdev-support-bot
10+
ports:
11+
- "27017:27017"
12+
volumes:
13+
- mongodb_dev_data:/data/db
14+
15+
volumes:
16+
mongodb_dev_data:

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"test:ci": "jest --ci",
1818
"lint:fix": "eslint --fix src && prettier --write src",
1919
"lint:types": "tsc --noEmit",
20-
"install:clean": "rm -rf node_modules && rm yarn.lock && yarn"
20+
"install:clean": "rm -rf node_modules && rm yarn.lock && yarn",
21+
"docker:dev:up": "docker compose -f docker-compose.dev.yml up -d",
22+
"docker:dev:down": "docker compose -f docker-compose.dev.yml down"
2123
},
2224
"keywords": [],
2325
"author": "",
@@ -66,5 +68,6 @@
6668
"lint-staged": {
6769
"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": "prettier --write",
6870
"*.js": "eslint --fix"
69-
}
71+
},
72+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
7073
}

src/env.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ export const { ONBOARDING_CHANNEL } = process.env;
4242
export const { JOIN_LOG_CHANNEL } = process.env;
4343
export const { INTRO_CHANNEL } = process.env;
4444
export const { INTRO_ROLE } = process.env;
45+
46+
export const { REPEL_ROLE_NAME } = process.env;
47+
export const REPEL_DELETE_COUNT =
48+
Number.parseInt(process.env.REPEL_DELETE_COUNT) || 2;

src/v2/commands/index.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { resourceInteraction } from './resource/index.js';
3636
import { shitpostInteraction } from './shitpost/index.js';
3737
// import { warn } from './warn/index.js';
3838
import { whynoInteraction } from './whyno/index.js';
39+
import { repelInteraction } from './repel';
3940

4041
export const guildCommands = new Map(
4142
[
@@ -50,8 +51,9 @@ export const guildCommands = new Map(
5051
whynoInteraction,
5152
roleCommands,
5253
setupCommands,
54+
repelInteraction,
5355
// warn // Not used atm
54-
].map(command => [command.name, command])
56+
].map(command => [command.name, command]),
5557
); // placeholder for now
5658

5759
export const applicationCommands = new Collection<
@@ -88,7 +90,7 @@ const stripNullish = <T>(obj: T): T => {
8890
return Object.fromEntries(
8991
Object.entries(obj)
9092
.map(([a, b]) => [a, stripNullish(b)])
91-
.filter(([, b]) => b != null)
93+
.filter(([, b]) => b != null),
9294
) as T;
9395
};
9496

@@ -121,7 +123,7 @@ export const registerCommands = async (client: Client): Promise<void> => {
121123
content: 'Something went wrong when trying to execute the command',
122124
});
123125
}
124-
})
126+
}),
125127
);
126128

127129
for (const { onAttach } of applicationCommands.values()) {
@@ -152,7 +154,7 @@ export const registerCommands = async (client: Client): Promise<void> => {
152154
await addCommands(
153155
discordCommandsById,
154156
applicationCommands,
155-
client.application.commands
157+
client.application.commands,
156158
);
157159

158160
console.log('General Commands All Added');
@@ -170,14 +172,14 @@ async function addCommands(
170172
ApplicationCommand<{ guild: GuildResolvable }>
171173
>,
172174
commandDescriptions: Map<string, CommandDataWithHandler>,
173-
commandManager: ApplicationCommandManager | GuildApplicationCommandManager
175+
commandManager: ApplicationCommandManager | GuildApplicationCommandManager,
174176
) {
175177
const discordChatInputCommandsById = serverCommands.filter(
176-
x => x.type === ApplicationCommandType.ChatInput
178+
x => x.type === ApplicationCommandType.ChatInput,
177179
);
178180

179181
const discordCommands = new Collection(
180-
discordChatInputCommandsById.map(value => [value.name, value])
182+
discordChatInputCommandsById.map(value => [value.name, value]),
181183
);
182184

183185
const validCommands = pipe<
@@ -188,22 +190,22 @@ async function addCommands(
188190
([key, val]: [string, CommandDataWithHandler]) =>
189191
'guild' in commandManager && val.guildValidate
190192
? val.guildValidate(commandManager.guild)
191-
: true
193+
: true,
192194
),
193195
map(([key]) => key),
194196
]);
195197

196198
const newCommands = difference(
197199
validCommands(commandDescriptions),
198-
discordCommands.keys()
200+
discordCommands.keys(),
199201
);
200202
const existingCommands = intersection(
201203
validCommands(commandDescriptions),
202-
discordCommands.keys()
204+
discordCommands.keys(),
203205
);
204206
const deletedCommands = difference<string>(
205207
discordCommands.keys(),
206-
validCommands(commandDescriptions)
208+
validCommands(commandDescriptions),
207209
);
208210

209211
// const new = await client.application.commands.create()
@@ -213,15 +215,15 @@ async function addCommands(
213215
editExistingCommands(
214216
commandDescriptions,
215217
commandManager,
216-
discordCommands
218+
discordCommands,
217219
)(existingCommands),
218-
deleteRemovedCommands(commandManager, discordCommands)(deletedCommands)
219-
)
220+
deleteRemovedCommands(commandManager, discordCommands)(deletedCommands),
221+
),
220222
);
221223
}
222224

223225
function getDestination(
224-
commandManager: ApplicationCommandManager | GuildApplicationCommandManager
226+
commandManager: ApplicationCommandManager | GuildApplicationCommandManager,
225227
) {
226228
return 'guild' in commandManager
227229
? `Guild: ${commandManager.guild.name}`
@@ -230,7 +232,7 @@ function getDestination(
230232

231233
function createNewCommands(
232234
cmdDescriptions: Map<string, CommandDataWithHandler>,
233-
cmdMgr: ApplicationCommandManager | GuildApplicationCommandManager
235+
cmdMgr: ApplicationCommandManager | GuildApplicationCommandManager,
234236
) {
235237
const destination = getDestination(cmdMgr);
236238
return map(async (name: string) => {
@@ -248,7 +250,7 @@ function createNewCommands(
248250
function editExistingCommands(
249251
cmdDescriptions: Map<string, CommandDataWithHandler>,
250252
cmdMgr: ApplicationCommandManager | GuildApplicationCommandManager,
251-
existingCommands: Map<string, ApplicationCommand>
253+
existingCommands: Map<string, ApplicationCommand>,
252254
) {
253255
const destination = getDestination(cmdMgr);
254256
return map((name: string) => {
@@ -260,7 +262,7 @@ function editExistingCommands(
260262
if (
261263
!isEqual(
262264
getRelevantCmdProperties(cmd),
263-
getRelevantCmdProperties(existing)
265+
getRelevantCmdProperties(existing),
264266
)
265267
) {
266268
console.info(`Updating ${name} for ${destination}`);
@@ -272,7 +274,7 @@ function editExistingCommands(
272274

273275
function deleteRemovedCommands(
274276
cmdMgr: ApplicationCommandManager | GuildApplicationCommandManager,
275-
existingCommands: Map<string, ApplicationCommand>
277+
existingCommands: Map<string, ApplicationCommand>,
276278
) {
277279
const destination = getDestination(cmdMgr);
278280
return map(async (name: string) => {

0 commit comments

Comments
 (0)