mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-05-13 17:26:08 +03:00
Merge branch 'master' into clear-filter-by-author
This commit is contained in:
commit
da30de4cf4
4 changed files with 15 additions and 11 deletions
|
@ -5,10 +5,14 @@ namespace Octobot.Data;
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class MemberData
|
public sealed class MemberData
|
||||||
{
|
{
|
||||||
public MemberData(ulong id, DateTimeOffset? bannedUntil = null)
|
public MemberData(ulong id, DateTimeOffset? bannedUntil = null, List<Reminder>? reminders = null)
|
||||||
{
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
BannedUntil = bannedUntil;
|
BannedUntil = bannedUntil;
|
||||||
|
if (reminders is not null)
|
||||||
|
{
|
||||||
|
Reminders = reminders;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ulong Id { get; }
|
public ulong Id { get; }
|
||||||
|
|
|
@ -2,7 +2,7 @@ namespace Octobot.Data;
|
||||||
|
|
||||||
public struct Reminder
|
public struct Reminder
|
||||||
{
|
{
|
||||||
public DateTimeOffset At;
|
public DateTimeOffset At { get; init; }
|
||||||
public string Text;
|
public string Text { get; init; }
|
||||||
public ulong Channel;
|
public ulong Channel { get; init; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -286,7 +286,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService
|
||||||
};
|
};
|
||||||
|
|
||||||
var contentResult = await _utility.GetEventNotificationMentions(
|
var contentResult = await _utility.GetEventNotificationMentions(
|
||||||
scheduledEvent, data.Settings, ct);
|
scheduledEvent, data, ct);
|
||||||
if (!contentResult.IsDefined(out var content))
|
if (!contentResult.IsDefined(out var content))
|
||||||
{
|
{
|
||||||
return Result.FromError(contentResult);
|
return Result.FromError(contentResult);
|
||||||
|
@ -412,7 +412,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService
|
||||||
IGuildScheduledEvent scheduledEvent, GuildData data, CancellationToken ct)
|
IGuildScheduledEvent scheduledEvent, GuildData data, CancellationToken ct)
|
||||||
{
|
{
|
||||||
var contentResult = await _utility.GetEventNotificationMentions(
|
var contentResult = await _utility.GetEventNotificationMentions(
|
||||||
scheduledEvent, data.Settings, ct);
|
scheduledEvent, data, ct);
|
||||||
if (!contentResult.IsDefined(out var content))
|
if (!contentResult.IsDefined(out var content))
|
||||||
{
|
{
|
||||||
return Result.FromError(contentResult);
|
return Result.FromError(contentResult);
|
||||||
|
|
|
@ -160,16 +160,16 @@ public sealed class UtilityService : IHostedService
|
||||||
/// <param name="scheduledEvent">
|
/// <param name="scheduledEvent">
|
||||||
/// The scheduled event whose subscribers will be mentioned.
|
/// The scheduled event whose subscribers will be mentioned.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="settings">The settings of the guild containing the scheduled event</param>
|
/// <param name="data">The data of the guild containing the scheduled event.</param>
|
||||||
/// <param name="ct">The cancellation token for this operation.</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>
|
/// <returns>A result containing the string which may or may not have succeeded.</returns>
|
||||||
public async Task<Result<string>> GetEventNotificationMentions(
|
public async Task<Result<string>> GetEventNotificationMentions(
|
||||||
IGuildScheduledEvent scheduledEvent, JsonNode settings, CancellationToken ct = default)
|
IGuildScheduledEvent scheduledEvent, GuildData data, CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
var builder = new StringBuilder();
|
var builder = new StringBuilder();
|
||||||
var role = GuildSettings.EventNotificationRole.Get(settings);
|
var role = GuildSettings.EventNotificationRole.Get(data.Settings);
|
||||||
var subscribersResult = await _eventApi.GetGuildScheduledEventUsersAsync(
|
var subscribersResult = await _eventApi.GetGuildScheduledEventUsersAsync(
|
||||||
scheduledEvent.GuildID, scheduledEvent.ID, withMember: true, ct: ct);
|
scheduledEvent.GuildID, scheduledEvent.ID, ct: ct);
|
||||||
if (!subscribersResult.IsDefined(out var subscribers))
|
if (!subscribersResult.IsDefined(out var subscribers))
|
||||||
{
|
{
|
||||||
return Result<string>.FromError(subscribersResult);
|
return Result<string>.FromError(subscribersResult);
|
||||||
|
@ -181,7 +181,7 @@ public sealed class UtilityService : IHostedService
|
||||||
}
|
}
|
||||||
|
|
||||||
builder = subscribers.Where(
|
builder = subscribers.Where(
|
||||||
subscriber => subscriber.GuildMember.IsDefined(out var member) && !member.Roles.Contains(role))
|
subscriber => !data.GetOrCreateMemberData(subscriber.User.ID).Roles.Contains(role.Value))
|
||||||
.Aggregate(builder, (current, subscriber) => current.Append($"{Mention.User(subscriber.User)} "));
|
.Aggregate(builder, (current, subscriber) => current.Append($"{Mention.User(subscriber.User)} "));
|
||||||
return builder.ToString();
|
return builder.ToString();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue