mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-04-20 00:43:36 +03:00
resolve a ton of conversations
probably pt. 1 Co-authored-by: Octol1ttle <l1ttleofficial@outlook.com> Signed-off-by: Macintosh II <mctaylxrs@outlook.com>
This commit is contained in:
parent
f44e2bad86
commit
9d11de7863
3 changed files with 38 additions and 31 deletions
|
@ -601,7 +601,7 @@
|
||||||
<value>All settings have been reset</value>
|
<value>All settings have been reset</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="ShowInfoDisplayName" xml:space="preserve">
|
<data name="ShowInfoDisplayName" xml:space="preserve">
|
||||||
<value>Display Name</value>
|
<value>Display name</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="NotPresent" xml:space="preserve">
|
<data name="NotPresent" xml:space="preserve">
|
||||||
<value>Not present</value>
|
<value>Not present</value>
|
||||||
|
|
|
@ -634,6 +634,6 @@
|
||||||
<value>Заглушен с помощью тайм-аута</value>
|
<value>Заглушен с помощью тайм-аута</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="ShowInfoMutedWithMuteRole" xml:space="preserve">
|
<data name="ShowInfoMutedWithMuteRole" xml:space="preserve">
|
||||||
<value>Заглушен с помощью мут роли</value>
|
<value>Заглушен с помощью роли мута</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
|
@ -17,6 +17,9 @@ using Remora.Results;
|
||||||
|
|
||||||
namespace Boyfriend.Commands;
|
namespace Boyfriend.Commands;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handles commands related to tools: /showinfo.
|
||||||
|
/// </summary>
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public class ToolsCommandGroup : CommandGroup
|
public class ToolsCommandGroup : CommandGroup
|
||||||
{
|
{
|
||||||
|
@ -38,12 +41,19 @@ public class ToolsCommandGroup : CommandGroup
|
||||||
_userApi = userApi;
|
_userApi = userApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A slash command that shows information about user.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="target">The user to show info about.</param>
|
||||||
|
/// <returns>
|
||||||
|
/// A feedback sending result which may or may not have succeeded.
|
||||||
|
/// </returns>
|
||||||
[Command("showinfo")]
|
[Command("showinfo")]
|
||||||
[DiscordDefaultDMPermission(false)]
|
[DiscordDefaultDMPermission(false)]
|
||||||
[Description("Shows info about user")]
|
[Description("Shows info about user")]
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public async Task<Result> ExecuteShowInfoAsync(
|
public async Task<Result> ExecuteShowInfoAsync(
|
||||||
[Description("Specific user or ID to show info about")]
|
[Description("User to show info about")]
|
||||||
IUser? target = null)
|
IUser? target = null)
|
||||||
{
|
{
|
||||||
if (!_context.TryGetContextIDs(out var guildId, out _, out var userId))
|
if (!_context.TryGetContextIDs(out var guildId, out _, out var userId))
|
||||||
|
@ -66,29 +76,12 @@ public class ToolsCommandGroup : CommandGroup
|
||||||
var data = await _guildData.GetData(guildId, CancellationToken);
|
var data = await _guildData.GetData(guildId, CancellationToken);
|
||||||
Messages.Culture = GuildSettings.Language.Get(data.Settings);
|
Messages.Culture = GuildSettings.Language.Get(data.Settings);
|
||||||
|
|
||||||
if (target is not null)
|
return await ShowUserInfoAsync(target ?? user, currentUser, data, guildId, CancellationToken);
|
||||||
{
|
|
||||||
return await ShowUserInfoAsync(target, currentUser, data, guildId, CancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
return await ShowUserInfoAsync(user, currentUser, data, guildId, CancellationToken);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Result> ShowUserInfoAsync(
|
private async Task<Result> ShowUserInfoAsync(
|
||||||
IUser user, IUser currentUser, GuildData data, Snowflake guildId, CancellationToken ct = default)
|
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}>");
|
var builder = new StringBuilder().AppendLine($"### <@{user.ID}>");
|
||||||
|
|
||||||
if (user.GlobalName is not null)
|
if (user.GlobalName is not null)
|
||||||
|
@ -100,6 +93,22 @@ public class ToolsCommandGroup : CommandGroup
|
||||||
builder.Append("- ").AppendLine(Messages.ShowInfoDiscordUserSince)
|
builder.Append("- ").AppendLine(Messages.ShowInfoDiscordUserSince)
|
||||||
.Append(" - ").AppendLine(Markdown.Timestamp(user.ID.Timestamp));
|
.Append(" - ").AppendLine(Markdown.Timestamp(user.ID.Timestamp));
|
||||||
|
|
||||||
|
var memberData = data.GetOrCreateMemberData(user.ID);
|
||||||
|
|
||||||
|
var guildMemberResult = await _guildApi.GetGuildMemberAsync(guildId, user.ID, ct);
|
||||||
|
DateTimeOffset? communicationDisabledUntil = null;
|
||||||
|
if (guildMemberResult.IsSuccess)
|
||||||
|
{
|
||||||
|
communicationDisabledUntil = guildMemberResult.Entity.CommunicationDisabledUntil.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
var isMuted = (memberData.MutedUntil is not null && DateTimeOffset.UtcNow <= memberData.MutedUntil) ||
|
||||||
|
communicationDisabledUntil is not null;
|
||||||
|
|
||||||
|
var existingBanResult = await _guildApi.GetGuildBanAsync(guildId, user.ID, ct);
|
||||||
|
|
||||||
|
var embedColor = ColorsList.Cyan;
|
||||||
|
|
||||||
if (isMuted || existingBanResult.IsDefined())
|
if (isMuted || existingBanResult.IsDefined())
|
||||||
{
|
{
|
||||||
builder.Append("### ")
|
builder.Append("### ")
|
||||||
|
@ -108,7 +117,7 @@ public class ToolsCommandGroup : CommandGroup
|
||||||
|
|
||||||
if (isMuted)
|
if (isMuted)
|
||||||
{
|
{
|
||||||
ShowInfoMutedUntilAsync(memberData, guildMember, builder);
|
ShowInfoMutedUntilAsync(memberData, communicationDisabledUntil, builder);
|
||||||
|
|
||||||
embedColor = ColorsList.Red;
|
embedColor = ColorsList.Red;
|
||||||
}
|
}
|
||||||
|
@ -146,30 +155,28 @@ public class ToolsCommandGroup : CommandGroup
|
||||||
builder.Append("- ").AppendLine(Messages.ShowInfoBanned)
|
builder.Append("- ").AppendLine(Messages.ShowInfoBanned)
|
||||||
.Append(" - ").AppendLine(string.Format(
|
.Append(" - ").AppendLine(string.Format(
|
||||||
Messages.DescriptionActionExpiresAt, Markdown.Timestamp(memberData.BannedUntil.Value)));
|
Messages.DescriptionActionExpiresAt, Markdown.Timestamp(memberData.BannedUntil.Value)));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memberData.BannedUntil >= DateTimeOffset.MaxValue)
|
builder.Append("- ").AppendLine(Messages.ShowInfoBannedPermanently);
|
||||||
{
|
|
||||||
builder.Append("- ").AppendLine(Messages.ShowInfoBannedPermanently);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ShowInfoMutedUntilAsync(
|
private static void ShowInfoMutedUntilAsync(
|
||||||
MemberData memberData, IGuildMember? guildMember, StringBuilder builder)
|
MemberData memberData, DateTimeOffset? communicationDisabledUntil, StringBuilder builder)
|
||||||
{
|
{
|
||||||
builder.Append("- ").AppendLine(Messages.ShowInfoMuted);
|
builder.Append("- ").AppendLine(Messages.ShowInfoMuted);
|
||||||
if (memberData.MutedUntil is not null && DateTimeOffset.UtcNow <= memberData.MutedUntil)
|
if (memberData.MutedUntil is not null && DateTimeOffset.UtcNow <= memberData.MutedUntil)
|
||||||
{
|
{
|
||||||
builder.Append(" - ").AppendLine(Messages.ShowInfoMutedWithMuteRole)
|
builder.Append(" - ").AppendLine(Messages.ShowInfoMutedWithMuteRole)
|
||||||
.Append(" - ").Append(" - ").AppendLine(string.Format(
|
.Append(" - ").AppendLine(string.Format(
|
||||||
Messages.DescriptionActionExpiresAt, Markdown.Timestamp(memberData.MutedUntil.Value)));
|
Messages.DescriptionActionExpiresAt, Markdown.Timestamp(memberData.MutedUntil.Value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (guildMember is not null && guildMember.CommunicationDisabledUntil.IsDefined())
|
if (communicationDisabledUntil is not null)
|
||||||
{
|
{
|
||||||
builder.Append(" - ").AppendLine(Messages.ShowInfoMutedWithTimeout)
|
builder.Append(" - ").AppendLine(Messages.ShowInfoMutedWithTimeout)
|
||||||
.Append(" - ").Append(" - ").AppendLine(string.Format(
|
.Append(" - ").AppendLine(string.Format(
|
||||||
Messages.DescriptionActionExpiresAt, Markdown.Timestamp(guildMember.CommunicationDisabledUntil.Value.Value)));
|
Messages.DescriptionActionExpiresAt, Markdown.Timestamp(communicationDisabledUntil.Value)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue