mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
- .say replacement fix
- .send and .qid now use smarttext instead of crembed - added + operator for adding string to smarttext
This commit is contained in:
@@ -5,7 +5,7 @@ using NadekoBot.Services;
|
|||||||
|
|
||||||
namespace NadekoBot
|
namespace NadekoBot
|
||||||
{
|
{
|
||||||
public sealed class SmartEmbedText : SmartText
|
public sealed record SmartEmbedText : SmartText
|
||||||
{
|
{
|
||||||
public string PlainText { get; set; }
|
public string PlainText { get; set; }
|
||||||
public string Title { get; set; }
|
public string Title { get; set; }
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
namespace NadekoBot
|
namespace NadekoBot
|
||||||
{
|
{
|
||||||
public sealed class SmartPlainText : SmartText
|
public sealed record SmartPlainText : SmartText
|
||||||
{
|
{
|
||||||
public string Text { get; set; }
|
public string Text { get; init; }
|
||||||
|
|
||||||
public SmartPlainText(string text)
|
public SmartPlainText(string text)
|
||||||
{
|
{
|
||||||
|
@@ -1,14 +1,28 @@
|
|||||||
using Newtonsoft.Json;
|
using System;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace NadekoBot
|
namespace NadekoBot
|
||||||
{
|
{
|
||||||
public abstract class SmartText
|
public abstract record SmartText
|
||||||
{
|
{
|
||||||
public bool IsEmbed => this is SmartEmbedText;
|
public bool IsEmbed => this is SmartEmbedText;
|
||||||
public bool IsPlainText => this is SmartPlainText;
|
public bool IsPlainText => this is SmartPlainText;
|
||||||
|
|
||||||
public static implicit operator SmartText(string input)
|
public static SmartText operator +(SmartText text, string input)
|
||||||
=> new SmartPlainText(input);
|
=> text switch
|
||||||
|
{
|
||||||
|
SmartEmbedText set => set with { PlainText = set.PlainText + input },
|
||||||
|
SmartPlainText spt => new SmartPlainText(spt.Text + input),
|
||||||
|
_ => throw new ArgumentOutOfRangeException(nameof(text))
|
||||||
|
};
|
||||||
|
|
||||||
|
public static SmartText operator +(string input, SmartText text)
|
||||||
|
=> text switch
|
||||||
|
{
|
||||||
|
SmartEmbedText set => set with { PlainText = input + set.PlainText },
|
||||||
|
SmartPlainText spt => new SmartPlainText(input + spt.Text),
|
||||||
|
_ => throw new ArgumentOutOfRangeException(nameof(text))
|
||||||
|
};
|
||||||
|
|
||||||
public static SmartText CreateFrom(string input)
|
public static SmartText CreateFrom(string input)
|
||||||
{
|
{
|
||||||
|
@@ -22,14 +22,12 @@ namespace NadekoBot.Modules.Administration
|
|||||||
public class SelfCommands : NadekoSubmodule<SelfService>
|
public class SelfCommands : NadekoSubmodule<SelfService>
|
||||||
{
|
{
|
||||||
private readonly DiscordSocketClient _client;
|
private readonly DiscordSocketClient _client;
|
||||||
private readonly Bot _bot;
|
|
||||||
private readonly IBotStrings _strings;
|
private readonly IBotStrings _strings;
|
||||||
private readonly ICoordinator _coord;
|
private readonly ICoordinator _coord;
|
||||||
|
|
||||||
public SelfCommands(DiscordSocketClient client, Bot bot, IBotStrings strings, ICoordinator coord)
|
public SelfCommands(DiscordSocketClient client, IBotStrings strings, ICoordinator coord)
|
||||||
{
|
{
|
||||||
_client = client;
|
_client = client;
|
||||||
_bot = bot;
|
|
||||||
_strings = strings;
|
_strings = strings;
|
||||||
_coord = coord;
|
_coord = coord;
|
||||||
}
|
}
|
||||||
@@ -447,14 +445,12 @@ namespace NadekoBot.Modules.Administration
|
|||||||
|
|
||||||
[NadekoCommand, Aliases]
|
[NadekoCommand, Aliases]
|
||||||
[OwnerOnly]
|
[OwnerOnly]
|
||||||
public async Task Send(string where, [Leftover] string msg = null)
|
public async Task Send(string where, [Leftover] SmartText text = null)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(msg))
|
|
||||||
return;
|
|
||||||
|
|
||||||
var ids = where.Split('|');
|
var ids = where.Split('|');
|
||||||
if (ids.Length != 2)
|
if (ids.Length != 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var sid = ulong.Parse(ids[0]);
|
var sid = ulong.Parse(ids[0]);
|
||||||
var server = _client.Guilds.FirstOrDefault(s => s.Id == sid);
|
var server = _client.Guilds.FirstOrDefault(s => s.Id == sid);
|
||||||
|
|
||||||
@@ -470,45 +466,28 @@ namespace NadekoBot.Modules.Administration
|
|||||||
var cid = ulong.Parse(ids[1].Substring(2));
|
var cid = ulong.Parse(ids[1].Substring(2));
|
||||||
var ch = server.TextChannels.FirstOrDefault(c => c.Id == cid);
|
var ch = server.TextChannels.FirstOrDefault(c => c.Id == cid);
|
||||||
if (ch is null)
|
if (ch is null)
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (CREmbed.TryParse(msg, out var crembed))
|
text = rep.Replace(text);
|
||||||
{
|
await ch.SendAsync(_eb, text, sanitizeAll: false);
|
||||||
rep.Replace(crembed);
|
|
||||||
await ch.EmbedAsync(crembed, _eb).ConfigureAwait(false);
|
|
||||||
await ReplyConfirmLocalizedAsync("message_sent").ConfigureAwait(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await ch.SendMessageAsync(rep.Replace(msg).SanitizeMentions()).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
else if (ids[1].ToUpperInvariant().StartsWith("U:", StringComparison.InvariantCulture))
|
else if (ids[1].ToUpperInvariant().StartsWith("U:", StringComparison.InvariantCulture))
|
||||||
{
|
{
|
||||||
var uid = ulong.Parse(ids[1].Substring(2));
|
var uid = ulong.Parse(ids[1].Substring(2));
|
||||||
var user = server.Users.FirstOrDefault(u => u.Id == uid);
|
var user = server.Users.FirstOrDefault(u => u.Id == uid);
|
||||||
if (user is null)
|
if (user is null)
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (CREmbed.TryParse(msg, out var crembed))
|
var ch = await user.GetOrCreateDMChannelAsync();
|
||||||
{
|
text = rep.Replace(text);
|
||||||
rep.Replace(crembed);
|
await ch.SendAsync(_eb, text);
|
||||||
await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false))
|
|
||||||
.EmbedAsync(crembed, _eb)
|
|
||||||
.ConfigureAwait(false);
|
|
||||||
await ReplyConfirmLocalizedAsync("message_sent").ConfigureAwait(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendMessageAsync(rep.Replace(msg).SanitizeMentions()).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await ReplyErrorLocalizedAsync("invalid_format").ConfigureAwait(false);
|
await ReplyErrorLocalizedAsync("invalid_format").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await ReplyConfirmLocalizedAsync("message_sent").ConfigureAwait(false);
|
await ReplyConfirmLocalizedAsync("message_sent").ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -174,18 +174,10 @@ namespace NadekoBot.Modules.Utility
|
|||||||
|
|
||||||
var infoText = $"`#{quote.Id} added by {quote.AuthorName.SanitizeAllMentions()}` 🗯️ " + quote.Keyword.ToLowerInvariant().SanitizeAllMentions() + ":\n";
|
var infoText = $"`#{quote.Id} added by {quote.AuthorName.SanitizeAllMentions()}` 🗯️ " + quote.Keyword.ToLowerInvariant().SanitizeAllMentions() + ":\n";
|
||||||
|
|
||||||
if (CREmbed.TryParse(quote.Text, out var crembed))
|
|
||||||
{
|
|
||||||
rep.Replace(crembed);
|
|
||||||
|
|
||||||
await ctx.Channel.EmbedAsync(crembed.ToEmbed(_eb), infoText + crembed.PlainText?.SanitizeAllMentions())
|
var text = SmartText.CreateFrom(quote.Text);
|
||||||
.ConfigureAwait(false);
|
text = rep.Replace(text);
|
||||||
}
|
await ctx.Channel.SendAsync(_eb, infoText + text, true);
|
||||||
else
|
|
||||||
{
|
|
||||||
await ctx.Channel.SendMessageAsync(infoText + rep.Replace(quote.Text)?.SanitizeAllMentions())
|
|
||||||
.ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Aliases]
|
[NadekoCommand, Aliases]
|
||||||
|
@@ -36,7 +36,6 @@ namespace NadekoBot.Modules.Utility
|
|||||||
_tracker = tracker;
|
_tracker = tracker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[NadekoCommand, Aliases]
|
[NadekoCommand, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[UserPerm(GuildPerm.ManageMessages)]
|
[UserPerm(GuildPerm.ManageMessages)]
|
||||||
@@ -47,7 +46,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
.WithDefault(ctx.User, channel, (SocketGuild)ctx.Guild, (DiscordSocketClient)ctx.Client)
|
.WithDefault(ctx.User, channel, (SocketGuild)ctx.Guild, (DiscordSocketClient)ctx.Client)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
rep.Replace(message);
|
message = rep.Replace(message);
|
||||||
|
|
||||||
await channel.SendAsync(_eb, message, !((IGuildUser)Context.User).GuildPermissions.MentionEveryone);
|
await channel.SendAsync(_eb, message, !((IGuildUser)Context.User).GuildPermissions.MentionEveryone);
|
||||||
}
|
}
|
||||||
@@ -56,7 +55,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
[UserPerm(GuildPerm.ManageMessages)]
|
[UserPerm(GuildPerm.ManageMessages)]
|
||||||
[Priority(0)]
|
[Priority(0)]
|
||||||
public Task Say([Leftover] string message)
|
public Task Say([Leftover] SmartText message)
|
||||||
=> Say((ITextChannel)ctx.Channel, message);
|
=> Say((ITextChannel)ctx.Channel, message);
|
||||||
|
|
||||||
[NadekoCommand, Aliases]
|
[NadekoCommand, Aliases]
|
||||||
|
Reference in New Issue
Block a user