Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always default cancellation tokens #319

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TeamOctolings.Octobot/Commands/InfoCommandGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public async Task<Result> ExecuteGuildInfoAsync()
return await ShowGuildInfoAsync(bot, guild, CancellationToken);
}

private Task<Result> ShowGuildInfoAsync(IUser bot, IGuild guild, CancellationToken ct)
private Task<Result> ShowGuildInfoAsync(IUser bot, IGuild guild, CancellationToken ct = default)
{
var description = new StringBuilder().AppendLine($"## {guild.Name}");

Expand Down
6 changes: 3 additions & 3 deletions TeamOctolings.Octobot/Commands/MuteCommandGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ var interactionResult

private async Task<Result> SelectMuteMethodAsync(
IUser executor, IUser target, string reason, TimeSpan duration, Snowflake guildId, GuildData data,
IUser bot, DateTimeOffset until, CancellationToken ct)
IUser bot, DateTimeOffset until, CancellationToken ct = default)
{
var muteRole = GuildSettings.MuteRole.Get(data.Settings);

Expand All @@ -186,7 +186,7 @@ private async Task<Result> SelectMuteMethodAsync(

private async Task<Result> RoleMuteUserAsync(
IUser executor, IUser target, string reason, Snowflake guildId, GuildData data,
DateTimeOffset until, Snowflake muteRole, CancellationToken ct)
DateTimeOffset until, Snowflake muteRole, CancellationToken ct = default)
{
var assignRoles = new List<Snowflake> { muteRole };
var memberData = data.GetOrCreateMemberData(target.ID);
Expand All @@ -208,7 +208,7 @@ private async Task<Result> RoleMuteUserAsync(

private async Task<Result> TimeoutUserAsync(
IUser executor, IUser target, string reason, TimeSpan duration, Snowflake guildId,
IUser bot, DateTimeOffset until, CancellationToken ct)
IUser bot, DateTimeOffset until, CancellationToken ct = default)
{
if (duration.TotalDays >= 28)
{
Expand Down
4 changes: 2 additions & 2 deletions TeamOctolings.Octobot/Commands/RemindCommandGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public async Task<Result> ExecuteListReminderAsync()
return await ListRemindersAsync(data.GetOrCreateMemberData(executorId), guildId, executor, bot, CancellationToken);
}

private Task<Result> ListRemindersAsync(MemberData data, Snowflake guildId, IUser executor, IUser bot, CancellationToken ct)
private Task<Result> ListRemindersAsync(MemberData data, Snowflake guildId, IUser executor, IUser bot, CancellationToken ct = default)
{
if (data.Reminders.Count == 0)
{
Expand Down Expand Up @@ -353,7 +353,7 @@ public async Task<Result> ExecuteDeleteReminderAsync(
}

private Task<Result> DeleteReminderAsync(MemberData data, int index, IUser bot,
CancellationToken ct)
CancellationToken ct = default)
{
if (index >= data.Reminders.Count)
{
Expand Down
6 changes: 3 additions & 3 deletions TeamOctolings.Octobot/Commands/ToolsCommandGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public async Task<Result> ExecuteRandomAsync(
}

private Task<Result> SendRandomNumberAsync(long first, long? secondNullable,
IUser executor, CancellationToken ct)
IUser executor, CancellationToken ct = default)
{
const long secondDefault = 0;
var second = secondNullable ?? secondDefault;
Expand Down Expand Up @@ -187,7 +187,7 @@ public async Task<Result> ExecuteTimestampAsync(
return await SendTimestampAsync(offset, executor, CancellationToken);
}

private Task<Result> SendTimestampAsync(TimeSpan? offset, IUser executor, CancellationToken ct)
private Task<Result> SendTimestampAsync(TimeSpan? offset, IUser executor, CancellationToken ct = default)
{
var timestamp = DateTimeOffset.UtcNow.Add(offset ?? TimeSpan.Zero).ToUnixTimeSeconds();

Expand Down Expand Up @@ -249,7 +249,7 @@ public async Task<Result> ExecuteEightBallAsync(
return await AnswerEightBallAsync(bot, CancellationToken);
}

private Task<Result> AnswerEightBallAsync(IUser bot, CancellationToken ct)
private Task<Result> AnswerEightBallAsync(IUser bot, CancellationToken ct = default)
{
var typeNumber = Random.Shared.Next(0, 4);
var embedColor = typeNumber switch
Expand Down
2 changes: 1 addition & 1 deletion TeamOctolings.Octobot/Responders/GuildLoadedResponder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public async Task<Result> RespondAsync(IGuildCreate gatewayEvent, CancellationTo
GuildSettings.PrivateFeedbackChannel.Get(cfg), embedResult: embed, ct: ct);
}

private async Task<Result> SendDataLoadFailed(IGuild guild, GuildData data, IUser bot, CancellationToken ct)
private async Task<Result> SendDataLoadFailed(IGuild guild, GuildData data, IUser bot, CancellationToken ct = default)
{
var channelResult = await _utility.GetEmergencyFeedbackChannel(guild, data, ct);
if (!channelResult.IsDefined(out var channel))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public async Task<Result> RespondAsync(IGuildMemberAdd gatewayEvent, Cancellatio
}

private async Task<Result> TryReturnRolesAsync(
JsonNode cfg, MemberData memberData, Snowflake guildId, Snowflake userId, CancellationToken ct)
JsonNode cfg, MemberData memberData, Snowflake guildId, Snowflake userId, CancellationToken ct = default)
{
if (!GuildSettings.ReturnRolesOnRejoin.Get(cfg))
{
Expand Down
2 changes: 1 addition & 1 deletion TeamOctolings.Octobot/Services/GuildDataService.cs
Octol1ttle marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private Task SaveAsync(CancellationToken ct)
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))
Expand Down
12 changes: 6 additions & 6 deletions TeamOctolings.Octobot/Services/Update/MemberUpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected override async Task ExecuteAsync(CancellationToken ct)
}
}

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);
Expand All @@ -79,7 +79,7 @@ private async Task<Result> TickMemberDatasAsync(Snowflake guildId, CancellationT

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();
Expand Down Expand Up @@ -144,7 +144,7 @@ var interactionResult
}

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)
{
Expand All @@ -169,7 +169,7 @@ private async Task<Result> TryAutoUnbanAsync(
}

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)
{
Expand All @@ -188,7 +188,7 @@ private async Task<Result> TryAutoUnmuteAsync(
}

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
Expand Down Expand Up @@ -226,7 +226,7 @@ private async Task<Result> FilterNicknameAsync(Snowflake guildId, IUser user, IG
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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected override async Task ExecuteAsync(CancellationToken ct)
}
}

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);
Expand Down Expand Up @@ -133,7 +133,7 @@ private static Result<IGuildScheduledEvent> TryGetScheduledEvent(IEnumerable<IGu

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
Expand All @@ -160,7 +160,7 @@ private async Task<Result> TickScheduledEventAsync(
}

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,
Expand Down Expand Up @@ -319,7 +319,7 @@ private async Task<Result> SendScheduledEventStartedMessage(
}

private async Task<Result> SendScheduledEventCompletedMessage(ScheduledEventData eventData, GuildData data,
CancellationToken ct)
CancellationToken ct = default)
{
if (GuildSettings.EventNotificationChannel.Get(data.Settings).Empty())
{
Expand Down Expand Up @@ -351,7 +351,7 @@ private async Task<Result> SendScheduledEventCompletedMessage(ScheduledEventData
}

private async Task<Result> SendScheduledEventCancelledMessage(ScheduledEventData eventData, GuildData data,
CancellationToken ct)
CancellationToken ct = default)
{
if (GuildSettings.EventNotificationChannel.Get(data.Settings).Empty())
{
Expand Down Expand Up @@ -405,7 +405,7 @@ private static Result<string> GetExternalEventStartedEmbedDescription(IGuildSche
}

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())
{
Expand Down
2 changes: 1 addition & 1 deletion TeamOctolings.Octobot/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void LogAction(
}
}

public async Task<Result<Snowflake>> GetEmergencyFeedbackChannel(IGuild guild, GuildData data, CancellationToken ct)
public async Task<Result<Snowflake>> GetEmergencyFeedbackChannel(IGuild guild, GuildData data, CancellationToken ct = default)
{
var privateFeedback = GuildSettings.PrivateFeedbackChannel.Get(data.Settings);
if (!privateFeedback.Empty())
Expand Down