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-12-17 19:49:44 +03:00
|
|
|
|
using Remora.Discord.API.Objects;
|
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;
|
2023-12-17 19:49:44 +03:00
|
|
|
|
using Remora.Discord.Commands.Feedback.Messages;
|
2023-07-09 16:32:14 +03:00
|
|
|
|
using Remora.Discord.Commands.Feedback.Services;
|
|
|
|
|
using Remora.Discord.Extensions.Embeds;
|
2023-12-19 13:32:11 +03:00
|
|
|
|
using Remora.Discord.Extensions.Formatting;
|
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 =
|
2023-12-20 19:23:37 +03:00
|
|
|
|
[
|
2023-09-29 18:36:16 +03:00
|
|
|
|
("Octol1ttle", new Snowflake(504343489664909322)),
|
|
|
|
|
("mctaylors", new Snowflake(326642240229474304)),
|
|
|
|
|
("neroduckale", new Snowflake(474943797063843851))
|
2023-12-20 19:23:37 +03:00
|
|
|
|
];
|
2023-09-29 18:36:16 +03:00
|
|
|
|
|
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
|
|
|
|
{
|
2024-03-20 21:08:16 +03:00
|
|
|
|
return ResultExtensions.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);
|
2023-12-18 12:26:08 +03:00
|
|
|
|
var tag = guildMemberResult.IsSuccess
|
|
|
|
|
? $"<@{dev.Id}>"
|
2023-12-19 13:32:11 +03:00
|
|
|
|
: Markdown.Hyperlink($"@{dev.Username}", $"https://github.com/{dev.Username}");
|
2023-09-29 18:36:16 +03:00
|
|
|
|
|
2023-12-04 17:09:47 +03:00
|
|
|
|
builder.AppendBulletPointLine($"{tag} — {$"AboutDeveloper@{dev.Username}".Localized()}");
|
2023-08-02 23:51:16 +03:00
|
|
|
|
}
|
2023-07-09 16:32:14 +03:00
|
|
|
|
|
2023-12-20 19:25:13 +03:00
|
|
|
|
var embed = new EmbedBuilder()
|
|
|
|
|
.WithSmallTitle(string.Format(Messages.AboutBot, bot.Username), bot)
|
2023-07-09 16:32:14 +03:00
|
|
|
|
.WithDescription(builder.ToString())
|
|
|
|
|
.WithColour(ColorsList.Cyan)
|
2024-01-22 18:47:53 +03:00
|
|
|
|
.WithImageUrl("https://i.ibb.co/fS6wZhh/octobot-banner.png")
|
2024-03-19 20:51:32 +03:00
|
|
|
|
.WithFooter(string.Format(Messages.Version, BuildInfo.Version))
|
2023-07-09 16:32:14 +03:00
|
|
|
|
.Build();
|
|
|
|
|
|
2023-12-17 21:35:09 +03:00
|
|
|
|
var repositoryButton = new ButtonComponent(
|
|
|
|
|
ButtonComponentStyle.Link,
|
|
|
|
|
Messages.ButtonOpenRepository,
|
|
|
|
|
new PartialEmoji(Name: "🌐"),
|
2024-03-19 20:51:32 +03:00
|
|
|
|
URL: BuildInfo.RepositoryUrl
|
2023-12-17 21:35:09 +03:00
|
|
|
|
);
|
|
|
|
|
|
2024-03-23 21:45:39 +03:00
|
|
|
|
var wikiButton = new ButtonComponent(
|
|
|
|
|
ButtonComponentStyle.Link,
|
|
|
|
|
Messages.ButtonOpenWiki,
|
|
|
|
|
new PartialEmoji(Name: "📖"),
|
|
|
|
|
URL: BuildInfo.WikiUrl
|
|
|
|
|
);
|
|
|
|
|
|
2023-12-17 21:35:09 +03:00
|
|
|
|
var issuesButton = new ButtonComponent(
|
2023-12-17 19:49:44 +03:00
|
|
|
|
ButtonComponentStyle.Link,
|
2024-03-20 15:59:25 +03:00
|
|
|
|
BuildInfo.IsDirty
|
|
|
|
|
? Messages.ButtonDirty
|
|
|
|
|
: Messages.ButtonReportIssue,
|
2023-12-17 21:35:09 +03:00
|
|
|
|
new PartialEmoji(Name: "⚠️"),
|
2024-03-20 15:59:25 +03:00
|
|
|
|
URL: BuildInfo.IssuesUrl,
|
|
|
|
|
IsDisabled: BuildInfo.IsDirty
|
2023-12-17 19:49:44 +03:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return await _feedback.SendContextualEmbedResultAsync(embed,
|
|
|
|
|
new FeedbackMessageOptions(MessageComponents: new[]
|
|
|
|
|
{
|
2024-03-23 21:45:39 +03:00
|
|
|
|
new ActionRowComponent(new[] { repositoryButton, wikiButton, issuesButton })
|
2023-12-17 19:49:44 +03:00
|
|
|
|
}), ct);
|
2023-07-09 16:32:14 +03:00
|
|
|
|
}
|
|
|
|
|
}
|