Added .roleinfo commands, added the ability to show colors other than ok error and pending to IEmbedBuilder

This commit is contained in:
Kwoth
2022-08-11 17:04:51 +02:00
parent dc229ea2b3
commit b164da38e3
6 changed files with 42 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ public interface IEmbedBuilder
IEmbedBuilder WithFooter(string text, string? iconUrl = null); IEmbedBuilder WithFooter(string text, string? iconUrl = null);
IEmbedBuilder WithAuthor(string name, string? iconUrl = null, string? url = null); IEmbedBuilder WithAuthor(string name, string? iconUrl = null, string? url = null);
IEmbedBuilder WithColor(EmbedColor color); IEmbedBuilder WithColor(EmbedColor color);
IEmbedBuilder WithDiscordColor(Color color);
Embed Build(); Embed Build();
IEmbedBuilder WithUrl(string url); IEmbedBuilder WithUrl(string url);
IEmbedBuilder WithImageUrl(string url); IEmbedBuilder WithImageUrl(string url);

View File

@@ -97,6 +97,33 @@ public partial class Utility
.WithOkColor(); .WithOkColor();
await ctx.Channel.EmbedAsync(embed); await ctx.Channel.EmbedAsync(embed);
} }
[Cmd]
[RequireUserPermission(GuildPermission.ManageRoles)]
public async Task RoleInfo([Leftover] SocketRole role)
{
if (role.IsEveryone)
return;
var createdAt = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)
.AddMilliseconds(role.Id >> 22);
var usercount = role.Members.LongCount();
var embed = _eb.Create()
.WithTitle(role.Name.TrimTo(128))
.WithDescription(role.Permissions.ToList().Join(" | "))
.AddField(GetText(strs.id), role.Id.ToString(), true)
.AddField(GetText(strs.created_at), $"{createdAt:dd.MM.yyyy HH:mm}", true)
.AddField(GetText(strs.users), usercount.ToString(), true)
.AddField(GetText(strs.color), $"#{role.Color.R:X2}{role.Color.G:X2}{role.Color.B:X2}", true)
.AddField(GetText(strs.mentionable), role.IsMentionable.ToString(), true)
.AddField(GetText(strs.hoisted), role.IsHoisted.ToString(), true)
.WithOkColor();
if (!string.IsNullOrWhiteSpace(role.GetIconUrl()))
embed = embed.WithThumbnailUrl(role.GetIconUrl());
await ctx.Channel.EmbedAsync(embed);
}
[Cmd] [Cmd]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]

View File

@@ -67,6 +67,9 @@ public sealed class DiscordEmbedBuilderWrapper : IEmbedBuilder
_ => throw new ArgumentOutOfRangeException(nameof(color), "Unsupported EmbedColor type") _ => throw new ArgumentOutOfRangeException(nameof(color), "Unsupported EmbedColor type")
}; };
public IEmbedBuilder WithDiscordColor(Color color)
=> Wrap(embed.WithColor(color));
public Embed Build() public Embed Build()
=> embed.Build(); => embed.Build();

View File

@@ -217,6 +217,9 @@ serverinfo:
channelinfo: channelinfo:
- channelinfo - channelinfo
- cinfo - cinfo
roleinfo:
- roleinfo
- rinfo
userinfo: userinfo:
- userinfo - userinfo
- uinfo - uinfo

View File

@@ -423,6 +423,10 @@ channelinfo:
desc: "Shows info about the channel. If no channel is supplied, it defaults to current one." desc: "Shows info about the channel. If no channel is supplied, it defaults to current one."
args: args:
- "#some-channel" - "#some-channel"
roleinfo:
desc: "Shows info about the specified role."
args:
- "Gamers"
userinfo: userinfo:
desc: "Shows info about the user. If no user is supplied, it defaults a user running the command." desc: "Shows info about the user. If no user is supplied, it defaults a user running the command."
args: args:

View File

@@ -142,6 +142,10 @@
"rar_err": "Failed to remove roles. I have insufficient permissions.", "rar_err": "Failed to remove roles. I have insufficient permissions.",
"rc": "Color of {0} role has been changed.", "rc": "Color of {0} role has been changed.",
"rc_perms": "Error occurred due to invalid color or insufficient permissions.", "rc_perms": "Error occurred due to invalid color or insufficient permissions.",
"color": "Color",
"icon": "Icon",
"hoisted": "Hoisted",
"mentionable": "Mentionable",
"remrole": "Successfully removed role {0} from user {1}", "remrole": "Successfully removed role {0} from user {1}",
"remrole_err": "Failed to remove role. I have insufficient permissions.", "remrole_err": "Failed to remove role. I have insufficient permissions.",
"renrole": "Role renamed.", "renrole": "Role renamed.",