1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-04-30 11:09:54 +03:00

Split GuildUpdateService into separate services (#80)

GuildUpdateService is a service that contains way too many
responsibilities with everything strictly coupled to each other. The
code is buggy, hard to refactor and swallows errors. This prompted me to
make this PR, which splits it into three independant services:
- SongUpdateService (responsible for changing songs presence);
- MemberUpdateService (responsible for updating member datas: unbanning
users, adding the default role, sending reminders, filtering nicknames);
- ScheduledEventUpdateService (responsible for updating scheduled
events: sending notifications, automatically starting events).

All of these services and their methods use Results to push errors all
the way up in the stack, making sure no error is missed. To make logging
and debugging easier, an extension method for `ILogger` was created -
`LogResult`. The method checks if the result was successful or if its
failure was caused by a user or environment error before logging
anything - providing cleaner code and logs. `ExceptionError`s will also
have their exception stacktrace and type logged (except in Remora code).

This PR also fixes an issue that prevented banned users from being
unbanned when their punishment was over.

---------

Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
Octol1ttle 2023-08-05 23:02:40 +05:00 committed by GitHub
parent e9f7825e4a
commit f260681b39
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 720 additions and 653 deletions

View file

@ -2,6 +2,7 @@ using System.ComponentModel;
using System.Text;
using Boyfriend.Data;
using Boyfriend.Services;
using Boyfriend.Services.Update;
using JetBrains.Annotations;
using Remora.Commands.Attributes;
using Remora.Commands.Groups;
@ -203,7 +204,7 @@ public class BanCommandGroup : CommandGroup
/// was unbanned and vice-versa.
/// </returns>
/// <seealso cref="ExecuteBanAsync" />
/// <seealso cref="GuildUpdateService.TickGuildAsync" />
/// <seealso cref="MemberUpdateService.TickMemberDataAsync" />
[Command("unban")]
[DiscordDefaultMemberPermissions(DiscordPermission.BanMembers)]
[DiscordDefaultDMPermission(false)]