mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-05-02 20:19:55 +03:00
Always default cancellation tokens (#319)
This PR makes sure that a cancellation token is never *required* to use an `async` method. This does not affect user experience in any way, only code quality. --------- Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
a953053f1d
commit
a0e7b3a611
10 changed files with 26 additions and 26 deletions
|
@ -27,7 +27,7 @@ public sealed class GuildDataService : BackgroundService
|
|||
return SaveAsync(ct);
|
||||
}
|
||||
|
||||
private Task SaveAsync(CancellationToken ct)
|
||||
private Task SaveAsync(CancellationToken ct = default)
|
||||
{
|
||||
var tasks = new List<Task>();
|
||||
var datas = _datas.Values.ToArray();
|
||||
|
@ -44,7 +44,7 @@ public sealed class GuildDataService : BackgroundService
|
|||
return Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
private static async Task SerializeObjectSafelyAsync<T>(T obj, string path, CancellationToken ct)
|
||||
private static async Task SerializeObjectSafelyAsync<T>(T obj, string path, CancellationToken ct = default)
|
||||
{
|
||||
var tempFilePath = path + ".tmp";
|
||||
await using (var tempFileStream = File.Create(tempFilePath))
|
||||
|
|
|
@ -62,7 +62,7 @@ public sealed partial class MemberUpdateService : BackgroundService
|
|||
}
|
||||
}
|
||||
|
||||
private async Task<Result> TickMemberDatasAsync(Snowflake guildId, CancellationToken ct)
|
||||
private async Task<Result> TickMemberDatasAsync(Snowflake guildId, CancellationToken ct = default)
|
||||
{
|
||||
var guildData = await _guildData.GetData(guildId, ct);
|
||||
var defaultRole = GuildSettings.DefaultRole.Get(guildData.Settings);
|
||||
|
@ -79,7 +79,7 @@ public sealed partial class MemberUpdateService : BackgroundService
|
|||
|
||||
private async Task<Result> TickMemberDataAsync(Snowflake guildId, GuildData guildData, Snowflake defaultRole,
|
||||
MemberData data,
|
||||
CancellationToken ct)
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
var failedResults = new List<Result>();
|
||||
var id = data.Id.ToSnowflake();
|
||||
|
@ -144,7 +144,7 @@ public sealed partial class MemberUpdateService : BackgroundService
|
|||
}
|
||||
|
||||
private async Task<Result> TryAutoUnbanAsync(
|
||||
Snowflake guildId, Snowflake id, MemberData data, CancellationToken ct)
|
||||
Snowflake guildId, Snowflake id, MemberData data, CancellationToken ct = default)
|
||||
{
|
||||
if (data.BannedUntil is null || DateTimeOffset.UtcNow <= data.BannedUntil)
|
||||
{
|
||||
|
@ -169,7 +169,7 @@ public sealed partial class MemberUpdateService : BackgroundService
|
|||
}
|
||||
|
||||
private async Task<Result> TryAutoUnmuteAsync(
|
||||
Snowflake guildId, Snowflake id, MemberData data, CancellationToken ct)
|
||||
Snowflake guildId, Snowflake id, MemberData data, CancellationToken ct = default)
|
||||
{
|
||||
if (data.MutedUntil is null || DateTimeOffset.UtcNow <= data.MutedUntil)
|
||||
{
|
||||
|
@ -188,7 +188,7 @@ public sealed partial class MemberUpdateService : BackgroundService
|
|||
}
|
||||
|
||||
private async Task<Result> FilterNicknameAsync(Snowflake guildId, IUser user, IGuildMember member,
|
||||
CancellationToken ct)
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
var currentNickname = member.Nickname.IsDefined(out var nickname)
|
||||
? nickname
|
||||
|
@ -226,7 +226,7 @@ public sealed partial class MemberUpdateService : BackgroundService
|
|||
private static partial Regex IllegalChars();
|
||||
|
||||
private async Task<Result> TickReminderAsync(Reminder reminder, IUser user, MemberData data, Snowflake guildId,
|
||||
CancellationToken ct)
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
if (DateTimeOffset.UtcNow < reminder.At)
|
||||
{
|
||||
|
|
|
@ -46,7 +46,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService
|
|||
}
|
||||
}
|
||||
|
||||
private async Task<Result> TickScheduledEventsAsync(Snowflake guildId, CancellationToken ct)
|
||||
private async Task<Result> TickScheduledEventsAsync(Snowflake guildId, CancellationToken ct = default)
|
||||
{
|
||||
var failedResults = new List<Result>();
|
||||
var data = await _guildData.GetData(guildId, ct);
|
||||
|
@ -133,7 +133,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService
|
|||
|
||||
private async Task<Result> TickScheduledEventAsync(
|
||||
Snowflake guildId, GuildData data, IGuildScheduledEvent scheduledEvent, ScheduledEventData eventData,
|
||||
CancellationToken ct)
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
if (GuildSettings.AutoStartEvents.Get(data.Settings)
|
||||
&& DateTimeOffset.UtcNow >= scheduledEvent.ScheduledStartTime
|
||||
|
@ -160,7 +160,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService
|
|||
}
|
||||
|
||||
private async Task<Result> AutoStartEventAsync(
|
||||
Snowflake guildId, IGuildScheduledEvent scheduledEvent, CancellationToken ct)
|
||||
Snowflake guildId, IGuildScheduledEvent scheduledEvent, CancellationToken ct = default)
|
||||
{
|
||||
return (Result)await _eventApi.ModifyGuildScheduledEventAsync(
|
||||
guildId, scheduledEvent.ID,
|
||||
|
@ -319,7 +319,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService
|
|||
}
|
||||
|
||||
private async Task<Result> SendScheduledEventCompletedMessage(ScheduledEventData eventData, GuildData data,
|
||||
CancellationToken ct)
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
if (GuildSettings.EventNotificationChannel.Get(data.Settings).Empty())
|
||||
{
|
||||
|
@ -351,7 +351,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService
|
|||
}
|
||||
|
||||
private async Task<Result> SendScheduledEventCancelledMessage(ScheduledEventData eventData, GuildData data,
|
||||
CancellationToken ct)
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
if (GuildSettings.EventNotificationChannel.Get(data.Settings).Empty())
|
||||
{
|
||||
|
@ -405,7 +405,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService
|
|||
}
|
||||
|
||||
private async Task<Result> SendEarlyEventNotificationAsync(
|
||||
IGuildScheduledEvent scheduledEvent, GuildData data, CancellationToken ct)
|
||||
IGuildScheduledEvent scheduledEvent, GuildData data, CancellationToken ct = default)
|
||||
{
|
||||
if (GuildSettings.EventNotificationChannel.Get(data.Settings).Empty())
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue