Skip to content

Commit

Permalink
Apply official naming guidelines to Octobot (#306)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Octol1ttle authored May 16, 2024
1 parent 19fadea commit 793afd0
Show file tree
Hide file tree
Showing 61 changed files with 445 additions and 460 deletions.
10 changes: 5 additions & 5 deletions Octobot.sln
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

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
Debug|Any CPU = Debug|Any CPU
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Octobot.Attributes;
namespace TeamOctolings.Octobot.Attributes;

/// <summary>
/// Any property marked with <see cref="StaticCallersOnlyAttribute"/> should only be accessed by static methods.
Expand Down
2 changes: 1 addition & 1 deletion src/BuildInfo.cs → TeamOctolings.Octobot/BuildInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Octobot;
namespace TeamOctolings.Octobot;

public static class BuildInfo
{
Expand Down
2 changes: 1 addition & 1 deletion src/ColorsList.cs → TeamOctolings.Octobot/ColorsList.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Drawing;

namespace Octobot;
namespace TeamOctolings.Octobot;

/// <summary>
/// Contains all colors used in embeds.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,8 +15,11 @@
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;

/// <summary>
/// Handles the command to show information about this bot: /about.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
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;
Expand All @@ -19,8 +14,13 @@
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;

/// <summary>
/// Handles commands related to ban management: /ban and /unban.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,8 +13,11 @@
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;

/// <summary>
/// Handles the command to clear messages in a channel: /clear.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,8 +10,9 @@
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;

/// <summary>
/// Handles error logging for slash command groups.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Handles error logging for slash commands that couldn't be successfully prepared.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,8 +12,11 @@
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;

/// <summary>
/// Handles the command to kick members of a guild: /kick.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
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;
Expand All @@ -19,8 +14,13 @@
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;

/// <summary>
/// Handles commands related to mute management: /mute and /unmute.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,8 +12,11 @@
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;

/// <summary>
/// Handles the command to get the time taken for the gateway to respond to the last heartbeat: /ping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
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;
Expand All @@ -17,9 +14,12 @@
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;

/// <summary>
/// Handles commands to manage reminders: /remind, /listremind, /delremind
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
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;
Expand All @@ -19,8 +15,12 @@
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;

/// <summary>
/// Handles the commands to list and modify per-guild settings: /settings and /settings list.
Expand All @@ -29,13 +29,13 @@ namespace Octobot.Commands;
public class SettingsCommandGroup : CommandGroup
{
/// <summary>
/// Represents all options as an array of objects implementing <see cref="IOption" />.
/// Represents all options as an array of objects implementing <see cref="IGuildOption" />.
/// </summary>
/// <remarks>
/// WARNING: If you update this array in any way, you must also update <see cref="AllOptionsEnum" /> and make sure
/// that the orders match.
/// </remarks>
private static readonly IOption[] AllOptions =
private static readonly IGuildOption[] AllOptions =
[
GuildSettings.Language,
GuildSettings.WelcomeMessage,
Expand Down Expand Up @@ -199,7 +199,7 @@ public async Task<Result> ExecuteEditSettingsAsync(
}

private async Task<Result> 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);
Expand Down Expand Up @@ -270,7 +270,7 @@ public async Task<Result> ExecuteResetSettingsAsync(
}

private async Task<Result> ResetSingleSettingAsync(JsonNode cfg, IUser bot,
IOption option, CancellationToken ct = default)
IGuildOption option, CancellationToken ct = default)
{
var resetResult = option.Reset(cfg);
if (!resetResult.IsSuccess)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
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;
Expand All @@ -17,8 +13,12 @@
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;

/// <summary>
/// Handles tool commands: /userinfo, /guildinfo, /random, /timestamp, /8ball.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text.Json.Nodes;
using Remora.Rest.Core;

namespace Octobot.Data;
namespace TeamOctolings.Octobot.Data;

/// <summary>
/// Stores information about a guild. This information is not accessible via the Discord API.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Contains all per-guild settings that can be set by a member
Expand All @@ -22,7 +22,7 @@ public static class GuildSettings
/// </list>
/// </remarks>
/// <seealso cref="GuildMemberJoinedResponder" />
public static readonly Option<string> WelcomeMessage = new("WelcomeMessage", "default");
public static readonly GuildOption<string> WelcomeMessage = new("WelcomeMessage", "default");

/// <summary>
/// Controls what message should be sent in <see cref="PublicFeedbackChannel" /> when a member leaves the guild.
Expand All @@ -34,7 +34,7 @@ public static class GuildSettings
/// </list>
/// </remarks>
/// <seealso cref="GuildMemberLeftResponder" />
public static readonly Option<string> LeaveMessage = new("LeaveMessage", "default");
public static readonly GuildOption<string> LeaveMessage = new("LeaveMessage", "default");

/// <summary>
/// Controls whether or not the <see cref="Messages.Ready" /> message should be sent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Octobot.Data;
namespace TeamOctolings.Octobot.Data;

/// <summary>
/// Stores information about a member
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using JetBrains.Annotations;
using Octobot.Commands;
using TeamOctolings.Octobot.Commands;

namespace Octobot.Data.Options;
namespace TeamOctolings.Octobot.Data.Options;

/// <summary>
/// Represents all options as enums.
Expand Down
Original file line number Diff line number Diff line change
@@ -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<bool>
public sealed class BoolOption : GuildOption<bool>
{
public BoolOption(string name, bool defaultValue) : base(name, defaultValue) { }

Expand Down
Loading

0 comments on commit 793afd0

Please sign in to comment.