Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ ONBOARDING_CHANNEL=
JOIN_LOG_CHANNEL=
INTRO_CHANNEL=
INTRO_ROLE=
REPEL_ROLE_NAME=MiniMod # The name of the role that is used for MiniMods
REPEL_DELETE_COUNT=2 # The number of messages to delete when using the repel command
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ cd webdev-support-bot

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


yarn install # or npm install
code .

yarn docker:dev:up
yarn dev # or npm dev

# or be fancy with a one-liner
git clone https://github.com/ljosberinn/webdev-support-bot/ && cd webdev-support-bot && cp .env.example .env && yarn install && code . && yarn dev
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
```

## Environment variables
Expand Down
16 changes: 16 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
services:
mongodb:
image: mongo:7.0
container_name: webdev-support-bot-mongo-dev
restart: unless-stopped
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: password
MONGO_INITDB_DATABASE: webdev-support-bot
ports:
- "27017:27017"
volumes:
- mongodb_dev_data:/data/db

volumes:
mongodb_dev_data:
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"test:ci": "jest --ci",
"lint:fix": "eslint --fix src && prettier --write src",
"lint:types": "tsc --noEmit",
"install:clean": "rm -rf node_modules && rm yarn.lock && yarn"
"install:clean": "rm -rf node_modules && rm yarn.lock && yarn",
"docker:dev:up": "docker compose -f docker-compose.dev.yml up -d",
"docker:dev:down": "docker compose -f docker-compose.dev.yml down"
},
"keywords": [],
"author": "",
Expand Down Expand Up @@ -66,5 +68,6 @@
"lint-staged": {
"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": "prettier --write",
"*.js": "eslint --fix"
}
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
4 changes: 4 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ export const { ONBOARDING_CHANNEL } = process.env;
export const { JOIN_LOG_CHANNEL } = process.env;
export const { INTRO_CHANNEL } = process.env;
export const { INTRO_ROLE } = process.env;

export const { REPEL_ROLE_NAME } = process.env;
export const REPEL_DELETE_COUNT =
Number.parseInt(process.env.REPEL_DELETE_COUNT) || 2;
40 changes: 21 additions & 19 deletions src/v2/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { resourceInteraction } from './resource/index.js';
import { shitpostInteraction } from './shitpost/index.js';
// import { warn } from './warn/index.js';
import { whynoInteraction } from './whyno/index.js';
import { repelInteraction } from './repel';

export const guildCommands = new Map(
[
Expand All @@ -50,8 +51,9 @@ export const guildCommands = new Map(
whynoInteraction,
roleCommands,
setupCommands,
repelInteraction,
// warn // Not used atm
].map(command => [command.name, command])
].map(command => [command.name, command]),
); // placeholder for now

export const applicationCommands = new Collection<
Expand Down Expand Up @@ -88,7 +90,7 @@ const stripNullish = <T>(obj: T): T => {
return Object.fromEntries(
Object.entries(obj)
.map(([a, b]) => [a, stripNullish(b)])
.filter(([, b]) => b != null)
.filter(([, b]) => b != null),
) as T;
};

Expand Down Expand Up @@ -121,7 +123,7 @@ export const registerCommands = async (client: Client): Promise<void> => {
content: 'Something went wrong when trying to execute the command',
});
}
})
}),
);

for (const { onAttach } of applicationCommands.values()) {
Expand Down Expand Up @@ -152,7 +154,7 @@ export const registerCommands = async (client: Client): Promise<void> => {
await addCommands(
discordCommandsById,
applicationCommands,
client.application.commands
client.application.commands,
);

console.log('General Commands All Added');
Expand All @@ -170,14 +172,14 @@ async function addCommands(
ApplicationCommand<{ guild: GuildResolvable }>
>,
commandDescriptions: Map<string, CommandDataWithHandler>,
commandManager: ApplicationCommandManager | GuildApplicationCommandManager
commandManager: ApplicationCommandManager | GuildApplicationCommandManager,
) {
const discordChatInputCommandsById = serverCommands.filter(
x => x.type === ApplicationCommandType.ChatInput
x => x.type === ApplicationCommandType.ChatInput,
);

const discordCommands = new Collection(
discordChatInputCommandsById.map(value => [value.name, value])
discordChatInputCommandsById.map(value => [value.name, value]),
);

const validCommands = pipe<
Expand All @@ -188,22 +190,22 @@ async function addCommands(
([key, val]: [string, CommandDataWithHandler]) =>
'guild' in commandManager && val.guildValidate
? val.guildValidate(commandManager.guild)
: true
: true,
),
map(([key]) => key),
]);

const newCommands = difference(
validCommands(commandDescriptions),
discordCommands.keys()
discordCommands.keys(),
);
const existingCommands = intersection(
validCommands(commandDescriptions),
discordCommands.keys()
discordCommands.keys(),
);
const deletedCommands = difference<string>(
discordCommands.keys(),
validCommands(commandDescriptions)
validCommands(commandDescriptions),
);

// const new = await client.application.commands.create()
Expand All @@ -213,15 +215,15 @@ async function addCommands(
editExistingCommands(
commandDescriptions,
commandManager,
discordCommands
discordCommands,
)(existingCommands),
deleteRemovedCommands(commandManager, discordCommands)(deletedCommands)
)
deleteRemovedCommands(commandManager, discordCommands)(deletedCommands),
),
);
}

function getDestination(
commandManager: ApplicationCommandManager | GuildApplicationCommandManager
commandManager: ApplicationCommandManager | GuildApplicationCommandManager,
) {
return 'guild' in commandManager
? `Guild: ${commandManager.guild.name}`
Expand All @@ -230,7 +232,7 @@ function getDestination(

function createNewCommands(
cmdDescriptions: Map<string, CommandDataWithHandler>,
cmdMgr: ApplicationCommandManager | GuildApplicationCommandManager
cmdMgr: ApplicationCommandManager | GuildApplicationCommandManager,
) {
const destination = getDestination(cmdMgr);
return map(async (name: string) => {
Expand All @@ -248,7 +250,7 @@ function createNewCommands(
function editExistingCommands(
cmdDescriptions: Map<string, CommandDataWithHandler>,
cmdMgr: ApplicationCommandManager | GuildApplicationCommandManager,
existingCommands: Map<string, ApplicationCommand>
existingCommands: Map<string, ApplicationCommand>,
) {
const destination = getDestination(cmdMgr);
return map((name: string) => {
Expand All @@ -260,7 +262,7 @@ function editExistingCommands(
if (
!isEqual(
getRelevantCmdProperties(cmd),
getRelevantCmdProperties(existing)
getRelevantCmdProperties(existing),
)
) {
console.info(`Updating ${name} for ${destination}`);
Expand All @@ -272,7 +274,7 @@ function editExistingCommands(

function deleteRemovedCommands(
cmdMgr: ApplicationCommandManager | GuildApplicationCommandManager,
existingCommands: Map<string, ApplicationCommand>
existingCommands: Map<string, ApplicationCommand>,
) {
const destination = getDestination(cmdMgr);
return map(async (name: string) => {
Expand Down
Loading
Loading