mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-01-31 09:09:00 +03:00
/userinfo: Show if the user was kicked (#242)
Closes #241 Updates: - Show if the user was kicked by [adding "Kicked" parameter to MemberData](https://github.com/LabsDevelopment/Octobot/issues/241) - Change `mctaylors-ru`'s `UserInfoBannedPermanently` string to be different from `UserInfoBanned` - Finally add `AppendPunishmentsInformation` method to avoid Cognitive Complexity - Use MemberData to check if the user was banned - Rename variable `isMuted` to `wasMuted` to be consistent with other variable names --------- Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
This commit is contained in:
parent
7d9a85d815
commit
285763d50d
9 changed files with 58 additions and 24 deletions
|
@ -585,4 +585,7 @@
|
||||||
<data name="ButtonReportIssue" xml:space="preserve">
|
<data name="ButtonReportIssue" xml:space="preserve">
|
||||||
<value>Report an issue</value>
|
<value>Report an issue</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="UserInfoKicked" xml:space="preserve">
|
||||||
|
<value>Kicked</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
|
@ -585,4 +585,7 @@
|
||||||
<data name="ButtonReportIssue" xml:space="preserve">
|
<data name="ButtonReportIssue" xml:space="preserve">
|
||||||
<value>Сообщить о проблеме</value>
|
<value>Сообщить о проблеме</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="UserInfoKicked" xml:space="preserve">
|
||||||
|
<value>Выгнан</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
|
@ -502,7 +502,7 @@
|
||||||
<value>приколы полученные по заслугам</value>
|
<value>приколы полученные по заслугам</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="UserInfoBannedPermanently" xml:space="preserve">
|
<data name="UserInfoBannedPermanently" xml:space="preserve">
|
||||||
<value>забанен</value>
|
<value>пермабан</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="UserInfoNotOnGuild" xml:space="preserve">
|
<data name="UserInfoNotOnGuild" xml:space="preserve">
|
||||||
<value>вышел из сервера</value>
|
<value>вышел из сервера</value>
|
||||||
|
@ -585,4 +585,7 @@
|
||||||
<data name="ButtonReportIssue" xml:space="preserve">
|
<data name="ButtonReportIssue" xml:space="preserve">
|
||||||
<value>зарепортить баг</value>
|
<value>зарепортить баг</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="UserInfoKicked" xml:space="preserve">
|
||||||
|
<value>кикнут</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
|
@ -151,7 +151,9 @@ public class KickCommandGroup : CommandGroup
|
||||||
return Result.FromError(kickResult.Error);
|
return Result.FromError(kickResult.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.GetOrCreateMemberData(target.ID).Roles.Clear();
|
var memberData = data.GetOrCreateMemberData(target.ID);
|
||||||
|
memberData.Roles.Clear();
|
||||||
|
memberData.Kicked = true;
|
||||||
|
|
||||||
var title = string.Format(Messages.UserKicked, target.GetTag());
|
var title = string.Format(Messages.UserKicked, target.GetTag());
|
||||||
var description = MarkdownExtensions.BulletPoint(string.Format(Messages.DescriptionActionReason, reason));
|
var description = MarkdownExtensions.BulletPoint(string.Format(Messages.DescriptionActionReason, reason));
|
||||||
|
|
|
@ -300,9 +300,9 @@ public class MuteCommandGroup : CommandGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
var memberData = data.GetOrCreateMemberData(target.ID);
|
var memberData = data.GetOrCreateMemberData(target.ID);
|
||||||
var isMuted = memberData.MutedUntil is not null || communicationDisabledUntil is not null;
|
var wasMuted = memberData.MutedUntil is not null || communicationDisabledUntil is not null;
|
||||||
|
|
||||||
if (!isMuted)
|
if (!wasMuted)
|
||||||
{
|
{
|
||||||
var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.UserNotMuted, bot)
|
var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.UserNotMuted, bot)
|
||||||
.WithColour(ColorsList.Red).Build();
|
.WithColour(ColorsList.Red).Build();
|
||||||
|
|
|
@ -122,32 +122,21 @@ public class ToolsCommandGroup : CommandGroup
|
||||||
embedColor = AppendGuildInformation(embedColor, guildMember, builder);
|
embedColor = AppendGuildInformation(embedColor, guildMember, builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
var isMuted = (memberData.MutedUntil is not null && DateTimeOffset.UtcNow <= memberData.MutedUntil) ||
|
var wasMuted = (memberData.MutedUntil is not null && DateTimeOffset.UtcNow <= memberData.MutedUntil) ||
|
||||||
communicationDisabledUntil is not null;
|
communicationDisabledUntil is not null;
|
||||||
|
var wasBanned = memberData.BannedUntil is not null;
|
||||||
|
var wasKicked = memberData.Kicked;
|
||||||
|
|
||||||
var existingBanResult = await _guildApi.GetGuildBanAsync(guildId, target.ID, ct);
|
if (wasMuted || wasBanned || wasKicked)
|
||||||
|
|
||||||
if (isMuted || existingBanResult.IsDefined())
|
|
||||||
{
|
{
|
||||||
builder.Append("### ")
|
builder.Append("### ")
|
||||||
.AppendLine(Markdown.Bold(Messages.UserInfoPunishments));
|
.AppendLine(Markdown.Bold(Messages.UserInfoPunishments));
|
||||||
|
|
||||||
|
embedColor = AppendPunishmentsInformation(wasMuted, wasKicked, wasBanned, memberData,
|
||||||
|
builder, embedColor, communicationDisabledUntil);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMuted)
|
if (!guildMemberResult.IsSuccess && !wasBanned)
|
||||||
{
|
|
||||||
AppendMuteInformation(memberData, communicationDisabledUntil, builder);
|
|
||||||
|
|
||||||
embedColor = ColorsList.Red;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (existingBanResult.IsDefined())
|
|
||||||
{
|
|
||||||
AppendBanInformation(memberData, builder);
|
|
||||||
|
|
||||||
embedColor = ColorsList.Black;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!guildMemberResult.IsSuccess && !existingBanResult.IsDefined())
|
|
||||||
{
|
{
|
||||||
builder.Append("### ")
|
builder.Append("### ")
|
||||||
.AppendLine(Markdown.Bold(Messages.UserInfoNotOnGuild));
|
.AppendLine(Markdown.Bold(Messages.UserInfoNotOnGuild));
|
||||||
|
@ -166,6 +155,29 @@ public class ToolsCommandGroup : CommandGroup
|
||||||
return await _feedback.SendContextualEmbedResultAsync(embed, ct: ct);
|
return await _feedback.SendContextualEmbedResultAsync(embed, ct: ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Color AppendPunishmentsInformation(bool wasMuted, bool wasKicked, bool wasBanned,
|
||||||
|
MemberData memberData, StringBuilder builder, Color embedColor, DateTimeOffset? communicationDisabledUntil)
|
||||||
|
{
|
||||||
|
if (wasMuted)
|
||||||
|
{
|
||||||
|
AppendMuteInformation(memberData, communicationDisabledUntil, builder);
|
||||||
|
embedColor = ColorsList.Red;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wasKicked)
|
||||||
|
{
|
||||||
|
builder.AppendBulletPointLine(Messages.UserInfoKicked);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wasBanned)
|
||||||
|
{
|
||||||
|
AppendBanInformation(memberData, builder);
|
||||||
|
embedColor = ColorsList.Black;
|
||||||
|
}
|
||||||
|
|
||||||
|
return embedColor;
|
||||||
|
}
|
||||||
|
|
||||||
private static Color AppendGuildInformation(Color color, IGuildMember guildMember, StringBuilder builder)
|
private static Color AppendGuildInformation(Color color, IGuildMember guildMember, StringBuilder builder)
|
||||||
{
|
{
|
||||||
if (guildMember.Nickname.IsDefined(out var nickname))
|
if (guildMember.Nickname.IsDefined(out var nickname))
|
||||||
|
|
|
@ -18,6 +18,7 @@ public sealed class MemberData
|
||||||
public ulong Id { get; }
|
public ulong Id { get; }
|
||||||
public DateTimeOffset? BannedUntil { get; set; }
|
public DateTimeOffset? BannedUntil { get; set; }
|
||||||
public DateTimeOffset? MutedUntil { get; set; }
|
public DateTimeOffset? MutedUntil { get; set; }
|
||||||
|
public bool Kicked { get; set; }
|
||||||
public List<ulong> Roles { get; set; } = [];
|
public List<ulong> Roles { get; set; } = [];
|
||||||
public List<Reminder> Reminders { get; } = [];
|
public List<Reminder> Reminders { get; } = [];
|
||||||
}
|
}
|
||||||
|
|
8
src/Messages.Designer.cs
generated
8
src/Messages.Designer.cs
generated
|
@ -1036,5 +1036,13 @@ namespace Octobot {
|
||||||
return ResourceManager.GetString("ButtonReportIssue", resourceCulture);
|
return ResourceManager.GetString("ButtonReportIssue", resourceCulture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static string UserInfoKicked
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return ResourceManager.GetString("UserInfoKicked", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,8 @@ public class GuildMemberJoinedResponder : IResponder<IGuildMemberAdd>
|
||||||
var cfg = data.Settings;
|
var cfg = data.Settings;
|
||||||
var memberData = data.GetOrCreateMemberData(user.ID);
|
var memberData = data.GetOrCreateMemberData(user.ID);
|
||||||
|
|
||||||
|
memberData.Kicked = false;
|
||||||
|
|
||||||
var returnRolesResult = await TryReturnRolesAsync(cfg, memberData, gatewayEvent.GuildID, user.ID, ct);
|
var returnRolesResult = await TryReturnRolesAsync(cfg, memberData, gatewayEvent.GuildID, user.ID, ct);
|
||||||
if (!returnRolesResult.IsSuccess)
|
if (!returnRolesResult.IsSuccess)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue