From f2f07245c215f98614701ad1b4db68ace368e945 Mon Sep 17 00:00:00 2001 From: mctaylors Date: Mon, 18 Mar 2024 17:08:34 +0300 Subject: [PATCH 01/42] Remove unused locales that I found Signed-off-by: mctaylors --- locale/Messages.resx | 24 ------------------- locale/Messages.ru.resx | 24 ------------------- locale/Messages.tt-ru.resx | 24 ------------------- src/Messages.Designer.cs | 48 -------------------------------------- 4 files changed, 120 deletions(-) diff --git a/locale/Messages.resx b/locale/Messages.resx index ca48fba..a0b1210 100644 --- a/locale/Messages.resx +++ b/locale/Messages.resx @@ -138,24 +138,12 @@ ms - - Not specified - - - Not specified - Language - - Prefix - Remove roles on mute - - Send welcome messages - Mute role @@ -198,9 +186,6 @@ Channel for event notifications - - Event start notifications receivers - Event "{0}" started @@ -216,9 +201,6 @@ Nothing changed! `{0}` is already set to {1} - - Not specified - You need to specify a user! @@ -444,12 +426,6 @@ There are {0} total pages - - Next - - - Previous - {0}'s reminders diff --git a/locale/Messages.ru.resx b/locale/Messages.ru.resx index 7423347..813fa33 100644 --- a/locale/Messages.ru.resx +++ b/locale/Messages.ru.resx @@ -135,24 +135,12 @@ мс - - Не указан - - - Не указана - Язык - - Префикс - Удалять роли при муте - - Отправлять приветствия - Роль мута @@ -195,9 +183,6 @@ Канал для уведомлений о событиях - - Получатели уведомлений о начале событий - Событие "{0}" началось @@ -213,9 +198,6 @@ Ничего не изменилось! Значение настройки `{0}` уже {1} - - Не указано - Надо указать пользователя! @@ -444,12 +426,6 @@ Всего есть {0} страниц(-ы) - - Далее - - - Назад - Напоминания {0} diff --git a/locale/Messages.tt-ru.resx b/locale/Messages.tt-ru.resx index dc3bb6f..8dd112e 100644 --- a/locale/Messages.tt-ru.resx +++ b/locale/Messages.tt-ru.resx @@ -138,24 +138,12 @@ мс - - *тут ничего нет* - - - нъет - язык - - префикс - удалять звание при муте - - разглашать о том что пришел новый шизоид - звание замученного @@ -198,9 +186,6 @@ канал для уведомлений о движухах - - получатели уведомлений о начале движух - движуха "{0}" начинается @@ -216,9 +201,6 @@ ты все сломал! значение прикола `{0}` и так {1} - - нъет - укажи самого шизика @@ -444,12 +426,6 @@ ну а если быть точнее, тут всего {0} страниц(-ы) - - следующее - - - предыдущее - напоминалки {0} diff --git a/src/Messages.Designer.cs b/src/Messages.Designer.cs index ca460cf..c04bfce 100644 --- a/src/Messages.Designer.cs +++ b/src/Messages.Designer.cs @@ -108,42 +108,18 @@ namespace Octobot { } } - internal static string ChannelNotSpecified { - get { - return ResourceManager.GetString("ChannelNotSpecified", resourceCulture); - } - } - - internal static string RoleNotSpecified { - get { - return ResourceManager.GetString("RoleNotSpecified", resourceCulture); - } - } - internal static string SettingsLang { get { return ResourceManager.GetString("SettingsLang", resourceCulture); } } - internal static string SettingsPrefix { - get { - return ResourceManager.GetString("SettingsPrefix", resourceCulture); - } - } - internal static string SettingsRemoveRolesOnMute { get { return ResourceManager.GetString("SettingsRemoveRolesOnMute", resourceCulture); } } - internal static string SettingsSendWelcomeMessages { - get { - return ResourceManager.GetString("SettingsSendWelcomeMessages", resourceCulture); - } - } - internal static string SettingsMuteRole { get { return ResourceManager.GetString("SettingsMuteRole", resourceCulture); @@ -240,12 +216,6 @@ namespace Octobot { } } - internal static string SettingsEventStartedReceivers { - get { - return ResourceManager.GetString("SettingsEventStartedReceivers", resourceCulture); - } - } - internal static string EventStarted { get { return ResourceManager.GetString("EventStarted", resourceCulture); @@ -276,12 +246,6 @@ namespace Octobot { } } - internal static string SettingNotDefined { - get { - return ResourceManager.GetString("SettingNotDefined", resourceCulture); - } - } - internal static string UserCannotBanMembers { get { return ResourceManager.GetString("UserCannotBanMembers", resourceCulture); @@ -720,18 +684,6 @@ namespace Octobot { } } - internal static string Next { - get { - return ResourceManager.GetString("Next", resourceCulture); - } - } - - internal static string Previous { - get { - return ResourceManager.GetString("Previous", resourceCulture); - } - } - internal static string ReminderList { get { return ResourceManager.GetString("ReminderList", resourceCulture); From a44f9302d731d849ca17afbe97e3209fb33602d1 Mon Sep 17 00:00:00 2001 From: mctaylors Date: Sun, 24 Mar 2024 15:28:18 +0300 Subject: [PATCH 02/42] Remove UserCannot.*Members and some other Signed-off-by: mctaylors --- locale/Messages.resx | 15 --------------- locale/Messages.ru.resx | 15 --------------- locale/Messages.tt-ru.resx | 15 --------------- src/Messages.Designer.cs | 30 ------------------------------ 4 files changed, 75 deletions(-) diff --git a/locale/Messages.resx b/locale/Messages.resx index a0b1210..66355d0 100644 --- a/locale/Messages.resx +++ b/locale/Messages.resx @@ -204,21 +204,6 @@ You need to specify a user! - - You cannot ban users from this guild! - - - You cannot manage messages in this guild! - - - You cannot kick members from this guild! - - - You cannot moderate members in this guild! - - - You cannot manage this guild! - I cannot ban users from this guild! diff --git a/locale/Messages.ru.resx b/locale/Messages.ru.resx index 813fa33..6e0cddb 100644 --- a/locale/Messages.ru.resx +++ b/locale/Messages.ru.resx @@ -201,21 +201,6 @@ Надо указать пользователя! - - Ты не можешь банить пользователей на этом сервере! - - - Ты не можешь управлять сообщениями этого сервера! - - - Ты не можешь выгонять участников с этого сервера! - - - Ты не можешь модерировать участников этого сервера! - - - Ты не можешь настраивать этот сервер! - Я не могу банить пользователей на этом сервере! diff --git a/locale/Messages.tt-ru.resx b/locale/Messages.tt-ru.resx index 8dd112e..2082cce 100644 --- a/locale/Messages.tt-ru.resx +++ b/locale/Messages.tt-ru.resx @@ -204,21 +204,6 @@ укажи самого шизика - - бан - - - тебе нельзя иметь власть над сообщениями шизоидов - - - кик шизиков нельзя - - - тебе нельзя управлять шизоидами - - - тебе нельзя редактировать дурку - я не могу ваще никого банить чел. diff --git a/src/Messages.Designer.cs b/src/Messages.Designer.cs index c04bfce..3105bd1 100644 --- a/src/Messages.Designer.cs +++ b/src/Messages.Designer.cs @@ -246,36 +246,6 @@ namespace Octobot { } } - internal static string UserCannotBanMembers { - get { - return ResourceManager.GetString("UserCannotBanMembers", resourceCulture); - } - } - - internal static string UserCannotManageMessages { - get { - return ResourceManager.GetString("UserCannotManageMessages", resourceCulture); - } - } - - internal static string UserCannotKickMembers { - get { - return ResourceManager.GetString("UserCannotKickMembers", resourceCulture); - } - } - - internal static string UserCannotModerateMembers { - get { - return ResourceManager.GetString("UserCannotModerateMembers", resourceCulture); - } - } - - internal static string UserCannotManageGuild { - get { - return ResourceManager.GetString("UserCannotManageGuild", resourceCulture); - } - } - internal static string BotCannotBanMembers { get { return ResourceManager.GetString("BotCannotBanMembers", resourceCulture); From cccc4d6205259d2712567e2de91174112395cc2f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Mar 2024 10:47:05 +0300 Subject: [PATCH 03/42] Bump muno92/resharper_inspectcode from 1.11.7 to 1.11.8 (#292) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [muno92/resharper_inspectcode](https://github.com/muno92/resharper_inspectcode) from 1.11.7 to 1.11.8.
Release notes

Sourced from muno92/resharper_inspectcode's releases.

1.11.8

What's Changed

New Contributors

Full Changelog: https://github.com/muno92/resharper_inspectcode/compare/1.11.7...1.11.8

Changelog

Sourced from muno92/resharper_inspectcode's changelog.

1.11.8 - 2024-03-23

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=muno92/resharper_inspectcode&package-manager=github_actions&previous-version=1.11.7&new-version=1.11.8)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/build-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 8002f6f..859f8fa 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -23,7 +23,7 @@ jobs: uses: actions/checkout@v4 - name: ReSharper CLI InspectCode - uses: muno92/resharper_inspectcode@1.11.7 + uses: muno92/resharper_inspectcode@1.11.8 with: solutionPath: ./Octobot.sln ignoreIssueType: InvertIf, ConvertIfStatementToSwitchStatement, ConvertToPrimaryConstructor From 9429dfe8d8c64d1c49ee6879fcd82e2b57f740ae Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Tue, 26 Mar 2024 15:35:31 +0500 Subject: [PATCH 04/42] Fix "No operation context has been set for this scope." crash on startup (#293) Signed-off-by: Octol1ttle --- src/Services/AccessControlService.cs | 65 +++++++++++----------------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/src/Services/AccessControlService.cs b/src/Services/AccessControlService.cs index aeb16e4..cb235f9 100644 --- a/src/Services/AccessControlService.cs +++ b/src/Services/AccessControlService.cs @@ -2,8 +2,6 @@ using Octobot.Extensions; using Remora.Discord.API.Abstractions.Objects; using Remora.Discord.API.Abstractions.Rest; -using Remora.Discord.Commands.Conditions; -using Remora.Discord.Commands.Results; using Remora.Rest.Core; using Remora.Results; @@ -13,32 +11,30 @@ public sealed class AccessControlService { private readonly GuildDataService _data; private readonly IDiscordRestGuildAPI _guildApi; - private readonly RequireDiscordPermissionCondition _permission; private readonly IDiscordRestUserAPI _userApi; - public AccessControlService(GuildDataService data, IDiscordRestGuildAPI guildApi, IDiscordRestUserAPI userApi, - RequireDiscordPermissionCondition permission) + public AccessControlService(GuildDataService data, IDiscordRestGuildAPI guildApi, IDiscordRestUserAPI userApi) { _data = data; _guildApi = guildApi; _userApi = userApi; - _permission = permission; } - private async Task> CheckPermissionAsync(GuildData data, Snowflake memberId, IGuildMember member, - DiscordPermission permission, CancellationToken ct = default) + private static bool CheckPermission(IEnumerable roles, GuildData data, Snowflake memberId, + IGuildMember member, + DiscordPermission permission) { var moderatorRole = GuildSettings.ModeratorRole.Get(data.Settings); - var result = await _permission.CheckAsync(new RequireDiscordPermissionAttribute([permission]), member, ct); - - if (result.Error is not null and not PermissionDeniedError) + if (!moderatorRole.Empty() && data.GetOrCreateMemberData(memberId).Roles.Contains(moderatorRole.Value)) { - return Result.FromError(result); + return true; } - var hasPermission = result.IsSuccess; - return hasPermission || (!moderatorRole.Empty() && - data.GetOrCreateMemberData(memberId).Roles.Contains(moderatorRole.Value)); + return roles + .Where(r => member.Roles.Contains(r.ID)) + .Any(r => + r.Permissions.HasPermission(permission) + ); } /// @@ -67,30 +63,35 @@ public sealed class AccessControlService return Result.FromSuccess($"UserCannot{action}Themselves".Localized()); } - var botResult = await _userApi.GetCurrentUserAsync(ct); - if (!botResult.IsDefined(out var bot)) - { - return Result.FromError(botResult); - } - var guildResult = await _guildApi.GetGuildAsync(guildId, ct: ct); if (!guildResult.IsDefined(out var guild)) { return Result.FromError(guildResult); } - var targetMemberResult = await _guildApi.GetGuildMemberAsync(guildId, targetId, ct); - if (!targetMemberResult.IsDefined(out var targetMember)) + if (interacterId == guild.OwnerID) { return Result.FromSuccess(null); } + var botResult = await _userApi.GetCurrentUserAsync(ct); + if (!botResult.IsDefined(out var bot)) + { + return Result.FromError(botResult); + } + var botMemberResult = await _guildApi.GetGuildMemberAsync(guildId, bot.ID, ct); if (!botMemberResult.IsDefined(out var botMember)) { return Result.FromError(botMemberResult); } + var targetMemberResult = await _guildApi.GetGuildMemberAsync(guildId, targetId, ct); + if (!targetMemberResult.IsDefined(out var targetMember)) + { + return Result.FromSuccess(null); + } + var rolesResult = await _guildApi.GetGuildRolesAsync(guildId, ct); if (!rolesResult.IsDefined(out var roles)) { @@ -110,18 +111,14 @@ public sealed class AccessControlService var data = await _data.GetData(guildId, ct); - var permissionResult = await CheckPermissionAsync(data, interacterId.Value, interacter, + var hasPermission = CheckPermission(roles, data, interacterId.Value, interacter, action switch { "Ban" => DiscordPermission.BanMembers, "Kick" => DiscordPermission.KickMembers, "Mute" or "Unmute" => DiscordPermission.ModerateMembers, _ => throw new Exception() - }, ct); - if (!permissionResult.IsDefined(out var hasPermission)) - { - return Result.FromError(permissionResult); - } + }); return hasPermission ? CheckInteractions(action, guild, roles, targetMember, botMember, interacter) @@ -137,11 +134,6 @@ public sealed class AccessControlService return new ArgumentNullError(nameof(targetMember.User)); } - if (!interacter.User.IsDefined(out var interacterUser)) - { - return new ArgumentNullError(nameof(interacter.User)); - } - if (botMember.User == targetMember.User) { return Result.FromSuccess($"UserCannot{action}Bot".Localized()); @@ -161,11 +153,6 @@ public sealed class AccessControlService return Result.FromSuccess($"BotCannot{action}Target".Localized()); } - if (interacterUser.ID == guild.OwnerID) - { - return Result.FromSuccess(null); - } - var interacterRoles = roles.Where(r => interacter.Roles.Contains(r.ID)); var targetInteracterRoleDiff = targetRoles.MaxOrDefault(r => r.Position) - interacterRoles.MaxOrDefault(r => r.Position); From 70fccf83352dcfdb0c22f046e8d08aae58eabb08 Mon Sep 17 00:00:00 2001 From: Macintxsh <95250141+mctaylors@users.noreply.github.com> Date: Mon, 1 Apr 2024 15:57:49 +0300 Subject: [PATCH 05/42] Use unicode codes instead of emojis (#295) This change was made to avoid using emoji in the code, which may not render correctly depending on the IDE and/or operating system. --- src/Commands/AboutCommandGroup.cs | 6 +++--- src/Commands/Events/ErrorLoggingPostExecutionEvent.cs | 2 +- src/Responders/GuildLoadedResponder.cs | 2 +- src/Services/Update/ScheduledEventUpdateService.cs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Commands/AboutCommandGroup.cs b/src/Commands/AboutCommandGroup.cs index 027e7f8..f2fa11f 100644 --- a/src/Commands/AboutCommandGroup.cs +++ b/src/Commands/AboutCommandGroup.cs @@ -107,14 +107,14 @@ public class AboutCommandGroup : CommandGroup var repositoryButton = new ButtonComponent( ButtonComponentStyle.Link, Messages.ButtonOpenRepository, - new PartialEmoji(Name: "🌐"), + new PartialEmoji(Name: "\ud83c\udf10"), // 'GLOBE WITH MERIDIANS' (U+1F310) URL: BuildInfo.RepositoryUrl ); var wikiButton = new ButtonComponent( ButtonComponentStyle.Link, Messages.ButtonOpenWiki, - new PartialEmoji(Name: "📖"), + new PartialEmoji(Name: "\ud83d\udcd6"), // 'OPEN BOOK' (U+1F4D6) URL: BuildInfo.WikiUrl ); @@ -123,7 +123,7 @@ public class AboutCommandGroup : CommandGroup BuildInfo.IsDirty ? Messages.ButtonDirty : Messages.ButtonReportIssue, - new PartialEmoji(Name: "⚠️"), + new PartialEmoji(Name: "\u26a0\ufe0f"), // 'WARNING SIGN' (U+26A0) URL: BuildInfo.IssuesUrl, IsDisabled: BuildInfo.IsDirty ); diff --git a/src/Commands/Events/ErrorLoggingPostExecutionEvent.cs b/src/Commands/Events/ErrorLoggingPostExecutionEvent.cs index 5fa2ea8..551c2d0 100644 --- a/src/Commands/Events/ErrorLoggingPostExecutionEvent.cs +++ b/src/Commands/Events/ErrorLoggingPostExecutionEvent.cs @@ -73,7 +73,7 @@ public class ErrorLoggingPostExecutionEvent : IPostExecutionEvent BuildInfo.IsDirty ? Messages.ButtonDirty : Messages.ButtonReportIssue, - new PartialEmoji(Name: "⚠️"), + new PartialEmoji(Name: "\u26a0\ufe0f"), // 'WARNING SIGN' (U+26A0) URL: BuildInfo.IssuesUrl, IsDisabled: BuildInfo.IsDirty ); diff --git a/src/Responders/GuildLoadedResponder.cs b/src/Responders/GuildLoadedResponder.cs index b03fd3f..55e9673 100644 --- a/src/Responders/GuildLoadedResponder.cs +++ b/src/Responders/GuildLoadedResponder.cs @@ -114,7 +114,7 @@ public class GuildLoadedResponder : IResponder BuildInfo.IsDirty ? Messages.ButtonDirty : Messages.ButtonReportIssue, - new PartialEmoji(Name: "⚠️"), + new PartialEmoji(Name: "\u26a0\ufe0f"), // 'WARNING SIGN' (U+26A0) URL: BuildInfo.IssuesUrl, IsDisabled: BuildInfo.IsDirty ); diff --git a/src/Services/Update/ScheduledEventUpdateService.cs b/src/Services/Update/ScheduledEventUpdateService.cs index 8168fc1..cb87779 100644 --- a/src/Services/Update/ScheduledEventUpdateService.cs +++ b/src/Services/Update/ScheduledEventUpdateService.cs @@ -223,7 +223,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService var button = new ButtonComponent( ButtonComponentStyle.Link, Messages.ButtonOpenEventInfo, - new PartialEmoji(Name: "📋"), + new PartialEmoji(Name: "\ud83d\udccb"), // 'CLIPBOARD' (U+1F4CB) URL: $"https://discord.com/events/{scheduledEvent.GuildID}/{scheduledEvent.ID}" ); From 96680d3beb4361d20f7efe1edd02c567519476a5 Mon Sep 17 00:00:00 2001 From: Macintxsh <95250141+mctaylors@users.noreply.github.com> Date: Mon, 1 Apr 2024 15:59:19 +0300 Subject: [PATCH 06/42] Make the logo in /about independent of image hosting (#296) PR's name speaks for itself. It might also be useful to update the logo more easily. --------- Signed-off-by: Macintxsh <95250141+mctaylors@users.noreply.github.com> Co-authored-by: Octol1ttle --- src/Commands/AboutCommandGroup.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/AboutCommandGroup.cs b/src/Commands/AboutCommandGroup.cs index f2fa11f..b8c6d0f 100644 --- a/src/Commands/AboutCommandGroup.cs +++ b/src/Commands/AboutCommandGroup.cs @@ -100,7 +100,7 @@ public class AboutCommandGroup : CommandGroup .WithSmallTitle(string.Format(Messages.AboutBot, bot.Username), bot) .WithDescription(builder.ToString()) .WithColour(ColorsList.Cyan) - .WithImageUrl("https://i.ibb.co/fS6wZhh/octobot-banner.png") + .WithImageUrl("https://raw.githubusercontent.com/TeamOctolings/Octobot/master/docs/octobot-banner.png") .WithFooter(string.Format(Messages.Version, BuildInfo.Version)) .Build(); From d3053d87e813bf698851d19b2d3337fe1ee1852e Mon Sep 17 00:00:00 2001 From: Macintxsh <95250141+mctaylors@users.noreply.github.com> Date: Mon, 1 Apr 2024 22:20:41 +0300 Subject: [PATCH 07/42] Remove mctaylors' version of the Russian language (#297) 295 PR/issues ~(not 300, however)~ or ~1.5 years ago, I made #2, the Russian language replacement aka mctaylors-ru. This was my first contribution to the Octobot project (formerly known as Boyfriend). This was to add some sort of unique, unusual feature to Octobot, which doesn't have any moderator bots. Everyone loved the language. But it just became difficult to maintain. I certainly don't want to get rid of it, but it leaves me no other choice. This isn't a joke or anything like that. I'm tired of maintaining it. And I'm sure the other contributors are too. This PR removes the mctaylors-ru language. --------- Signed-off-by: mctaylors Co-authored-by: Octol1ttle --- locale/Messages.tt-ru.resx | 684 ----------------------------- src/Data/Options/LanguageOption.cs | 3 +- src/Services/GuildDataService.cs | 18 +- 3 files changed, 17 insertions(+), 688 deletions(-) delete mode 100644 locale/Messages.tt-ru.resx diff --git a/locale/Messages.tt-ru.resx b/locale/Messages.tt-ru.resx deleted file mode 100644 index 4e92a44..0000000 --- a/locale/Messages.tt-ru.resx +++ /dev/null @@ -1,684 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - я родился! - - - сообщение {0} вырезано: - - - сообщение {0} переделано: - - - {0}, добро пожаловать на сервер {1} - - - вииимо! - - - вуууми! - - - нгьес! - - - вы были забанены - - - время бана закончиловсь - - - вы были кикнуты - - - мс - - - *тут ничего нет* - - - нъет - - - язык - - - префикс - - - удалять звание при муте - - - разглашать о том что пришел новый шизоид - - - звание замученного - - - такого языка нету... - - - да - - - нъет - - - шизик не забанен - - - шизоид не замучен! - - - здравствуйте (типо настройка) - - - {0} забанен - - - получать инфу о старте бота - - - криво настроил прикол, давай по новой - - - ты шо, мутить больше чем на 28 дней таймаут не разрешает, вот настроишь роль мута, тогда поговорим - - - я не могу замутить ботов, сделай что нибудь - - - роль для уведомлений о создании движухи - - - канал для уведомлений о движухах - - - получатели уведомлений о начале движух - - - движуха "{0}" начинается - - - движуха "{0}" отменена! - - - движуха "{0}" завершена! - - - вырезано {0} забавных сообщений - - - ты все сломал! значение прикола `{0}` и так {1} - - - нъет - - - укажи самого шизика - - - бан - - - тебе нельзя иметь власть над сообщениями шизоидов - - - кик шизиков нельзя - - - тебе нельзя мутить шизоидов - - - тебе нельзя раззамучивать шизоидов - - - тебе нельзя редактировать дурку - - - я не могу ваще никого банить чел. - - - я не могу исправлять орфографический кринж участников, сделай что нибудь. - - - я не могу ваще никого кикать чел. - - - я не могу контроллировать за всеми ними, сделай что нибудь. - - - я не могу этому серверу хоть че либо нибудь изменить, сделай что нибудь. - - - ээбля френдли фаер огонь по своим - - - бан админу нельзя - - - бан этому шизику нельзя - - - самобан нельзя - - - я не могу его забанить... - - - кик админу нельзя - - - самокик нельзя - - - ээбля френдли фаер огонь по своим - - - я не могу его кикнуть... - - - кик этому шизику нельзя - - - мут админу нельзя - - - самомут нельзя - - - ээбля френдли фаер огонь по своим - - - я не могу его замутить... - - - мут этому шизику нельзя - - - сильно - - - ты замучен. - - - ... - - - тебе нельзя раззамучивать - - - я не могу его раззамутить... - - - движуха "{0}" начнется {1}! - - - заранее пнуть в минутах до начала движухи - - - у нас такого шизоида нету, проверь, валиден ли ID уважаемого (я забываю о шизоидах если они ливнули минимум месяц назад) - - - дефолтное звание - - - канал для секретных уведомлений - - - канал для не секретных уведомлений - - - вернуть звания при переподключении в дурку - - - автоматом стартить движухи - - - ответственный - - - {0} создает новое событие: - - - движуха произойдет {0} в канале {1} - - - движуха будет происходить с {0} до {1} в {2} - - - открыть ивент - - - все это длилось `{0}` - - - движуха происходит в {0} - - - движуха происходит в {0} до {1} - - - этот шизоид уже лежит в бане - - - {0} раззабанен - - - {0} в муте - - - {0} в размуте - - - этого шизоида никто не мутил. - - - у нас такого шизоида нету... - - - {0} вышел с посторонней помощью - - - причина: {0} - - - до: {0} - - - этот шизоид УЖЕ замучился - - - от {0} - - - девелоперы: - - - репа Octobot (тык) - - - немного об {0} - - - скучный девелопер + дизайнер создавший Octobot's Wiki - - - ВАЖНЫЙ соучастник кодинг-стримов @Octol1ttle - - - САМЫЙ ВАЖНЫЙ чел написавший кода больше всех (99.99%) - - - напоминалка для {0} скрафченА - - - напоминалка для {0} - - - ты хотел чтоб я напомнил тебе {0} - - - приколы Octobot - - - прикол редактирован - - - прикол сдох - - - стало - - - переобувать шизоидов пытающихся поднять себя в табе - - - это страница - - - если я был бы html, я бы сказал 404 - - - ну а если быть точнее, тут всего {0} страниц(-ы) - - - следующее - - - предыдущее - - - напоминалки {0} - - - у тебя нет напоминалки на этом номере! - - - напоминалка уничтожена - - - ты еще не крафтил напоминалки - - - {0} откачен к заводским - - - откатываемся к заводским... - - - чекнуть сообщение: {0} - - - чекнуть канал: {0} - - - номер в списке: {0} - - - время отправки: {0} - - - че там в напоминалке: {0} - - - дисплейнейм - - - деанон {0} - - - замучен - - - юзер Discord со времен - - - забанен - - - приколы полученные по заслугам - - - пермабан - - - вышел из сервера - - - замучен таймаутом - - - замучен ролькой - - - участник сервера со времен - - - сервернейм - - - рольки - - - бустит сервер со времен - - - рандомное число {0}: - - - ну чувак... - - - наибольшее: {0} - - - наименьшее: {0} - - - (дефолт) - - - таймштамп для {0}: - - - офсет: {0} - - - дескрипшон гильдии - - - создался - - - админ гильдии - - - буст гильдии - - - уровень - - - кол-во бустов - - - алло а чё мне удалять-то - - - вырезано {0} забавных сообщений от {1} - - - произошёл тотальный разнос в гилддате. - - - возможно всё съедет с крыши, но знай, что я больше ничё не сохраню. - - - произошёл тотальный разнос в команде, удачи. - - - если ты это читаешь второй раз за сегодня, пиши разрабам - - - зарепортить баг - - - ну, мы потеряли {0} - - - до свидания (типо настройка) - - - ты там правильно напиши таймспан - - - кикнут - - - напоминалка подправлена - - - абсолютли - - - заявлено - - - ваще не сомневайся - - - 100% да - - - будь в этом уверен - - - я считаю что да - - - ну вполне вероятно - - - ну выглядит нормально - - - мне сказали ок - - - мгм - - - ну-ка попробуй снова - - - давай позже - - - щас пока не скажу - - - я не могу сейчас предсказать - - - ну сконцентрируйся и давай еще раз - - - даже не думай - - - мое завление это нет - - - я тут посчитал, короче нет - - - выглядит такое себе - - - чот сомневаюсь - - - правильно пишут так: `1h30m` - - - {0} - - - канал куда говорить здравствуйте - - - вот иди сам и почини что сломал - - - вики Octobot (жмак) - - - звание админа - - diff --git a/src/Data/Options/LanguageOption.cs b/src/Data/Options/LanguageOption.cs index 464c61b..22f98df 100644 --- a/src/Data/Options/LanguageOption.cs +++ b/src/Data/Options/LanguageOption.cs @@ -11,8 +11,7 @@ public sealed class LanguageOption : Option private static readonly Dictionary CultureInfoCache = new() { { "en", new CultureInfo("en-US") }, - { "ru", new CultureInfo("ru-RU") }, - { "mctaylors-ru", new CultureInfo("tt-RU") } + { "ru", new CultureInfo("ru-RU") } }; public LanguageOption(string name, string defaultValue) : base(name, CultureInfoCache[defaultValue]) { } diff --git a/src/Services/GuildDataService.cs b/src/Services/GuildDataService.cs index c9458a0..e503d22 100644 --- a/src/Services/GuildDataService.cs +++ b/src/Services/GuildDataService.cs @@ -78,7 +78,7 @@ public sealed class GuildDataService : BackgroundService var settingsPath = $"{path}/Settings.json"; var scheduledEventsPath = $"{path}/ScheduledEvents.json"; - MigrateGuildData(guildId, path); + MigrateDataDirectory(guildId, path); Directory.CreateDirectory(path); @@ -106,6 +106,11 @@ public sealed class GuildDataService : BackgroundService dataLoadFailed = true; } + if (jsonSettings is not null) + { + FixJsonSettings(jsonSettings); + } + await using var eventsStream = File.OpenRead(scheduledEventsPath); Dictionary? events = null; try @@ -155,7 +160,7 @@ public sealed class GuildDataService : BackgroundService return finalData; } - private void MigrateGuildData(Snowflake guildId, string newPath) + private void MigrateDataDirectory(Snowflake guildId, string newPath) { var oldPath = $"{guildId}"; @@ -169,6 +174,15 @@ public sealed class GuildDataService : BackgroundService } } + private static void FixJsonSettings(JsonNode settings) + { + var language = settings[GuildSettings.Language.Name]?.GetValue(); + if (language is "mctaylors-ru") + { + settings[GuildSettings.Language.Name] = "ru"; + } + } + public async Task GetSettings(Snowflake guildId, CancellationToken ct = default) { return (await GetData(guildId, ct)).Settings; From defa3c2e4acc5e30f6e533a2b3480b73e37a05b2 Mon Sep 17 00:00:00 2001 From: Macintxsh <95250141+mctaylors@users.noreply.github.com> Date: Sun, 7 Apr 2024 13:51:28 +0300 Subject: [PATCH 08/42] Listen to Maritime Memory on Wii U Discontinuation Day (#299) Due to the shutdown of Wii U online services on April 8 at 23:00 UTC (which affects Splatoon for Wii U), I'm opening a PR to memorialize Splatoon multiplayer on Wii U by replacing bot music with Maritime Memory on April 8-9. Signed-off-by: mctaylors --- src/Services/Update/SongUpdateService.cs | 31 +++++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/Services/Update/SongUpdateService.cs b/src/Services/Update/SongUpdateService.cs index 53cc59b..41d5bf3 100644 --- a/src/Services/Update/SongUpdateService.cs +++ b/src/Services/Update/SongUpdateService.cs @@ -32,6 +32,11 @@ public sealed class SongUpdateService : BackgroundService ("Off the Hook", "Fly Octo Fly ~ Ebb & Flow (Octo)", new TimeSpan(0, 3, 5)) ]; + private static readonly (string Author, string Name, TimeSpan Duration)[] SpecialSongList = + [ + ("Squid Sisters", "Maritime Memory", new TimeSpan(0, 2, 47)) + ]; + private readonly List _activityList = [new Activity("with Remora.Discord", ActivityType.Game)]; private readonly DiscordGatewayClient _client; @@ -54,19 +59,33 @@ public sealed class SongUpdateService : BackgroundService while (!ct.IsCancellationRequested) { - var nextSong = SongList[_nextSongIndex]; + var nextSong = NextSong(); _activityList[0] = new Activity($"{nextSong.Name} / {nextSong.Author}", ActivityType.Listening); _client.SubmitCommand( new UpdatePresence( UserStatus.Online, false, DateTimeOffset.UtcNow, _activityList)); - _nextSongIndex++; - if (_nextSongIndex >= SongList.Length) - { - _nextSongIndex = 0; - } await Task.Delay(nextSong.Duration, ct); } } + + private (string Author, string Name, TimeSpan Duration) NextSong() + { + var today = DateTime.Today; + // Discontinuation of Online Services for Nintendo Wii U + if (today.Day is 8 or 9 && today.Month is 4) + { + return SpecialSongList[0]; // Maritime Memory / Squid Sisters + } + + var nextSong = SongList[_nextSongIndex]; + _nextSongIndex++; + if (_nextSongIndex >= SongList.Length) + { + _nextSongIndex = 0; + } + + return nextSong; + } } From 508edcbd683f5505a6cbe636aaed6b315a6ed378 Mon Sep 17 00:00:00 2001 From: Macintxsh <95250141+mctaylors@users.noreply.github.com> Date: Mon, 8 Apr 2024 14:02:31 +0300 Subject: [PATCH 09/42] Don't hardcode logo's link in /about (#301) In this PR, I made the logo link in /about use HEAD instead of hardcoded branch. --------- Signed-off-by: mctaylors Co-authored-by: Octol1ttle --- src/Commands/AboutCommandGroup.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/AboutCommandGroup.cs b/src/Commands/AboutCommandGroup.cs index b8c6d0f..02384f8 100644 --- a/src/Commands/AboutCommandGroup.cs +++ b/src/Commands/AboutCommandGroup.cs @@ -100,7 +100,7 @@ public class AboutCommandGroup : CommandGroup .WithSmallTitle(string.Format(Messages.AboutBot, bot.Username), bot) .WithDescription(builder.ToString()) .WithColour(ColorsList.Cyan) - .WithImageUrl("https://raw.githubusercontent.com/TeamOctolings/Octobot/master/docs/octobot-banner.png") + .WithImageUrl("https://raw.githubusercontent.com/TeamOctolings/Octobot/HEAD/docs/octobot-banner.png") .WithFooter(string.Format(Messages.Version, BuildInfo.Version)) .Build(); From 3029089385e66e886c9a43f369889287d90cfa8a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 May 2024 12:41:55 +0000 Subject: [PATCH 10/42] Bump muno92/resharper_inspectcode from 1.11.8 to 1.11.10 (#302) --- .github/workflows/build-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 859f8fa..c92386e 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -23,7 +23,7 @@ jobs: uses: actions/checkout@v4 - name: ReSharper CLI InspectCode - uses: muno92/resharper_inspectcode@1.11.8 + uses: muno92/resharper_inspectcode@1.11.10 with: solutionPath: ./Octobot.sln ignoreIssueType: InvertIf, ConvertIfStatementToSwitchStatement, ConvertToPrimaryConstructor From 2502beb5df94c0d62bb7e7ed4a0c5bb528f7ecda Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Mon, 13 May 2024 17:43:59 +0500 Subject: [PATCH 11/42] Dependabot: ignore patch updates (#304) This PR *should* disable creating Dependabot PRs for patch updates. These updates often don't contain significant changes and only clutter the PR feed in addition to taking the maintainers' time --- .github/dependabot.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 4545f2b..57eea90 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -15,6 +15,10 @@ updates: labels: - "type: change" - "area: build/ci" + # For all packages, ignore all patch updates + ignore: + - dependency-name: "*" + update-types: [ "version-update:semver-patch" ] - package-ecosystem: "nuget" # See documentation for possible values directory: "/" # Location of package manifests @@ -30,3 +34,7 @@ updates: remora: patterns: - "Remora.Discord.*" + # For all packages, ignore all patch updates + ignore: + - dependency-name: "*" + update-types: [ "version-update:semver-patch" ] From 19fadead913edc8dea303c337e9f9fcf94d47d12 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Mon, 13 May 2024 18:10:41 +0500 Subject: [PATCH 12/42] Enable result stacktraces in release mode (#305) Originally I did not enable because "stack traces are expensive to retrieve", but let's be honest, who cares, this is a Discord bot, there's no such thing as "good performance" --- src/Extensions/ResultExtensions.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Extensions/ResultExtensions.cs b/src/Extensions/ResultExtensions.cs index f456dac..a95a1e2 100644 --- a/src/Extensions/ResultExtensions.cs +++ b/src/Extensions/ResultExtensions.cs @@ -21,7 +21,6 @@ public static class ResultExtensions return casted; } - [Conditional("DEBUG")] private static void LogResultStackTrace(Result result) { if (Octobot.StaticLogger is null || result.IsSuccess) From 793afd0e06fc346ba3161d368df7c87f2f068f38 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Thu, 16 May 2024 20:34:26 +0500 Subject: [PATCH 13/42] Apply official naming guidelines to Octobot (#306) 1. The root namespace was changed from `Octobot` to `TeamOctolings.Octobot`: > DO prefix namespace names with a company name to prevent namespaces from different companies from having the same name. 2. `Octobot.cs` was renamed to `Program.cs`: > DO NOT use the same name for a namespace and a type in that namespace. 3. `IOption`, `Option` were renamed to `IGuildOption` and `GuildOption` respectively: > DO NOT introduce generic type names such as Element, Node, Log, and Message. 4. `Utility` was moved out of the `Services` namespace. It didn't belong there anyway 5. `Program` static fields were moved to `Utility` 6. Localisation files were moved back to the project source files. Looks like this fixed `Message.Designer.cs` code generation --------- Signed-off-by: Octol1ttle --- Octobot.sln | 10 +- .../Attributes/StaticCallersOnlyAttribute.cs | 2 +- {src => TeamOctolings.Octobot}/BuildInfo.cs | 2 +- {src => TeamOctolings.Octobot}/ColorsList.cs | 2 +- .../Commands/AboutCommandGroup.cs | 8 +- .../Commands/BanCommandGroup.cs | 12 +- .../Commands/ClearCommandGroup.cs | 8 +- .../Events/ErrorLoggingPostExecutionEvent.cs | 4 +- .../Events/LoggingPreparationErrorEvent.cs | 4 +- .../Commands/KickCommandGroup.cs | 8 +- .../Commands/MuteCommandGroup.cs | 12 +- .../Commands/PingCommandGroup.cs | 8 +- .../Commands/RemindCommandGroup.cs | 10 +- .../Commands/SettingsCommandGroup.cs | 18 +- .../Commands/ToolsCommandGroup.cs | 10 +- .../Data/GuildData.cs | 2 +- .../Data/GuildSettings.cs | 10 +- .../Data/MemberData.cs | 2 +- .../Data/Options/AllOptionsEnum.cs | 4 +- .../Data/Options/BoolOption.cs | 4 +- .../Data/Options/GuildOption.cs | 8 +- .../Data/Options/IGuildOption.cs | 4 +- .../Data/Options/LanguageOption.cs | 4 +- .../Data/Options/SnowflakeOption.cs | 6 +- .../Data/Options/TimeSpanOption.cs | 6 +- .../Data/Reminder.cs | 2 +- .../Data/ScheduledEventData.cs | 2 +- .../Extensions/ChannelApiExtensions.cs | 2 +- .../Extensions/CollectionExtensions.cs | 2 +- .../Extensions/CommandContextExtensions.cs | 2 +- .../Extensions/DiffPaneModelExtensions.cs | 2 +- .../Extensions/EmbedBuilderExtensions.cs | 2 +- .../Extensions/FeedbackServiceExtensions.cs | 2 +- .../GuildScheduledEventExtensions.cs | 2 +- .../Extensions/LoggerExtensions.cs | 2 +- .../Extensions/MarkdownExtensions.cs | 2 +- .../Extensions/ResultExtensions.cs | 13 +- .../Extensions/SnowflakeExtensions.cs | 2 +- .../Extensions/StringBuilderExtensions.cs | 2 +- .../Extensions/StringExtensions.cs | 2 +- .../Extensions/UInt64Extensions.cs | 2 +- .../Extensions/UserExtensions.cs | 2 +- .../Messages.Designer.cs | 564 +++++++++--------- .../Messages.resx | 0 .../Messages.ru.resx | 0 .../Parsers/TimeSpanParser.cs | 2 +- .../Program.cs | 25 +- .../Responders/GuildLoadedResponder.cs | 8 +- .../Responders/GuildMemberJoinedResponder.cs | 10 +- .../Responders/GuildMemberLeftResponder.cs | 10 +- .../Responders/GuildUnloadedResponder.cs | 6 +- .../Responders/MessageDeletedResponder.cs | 10 +- .../Responders/MessageEditedResponder.cs | 10 +- .../Responders/MessageReceivedResponder.cs | 2 +- .../Services/AccessControlService.cs | 8 +- .../Services/GuildDataService.cs | 4 +- .../Services/Update/MemberUpdateService.cs | 6 +- .../Update/ScheduledEventUpdateService.cs | 6 +- .../Services/Update/SongUpdateService.cs | 2 +- .../TeamOctolings.Octobot.csproj | 8 +- .../Utility.cs | 15 +- 61 files changed, 447 insertions(+), 462 deletions(-) rename {src => TeamOctolings.Octobot}/Attributes/StaticCallersOnlyAttribute.cs (88%) rename {src => TeamOctolings.Octobot}/BuildInfo.cs (93%) rename {src => TeamOctolings.Octobot}/ColorsList.cs (95%) rename {src => TeamOctolings.Octobot}/Commands/AboutCommandGroup.cs (97%) rename {src => TeamOctolings.Octobot}/Commands/BanCommandGroup.cs (98%) rename {src => TeamOctolings.Octobot}/Commands/ClearCommandGroup.cs (97%) rename {src => TeamOctolings.Octobot}/Commands/Events/ErrorLoggingPostExecutionEvent.cs (97%) rename {src => TeamOctolings.Octobot}/Commands/Events/LoggingPreparationErrorEvent.cs (93%) rename {src => TeamOctolings.Octobot}/Commands/KickCommandGroup.cs (97%) rename {src => TeamOctolings.Octobot}/Commands/MuteCommandGroup.cs (98%) rename {src => TeamOctolings.Octobot}/Commands/PingCommandGroup.cs (96%) rename {src => TeamOctolings.Octobot}/Commands/RemindCommandGroup.cs (98%) rename {src => TeamOctolings.Octobot}/Commands/SettingsCommandGroup.cs (96%) rename {src => TeamOctolings.Octobot}/Commands/ToolsCommandGroup.cs (99%) rename {src => TeamOctolings.Octobot}/Data/GuildData.cs (97%) rename {src => TeamOctolings.Octobot}/Data/GuildSettings.cs (92%) rename {src => TeamOctolings.Octobot}/Data/MemberData.cs (93%) rename {src => TeamOctolings.Octobot}/Data/Options/AllOptionsEnum.cs (92%) rename {src => TeamOctolings.Octobot}/Data/Options/BoolOption.cs (91%) rename src/Data/Options/Option.cs => TeamOctolings.Octobot/Data/Options/GuildOption.cs (90%) rename src/Data/Options/IOption.cs => TeamOctolings.Octobot/Data/Options/IGuildOption.cs (73%) rename {src => TeamOctolings.Octobot}/Data/Options/LanguageOption.cs (91%) rename {src => TeamOctolings.Octobot}/Data/Options/SnowflakeOption.cs (87%) rename {src => TeamOctolings.Octobot}/Data/Options/TimeSpanOption.cs (82%) rename {src => TeamOctolings.Octobot}/Data/Reminder.cs (83%) rename {src => TeamOctolings.Octobot}/Data/ScheduledEventData.cs (97%) rename {src => TeamOctolings.Octobot}/Extensions/ChannelApiExtensions.cs (96%) rename {src => TeamOctolings.Octobot}/Extensions/CollectionExtensions.cs (96%) rename {src => TeamOctolings.Octobot}/Extensions/CommandContextExtensions.cs (92%) rename {src => TeamOctolings.Octobot}/Extensions/DiffPaneModelExtensions.cs (94%) rename {src => TeamOctolings.Octobot}/Extensions/EmbedBuilderExtensions.cs (99%) rename {src => TeamOctolings.Octobot}/Extensions/FeedbackServiceExtensions.cs (93%) rename {src => TeamOctolings.Octobot}/Extensions/GuildScheduledEventExtensions.cs (95%) rename {src => TeamOctolings.Octobot}/Extensions/LoggerExtensions.cs (96%) rename {src => TeamOctolings.Octobot}/Extensions/MarkdownExtensions.cs (88%) rename {src => TeamOctolings.Octobot}/Extensions/ResultExtensions.cs (82%) rename {src => TeamOctolings.Octobot}/Extensions/SnowflakeExtensions.cs (96%) rename {src => TeamOctolings.Octobot}/Extensions/StringBuilderExtensions.cs (98%) rename {src => TeamOctolings.Octobot}/Extensions/StringExtensions.cs (98%) rename {src => TeamOctolings.Octobot}/Extensions/UInt64Extensions.cs (82%) rename {src => TeamOctolings.Octobot}/Extensions/UserExtensions.cs (85%) rename {src => TeamOctolings.Octobot}/Messages.Designer.cs (89%) rename {locale => TeamOctolings.Octobot}/Messages.resx (100%) rename {locale => TeamOctolings.Octobot}/Messages.ru.resx (100%) rename {src => TeamOctolings.Octobot}/Parsers/TimeSpanParser.cs (98%) rename src/Octobot.cs => TeamOctolings.Octobot/Program.cs (86%) rename {src => TeamOctolings.Octobot}/Responders/GuildLoadedResponder.cs (96%) rename {src => TeamOctolings.Octobot}/Responders/GuildMemberJoinedResponder.cs (94%) rename {src => TeamOctolings.Octobot}/Responders/GuildMemberLeftResponder.cs (91%) rename {src => TeamOctolings.Octobot}/Responders/GuildUnloadedResponder.cs (90%) rename {src => TeamOctolings.Octobot}/Responders/MessageDeletedResponder.cs (94%) rename {src => TeamOctolings.Octobot}/Responders/MessageEditedResponder.cs (95%) rename {src => TeamOctolings.Octobot}/Responders/MessageReceivedResponder.cs (96%) rename {src => TeamOctolings.Octobot}/Services/AccessControlService.cs (97%) rename {src => TeamOctolings.Octobot}/Services/GuildDataService.cs (98%) rename {src => TeamOctolings.Octobot}/Services/Update/MemberUpdateService.cs (98%) rename {src => TeamOctolings.Octobot}/Services/Update/ScheduledEventUpdateService.cs (99%) rename {src => TeamOctolings.Octobot}/Services/Update/SongUpdateService.cs (98%) rename Octobot.csproj => TeamOctolings.Octobot/TeamOctolings.Octobot.csproj (90%) rename {src/Services => TeamOctolings.Octobot}/Utility.cs (92%) diff --git a/Octobot.sln b/Octobot.sln index 9dd2b89..b82f7a9 100644 --- a/Octobot.sln +++ b/Octobot.sln @@ -1,6 +1,6 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Octobot", "Octobot.csproj", "{9CA7A44F-167C-46D4-923D-88CE71044144}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeamOctolings.Octobot", "TeamOctolings.Octobot\TeamOctolings.Octobot.csproj", "{A1679BA2-3A36-4D98-80C0-EEE771398FBD}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -8,9 +8,9 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {9CA7A44F-167C-46D4-923D-88CE71044144}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9CA7A44F-167C-46D4-923D-88CE71044144}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9CA7A44F-167C-46D4-923D-88CE71044144}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9CA7A44F-167C-46D4-923D-88CE71044144}.Release|Any CPU.Build.0 = Release|Any CPU + {A1679BA2-3A36-4D98-80C0-EEE771398FBD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A1679BA2-3A36-4D98-80C0-EEE771398FBD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A1679BA2-3A36-4D98-80C0-EEE771398FBD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A1679BA2-3A36-4D98-80C0-EEE771398FBD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/src/Attributes/StaticCallersOnlyAttribute.cs b/TeamOctolings.Octobot/Attributes/StaticCallersOnlyAttribute.cs similarity index 88% rename from src/Attributes/StaticCallersOnlyAttribute.cs rename to TeamOctolings.Octobot/Attributes/StaticCallersOnlyAttribute.cs index e8787bf..0256f62 100644 --- a/src/Attributes/StaticCallersOnlyAttribute.cs +++ b/TeamOctolings.Octobot/Attributes/StaticCallersOnlyAttribute.cs @@ -1,4 +1,4 @@ -namespace Octobot.Attributes; +namespace TeamOctolings.Octobot.Attributes; /// /// Any property marked with should only be accessed by static methods. diff --git a/src/BuildInfo.cs b/TeamOctolings.Octobot/BuildInfo.cs similarity index 93% rename from src/BuildInfo.cs rename to TeamOctolings.Octobot/BuildInfo.cs index 2eb6059..4b9a09f 100644 --- a/src/BuildInfo.cs +++ b/TeamOctolings.Octobot/BuildInfo.cs @@ -1,4 +1,4 @@ -namespace Octobot; +namespace TeamOctolings.Octobot; public static class BuildInfo { diff --git a/src/ColorsList.cs b/TeamOctolings.Octobot/ColorsList.cs similarity index 95% rename from src/ColorsList.cs rename to TeamOctolings.Octobot/ColorsList.cs index cd40313..3b66c0a 100644 --- a/src/ColorsList.cs +++ b/TeamOctolings.Octobot/ColorsList.cs @@ -1,6 +1,6 @@ using System.Drawing; -namespace Octobot; +namespace TeamOctolings.Octobot; /// /// Contains all colors used in embeds. diff --git a/src/Commands/AboutCommandGroup.cs b/TeamOctolings.Octobot/Commands/AboutCommandGroup.cs similarity index 97% rename from src/Commands/AboutCommandGroup.cs rename to TeamOctolings.Octobot/Commands/AboutCommandGroup.cs index 02384f8..9f05af3 100644 --- a/src/Commands/AboutCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/AboutCommandGroup.cs @@ -1,9 +1,6 @@ using System.ComponentModel; using System.Text; using JetBrains.Annotations; -using Octobot.Data; -using Octobot.Extensions; -using Octobot.Services; using Remora.Commands.Attributes; using Remora.Commands.Groups; using Remora.Discord.API.Abstractions.Objects; @@ -18,8 +15,11 @@ using Remora.Discord.Extensions.Embeds; using Remora.Discord.Extensions.Formatting; using Remora.Rest.Core; using Remora.Results; +using TeamOctolings.Octobot.Data; +using TeamOctolings.Octobot.Extensions; +using TeamOctolings.Octobot.Services; -namespace Octobot.Commands; +namespace TeamOctolings.Octobot.Commands; /// /// Handles the command to show information about this bot: /about. diff --git a/src/Commands/BanCommandGroup.cs b/TeamOctolings.Octobot/Commands/BanCommandGroup.cs similarity index 98% rename from src/Commands/BanCommandGroup.cs rename to TeamOctolings.Octobot/Commands/BanCommandGroup.cs index 02a377a..8d90286 100644 --- a/src/Commands/BanCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/BanCommandGroup.cs @@ -2,11 +2,6 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Text; using JetBrains.Annotations; -using Octobot.Data; -using Octobot.Extensions; -using Octobot.Parsers; -using Octobot.Services; -using Octobot.Services.Update; using Remora.Commands.Attributes; using Remora.Commands.Groups; using Remora.Discord.API.Abstractions.Objects; @@ -19,8 +14,13 @@ using Remora.Discord.Extensions.Embeds; using Remora.Discord.Extensions.Formatting; using Remora.Rest.Core; using Remora.Results; +using TeamOctolings.Octobot.Data; +using TeamOctolings.Octobot.Extensions; +using TeamOctolings.Octobot.Parsers; +using TeamOctolings.Octobot.Services; +using TeamOctolings.Octobot.Services.Update; -namespace Octobot.Commands; +namespace TeamOctolings.Octobot.Commands; /// /// Handles commands related to ban management: /ban and /unban. diff --git a/src/Commands/ClearCommandGroup.cs b/TeamOctolings.Octobot/Commands/ClearCommandGroup.cs similarity index 97% rename from src/Commands/ClearCommandGroup.cs rename to TeamOctolings.Octobot/Commands/ClearCommandGroup.cs index 84b69db..8a8cb2f 100644 --- a/src/Commands/ClearCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/ClearCommandGroup.cs @@ -1,9 +1,6 @@ using System.ComponentModel; using System.Text; using JetBrains.Annotations; -using Octobot.Data; -using Octobot.Extensions; -using Octobot.Services; using Remora.Commands.Attributes; using Remora.Commands.Groups; using Remora.Discord.API.Abstractions.Objects; @@ -16,8 +13,11 @@ using Remora.Discord.Extensions.Embeds; using Remora.Discord.Extensions.Formatting; using Remora.Rest.Core; using Remora.Results; +using TeamOctolings.Octobot.Data; +using TeamOctolings.Octobot.Extensions; +using TeamOctolings.Octobot.Services; -namespace Octobot.Commands; +namespace TeamOctolings.Octobot.Commands; /// /// Handles the command to clear messages in a channel: /clear. diff --git a/src/Commands/Events/ErrorLoggingPostExecutionEvent.cs b/TeamOctolings.Octobot/Commands/Events/ErrorLoggingPostExecutionEvent.cs similarity index 97% rename from src/Commands/Events/ErrorLoggingPostExecutionEvent.cs rename to TeamOctolings.Octobot/Commands/Events/ErrorLoggingPostExecutionEvent.cs index 551c2d0..7ffc4fe 100644 --- a/src/Commands/Events/ErrorLoggingPostExecutionEvent.cs +++ b/TeamOctolings.Octobot/Commands/Events/ErrorLoggingPostExecutionEvent.cs @@ -1,6 +1,5 @@ using JetBrains.Annotations; using Microsoft.Extensions.Logging; -using Octobot.Extensions; using Remora.Discord.API.Abstractions.Objects; using Remora.Discord.API.Abstractions.Rest; using Remora.Discord.API.Objects; @@ -11,8 +10,9 @@ using Remora.Discord.Commands.Services; using Remora.Discord.Extensions.Embeds; using Remora.Discord.Extensions.Formatting; using Remora.Results; +using TeamOctolings.Octobot.Extensions; -namespace Octobot.Commands.Events; +namespace TeamOctolings.Octobot.Commands.Events; /// /// Handles error logging for slash command groups. diff --git a/src/Commands/Events/LoggingPreparationErrorEvent.cs b/TeamOctolings.Octobot/Commands/Events/LoggingPreparationErrorEvent.cs similarity index 93% rename from src/Commands/Events/LoggingPreparationErrorEvent.cs rename to TeamOctolings.Octobot/Commands/Events/LoggingPreparationErrorEvent.cs index 87b4090..10a6a1f 100644 --- a/src/Commands/Events/LoggingPreparationErrorEvent.cs +++ b/TeamOctolings.Octobot/Commands/Events/LoggingPreparationErrorEvent.cs @@ -1,11 +1,11 @@ using JetBrains.Annotations; using Microsoft.Extensions.Logging; -using Octobot.Extensions; using Remora.Discord.Commands.Contexts; using Remora.Discord.Commands.Services; using Remora.Results; +using TeamOctolings.Octobot.Extensions; -namespace Octobot.Commands.Events; +namespace TeamOctolings.Octobot.Commands.Events; /// /// Handles error logging for slash commands that couldn't be successfully prepared. diff --git a/src/Commands/KickCommandGroup.cs b/TeamOctolings.Octobot/Commands/KickCommandGroup.cs similarity index 97% rename from src/Commands/KickCommandGroup.cs rename to TeamOctolings.Octobot/Commands/KickCommandGroup.cs index 87b915a..4252232 100644 --- a/src/Commands/KickCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/KickCommandGroup.cs @@ -1,9 +1,6 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations; using JetBrains.Annotations; -using Octobot.Data; -using Octobot.Extensions; -using Octobot.Services; using Remora.Commands.Attributes; using Remora.Commands.Groups; using Remora.Discord.API.Abstractions.Objects; @@ -15,8 +12,11 @@ using Remora.Discord.Commands.Feedback.Services; using Remora.Discord.Extensions.Embeds; using Remora.Rest.Core; using Remora.Results; +using TeamOctolings.Octobot.Data; +using TeamOctolings.Octobot.Extensions; +using TeamOctolings.Octobot.Services; -namespace Octobot.Commands; +namespace TeamOctolings.Octobot.Commands; /// /// Handles the command to kick members of a guild: /kick. diff --git a/src/Commands/MuteCommandGroup.cs b/TeamOctolings.Octobot/Commands/MuteCommandGroup.cs similarity index 98% rename from src/Commands/MuteCommandGroup.cs rename to TeamOctolings.Octobot/Commands/MuteCommandGroup.cs index ce0a296..8e449f7 100644 --- a/src/Commands/MuteCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/MuteCommandGroup.cs @@ -2,11 +2,6 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Text; using JetBrains.Annotations; -using Octobot.Data; -using Octobot.Extensions; -using Octobot.Parsers; -using Octobot.Services; -using Octobot.Services.Update; using Remora.Commands.Attributes; using Remora.Commands.Groups; using Remora.Discord.API.Abstractions.Objects; @@ -19,8 +14,13 @@ using Remora.Discord.Extensions.Embeds; using Remora.Discord.Extensions.Formatting; using Remora.Rest.Core; using Remora.Results; +using TeamOctolings.Octobot.Data; +using TeamOctolings.Octobot.Extensions; +using TeamOctolings.Octobot.Parsers; +using TeamOctolings.Octobot.Services; +using TeamOctolings.Octobot.Services.Update; -namespace Octobot.Commands; +namespace TeamOctolings.Octobot.Commands; /// /// Handles commands related to mute management: /mute and /unmute. diff --git a/src/Commands/PingCommandGroup.cs b/TeamOctolings.Octobot/Commands/PingCommandGroup.cs similarity index 96% rename from src/Commands/PingCommandGroup.cs rename to TeamOctolings.Octobot/Commands/PingCommandGroup.cs index d64c6dd..70b9f23 100644 --- a/src/Commands/PingCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/PingCommandGroup.cs @@ -1,8 +1,5 @@ using System.ComponentModel; using JetBrains.Annotations; -using Octobot.Data; -using Octobot.Extensions; -using Octobot.Services; using Remora.Commands.Attributes; using Remora.Commands.Groups; using Remora.Discord.API.Abstractions.Objects; @@ -15,8 +12,11 @@ using Remora.Discord.Extensions.Embeds; using Remora.Discord.Gateway; using Remora.Rest.Core; using Remora.Results; +using TeamOctolings.Octobot.Data; +using TeamOctolings.Octobot.Extensions; +using TeamOctolings.Octobot.Services; -namespace Octobot.Commands; +namespace TeamOctolings.Octobot.Commands; /// /// Handles the command to get the time taken for the gateway to respond to the last heartbeat: /ping diff --git a/src/Commands/RemindCommandGroup.cs b/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs similarity index 98% rename from src/Commands/RemindCommandGroup.cs rename to TeamOctolings.Octobot/Commands/RemindCommandGroup.cs index aa1ef7e..f40ba6b 100644 --- a/src/Commands/RemindCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs @@ -2,9 +2,6 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Text; using JetBrains.Annotations; -using Octobot.Data; -using Octobot.Extensions; -using Octobot.Services; using Remora.Commands.Attributes; using Remora.Commands.Groups; using Remora.Discord.API.Abstractions.Objects; @@ -17,9 +14,12 @@ using Remora.Discord.Extensions.Embeds; using Remora.Discord.Extensions.Formatting; using Remora.Rest.Core; using Remora.Results; -using Octobot.Parsers; +using TeamOctolings.Octobot.Data; +using TeamOctolings.Octobot.Extensions; +using TeamOctolings.Octobot.Parsers; +using TeamOctolings.Octobot.Services; -namespace Octobot.Commands; +namespace TeamOctolings.Octobot.Commands; /// /// Handles commands to manage reminders: /remind, /listremind, /delremind diff --git a/src/Commands/SettingsCommandGroup.cs b/TeamOctolings.Octobot/Commands/SettingsCommandGroup.cs similarity index 96% rename from src/Commands/SettingsCommandGroup.cs rename to TeamOctolings.Octobot/Commands/SettingsCommandGroup.cs index a39e9c7..56584bf 100644 --- a/src/Commands/SettingsCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/SettingsCommandGroup.cs @@ -3,10 +3,6 @@ using System.ComponentModel.DataAnnotations; using System.Text; using System.Text.Json.Nodes; using JetBrains.Annotations; -using Octobot.Data; -using Octobot.Data.Options; -using Octobot.Extensions; -using Octobot.Services; using Remora.Commands.Attributes; using Remora.Commands.Groups; using Remora.Discord.API.Abstractions.Objects; @@ -19,8 +15,12 @@ using Remora.Discord.Extensions.Embeds; using Remora.Discord.Extensions.Formatting; using Remora.Rest.Core; using Remora.Results; +using TeamOctolings.Octobot.Data; +using TeamOctolings.Octobot.Data.Options; +using TeamOctolings.Octobot.Extensions; +using TeamOctolings.Octobot.Services; -namespace Octobot.Commands; +namespace TeamOctolings.Octobot.Commands; /// /// Handles the commands to list and modify per-guild settings: /settings and /settings list. @@ -29,13 +29,13 @@ namespace Octobot.Commands; public class SettingsCommandGroup : CommandGroup { /// - /// Represents all options as an array of objects implementing . + /// Represents all options as an array of objects implementing . /// /// /// WARNING: If you update this array in any way, you must also update and make sure /// that the orders match. /// - private static readonly IOption[] AllOptions = + private static readonly IGuildOption[] AllOptions = [ GuildSettings.Language, GuildSettings.WelcomeMessage, @@ -199,7 +199,7 @@ public class SettingsCommandGroup : CommandGroup } private async Task EditSettingAsync( - IOption option, string value, GuildData data, Snowflake channelId, IUser executor, IUser bot, + IGuildOption option, string value, GuildData data, Snowflake channelId, IUser executor, IUser bot, CancellationToken ct = default) { var setResult = option.Set(data.Settings, value); @@ -270,7 +270,7 @@ public class SettingsCommandGroup : CommandGroup } private async Task ResetSingleSettingAsync(JsonNode cfg, IUser bot, - IOption option, CancellationToken ct = default) + IGuildOption option, CancellationToken ct = default) { var resetResult = option.Reset(cfg); if (!resetResult.IsSuccess) diff --git a/src/Commands/ToolsCommandGroup.cs b/TeamOctolings.Octobot/Commands/ToolsCommandGroup.cs similarity index 99% rename from src/Commands/ToolsCommandGroup.cs rename to TeamOctolings.Octobot/Commands/ToolsCommandGroup.cs index d4f3f75..3e84527 100644 --- a/src/Commands/ToolsCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/ToolsCommandGroup.cs @@ -2,10 +2,6 @@ using System.ComponentModel; using System.Drawing; using System.Text; using JetBrains.Annotations; -using Octobot.Data; -using Octobot.Extensions; -using Octobot.Parsers; -using Octobot.Services; using Remora.Commands.Attributes; using Remora.Commands.Groups; using Remora.Discord.API.Abstractions.Objects; @@ -17,8 +13,12 @@ using Remora.Discord.Extensions.Embeds; using Remora.Discord.Extensions.Formatting; using Remora.Rest.Core; using Remora.Results; +using TeamOctolings.Octobot.Data; +using TeamOctolings.Octobot.Extensions; +using TeamOctolings.Octobot.Parsers; +using TeamOctolings.Octobot.Services; -namespace Octobot.Commands; +namespace TeamOctolings.Octobot.Commands; /// /// Handles tool commands: /userinfo, /guildinfo, /random, /timestamp, /8ball. diff --git a/src/Data/GuildData.cs b/TeamOctolings.Octobot/Data/GuildData.cs similarity index 97% rename from src/Data/GuildData.cs rename to TeamOctolings.Octobot/Data/GuildData.cs index 5a903d6..f393323 100644 --- a/src/Data/GuildData.cs +++ b/TeamOctolings.Octobot/Data/GuildData.cs @@ -1,7 +1,7 @@ using System.Text.Json.Nodes; using Remora.Rest.Core; -namespace Octobot.Data; +namespace TeamOctolings.Octobot.Data; /// /// Stores information about a guild. This information is not accessible via the Discord API. diff --git a/src/Data/GuildSettings.cs b/TeamOctolings.Octobot/Data/GuildSettings.cs similarity index 92% rename from src/Data/GuildSettings.cs rename to TeamOctolings.Octobot/Data/GuildSettings.cs index a1d8d74..dc59d6f 100644 --- a/src/Data/GuildSettings.cs +++ b/TeamOctolings.Octobot/Data/GuildSettings.cs @@ -1,8 +1,8 @@ -using Octobot.Data.Options; -using Octobot.Responders; using Remora.Discord.API.Abstractions.Objects; +using TeamOctolings.Octobot.Data.Options; +using TeamOctolings.Octobot.Responders; -namespace Octobot.Data; +namespace TeamOctolings.Octobot.Data; /// /// Contains all per-guild settings that can be set by a member @@ -22,7 +22,7 @@ public static class GuildSettings /// /// /// - public static readonly Option WelcomeMessage = new("WelcomeMessage", "default"); + public static readonly GuildOption WelcomeMessage = new("WelcomeMessage", "default"); /// /// Controls what message should be sent in when a member leaves the guild. @@ -34,7 +34,7 @@ public static class GuildSettings /// /// /// - public static readonly Option LeaveMessage = new("LeaveMessage", "default"); + public static readonly GuildOption LeaveMessage = new("LeaveMessage", "default"); /// /// Controls whether or not the message should be sent diff --git a/src/Data/MemberData.cs b/TeamOctolings.Octobot/Data/MemberData.cs similarity index 93% rename from src/Data/MemberData.cs rename to TeamOctolings.Octobot/Data/MemberData.cs index 1b3d0d9..984d4af 100644 --- a/src/Data/MemberData.cs +++ b/TeamOctolings.Octobot/Data/MemberData.cs @@ -1,4 +1,4 @@ -namespace Octobot.Data; +namespace TeamOctolings.Octobot.Data; /// /// Stores information about a member diff --git a/src/Data/Options/AllOptionsEnum.cs b/TeamOctolings.Octobot/Data/Options/AllOptionsEnum.cs similarity index 92% rename from src/Data/Options/AllOptionsEnum.cs rename to TeamOctolings.Octobot/Data/Options/AllOptionsEnum.cs index d9e0c13..6a4280e 100644 --- a/src/Data/Options/AllOptionsEnum.cs +++ b/TeamOctolings.Octobot/Data/Options/AllOptionsEnum.cs @@ -1,7 +1,7 @@ using JetBrains.Annotations; -using Octobot.Commands; +using TeamOctolings.Octobot.Commands; -namespace Octobot.Data.Options; +namespace TeamOctolings.Octobot.Data.Options; /// /// Represents all options as enums. diff --git a/src/Data/Options/BoolOption.cs b/TeamOctolings.Octobot/Data/Options/BoolOption.cs similarity index 91% rename from src/Data/Options/BoolOption.cs rename to TeamOctolings.Octobot/Data/Options/BoolOption.cs index 6876164..6a3c899 100644 --- a/src/Data/Options/BoolOption.cs +++ b/TeamOctolings.Octobot/Data/Options/BoolOption.cs @@ -1,9 +1,9 @@ using System.Text.Json.Nodes; using Remora.Results; -namespace Octobot.Data.Options; +namespace TeamOctolings.Octobot.Data.Options; -public sealed class BoolOption : Option +public sealed class BoolOption : GuildOption { public BoolOption(string name, bool defaultValue) : base(name, defaultValue) { } diff --git a/src/Data/Options/Option.cs b/TeamOctolings.Octobot/Data/Options/GuildOption.cs similarity index 90% rename from src/Data/Options/Option.cs rename to TeamOctolings.Octobot/Data/Options/GuildOption.cs index 5d703a8..5d9f1a2 100644 --- a/src/Data/Options/Option.cs +++ b/TeamOctolings.Octobot/Data/Options/GuildOption.cs @@ -2,18 +2,18 @@ using System.Text.Json.Nodes; using Remora.Discord.Extensions.Formatting; using Remora.Results; -namespace Octobot.Data.Options; +namespace TeamOctolings.Octobot.Data.Options; /// -/// Represents an per-guild option. +/// Represents a per-guild option. /// /// The type of the option. -public class Option : IOption +public class GuildOption : IGuildOption where T : notnull { protected readonly T DefaultValue; - public Option(string name, T defaultValue) + public GuildOption(string name, T defaultValue) { Name = name; DefaultValue = defaultValue; diff --git a/src/Data/Options/IOption.cs b/TeamOctolings.Octobot/Data/Options/IGuildOption.cs similarity index 73% rename from src/Data/Options/IOption.cs rename to TeamOctolings.Octobot/Data/Options/IGuildOption.cs index b8ed03c..a8c3e6e 100644 --- a/src/Data/Options/IOption.cs +++ b/TeamOctolings.Octobot/Data/Options/IGuildOption.cs @@ -1,9 +1,9 @@ using System.Text.Json.Nodes; using Remora.Results; -namespace Octobot.Data.Options; +namespace TeamOctolings.Octobot.Data.Options; -public interface IOption +public interface IGuildOption { string Name { get; } string Display(JsonNode settings); diff --git a/src/Data/Options/LanguageOption.cs b/TeamOctolings.Octobot/Data/Options/LanguageOption.cs similarity index 91% rename from src/Data/Options/LanguageOption.cs rename to TeamOctolings.Octobot/Data/Options/LanguageOption.cs index 22f98df..15ab6ff 100644 --- a/src/Data/Options/LanguageOption.cs +++ b/TeamOctolings.Octobot/Data/Options/LanguageOption.cs @@ -3,10 +3,10 @@ using System.Text.Json.Nodes; using Remora.Discord.Extensions.Formatting; using Remora.Results; -namespace Octobot.Data.Options; +namespace TeamOctolings.Octobot.Data.Options; /// -public sealed class LanguageOption : Option +public sealed class LanguageOption : GuildOption { private static readonly Dictionary CultureInfoCache = new() { diff --git a/src/Data/Options/SnowflakeOption.cs b/TeamOctolings.Octobot/Data/Options/SnowflakeOption.cs similarity index 87% rename from src/Data/Options/SnowflakeOption.cs rename to TeamOctolings.Octobot/Data/Options/SnowflakeOption.cs index 7118da8..b7405f2 100644 --- a/src/Data/Options/SnowflakeOption.cs +++ b/TeamOctolings.Octobot/Data/Options/SnowflakeOption.cs @@ -1,13 +1,13 @@ using System.Text.Json.Nodes; using System.Text.RegularExpressions; -using Octobot.Extensions; using Remora.Discord.Extensions.Formatting; using Remora.Rest.Core; using Remora.Results; +using TeamOctolings.Octobot.Extensions; -namespace Octobot.Data.Options; +namespace TeamOctolings.Octobot.Data.Options; -public sealed partial class SnowflakeOption : Option +public sealed partial class SnowflakeOption : GuildOption { public SnowflakeOption(string name) : base(name, 0UL.ToSnowflake()) { } diff --git a/src/Data/Options/TimeSpanOption.cs b/TeamOctolings.Octobot/Data/Options/TimeSpanOption.cs similarity index 82% rename from src/Data/Options/TimeSpanOption.cs rename to TeamOctolings.Octobot/Data/Options/TimeSpanOption.cs index d237b6e..3501f09 100644 --- a/src/Data/Options/TimeSpanOption.cs +++ b/TeamOctolings.Octobot/Data/Options/TimeSpanOption.cs @@ -1,10 +1,10 @@ using System.Text.Json.Nodes; -using Octobot.Parsers; using Remora.Results; +using TeamOctolings.Octobot.Parsers; -namespace Octobot.Data.Options; +namespace TeamOctolings.Octobot.Data.Options; -public sealed class TimeSpanOption : Option +public sealed class TimeSpanOption : GuildOption { public TimeSpanOption(string name, TimeSpan defaultValue) : base(name, defaultValue) { } diff --git a/src/Data/Reminder.cs b/TeamOctolings.Octobot/Data/Reminder.cs similarity index 83% rename from src/Data/Reminder.cs rename to TeamOctolings.Octobot/Data/Reminder.cs index f21b222..c3936da 100644 --- a/src/Data/Reminder.cs +++ b/TeamOctolings.Octobot/Data/Reminder.cs @@ -1,4 +1,4 @@ -namespace Octobot.Data; +namespace TeamOctolings.Octobot.Data; public struct Reminder { diff --git a/src/Data/ScheduledEventData.cs b/TeamOctolings.Octobot/Data/ScheduledEventData.cs similarity index 97% rename from src/Data/ScheduledEventData.cs rename to TeamOctolings.Octobot/Data/ScheduledEventData.cs index 59efc63..7ba6e92 100644 --- a/src/Data/ScheduledEventData.cs +++ b/TeamOctolings.Octobot/Data/ScheduledEventData.cs @@ -1,7 +1,7 @@ using System.Text.Json.Serialization; using Remora.Discord.API.Abstractions.Objects; -namespace Octobot.Data; +namespace TeamOctolings.Octobot.Data; /// /// Stores information about scheduled events. This information is not provided by the Discord API. diff --git a/src/Extensions/ChannelApiExtensions.cs b/TeamOctolings.Octobot/Extensions/ChannelApiExtensions.cs similarity index 96% rename from src/Extensions/ChannelApiExtensions.cs rename to TeamOctolings.Octobot/Extensions/ChannelApiExtensions.cs index 99eff67..2767f96 100644 --- a/src/Extensions/ChannelApiExtensions.cs +++ b/TeamOctolings.Octobot/Extensions/ChannelApiExtensions.cs @@ -5,7 +5,7 @@ using Remora.Discord.API.Objects; using Remora.Rest.Core; using Remora.Results; -namespace Octobot.Extensions; +namespace TeamOctolings.Octobot.Extensions; public static class ChannelApiExtensions { diff --git a/src/Extensions/CollectionExtensions.cs b/TeamOctolings.Octobot/Extensions/CollectionExtensions.cs similarity index 96% rename from src/Extensions/CollectionExtensions.cs rename to TeamOctolings.Octobot/Extensions/CollectionExtensions.cs index 2369532..3ea13a8 100644 --- a/src/Extensions/CollectionExtensions.cs +++ b/TeamOctolings.Octobot/Extensions/CollectionExtensions.cs @@ -1,6 +1,6 @@ using Remora.Results; -namespace Octobot.Extensions; +namespace TeamOctolings.Octobot.Extensions; public static class CollectionExtensions { diff --git a/src/Extensions/CommandContextExtensions.cs b/TeamOctolings.Octobot/Extensions/CommandContextExtensions.cs similarity index 92% rename from src/Extensions/CommandContextExtensions.cs rename to TeamOctolings.Octobot/Extensions/CommandContextExtensions.cs index a0c02f2..16b8b56 100644 --- a/src/Extensions/CommandContextExtensions.cs +++ b/TeamOctolings.Octobot/Extensions/CommandContextExtensions.cs @@ -2,7 +2,7 @@ using Remora.Discord.Commands.Extensions; using Remora.Rest.Core; -namespace Octobot.Extensions; +namespace TeamOctolings.Octobot.Extensions; public static class CommandContextExtensions { diff --git a/src/Extensions/DiffPaneModelExtensions.cs b/TeamOctolings.Octobot/Extensions/DiffPaneModelExtensions.cs similarity index 94% rename from src/Extensions/DiffPaneModelExtensions.cs rename to TeamOctolings.Octobot/Extensions/DiffPaneModelExtensions.cs index 1c3a098..3bb707b 100644 --- a/src/Extensions/DiffPaneModelExtensions.cs +++ b/TeamOctolings.Octobot/Extensions/DiffPaneModelExtensions.cs @@ -1,7 +1,7 @@ using System.Text; using DiffPlex.DiffBuilder.Model; -namespace Octobot.Extensions; +namespace TeamOctolings.Octobot.Extensions; public static class DiffPaneModelExtensions { diff --git a/src/Extensions/EmbedBuilderExtensions.cs b/TeamOctolings.Octobot/Extensions/EmbedBuilderExtensions.cs similarity index 99% rename from src/Extensions/EmbedBuilderExtensions.cs rename to TeamOctolings.Octobot/Extensions/EmbedBuilderExtensions.cs index 2d61403..dab0265 100644 --- a/src/Extensions/EmbedBuilderExtensions.cs +++ b/TeamOctolings.Octobot/Extensions/EmbedBuilderExtensions.cs @@ -4,7 +4,7 @@ using Remora.Discord.API.Objects; using Remora.Discord.Extensions.Embeds; using Remora.Rest.Core; -namespace Octobot.Extensions; +namespace TeamOctolings.Octobot.Extensions; public static class EmbedBuilderExtensions { diff --git a/src/Extensions/FeedbackServiceExtensions.cs b/TeamOctolings.Octobot/Extensions/FeedbackServiceExtensions.cs similarity index 93% rename from src/Extensions/FeedbackServiceExtensions.cs rename to TeamOctolings.Octobot/Extensions/FeedbackServiceExtensions.cs index e6ef376..c66c946 100644 --- a/src/Extensions/FeedbackServiceExtensions.cs +++ b/TeamOctolings.Octobot/Extensions/FeedbackServiceExtensions.cs @@ -3,7 +3,7 @@ using Remora.Discord.Commands.Feedback.Messages; using Remora.Discord.Commands.Feedback.Services; using Remora.Results; -namespace Octobot.Extensions; +namespace TeamOctolings.Octobot.Extensions; public static class FeedbackServiceExtensions { diff --git a/src/Extensions/GuildScheduledEventExtensions.cs b/TeamOctolings.Octobot/Extensions/GuildScheduledEventExtensions.cs similarity index 95% rename from src/Extensions/GuildScheduledEventExtensions.cs rename to TeamOctolings.Octobot/Extensions/GuildScheduledEventExtensions.cs index f1b6985..b8eb2d1 100644 --- a/src/Extensions/GuildScheduledEventExtensions.cs +++ b/TeamOctolings.Octobot/Extensions/GuildScheduledEventExtensions.cs @@ -2,7 +2,7 @@ using Remora.Rest.Core; using Remora.Results; -namespace Octobot.Extensions; +namespace TeamOctolings.Octobot.Extensions; public static class GuildScheduledEventExtensions { diff --git a/src/Extensions/LoggerExtensions.cs b/TeamOctolings.Octobot/Extensions/LoggerExtensions.cs similarity index 96% rename from src/Extensions/LoggerExtensions.cs rename to TeamOctolings.Octobot/Extensions/LoggerExtensions.cs index fca3702..76fa386 100644 --- a/src/Extensions/LoggerExtensions.cs +++ b/TeamOctolings.Octobot/Extensions/LoggerExtensions.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.Logging; using Remora.Results; -namespace Octobot.Extensions; +namespace TeamOctolings.Octobot.Extensions; public static class LoggerExtensions { diff --git a/src/Extensions/MarkdownExtensions.cs b/TeamOctolings.Octobot/Extensions/MarkdownExtensions.cs similarity index 88% rename from src/Extensions/MarkdownExtensions.cs rename to TeamOctolings.Octobot/Extensions/MarkdownExtensions.cs index 7b7f780..202cd37 100644 --- a/src/Extensions/MarkdownExtensions.cs +++ b/TeamOctolings.Octobot/Extensions/MarkdownExtensions.cs @@ -1,4 +1,4 @@ -namespace Octobot.Extensions; +namespace TeamOctolings.Octobot.Extensions; public static class MarkdownExtensions { diff --git a/src/Extensions/ResultExtensions.cs b/TeamOctolings.Octobot/Extensions/ResultExtensions.cs similarity index 82% rename from src/Extensions/ResultExtensions.cs rename to TeamOctolings.Octobot/Extensions/ResultExtensions.cs index a95a1e2..d7ef7d7 100644 --- a/src/Extensions/ResultExtensions.cs +++ b/TeamOctolings.Octobot/Extensions/ResultExtensions.cs @@ -2,7 +2,7 @@ using Microsoft.Extensions.Logging; using Remora.Results; -namespace Octobot.Extensions; +namespace TeamOctolings.Octobot.Extensions; public static class ResultExtensions { @@ -23,18 +23,23 @@ public static class ResultExtensions private static void LogResultStackTrace(Result result) { - if (Octobot.StaticLogger is null || result.IsSuccess) + if (result.IsSuccess) { return; } - Octobot.StaticLogger.LogError("{ErrorType}: {ErrorMessage}{NewLine}{StackTrace}", + if (Utility.StaticLogger is null) + { + throw new InvalidOperationException(); + } + + Utility.StaticLogger.LogError("{ErrorType}: {ErrorMessage}{NewLine}{StackTrace}", result.Error.GetType().FullName, result.Error.Message, Environment.NewLine, ConstructStackTrace()); var inner = result.Inner; while (inner is { IsSuccess: false }) { - Octobot.StaticLogger.LogError("Caused by: {ResultType}: {ResultMessage}", + Utility.StaticLogger.LogError("Caused by: {ResultType}: {ResultMessage}", inner.Error.GetType().FullName, inner.Error.Message); inner = inner.Inner; diff --git a/src/Extensions/SnowflakeExtensions.cs b/TeamOctolings.Octobot/Extensions/SnowflakeExtensions.cs similarity index 96% rename from src/Extensions/SnowflakeExtensions.cs rename to TeamOctolings.Octobot/Extensions/SnowflakeExtensions.cs index e60bc44..70810ef 100644 --- a/src/Extensions/SnowflakeExtensions.cs +++ b/TeamOctolings.Octobot/Extensions/SnowflakeExtensions.cs @@ -1,6 +1,6 @@ using Remora.Rest.Core; -namespace Octobot.Extensions; +namespace TeamOctolings.Octobot.Extensions; public static class SnowflakeExtensions { diff --git a/src/Extensions/StringBuilderExtensions.cs b/TeamOctolings.Octobot/Extensions/StringBuilderExtensions.cs similarity index 98% rename from src/Extensions/StringBuilderExtensions.cs rename to TeamOctolings.Octobot/Extensions/StringBuilderExtensions.cs index ddd24a3..25b7b5b 100644 --- a/src/Extensions/StringBuilderExtensions.cs +++ b/TeamOctolings.Octobot/Extensions/StringBuilderExtensions.cs @@ -1,6 +1,6 @@ using System.Text; -namespace Octobot.Extensions; +namespace TeamOctolings.Octobot.Extensions; public static class StringBuilderExtensions { diff --git a/src/Extensions/StringExtensions.cs b/TeamOctolings.Octobot/Extensions/StringExtensions.cs similarity index 98% rename from src/Extensions/StringExtensions.cs rename to TeamOctolings.Octobot/Extensions/StringExtensions.cs index cb8d606..bf7f6c8 100644 --- a/src/Extensions/StringExtensions.cs +++ b/TeamOctolings.Octobot/Extensions/StringExtensions.cs @@ -1,7 +1,7 @@ using System.Net; using Remora.Discord.Extensions.Formatting; -namespace Octobot.Extensions; +namespace TeamOctolings.Octobot.Extensions; public static class StringExtensions { diff --git a/src/Extensions/UInt64Extensions.cs b/TeamOctolings.Octobot/Extensions/UInt64Extensions.cs similarity index 82% rename from src/Extensions/UInt64Extensions.cs rename to TeamOctolings.Octobot/Extensions/UInt64Extensions.cs index 5d1db00..2b9c0a2 100644 --- a/src/Extensions/UInt64Extensions.cs +++ b/TeamOctolings.Octobot/Extensions/UInt64Extensions.cs @@ -1,7 +1,7 @@ using Remora.Discord.API; using Remora.Rest.Core; -namespace Octobot.Extensions; +namespace TeamOctolings.Octobot.Extensions; public static class UInt64Extensions { diff --git a/src/Extensions/UserExtensions.cs b/TeamOctolings.Octobot/Extensions/UserExtensions.cs similarity index 85% rename from src/Extensions/UserExtensions.cs rename to TeamOctolings.Octobot/Extensions/UserExtensions.cs index 38fe985..d9eff33 100644 --- a/src/Extensions/UserExtensions.cs +++ b/TeamOctolings.Octobot/Extensions/UserExtensions.cs @@ -1,6 +1,6 @@ using Remora.Discord.API.Abstractions.Objects; -namespace Octobot.Extensions; +namespace TeamOctolings.Octobot.Extensions; public static class UserExtensions { diff --git a/src/Messages.Designer.cs b/TeamOctolings.Octobot/Messages.Designer.cs similarity index 89% rename from src/Messages.Designer.cs rename to TeamOctolings.Octobot/Messages.Designer.cs index 2910bae..bbc1366 100644 --- a/src/Messages.Designer.cs +++ b/TeamOctolings.Octobot/Messages.Designer.cs @@ -7,31 +7,34 @@ // //------------------------------------------------------------------------------ -namespace Octobot { +namespace TeamOctolings.Octobot { + using System; + + [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [System.Diagnostics.DebuggerNonUserCodeAttribute()] [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Messages { - + private static System.Resources.ResourceManager resourceMan; - + private static System.Globalization.CultureInfo resourceCulture; - + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Messages() { } - + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] internal static System.Resources.ResourceManager ResourceManager { get { if (object.Equals(null, resourceMan)) { - System.Resources.ResourceManager temp = new System.Resources.ResourceManager("Octobot.locale.Messages", typeof(Messages).Assembly); + System.Resources.ResourceManager temp = new System.Resources.ResourceManager("TeamOctolings.Octobot.Messages", typeof(Messages).Assembly); resourceMan = temp; } return resourceMan; } } - + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] internal static System.Globalization.CultureInfo Culture { get { @@ -41,1180 +44,1157 @@ namespace Octobot { resourceCulture = value; } } - + internal static string Ready { get { return ResourceManager.GetString("Ready", resourceCulture); } } - + internal static string CachedMessageDeleted { get { return ResourceManager.GetString("CachedMessageDeleted", resourceCulture); } } - + internal static string CachedMessageEdited { get { return ResourceManager.GetString("CachedMessageEdited", resourceCulture); } } - + internal static string DefaultWelcomeMessage { get { return ResourceManager.GetString("DefaultWelcomeMessage", resourceCulture); } } - + internal static string Generic1 { get { return ResourceManager.GetString("Generic1", resourceCulture); } } - + internal static string Generic2 { get { return ResourceManager.GetString("Generic2", resourceCulture); } } - + internal static string Generic3 { get { return ResourceManager.GetString("Generic3", resourceCulture); } } - + internal static string YouWereBanned { get { return ResourceManager.GetString("YouWereBanned", resourceCulture); } } - + internal static string PunishmentExpired { get { return ResourceManager.GetString("PunishmentExpired", resourceCulture); } } - + internal static string YouWereKicked { get { return ResourceManager.GetString("YouWereKicked", resourceCulture); } } - + internal static string Milliseconds { get { return ResourceManager.GetString("Milliseconds", resourceCulture); } } - + internal static string ChannelNotSpecified { get { return ResourceManager.GetString("ChannelNotSpecified", resourceCulture); } } - + internal static string RoleNotSpecified { get { return ResourceManager.GetString("RoleNotSpecified", resourceCulture); } } - - internal static string SettingsLang { + + internal static string SettingsLanguage { get { - return ResourceManager.GetString("SettingsLang", resourceCulture); + return ResourceManager.GetString("SettingsLanguage", resourceCulture); } } - + internal static string SettingsPrefix { get { return ResourceManager.GetString("SettingsPrefix", resourceCulture); } } - + internal static string SettingsRemoveRolesOnMute { get { return ResourceManager.GetString("SettingsRemoveRolesOnMute", resourceCulture); } } - + internal static string SettingsSendWelcomeMessages { get { return ResourceManager.GetString("SettingsSendWelcomeMessages", resourceCulture); } } - + internal static string SettingsMuteRole { get { return ResourceManager.GetString("SettingsMuteRole", resourceCulture); } } - + internal static string LanguageNotSupported { get { return ResourceManager.GetString("LanguageNotSupported", resourceCulture); } } - + internal static string Yes { get { return ResourceManager.GetString("Yes", resourceCulture); } } - + internal static string No { get { return ResourceManager.GetString("No", resourceCulture); } } - + internal static string UserNotBanned { get { return ResourceManager.GetString("UserNotBanned", resourceCulture); } } - + internal static string MemberNotMuted { get { return ResourceManager.GetString("MemberNotMuted", resourceCulture); } } - + internal static string SettingsWelcomeMessage { get { return ResourceManager.GetString("SettingsWelcomeMessage", resourceCulture); } } - + internal static string UserBanned { get { return ResourceManager.GetString("UserBanned", resourceCulture); } } - + internal static string SettingsReceiveStartupMessages { get { return ResourceManager.GetString("SettingsReceiveStartupMessages", resourceCulture); } } - + internal static string InvalidSettingValue { get { return ResourceManager.GetString("InvalidSettingValue", resourceCulture); } } - - internal static string InvalidRole { - get { - return ResourceManager.GetString("InvalidRole", resourceCulture); - } - } - - internal static string InvalidChannel { - get { - return ResourceManager.GetString("InvalidChannel", resourceCulture); - } - } - + internal static string DurationRequiredForTimeOuts { get { return ResourceManager.GetString("DurationRequiredForTimeOuts", resourceCulture); } } - + internal static string CannotTimeOutBot { get { return ResourceManager.GetString("CannotTimeOutBot", resourceCulture); } } - + internal static string SettingsEventNotificationRole { get { return ResourceManager.GetString("SettingsEventNotificationRole", resourceCulture); } } - + internal static string SettingsEventNotificationChannel { get { return ResourceManager.GetString("SettingsEventNotificationChannel", resourceCulture); } } - + internal static string SettingsEventStartedReceivers { get { return ResourceManager.GetString("SettingsEventStartedReceivers", resourceCulture); } } - + internal static string EventStarted { get { return ResourceManager.GetString("EventStarted", resourceCulture); } } - + internal static string EventCancelled { get { return ResourceManager.GetString("EventCancelled", resourceCulture); } } - + internal static string EventCompleted { get { return ResourceManager.GetString("EventCompleted", resourceCulture); } } - + internal static string MessagesCleared { get { return ResourceManager.GetString("MessagesCleared", resourceCulture); } } - + internal static string SettingsNothingChanged { get { return ResourceManager.GetString("SettingsNothingChanged", resourceCulture); } } - + internal static string SettingNotDefined { get { return ResourceManager.GetString("SettingNotDefined", resourceCulture); } } - + + internal static string MissingUser { + get { + return ResourceManager.GetString("MissingUser", resourceCulture); + } + } + internal static string UserCannotBanMembers { get { return ResourceManager.GetString("UserCannotBanMembers", resourceCulture); } } - + internal static string UserCannotManageMessages { get { return ResourceManager.GetString("UserCannotManageMessages", resourceCulture); } } - + internal static string UserCannotKickMembers { get { return ResourceManager.GetString("UserCannotKickMembers", resourceCulture); } } - - internal static string UserCannotModerateMembers { + + internal static string UserCannotMuteMembers { get { - return ResourceManager.GetString("UserCannotModerateMembers", resourceCulture); + return ResourceManager.GetString("UserCannotMuteMembers", resourceCulture); } } - + + internal static string UserCannotUnmuteMembers { + get { + return ResourceManager.GetString("UserCannotUnmuteMembers", resourceCulture); + } + } + internal static string UserCannotManageGuild { get { return ResourceManager.GetString("UserCannotManageGuild", resourceCulture); } } - + internal static string BotCannotBanMembers { get { return ResourceManager.GetString("BotCannotBanMembers", resourceCulture); } } - + internal static string BotCannotManageMessages { get { return ResourceManager.GetString("BotCannotManageMessages", resourceCulture); } } - + internal static string BotCannotKickMembers { get { return ResourceManager.GetString("BotCannotKickMembers", resourceCulture); } } - + internal static string BotCannotModerateMembers { get { return ResourceManager.GetString("BotCannotModerateMembers", resourceCulture); } } - + internal static string BotCannotManageGuild { get { return ResourceManager.GetString("BotCannotManageGuild", resourceCulture); } } - + internal static string UserCannotBanOwner { get { return ResourceManager.GetString("UserCannotBanOwner", resourceCulture); } } - + internal static string UserCannotBanThemselves { get { return ResourceManager.GetString("UserCannotBanThemselves", resourceCulture); } } - + internal static string UserCannotBanBot { get { return ResourceManager.GetString("UserCannotBanBot", resourceCulture); } } - + internal static string BotCannotBanTarget { get { return ResourceManager.GetString("BotCannotBanTarget", resourceCulture); } } - + internal static string UserCannotBanTarget { get { return ResourceManager.GetString("UserCannotBanTarget", resourceCulture); } } - + internal static string UserCannotKickOwner { get { return ResourceManager.GetString("UserCannotKickOwner", resourceCulture); } } - + internal static string UserCannotKickThemselves { get { return ResourceManager.GetString("UserCannotKickThemselves", resourceCulture); } } - + internal static string UserCannotKickBot { get { return ResourceManager.GetString("UserCannotKickBot", resourceCulture); } } - + internal static string BotCannotKickTarget { get { return ResourceManager.GetString("BotCannotKickTarget", resourceCulture); } } - + internal static string UserCannotKickTarget { get { return ResourceManager.GetString("UserCannotKickTarget", resourceCulture); } } - + internal static string UserCannotMuteOwner { get { return ResourceManager.GetString("UserCannotMuteOwner", resourceCulture); } } - + internal static string UserCannotMuteThemselves { get { return ResourceManager.GetString("UserCannotMuteThemselves", resourceCulture); } } - + internal static string UserCannotMuteBot { get { return ResourceManager.GetString("UserCannotMuteBot", resourceCulture); } } - + internal static string BotCannotMuteTarget { get { return ResourceManager.GetString("BotCannotMuteTarget", resourceCulture); } } - + internal static string UserCannotMuteTarget { get { return ResourceManager.GetString("UserCannotMuteTarget", resourceCulture); } } - + internal static string UserCannotUnmuteOwner { get { return ResourceManager.GetString("UserCannotUnmuteOwner", resourceCulture); } } - + internal static string UserCannotUnmuteThemselves { get { return ResourceManager.GetString("UserCannotUnmuteThemselves", resourceCulture); } } - + internal static string UserCannotUnmuteBot { get { return ResourceManager.GetString("UserCannotUnmuteBot", resourceCulture); } } - + internal static string BotCannotUnmuteTarget { get { return ResourceManager.GetString("BotCannotUnmuteTarget", resourceCulture); } } - + internal static string UserCannotUnmuteTarget { get { return ResourceManager.GetString("UserCannotUnmuteTarget", resourceCulture); } } - + internal static string EventEarlyNotification { get { return ResourceManager.GetString("EventEarlyNotification", resourceCulture); } } - + internal static string SettingsEventEarlyNotificationOffset { get { return ResourceManager.GetString("SettingsEventEarlyNotificationOffset", resourceCulture); } } - + internal static string UserNotFound { get { return ResourceManager.GetString("UserNotFound", resourceCulture); } } - + internal static string SettingsDefaultRole { get { return ResourceManager.GetString("SettingsDefaultRole", resourceCulture); } } - + internal static string SettingsPublicFeedbackChannel { get { return ResourceManager.GetString("SettingsPublicFeedbackChannel", resourceCulture); } } - + internal static string SettingsPrivateFeedbackChannel { get { return ResourceManager.GetString("SettingsPrivateFeedbackChannel", resourceCulture); } } - + internal static string SettingsReturnRolesOnRejoin { get { return ResourceManager.GetString("SettingsReturnRolesOnRejoin", resourceCulture); } } - + internal static string SettingsAutoStartEvents { get { return ResourceManager.GetString("SettingsAutoStartEvents", resourceCulture); } } - + internal static string IssuedBy { get { return ResourceManager.GetString("IssuedBy", resourceCulture); } } - + internal static string EventCreatedTitle { get { return ResourceManager.GetString("EventCreatedTitle", resourceCulture); } } - + internal static string DescriptionLocalEventCreated { get { return ResourceManager.GetString("DescriptionLocalEventCreated", resourceCulture); } } - + internal static string DescriptionExternalEventCreated { get { return ResourceManager.GetString("DescriptionExternalEventCreated", resourceCulture); } } - + internal static string ButtonOpenEventInfo { get { return ResourceManager.GetString("ButtonOpenEventInfo", resourceCulture); } } - + internal static string EventDuration { get { return ResourceManager.GetString("EventDuration", resourceCulture); } } - + internal static string DescriptionLocalEventStarted { get { return ResourceManager.GetString("DescriptionLocalEventStarted", resourceCulture); } } - + internal static string DescriptionExternalEventStarted { get { return ResourceManager.GetString("DescriptionExternalEventStarted", resourceCulture); } } - + internal static string UserAlreadyBanned { get { return ResourceManager.GetString("UserAlreadyBanned", resourceCulture); } } - + internal static string UserUnbanned { get { return ResourceManager.GetString("UserUnbanned", resourceCulture); } } - + internal static string UserMuted { get { return ResourceManager.GetString("UserMuted", resourceCulture); } } - + internal static string UserUnmuted { get { return ResourceManager.GetString("UserUnmuted", resourceCulture); } } - + internal static string UserNotMuted { get { return ResourceManager.GetString("UserNotMuted", resourceCulture); } } - + internal static string UserNotFoundShort { get { return ResourceManager.GetString("UserNotFoundShort", resourceCulture); } } - + internal static string UserKicked { get { return ResourceManager.GetString("UserKicked", resourceCulture); } } - + internal static string DescriptionActionReason { get { return ResourceManager.GetString("DescriptionActionReason", resourceCulture); } } - + internal static string DescriptionActionExpiresAt { get { return ResourceManager.GetString("DescriptionActionExpiresAt", resourceCulture); } } - + internal static string UserAlreadyMuted { get { return ResourceManager.GetString("UserAlreadyMuted", resourceCulture); } } - + internal static string MessageFrom { get { return ResourceManager.GetString("MessageFrom", resourceCulture); } } - + internal static string AboutTitleDevelopers { get { return ResourceManager.GetString("AboutTitleDevelopers", resourceCulture); } } - + internal static string ButtonOpenRepository { get { return ResourceManager.GetString("ButtonOpenRepository", resourceCulture); } } - + internal static string AboutBot { get { return ResourceManager.GetString("AboutBot", resourceCulture); } } - + internal static string AboutDeveloper_mctaylors { get { return ResourceManager.GetString("AboutDeveloper@mctaylors", resourceCulture); } } - + internal static string AboutDeveloper_Octol1ttle { get { return ResourceManager.GetString("AboutDeveloper@Octol1ttle", resourceCulture); } } - + internal static string AboutDeveloper_neroduckale { get { return ResourceManager.GetString("AboutDeveloper@neroduckale", resourceCulture); } } - + internal static string ReminderCreated { get { return ResourceManager.GetString("ReminderCreated", resourceCulture); } } - + internal static string Reminder { get { return ResourceManager.GetString("Reminder", resourceCulture); } } - + internal static string DescriptionReminder { get { return ResourceManager.GetString("DescriptionReminder", resourceCulture); } } - + internal static string SettingsListTitle { get { return ResourceManager.GetString("SettingsListTitle", resourceCulture); } } - + internal static string SettingSuccessfullyChanged { get { return ResourceManager.GetString("SettingSuccessfullyChanged", resourceCulture); } } - + internal static string SettingNotChanged { get { return ResourceManager.GetString("SettingNotChanged", resourceCulture); } } - + internal static string SettingIsNow { get { return ResourceManager.GetString("SettingIsNow", resourceCulture); } } - + + internal static string SettingsRenameHoistedUsers { + get { + return ResourceManager.GetString("SettingsRenameHoistedUsers", resourceCulture); + } + } + internal static string Page { get { return ResourceManager.GetString("Page", resourceCulture); } } - + internal static string PageNotFound { get { return ResourceManager.GetString("PageNotFound", resourceCulture); } } - + internal static string PagesAllowed { get { return ResourceManager.GetString("PagesAllowed", resourceCulture); } } - + internal static string Next { get { return ResourceManager.GetString("Next", resourceCulture); } } - + internal static string Previous { get { return ResourceManager.GetString("Previous", resourceCulture); } } - + internal static string ReminderList { get { return ResourceManager.GetString("ReminderList", resourceCulture); } } - + internal static string InvalidReminderPosition { get { return ResourceManager.GetString("InvalidReminderPosition", resourceCulture); } } - + internal static string ReminderDeleted { get { return ResourceManager.GetString("ReminderDeleted", resourceCulture); } } - + internal static string NoRemindersFound { get { return ResourceManager.GetString("NoRemindersFound", resourceCulture); } } - + internal static string SingleSettingReset { get { return ResourceManager.GetString("SingleSettingReset", resourceCulture); } } - + internal static string AllSettingsReset { get { return ResourceManager.GetString("AllSettingsReset", resourceCulture); } } - + internal static string DescriptionActionJumpToMessage { get { return ResourceManager.GetString("DescriptionActionJumpToMessage", resourceCulture); } } - + internal static string DescriptionActionJumpToChannel { get { return ResourceManager.GetString("DescriptionActionJumpToChannel", resourceCulture); } } - + internal static string ReminderPosition { get { return ResourceManager.GetString("ReminderPosition", resourceCulture); } } - + internal static string ReminderTime { get { return ResourceManager.GetString("ReminderTime", resourceCulture); } } - + internal static string ReminderText { get { return ResourceManager.GetString("ReminderText", resourceCulture); } } - - internal static string InformationAbout { - get { - return ResourceManager.GetString("InformationAbout", resourceCulture); - } - } - + internal static string UserInfoDisplayName { get { return ResourceManager.GetString("UserInfoDisplayName", resourceCulture); } } - - internal static string UserInfoDiscordUserSince { + + internal static string InformationAbout { get { - return ResourceManager.GetString("UserInfoDiscordUserSince", resourceCulture); + return ResourceManager.GetString("InformationAbout", resourceCulture); } } - + internal static string UserInfoMuted { get { return ResourceManager.GetString("UserInfoMuted", resourceCulture); } } - + + internal static string UserInfoDiscordUserSince { + get { + return ResourceManager.GetString("UserInfoDiscordUserSince", resourceCulture); + } + } + internal static string UserInfoBanned { get { return ResourceManager.GetString("UserInfoBanned", resourceCulture); } } - + internal static string UserInfoPunishments { get { return ResourceManager.GetString("UserInfoPunishments", resourceCulture); } } - + internal static string UserInfoBannedPermanently { get { return ResourceManager.GetString("UserInfoBannedPermanently", resourceCulture); } } - + internal static string UserInfoNotOnGuild { get { return ResourceManager.GetString("UserInfoNotOnGuild", resourceCulture); } } - + internal static string UserInfoMutedByTimeout { get { return ResourceManager.GetString("UserInfoMutedByTimeout", resourceCulture); } } - + internal static string UserInfoMutedByMuteRole { get { return ResourceManager.GetString("UserInfoMutedByMuteRole", resourceCulture); } } - + internal static string UserInfoGuildMemberSince { get { return ResourceManager.GetString("UserInfoGuildMemberSince", resourceCulture); } } - + internal static string UserInfoGuildNickname { get { return ResourceManager.GetString("UserInfoGuildNickname", resourceCulture); } } - + internal static string UserInfoGuildRoles { get { return ResourceManager.GetString("UserInfoGuildRoles", resourceCulture); } } - + internal static string UserInfoGuildMemberPremiumSince { get { return ResourceManager.GetString("UserInfoGuildMemberPremiumSince", resourceCulture); } } - - internal static string RandomTitle - { + + internal static string RandomTitle { get { return ResourceManager.GetString("RandomTitle", resourceCulture); } } - - internal static string RandomMinMaxSame - { + + internal static string RandomMinMaxSame { get { return ResourceManager.GetString("RandomMinMaxSame", resourceCulture); } } - - internal static string RandomMax - { - get { - return ResourceManager.GetString("RandomMax", resourceCulture); - } - } - - internal static string RandomMin - { + + internal static string RandomMin { get { return ResourceManager.GetString("RandomMin", resourceCulture); } } - - internal static string Default - { + + internal static string RandomMax { + get { + return ResourceManager.GetString("RandomMax", resourceCulture); + } + } + + internal static string Default { get { return ResourceManager.GetString("Default", resourceCulture); } } - - internal static string TimestampTitle - { - get - { + + internal static string TimestampTitle { + get { return ResourceManager.GetString("TimestampTitle", resourceCulture); } } - - internal static string TimestampOffset - { - get - { + + internal static string TimestampOffset { + get { return ResourceManager.GetString("TimestampOffset", resourceCulture); } } - - internal static string GuildInfoDescription - { - get - { + + internal static string GuildInfoDescription { + get { return ResourceManager.GetString("GuildInfoDescription", resourceCulture); } } - - internal static string GuildInfoCreatedAt - { - get - { + + internal static string GuildInfoCreatedAt { + get { return ResourceManager.GetString("GuildInfoCreatedAt", resourceCulture); } } - - internal static string GuildInfoOwner - { - get - { + + internal static string GuildInfoOwner { + get { return ResourceManager.GetString("GuildInfoOwner", resourceCulture); } } - - internal static string GuildInfoServerBoost - { - get - { + + internal static string GuildInfoServerBoost { + get { return ResourceManager.GetString("GuildInfoServerBoost", resourceCulture); } } - - internal static string GuildInfoBoostTier - { - get - { + + internal static string GuildInfoBoostTier { + get { return ResourceManager.GetString("GuildInfoBoostTier", resourceCulture); } } - - internal static string GuildInfoBoostCount - { - get - { + + internal static string GuildInfoBoostCount { + get { return ResourceManager.GetString("GuildInfoBoostCount", resourceCulture); } } - - internal static string NoMessagesToClear - { - get - { + + internal static string NoMessagesToClear { + get { return ResourceManager.GetString("NoMessagesToClear", resourceCulture); } } - - internal static string MessagesClearedFiltered - { - get - { + + internal static string MessagesClearedFiltered { + get { return ResourceManager.GetString("MessagesClearedFiltered", resourceCulture); } } - - internal static string DataLoadFailedTitle - { - get - { + + internal static string DataLoadFailedTitle { + get { return ResourceManager.GetString("DataLoadFailedTitle", resourceCulture); } } - - internal static string DataLoadFailedDescription - { - get - { + + internal static string DataLoadFailedDescription { + get { return ResourceManager.GetString("DataLoadFailedDescription", resourceCulture); } } - - internal static string CommandExecutionFailed - { - get - { + + internal static string CommandExecutionFailed { + get { return ResourceManager.GetString("CommandExecutionFailed", resourceCulture); } } - - internal static string ContactDevelopers - { - get - { + + internal static string ContactDevelopers { + get { return ResourceManager.GetString("ContactDevelopers", resourceCulture); } } - - internal static string ButtonReportIssue - { - get - { + + internal static string ButtonReportIssue { + get { return ResourceManager.GetString("ButtonReportIssue", resourceCulture); } } - + internal static string DefaultLeaveMessage { get { return ResourceManager.GetString("DefaultLeaveMessage", resourceCulture); } } - + internal static string SettingsLeaveMessage { get { return ResourceManager.GetString("SettingsLeaveMessage", resourceCulture); } } - + internal static string InvalidTimeSpan { get { return ResourceManager.GetString("InvalidTimeSpan", resourceCulture); } } - + internal static string UserInfoKicked { get { return ResourceManager.GetString("UserInfoKicked", resourceCulture); } } - + internal static string ReminderEdited { get { return ResourceManager.GetString("ReminderEdited", resourceCulture); } } - + internal static string EightBallPositive1 { get { return ResourceManager.GetString("EightBallPositive1", resourceCulture); } } - + internal static string EightBallPositive2 { get { return ResourceManager.GetString("EightBallPositive2", resourceCulture); } } - + internal static string EightBallPositive3 { get { return ResourceManager.GetString("EightBallPositive3", resourceCulture); } } - + internal static string EightBallPositive4 { get { return ResourceManager.GetString("EightBallPositive4", resourceCulture); } } - + internal static string EightBallPositive5 { get { return ResourceManager.GetString("EightBallPositive5", resourceCulture); } } - + internal static string EightBallQuestionable1 { get { return ResourceManager.GetString("EightBallQuestionable1", resourceCulture); } } - + internal static string EightBallQuestionable2 { get { return ResourceManager.GetString("EightBallQuestionable2", resourceCulture); } } - + internal static string EightBallQuestionable3 { get { return ResourceManager.GetString("EightBallQuestionable3", resourceCulture); } } - + internal static string EightBallQuestionable4 { get { return ResourceManager.GetString("EightBallQuestionable4", resourceCulture); } } - + internal static string EightBallQuestionable5 { get { return ResourceManager.GetString("EightBallQuestionable5", resourceCulture); } } - + internal static string EightBallNeutral1 { get { return ResourceManager.GetString("EightBallNeutral1", resourceCulture); } } - + internal static string EightBallNeutral2 { get { return ResourceManager.GetString("EightBallNeutral2", resourceCulture); } } - + internal static string EightBallNeutral3 { get { return ResourceManager.GetString("EightBallNeutral3", resourceCulture); } } - + internal static string EightBallNeutral4 { get { return ResourceManager.GetString("EightBallNeutral4", resourceCulture); } } - + internal static string EightBallNeutral5 { get { return ResourceManager.GetString("EightBallNeutral5", resourceCulture); } } - + internal static string EightBallNegative1 { get { return ResourceManager.GetString("EightBallNegative1", resourceCulture); } } - + internal static string EightBallNegative2 { get { return ResourceManager.GetString("EightBallNegative2", resourceCulture); } } - + internal static string EightBallNegative3 { get { return ResourceManager.GetString("EightBallNegative3", resourceCulture); } } - + internal static string EightBallNegative4 { get { return ResourceManager.GetString("EightBallNegative4", resourceCulture); } } - + internal static string EightBallNegative5 { get { return ResourceManager.GetString("EightBallNegative5", resourceCulture); } } - + internal static string TimeSpanExample { get { return ResourceManager.GetString("TimeSpanExample", resourceCulture); } } - + internal static string Version { get { return ResourceManager.GetString("Version", resourceCulture); } } - + internal static string SettingsWelcomeMessagesChannel { get { return ResourceManager.GetString("SettingsWelcomeMessagesChannel", resourceCulture); } } - + internal static string ButtonDirty { get { return ResourceManager.GetString("ButtonDirty", resourceCulture); } } - + internal static string ButtonOpenWiki { get { return ResourceManager.GetString("ButtonOpenWiki", resourceCulture); } } + + internal static string SettingsModeratorRole { + get { + return ResourceManager.GetString("SettingsModeratorRole", resourceCulture); + } + } } } diff --git a/locale/Messages.resx b/TeamOctolings.Octobot/Messages.resx similarity index 100% rename from locale/Messages.resx rename to TeamOctolings.Octobot/Messages.resx diff --git a/locale/Messages.ru.resx b/TeamOctolings.Octobot/Messages.ru.resx similarity index 100% rename from locale/Messages.ru.resx rename to TeamOctolings.Octobot/Messages.ru.resx diff --git a/src/Parsers/TimeSpanParser.cs b/TeamOctolings.Octobot/Parsers/TimeSpanParser.cs similarity index 98% rename from src/Parsers/TimeSpanParser.cs rename to TeamOctolings.Octobot/Parsers/TimeSpanParser.cs index 1f44d46..99a8b90 100644 --- a/src/Parsers/TimeSpanParser.cs +++ b/TeamOctolings.Octobot/Parsers/TimeSpanParser.cs @@ -4,7 +4,7 @@ using JetBrains.Annotations; using Remora.Commands.Parsers; using Remora.Results; -namespace Octobot.Parsers; +namespace TeamOctolings.Octobot.Parsers; /// /// Parses s. diff --git a/src/Octobot.cs b/TeamOctolings.Octobot/Program.cs similarity index 86% rename from src/Octobot.cs rename to TeamOctolings.Octobot/Program.cs index 065967e..d1d6220 100644 --- a/src/Octobot.cs +++ b/TeamOctolings.Octobot/Program.cs @@ -2,13 +2,8 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using Octobot.Attributes; -using Octobot.Commands.Events; -using Octobot.Services; -using Octobot.Services.Update; using Remora.Discord.API.Abstractions.Gateway.Commands; using Remora.Discord.API.Abstractions.Objects; -using Remora.Discord.API.Objects; using Remora.Discord.Caching.Extensions; using Remora.Discord.Caching.Services; using Remora.Discord.Commands.Extensions; @@ -16,24 +11,20 @@ using Remora.Discord.Commands.Services; using Remora.Discord.Extensions.Extensions; using Remora.Discord.Gateway; using Remora.Discord.Hosting.Extensions; -using Remora.Rest.Core; using Serilog.Extensions.Logging; +using TeamOctolings.Octobot.Commands.Events; +using TeamOctolings.Octobot.Services; +using TeamOctolings.Octobot.Services.Update; -namespace Octobot; +namespace TeamOctolings.Octobot; -public sealed class Octobot +public sealed class Program { - public static readonly AllowedMentions NoMentions = new( - Array.Empty(), Array.Empty(), Array.Empty()); - - [StaticCallersOnly] - public static ILogger? StaticLogger { get; private set; } - public static async Task Main(string[] args) { var host = CreateHostBuilder(args).UseConsoleLifetime().Build(); var services = host.Services; - StaticLogger = services.GetRequiredService>(); + Utility.StaticLogger = services.GetRequiredService>(); var slashService = services.GetRequiredService(); // Providing a guild ID to this call will result in command duplicates! @@ -82,8 +73,8 @@ public sealed class Octobot // Init .AddDiscordCaching() .AddDiscordCommands(true, false) - .AddRespondersFromAssembly(typeof(Octobot).Assembly) - .AddCommandGroupsFromAssembly(typeof(Octobot).Assembly) + .AddRespondersFromAssembly(typeof(Program).Assembly) + .AddCommandGroupsFromAssembly(typeof(Program).Assembly) // Slash command event handlers .AddPreparationErrorEvent() .AddPostExecutionEvent() diff --git a/src/Responders/GuildLoadedResponder.cs b/TeamOctolings.Octobot/Responders/GuildLoadedResponder.cs similarity index 96% rename from src/Responders/GuildLoadedResponder.cs rename to TeamOctolings.Octobot/Responders/GuildLoadedResponder.cs index 55e9673..0c71a06 100644 --- a/src/Responders/GuildLoadedResponder.cs +++ b/TeamOctolings.Octobot/Responders/GuildLoadedResponder.cs @@ -1,8 +1,5 @@ using JetBrains.Annotations; using Microsoft.Extensions.Logging; -using Octobot.Data; -using Octobot.Extensions; -using Octobot.Services; using Remora.Discord.API.Abstractions.Gateway.Events; using Remora.Discord.API.Abstractions.Objects; using Remora.Discord.API.Abstractions.Rest; @@ -11,8 +8,11 @@ using Remora.Discord.API.Objects; using Remora.Discord.Extensions.Embeds; using Remora.Discord.Gateway.Responders; using Remora.Results; +using TeamOctolings.Octobot.Data; +using TeamOctolings.Octobot.Extensions; +using TeamOctolings.Octobot.Services; -namespace Octobot.Responders; +namespace TeamOctolings.Octobot.Responders; /// /// Handles sending a message to a guild that has just initialized if that guild diff --git a/src/Responders/GuildMemberJoinedResponder.cs b/TeamOctolings.Octobot/Responders/GuildMemberJoinedResponder.cs similarity index 94% rename from src/Responders/GuildMemberJoinedResponder.cs rename to TeamOctolings.Octobot/Responders/GuildMemberJoinedResponder.cs index 61ef5cc..6964fe7 100644 --- a/src/Responders/GuildMemberJoinedResponder.cs +++ b/TeamOctolings.Octobot/Responders/GuildMemberJoinedResponder.cs @@ -1,16 +1,16 @@ using System.Text.Json.Nodes; using JetBrains.Annotations; -using Octobot.Data; -using Octobot.Extensions; -using Octobot.Services; using Remora.Discord.API.Abstractions.Gateway.Events; using Remora.Discord.API.Abstractions.Rest; using Remora.Discord.Extensions.Embeds; using Remora.Discord.Gateway.Responders; using Remora.Rest.Core; using Remora.Results; +using TeamOctolings.Octobot.Data; +using TeamOctolings.Octobot.Extensions; +using TeamOctolings.Octobot.Services; -namespace Octobot.Responders; +namespace TeamOctolings.Octobot.Responders; /// /// Handles sending a guild's if one is set. @@ -77,7 +77,7 @@ public class GuildMemberJoinedResponder : IResponder return await _channelApi.CreateMessageWithEmbedResultAsync( GuildSettings.WelcomeMessagesChannel.Get(cfg), embedResult: embed, - allowedMentions: Octobot.NoMentions, ct: ct); + allowedMentions: Utility.NoMentions, ct: ct); } private async Task TryReturnRolesAsync( diff --git a/src/Responders/GuildMemberLeftResponder.cs b/TeamOctolings.Octobot/Responders/GuildMemberLeftResponder.cs similarity index 91% rename from src/Responders/GuildMemberLeftResponder.cs rename to TeamOctolings.Octobot/Responders/GuildMemberLeftResponder.cs index 90cc64c..4f6150c 100644 --- a/src/Responders/GuildMemberLeftResponder.cs +++ b/TeamOctolings.Octobot/Responders/GuildMemberLeftResponder.cs @@ -1,14 +1,14 @@ using JetBrains.Annotations; -using Octobot.Data; -using Octobot.Extensions; -using Octobot.Services; using Remora.Discord.API.Abstractions.Gateway.Events; using Remora.Discord.API.Abstractions.Rest; using Remora.Discord.Extensions.Embeds; using Remora.Discord.Gateway.Responders; using Remora.Results; +using TeamOctolings.Octobot.Data; +using TeamOctolings.Octobot.Extensions; +using TeamOctolings.Octobot.Services; -namespace Octobot.Responders; +namespace TeamOctolings.Octobot.Responders; /// /// Handles sending a guild's if one is set. @@ -67,6 +67,6 @@ public class GuildMemberLeftResponder : IResponder return await _channelApi.CreateMessageWithEmbedResultAsync( GuildSettings.WelcomeMessagesChannel.Get(cfg), embedResult: embed, - allowedMentions: Octobot.NoMentions, ct: ct); + allowedMentions: Utility.NoMentions, ct: ct); } } diff --git a/src/Responders/GuildUnloadedResponder.cs b/TeamOctolings.Octobot/Responders/GuildUnloadedResponder.cs similarity index 90% rename from src/Responders/GuildUnloadedResponder.cs rename to TeamOctolings.Octobot/Responders/GuildUnloadedResponder.cs index b49d136..a4680d4 100644 --- a/src/Responders/GuildUnloadedResponder.cs +++ b/TeamOctolings.Octobot/Responders/GuildUnloadedResponder.cs @@ -1,12 +1,12 @@ using JetBrains.Annotations; using Microsoft.Extensions.Logging; -using Octobot.Data; -using Octobot.Services; using Remora.Discord.API.Abstractions.Gateway.Events; using Remora.Discord.Gateway.Responders; using Remora.Results; +using TeamOctolings.Octobot.Data; +using TeamOctolings.Octobot.Services; -namespace Octobot.Responders; +namespace TeamOctolings.Octobot.Responders; /// /// Handles removing guild ID from if the guild becomes unavailable. diff --git a/src/Responders/MessageDeletedResponder.cs b/TeamOctolings.Octobot/Responders/MessageDeletedResponder.cs similarity index 94% rename from src/Responders/MessageDeletedResponder.cs rename to TeamOctolings.Octobot/Responders/MessageDeletedResponder.cs index 5a69273..6b09b8d 100644 --- a/src/Responders/MessageDeletedResponder.cs +++ b/TeamOctolings.Octobot/Responders/MessageDeletedResponder.cs @@ -1,8 +1,5 @@ using System.Text; using JetBrains.Annotations; -using Octobot.Data; -using Octobot.Extensions; -using Octobot.Services; using Remora.Discord.API.Abstractions.Gateway.Events; using Remora.Discord.API.Abstractions.Objects; using Remora.Discord.API.Abstractions.Rest; @@ -10,8 +7,11 @@ using Remora.Discord.Extensions.Embeds; using Remora.Discord.Extensions.Formatting; using Remora.Discord.Gateway.Responders; using Remora.Results; +using TeamOctolings.Octobot.Data; +using TeamOctolings.Octobot.Extensions; +using TeamOctolings.Octobot.Services; -namespace Octobot.Responders; +namespace TeamOctolings.Octobot.Responders; /// /// Handles logging the contents of a deleted message and the user who deleted the message @@ -102,6 +102,6 @@ public class MessageDeletedResponder : IResponder return await _channelApi.CreateMessageWithEmbedResultAsync( GuildSettings.PrivateFeedbackChannel.Get(cfg), embedResult: embed, - allowedMentions: Octobot.NoMentions, ct: ct); + allowedMentions: Utility.NoMentions, ct: ct); } } diff --git a/src/Responders/MessageEditedResponder.cs b/TeamOctolings.Octobot/Responders/MessageEditedResponder.cs similarity index 95% rename from src/Responders/MessageEditedResponder.cs rename to TeamOctolings.Octobot/Responders/MessageEditedResponder.cs index 1143652..6134214 100644 --- a/src/Responders/MessageEditedResponder.cs +++ b/TeamOctolings.Octobot/Responders/MessageEditedResponder.cs @@ -1,9 +1,6 @@ using System.Text; using DiffPlex.DiffBuilder; using JetBrains.Annotations; -using Octobot.Data; -using Octobot.Extensions; -using Octobot.Services; using Remora.Discord.API.Abstractions.Gateway.Events; using Remora.Discord.API.Abstractions.Objects; using Remora.Discord.API.Abstractions.Rest; @@ -12,8 +9,11 @@ using Remora.Discord.Caching.Services; using Remora.Discord.Extensions.Embeds; using Remora.Discord.Gateway.Responders; using Remora.Results; +using TeamOctolings.Octobot.Data; +using TeamOctolings.Octobot.Extensions; +using TeamOctolings.Octobot.Services; -namespace Octobot.Responders; +namespace TeamOctolings.Octobot.Responders; /// /// Handles logging the difference between an edited message's old and new content @@ -104,6 +104,6 @@ public class MessageEditedResponder : IResponder return await _channelApi.CreateMessageWithEmbedResultAsync( GuildSettings.PrivateFeedbackChannel.Get(cfg), embedResult: embed, - allowedMentions: Octobot.NoMentions, ct: ct); + allowedMentions: Utility.NoMentions, ct: ct); } } diff --git a/src/Responders/MessageReceivedResponder.cs b/TeamOctolings.Octobot/Responders/MessageReceivedResponder.cs similarity index 96% rename from src/Responders/MessageReceivedResponder.cs rename to TeamOctolings.Octobot/Responders/MessageReceivedResponder.cs index 4c26d8d..34a8f5c 100644 --- a/src/Responders/MessageReceivedResponder.cs +++ b/TeamOctolings.Octobot/Responders/MessageReceivedResponder.cs @@ -5,7 +5,7 @@ using Remora.Discord.Gateway.Responders; using Remora.Rest.Core; using Remora.Results; -namespace Octobot.Responders; +namespace TeamOctolings.Octobot.Responders; /// /// Handles sending replies to easter egg messages. diff --git a/src/Services/AccessControlService.cs b/TeamOctolings.Octobot/Services/AccessControlService.cs similarity index 97% rename from src/Services/AccessControlService.cs rename to TeamOctolings.Octobot/Services/AccessControlService.cs index cb235f9..b5b98ea 100644 --- a/src/Services/AccessControlService.cs +++ b/TeamOctolings.Octobot/Services/AccessControlService.cs @@ -1,11 +1,11 @@ -using Octobot.Data; -using Octobot.Extensions; -using Remora.Discord.API.Abstractions.Objects; +using Remora.Discord.API.Abstractions.Objects; using Remora.Discord.API.Abstractions.Rest; using Remora.Rest.Core; using Remora.Results; +using TeamOctolings.Octobot.Data; +using TeamOctolings.Octobot.Extensions; -namespace Octobot.Services; +namespace TeamOctolings.Octobot.Services; public sealed class AccessControlService { diff --git a/src/Services/GuildDataService.cs b/TeamOctolings.Octobot/Services/GuildDataService.cs similarity index 98% rename from src/Services/GuildDataService.cs rename to TeamOctolings.Octobot/Services/GuildDataService.cs index e503d22..866ee08 100644 --- a/src/Services/GuildDataService.cs +++ b/TeamOctolings.Octobot/Services/GuildDataService.cs @@ -3,10 +3,10 @@ using System.Text.Json; using System.Text.Json.Nodes; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using Octobot.Data; using Remora.Rest.Core; +using TeamOctolings.Octobot.Data; -namespace Octobot.Services; +namespace TeamOctolings.Octobot.Services; /// /// Handles saving, loading, initializing and providing . diff --git a/src/Services/Update/MemberUpdateService.cs b/TeamOctolings.Octobot/Services/Update/MemberUpdateService.cs similarity index 98% rename from src/Services/Update/MemberUpdateService.cs rename to TeamOctolings.Octobot/Services/Update/MemberUpdateService.cs index e177fca..51cf647 100644 --- a/src/Services/Update/MemberUpdateService.cs +++ b/TeamOctolings.Octobot/Services/Update/MemberUpdateService.cs @@ -2,16 +2,16 @@ using System.Text; using System.Text.RegularExpressions; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using Octobot.Data; -using Octobot.Extensions; using Remora.Discord.API.Abstractions.Objects; using Remora.Discord.API.Abstractions.Rest; using Remora.Discord.Extensions.Embeds; using Remora.Discord.Extensions.Formatting; using Remora.Rest.Core; using Remora.Results; +using TeamOctolings.Octobot.Data; +using TeamOctolings.Octobot.Extensions; -namespace Octobot.Services.Update; +namespace TeamOctolings.Octobot.Services.Update; public sealed partial class MemberUpdateService : BackgroundService { diff --git a/src/Services/Update/ScheduledEventUpdateService.cs b/TeamOctolings.Octobot/Services/Update/ScheduledEventUpdateService.cs similarity index 99% rename from src/Services/Update/ScheduledEventUpdateService.cs rename to TeamOctolings.Octobot/Services/Update/ScheduledEventUpdateService.cs index cb87779..ce9c212 100644 --- a/src/Services/Update/ScheduledEventUpdateService.cs +++ b/TeamOctolings.Octobot/Services/Update/ScheduledEventUpdateService.cs @@ -1,8 +1,6 @@ using System.Text.Json.Nodes; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using Octobot.Data; -using Octobot.Extensions; using Remora.Discord.API.Abstractions.Objects; using Remora.Discord.API.Abstractions.Rest; using Remora.Discord.API.Objects; @@ -10,8 +8,10 @@ using Remora.Discord.Extensions.Embeds; using Remora.Discord.Extensions.Formatting; using Remora.Rest.Core; using Remora.Results; +using TeamOctolings.Octobot.Data; +using TeamOctolings.Octobot.Extensions; -namespace Octobot.Services.Update; +namespace TeamOctolings.Octobot.Services.Update; public sealed class ScheduledEventUpdateService : BackgroundService { diff --git a/src/Services/Update/SongUpdateService.cs b/TeamOctolings.Octobot/Services/Update/SongUpdateService.cs similarity index 98% rename from src/Services/Update/SongUpdateService.cs rename to TeamOctolings.Octobot/Services/Update/SongUpdateService.cs index 41d5bf3..b07256f 100644 --- a/src/Services/Update/SongUpdateService.cs +++ b/TeamOctolings.Octobot/Services/Update/SongUpdateService.cs @@ -4,7 +4,7 @@ using Remora.Discord.API.Gateway.Commands; using Remora.Discord.API.Objects; using Remora.Discord.Gateway; -namespace Octobot.Services.Update; +namespace TeamOctolings.Octobot.Services.Update; public sealed class SongUpdateService : BackgroundService { diff --git a/Octobot.csproj b/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj similarity index 90% rename from Octobot.csproj rename to TeamOctolings.Octobot/TeamOctolings.Octobot.csproj index bdfb46a..9c3d58b 100644 --- a/Octobot.csproj +++ b/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj @@ -1,4 +1,4 @@ - + Exe @@ -16,7 +16,7 @@ TeamOctolings en A general-purpose Discord bot for moderation written in C# - docs/octobot.ico + ../docs/octobot.ico false @@ -35,12 +35,12 @@ - + ResXFileCodeGenerator Messages.Designer.cs - + diff --git a/src/Services/Utility.cs b/TeamOctolings.Octobot/Utility.cs similarity index 92% rename from src/Services/Utility.cs rename to TeamOctolings.Octobot/Utility.cs index 3b9ab19..463212b 100644 --- a/src/Services/Utility.cs +++ b/TeamOctolings.Octobot/Utility.cs @@ -1,16 +1,19 @@ using System.Drawing; using System.Text; using System.Text.Json.Nodes; -using Octobot.Data; -using Octobot.Extensions; +using Microsoft.Extensions.Logging; using Remora.Discord.API.Abstractions.Objects; using Remora.Discord.API.Abstractions.Rest; +using Remora.Discord.API.Objects; using Remora.Discord.Extensions.Embeds; using Remora.Discord.Extensions.Formatting; using Remora.Rest.Core; using Remora.Results; +using TeamOctolings.Octobot.Attributes; +using TeamOctolings.Octobot.Data; +using TeamOctolings.Octobot.Extensions; -namespace Octobot.Services; +namespace TeamOctolings.Octobot; /// /// Provides utility methods that cannot be transformed to extension methods because they require usage @@ -18,6 +21,9 @@ namespace Octobot.Services; /// public sealed class Utility { + public static readonly AllowedMentions NoMentions = new( + Array.Empty(), Array.Empty(), Array.Empty()); + private readonly IDiscordRestChannelAPI _channelApi; private readonly IDiscordRestGuildScheduledEventAPI _eventApi; private readonly IDiscordRestGuildAPI _guildApi; @@ -30,6 +36,9 @@ public sealed class Utility _guildApi = guildApi; } + [StaticCallersOnly] + public static ILogger? StaticLogger { get; set; } + /// /// Gets the string mentioning the and event subscribers related to /// a scheduled From ebcdcb35f7f4f34fd37209821c939336cf5cd878 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Sat, 18 May 2024 21:12:38 +0500 Subject: [PATCH 14/42] Separate /*info commands from ToolsCommandGroup (#308) who tf thought that putting 1234915912 methods responsible for 23981 commands in a single class was a good idea??????? Signed-off-by: Octol1ttle --- .../Commands/InfoCommandGroup.cs | 329 ++++++++++++++++++ .../Commands/ToolsCommandGroup.cs | 325 +---------------- 2 files changed, 347 insertions(+), 307 deletions(-) create mode 100644 TeamOctolings.Octobot/Commands/InfoCommandGroup.cs diff --git a/TeamOctolings.Octobot/Commands/InfoCommandGroup.cs b/TeamOctolings.Octobot/Commands/InfoCommandGroup.cs new file mode 100644 index 0000000..65ddd53 --- /dev/null +++ b/TeamOctolings.Octobot/Commands/InfoCommandGroup.cs @@ -0,0 +1,329 @@ +using System.ComponentModel; +using System.Drawing; +using System.Text; +using JetBrains.Annotations; +using Remora.Commands.Attributes; +using Remora.Commands.Groups; +using Remora.Discord.API.Abstractions.Objects; +using Remora.Discord.API.Abstractions.Rest; +using Remora.Discord.Commands.Attributes; +using Remora.Discord.Commands.Contexts; +using Remora.Discord.Commands.Feedback.Services; +using Remora.Discord.Extensions.Embeds; +using Remora.Discord.Extensions.Formatting; +using Remora.Rest.Core; +using Remora.Results; +using TeamOctolings.Octobot.Data; +using TeamOctolings.Octobot.Extensions; +using TeamOctolings.Octobot.Services; + +namespace TeamOctolings.Octobot.Commands; + +/// +/// Handles info commands: /userinfo, /guildinfo. +/// +[UsedImplicitly] +public class InfoCommandGroup : CommandGroup +{ + private readonly ICommandContext _context; + private readonly IFeedbackService _feedback; + private readonly IDiscordRestGuildAPI _guildApi; + private readonly GuildDataService _guildData; + private readonly IDiscordRestUserAPI _userApi; + + public InfoCommandGroup( + ICommandContext context, IFeedbackService feedback, + GuildDataService guildData, IDiscordRestGuildAPI guildApi, + IDiscordRestUserAPI userApi) + { + _context = context; + _guildData = guildData; + _feedback = feedback; + _guildApi = guildApi; + _userApi = userApi; + } + + /// + /// A slash command that shows information about user. + /// + /// + /// Information in the output: + /// + /// Display name + /// Discord user since + /// Guild nickname + /// Guild member since + /// Nitro booster since + /// Guild roles + /// Active mute information + /// Active ban information + /// Is on guild status + /// + /// + /// The user to show info about. + /// + /// A feedback sending result which may or may not have succeeded. + /// + [Command("userinfo")] + [DiscordDefaultDMPermission(false)] + [Description("Shows info about user")] + [UsedImplicitly] + public async Task ExecuteUserInfoAsync( + [Description("User to show info about")] + IUser? target = null) + { + if (!_context.TryGetContextIDs(out var guildId, out _, out var executorId)) + { + return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); + } + + var botResult = await _userApi.GetCurrentUserAsync(CancellationToken); + if (!botResult.IsDefined(out var bot)) + { + return ResultExtensions.FromError(botResult); + } + + var executorResult = await _userApi.GetUserAsync(executorId, CancellationToken); + if (!executorResult.IsDefined(out var executor)) + { + return ResultExtensions.FromError(executorResult); + } + + var data = await _guildData.GetData(guildId, CancellationToken); + Messages.Culture = GuildSettings.Language.Get(data.Settings); + + return await ShowUserInfoAsync(target ?? executor, bot, data, guildId, CancellationToken); + } + + private async Task ShowUserInfoAsync( + IUser target, IUser bot, GuildData data, Snowflake guildId, CancellationToken ct = default) + { + var builder = new StringBuilder().AppendLine($"### <@{target.ID}>"); + + if (target.GlobalName.IsDefined(out var globalName)) + { + builder.AppendBulletPointLine(Messages.UserInfoDisplayName) + .AppendLine(Markdown.InlineCode(globalName)); + } + + builder.AppendBulletPointLine(Messages.UserInfoDiscordUserSince) + .AppendLine(Markdown.Timestamp(target.ID.Timestamp)); + + var memberData = data.GetOrCreateMemberData(target.ID); + + var embedColor = ColorsList.Cyan; + + var guildMemberResult = await _guildApi.GetGuildMemberAsync(guildId, target.ID, ct); + DateTimeOffset? communicationDisabledUntil = null; + if (guildMemberResult.IsDefined(out var guildMember)) + { + communicationDisabledUntil = guildMember.CommunicationDisabledUntil.OrDefault(null); + + embedColor = AppendGuildInformation(embedColor, guildMember, builder); + } + + var wasMuted = (memberData.MutedUntil is not null && DateTimeOffset.UtcNow <= memberData.MutedUntil) || + communicationDisabledUntil is not null; + var wasBanned = memberData.BannedUntil is not null; + var wasKicked = memberData.Kicked; + + if (wasMuted || wasBanned || wasKicked) + { + builder.Append("### ") + .AppendLine(Markdown.Bold(Messages.UserInfoPunishments)); + + embedColor = AppendPunishmentsInformation(wasMuted, wasKicked, wasBanned, memberData, + builder, embedColor, communicationDisabledUntil); + } + + if (!guildMemberResult.IsSuccess && !wasBanned) + { + builder.Append("### ") + .AppendLine(Markdown.Bold(Messages.UserInfoNotOnGuild)); + + embedColor = ColorsList.Default; + } + + var embed = new EmbedBuilder().WithSmallTitle( + string.Format(Messages.InformationAbout, target.GetTag()), bot) + .WithDescription(builder.ToString()) + .WithColour(embedColor) + .WithLargeUserAvatar(target) + .WithFooter($"ID: {target.ID.ToString()}") + .Build(); + + return await _feedback.SendContextualEmbedResultAsync(embed, ct: ct); + } + + private static Color AppendPunishmentsInformation(bool wasMuted, bool wasKicked, bool wasBanned, + MemberData memberData, StringBuilder builder, Color embedColor, DateTimeOffset? communicationDisabledUntil) + { + if (wasMuted) + { + AppendMuteInformation(memberData, communicationDisabledUntil, builder); + embedColor = ColorsList.Red; + } + + if (wasKicked) + { + builder.AppendBulletPointLine(Messages.UserInfoKicked); + } + + if (wasBanned) + { + AppendBanInformation(memberData, builder); + embedColor = ColorsList.Black; + } + + return embedColor; + } + + private static Color AppendGuildInformation(Color color, IGuildMember guildMember, StringBuilder builder) + { + if (guildMember.Nickname.IsDefined(out var nickname)) + { + builder.AppendBulletPointLine(Messages.UserInfoGuildNickname) + .AppendLine(Markdown.InlineCode(nickname)); + } + + builder.AppendBulletPointLine(Messages.UserInfoGuildMemberSince) + .AppendLine(Markdown.Timestamp(guildMember.JoinedAt)); + + if (guildMember.PremiumSince.IsDefined(out var premiumSince)) + { + builder.AppendBulletPointLine(Messages.UserInfoGuildMemberPremiumSince) + .AppendLine(Markdown.Timestamp(premiumSince.Value)); + color = ColorsList.Magenta; + } + + if (guildMember.Roles.Count > 0) + { + builder.AppendBulletPointLine(Messages.UserInfoGuildRoles); + for (var i = 0; i < guildMember.Roles.Count - 1; i++) + { + builder.Append($"<@&{guildMember.Roles[i]}>, "); + } + + builder.AppendLine($"<@&{guildMember.Roles[^1]}>"); + } + + return color; + } + + private static void AppendBanInformation(MemberData memberData, StringBuilder builder) + { + if (memberData.BannedUntil < DateTimeOffset.MaxValue) + { + builder.AppendBulletPointLine(Messages.UserInfoBanned) + .AppendSubBulletPointLine(string.Format( + Messages.DescriptionActionExpiresAt, Markdown.Timestamp(memberData.BannedUntil.Value))); + return; + } + + builder.AppendBulletPointLine(Messages.UserInfoBannedPermanently); + } + + private static void AppendMuteInformation( + MemberData memberData, DateTimeOffset? communicationDisabledUntil, StringBuilder builder) + { + builder.AppendBulletPointLine(Messages.UserInfoMuted); + if (memberData.MutedUntil is not null && DateTimeOffset.UtcNow <= memberData.MutedUntil) + { + builder.AppendSubBulletPointLine(Messages.UserInfoMutedByMuteRole) + .AppendSubBulletPointLine(string.Format( + Messages.DescriptionActionExpiresAt, Markdown.Timestamp(memberData.MutedUntil.Value))); + } + + if (communicationDisabledUntil is not null) + { + builder.AppendSubBulletPointLine(Messages.UserInfoMutedByTimeout) + .AppendSubBulletPointLine(string.Format( + Messages.DescriptionActionExpiresAt, Markdown.Timestamp(communicationDisabledUntil.Value))); + } + } + + /// + /// A slash command that shows guild information. + /// + /// + /// Information in the output: + /// + /// Guild description + /// Creation date + /// Guild's language + /// Guild's owner + /// Boost level + /// Boost count + /// + /// + /// + /// A feedback sending result which may or may not have succeeded. + /// + [Command("guildinfo")] + [DiscordDefaultDMPermission(false)] + [Description("Shows info about current guild")] + [UsedImplicitly] + public async Task ExecuteGuildInfoAsync() + { + if (!_context.TryGetContextIDs(out var guildId, out _, out _)) + { + return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); + } + + var botResult = await _userApi.GetCurrentUserAsync(CancellationToken); + if (!botResult.IsDefined(out var bot)) + { + return ResultExtensions.FromError(botResult); + } + + var guildResult = await _guildApi.GetGuildAsync(guildId, ct: CancellationToken); + if (!guildResult.IsDefined(out var guild)) + { + return ResultExtensions.FromError(guildResult); + } + + var data = await _guildData.GetData(guildId, CancellationToken); + Messages.Culture = GuildSettings.Language.Get(data.Settings); + + return await ShowGuildInfoAsync(bot, guild, CancellationToken); + } + + private Task ShowGuildInfoAsync(IUser bot, IGuild guild, CancellationToken ct) + { + var description = new StringBuilder().AppendLine($"## {guild.Name}"); + + if (guild.Description is not null) + { + description.AppendBulletPointLine(Messages.GuildInfoDescription) + .AppendLine(Markdown.InlineCode(guild.Description)); + } + + description.AppendBulletPointLine(Messages.GuildInfoCreatedAt) + .AppendLine(Markdown.Timestamp(guild.ID.Timestamp)) + .AppendBulletPointLine(Messages.GuildInfoOwner) + .AppendLine(Mention.User(guild.OwnerID)); + + var embedColor = ColorsList.Cyan; + + if (guild.PremiumTier > PremiumTier.None) + { + description.Append("### ").AppendLine(Messages.GuildInfoServerBoost) + .AppendBulletPoint(Messages.GuildInfoBoostTier) + .Append(": ").AppendLine(Markdown.InlineCode(guild.PremiumTier.ToString())) + .AppendBulletPoint(Messages.GuildInfoBoostCount) + .Append(": ").AppendLine(Markdown.InlineCode(guild.PremiumSubscriptionCount.ToString())); + embedColor = ColorsList.Magenta; + } + + var embed = new EmbedBuilder().WithSmallTitle( + string.Format(Messages.InformationAbout, guild.Name), bot) + .WithDescription(description.ToString()) + .WithColour(embedColor) + .WithLargeGuildIcon(guild) + .WithGuildBanner(guild) + .WithFooter($"ID: {guild.ID.ToString()}") + .Build(); + + return _feedback.SendContextualEmbedResultAsync(embed, ct: ct); + } +} diff --git a/TeamOctolings.Octobot/Commands/ToolsCommandGroup.cs b/TeamOctolings.Octobot/Commands/ToolsCommandGroup.cs index 3e84527..6af3040 100644 --- a/TeamOctolings.Octobot/Commands/ToolsCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/ToolsCommandGroup.cs @@ -1,5 +1,4 @@ using System.ComponentModel; -using System.Drawing; using System.Text; using JetBrains.Annotations; using Remora.Commands.Attributes; @@ -11,7 +10,6 @@ using Remora.Discord.Commands.Contexts; using Remora.Discord.Commands.Feedback.Services; using Remora.Discord.Extensions.Embeds; using Remora.Discord.Extensions.Formatting; -using Remora.Rest.Core; using Remora.Results; using TeamOctolings.Octobot.Data; using TeamOctolings.Octobot.Extensions; @@ -21,313 +19,42 @@ using TeamOctolings.Octobot.Services; namespace TeamOctolings.Octobot.Commands; /// -/// Handles tool commands: /userinfo, /guildinfo, /random, /timestamp, /8ball. +/// Handles tool commands: /random, /timestamp, /8ball. /// [UsedImplicitly] public class ToolsCommandGroup : CommandGroup { + private static readonly TimestampStyle[] AllStyles = + [ + TimestampStyle.ShortDate, + TimestampStyle.LongDate, + TimestampStyle.ShortTime, + TimestampStyle.LongTime, + TimestampStyle.ShortDateTime, + TimestampStyle.LongDateTime, + TimestampStyle.RelativeTime + ]; + + private static readonly string[] AnswerTypes = + [ + "Positive", "Questionable", "Neutral", "Negative" + ]; + private readonly ICommandContext _context; private readonly IFeedbackService _feedback; - private readonly IDiscordRestGuildAPI _guildApi; private readonly GuildDataService _guildData; private readonly IDiscordRestUserAPI _userApi; public ToolsCommandGroup( ICommandContext context, IFeedbackService feedback, - GuildDataService guildData, IDiscordRestGuildAPI guildApi, - IDiscordRestUserAPI userApi) + GuildDataService guildData, IDiscordRestUserAPI userApi) { _context = context; _guildData = guildData; _feedback = feedback; - _guildApi = guildApi; _userApi = userApi; } - /// - /// A slash command that shows information about user. - /// - /// - /// Information in the output: - /// - /// Display name - /// Discord user since - /// Guild nickname - /// Guild member since - /// Nitro booster since - /// Guild roles - /// Active mute information - /// Active ban information - /// Is on guild status - /// - /// - /// The user to show info about. - /// - /// A feedback sending result which may or may not have succeeded. - /// - [Command("userinfo")] - [DiscordDefaultDMPermission(false)] - [Description("Shows info about user")] - [UsedImplicitly] - public async Task ExecuteUserInfoAsync( - [Description("User to show info about")] - IUser? target = null) - { - if (!_context.TryGetContextIDs(out var guildId, out _, out var executorId)) - { - return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); - } - - var botResult = await _userApi.GetCurrentUserAsync(CancellationToken); - if (!botResult.IsDefined(out var bot)) - { - return ResultExtensions.FromError(botResult); - } - - var executorResult = await _userApi.GetUserAsync(executorId, CancellationToken); - if (!executorResult.IsDefined(out var executor)) - { - return ResultExtensions.FromError(executorResult); - } - - var data = await _guildData.GetData(guildId, CancellationToken); - Messages.Culture = GuildSettings.Language.Get(data.Settings); - - return await ShowUserInfoAsync(target ?? executor, bot, data, guildId, CancellationToken); - } - - private async Task ShowUserInfoAsync( - IUser target, IUser bot, GuildData data, Snowflake guildId, CancellationToken ct = default) - { - var builder = new StringBuilder().AppendLine($"### <@{target.ID}>"); - - if (target.GlobalName.IsDefined(out var globalName)) - { - builder.AppendBulletPointLine(Messages.UserInfoDisplayName) - .AppendLine(Markdown.InlineCode(globalName)); - } - - builder.AppendBulletPointLine(Messages.UserInfoDiscordUserSince) - .AppendLine(Markdown.Timestamp(target.ID.Timestamp)); - - var memberData = data.GetOrCreateMemberData(target.ID); - - var embedColor = ColorsList.Cyan; - - var guildMemberResult = await _guildApi.GetGuildMemberAsync(guildId, target.ID, ct); - DateTimeOffset? communicationDisabledUntil = null; - if (guildMemberResult.IsDefined(out var guildMember)) - { - communicationDisabledUntil = guildMember.CommunicationDisabledUntil.OrDefault(null); - - embedColor = AppendGuildInformation(embedColor, guildMember, builder); - } - - var wasMuted = (memberData.MutedUntil is not null && DateTimeOffset.UtcNow <= memberData.MutedUntil) || - communicationDisabledUntil is not null; - var wasBanned = memberData.BannedUntil is not null; - var wasKicked = memberData.Kicked; - - if (wasMuted || wasBanned || wasKicked) - { - builder.Append("### ") - .AppendLine(Markdown.Bold(Messages.UserInfoPunishments)); - - embedColor = AppendPunishmentsInformation(wasMuted, wasKicked, wasBanned, memberData, - builder, embedColor, communicationDisabledUntil); - } - - if (!guildMemberResult.IsSuccess && !wasBanned) - { - builder.Append("### ") - .AppendLine(Markdown.Bold(Messages.UserInfoNotOnGuild)); - - embedColor = ColorsList.Default; - } - - var embed = new EmbedBuilder().WithSmallTitle( - string.Format(Messages.InformationAbout, target.GetTag()), bot) - .WithDescription(builder.ToString()) - .WithColour(embedColor) - .WithLargeUserAvatar(target) - .WithFooter($"ID: {target.ID.ToString()}") - .Build(); - - return await _feedback.SendContextualEmbedResultAsync(embed, ct: ct); - } - - private static Color AppendPunishmentsInformation(bool wasMuted, bool wasKicked, bool wasBanned, - MemberData memberData, StringBuilder builder, Color embedColor, DateTimeOffset? communicationDisabledUntil) - { - if (wasMuted) - { - AppendMuteInformation(memberData, communicationDisabledUntil, builder); - embedColor = ColorsList.Red; - } - - if (wasKicked) - { - builder.AppendBulletPointLine(Messages.UserInfoKicked); - } - - if (wasBanned) - { - AppendBanInformation(memberData, builder); - embedColor = ColorsList.Black; - } - - return embedColor; - } - - private static Color AppendGuildInformation(Color color, IGuildMember guildMember, StringBuilder builder) - { - if (guildMember.Nickname.IsDefined(out var nickname)) - { - builder.AppendBulletPointLine(Messages.UserInfoGuildNickname) - .AppendLine(Markdown.InlineCode(nickname)); - } - - builder.AppendBulletPointLine(Messages.UserInfoGuildMemberSince) - .AppendLine(Markdown.Timestamp(guildMember.JoinedAt)); - - if (guildMember.PremiumSince.IsDefined(out var premiumSince)) - { - builder.AppendBulletPointLine(Messages.UserInfoGuildMemberPremiumSince) - .AppendLine(Markdown.Timestamp(premiumSince.Value)); - color = ColorsList.Magenta; - } - - if (guildMember.Roles.Count > 0) - { - builder.AppendBulletPointLine(Messages.UserInfoGuildRoles); - for (var i = 0; i < guildMember.Roles.Count - 1; i++) - { - builder.Append($"<@&{guildMember.Roles[i]}>, "); - } - - builder.AppendLine($"<@&{guildMember.Roles[^1]}>"); - } - - return color; - } - - private static void AppendBanInformation(MemberData memberData, StringBuilder builder) - { - if (memberData.BannedUntil < DateTimeOffset.MaxValue) - { - builder.AppendBulletPointLine(Messages.UserInfoBanned) - .AppendSubBulletPointLine(string.Format( - Messages.DescriptionActionExpiresAt, Markdown.Timestamp(memberData.BannedUntil.Value))); - return; - } - - builder.AppendBulletPointLine(Messages.UserInfoBannedPermanently); - } - - private static void AppendMuteInformation( - MemberData memberData, DateTimeOffset? communicationDisabledUntil, StringBuilder builder) - { - builder.AppendBulletPointLine(Messages.UserInfoMuted); - if (memberData.MutedUntil is not null && DateTimeOffset.UtcNow <= memberData.MutedUntil) - { - builder.AppendSubBulletPointLine(Messages.UserInfoMutedByMuteRole) - .AppendSubBulletPointLine(string.Format( - Messages.DescriptionActionExpiresAt, Markdown.Timestamp(memberData.MutedUntil.Value))); - } - - if (communicationDisabledUntil is not null) - { - builder.AppendSubBulletPointLine(Messages.UserInfoMutedByTimeout) - .AppendSubBulletPointLine(string.Format( - Messages.DescriptionActionExpiresAt, Markdown.Timestamp(communicationDisabledUntil.Value))); - } - } - - /// - /// A slash command that shows guild information. - /// - /// - /// Information in the output: - /// - /// Guild description - /// Creation date - /// Guild's language - /// Guild's owner - /// Boost level - /// Boost count - /// - /// - /// - /// A feedback sending result which may or may not have succeeded. - /// - [Command("guildinfo")] - [DiscordDefaultDMPermission(false)] - [Description("Shows info about current guild")] - [UsedImplicitly] - public async Task ExecuteGuildInfoAsync() - { - if (!_context.TryGetContextIDs(out var guildId, out _, out _)) - { - return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); - } - - var botResult = await _userApi.GetCurrentUserAsync(CancellationToken); - if (!botResult.IsDefined(out var bot)) - { - return ResultExtensions.FromError(botResult); - } - - var guildResult = await _guildApi.GetGuildAsync(guildId, ct: CancellationToken); - if (!guildResult.IsDefined(out var guild)) - { - return ResultExtensions.FromError(guildResult); - } - - var data = await _guildData.GetData(guildId, CancellationToken); - Messages.Culture = GuildSettings.Language.Get(data.Settings); - - return await ShowGuildInfoAsync(bot, guild, CancellationToken); - } - - private Task ShowGuildInfoAsync(IUser bot, IGuild guild, CancellationToken ct) - { - var description = new StringBuilder().AppendLine($"## {guild.Name}"); - - if (guild.Description is not null) - { - description.AppendBulletPointLine(Messages.GuildInfoDescription) - .AppendLine(Markdown.InlineCode(guild.Description)); - } - - description.AppendBulletPointLine(Messages.GuildInfoCreatedAt) - .AppendLine(Markdown.Timestamp(guild.ID.Timestamp)) - .AppendBulletPointLine(Messages.GuildInfoOwner) - .AppendLine(Mention.User(guild.OwnerID)); - - var embedColor = ColorsList.Cyan; - - if (guild.PremiumTier > PremiumTier.None) - { - description.Append("### ").AppendLine(Messages.GuildInfoServerBoost) - .AppendBulletPoint(Messages.GuildInfoBoostTier) - .Append(": ").AppendLine(Markdown.InlineCode(guild.PremiumTier.ToString())) - .AppendBulletPoint(Messages.GuildInfoBoostCount) - .Append(": ").AppendLine(Markdown.InlineCode(guild.PremiumSubscriptionCount.ToString())); - embedColor = ColorsList.Magenta; - } - - var embed = new EmbedBuilder().WithSmallTitle( - string.Format(Messages.InformationAbout, guild.Name), bot) - .WithDescription(description.ToString()) - .WithColour(embedColor) - .WithLargeGuildIcon(guild) - .WithGuildBanner(guild) - .WithFooter($"ID: {guild.ID.ToString()}") - .Build(); - - return _feedback.SendContextualEmbedResultAsync(embed, ct: ct); - } - /// /// A slash command that generates a random number using maximum and minimum numbers. /// @@ -405,17 +132,6 @@ public class ToolsCommandGroup : CommandGroup return _feedback.SendContextualEmbedResultAsync(embed, ct: ct); } - private static readonly TimestampStyle[] AllStyles = - [ - TimestampStyle.ShortDate, - TimestampStyle.LongDate, - TimestampStyle.ShortTime, - TimestampStyle.LongTime, - TimestampStyle.ShortDateTime, - TimestampStyle.LongDateTime, - TimestampStyle.RelativeTime - ]; - /// /// A slash command that shows the current timestamp with an optional offset in all styles supported by Discord. /// @@ -533,11 +249,6 @@ public class ToolsCommandGroup : CommandGroup return await AnswerEightBallAsync(bot, CancellationToken); } - private static readonly string[] AnswerTypes = - [ - "Positive", "Questionable", "Neutral", "Negative" - ]; - private Task AnswerEightBallAsync(IUser bot, CancellationToken ct) { var typeNumber = Random.Shared.Next(0, 4); From d03e2504fc0640f8dd2d3a4b335ca9718af75c79 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Thu, 23 May 2024 17:47:51 +0500 Subject: [PATCH 15/42] Seal implicitly used classes (#309) Apparently the `[UsedImplicitly]` annotation suppresses the "Class has no inheritors and can be marked sealed" warning. Cool to know. Signed-off-by: Octol1ttle --- TeamOctolings.Octobot/Commands/AboutCommandGroup.cs | 4 ++-- TeamOctolings.Octobot/Commands/BanCommandGroup.cs | 2 +- TeamOctolings.Octobot/Commands/ClearCommandGroup.cs | 2 +- .../Commands/Events/ErrorLoggingPostExecutionEvent.cs | 2 +- .../Commands/Events/LoggingPreparationErrorEvent.cs | 2 +- TeamOctolings.Octobot/Commands/InfoCommandGroup.cs | 2 +- TeamOctolings.Octobot/Commands/KickCommandGroup.cs | 2 +- TeamOctolings.Octobot/Commands/MuteCommandGroup.cs | 2 +- TeamOctolings.Octobot/Commands/PingCommandGroup.cs | 2 +- TeamOctolings.Octobot/Commands/RemindCommandGroup.cs | 4 ++-- TeamOctolings.Octobot/Commands/SettingsCommandGroup.cs | 2 +- TeamOctolings.Octobot/Commands/ToolsCommandGroup.cs | 2 +- TeamOctolings.Octobot/Responders/GuildLoadedResponder.cs | 2 +- .../Responders/GuildMemberJoinedResponder.cs | 2 +- TeamOctolings.Octobot/Responders/GuildMemberLeftResponder.cs | 2 +- TeamOctolings.Octobot/Responders/GuildUnloadedResponder.cs | 2 +- TeamOctolings.Octobot/Responders/MessageDeletedResponder.cs | 2 +- TeamOctolings.Octobot/Responders/MessageEditedResponder.cs | 2 +- TeamOctolings.Octobot/Responders/MessageReceivedResponder.cs | 2 +- 19 files changed, 21 insertions(+), 21 deletions(-) diff --git a/TeamOctolings.Octobot/Commands/AboutCommandGroup.cs b/TeamOctolings.Octobot/Commands/AboutCommandGroup.cs index 9f05af3..dbb8b12 100644 --- a/TeamOctolings.Octobot/Commands/AboutCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/AboutCommandGroup.cs @@ -25,7 +25,7 @@ namespace TeamOctolings.Octobot.Commands; /// Handles the command to show information about this bot: /about. /// [UsedImplicitly] -public class AboutCommandGroup : CommandGroup +public sealed class AboutCommandGroup : CommandGroup { private static readonly (string Username, Snowflake Id)[] Developers = [ @@ -36,9 +36,9 @@ public class AboutCommandGroup : CommandGroup private readonly ICommandContext _context; private readonly IFeedbackService _feedback; + private readonly IDiscordRestGuildAPI _guildApi; private readonly GuildDataService _guildData; private readonly IDiscordRestUserAPI _userApi; - private readonly IDiscordRestGuildAPI _guildApi; public AboutCommandGroup( ICommandContext context, GuildDataService guildData, diff --git a/TeamOctolings.Octobot/Commands/BanCommandGroup.cs b/TeamOctolings.Octobot/Commands/BanCommandGroup.cs index 8d90286..69be80f 100644 --- a/TeamOctolings.Octobot/Commands/BanCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/BanCommandGroup.cs @@ -26,7 +26,7 @@ namespace TeamOctolings.Octobot.Commands; /// Handles commands related to ban management: /ban and /unban. /// [UsedImplicitly] -public class BanCommandGroup : CommandGroup +public sealed class BanCommandGroup : CommandGroup { private readonly AccessControlService _access; private readonly IDiscordRestChannelAPI _channelApi; diff --git a/TeamOctolings.Octobot/Commands/ClearCommandGroup.cs b/TeamOctolings.Octobot/Commands/ClearCommandGroup.cs index 8a8cb2f..38d864b 100644 --- a/TeamOctolings.Octobot/Commands/ClearCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/ClearCommandGroup.cs @@ -23,7 +23,7 @@ namespace TeamOctolings.Octobot.Commands; /// Handles the command to clear messages in a channel: /clear. /// [UsedImplicitly] -public class ClearCommandGroup : CommandGroup +public sealed class ClearCommandGroup : CommandGroup { private readonly IDiscordRestChannelAPI _channelApi; private readonly ICommandContext _context; diff --git a/TeamOctolings.Octobot/Commands/Events/ErrorLoggingPostExecutionEvent.cs b/TeamOctolings.Octobot/Commands/Events/ErrorLoggingPostExecutionEvent.cs index 7ffc4fe..7409d3b 100644 --- a/TeamOctolings.Octobot/Commands/Events/ErrorLoggingPostExecutionEvent.cs +++ b/TeamOctolings.Octobot/Commands/Events/ErrorLoggingPostExecutionEvent.cs @@ -18,7 +18,7 @@ namespace TeamOctolings.Octobot.Commands.Events; /// Handles error logging for slash command groups. /// [UsedImplicitly] -public class ErrorLoggingPostExecutionEvent : IPostExecutionEvent +public sealed class ErrorLoggingPostExecutionEvent : IPostExecutionEvent { private readonly IFeedbackService _feedback; private readonly ILogger _logger; diff --git a/TeamOctolings.Octobot/Commands/Events/LoggingPreparationErrorEvent.cs b/TeamOctolings.Octobot/Commands/Events/LoggingPreparationErrorEvent.cs index 10a6a1f..9e69a7f 100644 --- a/TeamOctolings.Octobot/Commands/Events/LoggingPreparationErrorEvent.cs +++ b/TeamOctolings.Octobot/Commands/Events/LoggingPreparationErrorEvent.cs @@ -11,7 +11,7 @@ namespace TeamOctolings.Octobot.Commands.Events; /// Handles error logging for slash commands that couldn't be successfully prepared. /// [UsedImplicitly] -public class LoggingPreparationErrorEvent : IPreparationErrorEvent +public sealed class LoggingPreparationErrorEvent : IPreparationErrorEvent { private readonly ILogger _logger; diff --git a/TeamOctolings.Octobot/Commands/InfoCommandGroup.cs b/TeamOctolings.Octobot/Commands/InfoCommandGroup.cs index 65ddd53..d7798f3 100644 --- a/TeamOctolings.Octobot/Commands/InfoCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/InfoCommandGroup.cs @@ -23,7 +23,7 @@ namespace TeamOctolings.Octobot.Commands; /// Handles info commands: /userinfo, /guildinfo. /// [UsedImplicitly] -public class InfoCommandGroup : CommandGroup +public sealed class InfoCommandGroup : CommandGroup { private readonly ICommandContext _context; private readonly IFeedbackService _feedback; diff --git a/TeamOctolings.Octobot/Commands/KickCommandGroup.cs b/TeamOctolings.Octobot/Commands/KickCommandGroup.cs index 4252232..a8fea2a 100644 --- a/TeamOctolings.Octobot/Commands/KickCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/KickCommandGroup.cs @@ -22,7 +22,7 @@ namespace TeamOctolings.Octobot.Commands; /// Handles the command to kick members of a guild: /kick. /// [UsedImplicitly] -public class KickCommandGroup : CommandGroup +public sealed class KickCommandGroup : CommandGroup { private readonly AccessControlService _access; private readonly IDiscordRestChannelAPI _channelApi; diff --git a/TeamOctolings.Octobot/Commands/MuteCommandGroup.cs b/TeamOctolings.Octobot/Commands/MuteCommandGroup.cs index 8e449f7..282afe8 100644 --- a/TeamOctolings.Octobot/Commands/MuteCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/MuteCommandGroup.cs @@ -26,7 +26,7 @@ namespace TeamOctolings.Octobot.Commands; /// Handles commands related to mute management: /mute and /unmute. /// [UsedImplicitly] -public class MuteCommandGroup : CommandGroup +public sealed class MuteCommandGroup : CommandGroup { private readonly AccessControlService _access; private readonly ICommandContext _context; diff --git a/TeamOctolings.Octobot/Commands/PingCommandGroup.cs b/TeamOctolings.Octobot/Commands/PingCommandGroup.cs index 70b9f23..01a1ee2 100644 --- a/TeamOctolings.Octobot/Commands/PingCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/PingCommandGroup.cs @@ -22,7 +22,7 @@ namespace TeamOctolings.Octobot.Commands; /// Handles the command to get the time taken for the gateway to respond to the last heartbeat: /ping /// [UsedImplicitly] -public class PingCommandGroup : CommandGroup +public sealed class PingCommandGroup : CommandGroup { private readonly IDiscordRestChannelAPI _channelApi; private readonly DiscordGatewayClient _client; diff --git a/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs b/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs index f40ba6b..bf59d67 100644 --- a/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs @@ -25,13 +25,13 @@ namespace TeamOctolings.Octobot.Commands; /// Handles commands to manage reminders: /remind, /listremind, /delremind /// [UsedImplicitly] -public class RemindCommandGroup : CommandGroup +public sealed class RemindCommandGroup : CommandGroup { private readonly IInteractionCommandContext _context; private readonly IFeedbackService _feedback; private readonly GuildDataService _guildData; - private readonly IDiscordRestUserAPI _userApi; private readonly IDiscordRestInteractionAPI _interactionApi; + private readonly IDiscordRestUserAPI _userApi; public RemindCommandGroup( IInteractionCommandContext context, GuildDataService guildData, IFeedbackService feedback, diff --git a/TeamOctolings.Octobot/Commands/SettingsCommandGroup.cs b/TeamOctolings.Octobot/Commands/SettingsCommandGroup.cs index 56584bf..0acaa88 100644 --- a/TeamOctolings.Octobot/Commands/SettingsCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/SettingsCommandGroup.cs @@ -26,7 +26,7 @@ namespace TeamOctolings.Octobot.Commands; /// Handles the commands to list and modify per-guild settings: /settings and /settings list. /// [UsedImplicitly] -public class SettingsCommandGroup : CommandGroup +public sealed class SettingsCommandGroup : CommandGroup { /// /// Represents all options as an array of objects implementing . diff --git a/TeamOctolings.Octobot/Commands/ToolsCommandGroup.cs b/TeamOctolings.Octobot/Commands/ToolsCommandGroup.cs index 6af3040..b4c3488 100644 --- a/TeamOctolings.Octobot/Commands/ToolsCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/ToolsCommandGroup.cs @@ -22,7 +22,7 @@ namespace TeamOctolings.Octobot.Commands; /// Handles tool commands: /random, /timestamp, /8ball. /// [UsedImplicitly] -public class ToolsCommandGroup : CommandGroup +public sealed class ToolsCommandGroup : CommandGroup { private static readonly TimestampStyle[] AllStyles = [ diff --git a/TeamOctolings.Octobot/Responders/GuildLoadedResponder.cs b/TeamOctolings.Octobot/Responders/GuildLoadedResponder.cs index 0c71a06..cebb1ea 100644 --- a/TeamOctolings.Octobot/Responders/GuildLoadedResponder.cs +++ b/TeamOctolings.Octobot/Responders/GuildLoadedResponder.cs @@ -19,7 +19,7 @@ namespace TeamOctolings.Octobot.Responders; /// has enabled /// [UsedImplicitly] -public class GuildLoadedResponder : IResponder +public sealed class GuildLoadedResponder : IResponder { private readonly IDiscordRestChannelAPI _channelApi; private readonly GuildDataService _guildData; diff --git a/TeamOctolings.Octobot/Responders/GuildMemberJoinedResponder.cs b/TeamOctolings.Octobot/Responders/GuildMemberJoinedResponder.cs index 6964fe7..c1f1da0 100644 --- a/TeamOctolings.Octobot/Responders/GuildMemberJoinedResponder.cs +++ b/TeamOctolings.Octobot/Responders/GuildMemberJoinedResponder.cs @@ -18,7 +18,7 @@ namespace TeamOctolings.Octobot.Responders; /// /// [UsedImplicitly] -public class GuildMemberJoinedResponder : IResponder +public sealed class GuildMemberJoinedResponder : IResponder { private readonly IDiscordRestChannelAPI _channelApi; private readonly IDiscordRestGuildAPI _guildApi; diff --git a/TeamOctolings.Octobot/Responders/GuildMemberLeftResponder.cs b/TeamOctolings.Octobot/Responders/GuildMemberLeftResponder.cs index 4f6150c..9774899 100644 --- a/TeamOctolings.Octobot/Responders/GuildMemberLeftResponder.cs +++ b/TeamOctolings.Octobot/Responders/GuildMemberLeftResponder.cs @@ -15,7 +15,7 @@ namespace TeamOctolings.Octobot.Responders; /// /// [UsedImplicitly] -public class GuildMemberLeftResponder : IResponder +public sealed class GuildMemberLeftResponder : IResponder { private readonly IDiscordRestChannelAPI _channelApi; private readonly IDiscordRestGuildAPI _guildApi; diff --git a/TeamOctolings.Octobot/Responders/GuildUnloadedResponder.cs b/TeamOctolings.Octobot/Responders/GuildUnloadedResponder.cs index a4680d4..c73c134 100644 --- a/TeamOctolings.Octobot/Responders/GuildUnloadedResponder.cs +++ b/TeamOctolings.Octobot/Responders/GuildUnloadedResponder.cs @@ -12,7 +12,7 @@ namespace TeamOctolings.Octobot.Responders; /// Handles removing guild ID from if the guild becomes unavailable. /// [UsedImplicitly] -public class GuildUnloadedResponder : IResponder +public sealed class GuildUnloadedResponder : IResponder { private readonly GuildDataService _guildData; private readonly ILogger _logger; diff --git a/TeamOctolings.Octobot/Responders/MessageDeletedResponder.cs b/TeamOctolings.Octobot/Responders/MessageDeletedResponder.cs index 6b09b8d..88a8de2 100644 --- a/TeamOctolings.Octobot/Responders/MessageDeletedResponder.cs +++ b/TeamOctolings.Octobot/Responders/MessageDeletedResponder.cs @@ -18,7 +18,7 @@ namespace TeamOctolings.Octobot.Responders; /// to a guild's if one is set. /// [UsedImplicitly] -public class MessageDeletedResponder : IResponder +public sealed class MessageDeletedResponder : IResponder { private readonly IDiscordRestAuditLogAPI _auditLogApi; private readonly IDiscordRestChannelAPI _channelApi; diff --git a/TeamOctolings.Octobot/Responders/MessageEditedResponder.cs b/TeamOctolings.Octobot/Responders/MessageEditedResponder.cs index 6134214..2968562 100644 --- a/TeamOctolings.Octobot/Responders/MessageEditedResponder.cs +++ b/TeamOctolings.Octobot/Responders/MessageEditedResponder.cs @@ -20,7 +20,7 @@ namespace TeamOctolings.Octobot.Responders; /// to a guild's if one is set. /// [UsedImplicitly] -public class MessageEditedResponder : IResponder +public sealed class MessageEditedResponder : IResponder { private readonly CacheService _cacheService; private readonly IDiscordRestChannelAPI _channelApi; diff --git a/TeamOctolings.Octobot/Responders/MessageReceivedResponder.cs b/TeamOctolings.Octobot/Responders/MessageReceivedResponder.cs index 34a8f5c..24d53a5 100644 --- a/TeamOctolings.Octobot/Responders/MessageReceivedResponder.cs +++ b/TeamOctolings.Octobot/Responders/MessageReceivedResponder.cs @@ -11,7 +11,7 @@ namespace TeamOctolings.Octobot.Responders; /// Handles sending replies to easter egg messages. /// [UsedImplicitly] -public class MessageCreateResponder : IResponder +public sealed class MessageCreateResponder : IResponder { private readonly IDiscordRestChannelAPI _channelApi; From ea9302e1858807d1a79293ae7e9ed43773373329 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Thu, 23 May 2024 18:21:52 +0500 Subject: [PATCH 16/42] Use MemberData roles when checking permissions & interactions (#312) Closes #311 This change fixes unexpected behavior when a member's Discord roles get desynchronized with their MemberData roles (e.g. when a member gets role-muted). In addition this results in less API requests being made when there are cache misses (commands should execute faster) --------- Signed-off-by: Octol1ttle --- .../Services/AccessControlService.cs | 57 ++++++------------- 1 file changed, 18 insertions(+), 39 deletions(-) diff --git a/TeamOctolings.Octobot/Services/AccessControlService.cs b/TeamOctolings.Octobot/Services/AccessControlService.cs index b5b98ea..d39c9e5 100644 --- a/TeamOctolings.Octobot/Services/AccessControlService.cs +++ b/TeamOctolings.Octobot/Services/AccessControlService.cs @@ -20,18 +20,17 @@ public sealed class AccessControlService _userApi = userApi; } - private static bool CheckPermission(IEnumerable roles, GuildData data, Snowflake memberId, - IGuildMember member, + private static bool CheckPermission(IEnumerable roles, GuildData data, MemberData memberData, DiscordPermission permission) { var moderatorRole = GuildSettings.ModeratorRole.Get(data.Settings); - if (!moderatorRole.Empty() && data.GetOrCreateMemberData(memberId).Roles.Contains(moderatorRole.Value)) + if (!moderatorRole.Empty() && memberData.Roles.Contains(moderatorRole.Value)) { return true; } return roles - .Where(r => member.Roles.Contains(r.ID)) + .Where(r => memberData.Roles.Contains(r.ID.Value)) .Any(r => r.Permissions.HasPermission(permission) ); @@ -80,38 +79,23 @@ public sealed class AccessControlService return Result.FromError(botResult); } - var botMemberResult = await _guildApi.GetGuildMemberAsync(guildId, bot.ID, ct); - if (!botMemberResult.IsDefined(out var botMember)) - { - return Result.FromError(botMemberResult); - } - - var targetMemberResult = await _guildApi.GetGuildMemberAsync(guildId, targetId, ct); - if (!targetMemberResult.IsDefined(out var targetMember)) - { - return Result.FromSuccess(null); - } - var rolesResult = await _guildApi.GetGuildRolesAsync(guildId, ct); if (!rolesResult.IsDefined(out var roles)) { return Result.FromError(rolesResult); } + var data = await _data.GetData(guildId, ct); + var targetData = data.GetOrCreateMemberData(targetId); + var botData = data.GetOrCreateMemberData(bot.ID); + if (interacterId is null) { - return CheckInteractions(action, guild, roles, targetMember, botMember, botMember); + return CheckInteractions(action, guild, roles, targetData, botData, botData); } - var interacterResult = await _guildApi.GetGuildMemberAsync(guildId, interacterId.Value, ct); - if (!interacterResult.IsDefined(out var interacter)) - { - return Result.FromError(interacterResult); - } - - var data = await _data.GetData(guildId, ct); - - var hasPermission = CheckPermission(roles, data, interacterId.Value, interacter, + var interacterData = data.GetOrCreateMemberData(interacterId.Value); + var hasPermission = CheckPermission(roles, data, interacterData, action switch { "Ban" => DiscordPermission.BanMembers, @@ -121,31 +105,26 @@ public sealed class AccessControlService }); return hasPermission - ? CheckInteractions(action, guild, roles, targetMember, botMember, interacter) + ? CheckInteractions(action, guild, roles, targetData, botData, interacterData) : Result.FromSuccess($"UserCannot{action}Members".Localized()); } private static Result CheckInteractions( - string action, IGuild guild, IReadOnlyList roles, IGuildMember targetMember, IGuildMember botMember, - IGuildMember interacter) + string action, IGuild guild, IReadOnlyList roles, MemberData targetData, MemberData botData, + MemberData interacterData) { - if (!targetMember.User.IsDefined(out var targetUser)) - { - return new ArgumentNullError(nameof(targetMember.User)); - } - - if (botMember.User == targetMember.User) + if (botData.Id == targetData.Id) { return Result.FromSuccess($"UserCannot{action}Bot".Localized()); } - if (targetUser.ID == guild.OwnerID) + if (targetData.Id == guild.OwnerID) { return Result.FromSuccess($"UserCannot{action}Owner".Localized()); } - var targetRoles = roles.Where(r => targetMember.Roles.Contains(r.ID)).ToList(); - var botRoles = roles.Where(r => botMember.Roles.Contains(r.ID)); + var targetRoles = roles.Where(r => targetData.Roles.Contains(r.ID.Value)).ToList(); + var botRoles = roles.Where(r => botData.Roles.Contains(r.ID.Value)); var targetBotRoleDiff = targetRoles.MaxOrDefault(r => r.Position) - botRoles.MaxOrDefault(r => r.Position); if (targetBotRoleDiff >= 0) @@ -153,7 +132,7 @@ public sealed class AccessControlService return Result.FromSuccess($"BotCannot{action}Target".Localized()); } - var interacterRoles = roles.Where(r => interacter.Roles.Contains(r.ID)); + var interacterRoles = roles.Where(r => interacterData.Roles.Contains(r.ID.Value)); var targetInteracterRoleDiff = targetRoles.MaxOrDefault(r => r.Position) - interacterRoles.MaxOrDefault(r => r.Position); return targetInteracterRoleDiff < 0 From daef4f1d48874b9f2cec25fad70414061f46aa0c Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Thu, 30 May 2024 15:32:27 +0500 Subject: [PATCH 17/42] Upgrade NuGet dependencies (#313) Signed-off-by: Octol1ttle --- .../Extensions/ChannelApiExtensions.cs | 7 ++++--- TeamOctolings.Octobot/TeamOctolings.Octobot.csproj | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/TeamOctolings.Octobot/Extensions/ChannelApiExtensions.cs b/TeamOctolings.Octobot/Extensions/ChannelApiExtensions.cs index 2767f96..82f8889 100644 --- a/TeamOctolings.Octobot/Extensions/ChannelApiExtensions.cs +++ b/TeamOctolings.Octobot/Extensions/ChannelApiExtensions.cs @@ -12,11 +12,12 @@ public static class ChannelApiExtensions public static async Task CreateMessageWithEmbedResultAsync(this IDiscordRestChannelAPI channelApi, Snowflake channelId, Optional message = default, Optional nonce = default, Optional isTextToSpeech = default, Optional> embedResult = default, - Optional allowedMentions = default, Optional messageRefenence = default, + Optional allowedMentions = default, Optional messageReference = default, Optional> components = default, Optional> stickerIds = default, Optional>> attachments = default, - Optional flags = default, CancellationToken ct = default) + Optional flags = default, Optional enforceNonce = default, + Optional poll = default, CancellationToken ct = default) { if (!embedResult.IsDefined() || !embedResult.Value.IsDefined(out var embed)) { @@ -24,6 +25,6 @@ public static class ChannelApiExtensions } return (Result)await channelApi.CreateMessageAsync(channelId, message, nonce, isTextToSpeech, new[] { embed }, - allowedMentions, messageRefenence, components, stickerIds, attachments, flags, ct); + allowedMentions, messageReference, components, stickerIds, attachments, flags, enforceNonce, poll, ct); } } diff --git a/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj b/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj index 9c3d58b..19e37f9 100644 --- a/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj +++ b/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj @@ -22,16 +22,16 @@ - + - - - - + + + + From 29a1eb986987d9a633b1acf21fc8b74598e3f04e Mon Sep 17 00:00:00 2001 From: Fakeintxsh <95250141+mctaylors@users.noreply.github.com> Date: Fri, 31 May 2024 21:46:12 +0500 Subject: [PATCH 18/42] Add description to /clear's author to clarify its functionality (#315) Closes #314 What? The title speaks for itself. --- TeamOctolings.Octobot/Commands/ClearCommandGroup.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/TeamOctolings.Octobot/Commands/ClearCommandGroup.cs b/TeamOctolings.Octobot/Commands/ClearCommandGroup.cs index 38d864b..7c1b516 100644 --- a/TeamOctolings.Octobot/Commands/ClearCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/ClearCommandGroup.cs @@ -64,6 +64,7 @@ public sealed class ClearCommandGroup : CommandGroup public async Task ExecuteClear( [Description("Number of messages to remove (2-100)")] [MinValue(2)] [MaxValue(100)] int amount, + [Description("Ignore messages except from the specified author")] IUser? author = null) { if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var executorId)) From 2b0c4b62d3e8af97ff96215d6e6b05aa3f44b323 Mon Sep 17 00:00:00 2001 From: Fakeintxsh <95250141+mctaylors@users.noreply.github.com> Date: Tue, 11 Jun 2024 09:28:06 +0300 Subject: [PATCH 19/42] README: Refer to the Octobot's Wiki in Building Octobot (#316) Signed-off-by: Fakeintxsh <95250141+mctaylors@users.noreply.github.com> --- docs/README.md | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/docs/README.md b/docs/README.md index 7056857..ccc3b83 100644 --- a/docs/README.md +++ b/docs/README.md @@ -15,23 +15,16 @@ Veemo! I'm a general-purpose bot for moderation (formerly known as Boyfriend) wr * Reminding everyone about that new event you made * Renaming those annoying self-hoisting members * Log everything from joining the server to deleting messages -* Listen to music! +* Listen to Inkantation! *...a-a-and more!* ## Building Octobot -1. Install [.NET 8 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) -2. Go to the [Discord Developer Portal](https://discord.com/developers), create a new application and get a bot token. Don't forget to also enable all intents! -3. Clone this repository and open `Octobot` folder. -``` -git clone https://github.com/TeamOctolings/Octobot -cd Octobot -``` -4. Run Octobot using `dotnet` with `BOT_TOKEN` variable. -``` -dotnet run BOT_TOKEN='ENTER_TOKEN_HERE' -``` +Check out the Octobot's Wiki for details. + +| [Windows](https://github.com/TeamOctolings/Octobot/wiki/Installing-Windows) | [Linux/macOS](https://github.com/TeamOctolings/Octobot/wiki/Installing-Unix) | +| --- | --- | ## Contributing From a953053f1d7ad7012f80d2bb338c7ee107e5bf9c Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Sat, 22 Jun 2024 00:28:29 +0500 Subject: [PATCH 20/42] Handle audit log entries for message deletion being empty (#317) In order to determine who deleted a message, Octobot fetches the audit log with a filter on the action "Message Delete", gets the latest entry and uses its author if the timestamps roughly match. However, if the filter returns no entries (as in, no message deletions are present in the audit log), `Single()` will throw an exception with the message `Sequence contains no elements`. To fix this, this PR replaces `Single()` with `SingleOrDefault()` and adds a null-check on `auditLog` in the form of a pattern access Signed-off-by: Octol1ttle --- TeamOctolings.Octobot/Responders/MessageDeletedResponder.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TeamOctolings.Octobot/Responders/MessageDeletedResponder.cs b/TeamOctolings.Octobot/Responders/MessageDeletedResponder.cs index 88a8de2..f0e3d22 100644 --- a/TeamOctolings.Octobot/Responders/MessageDeletedResponder.cs +++ b/TeamOctolings.Octobot/Responders/MessageDeletedResponder.cs @@ -66,10 +66,10 @@ public sealed class MessageDeletedResponder : IResponder return ResultExtensions.FromError(auditLogResult); } - var auditLog = auditLogPage.AuditLogEntries.Single(); - var deleterResult = Result.FromSuccess(message.Author); - if (auditLog.UserID is not null + + var auditLog = auditLogPage.AuditLogEntries.SingleOrDefault(); + if (auditLog is { UserID: not null } && auditLog.Options.Value.ChannelID == gatewayEvent.ChannelID && DateTimeOffset.UtcNow.Subtract(auditLog.ID.Timestamp).TotalSeconds <= 2) { From a0e7b3a6116c6ff44e1ea2877ffb33d35b931bf8 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Tue, 25 Jun 2024 15:09:45 +0500 Subject: [PATCH 21/42] 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 --- TeamOctolings.Octobot/Commands/InfoCommandGroup.cs | 2 +- TeamOctolings.Octobot/Commands/MuteCommandGroup.cs | 6 +++--- TeamOctolings.Octobot/Commands/RemindCommandGroup.cs | 4 ++-- TeamOctolings.Octobot/Commands/ToolsCommandGroup.cs | 6 +++--- .../Responders/GuildLoadedResponder.cs | 2 +- .../Responders/GuildMemberJoinedResponder.cs | 2 +- TeamOctolings.Octobot/Services/GuildDataService.cs | 4 ++-- .../Services/Update/MemberUpdateService.cs | 12 ++++++------ .../Services/Update/ScheduledEventUpdateService.cs | 12 ++++++------ TeamOctolings.Octobot/Utility.cs | 2 +- 10 files changed, 26 insertions(+), 26 deletions(-) diff --git a/TeamOctolings.Octobot/Commands/InfoCommandGroup.cs b/TeamOctolings.Octobot/Commands/InfoCommandGroup.cs index d7798f3..f07b210 100644 --- a/TeamOctolings.Octobot/Commands/InfoCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/InfoCommandGroup.cs @@ -288,7 +288,7 @@ public sealed class InfoCommandGroup : CommandGroup return await ShowGuildInfoAsync(bot, guild, CancellationToken); } - private Task ShowGuildInfoAsync(IUser bot, IGuild guild, CancellationToken ct) + private Task ShowGuildInfoAsync(IUser bot, IGuild guild, CancellationToken ct = default) { var description = new StringBuilder().AppendLine($"## {guild.Name}"); diff --git a/TeamOctolings.Octobot/Commands/MuteCommandGroup.cs b/TeamOctolings.Octobot/Commands/MuteCommandGroup.cs index 282afe8..46e8d84 100644 --- a/TeamOctolings.Octobot/Commands/MuteCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/MuteCommandGroup.cs @@ -170,7 +170,7 @@ public sealed class MuteCommandGroup : CommandGroup private async Task 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); @@ -186,7 +186,7 @@ public sealed class MuteCommandGroup : CommandGroup private async Task 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 { muteRole }; var memberData = data.GetOrCreateMemberData(target.ID); @@ -208,7 +208,7 @@ public sealed class MuteCommandGroup : CommandGroup private async Task 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) { diff --git a/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs b/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs index bf59d67..be53ed7 100644 --- a/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs @@ -78,7 +78,7 @@ public sealed class RemindCommandGroup : CommandGroup return await ListRemindersAsync(data.GetOrCreateMemberData(executorId), guildId, executor, bot, CancellationToken); } - private Task ListRemindersAsync(MemberData data, Snowflake guildId, IUser executor, IUser bot, CancellationToken ct) + private Task ListRemindersAsync(MemberData data, Snowflake guildId, IUser executor, IUser bot, CancellationToken ct = default) { if (data.Reminders.Count == 0) { @@ -353,7 +353,7 @@ public sealed class RemindCommandGroup : CommandGroup } private Task DeleteReminderAsync(MemberData data, int index, IUser bot, - CancellationToken ct) + CancellationToken ct = default) { if (index >= data.Reminders.Count) { diff --git a/TeamOctolings.Octobot/Commands/ToolsCommandGroup.cs b/TeamOctolings.Octobot/Commands/ToolsCommandGroup.cs index b4c3488..2936392 100644 --- a/TeamOctolings.Octobot/Commands/ToolsCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/ToolsCommandGroup.cs @@ -90,7 +90,7 @@ public sealed class ToolsCommandGroup : CommandGroup } private Task SendRandomNumberAsync(long first, long? secondNullable, - IUser executor, CancellationToken ct) + IUser executor, CancellationToken ct = default) { const long secondDefault = 0; var second = secondNullable ?? secondDefault; @@ -187,7 +187,7 @@ public sealed class ToolsCommandGroup : CommandGroup return await SendTimestampAsync(offset, executor, CancellationToken); } - private Task SendTimestampAsync(TimeSpan? offset, IUser executor, CancellationToken ct) + private Task SendTimestampAsync(TimeSpan? offset, IUser executor, CancellationToken ct = default) { var timestamp = DateTimeOffset.UtcNow.Add(offset ?? TimeSpan.Zero).ToUnixTimeSeconds(); @@ -249,7 +249,7 @@ public sealed class ToolsCommandGroup : CommandGroup return await AnswerEightBallAsync(bot, CancellationToken); } - private Task AnswerEightBallAsync(IUser bot, CancellationToken ct) + private Task AnswerEightBallAsync(IUser bot, CancellationToken ct = default) { var typeNumber = Random.Shared.Next(0, 4); var embedColor = typeNumber switch diff --git a/TeamOctolings.Octobot/Responders/GuildLoadedResponder.cs b/TeamOctolings.Octobot/Responders/GuildLoadedResponder.cs index cebb1ea..b420db2 100644 --- a/TeamOctolings.Octobot/Responders/GuildLoadedResponder.cs +++ b/TeamOctolings.Octobot/Responders/GuildLoadedResponder.cs @@ -94,7 +94,7 @@ public sealed class GuildLoadedResponder : IResponder GuildSettings.PrivateFeedbackChannel.Get(cfg), embedResult: embed, ct: ct); } - private async Task SendDataLoadFailed(IGuild guild, GuildData data, IUser bot, CancellationToken ct) + private async Task SendDataLoadFailed(IGuild guild, GuildData data, IUser bot, CancellationToken ct = default) { var channelResult = await _utility.GetEmergencyFeedbackChannel(guild, data, ct); if (!channelResult.IsDefined(out var channel)) diff --git a/TeamOctolings.Octobot/Responders/GuildMemberJoinedResponder.cs b/TeamOctolings.Octobot/Responders/GuildMemberJoinedResponder.cs index c1f1da0..ae9f174 100644 --- a/TeamOctolings.Octobot/Responders/GuildMemberJoinedResponder.cs +++ b/TeamOctolings.Octobot/Responders/GuildMemberJoinedResponder.cs @@ -81,7 +81,7 @@ public sealed class GuildMemberJoinedResponder : IResponder } private async Task 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)) { diff --git a/TeamOctolings.Octobot/Services/GuildDataService.cs b/TeamOctolings.Octobot/Services/GuildDataService.cs index 866ee08..a7af7c9 100644 --- a/TeamOctolings.Octobot/Services/GuildDataService.cs +++ b/TeamOctolings.Octobot/Services/GuildDataService.cs @@ -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(); var datas = _datas.Values.ToArray(); @@ -44,7 +44,7 @@ public sealed class GuildDataService : BackgroundService return Task.WhenAll(tasks); } - private static async Task SerializeObjectSafelyAsync(T obj, string path, CancellationToken ct) + private static async Task SerializeObjectSafelyAsync(T obj, string path, CancellationToken ct = default) { var tempFilePath = path + ".tmp"; await using (var tempFileStream = File.Create(tempFilePath)) diff --git a/TeamOctolings.Octobot/Services/Update/MemberUpdateService.cs b/TeamOctolings.Octobot/Services/Update/MemberUpdateService.cs index 51cf647..0c49c24 100644 --- a/TeamOctolings.Octobot/Services/Update/MemberUpdateService.cs +++ b/TeamOctolings.Octobot/Services/Update/MemberUpdateService.cs @@ -62,7 +62,7 @@ public sealed partial class MemberUpdateService : BackgroundService } } - private async Task TickMemberDatasAsync(Snowflake guildId, CancellationToken ct) + private async Task 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 TickMemberDataAsync(Snowflake guildId, GuildData guildData, Snowflake defaultRole, MemberData data, - CancellationToken ct) + CancellationToken ct = default) { var failedResults = new List(); var id = data.Id.ToSnowflake(); @@ -144,7 +144,7 @@ public sealed partial class MemberUpdateService : BackgroundService } private async Task 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 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 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 TickReminderAsync(Reminder reminder, IUser user, MemberData data, Snowflake guildId, - CancellationToken ct) + CancellationToken ct = default) { if (DateTimeOffset.UtcNow < reminder.At) { diff --git a/TeamOctolings.Octobot/Services/Update/ScheduledEventUpdateService.cs b/TeamOctolings.Octobot/Services/Update/ScheduledEventUpdateService.cs index ce9c212..ef145aa 100644 --- a/TeamOctolings.Octobot/Services/Update/ScheduledEventUpdateService.cs +++ b/TeamOctolings.Octobot/Services/Update/ScheduledEventUpdateService.cs @@ -46,7 +46,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService } } - private async Task TickScheduledEventsAsync(Snowflake guildId, CancellationToken ct) + private async Task TickScheduledEventsAsync(Snowflake guildId, CancellationToken ct = default) { var failedResults = new List(); var data = await _guildData.GetData(guildId, ct); @@ -133,7 +133,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService private async Task 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 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 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 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 SendEarlyEventNotificationAsync( - IGuildScheduledEvent scheduledEvent, GuildData data, CancellationToken ct) + IGuildScheduledEvent scheduledEvent, GuildData data, CancellationToken ct = default) { if (GuildSettings.EventNotificationChannel.Get(data.Settings).Empty()) { diff --git a/TeamOctolings.Octobot/Utility.cs b/TeamOctolings.Octobot/Utility.cs index 463212b..f337d93 100644 --- a/TeamOctolings.Octobot/Utility.cs +++ b/TeamOctolings.Octobot/Utility.cs @@ -125,7 +125,7 @@ public sealed class Utility } } - public async Task> GetEmergencyFeedbackChannel(IGuild guild, GuildData data, CancellationToken ct) + public async Task> GetEmergencyFeedbackChannel(IGuild guild, GuildData data, CancellationToken ct = default) { var privateFeedback = GuildSettings.PrivateFeedbackChannel.Get(data.Settings); if (!privateFeedback.Empty()) From 930b7ca6eda76a09883296d8657cf82a4e3e2d21 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Wed, 3 Jul 2024 22:09:39 +0500 Subject: [PATCH 22/42] Bump InspectCode from 1.11.10 to 1.11.12 (#323) I <3 breaking changes. --- .github/workflows/build-pr.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index c92386e..b2991db 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -22,8 +22,13 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.0.301' + - name: ReSharper CLI InspectCode - uses: muno92/resharper_inspectcode@1.11.10 + uses: muno92/resharper_inspectcode@1.11.12 with: solutionPath: ./Octobot.sln ignoreIssueType: InvertIf, ConvertIfStatementToSwitchStatement, ConvertToPrimaryConstructor From 07e8784d2e10e0db5dd8b1645b95d674dfbaa1a6 Mon Sep 17 00:00:00 2001 From: Macintxsh <95250141+mctaylors@users.noreply.github.com> Date: Wed, 3 Jul 2024 22:12:32 +0500 Subject: [PATCH 23/42] Redesign reminder-related commands (#321) In this PR, I redesigned the reminder-related commands and they will now have a quote block instead of a inline code block (to avoid some visual bugs). Except /listremind. It just has the inline code block removed. ![image](https://github.com/TeamOctolings/Octobot/assets/95250141/3521af97-ee11-405f-8cc2-7bf9a747e757) --- TeamOctolings.Octobot/Commands/RemindCommandGroup.cs | 10 +++++----- .../Extensions/MarkdownExtensions.cs | 12 ++++++++++++ .../Services/Update/MemberUpdateService.cs | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs b/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs index be53ed7..3188d27 100644 --- a/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/RemindCommandGroup.cs @@ -94,7 +94,7 @@ public sealed class RemindCommandGroup : CommandGroup { var reminder = data.Reminders[i]; builder.AppendBulletPointLine(string.Format(Messages.ReminderPosition, Markdown.InlineCode((i + 1).ToString()))) - .AppendSubBulletPointLine(string.Format(Messages.ReminderText, Markdown.InlineCode(reminder.Text))) + .AppendSubBulletPointLine(string.Format(Messages.ReminderText, reminder.Text)) .AppendSubBulletPointLine(string.Format(Messages.ReminderTime, Markdown.Timestamp(reminder.At))) .AppendSubBulletPointLine(string.Format(Messages.DescriptionActionJumpToMessage, $"https://discord.com/channels/{guildId.Value}/{reminder.ChannelId}/{reminder.MessageId}")); } @@ -182,7 +182,7 @@ public sealed class RemindCommandGroup : CommandGroup }); var builder = new StringBuilder() - .AppendBulletPointLine(string.Format(Messages.ReminderText, Markdown.InlineCode(text))) + .AppendLine(MarkdownExtensions.Quote(text)) .AppendBulletPoint(string.Format(Messages.ReminderTime, Markdown.Timestamp(remindAt))); var embed = new EmbedBuilder().WithSmallTitle( string.Format(Messages.ReminderCreated, executor.GetTag()), executor) @@ -279,7 +279,7 @@ public sealed class RemindCommandGroup : CommandGroup data.Reminders.RemoveAt(index); var builder = new StringBuilder() - .AppendBulletPointLine(string.Format(Messages.ReminderText, Markdown.InlineCode(oldReminder.Text))) + .AppendLine(MarkdownExtensions.Quote(oldReminder.Text)) .AppendBulletPoint(string.Format(Messages.ReminderTime, Markdown.Timestamp(remindAt))); var embed = new EmbedBuilder().WithSmallTitle( string.Format(Messages.ReminderEdited, executor.GetTag()), executor) @@ -309,7 +309,7 @@ public sealed class RemindCommandGroup : CommandGroup data.Reminders.RemoveAt(index); var builder = new StringBuilder() - .AppendBulletPointLine(string.Format(Messages.ReminderText, Markdown.InlineCode(value))) + .AppendLine(MarkdownExtensions.Quote(value)) .AppendBulletPoint(string.Format(Messages.ReminderTime, Markdown.Timestamp(oldReminder.At))); var embed = new EmbedBuilder().WithSmallTitle( string.Format(Messages.ReminderEdited, executor.GetTag()), executor) @@ -367,7 +367,7 @@ public sealed class RemindCommandGroup : CommandGroup var reminder = data.Reminders[index]; var description = new StringBuilder() - .AppendBulletPointLine(string.Format(Messages.ReminderText, Markdown.InlineCode(reminder.Text))) + .AppendLine(MarkdownExtensions.Quote(reminder.Text)) .AppendBulletPointLine(string.Format(Messages.ReminderTime, Markdown.Timestamp(reminder.At))); data.Reminders.RemoveAt(index); diff --git a/TeamOctolings.Octobot/Extensions/MarkdownExtensions.cs b/TeamOctolings.Octobot/Extensions/MarkdownExtensions.cs index 202cd37..30ddff5 100644 --- a/TeamOctolings.Octobot/Extensions/MarkdownExtensions.cs +++ b/TeamOctolings.Octobot/Extensions/MarkdownExtensions.cs @@ -13,4 +13,16 @@ public static class MarkdownExtensions { return $"- {text}"; } + + /// + /// Formats a string to use Markdown Quote formatting. + /// + /// The input text to format. + /// + /// A markdown-formatted quote string. + /// + public static string Quote(string text) + { + return $"> {text}"; + } } diff --git a/TeamOctolings.Octobot/Services/Update/MemberUpdateService.cs b/TeamOctolings.Octobot/Services/Update/MemberUpdateService.cs index 0c49c24..3170060 100644 --- a/TeamOctolings.Octobot/Services/Update/MemberUpdateService.cs +++ b/TeamOctolings.Octobot/Services/Update/MemberUpdateService.cs @@ -234,7 +234,7 @@ public sealed partial class MemberUpdateService : BackgroundService } var builder = new StringBuilder() - .AppendBulletPointLine(string.Format(Messages.DescriptionReminder, Markdown.InlineCode(reminder.Text))) + .AppendLine(MarkdownExtensions.Quote(reminder.Text)) .AppendBulletPointLine(string.Format(Messages.DescriptionActionJumpToMessage, $"https://discord.com/channels/{guildId.Value}/{reminder.ChannelId}/{reminder.MessageId}")); From d6d2660fb02b8eb3979f2acc16869d037c7d8b04 Mon Sep 17 00:00:00 2001 From: Macintxsh <95250141+mctaylors@users.noreply.github.com> Date: Wed, 31 Jul 2024 12:13:29 +0300 Subject: [PATCH 24/42] Show an error when entering the same value from the settings (#326) Closes #324 --- .../Commands/SettingsCommandGroup.cs | 21 +++++++++++++++++++ .../Data/Options/BoolOption.cs | 10 +++++++++ .../Data/Options/GuildOption.cs | 12 ++++++++++- .../Data/Options/IGuildOption.cs | 1 + .../Data/Options/LanguageOption.cs | 5 ++--- .../Data/Options/TimeSpanOption.cs | 10 +++++++++ TeamOctolings.Octobot/Messages.Designer.cs | 6 ++++++ TeamOctolings.Octobot/Messages.resx | 3 +++ TeamOctolings.Octobot/Messages.ru.resx | 3 +++ 9 files changed, 67 insertions(+), 4 deletions(-) diff --git a/TeamOctolings.Octobot/Commands/SettingsCommandGroup.cs b/TeamOctolings.Octobot/Commands/SettingsCommandGroup.cs index 0acaa88..15aa42b 100644 --- a/TeamOctolings.Octobot/Commands/SettingsCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/SettingsCommandGroup.cs @@ -202,6 +202,27 @@ public sealed class SettingsCommandGroup : CommandGroup IGuildOption option, string value, GuildData data, Snowflake channelId, IUser executor, IUser bot, CancellationToken ct = default) { + var equalsResult = option.ValueEquals(data.Settings, value); + if (!equalsResult.IsSuccess) + { + var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.SettingNotChanged, bot) + .WithDescription(equalsResult.Error.Message) + .WithColour(ColorsList.Red) + .Build(); + + return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct: ct); + } + + if (equalsResult.Entity) + { + var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.SettingNotChanged, bot) + .WithDescription(Messages.SettingValueEquals) + .WithColour(ColorsList.Red) + .Build(); + + return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct: ct); + } + var setResult = option.Set(data.Settings, value); if (!setResult.IsSuccess) { diff --git a/TeamOctolings.Octobot/Data/Options/BoolOption.cs b/TeamOctolings.Octobot/Data/Options/BoolOption.cs index 6a3c899..3b81abb 100644 --- a/TeamOctolings.Octobot/Data/Options/BoolOption.cs +++ b/TeamOctolings.Octobot/Data/Options/BoolOption.cs @@ -12,6 +12,16 @@ public sealed class BoolOption : GuildOption return Get(settings) ? Messages.Yes : Messages.No; } + public override Result ValueEquals(JsonNode settings, string value) + { + if (!TryParseBool(value, out var boolean)) + { + return new ArgumentInvalidError(nameof(value), Messages.InvalidSettingValue); + } + + return Value(settings).Equals(boolean.ToString()); + } + public override Result Set(JsonNode settings, string from) { if (!TryParseBool(from, out var value)) diff --git a/TeamOctolings.Octobot/Data/Options/GuildOption.cs b/TeamOctolings.Octobot/Data/Options/GuildOption.cs index 5d9f1a2..ea9c30e 100644 --- a/TeamOctolings.Octobot/Data/Options/GuildOption.cs +++ b/TeamOctolings.Octobot/Data/Options/GuildOption.cs @@ -21,9 +21,19 @@ public class GuildOption : IGuildOption public string Name { get; } + protected virtual string Value(JsonNode settings) + { + return Get(settings).ToString() ?? throw new InvalidOperationException(); + } + public virtual string Display(JsonNode settings) { - return Markdown.InlineCode(Get(settings).ToString() ?? throw new InvalidOperationException()); + return Markdown.InlineCode(Value(settings)); + } + + public virtual Result ValueEquals(JsonNode settings, string value) + { + return Value(settings).Equals(value); } /// diff --git a/TeamOctolings.Octobot/Data/Options/IGuildOption.cs b/TeamOctolings.Octobot/Data/Options/IGuildOption.cs index a8c3e6e..9920281 100644 --- a/TeamOctolings.Octobot/Data/Options/IGuildOption.cs +++ b/TeamOctolings.Octobot/Data/Options/IGuildOption.cs @@ -7,6 +7,7 @@ public interface IGuildOption { string Name { get; } string Display(JsonNode settings); + Result ValueEquals(JsonNode settings, string value); Result Set(JsonNode settings, string from); Result Reset(JsonNode settings); } diff --git a/TeamOctolings.Octobot/Data/Options/LanguageOption.cs b/TeamOctolings.Octobot/Data/Options/LanguageOption.cs index 15ab6ff..f58e011 100644 --- a/TeamOctolings.Octobot/Data/Options/LanguageOption.cs +++ b/TeamOctolings.Octobot/Data/Options/LanguageOption.cs @@ -1,6 +1,5 @@ using System.Globalization; using System.Text.Json.Nodes; -using Remora.Discord.Extensions.Formatting; using Remora.Results; namespace TeamOctolings.Octobot.Data.Options; @@ -16,9 +15,9 @@ public sealed class LanguageOption : GuildOption public LanguageOption(string name, string defaultValue) : base(name, CultureInfoCache[defaultValue]) { } - public override string Display(JsonNode settings) + protected override string Value(JsonNode settings) { - return Markdown.InlineCode(settings[Name]?.GetValue() ?? "en"); + return settings[Name]?.GetValue() ?? "en"; } /// diff --git a/TeamOctolings.Octobot/Data/Options/TimeSpanOption.cs b/TeamOctolings.Octobot/Data/Options/TimeSpanOption.cs index 3501f09..7e21343 100644 --- a/TeamOctolings.Octobot/Data/Options/TimeSpanOption.cs +++ b/TeamOctolings.Octobot/Data/Options/TimeSpanOption.cs @@ -8,6 +8,16 @@ public sealed class TimeSpanOption : GuildOption { public TimeSpanOption(string name, TimeSpan defaultValue) : base(name, defaultValue) { } + public override Result ValueEquals(JsonNode settings, string value) + { + if (!TimeSpanParser.TryParse(value).IsDefined(out var span)) + { + return new ArgumentInvalidError(nameof(value), Messages.InvalidSettingValue); + } + + return Value(settings).Equals(span.ToString()); + } + public override TimeSpan Get(JsonNode settings) { var property = settings[Name]; diff --git a/TeamOctolings.Octobot/Messages.Designer.cs b/TeamOctolings.Octobot/Messages.Designer.cs index bbc1366..ce59f1e 100644 --- a/TeamOctolings.Octobot/Messages.Designer.cs +++ b/TeamOctolings.Octobot/Messages.Designer.cs @@ -1196,5 +1196,11 @@ namespace TeamOctolings.Octobot { return ResourceManager.GetString("SettingsModeratorRole", resourceCulture); } } + + internal static string SettingValueEquals { + get { + return ResourceManager.GetString("SettingValueEquals", resourceCulture); + } + } } } diff --git a/TeamOctolings.Octobot/Messages.resx b/TeamOctolings.Octobot/Messages.resx index 47e7d4f..059584a 100644 --- a/TeamOctolings.Octobot/Messages.resx +++ b/TeamOctolings.Octobot/Messages.resx @@ -681,4 +681,7 @@ Moderator role + + The setting value is the same as the input value. + diff --git a/TeamOctolings.Octobot/Messages.ru.resx b/TeamOctolings.Octobot/Messages.ru.resx index 2eef257..fc8a594 100644 --- a/TeamOctolings.Octobot/Messages.ru.resx +++ b/TeamOctolings.Octobot/Messages.ru.resx @@ -681,4 +681,7 @@ Роль модератора + + Значение настройки такое же, как и вводное значение. + From e457b4609ed7630ac8920cea90c9e1282b4914ca Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Wed, 31 Jul 2024 23:57:21 +0500 Subject: [PATCH 25/42] Don't log stack traces for cancelled operations (#327) This PR fixes an issue where the `LogResultStackTrace` method would log stack traces for results that encountered an error due to a cancelled operation/task. The `LoggerExtensions` class already skipped `TaskCanceledException`s, but didn't skip `OperationCanceledException`s (which is a parent of `TaskCanceledException`). The patch specifically does not affect *inner* results which are canceled. Skipping logging these could hide the true cause of an error which appears important --- TeamOctolings.Octobot/Extensions/LoggerExtensions.cs | 2 +- TeamOctolings.Octobot/Extensions/ResultExtensions.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TeamOctolings.Octobot/Extensions/LoggerExtensions.cs b/TeamOctolings.Octobot/Extensions/LoggerExtensions.cs index 76fa386..fac4dda 100644 --- a/TeamOctolings.Octobot/Extensions/LoggerExtensions.cs +++ b/TeamOctolings.Octobot/Extensions/LoggerExtensions.cs @@ -25,7 +25,7 @@ public static class LoggerExtensions if (result.Error is ExceptionError exe) { - if (exe.Exception is TaskCanceledException) + if (exe.Exception is OperationCanceledException) { return; } diff --git a/TeamOctolings.Octobot/Extensions/ResultExtensions.cs b/TeamOctolings.Octobot/Extensions/ResultExtensions.cs index d7ef7d7..6872d34 100644 --- a/TeamOctolings.Octobot/Extensions/ResultExtensions.cs +++ b/TeamOctolings.Octobot/Extensions/ResultExtensions.cs @@ -23,7 +23,7 @@ public static class ResultExtensions private static void LogResultStackTrace(Result result) { - if (result.IsSuccess) + if (result.IsSuccess || result.Error is ExceptionError { Exception: OperationCanceledException }) { return; } From d1133124b8eaddb7f9a6891ef9bd678de0a046f0 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Sat, 24 Aug 2024 20:48:47 +0500 Subject: [PATCH 26/42] Apply new inspection fixes (#329) Rider and R# 2024.2 have introduced new inspections, causing current builds to fail. This PR applies fixes for issues caught by these inspections. --- TeamOctolings.Octobot/Commands/AboutCommandGroup.cs | 2 +- TeamOctolings.Octobot/Commands/BanCommandGroup.cs | 4 ++-- TeamOctolings.Octobot/Commands/ClearCommandGroup.cs | 2 +- .../Commands/Events/ErrorLoggingPostExecutionEvent.cs | 2 +- TeamOctolings.Octobot/Commands/KickCommandGroup.cs | 2 +- TeamOctolings.Octobot/Commands/MuteCommandGroup.cs | 4 ++-- TeamOctolings.Octobot/Data/Reminder.cs | 10 +++++----- .../Responders/GuildLoadedResponder.cs | 2 +- .../Services/Update/ScheduledEventUpdateService.cs | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/TeamOctolings.Octobot/Commands/AboutCommandGroup.cs b/TeamOctolings.Octobot/Commands/AboutCommandGroup.cs index dbb8b12..4575259 100644 --- a/TeamOctolings.Octobot/Commands/AboutCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/AboutCommandGroup.cs @@ -131,7 +131,7 @@ public sealed class AboutCommandGroup : CommandGroup return await _feedback.SendContextualEmbedResultAsync(embed, new FeedbackMessageOptions(MessageComponents: new[] { - new ActionRowComponent(new[] { repositoryButton, wikiButton, issuesButton }) + new ActionRowComponent([repositoryButton, wikiButton, issuesButton]) }), ct); } } diff --git a/TeamOctolings.Octobot/Commands/BanCommandGroup.cs b/TeamOctolings.Octobot/Commands/BanCommandGroup.cs index 69be80f..1d6b26c 100644 --- a/TeamOctolings.Octobot/Commands/BanCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/BanCommandGroup.cs @@ -62,7 +62,7 @@ public sealed class BanCommandGroup : CommandGroup /// /// /// A feedback sending result which may or may not have succeeded. A successful result does not mean that the user - /// was banned and vice-versa. + /// was banned and vice versa. /// /// [Command("ban", "бан")] @@ -219,7 +219,7 @@ public sealed class BanCommandGroup : CommandGroup /// /// /// A feedback sending result which may or may not have succeeded. A successful result does not mean that the user - /// was unbanned and vice-versa. + /// was unbanned and vice versa. /// /// /// diff --git a/TeamOctolings.Octobot/Commands/ClearCommandGroup.cs b/TeamOctolings.Octobot/Commands/ClearCommandGroup.cs index 7c1b516..7f29581 100644 --- a/TeamOctolings.Octobot/Commands/ClearCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/ClearCommandGroup.cs @@ -51,7 +51,7 @@ public sealed class ClearCommandGroup : CommandGroup /// The user whose messages will be cleared. /// /// A feedback sending result which may or may not have succeeded. A successful result does not mean that any messages - /// were cleared and vice-versa. + /// were cleared and vice versa. /// [Command("clear", "очистить")] [DiscordDefaultMemberPermissions(DiscordPermission.ManageMessages)] diff --git a/TeamOctolings.Octobot/Commands/Events/ErrorLoggingPostExecutionEvent.cs b/TeamOctolings.Octobot/Commands/Events/ErrorLoggingPostExecutionEvent.cs index 7409d3b..ff7339f 100644 --- a/TeamOctolings.Octobot/Commands/Events/ErrorLoggingPostExecutionEvent.cs +++ b/TeamOctolings.Octobot/Commands/Events/ErrorLoggingPostExecutionEvent.cs @@ -81,7 +81,7 @@ public sealed class ErrorLoggingPostExecutionEvent : IPostExecutionEvent return ResultExtensions.FromError(await _feedback.SendContextualEmbedResultAsync(embed, new FeedbackMessageOptions(MessageComponents: new[] { - new ActionRowComponent(new[] { issuesButton }) + new ActionRowComponent([issuesButton]) }), ct) ); } diff --git a/TeamOctolings.Octobot/Commands/KickCommandGroup.cs b/TeamOctolings.Octobot/Commands/KickCommandGroup.cs index a8fea2a..3011375 100644 --- a/TeamOctolings.Octobot/Commands/KickCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/KickCommandGroup.cs @@ -57,7 +57,7 @@ public sealed class KickCommandGroup : CommandGroup /// /// /// A feedback sending result which may or may not have succeeded. A successful result does not mean that the member - /// was kicked and vice-versa. + /// was kicked and vice versa. /// [Command("kick", "кик")] [DiscordDefaultMemberPermissions(DiscordPermission.ManageMessages)] diff --git a/TeamOctolings.Octobot/Commands/MuteCommandGroup.cs b/TeamOctolings.Octobot/Commands/MuteCommandGroup.cs index 46e8d84..5dce0b6 100644 --- a/TeamOctolings.Octobot/Commands/MuteCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/MuteCommandGroup.cs @@ -59,7 +59,7 @@ public sealed class MuteCommandGroup : CommandGroup /// /// /// A feedback sending result which may or may not have succeeded. A successful result does not mean that the member - /// was muted and vice-versa. + /// was muted and vice versa. /// /// [Command("mute", "мут")] @@ -235,7 +235,7 @@ public sealed class MuteCommandGroup : CommandGroup /// /// /// A feedback sending result which may or may not have succeeded. A successful result does not mean that the member - /// was unmuted and vice-versa. + /// was unmuted and vice versa. /// /// /// diff --git a/TeamOctolings.Octobot/Data/Reminder.cs b/TeamOctolings.Octobot/Data/Reminder.cs index c3936da..40f29e1 100644 --- a/TeamOctolings.Octobot/Data/Reminder.cs +++ b/TeamOctolings.Octobot/Data/Reminder.cs @@ -1,9 +1,9 @@ namespace TeamOctolings.Octobot.Data; -public struct Reminder +public sealed record Reminder { - public DateTimeOffset At { get; init; } - public string Text { get; init; } - public ulong ChannelId { get; init; } - public ulong MessageId { get; init; } + public required DateTimeOffset At { get; init; } + public required string Text { get; init; } + public required ulong ChannelId { get; init; } + public required ulong MessageId { get; init; } } diff --git a/TeamOctolings.Octobot/Responders/GuildLoadedResponder.cs b/TeamOctolings.Octobot/Responders/GuildLoadedResponder.cs index b420db2..b24ef0b 100644 --- a/TeamOctolings.Octobot/Responders/GuildLoadedResponder.cs +++ b/TeamOctolings.Octobot/Responders/GuildLoadedResponder.cs @@ -120,6 +120,6 @@ public sealed class GuildLoadedResponder : IResponder ); return await _channelApi.CreateMessageWithEmbedResultAsync(channel, embedResult: errorEmbed, - components: new[] { new ActionRowComponent(new[] { issuesButton }) }, ct: ct); + components: new[] { new ActionRowComponent([issuesButton]) }, ct: ct); } } diff --git a/TeamOctolings.Octobot/Services/Update/ScheduledEventUpdateService.cs b/TeamOctolings.Octobot/Services/Update/ScheduledEventUpdateService.cs index ef145aa..389a6a8 100644 --- a/TeamOctolings.Octobot/Services/Update/ScheduledEventUpdateService.cs +++ b/TeamOctolings.Octobot/Services/Update/ScheduledEventUpdateService.cs @@ -229,7 +229,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService return await _channelApi.CreateMessageWithEmbedResultAsync( GuildSettings.EventNotificationChannel.Get(settings), roleMention, embedResult: embed, - components: new[] { new ActionRowComponent(new[] { button }) }, ct: ct); + components: new[] { new ActionRowComponent([button]) }, ct: ct); } private static Result GetExternalScheduledEventCreatedEmbedDescription( From afd0141c13808dd4f06fba9103b2aaebcb1e062a Mon Sep 17 00:00:00 2001 From: Macintxsh <95250141+mctaylors@users.noreply.github.com> Date: Sat, 24 Aug 2024 18:50:32 +0300 Subject: [PATCH 27/42] /about: Replace repo link with website link (#328) A some sort of UX change. Repository link will be still accessible from the website. --- TeamOctolings.Octobot/BuildInfo.cs | 4 +++- TeamOctolings.Octobot/Commands/AboutCommandGroup.cs | 4 ++-- TeamOctolings.Octobot/Messages.Designer.cs | 4 ++-- TeamOctolings.Octobot/Messages.resx | 4 ++-- TeamOctolings.Octobot/Messages.ru.resx | 4 ++-- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/TeamOctolings.Octobot/BuildInfo.cs b/TeamOctolings.Octobot/BuildInfo.cs index 4b9a09f..a91e7f3 100644 --- a/TeamOctolings.Octobot/BuildInfo.cs +++ b/TeamOctolings.Octobot/BuildInfo.cs @@ -2,7 +2,9 @@ public static class BuildInfo { - public const string RepositoryUrl = "https://github.com/TeamOctolings/Octobot"; + public const string WebsiteUrl = "https://teamoctolings.github.io/Octobot"; + + private const string RepositoryUrl = "https://github.com/TeamOctolings/Octobot"; public const string IssuesUrl = $"{RepositoryUrl}/issues"; diff --git a/TeamOctolings.Octobot/Commands/AboutCommandGroup.cs b/TeamOctolings.Octobot/Commands/AboutCommandGroup.cs index 4575259..28caccf 100644 --- a/TeamOctolings.Octobot/Commands/AboutCommandGroup.cs +++ b/TeamOctolings.Octobot/Commands/AboutCommandGroup.cs @@ -106,9 +106,9 @@ public sealed class AboutCommandGroup : CommandGroup var repositoryButton = new ButtonComponent( ButtonComponentStyle.Link, - Messages.ButtonOpenRepository, + Messages.ButtonOpenWebsite, new PartialEmoji(Name: "\ud83c\udf10"), // 'GLOBE WITH MERIDIANS' (U+1F310) - URL: BuildInfo.RepositoryUrl + URL: BuildInfo.WebsiteUrl ); var wikiButton = new ButtonComponent( diff --git a/TeamOctolings.Octobot/Messages.Designer.cs b/TeamOctolings.Octobot/Messages.Designer.cs index ce59f1e..1a81e02 100644 --- a/TeamOctolings.Octobot/Messages.Designer.cs +++ b/TeamOctolings.Octobot/Messages.Designer.cs @@ -633,9 +633,9 @@ namespace TeamOctolings.Octobot { } } - internal static string ButtonOpenRepository { + internal static string ButtonOpenWebsite { get { - return ResourceManager.GetString("ButtonOpenRepository", resourceCulture); + return ResourceManager.GetString("ButtonOpenWebsite", resourceCulture); } } diff --git a/TeamOctolings.Octobot/Messages.resx b/TeamOctolings.Octobot/Messages.resx index 059584a..e4107fb 100644 --- a/TeamOctolings.Octobot/Messages.resx +++ b/TeamOctolings.Octobot/Messages.resx @@ -399,8 +399,8 @@ Developers: - - Octobot's source code + + Open Website About {0} diff --git a/TeamOctolings.Octobot/Messages.ru.resx b/TeamOctolings.Octobot/Messages.ru.resx index fc8a594..d942cec 100644 --- a/TeamOctolings.Octobot/Messages.ru.resx +++ b/TeamOctolings.Octobot/Messages.ru.resx @@ -399,8 +399,8 @@ Разработчики: - - Исходный код Octobot + + Открыть веб-сайт О боте {0} From 0fc53990b96cf9c901790c8c936a1e70d7e0ac37 Mon Sep 17 00:00:00 2001 From: Macintxsh <95250141+mctaylors@users.noreply.github.com> Date: Sun, 25 Aug 2024 10:11:54 +0300 Subject: [PATCH 28/42] =?UTF-8?q?Update=20song=20list=20with=20new=20Splat?= =?UTF-8?q?oon=E2=84=A2=20soundtracks=20(#266)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes in the list: 1. Fly Octo Fly ~ Ebb & Flow (Octo) / Off the Hook → Spectrum Obligato ~ Ebb & Flow (Out of Order) / Off the Hook feat. Dedf1sh 2. `#47` onward / Dedf1sh feat. Off the Hook 3. EchΘ Θnslaught / Free Association 4. Short Order / Off the Hook 5. Fins in the Air / Deep Cut Signed-off-by: Macintxsh <95250141+mctaylors@users.noreply.github.com> --- TeamOctolings.Octobot/Services/Update/SongUpdateService.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/TeamOctolings.Octobot/Services/Update/SongUpdateService.cs b/TeamOctolings.Octobot/Services/Update/SongUpdateService.cs index b07256f..d0b46ae 100644 --- a/TeamOctolings.Octobot/Services/Update/SongUpdateService.cs +++ b/TeamOctolings.Octobot/Services/Update/SongUpdateService.cs @@ -29,7 +29,11 @@ public sealed class SongUpdateService : BackgroundService ("Callie", "Bomb Rush Blush", new TimeSpan(0, 2, 18)), ("Turquoise October", "Octoling Rendezvous", new TimeSpan(0, 1, 57)), ("Damp Socks feat. Off the Hook", "Tentacle to the Metal", new TimeSpan(0, 2, 51)), - ("Off the Hook", "Fly Octo Fly ~ Ebb & Flow (Octo)", new TimeSpan(0, 3, 5)) + ("Off the Hook feat. Dedf1sh", "Spectrum Obligato ~ Ebb & Flow (Out of Order)", new TimeSpan(0, 4, 30)), + ("Dedf1sh feat. Off the Hook", "#47 onward", new TimeSpan(0, 4, 40)), + ("Free Association", "EchΘ Θnslaught", new TimeSpan(0, 2, 52)), + ("Off the Hook", "Short Order", new TimeSpan(0, 3, 36)), + ("Deep Cut", "Fins in the Air", new TimeSpan(0, 3, 1)) ]; private static readonly (string Author, string Name, TimeSpan Duration)[] SpecialSongList = From 086cb672f001d3c194311371b9f16ea796201974 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Sun, 25 Aug 2024 16:03:31 +0500 Subject: [PATCH 29/42] Fix wrong private key file name (#330) The key used for deploy is Ed25519, not RSA Signed-off-by: Octol1ttle --- .github/workflows/build-push.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml index a757eb2..1b63a9d 100644 --- a/.github/workflows/build-push.yml +++ b/.github/workflows/build-push.yml @@ -27,8 +27,8 @@ jobs: - name: Setup SSH key run: | - install -m 600 -D /dev/null ~/.ssh/id_rsa - echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa + install -m 600 -D /dev/null ~/.ssh/id_ed25519 + echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519 ssh-keyscan -H $SSH_HOST > ~/.ssh/known_hosts shell: bash env: From 8028d47ba1b5de1d0dd5eb9c0eb52e90a6f70d51 Mon Sep 17 00:00:00 2001 From: Macintxsh <95250141+mctaylors@users.noreply.github.com> Date: Mon, 23 Sep 2024 21:55:58 +0300 Subject: [PATCH 30/42] Fix redundant type specification (#333) This PR fixes failing checks for #332 --- TeamOctolings.Octobot/Services/Update/SongUpdateService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TeamOctolings.Octobot/Services/Update/SongUpdateService.cs b/TeamOctolings.Octobot/Services/Update/SongUpdateService.cs index d0b46ae..8eaa4c2 100644 --- a/TeamOctolings.Octobot/Services/Update/SongUpdateService.cs +++ b/TeamOctolings.Octobot/Services/Update/SongUpdateService.cs @@ -41,7 +41,7 @@ public sealed class SongUpdateService : BackgroundService ("Squid Sisters", "Maritime Memory", new TimeSpan(0, 2, 47)) ]; - private readonly List _activityList = [new Activity("with Remora.Discord", ActivityType.Game)]; + private readonly List _activityList = [new("with Remora.Discord", ActivityType.Game)]; private readonly DiscordGatewayClient _client; private readonly GuildDataService _guildData; From 450f1da54df36611894ce23876d9bc698efdf8c8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 18:59:32 +0000 Subject: [PATCH 31/42] Bump muno92/resharper_inspectcode from 1.11.12 to 1.12.0 (#332) --- .github/workflows/build-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index b2991db..2260918 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -28,7 +28,7 @@ jobs: dotnet-version: '8.0.301' - name: ReSharper CLI InspectCode - uses: muno92/resharper_inspectcode@1.11.12 + uses: muno92/resharper_inspectcode@1.12.0 with: solutionPath: ./Octobot.sln ignoreIssueType: InvertIf, ConvertIfStatementToSwitchStatement, ConvertToPrimaryConstructor From 9e44d49039792c2b94a7a87745780b108bb22a67 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Thu, 3 Oct 2024 23:18:25 +0500 Subject: [PATCH 32/42] Update dependencies (#334) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this is supposed to be Dependabot's job, but ig something happened to it Bumps `JetBrains.Annotations` from `2023.3.0` to `2024.2.0`
Changelog • Added DefaultEqualityUsageAttribute for equality members usage analysis. • MustDisposeResourceAttribute is now allowed on struct types. • Added ability to specify the description for UsedImplicitlyAttribute (new 'Reason' property). • Added copyright information to nuspec.
Bumps `Remora.Commands` from `10.0.5` to `10.0.6`
Changelog Upgrade Remora.Sdk. Upgrade nuget packages.
Bumps `Remora.Discord.Extensions` from `5.3.5` to `5.3.6` Bumps `Remora.Discord.Interactivity` from `4.5.4` to `5.0.0`
Changelog Update dependencies. BREAKING: Rework deletion logic for data leases to prevent deadlocks.
The breaking change in Remora should not affect us. Signed-off-by: Octol1ttle --- TeamOctolings.Octobot/TeamOctolings.Octobot.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj b/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj index 19e37f9..5c6da6d 100644 --- a/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj +++ b/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj @@ -24,14 +24,14 @@ - + - + - + - + From 84dc248038241c9783dfa7b034d20d505e5f2f30 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Sun, 27 Oct 2024 21:34:01 +0500 Subject: [PATCH 33/42] Add Dockerfile and compose.yaml (#335) This PR adds Dockerfile, to run Octobot within a Docker container, and compose.yaml, to run the Octobot container along with any services that the user may require. --------- Signed-off-by: Octol1ttle Signed-off-by: mctaylors Co-authored-by: mctaylors --- .github/workflows/build-push.yml | 50 ++++++++++++++++++++------------ .gitignore | 1 + Dockerfile | 15 ++++++++++ compose.example.yaml | 17 +++++++++++ 4 files changed, 65 insertions(+), 18 deletions(-) create mode 100644 Dockerfile create mode 100644 compose.example.yaml diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml index 1b63a9d..ae355cd 100644 --- a/.github/workflows/build-push.yml +++ b/.github/workflows/build-push.yml @@ -8,29 +8,43 @@ on: branches: [ "master" ] jobs: - upload-solution: - name: Upload Octobot to production + upload-image: + name: Upload Octobot Docker image runs-on: ubuntu-latest permissions: - actions: read - contents: read + packages: write environment: production steps: - - name: Checkout repository - uses: actions/checkout@v4 + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Publish solution - run: dotnet publish $PUBLISH_FLAGS - env: - PUBLISH_FLAGS: ${{vars.PUBLISH_FLAGS}} + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + push: true + tags: ghcr.io/${{vars.NAMESPACE}}/${{vars.IMAGE_NAME}}:latest + build-args: | + BUILDKIT_CONTEXT_KEEP_GIT_DIR=1 + PUBLISH_OPTIONS=${{vars.PUBLISH_OPTIONS}} + update-production: + name: Update Octobot on production + runs-on: ubuntu-latest + environment: production + needs: upload-image + + steps: - name: Setup SSH key run: | install -m 600 -D /dev/null ~/.ssh/id_ed25519 echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519 ssh-keyscan -H $SSH_HOST > ~/.ssh/known_hosts - shell: bash + shell: bash {0} env: SSH_PRIVATE_KEY: ${{secrets.SSH_PRIVATE_KEY}} SSH_HOST: ${{secrets.SSH_HOST}} @@ -38,26 +52,26 @@ jobs: - name: Stop currently running instance run: | ssh $SSH_USER@$SSH_HOST $STOP_COMMAND - shell: bash + shell: bash {0} env: SSH_USER: ${{secrets.SSH_USER}} SSH_HOST: ${{secrets.SSH_HOST}} STOP_COMMAND: ${{vars.STOP_COMMAND}} - - name: Upload published solution + - name: Update Docker image run: | - scp -r $UPLOAD_FROM $SSH_USER@$SSH_HOST:$UPLOAD_TO - shell: bash + ssh $SSH_USER@$SSH_HOST docker pull ghcr.io/$NAMESPACE/$IMAGE_NAME:latest + shell: bash {0} env: SSH_USER: ${{secrets.SSH_USER}} SSH_HOST: ${{secrets.SSH_HOST}} - UPLOAD_FROM: ${{vars.UPLOAD_FROM}} - UPLOAD_TO: ${{vars.UPLOAD_TO}} + NAMESPACE: ${{vars.NAMESPACE}} + IMAGE_NAME: ${{vars.IMAGE_NAME}} - name: Start new instance run: | ssh $SSH_USER@$SSH_HOST $START_COMMAND - shell: bash + shell: bash {0} env: SSH_USER: ${{secrets.SSH_USER}} SSH_HOST: ${{secrets.SSH_HOST}} diff --git a/.gitignore b/.gitignore index f97f6b8..fcda727 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ riderModule.iml /.vs/ GuildData/ Logs/ +compose.yaml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0ef831a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM mcr.microsoft.com/dotnet/sdk:8.0@sha256:35792ea4ad1db051981f62b313f1be3b46b1f45cadbaa3c288cd0d3056eefb83 AS build-env +WORKDIR /Octobot + +# Copy everything +COPY . ./ +# Load build argument with publish options +ARG PUBLISH_OPTIONS="-c Release" +# Build and publish a release +RUN dotnet publish ./TeamOctolings.Octobot $PUBLISH_OPTIONS -o out + +# Build runtime image +FROM mcr.microsoft.com/dotnet/runtime:8.0@sha256:a335dccd3231f7f9e2122691b21c634f96e187d3840c8b7dbad61ee09500e408 +WORKDIR /Octobot +COPY --from=build-env /Octobot/out . +ENTRYPOINT ["./TeamOctolings.Octobot"] diff --git a/compose.example.yaml b/compose.example.yaml new file mode 100644 index 0000000..522281f --- /dev/null +++ b/compose.example.yaml @@ -0,0 +1,17 @@ +services: + octobot: + container_name: octobot + build: + context: . + args: + - PUBLISH_OPTIONS + environment: + - BOT_TOKEN + volumes: + - guild-data:/Octobot/GuildData + - logs:/Octobot/Logs + restart: unless-stopped + +volumes: + guild-data: + logs: From 8a42ecd1ab30172399ffd4c4f9190f75592282f8 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Mon, 28 Oct 2024 09:51:24 +0500 Subject: [PATCH 34/42] Retrieve SSH port from environment secrets (#337) Fixes current deployment failure due to use of non-standard SSH port on our production host. `ssh-keyscan` command was moved out to its own step to help troubleshooting in the future. Signed-off-by: Octol1ttle --- .github/workflows/build-push.yml | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml index ae355cd..af3c4cb 100644 --- a/.github/workflows/build-push.yml +++ b/.github/workflows/build-push.yml @@ -39,30 +39,38 @@ jobs: needs: upload-image steps: - - name: Setup SSH key + - name: Copy SSH key run: | install -m 600 -D /dev/null ~/.ssh/id_ed25519 echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519 - ssh-keyscan -H $SSH_HOST > ~/.ssh/known_hosts - shell: bash {0} + shell: bash env: SSH_PRIVATE_KEY: ${{secrets.SSH_PRIVATE_KEY}} + + - name: Generate SSH known hosts file + run: | + ssh-keyscan -H $SSH_HOST -p $SSH_PORT > ~/.ssh/known_hosts + shell: bash + env: SSH_HOST: ${{secrets.SSH_HOST}} - + SSH_PORT: ${{secrets.SSH_PORT}} + - name: Stop currently running instance run: | - ssh $SSH_USER@$SSH_HOST $STOP_COMMAND - shell: bash {0} + ssh -p $SSH_PORT $SSH_USER@$SSH_HOST $STOP_COMMAND + shell: bash env: + SSH_PORT: ${{secrets.SSH_PORT}} SSH_USER: ${{secrets.SSH_USER}} SSH_HOST: ${{secrets.SSH_HOST}} STOP_COMMAND: ${{vars.STOP_COMMAND}} - name: Update Docker image run: | - ssh $SSH_USER@$SSH_HOST docker pull ghcr.io/$NAMESPACE/$IMAGE_NAME:latest - shell: bash {0} + ssh -p $SSH_PORT $SSH_USER@$SSH_HOST docker pull ghcr.io/$NAMESPACE/$IMAGE_NAME:latest + shell: bash env: + SSH_PORT: ${{secrets.SSH_PORT}} SSH_USER: ${{secrets.SSH_USER}} SSH_HOST: ${{secrets.SSH_HOST}} NAMESPACE: ${{vars.NAMESPACE}} @@ -70,9 +78,10 @@ jobs: - name: Start new instance run: | - ssh $SSH_USER@$SSH_HOST $START_COMMAND - shell: bash {0} + ssh -p $SSH_PORT $SSH_USER@$SSH_HOST $START_COMMAND + shell: bash env: + SSH_PORT: ${{secrets.SSH_PORT}} SSH_USER: ${{secrets.SSH_USER}} SSH_HOST: ${{secrets.SSH_HOST}} START_COMMAND: ${{vars.START_COMMAND}} From bfee88914951dce168f9e4f02797b60932d60814 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Mon, 28 Oct 2024 10:04:08 +0500 Subject: [PATCH 35/42] ssh-keyscan is a dumb command (#338) Signed-off-by: Octol1ttle --- .github/workflows/build-push.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml index af3c4cb..e7afe8e 100644 --- a/.github/workflows/build-push.yml +++ b/.github/workflows/build-push.yml @@ -5,7 +5,7 @@ concurrency: on: push: - branches: [ "master" ] + branches: [ "master", "deploy-test" ] jobs: upload-image: @@ -49,7 +49,7 @@ jobs: - name: Generate SSH known hosts file run: | - ssh-keyscan -H $SSH_HOST -p $SSH_PORT > ~/.ssh/known_hosts + ssh-keyscan -H -p $SSH_PORT $SSH_HOST > ~/.ssh/known_hosts shell: bash env: SSH_HOST: ${{secrets.SSH_HOST}} From 9fc97bc9089239d1559f1bfae55dba1ac591075f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Nov 2024 14:35:06 +0000 Subject: [PATCH 36/42] Bump GitInfo from 3.3.5 to 3.5.0 (#340) --- TeamOctolings.Octobot/TeamOctolings.Octobot.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj b/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj index 5c6da6d..a8bcbc5 100644 --- a/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj +++ b/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj @@ -22,7 +22,7 @@ - + From ed298202fc07d98d07b2b571287c7aa3dc7f5bbf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Nov 2024 14:41:36 +0000 Subject: [PATCH 37/42] Bump JetBrains.Annotations from 2024.2.0 to 2024.3.0 (#339) --- TeamOctolings.Octobot/TeamOctolings.Octobot.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj b/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj index a8bcbc5..ec09b3d 100644 --- a/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj +++ b/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj @@ -24,7 +24,7 @@ - + From 5c235b9f981714513af76b9e219540979a4afd1a Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Sun, 1 Dec 2024 21:48:25 +0500 Subject: [PATCH 38/42] Downgrade GitInfo from 3.5.0 to 3.3.5 (#343) This pull request downgrades GitInfo from 3.5.0 to 3.3.5 due to a decision from the maintainers to lock features behind a paywall. ![image](https://github.com/user-attachments/assets/f90eba84-1a1e-43eb-950e-e233a02feb9a) --- .github/dependabot.yml | 1 + TeamOctolings.Octobot/TeamOctolings.Octobot.csproj | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 57eea90..b961b81 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -36,5 +36,6 @@ updates: - "Remora.Discord.*" # For all packages, ignore all patch updates ignore: + - dependency-name: "GitInfo" - dependency-name: "*" update-types: [ "version-update:semver-patch" ] diff --git a/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj b/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj index ec09b3d..858d9d2 100644 --- a/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj +++ b/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj @@ -22,7 +22,7 @@ - + From bf818401d829e54b3dbcdc630d27bad9f80e6c25 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Sun, 1 Dec 2024 21:52:47 +0500 Subject: [PATCH 39/42] Bump TargetFramework from 8.0 to 9.0 (#344) Simple and self-explanatory. Closes #342 --------- Signed-off-by: Octol1ttle --- .github/workflows/build-pr.yml | 4 ++-- Dockerfile | 4 ++-- TeamOctolings.Octobot/TeamOctolings.Octobot.csproj | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 2260918..84ec975 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -25,10 +25,10 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: '8.0.301' + dotnet-version: '9.0.x' - name: ReSharper CLI InspectCode - uses: muno92/resharper_inspectcode@1.12.0 + uses: muno92/resharper_inspectcode@1.12.3 with: solutionPath: ./Octobot.sln ignoreIssueType: InvertIf, ConvertIfStatementToSwitchStatement, ConvertToPrimaryConstructor diff --git a/Dockerfile b/Dockerfile index 0ef831a..6cfeac6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/sdk:8.0@sha256:35792ea4ad1db051981f62b313f1be3b46b1f45cadbaa3c288cd0d3056eefb83 AS build-env +FROM mcr.microsoft.com/dotnet/sdk:9.0@sha256:7d24e90a392e88eb56093e4eb325ff883ad609382a55d42f17fd557b997022ca AS build-env WORKDIR /Octobot # Copy everything @@ -9,7 +9,7 @@ ARG PUBLISH_OPTIONS="-c Release" RUN dotnet publish ./TeamOctolings.Octobot $PUBLISH_OPTIONS -o out # Build runtime image -FROM mcr.microsoft.com/dotnet/runtime:8.0@sha256:a335dccd3231f7f9e2122691b21c634f96e187d3840c8b7dbad61ee09500e408 +FROM mcr.microsoft.com/dotnet/runtime:9.0@sha256:1e5eb0ed94ca96a34a914456db80e48bd1bb7bc3e3c8eda5e2c3d89c153c3081 WORKDIR /Octobot COPY --from=build-env /Octobot/out . ENTRYPOINT ["./TeamOctolings.Octobot"] diff --git a/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj b/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj index 858d9d2..418803a 100644 --- a/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj +++ b/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net9.0 enable enable 2.0.0 @@ -26,7 +26,7 @@ - + From 4785d162a23653f7ed122248c4e2a5a39fc1e75e Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Mon, 3 Feb 2025 16:58:57 +0500 Subject: [PATCH 40/42] Handle temporary files being present when loading guild data (#345) This PR fixes catastrophic guild data loading errors that appear when there are lingering temporary files. In normal operation, temporary files are deleted as soon as they are copied to the main file. It is also expected that temporary files are valid JSON files. However, due to a yesterday's DoS attack, something:tm: happened and a bunch of empty temporary files got written to disk. When Octobot recovered from the attack, it was unable to load any guild data because of the temporary files. This PR addresses this issue by changing the data loading logic: 1) Check if there's a temporary file. If it exists, try loading it. 2) If it is successfully loaded, move the temp file to the main file and resume operation as normal 3) If it could not be loaded, try loading the main file 4) If it is successfully loaded, delete the temporary file and resume operation as normal 5) If it is not, throw an error (like before) This PR was tested on production data and managed to load every guild without errors. Signed-off-by: Octol1ttle --- .../GuildScheduledEventExtensions.cs | 2 +- .../Services/GuildDataService.cs | 189 +++++++++++++----- 2 files changed, 144 insertions(+), 47 deletions(-) diff --git a/TeamOctolings.Octobot/Extensions/GuildScheduledEventExtensions.cs b/TeamOctolings.Octobot/Extensions/GuildScheduledEventExtensions.cs index b8eb2d1..7822d9b 100644 --- a/TeamOctolings.Octobot/Extensions/GuildScheduledEventExtensions.cs +++ b/TeamOctolings.Octobot/Extensions/GuildScheduledEventExtensions.cs @@ -10,7 +10,7 @@ public static class GuildScheduledEventExtensions out string? location) { endTime = default; - location = default; + location = null; if (!scheduledEvent.EntityMetadata.AsOptional().IsDefined(out var metadata)) { return new ArgumentNullError(nameof(scheduledEvent.EntityMetadata)); diff --git a/TeamOctolings.Octobot/Services/GuildDataService.cs b/TeamOctolings.Octobot/Services/GuildDataService.cs index a7af7c9..88edb5f 100644 --- a/TeamOctolings.Octobot/Services/GuildDataService.cs +++ b/TeamOctolings.Octobot/Services/GuildDataService.cs @@ -75,78 +75,48 @@ public sealed class GuildDataService : BackgroundService { var path = $"GuildData/{guildId}"; var memberDataPath = $"{path}/MemberData"; + var settingsPath = $"{path}/Settings.json"; + var scheduledEventsPath = $"{path}/ScheduledEvents.json"; MigrateDataDirectory(guildId, path); Directory.CreateDirectory(path); - if (!File.Exists(settingsPath)) - { - await File.WriteAllTextAsync(settingsPath, "{}", ct); - } - - if (!File.Exists(scheduledEventsPath)) - { - await File.WriteAllTextAsync(scheduledEventsPath, "{}", ct); - } - var dataLoadFailed = false; - await using var settingsStream = File.OpenRead(settingsPath); - JsonNode? jsonSettings = null; - try - { - jsonSettings = await JsonNode.ParseAsync(settingsStream, cancellationToken: ct); - } - catch (Exception e) - { - _logger.LogError(e, "Guild settings load failed: {Path}", settingsPath); - dataLoadFailed = true; - } - + var jsonSettings = await LoadGuildSettings(settingsPath, ct); if (jsonSettings is not null) { FixJsonSettings(jsonSettings); } - - await using var eventsStream = File.OpenRead(scheduledEventsPath); - Dictionary? events = null; - try + else { - events = await JsonSerializer.DeserializeAsync>( - eventsStream, cancellationToken: ct); + dataLoadFailed = true; } - catch (Exception e) + + var events = await LoadScheduledEvents(scheduledEventsPath, ct); + if (events is null) { - _logger.LogError(e, "Guild scheduled events load failed: {Path}", scheduledEventsPath); dataLoadFailed = true; } var memberData = new Dictionary(); - foreach (var dataFileInfo in Directory.CreateDirectory(memberDataPath).GetFiles()) + foreach (var dataFileInfo in Directory.CreateDirectory(memberDataPath).GetFiles() + .Where(dataFileInfo => + !memberData.ContainsKey( + ulong.Parse(dataFileInfo.Name.Replace(".json", "").Replace(".tmp", ""))))) { - await using var dataStream = dataFileInfo.OpenRead(); - MemberData? data; - try + var data = await LoadMemberData(dataFileInfo, memberDataPath, true, ct); + + if (data == null) { - data = await JsonSerializer.DeserializeAsync(dataStream, cancellationToken: ct); - } - catch (Exception e) - { - _logger.LogError(e, "Member data load failed: {MemberDataPath}/{FileName}", memberDataPath, - dataFileInfo.Name); dataLoadFailed = true; continue; } - if (data is null) - { - continue; - } - - memberData.Add(data.Id, data); + memberData.TryAdd(data.Id, data); } var finalData = new GuildData( @@ -160,6 +130,133 @@ public sealed class GuildDataService : BackgroundService return finalData; } + private async Task LoadMemberData(FileInfo dataFileInfo, string memberDataPath, bool loadTmp, + CancellationToken ct = default) + { + MemberData? data; + var temporaryPath = $"{dataFileInfo.FullName}.tmp"; + var usedInfo = loadTmp && File.Exists(temporaryPath) ? new FileInfo(temporaryPath) : dataFileInfo; + + var isTmp = usedInfo.Extension is ".tmp"; + try + { + await using var dataStream = usedInfo.OpenRead(); + data = await JsonSerializer.DeserializeAsync(dataStream, cancellationToken: ct); + if (isTmp) + { + usedInfo.CopyTo(usedInfo.FullName.Replace(".tmp", ""), true); + usedInfo.Delete(); + } + } + catch (Exception e) + { + if (isTmp) + { + _logger.LogWarning(e, + "Unable to load temporary member data file, deleting: {MemberDataPath}/{FileName}", memberDataPath, + usedInfo.Name); + usedInfo.Delete(); + return await LoadMemberData(dataFileInfo, memberDataPath, false, ct); + } + + _logger.LogError(e, "Member data load failed: {MemberDataPath}/{FileName}", memberDataPath, + usedInfo.Name); + return null; + } + + return data; + } + + private async Task?> LoadScheduledEvents(string scheduledEventsPath, + CancellationToken ct = default) + { + var tempScheduledEventsPath = $"{scheduledEventsPath}.tmp"; + + if (!File.Exists(scheduledEventsPath) && !File.Exists(tempScheduledEventsPath)) + { + return new Dictionary(); + } + + if (File.Exists(tempScheduledEventsPath)) + { + _logger.LogWarning("Found temporary scheduled events file, will try to parse and copy to main: ${Path}", + tempScheduledEventsPath); + try + { + await using var tempEventsStream = File.OpenRead(tempScheduledEventsPath); + var events = await JsonSerializer.DeserializeAsync>( + tempEventsStream, cancellationToken: ct); + File.Copy(tempScheduledEventsPath, scheduledEventsPath, true); + File.Delete(tempScheduledEventsPath); + + _logger.LogInformation("Successfully loaded temporary scheduled events file: ${Path}", + tempScheduledEventsPath); + return events; + } + catch (Exception e) + { + _logger.LogError(e, "Unable to load temporary scheduled events file: {Path}, deleting", + tempScheduledEventsPath); + File.Delete(tempScheduledEventsPath); + } + } + + try + { + await using var eventsStream = File.OpenRead(scheduledEventsPath); + return await JsonSerializer.DeserializeAsync>( + eventsStream, cancellationToken: ct); + } + catch (Exception e) + { + _logger.LogError(e, "Guild scheduled events load failed: {Path}", scheduledEventsPath); + return null; + } + } + + private async Task LoadGuildSettings(string settingsPath, CancellationToken ct = default) + { + var tempSettingsPath = $"{settingsPath}.tmp"; + + if (!File.Exists(settingsPath) && !File.Exists(tempSettingsPath)) + { + return new JsonObject(); + } + + if (File.Exists(tempSettingsPath)) + { + _logger.LogWarning("Found temporary settings file, will try to parse and copy to main: ${Path}", + tempSettingsPath); + try + { + await using var tempSettingsStream = File.OpenRead(tempSettingsPath); + var jsonSettings = await JsonNode.ParseAsync(tempSettingsStream, cancellationToken: ct); + + File.Copy(tempSettingsPath, settingsPath, true); + File.Delete(tempSettingsPath); + + _logger.LogInformation("Successfully loaded temporary settings file: ${Path}", tempSettingsPath); + return jsonSettings; + } + catch (Exception e) + { + _logger.LogError(e, "Unable to load temporary settings file: {Path}, deleting", tempSettingsPath); + File.Delete(tempSettingsPath); + } + } + + try + { + await using var settingsStream = File.OpenRead(settingsPath); + return await JsonNode.ParseAsync(settingsStream, cancellationToken: ct); + } + catch (Exception e) + { + _logger.LogError(e, "Guild settings load failed: {Path}", settingsPath); + return null; + } + } + private void MigrateDataDirectory(Snowflake guildId, string newPath) { var oldPath = $"{guildId}"; From f3330c47cc7958e09d27d80124c45476069d3162 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 17 Feb 2025 14:50:08 +0500 Subject: [PATCH 41/42] Bump Remora.Discord with 5 updates (#346) Bumps the remora group with 5 updates: | Package | From | To | | --- | --- | --- | | [Remora.Discord.Caching](https://github.com/Remora/Remora.Discord) | `39.0.0` | `40.0.0` | | [Remora.Commands](https://github.com/Remora/Remora.Commands) | `10.0.6` | `11.0.1` | | [Remora.Discord.Extensions](https://github.com/Remora/Remora.Discord) | `5.3.6` | `6.0.0` | | [Remora.Discord.Interactivity](https://github.com/Remora/Remora.Discord) | `5.0.0` | `6.0.0` | | [Remora.Discord.Hosting](https://github.com/Remora/Remora.Discord) | `6.0.10` | `7.0.0` | Signed-off-by: dependabot[bot] Signed-off-by: Octol1ttle Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Octol1ttle --- .../Responders/MessageEditedResponder.cs | 31 ++++++------------- .../TeamOctolings.Octobot.csproj | 10 +++--- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/TeamOctolings.Octobot/Responders/MessageEditedResponder.cs b/TeamOctolings.Octobot/Responders/MessageEditedResponder.cs index 2968562..e3d1c58 100644 --- a/TeamOctolings.Octobot/Responders/MessageEditedResponder.cs +++ b/TeamOctolings.Octobot/Responders/MessageEditedResponder.cs @@ -36,40 +36,29 @@ public sealed class MessageEditedResponder : IResponder public async Task RespondAsync(IMessageUpdate gatewayEvent, CancellationToken ct = default) { - if (!gatewayEvent.ID.IsDefined(out var messageId)) - { - return new ArgumentNullError(nameof(gatewayEvent.ID)); - } - - if (!gatewayEvent.ChannelID.IsDefined(out var channelId)) - { - return new ArgumentNullError(nameof(gatewayEvent.ChannelID)); - } - if (!gatewayEvent.GuildID.IsDefined(out var guildId) - || !gatewayEvent.Author.IsDefined(out var author) - || !gatewayEvent.EditedTimestamp.IsDefined(out var timestamp) - || !gatewayEvent.Content.IsDefined(out var newContent)) + || !gatewayEvent.EditedTimestamp.HasValue + || gatewayEvent.Author.IsBot.OrDefault(false)) { return Result.Success; } var cfg = await _guildData.GetSettings(guildId, ct); - if (author.IsBot.OrDefault(false) || GuildSettings.PrivateFeedbackChannel.Get(cfg).Empty()) + if (GuildSettings.PrivateFeedbackChannel.Get(cfg).Empty()) { return Result.Success; } - var cacheKey = new KeyHelpers.MessageCacheKey(channelId, messageId); + var cacheKey = new KeyHelpers.MessageCacheKey(gatewayEvent.ChannelID, gatewayEvent.ID); var messageResult = await _cacheService.TryGetValueAsync( cacheKey, ct); if (!messageResult.IsDefined(out var message)) { - _ = _channelApi.GetChannelMessageAsync(channelId, messageId, ct); + _ = _channelApi.GetChannelMessageAsync(gatewayEvent.ChannelID, gatewayEvent.ID, ct); return Result.Success; } - if (message.Content == newContent) + if (message.Content == gatewayEvent.Content) { return Result.Success; } @@ -83,22 +72,22 @@ public sealed class MessageEditedResponder : IResponder // We don't need to await this since the result is not needed // NOTE: Because this is not awaited, there may be a race condition depending on how fast clients are able to edit their messages // NOTE: Awaiting this might not even solve this if the same responder is called asynchronously - _ = _channelApi.GetChannelMessageAsync(channelId, messageId, ct); + _ = _channelApi.GetChannelMessageAsync(gatewayEvent.ChannelID, gatewayEvent.ID, ct); - var diff = InlineDiffBuilder.Diff(message.Content, newContent); + var diff = InlineDiffBuilder.Diff(message.Content, gatewayEvent.Content); Messages.Culture = GuildSettings.Language.Get(cfg); var builder = new StringBuilder() .AppendLine(diff.AsMarkdown()) .AppendLine(string.Format(Messages.DescriptionActionJumpToMessage, - $"https://discord.com/channels/{guildId}/{channelId}/{messageId}") + $"https://discord.com/channels/{guildId}/{gatewayEvent.ChannelID}/{gatewayEvent.ID}") ); var embed = new EmbedBuilder() .WithSmallTitle(string.Format(Messages.CachedMessageEdited, message.Author.GetTag()), message.Author) .WithDescription(builder.ToString()) - .WithTimestamp(timestamp.Value) + .WithTimestamp(gatewayEvent.EditedTimestamp.Value) .WithColour(ColorsList.Yellow) .Build(); diff --git a/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj b/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj index 418803a..b67eaf8 100644 --- a/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj +++ b/TeamOctolings.Octobot/TeamOctolings.Octobot.csproj @@ -27,11 +27,11 @@ - - - - - + + + + + From 5a351cbd97ff4ce11c628960ab8b7386c9f9228f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 19 May 2025 08:33:14 +0000 Subject: [PATCH 42/42] Bump muno92/resharper_inspectcode from 1.12.3 to 1.13.0 (#348) --- .github/workflows/build-pr.yml | 2 +- TeamOctolings.Octobot/Program.cs | 51 +++++++++---------- .../Responders/GuildMemberLeftResponder.cs | 10 ++-- TeamOctolings.Octobot/Utility.cs | 4 +- 4 files changed, 29 insertions(+), 38 deletions(-) diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 84ec975..07d5b90 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -28,7 +28,7 @@ jobs: dotnet-version: '9.0.x' - name: ReSharper CLI InspectCode - uses: muno92/resharper_inspectcode@1.12.3 + uses: muno92/resharper_inspectcode@1.13.0 with: solutionPath: ./Octobot.sln ignoreIssueType: InvertIf, ConvertIfStatementToSwitchStatement, ConvertToPrimaryConstructor diff --git a/TeamOctolings.Octobot/Program.cs b/TeamOctolings.Octobot/Program.cs index d1d6220..8cdbdcf 100644 --- a/TeamOctolings.Octobot/Program.cs +++ b/TeamOctolings.Octobot/Program.cs @@ -39,8 +39,7 @@ public sealed class Program private static IHostBuilder CreateHostBuilder(string[] args) { return Host.CreateDefaultBuilder(args) - .AddDiscordService( - services => + .AddDiscordService(services => { var configuration = services.GetRequiredService(); @@ -49,25 +48,22 @@ public sealed class Program "No bot token has been provided. Set the " + "BOT_TOKEN environment variable to a valid token."); } - ).ConfigureServices( - (_, services) => + ).ConfigureServices((_, services) => { - services.Configure( - options => - { - options.Intents |= GatewayIntents.MessageContents - | GatewayIntents.GuildMembers - | GatewayIntents.GuildPresences - | GatewayIntents.GuildScheduledEvents; - }); - services.Configure( - cSettings => - { - cSettings.SetDefaultAbsoluteExpiration(TimeSpan.FromHours(1)); - cSettings.SetDefaultSlidingExpiration(TimeSpan.FromMinutes(30)); - cSettings.SetAbsoluteExpiration(TimeSpan.FromDays(7)); - cSettings.SetSlidingExpiration(TimeSpan.FromDays(7)); - }); + services.Configure(options => + { + options.Intents |= GatewayIntents.MessageContents + | GatewayIntents.GuildMembers + | GatewayIntents.GuildPresences + | GatewayIntents.GuildScheduledEvents; + }); + services.Configure(cSettings => + { + cSettings.SetDefaultAbsoluteExpiration(TimeSpan.FromHours(1)); + cSettings.SetDefaultSlidingExpiration(TimeSpan.FromMinutes(30)); + cSettings.SetAbsoluteExpiration(TimeSpan.FromDays(7)); + cSettings.SetSlidingExpiration(TimeSpan.FromDays(7)); + }); services.AddTransient() // Init @@ -87,14 +83,13 @@ public sealed class Program .AddHostedService() .AddHostedService(); } - ).ConfigureLogging( - c => c.AddConsole() - .AddFile("Logs/Octobot-{Date}.log", - outputTemplate: "{Timestamp:o} [{Level:u4}] {Message} {NewLine}{Exception}") - .AddFilter("System.Net.Http.HttpClient.*.LogicalHandler", LogLevel.Warning) - .AddFilter("System.Net.Http.HttpClient.*.ClientHandler", LogLevel.Warning) - .AddFilter("System.Net.Http.HttpClient.*.LogicalHandler", LogLevel.Warning) - .AddFilter("System.Net.Http.HttpClient.*.ClientHandler", LogLevel.Warning) + ).ConfigureLogging(c => c.AddConsole() + .AddFile("Logs/Octobot-{Date}.log", + outputTemplate: "{Timestamp:o} [{Level:u4}] {Message} {NewLine}{Exception}") + .AddFilter("System.Net.Http.HttpClient.*.LogicalHandler", LogLevel.Warning) + .AddFilter("System.Net.Http.HttpClient.*.ClientHandler", LogLevel.Warning) + .AddFilter("System.Net.Http.HttpClient.*.LogicalHandler", LogLevel.Warning) + .AddFilter("System.Net.Http.HttpClient.*.ClientHandler", LogLevel.Warning) ); } } diff --git a/TeamOctolings.Octobot/Responders/GuildMemberLeftResponder.cs b/TeamOctolings.Octobot/Responders/GuildMemberLeftResponder.cs index 9774899..957a107 100644 --- a/TeamOctolings.Octobot/Responders/GuildMemberLeftResponder.cs +++ b/TeamOctolings.Octobot/Responders/GuildMemberLeftResponder.cs @@ -36,13 +36,9 @@ public sealed class GuildMemberLeftResponder : IResponder var cfg = data.Settings; var memberData = data.GetOrCreateMemberData(user.ID); - if (memberData.BannedUntil is not null || memberData.Kicked) - { - return Result.Success; - } - - if (GuildSettings.WelcomeMessagesChannel.Get(cfg).Empty() - || GuildSettings.LeaveMessage.Get(cfg) is "off" or "disable" or "disabled") + if (memberData.BannedUntil is not null || memberData.Kicked + || GuildSettings.WelcomeMessagesChannel.Get(cfg).Empty() + || GuildSettings.LeaveMessage.Get(cfg) is "off" or "disable" or "disabled") { return Result.Success; } diff --git a/TeamOctolings.Octobot/Utility.cs b/TeamOctolings.Octobot/Utility.cs index f337d93..a2f7aca 100644 --- a/TeamOctolings.Octobot/Utility.cs +++ b/TeamOctolings.Octobot/Utility.cs @@ -67,8 +67,8 @@ public sealed class Utility builder.Append($"{Mention.Role(role)} "); } - builder = subscribers.Where( - subscriber => !data.GetOrCreateMemberData(subscriber.User.ID).Roles.Contains(role.Value)) + builder = subscribers.Where(subscriber => + !data.GetOrCreateMemberData(subscriber.User.ID).Roles.Contains(role.Value)) .Aggregate(builder, (current, subscriber) => current.Append($"{Mention.User(subscriber.User)} ")); return builder.ToString(); }