chore: format with csharpier

This commit is contained in:
sam 2024-10-09 17:35:11 +02:00
parent 2f516dcb73
commit 4f54077c68
59 changed files with 2000 additions and 942 deletions

View file

@ -20,8 +20,8 @@ public class GuildCreateResponder(
ChannelCache channelCache,
WebhookExecutorService webhookExecutor,
IMemberCache memberCache,
GuildFetchService guildFetchService)
: IResponder<IGuildCreate>, IResponder<IGuildDelete>
GuildFetchService guildFetchService
) : IResponder<IGuildCreate>, IResponder<IGuildDelete>
{
private readonly ILogger _logger = logger.ForContext<GuildCreateResponder>();
@ -31,46 +31,56 @@ public class GuildCreateResponder(
string? guildName = null;
if (evt.Guild.TryPickT0(out var guild, out var unavailableGuild))
{
_logger.Verbose("Received guild create for available guild {GuildName} / {GuildId})", guild.Name, guild.ID);
_logger.Verbose(
"Received guild create for available guild {GuildName} / {GuildId})",
guild.Name,
guild.ID
);
guildId = guild.ID.ToUlong();
guildName = guild.Name;
guildCache.Set(guild);
foreach (var c in guild.Channels) channelCache.Set(c, guild.ID);
foreach (var r in guild.Roles) roleCache.Set(r, guild.ID);
foreach (var c in guild.Channels)
channelCache.Set(c, guild.ID);
foreach (var r in guild.Roles)
roleCache.Set(r, guild.ID);
if (!await memberCache.IsGuildCachedAsync(guild.ID))
guildFetchService.EnqueueGuild(guild.ID);
}
else
{
_logger.Verbose("Received guild create for unavailable guild {GuildId}", unavailableGuild.ID);
_logger.Verbose(
"Received guild create for unavailable guild {GuildId}",
unavailableGuild.ID
);
guildId = unavailableGuild.ID.ToUlong();
}
var tx = await db.Database.BeginTransactionAsync(ct);
if (await db.Guilds.FindAsync([guildId], ct) != null) return Result.Success;
if (await db.Guilds.FindAsync([guildId], ct) != null)
return Result.Success;
db.Add(new Guild
{
Id = guildId
});
db.Add(new Guild { Id = guildId });
await db.SaveChangesAsync(ct);
await tx.CommitAsync(ct);
_logger.Information("Joined new guild {GuildName} / {GuildId}", guildName, guildId);
if (config.Discord.GuildLogId != null && evt.Guild.IsT0)
webhookExecutor.QueueLog(config.Discord.GuildLogId.Value, new EmbedBuilder()
.WithTitle("Joined new guild")
.WithDescription($"Joined new guild **{guild.Name}**")
.WithFooter($"ID: {guild.ID}")
.WithCurrentTimestamp()
webhookExecutor.QueueLog(
config.Discord.GuildLogId.Value,
new EmbedBuilder()
.WithTitle("Joined new guild")
.WithDescription($"Joined new guild **{guild.Name}**")
.WithFooter($"ID: {guild.ID}")
.WithCurrentTimestamp()
#pragma warning disable CS8604 // Possible null reference argument.
.WithThumbnailUrl(guild.IconUrl())
.WithThumbnailUrl(guild.IconUrl())
#pragma warning restore CS8604 // Possible null reference argument.
.Build()
.GetOrThrow());
.Build()
.GetOrThrow()
);
return Result.Success;
}
@ -92,17 +102,20 @@ public class GuildCreateResponder(
_logger.Information("Left guild {GuildName} / {GuildId}", guild.Name, guild.ID);
if (config.Discord.GuildLogId != null)
webhookExecutor.QueueLog(config.Discord.GuildLogId.Value, new EmbedBuilder()
.WithTitle("Left guild")
.WithDescription($"Left guild **{guild.Name}**")
.WithFooter($"ID: {guild.ID}")
.WithCurrentTimestamp()
webhookExecutor.QueueLog(
config.Discord.GuildLogId.Value,
new EmbedBuilder()
.WithTitle("Left guild")
.WithDescription($"Left guild **{guild.Name}**")
.WithFooter($"ID: {guild.ID}")
.WithCurrentTimestamp()
#pragma warning disable CS8604 // Possible null reference argument.
.WithThumbnailUrl(guild.IconUrl())
.WithThumbnailUrl(guild.IconUrl())
#pragma warning restore CS8604 // Possible null reference argument.
.Build()
.GetOrThrow());
.Build()
.GetOrThrow()
);
return Task.FromResult(Result.Success);
}
}
}