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

Add /guildinfo (#152)

Signed-off-by: Macintosh II <mctaylxrs@outlook.com>
This commit is contained in:
Macintxsh 2023-10-06 15:23:45 +03:00 committed by GitHub
parent 6f1e543edb
commit 72f728323e
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 225 additions and 9 deletions

View file

@ -486,7 +486,7 @@
<data name="ShowInfoDisplayName" xml:space="preserve">
<value>Display name</value>
</data>
<data name="ShowInfoTitle" xml:space="preserve">
<data name="InformationAbout" xml:space="preserve">
<value>Information about {0}</value>
</data>
<data name="ShowInfoMuted" xml:space="preserve">
@ -546,4 +546,22 @@
<data name="TimestampOffset" xml:space="preserve">
<value>Offset: {0}</value>
</data>
<data name="GuildInfoDescription" xml:space="preserve">
<value>Guild description</value>
</data>
<data name="GuildInfoCreatedAt" xml:space="preserve">
<value>Creation date</value>
</data>
<data name="GuildInfoOwner" xml:space="preserve">
<value>Guild owner</value>
</data>
<data name="GuildInfoServerBoost" xml:space="preserve">
<value>Server Boost</value>
</data>
<data name="GuildInfoBoostTier" xml:space="preserve">
<value>Boost level</value>
</data>
<data name="GuildInfoBoostCount" xml:space="preserve">
<value>Boost count</value>
</data>
</root>

View file

@ -486,7 +486,7 @@
<data name="ShowInfoDisplayName" xml:space="preserve">
<value>Отображаемое имя</value>
</data>
<data name="ShowInfoTitle" xml:space="preserve">
<data name="InformationAbout" xml:space="preserve">
<value>Информация о {0}</value>
</data>
<data name="ShowInfoMuted" xml:space="preserve">
@ -546,4 +546,22 @@
<data name="TimestampOffset" xml:space="preserve">
<value>Офсет: {0}</value>
</data>
<data name="GuildInfoDescription" xml:space="preserve">
<value>Описание сервера</value>
</data>
<data name="GuildInfoCreatedAt" xml:space="preserve">
<value>Дата создания</value>
</data>
<data name="GuildInfoOwner" xml:space="preserve">
<value>Владелец сервера</value>
</data>
<data name="GuildInfoServerBoost" xml:space="preserve">
<value>Буст сервера</value>
</data>
<data name="GuildInfoBoostTier" xml:space="preserve">
<value>Уровень буста</value>
</data>
<data name="GuildInfoBoostCount" xml:space="preserve">
<value>Количество бустов</value>
</data>
</root>

View file

@ -486,7 +486,7 @@
<data name="ShowInfoDisplayName" xml:space="preserve">
<value>дисплейнейм</value>
</data>
<data name="ShowInfoTitle" xml:space="preserve">
<data name="InformationAbout" xml:space="preserve">
<value>деанон {0}</value>
</data>
<data name="ShowInfoMuted" xml:space="preserve">
@ -546,4 +546,22 @@
<data name="TimestampOffset" xml:space="preserve">
<value>офсет: {0}</value>
</data>
<data name="GuildInfoDescription" xml:space="preserve">
<value>дескрипшон гильдии</value>
</data>
<data name="GuildInfoCreatedAt" xml:space="preserve">
<value>создался</value>
</data>
<data name="GuildInfoOwner" xml:space="preserve">
<value>админ гильдии</value>
</data>
<data name="GuildInfoServerBoost" xml:space="preserve">
<value>буст гильдии</value>
</data>
<data name="GuildInfoBoostTier" xml:space="preserve">
<value>уровень</value>
</data>
<data name="GuildInfoBoostCount" xml:space="preserve">
<value>кол-во бустов</value>
</data>
</root>

View file

@ -19,7 +19,7 @@ using Remora.Results;
namespace Octobot.Commands;
/// <summary>
/// Handles tool commands: /showinfo, /random, /timestamp.
/// Handles tool commands: /showinfo, /guildinfo, /random, /timestamp.
/// </summary>
[UsedImplicitly]
public class ToolsCommandGroup : CommandGroup
@ -155,10 +155,10 @@ public class ToolsCommandGroup : CommandGroup
}
var embed = new EmbedBuilder().WithSmallTitle(
string.Format(Messages.ShowInfoTitle, target.GetTag()), bot)
string.Format(Messages.InformationAbout, target.GetTag()), bot)
.WithDescription(builder.ToString())
.WithColour(embedColor)
.WithLargeAvatar(target)
.WithLargeUserAvatar(target)
.WithFooter($"ID: {target.ID.ToString()}")
.Build();
@ -229,6 +229,91 @@ public class ToolsCommandGroup : CommandGroup
}
}
/// <summary>
/// A slash command that shows guild information.
/// </summary>
/// <remarks>
/// Information in the output:
/// <list type="bullet">
/// <item>Guild description</item>
/// <item>Creation date</item>
/// <item>Guild's language</item>
/// <item>Guild's owner</item>
/// <item>Boost level</item>
/// <item>Boost count</item>
/// </list>
/// </remarks>
/// <returns>
/// A feedback sending result which may or may not have succeeded.
/// </returns>
[Command("guildinfo")]
[DiscordDefaultDMPermission(false)]
[Description("Shows info current guild")]
[UsedImplicitly]
public async Task<Result> 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 Result.FromError(botResult);
}
var guildResult = await _guildApi.GetGuildAsync(guildId, ct: CancellationToken);
if (!guildResult.IsDefined(out var guild))
{
return Result.FromError(guildResult);
}
var data = await _guildData.GetData(guildId, CancellationToken);
Messages.Culture = GuildSettings.Language.Get(data.Settings);
return await ShowGuildInfoAsync(bot, guild, CancellationToken);
}
private async Task<Result> ShowGuildInfoAsync(IUser bot, IGuild guild, CancellationToken ct)
{
var description = new StringBuilder().AppendLine($"## {guild.Name}");
if (guild.Description is not null)
{
description.Append("- ").AppendLine(Messages.GuildInfoDescription)
.AppendLine(Markdown.InlineCode(guild.Description));
}
description.Append("- ").AppendLine(Messages.GuildInfoCreatedAt)
.AppendLine(Markdown.Timestamp(guild.ID.Timestamp))
.Append("- ").AppendLine(Messages.GuildInfoOwner)
.AppendLine(Mention.User(guild.OwnerID));
var embedColor = ColorsList.Cyan;
if (guild.PremiumTier > PremiumTier.None)
{
description.Append("### ").AppendLine(Messages.GuildInfoServerBoost)
.Append("- ").Append(Messages.GuildInfoBoostTier)
.Append(": ").AppendLine(Markdown.InlineCode(guild.PremiumTier.ToString()))
.Append("- ").Append(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 await _feedback.SendContextualEmbedResultAsync(embed, ct);
}
/// <summary>
/// A slash command that generates a random number using maximum and minimum numbers.
/// </summary>

View file

@ -64,7 +64,7 @@ public static class Extensions
/// <param name="builder">The builder to add the thumbnail to.</param>
/// <param name="avatarSource">The user whose avatar to use in the thumbnail field.</param>
/// <returns>The builder with the added avatar in the thumbnail field.</returns>
public static EmbedBuilder WithLargeAvatar(
public static EmbedBuilder WithLargeUserAvatar(
this EmbedBuilder builder, IUser avatarSource)
{
var avatarUrlResult = CDN.GetUserAvatarUrl(avatarSource, imageSize: 256);
@ -75,6 +75,35 @@ public static class Extensions
return builder.WithThumbnailUrl(avatarUrl.AbsoluteUri);
}
/// <summary>
/// Adds a guild icon in the thumbnail field.
/// </summary>
/// <param name="builder">The builder to add the thumbnail to.</param>
/// <param name="iconSource">The guild whose icon to use in the thumbnail field.</param>
/// <returns>The builder with the added icon in the thumbnail field.</returns>
public static EmbedBuilder WithLargeGuildIcon(
this EmbedBuilder builder, IGuild iconSource)
{
var iconUrlResult = CDN.GetGuildIconUrl(iconSource, imageSize: 256);
return iconUrlResult.IsSuccess
? builder.WithThumbnailUrl(iconUrlResult.Entity.AbsoluteUri)
: builder;
}
/// <summary>
/// Adds a guild banner in the image field.
/// </summary>
/// <param name="builder">The builder to add the image to.</param>
/// <param name="bannerSource">The guild whose banner to use in the image field.</param>
/// <returns>The builder with the added banner in the image field.</returns>
public static EmbedBuilder WithGuildBanner(
this EmbedBuilder builder, IGuild bannerSource)
{
return bannerSource.Banner is not null
? builder.WithImageUrl(CDN.GetGuildBannerUrl(bannerSource).Entity.AbsoluteUri)
: builder;
}
/// <summary>
/// Adds a footer representing that the action was performed in the <paramref name="guild" />.
/// </summary>

View file

@ -798,9 +798,9 @@ namespace Octobot {
}
}
internal static string ShowInfoTitle {
internal static string InformationAbout {
get {
return ResourceManager.GetString("ShowInfoTitle", resourceCulture);
return ResourceManager.GetString("InformationAbout", resourceCulture);
}
}
@ -932,5 +932,53 @@ namespace Octobot {
return ResourceManager.GetString("TimestampOffset", resourceCulture);
}
}
internal static string GuildInfoDescription
{
get
{
return ResourceManager.GetString("GuildInfoDescription", resourceCulture);
}
}
internal static string GuildInfoCreatedAt
{
get
{
return ResourceManager.GetString("GuildInfoCreatedAt", resourceCulture);
}
}
internal static string GuildInfoOwner
{
get
{
return ResourceManager.GetString("GuildInfoOwner", resourceCulture);
}
}
internal static string GuildInfoServerBoost
{
get
{
return ResourceManager.GetString("GuildInfoServerBoost", resourceCulture);
}
}
internal static string GuildInfoBoostTier
{
get
{
return ResourceManager.GetString("GuildInfoBoostTier", resourceCulture);
}
}
internal static string GuildInfoBoostCount
{
get
{
return ResourceManager.GetString("GuildInfoBoostCount", resourceCulture);
}
}
}
}