Skip to content

Commit

Permalink
Add /baninfo and /muteinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
FloatingMilkshake committed Jul 1, 2024
1 parent 5ac634d commit a624497
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Commands/InteractionCommands/DebugInteractions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,27 @@ public async Task UserInfoSlashCommand(InteractionContext ctx, [Option("user", "
{
await ctx.RespondAsync(embed: await DiscordHelpers.GenerateUserEmbed(user, ctx.Guild), ephemeral: !publicMessage);
}

[SlashCommand("muteinfo", "Show information about the mute for a user.")]
[SlashRequireHomeserverPerm(ServerPermLevel.TrialModerator)]
[SlashCommandPermissions(DiscordPermissions.ModerateMembers)]
public async Task MuteInfoSlashCommand(
InteractionContext ctx,
[Option("user", "The user whose mute information to show.")] DiscordUser targetUser,
[Option("public", "Whether to show the output publicly. Default: false")] bool isPublic = false)
{
await ctx.RespondAsync(embed: await MuteHelpers.MuteStatusEmbed(targetUser, ctx.Guild), ephemeral: !isPublic);
}

[SlashCommand("baninfo", "Show information about the ban for a user.")]
[SlashRequireHomeserverPerm(ServerPermLevel.TrialModerator)]
[SlashCommandPermissions(DiscordPermissions.ModerateMembers)]
public async Task BanInfoSlashCommand(
InteractionContext ctx,
[Option("user", "The user whose ban information to show.")] DiscordUser targetUser,
[Option("public", "Whether to show the output publicly. Default: false")] bool isPublic = false)
{
await ctx.RespondAsync(embed: await BanHelpers.BanStatusEmbed(targetUser, ctx.Guild), ephemeral: !isPublic);
}
}
}
52 changes: 52 additions & 0 deletions Helpers/BanHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,57 @@ public static async Task<bool> BanSilently(DiscordGuild targetGuild, ulong targe

}

public static async Task<DiscordEmbed> BanStatusEmbed(DiscordUser user, DiscordGuild guild)
{
DiscordMember member = default;
DiscordEmbedBuilder embedBuilder = new();
var guildBans = await guild.GetBansAsync();
var userBan = guildBans.FirstOrDefault(x => x.User.Id == user.Id);

embedBuilder.WithFooter(
$"User ID: {user.Id}",
null
)
.WithAuthor(
$"Ban status for {DiscordHelpers.UniqueUsername(user)}",
null,
await LykosAvatarMethods.UserOrMemberAvatarURL(user, Program.homeGuild, "png")
);

if (await Program.db.HashExistsAsync("bans", user.Id))
{
MemberPunishment ban = JsonConvert.DeserializeObject<MemberPunishment>(Program.db.HashGet("bans", user.Id));

embedBuilder.WithDescription("User is banned.")
.AddField("Banned", ban.ActionTime is null ? "Unknown time (Ban is too old)" : $"<t:{TimeHelpers.ToUnixTimestamp(ban.ActionTime)}:R>", true)
.WithColor(new DiscordColor(0xFEC13D));

if (ban.ExpireTime is null)
embedBuilder.AddField("Ban expires", "Never", true);
else
embedBuilder.AddField("Ban expires", $"<t:{TimeHelpers.ToUnixTimestamp(ban.ExpireTime)}:R>", true);

embedBuilder.AddField("Banned by", $"<@{ban.ModId}>", true);

embedBuilder.AddField("Reason", ban.Reason is null ? "No reason provided" : ban.Reason, false);
}
else
{
if (userBan is null)
{
embedBuilder.WithDescription("User is not banned.")
.WithColor(color: DiscordColor.DarkGreen);
}
else
{
embedBuilder.WithDescription($"User was banned without using {Program.discord.CurrentUser.Username}, so limited information is available.")
.WithColor(new DiscordColor(0xFEC13D));
embedBuilder.AddField("Reason", string.IsNullOrWhiteSpace(userBan.Reason) ? "No reason provided" : userBan.Reason, false);
}
}

return embedBuilder.Build();
}

}
}

0 comments on commit a624497

Please sign in to comment.