Skip to content

Automate dFunk roles#196

Open
crystopherross wants to merge 101 commits intomainfrom
iss41
Open

Automate dFunk roles#196
crystopherross wants to merge 101 commits intomainfrom
iss41

Conversation

@crystopherross
Copy link
Copy Markdown
Contributor

@crystopherross crystopherross commented May 15, 2025

Summary

This PR automates the process of updating Discord roles based on data from the dfunkt API, which addresses #41. The task runs automatically every Saturday at 12:00 AM, adjusting roles accordingly. This update reduces manual effort previously required to elect new posts and manage roles. The current functionary roles are automatically updated using Hive, the rest using data from dfunk. The update is done to every server the bots is in, but it is inactive by default, can be activated/deactivated using the /dfunk toggle command. However the command at this moment globally turns on/off the cronjob, this should be okay since the cronjob is only instantiated in the normal bot (not light).

Technical Details

  • Roles Updated: The following roles are now automatically updated:
    • Those implemented in Hive.
    • Dfunk group roles (dFunk, D-rek on Discord).
    • Special roles (for the moment dFunkt).
    • If roles with the given names are not in the server, these are created and used during the updates.
    • It is thus assumed that no dfunk-unrelated role has the same name as a dfunk-related role in Discord.
  • dfunkt API Integration:
    • The script communicates with the dfunkt API, using a series of functions to make GET requests as documented in the dfunkt GitHub repo. These are located in dfunk.ts.
    • Additional group and especial roles should be added manually in update-dfunk-roles.ts, in global variables groupRoleNames, specialRoleNames, dfunkGroupToDiscordRoleMapping.
    • Types for the data fetched from dfunkt where also created in dfunk-interfaces.ts
    • Only one endpoint is implemented at the moment, but the rest can be added easily.
  • Hive API Integration
    • Implemented in hive.ts.
    • May be expanded upon if needed.
  • Error Handling:
    • The script attempts to execute the update process up to 5 times, retrying every minute if it fails.
    • After 5 consecutive failures, an error message is logged to the Sysemgruppen's Mattermost uptimerobot channel.
    • A manual command (/dfunk update) is introduced for administrators to trigger the update manually.
    • Upon updating the following is logged on the console:
      • Which Discord users (KTH-ID) could not be updated.
      • If some group role in dfunk was not handled, and thus should be manually added to dfunkGroupToDiscordRoleMapping and groupRoleNames accordingly.
      • If some roles were created and what their names are.
  • Other Commands: Besides the /dfunk update command, the following are implemented:
    • /dfunk status: Returns the current status of the automatic update, whether it is active or not, when was the last update done, and if active, when the next update will take place (in UTC time).
      . /dfunk toggle: Turns on/off the automatic role update for all servers. By default the automatic update is inactive, thus, to use this feature, this command has to be run.

CronJobs

This PR introduces basic cron job functionality for automated tasks. It uses the cron package to create and manage scheduled tasks, which can be expanded in the future for other automated features. This also introduces new dependencies in package.json.

Side Effects

  • New Packages: The cron package and related dependencies have been added to package.json for cron job functionality.
  • Manual Command: The /dfunk command is now available for administrators to manage the automatic role updates.

Copy link
Copy Markdown
Member

@RafDevX RafDevX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not review further, @Benjaneb shall continue

Comment thread src/commands/commands.names.ts Outdated
Comment thread src/commands/commands.names.ts Outdated
Comment thread src/commands/testMandate/test.command.ts Outdated
Comment thread src/commands/commands.names.ts
@RafDevX RafDevX requested a review from Benjaneb May 22, 2025 16:11
@MuhammedReza07 MuhammedReza07 linked an issue Nov 12, 2025 that may be closed by this pull request
@MuhammedReza07
Copy link
Copy Markdown
Collaborator

  1. What remains to be done for this branch to be merged? It might be reasonable to merge and open a lot of additional issues instead of continuing the work on this branch. (It would at least make review simpler.)
  2. When reading through the commits, it seems like there is more functionality implemented here than is described by the initial PR message. Could you please update it to better reflect what you have implemented?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatically add dfunk roles using information from Hive

4 participants