The Milestone Commit (#48)

mctaylors:
- updated readme 7 times (and only adding new logo from /about)
-
[removed](https://github.com/TeamOctolings/Boyfriend/pull/48/commits/aeeb3d4399c31df70b47ccdf59f6963fdb68e9ec)
bot footer from created event embed on the second try
-
[changed](https://github.com/TeamOctolings/Boyfriend/pull/48/commits/4b9b91d9e4d2289d9aad4e600f5ca6a424638a6e)
cdn from discord to upload.systems

Octol1ttle:
- Guild settings code has been overhauled. Instead of instances of a
`GuildConfiguration` class being (de-)serialized when used with listing
and setting options provided by reflection, there are now multiple
`Option` classes responsible for the type of option they are storing.
The classes support getting a value, validating and setting values with
Results, and getting a user-friendly representation of these values.
This makes use of polymorphism, providing clean and easier to use and
refactor code.
- Gateway event responders have been split into their own separate
files, which should make it easier to find and modify responders when
needed.
- Warning suppressions regarding unused and never instantiated classes
have been replaced by `[ImplicitUse]` annotations provided by
`JetBrains.Annotations`. This avoids hiding real issues and provides a
better way to suppress false warnings while being explicit.
- It is no longer possible to execute some slash commands if they are
run without the correct permissions
- Dependencies are now more explicitly defined

neroduckale:
 - Made easter eggs case-insensitive

---------

Signed-off-by: Macintosh II <95250141+mctaylors@users.noreply.github.com>
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
Co-authored-by: Octol1ttle <l1ttleofficial@outlook.com>
Co-authored-by: nrdk <neroduck@vk.com>
This commit is contained in:
Octoling 2023-07-18 15:25:02 +03:00 committed by GitHub
parent 3eb17b96c5
commit c6dd3727c3
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 912 additions and 658 deletions

View file

@ -1,4 +1,5 @@
using System.Text;
using System.Text.Json.Nodes;
using Boyfriend.Data;
using Microsoft.Extensions.Hosting;
using Remora.Discord.API.Abstractions.Objects;
@ -103,38 +104,32 @@ public class UtilityService : IHostedService {
}
/// <summary>
/// Gets the string mentioning all <see cref="GuildConfiguration.NotificationReceiver" />s related to a scheduled
/// Gets the string mentioning the <see cref="GuildSettings.EventNotificationRole"/> and event subscribers related to a scheduled
/// event.
/// </summary>
/// <remarks>
/// If the guild configuration enables <see cref="GuildConfiguration.NotificationReceiver.Role" />, then the
/// <see cref="GuildConfiguration.EventNotificationRole" /> will also be mentioned.
/// </remarks>
/// <param name="scheduledEvent">
/// The scheduled event whose subscribers will be mentioned if the guild configuration enables
/// <see cref="GuildConfiguration.NotificationReceiver.Interested" />.
/// The scheduled event whose subscribers will be mentioned.
/// </param>
/// <param name="config">The configuration of the guild containing the scheduled event</param>
/// <param name="settings">The settings of the guild containing the scheduled event</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A result containing the string which may or may not have succeeded.</returns>
public async Task<Result<string>> GetEventNotificationMentions(
IGuildScheduledEvent scheduledEvent, GuildConfiguration config, CancellationToken ct = default) {
IGuildScheduledEvent scheduledEvent, JsonNode settings, CancellationToken ct = default) {
var builder = new StringBuilder();
var receivers = config.EventStartedReceivers;
var role = config.EventNotificationRole.ToDiscordSnowflake();
var role = GuildSettings.EventNotificationRole.Get(settings);
var usersResult = await _eventApi.GetGuildScheduledEventUsersAsync(
scheduledEvent.GuildID, scheduledEvent.ID, withMember: true, ct: ct);
if (!usersResult.IsDefined(out var users)) return Result<string>.FromError(usersResult);
if (receivers.Contains(GuildConfiguration.NotificationReceiver.Role) && role.Value is not 0)
if (role.Value is not 0)
builder.Append($"{Mention.Role(role)} ");
if (receivers.Contains(GuildConfiguration.NotificationReceiver.Interested))
builder = users.Where(
user => {
if (!user.GuildMember.IsDefined(out var member)) return true;
return !member.Roles.Contains(role);
})
.Aggregate(builder, (current, user) => current.Append($"{Mention.User(user.User)} "));
builder = users.Where(
user => {
if (!user.GuildMember.IsDefined(out var member)) return true;
return !member.Roles.Contains(role);
})
.Aggregate(builder, (current, user) => current.Append($"{Mention.User(user.User)} "));
return builder.ToString();
}
}