Skip to content

Commit

Permalink
refactor: remove IG mentions (#99)
Browse files Browse the repository at this point in the history
* refactor: remove IG mentions

* feat: remove reactions from selfrole

As the embed needs to be generated again, it is time to remove the mentions
and use buttons instead.

* fix: do not reply to all interactions

* fix: interaction already acknowledged

* fix: new docker-compose version

* refactor: remove zeroWidthSpace from config

* fix: use displayName instead of nickname
  • Loading branch information
HunteRoi authored Aug 30, 2023
1 parent 7c503b1 commit 02b4fe8
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 98 deletions.
4 changes: 2 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ A big welcome and thank you for considering contributing to this project. We wan
* [References](#references)

## Code of Conduct
We take our open source community seriously and hold ourselves and other contributors to high standards of communication. By participating and contributing to this project, you agree to uphold yo our [Code Of Conduct](https://github.com/IESN-IG/DataDrop/blob/master/.github/CODE_OF_CONDUCT.md).
We take our open source community seriously and hold ourselves and other contributors to high standards of communication. By participating and contributing to this project, you agree to uphold yo our [Code Of Conduct](https://github.com/section-IG/DataDrop/blob/master/.github/CODE_OF_CONDUCT.md).

## Getting started
We use [GitHub](https://github.com) to host code, to track Issues and feature requests, as well as accept Pull Requests (PRs). A few guidelines that cover all these topics:
- Search for existing Issues and PRs before creating your own.
- We work hard to makes sure issues are handled in a timely manner but, depending on the impact, it could take a while to investigate the root cause. A friendly ping in the comment thread to the submitter or a contributor can help draw attention if your issue is blocking.

### Issues
We use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.com/IESN-IG/DataDrop/issues/new/choose); it's that easy!
We use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.com/section-IG/DataDrop/issues/new/choose); it's that easy!

**Great Bug Reports** tend to have:
- A quick summary and/or background
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 IESN - IG
Copyright (c) 2019 Section - IODA

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# DataDrop
[![Continuous Delivery](https://github.com/Section-IG/DataDrop/actions/workflows/deployment.yml/badge.svg)](https://github.com/Section-IG/DataDrop/actions/workflows/deployment.yml)

Discord bot built with Discord.JS for Section IG guild.
Discord bot built with Discord.JS for Section IODA guild.

The following environment variables must be filled in a `.env` file.
This file is used when building the container to generate a production-ready .env file.
Expand Down
13 changes: 6 additions & 7 deletions config.development.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
],
"minLevel": "debug",
"includeTimestamp": true,
"prefix": "igb!",
"botName": "IG Bot Beta",
"prefix": "dab!",
"botName": "Yoda Beta",
"communitymanagerRoleid": "1028257512383848478",
"adminRoleid": "1028257512358674472",
"delegatesRoleid": "1028257512358674468",
"professorRoleid": "1028257512358674470",
"verifiedRoleId": "1048774508007407726",
"informationsChannelid": "1028257513109454855",
"faqChannelid": "1028257513109454856",
"igcomiteeChannelid": "1028257513109454857",
"comiteeChannelid": "1028257513109454857",
"dynamicChannelPrefix": "[DRoom]",
"dynamicChannelPrefixRegex": "^\\[DRoom\\]",
"staticTriggerChannelids": [
Expand All @@ -25,7 +25,7 @@
"1028257515680583727"
],
"rolesChannelid": "1028257513319170089",
"ig1": {
"first": {
"channelid": "1028257513604390939",
"roleid": "1028257512337711148",
"emote": "1⃣",
Expand Down Expand Up @@ -56,7 +56,7 @@
}
]
},
"ig2": {
"second": {
"channelid": "1028257514296463431",
"roleid": "1028257512337711152",
"emote": "2⃣",
Expand All @@ -75,7 +75,7 @@
}
]
},
"ig3": {
"third": {
"channelid": "1028257514799779857",
"roleid": "1028257512358674464",
"emote": "3⃣",
Expand Down Expand Up @@ -109,7 +109,6 @@
},
"ok_hand": "👌",
"warning": "⚠️",
"zeroWidthSpace": "",
"communicationServiceOptions": {
"mailData": {
"from": "[email protected]",
Expand Down
13 changes: 6 additions & 7 deletions config.production.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
],
"minLevel": "info",
"includeTimestamp": true,
"prefix": "ig!",
"botName": "IG Bot",
"prefix": "da!",
"botName": "Yoda",
"communitymanagerRoleid": "288659580064366592",
"adminRoleid": "360850813914185738",
"delegatesRoleid": "288659613732306944",
"professorRoleid": "360457051417083907",
"verifiedRoleId": "1048774703206109264",
"informationsChannelid": "288666915314991107",
"faqChannelid": "360126831376203778",
"igcomiteeChannelid": "506564987914027008",
"comiteeChannelid": "506564987914027008",
"dynamicChannelPrefix": "[DRoom]",
"dynamicChannelPrefixRegex": "^\\[DRoom\\]",
"staticTriggerChannelids": [
Expand All @@ -25,7 +25,7 @@
"762382057157558352"
],
"rolesChannelid": "522843160594874368",
"ig1": {
"first": {
"channelid": "764241363452690472",
"roleid": "353210852700061696",
"emote": "1⃣",
Expand Down Expand Up @@ -56,7 +56,7 @@
}
]
},
"ig2": {
"second": {
"channelid": "764241472534085662",
"roleid": "353210788271357954",
"emote": "2⃣",
Expand All @@ -75,7 +75,7 @@
}
]
},
"ig3": {
"third": {
"channelid": "628864027321303049",
"roleid": "353210727978237952",
"emote": "3⃣",
Expand Down Expand Up @@ -109,7 +109,6 @@
},
"ok_hand": "👌",
"warning": "⚠️",
"zeroWidthSpace": "",
"communicationServiceOptions": {
"mailData": {
"from": "[email protected]",
Expand Down
8 changes: 2 additions & 6 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ x-restart-policy:
version: '3.8'
services:
database:
<<: *env-file
<<: *network
<<: *restart-policy
<<: [*env-file, *network, *restart-policy]
build:
context: .
dockerfile: ./Database.Dockerfile
Expand All @@ -30,9 +28,7 @@ services:
timeout: 1s
retries: 60
bot:
<<: *env-file
<<: *network
<<: *restart-policy
<<: [*env-file, *network, *restart-policy]
build:
context: .
dockerfile: ./Dockerfile
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
},
"repository": {
"type": "git",
"url": "git+ssh://[email protected]:IESN-IG/DataDrop.git"
"url": "git+ssh://[email protected]:section-IG/DataDrop.git"
},
"author": "HunteRoi <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/IESN-IG/DataDrop/issues"
"url": "https://github.com/section-IG/DataDrop/issues"
},
"homepage": "https://github.com/IESN-IG/DataDrop#readme",
"homepage": "https://github.com/section-IG/DataDrop#readme",
"dependencies": {
"@hunteroi/advanced-logger": "^0.0.3",
"@hunteroi/discord-selfrole": "^3.1.0",
"@hunteroi/discord-selfrole": "^3.2.0",
"@hunteroi/discord-temp-channels": "^3.1.0",
"@hunteroi/discord-verification": "^1.4.0",
"discord.js": "^14.8.0",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const people = [
emails: ['[email protected]'],
},
{
name: 'Comité IG',
name: 'Comité IODA',
emails: ['[email protected]'],
},
];
Expand Down
13 changes: 3 additions & 10 deletions src/commands/eval.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Message, codeBlock } from 'discord.js';

import { DatadropClient } from '../datadrop';
import { Configuration } from '../models/Configuration';
import { clean } from '../helpers';

module.exports = {
name: 'eval',
Expand All @@ -25,18 +25,11 @@ module.exports = {
evaled = util.inspect(evaled);
}

content = clean(evaled, config);
content = clean(evaled);
} catch (err) {
content = `// An error occured\n\n${clean(err, config)}`;
content = `// An error occured\n\n${clean(err)}`;
} finally {
message.channel.send(codeBlock('xl', content));
}
}
};

function clean(text: any, config: Configuration): string {
if (typeof (text) === 'string') {
return text.replace(/@/g, `@${config.zeroWidthSpace}`);
}
return text;
}
9 changes: 4 additions & 5 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@ const defaultConfig: Configuration = {
verifiedRoleId: '',
informationsChannelid: '',
faqChannelid: '',
igcomiteeChannelid: '',
comiteeChannelid: '',
dynamicChannelPrefix: '',
dynamicChannelPrefixRegex: /.*/,
staticTriggerChannelids: [],
rolesChannelid: '',
ig1: { channelid: '', roleid: '', emote: '', groups: [] },
ig2: { channelid: '', roleid: '', emote: '', groups: [] },
ig3: { channelid: '', roleid: '', emote: '', groups: [] },
first: { channelid: '', roleid: '', emote: '', groups: [] },
second: { channelid: '', roleid: '', emote: '', groups: [] },
third: { channelid: '', roleid: '', emote: '', groups: [] },
alumni: { roleid: '', emote: '' },
tutor: { roleid: '', emote: '' },
announce: { roleid: '', emote: '', channelid: '' },
ok_hand: '',
warning: '',
zeroWidthSpace: '',
communicationServiceOptions: {
apiKey: '',
mailData: { from: '', templateId: '' }
Expand Down
49 changes: 30 additions & 19 deletions src/datadrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,12 @@ export class DatadropClient extends Client {
includeTimestamp: config.includeTimestamp,
});
this.commands = new Collection();

this.selfRoleManager = new SelfRoleManager(this, {
channelsMessagesFetchLimit: 10,
deleteAfterUnregistration: false,
useReactions: true,
deleteAfterUnregistration: false
});
this.#listenToSelfRoleEvents();

this.tempChannelsManager = new TempChannelsManager(this);
this.#listenToTempChannelsEvents();

this.database = new PostgresDatabaseService(this.logger);
const communicationService = new SendGridService(config.communicationServiceOptions);
Expand All @@ -57,7 +54,6 @@ export class DatadropClient extends Client {
validCodeMessage: (user: User, code: string) => `Le code ${code} est valide. Bienvenue ${user.username}!`,
invalidCodeMessage: (_, code: string) => `Le code ${code} est invalide!`
});
this.#listenToVerificationEvents();
}

get config(): Configuration {
Expand Down Expand Up @@ -116,24 +112,33 @@ export class DatadropClient extends Client {
const channel = msg.channel as GuildTextBasedChannel;
this.logger.info(`Message récupéré dans ${channel.parent!.name}-${channel.name} (${msg.channelId})`);
});
this.selfRoleManager.on(SelfRoleManagerEvents.roleAdd, (role, member) => this.logger.info(`Le rôle ${role.name} (<${role.id}>) a été ajouté à <${member.user.tag}>`));
this.selfRoleManager.on(SelfRoleManagerEvents.roleRemove, (role, member) => this.logger.info(`Le rôle ${role.name} (<${role.id}>) a été retiré de <${member.user.tag}>`));
this.selfRoleManager.on(SelfRoleManagerEvents.requiredRolesMissing, async (member: GuildMember, reaction: ButtonInteraction | MessageReaction | PartialMessageReaction, role: Role, requiredRoles: string[]) => {
this.selfRoleManager.on(SelfRoleManagerEvents.roleAdd, async (role: Role, member: GuildMember, interaction: ButtonInteraction) => {
this.logger.info(`Le rôle ${role.name} (<${role.id}>) a été ajouté à <${member.user.tag}>`);

await interaction.editReply(`Le rôle ${role} t'a été ajouté.`);
});
this.selfRoleManager.on(SelfRoleManagerEvents.roleRemove, async (role: Role, member: GuildMember, interaction: ButtonInteraction) => {
this.logger.info(`Le rôle ${role.name} (<${role.id}>) a été retiré de <${member.user.tag}>`);

await interaction.editReply(`Le rôle ${role} t'a été retiré.`);
});
this.selfRoleManager.on(SelfRoleManagerEvents.requiredRolesMissing, async (member: GuildMember, interaction: ButtonInteraction, role: Role, requiredRoles: string[]) => {
const requiredRolesMissing = (await Promise.all(requiredRoles.map(requiredRole => member.guild.roles.fetch(requiredRole))))
.map((requiredRole: Role | null) => requiredRole?.name)
.filter(requiredRoles => !!requiredRoles);

this.logger.info(`Le rôle ${role.name} (<${role.id}>) n'a pas pu être donné à <${member.user.tag}> parce que tous les rôles requis ne sont pas assignés à ce membre: ${requiredRolesMissing.join(', ')}`);
if (!(reaction instanceof ButtonInteraction)) {
try {
await member.send({ content: `Tu ne peux pas t'assigner le rôle ${role.name}! Tu dois d'abord avoir les rôles suivants: ${requiredRolesMissing.join(', ')}` });
} catch { /** ignore */ }
finally {
await reaction.users.remove(member);
}
}
this.logger.info(`Le rôle ${role.name} (<${role.id}>) n'a pas pu être donné à <${member.user.tag}> parce que tous les rôles requis ne sont pas assignés à ce membre: ${requiredRolesMissing.join(', ')}.`);

await interaction.editReply(`Tu ne peux pas t'assigner le rôle ${role}! Tu dois d'abord avoir les rôles suivants: ${requiredRolesMissing.join(', ')}.`);
});
this.selfRoleManager.on(SelfRoleManagerEvents.maxRolesReach, async (member: GuildMember, interaction: ButtonInteraction, currentRolesNumber: number, maxRolesNumber: number, role: Role) => {
this.logger.info(`Le rôle ${role.name} (<${role.id}>) n'a pas pu être donné à <${member.user.tag}> parce que ce membre a été la limite de rôles: ${currentRolesNumber}/${maxRolesNumber}.`);

await interaction.editReply(`Tu ne peux pas t'assigner le rôle ${role}! Tu as atteint la limite: ${currentRolesNumber}/${maxRolesNumber}.`);
});
this.selfRoleManager.on(SelfRoleManagerEvents.error, (error: unknown, message: string) => {
this.logger.error(`Une erreur est survenue lors de la gestion des rôles automatiques.\nErreur: ${message}\n${getErrorMessage(error)}`);
});
this.selfRoleManager.on(SelfRoleManagerEvents.error, (error: unknown, message: string) => this.logger.error(`Une erreur est survenue lors de la gestion des rôles automatiques.\nErreur: ${message}\n${getErrorMessage(error)}`));
}

#bindEvents(): void {
Expand All @@ -155,7 +160,13 @@ export class DatadropClient extends Client {
}

async start(): Promise<void> {

this.#listenToSelfRoleEvents();
this.#listenToTempChannelsEvents();
this.#listenToVerificationEvents();

this.#bindEvents();

this.#bindCommands();
await this.database?.start();
this.login();
Expand Down
Loading

0 comments on commit 02b4fe8

Please sign in to comment.