1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-01-31 00:19:00 +03:00

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 <l1ttleofficial@outlook.com>
This commit is contained in:
Octol1ttle 2024-05-16 20:34:26 +05:00 committed by GitHub
parent 19fadead91
commit 793afd0e06
Signed by: GitHub
GPG key ID: B5690EEEBB952194
61 changed files with 447 additions and 462 deletions

View file

@ -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

View file

@ -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.

View file

@ -1,4 +1,4 @@
namespace Octobot;
namespace TeamOctolings.Octobot;
public static class BuildInfo
{

View file

@ -1,6 +1,6 @@
using System.Drawing;
namespace Octobot;
namespace TeamOctolings.Octobot;
/// <summary>
/// Contains all colors used in embeds.

View file

@ -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;
/// <summary>
/// Handles the command to show information about this bot: /about.

View file

@ -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;
/// <summary>
/// Handles commands related to ban management: /ban and /unban.

View file

@ -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;
/// <summary>
/// Handles the command to clear messages in a channel: /clear.

View file

@ -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;
/// <summary>
/// Handles error logging for slash command groups.

View file

@ -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.

View file

@ -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;
/// <summary>
/// Handles the command to kick members of a guild: /kick.

View file

@ -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;
/// <summary>
/// Handles commands related to mute management: /mute and /unmute.

View file

@ -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;
/// <summary>
/// Handles the command to get the time taken for the gateway to respond to the last heartbeat: /ping

View file

@ -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;
/// <summary>
/// Handles commands to manage reminders: /remind, /listremind, /delremind

View file

@ -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;
/// <summary>
/// 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
{
/// <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,
@ -199,7 +199,7 @@ public class SettingsCommandGroup : CommandGroup
}
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);
@ -270,7 +270,7 @@ public class SettingsCommandGroup : CommandGroup
}
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)

View file

@ -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;
/// <summary>
/// Handles tool commands: /userinfo, /guildinfo, /random, /timestamp, /8ball.

View file

@ -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.

View file

@ -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
@ -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.
@ -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

View file

@ -1,4 +1,4 @@
namespace Octobot.Data;
namespace TeamOctolings.Octobot.Data;
/// <summary>
/// Stores information about a member

View file

@ -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.

View file

@ -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) { }

View file

@ -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;
/// <summary>
/// Represents an per-guild option.
/// Represents a per-guild option.
/// </summary>
/// <typeparam name="T">The type of the option.</typeparam>
public class Option<T> : IOption
public class GuildOption<T> : IGuildOption
where T : notnull
{
protected readonly T DefaultValue;
public Option(string name, T defaultValue)
public GuildOption(string name, T defaultValue)
{
Name = name;
DefaultValue = defaultValue;

View file

@ -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);

View file

@ -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;
/// <inheritdoc />
public sealed class LanguageOption : Option<CultureInfo>
public sealed class LanguageOption : GuildOption<CultureInfo>
{
private static readonly Dictionary<string, CultureInfo> CultureInfoCache = new()
{

View file

@ -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<Snowflake>
public sealed partial class SnowflakeOption : GuildOption<Snowflake>
{
public SnowflakeOption(string name) : base(name, 0UL.ToSnowflake()) { }

View file

@ -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<TimeSpan>
public sealed class TimeSpanOption : GuildOption<TimeSpan>
{
public TimeSpanOption(string name, TimeSpan defaultValue) : base(name, defaultValue) { }

View file

@ -1,4 +1,4 @@
namespace Octobot.Data;
namespace TeamOctolings.Octobot.Data;
public struct Reminder
{

View file

@ -1,7 +1,7 @@
using System.Text.Json.Serialization;
using Remora.Discord.API.Abstractions.Objects;
namespace Octobot.Data;
namespace TeamOctolings.Octobot.Data;
/// <summary>
/// Stores information about scheduled events. This information is not provided by the Discord API.

View file

@ -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
{

View file

@ -1,6 +1,6 @@
using Remora.Results;
namespace Octobot.Extensions;
namespace TeamOctolings.Octobot.Extensions;
public static class CollectionExtensions
{

View file

@ -2,7 +2,7 @@
using Remora.Discord.Commands.Extensions;
using Remora.Rest.Core;
namespace Octobot.Extensions;
namespace TeamOctolings.Octobot.Extensions;
public static class CommandContextExtensions
{

View file

@ -1,7 +1,7 @@
using System.Text;
using DiffPlex.DiffBuilder.Model;
namespace Octobot.Extensions;
namespace TeamOctolings.Octobot.Extensions;
public static class DiffPaneModelExtensions
{

View file

@ -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
{

View file

@ -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
{

View file

@ -2,7 +2,7 @@
using Remora.Rest.Core;
using Remora.Results;
namespace Octobot.Extensions;
namespace TeamOctolings.Octobot.Extensions;
public static class GuildScheduledEventExtensions
{

View file

@ -1,7 +1,7 @@
using Microsoft.Extensions.Logging;
using Remora.Results;
namespace Octobot.Extensions;
namespace TeamOctolings.Octobot.Extensions;
public static class LoggerExtensions
{

View file

@ -1,4 +1,4 @@
namespace Octobot.Extensions;
namespace TeamOctolings.Octobot.Extensions;
public static class MarkdownExtensions
{

View file

@ -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;

View file

@ -1,6 +1,6 @@
using Remora.Rest.Core;
namespace Octobot.Extensions;
namespace TeamOctolings.Octobot.Extensions;
public static class SnowflakeExtensions
{

View file

@ -1,6 +1,6 @@
using System.Text;
namespace Octobot.Extensions;
namespace TeamOctolings.Octobot.Extensions;
public static class StringBuilderExtensions
{

View file

@ -1,7 +1,7 @@
using System.Net;
using Remora.Discord.Extensions.Formatting;
namespace Octobot.Extensions;
namespace TeamOctolings.Octobot.Extensions;
public static class StringExtensions
{

View file

@ -1,7 +1,7 @@
using Remora.Discord.API;
using Remora.Rest.Core;
namespace Octobot.Extensions;
namespace TeamOctolings.Octobot.Extensions;
public static class UInt64Extensions
{

View file

@ -1,6 +1,6 @@
using Remora.Discord.API.Abstractions.Objects;
namespace Octobot.Extensions;
namespace TeamOctolings.Octobot.Extensions;
public static class UserExtensions
{

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,7 @@ using JetBrains.Annotations;
using Remora.Commands.Parsers;
using Remora.Results;
namespace Octobot.Parsers;
namespace TeamOctolings.Octobot.Parsers;
/// <summary>
/// Parses <see cref="TimeSpan"/>s.

View file

@ -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<MentionType>(), Array.Empty<Snowflake>(), Array.Empty<Snowflake>());
[StaticCallersOnly]
public static ILogger<Octobot>? StaticLogger { get; private set; }
public static async Task Main(string[] args)
{
var host = CreateHostBuilder(args).UseConsoleLifetime().Build();
var services = host.Services;
StaticLogger = services.GetRequiredService<ILogger<Octobot>>();
Utility.StaticLogger = services.GetRequiredService<ILogger<Program>>();
var slashService = services.GetRequiredService<SlashService>();
// 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<LoggingPreparationErrorEvent>()
.AddPostExecutionEvent<ErrorLoggingPostExecutionEvent>()

View file

@ -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;
/// <summary>
/// Handles sending a <see cref="Ready" /> message to a guild that has just initialized if that guild

View file

@ -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;
/// <summary>
/// Handles sending a guild's <see cref="GuildSettings.WelcomeMessage" /> if one is set.
@ -77,7 +77,7 @@ public class GuildMemberJoinedResponder : IResponder<IGuildMemberAdd>
return await _channelApi.CreateMessageWithEmbedResultAsync(
GuildSettings.WelcomeMessagesChannel.Get(cfg), embedResult: embed,
allowedMentions: Octobot.NoMentions, ct: ct);
allowedMentions: Utility.NoMentions, ct: ct);
}
private async Task<Result> TryReturnRolesAsync(

View file

@ -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;
/// <summary>
/// Handles sending a guild's <see cref="GuildSettings.LeaveMessage" /> if one is set.
@ -67,6 +67,6 @@ public class GuildMemberLeftResponder : IResponder<IGuildMemberRemove>
return await _channelApi.CreateMessageWithEmbedResultAsync(
GuildSettings.WelcomeMessagesChannel.Get(cfg), embedResult: embed,
allowedMentions: Octobot.NoMentions, ct: ct);
allowedMentions: Utility.NoMentions, ct: ct);
}
}

View file

@ -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;
/// <summary>
/// Handles removing guild ID from <see cref="GuildData" /> if the guild becomes unavailable.

View file

@ -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;
/// <summary>
/// Handles logging the contents of a deleted message and the user who deleted the message
@ -102,6 +102,6 @@ public class MessageDeletedResponder : IResponder<IMessageDelete>
return await _channelApi.CreateMessageWithEmbedResultAsync(
GuildSettings.PrivateFeedbackChannel.Get(cfg), embedResult: embed,
allowedMentions: Octobot.NoMentions, ct: ct);
allowedMentions: Utility.NoMentions, ct: ct);
}
}

View file

@ -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;
/// <summary>
/// Handles logging the difference between an edited message's old and new content
@ -104,6 +104,6 @@ public class MessageEditedResponder : IResponder<IMessageUpdate>
return await _channelApi.CreateMessageWithEmbedResultAsync(
GuildSettings.PrivateFeedbackChannel.Get(cfg), embedResult: embed,
allowedMentions: Octobot.NoMentions, ct: ct);
allowedMentions: Utility.NoMentions, ct: ct);
}
}

View file

@ -5,7 +5,7 @@ using Remora.Discord.Gateway.Responders;
using Remora.Rest.Core;
using Remora.Results;
namespace Octobot.Responders;
namespace TeamOctolings.Octobot.Responders;
/// <summary>
/// Handles sending replies to easter egg messages.

View file

@ -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
{

View file

@ -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;
/// <summary>
/// Handles saving, loading, initializing and providing <see cref="GuildData" />.

View file

@ -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
{

View file

@ -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
{

View file

@ -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
{

View file

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
@ -16,7 +16,7 @@
<Company>TeamOctolings</Company>
<NeutralLanguage>en</NeutralLanguage>
<Description>A general-purpose Discord bot for moderation written in C#</Description>
<ApplicationIcon>docs/octobot.ico</ApplicationIcon>
<ApplicationIcon>../docs/octobot.ico</ApplicationIcon>
<GitVersion>false</GitVersion>
</PropertyGroup>
@ -35,12 +35,12 @@
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="locale\Messages.resx">
<EmbeddedResource Update="Messages.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Messages.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="CodeAnalysis\BannedSymbols.txt" />
<AdditionalFiles Include="..\CodeAnalysis\BannedSymbols.txt" />
</ItemGroup>
</Project>

View file

@ -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;
/// <summary>
/// Provides utility methods that cannot be transformed to extension methods because they require usage
@ -18,6 +21,9 @@ namespace Octobot.Services;
/// </summary>
public sealed class Utility
{
public static readonly AllowedMentions NoMentions = new(
Array.Empty<MentionType>(), Array.Empty<Snowflake>(), Array.Empty<Snowflake>());
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<Program>? StaticLogger { get; set; }
/// <summary>
/// Gets the string mentioning the <see cref="GuildSettings.EventNotificationRole" /> and event subscribers related to
/// a scheduled