2023-07-09 16:32:14 +03:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Text;
|
2023-07-18 15:25:02 +03:00
|
|
|
|
using JetBrains.Annotations;
|
2023-09-30 16:58:32 +03:00
|
|
|
|
using Octobot.Data;
|
2023-10-12 18:37:25 +03:00
|
|
|
|
using Octobot.Extensions;
|
2023-09-30 16:58:32 +03:00
|
|
|
|
using Octobot.Services;
|
2023-07-09 16:32:14 +03:00
|
|
|
|
using Remora.Commands.Attributes;
|
|
|
|
|
using Remora.Commands.Groups;
|
2023-07-20 23:41:02 +03:00
|
|
|
|
using Remora.Discord.API.Abstractions.Objects;
|
2023-07-09 16:32:14 +03:00
|
|
|
|
using Remora.Discord.API.Abstractions.Rest;
|
2023-07-18 17:18:35 +03:00
|
|
|
|
using Remora.Discord.Commands.Attributes;
|
|
|
|
|
using Remora.Discord.Commands.Conditions;
|
2023-07-09 16:32:14 +03:00
|
|
|
|
using Remora.Discord.Commands.Contexts;
|
|
|
|
|
using Remora.Discord.Commands.Feedback.Services;
|
|
|
|
|
using Remora.Discord.Extensions.Embeds;
|
2023-09-29 18:36:16 +03:00
|
|
|
|
using Remora.Rest.Core;
|
2023-07-09 16:32:14 +03:00
|
|
|
|
using Remora.Results;
|
|
|
|
|
|
2023-09-30 16:58:32 +03:00
|
|
|
|
namespace Octobot.Commands;
|
2023-07-09 16:32:14 +03:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles the command to show information about this bot: /about.
|
|
|
|
|
/// </summary>
|
2023-07-18 15:25:02 +03:00
|
|
|
|
[UsedImplicitly]
|
2023-08-02 23:51:16 +03:00
|
|
|
|
public class AboutCommandGroup : CommandGroup
|
|
|
|
|
{
|
2023-09-29 18:36:16 +03:00
|
|
|
|
private static readonly (string Username, Snowflake Id)[] Developers =
|
|
|
|
|
{
|
|
|
|
|
("Octol1ttle", new Snowflake(504343489664909322)),
|
|
|
|
|
("mctaylors", new Snowflake(326642240229474304)),
|
|
|
|
|
("neroduckale", new Snowflake(474943797063843851))
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-02 23:51:16 +03:00
|
|
|
|
private readonly ICommandContext _context;
|
2023-11-04 21:28:22 +03:00
|
|
|
|
private readonly IFeedbackService _feedback;
|
2023-08-02 23:51:16 +03:00
|
|
|
|
private readonly GuildDataService _guildData;
|
|
|
|
|
private readonly IDiscordRestUserAPI _userApi;
|
2023-09-29 18:36:16 +03:00
|
|
|
|
private readonly IDiscordRestGuildAPI _guildApi;
|
2023-07-09 16:32:14 +03:00
|
|
|
|
|
|
|
|
|
public AboutCommandGroup(
|
2023-08-02 23:51:16 +03:00
|
|
|
|
ICommandContext context, GuildDataService guildData,
|
2023-11-04 21:28:22 +03:00
|
|
|
|
IFeedbackService feedback, IDiscordRestUserAPI userApi,
|
2023-09-29 18:36:16 +03:00
|
|
|
|
IDiscordRestGuildAPI guildApi)
|
2023-08-02 23:51:16 +03:00
|
|
|
|
{
|
2023-07-09 16:32:14 +03:00
|
|
|
|
_context = context;
|
2023-08-02 23:51:16 +03:00
|
|
|
|
_guildData = guildData;
|
|
|
|
|
_feedback = feedback;
|
2023-07-09 16:32:14 +03:00
|
|
|
|
_userApi = userApi;
|
2023-09-29 18:36:16 +03:00
|
|
|
|
_guildApi = guildApi;
|
2023-07-09 16:32:14 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A slash command that shows information about this bot.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>
|
|
|
|
|
/// A feedback sending result which may or may not have succeeded.
|
|
|
|
|
/// </returns>
|
|
|
|
|
[Command("about")]
|
2023-07-18 17:18:35 +03:00
|
|
|
|
[DiscordDefaultDMPermission(false)]
|
|
|
|
|
[RequireContext(ChannelContext.Guild)]
|
2023-09-30 16:58:32 +03:00
|
|
|
|
[Description("Shows Octobot's developers")]
|
2023-07-18 15:25:02 +03:00
|
|
|
|
[UsedImplicitly]
|
2023-08-02 23:51:16 +03:00
|
|
|
|
public async Task<Result> ExecuteAboutAsync()
|
|
|
|
|
{
|
2023-07-09 16:32:14 +03:00
|
|
|
|
if (!_context.TryGetContextIDs(out var guildId, out _, out _))
|
2023-08-02 23:51:16 +03:00
|
|
|
|
{
|
2023-07-28 19:58:55 +03:00
|
|
|
|
return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context");
|
2023-08-02 23:51:16 +03:00
|
|
|
|
}
|
2023-07-09 16:32:14 +03:00
|
|
|
|
|
2023-10-04 18:21:10 +03:00
|
|
|
|
var botResult = await _userApi.GetCurrentUserAsync(CancellationToken);
|
|
|
|
|
if (!botResult.IsDefined(out var bot))
|
2023-08-02 23:51:16 +03:00
|
|
|
|
{
|
2023-10-04 18:21:10 +03:00
|
|
|
|
return Result.FromError(botResult);
|
2023-08-02 23:51:16 +03:00
|
|
|
|
}
|
2023-07-09 16:32:14 +03:00
|
|
|
|
|
2023-08-02 23:51:16 +03:00
|
|
|
|
var cfg = await _guildData.GetSettings(guildId, CancellationToken);
|
2023-07-18 15:25:02 +03:00
|
|
|
|
Messages.Culture = GuildSettings.Language.Get(cfg);
|
2023-07-09 16:32:14 +03:00
|
|
|
|
|
2023-10-04 18:21:10 +03:00
|
|
|
|
return await SendAboutBotAsync(bot, guildId, CancellationToken);
|
2023-07-20 23:41:02 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-04 18:21:10 +03:00
|
|
|
|
private async Task<Result> SendAboutBotAsync(IUser bot, Snowflake guildId, CancellationToken ct = default)
|
2023-08-02 23:51:16 +03:00
|
|
|
|
{
|
2023-09-29 18:36:16 +03:00
|
|
|
|
var builder = new StringBuilder().Append("### ").AppendLine(Messages.AboutTitleDevelopers);
|
2023-07-09 16:32:14 +03:00
|
|
|
|
foreach (var dev in Developers)
|
2023-08-02 23:51:16 +03:00
|
|
|
|
{
|
2023-09-29 18:36:16 +03:00
|
|
|
|
var guildMemberResult = await _guildApi.GetGuildMemberAsync(
|
|
|
|
|
guildId, dev.Id, ct);
|
|
|
|
|
var tag = guildMemberResult.IsSuccess ? $"<@{dev.Id}>" : $"@{dev.Username}";
|
|
|
|
|
|
|
|
|
|
builder.AppendLine($"- {tag} — {$"AboutDeveloper@{dev.Username}".Localized()}");
|
2023-08-02 23:51:16 +03:00
|
|
|
|
}
|
2023-07-09 16:32:14 +03:00
|
|
|
|
|
2023-09-30 16:58:32 +03:00
|
|
|
|
builder.Append($"### [{Messages.AboutTitleRepository}](https://github.com/LabsDevelopment/Octobot)");
|
2023-07-09 16:32:14 +03:00
|
|
|
|
|
2023-10-04 18:21:10 +03:00
|
|
|
|
var embed = new EmbedBuilder().WithSmallTitle(Messages.AboutBot, bot)
|
2023-07-09 16:32:14 +03:00
|
|
|
|
.WithDescription(builder.ToString())
|
|
|
|
|
.WithColour(ColorsList.Cyan)
|
2023-11-22 11:34:40 +03:00
|
|
|
|
.WithImageUrl("https://cdn.mctaylors.ru/octobot-banner.png")
|
2023-07-09 16:32:14 +03:00
|
|
|
|
.Build();
|
|
|
|
|
|
2023-08-02 23:51:16 +03:00
|
|
|
|
return await _feedback.SendContextualEmbedResultAsync(embed, ct);
|
2023-07-09 16:32:14 +03:00
|
|
|
|
}
|
|
|
|
|
}
|