Added .showembed <msgid> and .showembed #channel <msgid> which will show you embed json from the specified message

This commit is contained in:
Kwoth
2021-12-13 20:29:45 +01:00
parent 96c9b699aa
commit 9be8140d4d
5 changed files with 88 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
- `.remindl` and `.remindrm` commands now supports optional 'server' parameter for Administrators which allows them to delete any reminder created on the server
- Added slots.currencyFontColor to gambling.yml
- Added `.qexport` and `.qimport` commands which allow you to export and import quotes just like `.crsexport`
- Added `.showembed <msgid>` and `.showembed #channel <msgid>` which will show you embed json from the specified message
### Changed
- `.at` and `.atl` commands reworked

View File

@@ -1,4 +1,5 @@
using System;
using System.Linq;
using Discord;
using NadekoBot.Extensions;
using NadekoBot.Services;
@@ -29,6 +30,47 @@ namespace NadekoBot
(Footer != null && (!string.IsNullOrWhiteSpace(Footer.Text) || !string.IsNullOrWhiteSpace(Footer.IconUrl))) ||
(Fields != null && Fields.Length > 0);
public static SmartEmbedText FromEmbed(IEmbed eb, string plainText = null)
{
var set = new SmartEmbedText();
set.PlainText = plainText;
set.Title = eb.Title;
set.Description = eb.Description;
set.Url = eb.Url;
set.Thumbnail = eb.Thumbnail?.Url;
set.Image = eb.Image?.Url;
set.Author = eb.Author is EmbedAuthor ea
? new()
{
Name = ea.Name,
Url = ea.Url,
IconUrl = ea.IconUrl
}
: null;
set.Footer = eb.Footer is EmbedFooter ef
? new()
{
Text = ef.Text,
IconUrl = ef.IconUrl
}
: null;
if (eb.Fields.Length > 0)
set.Fields = eb
.Fields
.Select(field => new SmartTextEmbedField()
{
Inline = field.Inline,
Name = field.Name,
Value = field.Value,
})
.ToArray();
set.Color = eb.Color?.RawValue ?? 0;
return set;
}
public EmbedBuilder GetEmbed()
{
var embed = new EmbedBuilder()

View File

@@ -362,7 +362,41 @@ namespace NadekoBot.Modules.Utility
await ctx.Channel.EmbedAsync(embed);
}
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
public Task ShowEmbed(ulong messageId)
=> ShowEmbed((ITextChannel)ctx.Channel, messageId);
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
public async Task ShowEmbed(ITextChannel ch, ulong messageId)
{
var user = (IGuildUser)ctx.User;
var perms = user.GetPermissions(ch);
if (!perms.ReadMessageHistory || !perms.ViewChannel)
{
await ReplyErrorLocalizedAsync(strs.insuf_perms_u);
return;
}
var msg = await ch.GetMessageAsync(messageId);
if (msg is null)
{
await ReplyErrorLocalizedAsync(strs.msg_not_found);
return;
}
var embed = msg.Embeds.FirstOrDefault();
if (embed is null)
{
await ReplyErrorLocalizedAsync(strs.not_found);
return;
}
var json = SmartEmbedText.FromEmbed(embed, msg.Content).ToJson();
await SendConfirmAsync(Format.Sanitize(json).Replace("](", "]\\("));
}
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
@@ -433,6 +467,8 @@ namespace NadekoBot.Modules.Utility
New
}
// [NadekoCommand, Usage, Description, Aliases]
// [RequireContext(ContextType.Guild)]
// public async Task CreateMyInvite(CreateInviteType type = CreateInviteType.Any)

View File

@@ -1270,4 +1270,6 @@ quotesexport:
- qexport
quotesimport:
- quotesimport
- qimport
- qimport
showembed:
- showembed

View File

@@ -2152,4 +2152,9 @@ imageonlychannel:
coordreload:
desc: "Reloads coordinator config"
args:
- ""
- ""
showembed:
desc: "Prints the json equivalent of the embed of the message specified by its Id."
args:
- "820022733172121600"
- "#some-channel 820022733172121600"