From 4f0bc4f6ad7bf7573b57c302c3f4577ee8c5efaa Mon Sep 17 00:00:00 2001 From: Mira <56395159+TheXorog@users.noreply.github.com> Date: Wed, 7 May 2025 20:15:26 +0200 Subject: [PATCH] fix: fix minor issues --- .../Commands/Configuration/JoinCommand.cs | 8 +++++++- ProjectMakoto/Events/JoinEvents.cs | 18 +++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/ProjectMakoto/Commands/Configuration/JoinCommand.cs b/ProjectMakoto/Commands/Configuration/JoinCommand.cs index d04b1ff5..61c9f6a2 100644 --- a/ProjectMakoto/Commands/Configuration/JoinCommand.cs +++ b/ProjectMakoto/Commands/Configuration/JoinCommand.cs @@ -61,7 +61,7 @@ internal sealed class JoinCommand : BaseCommand var ToggleGlobalban = new DiscordButtonComponent((ctx.DbGuild.Join.AutoBanGlobalBans ? ButtonStyle.Danger : ButtonStyle.Success), Guid.NewGuid().ToString(), this.GetString(CommandKey.ToggleGlobalBansButton), false, new DiscordComponentEmoji(DiscordEmoji.FromUnicode("🌐"))); var ChangeJoinlogChannel = new DiscordButtonComponent(ButtonStyle.Primary, Guid.NewGuid().ToString(), this.GetString(CommandKey.ChangeJoinlogChannelButton), false, new DiscordComponentEmoji(DiscordEmoji.FromUnicode("👋"))); var ChangeUserCountChannel = new DiscordButtonComponent(ButtonStyle.Primary, Guid.NewGuid().ToString(), this.GetString(CommandKey.ChangeUserCountChannel), false, new DiscordComponentEmoji(DiscordEmoji.FromUnicode("🔢"))); - var ChangeUserCountFormat = new DiscordButtonComponent(ButtonStyle.Primary, Guid.NewGuid().ToString(), this.GetString(CommandKey.ChangeUserCountChannelFormat), false, new DiscordComponentEmoji(DiscordEmoji.FromUnicode("🔢"))); + var ChangeUserCountFormat = new DiscordButtonComponent(ButtonStyle.Primary, Guid.NewGuid().ToString(), this.GetString(CommandKey.ChangeUserCountChannelFormat), ctx.DbGuild.Join.UserCountChannelId == 0, new DiscordComponentEmoji(DiscordEmoji.FromUnicode("🔢"))); var ChangeRoleOnJoin = new DiscordButtonComponent(ButtonStyle.Primary, Guid.NewGuid().ToString(), this.GetString(CommandKey.ChangeRoleButton), false, new DiscordComponentEmoji(DiscordEmoji.FromUnicode("👤"))); var ToggleReApplyRoles = new DiscordButtonComponent((ctx.DbGuild.Join.ReApplyRoles ? ButtonStyle.Danger : ButtonStyle.Success), Guid.NewGuid().ToString(), this.GetString(CommandKey.ToggleReApplyRole), false, new DiscordComponentEmoji(DiscordEmoji.FromUnicode("👥"))); var ToggleReApplyName = new DiscordButtonComponent((ctx.DbGuild.Join.ReApplyNickname ? ButtonStyle.Danger : ButtonStyle.Success), Guid.NewGuid().ToString(), this.GetString(CommandKey.ToggleReApplyNickname), false, new DiscordComponentEmoji(DiscordEmoji.FromUnicode("💬"))); @@ -201,6 +201,9 @@ internal sealed class JoinCommand : BaseCommand ctx.DbGuild.Join.UserCountChannelId = ChannelResult.Result is null ? 0 : ChannelResult.Result.Id; + if (ChannelResult.Result is not null) + await JoinEvents.RunUserCountUpdater(ctx.Bot, ctx.Guild); + await this.ExecuteCommand(ctx, arguments); return; } @@ -236,6 +239,9 @@ internal sealed class JoinCommand : BaseCommand ctx.DbGuild.Join.UserCountChannelFormat = modelResult.Result.Interaction.GetModalValueByCustomId("new_format"); + if (ctx.DbGuild.Join.UserCountChannelId != 0) + await JoinEvents.RunUserCountUpdater(ctx.Bot, ctx.Guild); + await this.ExecuteCommand(ctx, arguments); return; } diff --git a/ProjectMakoto/Events/JoinEvents.cs b/ProjectMakoto/Events/JoinEvents.cs index 4034eeca..584bb9b8 100644 --- a/ProjectMakoto/Events/JoinEvents.cs +++ b/ProjectMakoto/Events/JoinEvents.cs @@ -54,7 +54,7 @@ internal sealed class JoinEvents(Bot bot) : RequiresTranslation(bot) } } - await this.RunUserCountUpdater(e.Guild); + await RunUserCountUpdater(this.Bot, e.Guild); await this.Bot.Guilds[e.Guild.Id].Members[e.Member.Id].PerformAutoKickChecks(e.Guild, e.Member); } @@ -83,14 +83,14 @@ internal sealed class JoinEvents(Bot bot) : RequiresTranslation(bot) } } - await this.RunUserCountUpdater(e.Guild); + await RunUserCountUpdater(this.Bot, e.Guild); } - private async Task RunUserCountUpdater(DiscordGuild Guild) + internal static async Task RunUserCountUpdater(Bot bot, DiscordGuild Guild) { - if (this.Bot.Guilds[Guild.Id].Join.UserCountChannelId != 0) + if (bot.Guilds[Guild.Id].Join.UserCountChannelId != 0) { - if (Guild.Channels.ContainsKey(this.Bot.Guilds[Guild.Id].Join.UserCountChannelId)) + if (Guild.Channels.ContainsKey(bot.Guilds[Guild.Id].Join.UserCountChannelId)) { foreach (var b in ScheduledTaskExtensions.GetScheduledTasks()) { @@ -103,16 +103,16 @@ internal sealed class JoinEvents(Bot bot) : RequiresTranslation(bot) _ = new Func(async () => { - _ = Guild.GetChannel(this.Bot.Guilds[Guild.Id].Join.UserCountChannelId).ModifyAsync(x => + _ = Guild.GetChannel(bot.Guilds[Guild.Id].Join.UserCountChannelId).ModifyAsync(x => { - x.Name = (this.Bot.Guilds[Guild.Id].Join.UserCountChannelFormat is null ? "Count: %s" : this.Bot.Guilds[Guild.Id].Join.UserCountChannelFormat) + x.Name = (bot.Guilds[Guild.Id].Join.UserCountChannelFormat is null ? "Count: %s" : bot.Guilds[Guild.Id].Join.UserCountChannelFormat) .Replace("%s", Guild.MemberCount); }) .ContinueWith(x => { - this.Bot.Guilds[Guild.Id].Join.UserCountChannelLastEdit = DateTime.UtcNow; + bot.Guilds[Guild.Id].Join.UserCountChannelLastEdit = DateTime.UtcNow; }); - }).CreateScheduledTask(this.Bot.Guilds[Guild.Id].Join.UserCountChannelLastEdit.AddMinutes(5), + }).CreateScheduledTask(bot.Guilds[Guild.Id].Join.UserCountChannelLastEdit.AddMinutes(5), new ScheduledTaskIdentifier(Guild.Id, "", "usercount")); } }