mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-04-20 00:43:36 +03:00
Add /showinfo
This commit is contained in:
parent
e907930623
commit
62b6ae736a
7 changed files with 389 additions and 1 deletions
|
@ -600,4 +600,43 @@
|
|||
<data name="AllSettingsReset" xml:space="preserve">
|
||||
<value>All settings have been reset</value>
|
||||
</data>
|
||||
<data name="ShowInfoDisplayName" xml:space="preserve">
|
||||
<value>Display Name</value>
|
||||
</data>
|
||||
<data name="NotPresent" xml:space="preserve">
|
||||
<value>Not present</value>
|
||||
</data>
|
||||
<data name="ShowInfoTitle" xml:space="preserve">
|
||||
<value>Information about {0}</value>
|
||||
</data>
|
||||
<data name="ShowInfoMuted" xml:space="preserve">
|
||||
<value>Muted</value>
|
||||
</data>
|
||||
<data name="ShowInfoDiscordUserSince" xml:space="preserve">
|
||||
<value>Discord user since</value>
|
||||
</data>
|
||||
<data name="ShowInfoMentionedAs" xml:space="preserve">
|
||||
<value>Mentioned as</value>
|
||||
</data>
|
||||
<data name="ShowInfoBanned" xml:space="preserve">
|
||||
<value>Banned</value>
|
||||
</data>
|
||||
<data name="ShowInfoPunishments" xml:space="preserve">
|
||||
<value>Punishments</value>
|
||||
</data>
|
||||
<data name="ShowInfoBannedPermanently" xml:space="preserve">
|
||||
<value>Banned permanently</value>
|
||||
</data>
|
||||
<data name="ShowInfoNotOnServer" xml:space="preserve">
|
||||
<value>Not on the server</value>
|
||||
</data>
|
||||
<data name="ShowInfoMutedWithTimeout" xml:space="preserve">
|
||||
<value>Muted with a timeout</value>
|
||||
</data>
|
||||
<data name="ShowInfoMutedWithMuteRole" xml:space="preserve">
|
||||
<value>Muted with a mute role</value>
|
||||
</data>
|
||||
<data name="ShowInfoUntil" xml:space="preserve">
|
||||
<value>Until</value>
|
||||
</data>
|
||||
</root>
|
||||
|
|
|
@ -600,4 +600,43 @@
|
|||
<data name="AllSettingsReset" xml:space="preserve">
|
||||
<value>Все настройки были сброшены</value>
|
||||
</data>
|
||||
<data name="ShowInfoDisplayName" xml:space="preserve">
|
||||
<value>Отображаемое имя</value>
|
||||
</data>
|
||||
<data name="NotPresent" xml:space="preserve">
|
||||
<value>Отсутствует</value>
|
||||
</data>
|
||||
<data name="ShowInfoTitle" xml:space="preserve">
|
||||
<value>Информация о {0}</value>
|
||||
</data>
|
||||
<data name="ShowInfoMuted" xml:space="preserve">
|
||||
<value>Заглушен</value>
|
||||
</data>
|
||||
<data name="ShowInfoDiscordUserSince" xml:space="preserve">
|
||||
<value>Пользователь Discord с</value>
|
||||
</data>
|
||||
<data name="ShowInfoMentionedAs" xml:space="preserve">
|
||||
<value>Упоминается как</value>
|
||||
</data>
|
||||
<data name="ShowInfoBanned" xml:space="preserve">
|
||||
<value>Забанен</value>
|
||||
</data>
|
||||
<data name="ShowInfoPunishments" xml:space="preserve">
|
||||
<value>Наказания</value>
|
||||
</data>
|
||||
<data name="ShowInfoBannedPermanently" xml:space="preserve">
|
||||
<value>Забанен навсегда</value>
|
||||
</data>
|
||||
<data name="ShowInfoNotOnServer" xml:space="preserve">
|
||||
<value>Не на сервере</value>
|
||||
</data>
|
||||
<data name="ShowInfoMutedWithTimeout" xml:space="preserve">
|
||||
<value>Заглушен с помощью тайм-аута</value>
|
||||
</data>
|
||||
<data name="ShowInfoMutedWithMuteRole" xml:space="preserve">
|
||||
<value>Заглушен с помощью мут роли</value>
|
||||
</data>
|
||||
<data name="ShowInfoUntil" xml:space="preserve">
|
||||
<value>До</value>
|
||||
</data>
|
||||
</root>
|
||||
|
|
|
@ -600,4 +600,43 @@
|
|||
<data name="AllSettingsReset" xml:space="preserve">
|
||||
<value>откатываемся к заводским...</value>
|
||||
</data>
|
||||
<data name="ShowInfoDisplayName" xml:space="preserve">
|
||||
<value>дисплейнейм</value>
|
||||
</data>
|
||||
<data name="NotPresent" xml:space="preserve">
|
||||
<value>нету такого</value>
|
||||
</data>
|
||||
<data name="ShowInfoTitle" xml:space="preserve">
|
||||
<value>деанон {0}</value>
|
||||
</data>
|
||||
<data name="ShowInfoMuted" xml:space="preserve">
|
||||
<value>замучен</value>
|
||||
</data>
|
||||
<data name="ShowInfoDiscordUserSince" xml:space="preserve">
|
||||
<value>юзер Discord со времен</value>
|
||||
</data>
|
||||
<data name="ShowInfoMentionedAs" xml:space="preserve">
|
||||
<value>пинается как</value>
|
||||
</data>
|
||||
<data name="ShowInfoBanned" xml:space="preserve">
|
||||
<value>забанен</value>
|
||||
</data>
|
||||
<data name="ShowInfoPunishments" xml:space="preserve">
|
||||
<value>приколы полученные по заслугам</value>
|
||||
</data>
|
||||
<data name="ShowInfoBannedPermanently" xml:space="preserve">
|
||||
<value>забанен</value>
|
||||
</data>
|
||||
<data name="ShowInfoNotOnServer" xml:space="preserve">
|
||||
<value>вышел из сервера</value>
|
||||
</data>
|
||||
<data name="ShowInfoMutedWithTimeout" xml:space="preserve">
|
||||
<value>замучен таймаутом</value>
|
||||
</data>
|
||||
<data name="ShowInfoMutedWithMuteRole" xml:space="preserve">
|
||||
<value>замучен ролькой</value>
|
||||
</data>
|
||||
<data name="ShowInfoUntil" xml:space="preserve">
|
||||
<value>до</value>
|
||||
</data>
|
||||
</root>
|
||||
|
|
|
@ -102,7 +102,8 @@ public sealed class Boyfriend
|
|||
.WithCommandGroup<MuteCommandGroup>()
|
||||
.WithCommandGroup<PingCommandGroup>()
|
||||
.WithCommandGroup<RemindCommandGroup>()
|
||||
.WithCommandGroup<SettingsCommandGroup>();
|
||||
.WithCommandGroup<SettingsCommandGroup>()
|
||||
.WithCommandGroup<ToolsCommandGroup>();
|
||||
var responderTypes = typeof(Boyfriend).Assembly
|
||||
.GetExportedTypes()
|
||||
.Where(t => t.IsResponder());
|
||||
|
|
175
src/Commands/ToolsCommandGroup.cs
Normal file
175
src/Commands/ToolsCommandGroup.cs
Normal file
|
@ -0,0 +1,175 @@
|
|||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
using Boyfriend.Data;
|
||||
using Boyfriend.Services;
|
||||
using JetBrains.Annotations;
|
||||
using Remora.Commands.Attributes;
|
||||
using Remora.Commands.Groups;
|
||||
using Remora.Discord.API.Abstractions.Objects;
|
||||
using Remora.Discord.API.Abstractions.Rest;
|
||||
using Remora.Discord.Commands.Attributes;
|
||||
using Remora.Discord.Commands.Contexts;
|
||||
using Remora.Discord.Commands.Feedback.Services;
|
||||
using Remora.Discord.Extensions.Embeds;
|
||||
using Remora.Discord.Extensions.Formatting;
|
||||
using Remora.Rest.Core;
|
||||
using Remora.Results;
|
||||
|
||||
namespace Boyfriend.Commands;
|
||||
|
||||
[UsedImplicitly]
|
||||
public class ToolsCommandGroup : CommandGroup
|
||||
{
|
||||
private readonly ICommandContext _context;
|
||||
private readonly FeedbackService _feedback;
|
||||
private readonly GuildDataService _guildData;
|
||||
private readonly IDiscordRestGuildAPI _guildApi;
|
||||
private readonly IDiscordRestUserAPI _userApi;
|
||||
|
||||
public ToolsCommandGroup(
|
||||
ICommandContext context, FeedbackService feedback,
|
||||
GuildDataService guildData, IDiscordRestGuildAPI guildApi,
|
||||
IDiscordRestUserAPI userApi, IDiscordRestChannelAPI channelApi)
|
||||
{
|
||||
_context = context;
|
||||
_guildData = guildData;
|
||||
_feedback = feedback;
|
||||
_guildApi = guildApi;
|
||||
_userApi = userApi;
|
||||
}
|
||||
|
||||
[Command("showinfo")]
|
||||
[DiscordDefaultDMPermission(false)]
|
||||
[Description("Shows info about user")]
|
||||
[UsedImplicitly]
|
||||
public async Task<Result> ExecuteShowInfoAsync(
|
||||
[Description("Specific user or ID to show info about")]
|
||||
IUser? target = null)
|
||||
{
|
||||
if (!_context.TryGetContextIDs(out var guildId, out _, out var userId))
|
||||
{
|
||||
return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context");
|
||||
}
|
||||
|
||||
var userResult = await _userApi.GetUserAsync(userId, CancellationToken);
|
||||
if (!userResult.IsDefined(out var user))
|
||||
{
|
||||
return Result.FromError(userResult);
|
||||
}
|
||||
|
||||
var currentUserResult = await _userApi.GetCurrentUserAsync(CancellationToken);
|
||||
if (!currentUserResult.IsDefined(out var currentUser))
|
||||
{
|
||||
return Result.FromError(currentUserResult);
|
||||
}
|
||||
|
||||
var data = await _guildData.GetData(guildId, CancellationToken);
|
||||
Messages.Culture = GuildSettings.Language.Get(data.Settings);
|
||||
|
||||
if (target is not null)
|
||||
{
|
||||
return await ShowUserInfoAsync(target, currentUser, data, guildId, CancellationToken);
|
||||
}
|
||||
|
||||
return await ShowUserInfoAsync(user, currentUser, data, guildId, CancellationToken);
|
||||
}
|
||||
|
||||
private async Task<Result> ShowUserInfoAsync(
|
||||
IUser user, IUser currentUser, GuildData data, Snowflake guildId, CancellationToken ct = default)
|
||||
{
|
||||
var embedColor = ColorsList.Cyan;
|
||||
|
||||
var memberData = data.GetOrCreateMemberData(user.ID);
|
||||
|
||||
var guildMemberResult = await _guildApi.GetGuildMemberAsync(guildId, user.ID, ct);
|
||||
guildMemberResult.IsDefined(out var guildMember);
|
||||
|
||||
var isMuted = (memberData.MutedUntil is not null && DateTimeOffset.UtcNow <= memberData.MutedUntil) ||
|
||||
(guildMember is not null && guildMember.CommunicationDisabledUntil.IsDefined());
|
||||
|
||||
var existingBanResult = await _guildApi.GetGuildBanAsync(guildId, user.ID, ct);
|
||||
|
||||
var builder = new StringBuilder().AppendLine($"### <@{user.ID}>");
|
||||
|
||||
if (user.GlobalName is not null)
|
||||
{
|
||||
builder.Append("- ").AppendLine(Messages.ShowInfoDisplayName)
|
||||
.Append(" - ").AppendLine(Markdown.Sanitize(user.GlobalName));
|
||||
}
|
||||
|
||||
builder.Append("- ").AppendLine(Messages.ShowInfoDiscordUserSince)
|
||||
.Append(" - ").AppendLine(Markdown.Timestamp(user.ID.Timestamp));
|
||||
|
||||
if (isMuted || existingBanResult.IsDefined())
|
||||
{
|
||||
builder.Append("### ")
|
||||
.AppendLine(Markdown.Bold(Messages.ShowInfoPunishments));
|
||||
}
|
||||
|
||||
if (isMuted)
|
||||
{
|
||||
ShowInfoMutedUntilAsync(memberData, guildMember, builder);
|
||||
|
||||
embedColor = ColorsList.Red;
|
||||
}
|
||||
|
||||
if (existingBanResult.IsDefined())
|
||||
{
|
||||
ShowInfoBannedUntilAsync(memberData, builder);
|
||||
|
||||
embedColor = ColorsList.Black;
|
||||
}
|
||||
|
||||
if (!guildMemberResult.IsSuccess && !existingBanResult.IsDefined())
|
||||
{
|
||||
builder.Append("### ")
|
||||
.AppendLine(Markdown.Bold(Messages.ShowInfoNotOnServer));
|
||||
|
||||
embedColor = ColorsList.Default;
|
||||
}
|
||||
|
||||
var embed = new EmbedBuilder().WithSmallTitle(
|
||||
string.Format(Messages.ShowInfoTitle, user.GetTag()), currentUser)
|
||||
.WithDescription(builder.ToString())
|
||||
.WithColour(embedColor)
|
||||
.WithLargeAvatar(user)
|
||||
.WithFooter($"ID: {user.ID.ToString()}")
|
||||
.Build();
|
||||
|
||||
return await _feedback.SendContextualEmbedResultAsync(embed, ct);
|
||||
}
|
||||
|
||||
private static void ShowInfoBannedUntilAsync(MemberData memberData, StringBuilder builder)
|
||||
{
|
||||
if (memberData.BannedUntil < DateTimeOffset.MaxValue)
|
||||
{
|
||||
builder.Append("- ").AppendLine(Messages.ShowInfoBanned)
|
||||
.Append(" - ").Append(Messages.ShowInfoUntil).Append(' ')
|
||||
.AppendLine(Markdown.Timestamp(memberData.BannedUntil.Value));
|
||||
}
|
||||
|
||||
if (memberData.BannedUntil >= DateTimeOffset.MaxValue)
|
||||
{
|
||||
builder.Append("- ").AppendLine(Messages.ShowInfoBannedPermanently);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ShowInfoMutedUntilAsync(
|
||||
MemberData memberData, IGuildMember? guildMember, StringBuilder builder)
|
||||
{
|
||||
builder.Append("- ").AppendLine(Messages.ShowInfoMuted);
|
||||
if (memberData.MutedUntil is not null && DateTimeOffset.UtcNow <= memberData.MutedUntil)
|
||||
{
|
||||
builder.Append(" - ").AppendLine(Messages.ShowInfoMutedWithMuteRole)
|
||||
.Append(" - ").Append(Messages.ShowInfoUntil).Append(' ')
|
||||
.AppendLine(Markdown.Timestamp(memberData.MutedUntil.Value));
|
||||
}
|
||||
|
||||
if (guildMember is not null && guildMember.CommunicationDisabledUntil.IsDefined())
|
||||
{
|
||||
builder.Append(" - ").AppendLine(Messages.ShowInfoMutedWithTimeout)
|
||||
.Append(" - ").Append(Messages.ShowInfoUntil).Append(' ')
|
||||
.AppendLine(Markdown.Timestamp(guildMember.CommunicationDisabledUntil.Value.Value));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -74,6 +74,23 @@ public static class Extensions
|
|||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a user avatar in the thumbnail field.
|
||||
/// </summary>
|
||||
/// <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(
|
||||
this EmbedBuilder builder, IUser avatarSource)
|
||||
{
|
||||
var avatarUrlResult = CDN.GetUserAvatarUrl(avatarSource, imageSize: 256);
|
||||
var avatarUrl = avatarUrlResult.IsSuccess
|
||||
? avatarUrlResult.Entity
|
||||
: CDN.GetDefaultUserAvatarUrl(avatarSource, imageSize: 256).Entity;
|
||||
|
||||
return builder.WithThumbnailUrl(avatarUrl.AbsoluteUri);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a footer representing that the action was performed in the <paramref name="guild" />.
|
||||
/// </summary>
|
||||
|
|
78
src/Messages.Designer.cs
generated
78
src/Messages.Designer.cs
generated
|
@ -1013,5 +1013,83 @@ namespace Boyfriend {
|
|||
return ResourceManager.GetString("AllSettingsReset", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string NotPresent {
|
||||
get {
|
||||
return ResourceManager.GetString("NotPresent", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string ShowInfoTitle {
|
||||
get {
|
||||
return ResourceManager.GetString("ShowInfoTitle", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string ShowInfoMentionedAs {
|
||||
get {
|
||||
return ResourceManager.GetString("ShowInfoMentionedAs", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string ShowInfoDisplayName {
|
||||
get {
|
||||
return ResourceManager.GetString("ShowInfoDisplayName", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string ShowInfoDiscordUserSince {
|
||||
get {
|
||||
return ResourceManager.GetString("ShowInfoDiscordUserSince", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string ShowInfoMuted {
|
||||
get {
|
||||
return ResourceManager.GetString("ShowInfoMuted", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string ShowInfoBanned {
|
||||
get {
|
||||
return ResourceManager.GetString("ShowInfoBanned", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string ShowInfoPunishments {
|
||||
get {
|
||||
return ResourceManager.GetString("ShowInfoPunishments", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string ShowInfoBannedPermanently {
|
||||
get {
|
||||
return ResourceManager.GetString("ShowInfoBannedPermanently", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string ShowInfoNotOnServer {
|
||||
get {
|
||||
return ResourceManager.GetString("ShowInfoNotOnServer", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string ShowInfoMutedWithTimeout {
|
||||
get {
|
||||
return ResourceManager.GetString("ShowInfoMutedWithTimeout", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string ShowInfoMutedWithMuteRole {
|
||||
get {
|
||||
return ResourceManager.GetString("ShowInfoMutedWithMuteRole", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string ShowInfoUntil {
|
||||
get {
|
||||
return ResourceManager.GetString("ShowInfoUntil", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue