mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
Part2 of the response system rework
This commit is contained in:
@@ -26,7 +26,7 @@ public partial class Utility
|
||||
public async Task AliasesClear()
|
||||
{
|
||||
var count = _service.ClearAliases(ctx.Guild.Id);
|
||||
await ReplyConfirmLocalizedAsync(strs.aliases_cleared(count));
|
||||
await Response().Confirm(strs.aliases_cleared(count)).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -43,7 +43,7 @@ public partial class Utility
|
||||
{
|
||||
if (!_service.AliasMaps.TryGetValue(ctx.Guild.Id, out var maps) || !maps.TryRemove(trigger, out _))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.alias_remove_fail(Format.Code(trigger)));
|
||||
await Response().Error(strs.alias_remove_fail(Format.Code(trigger))).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public partial class Utility
|
||||
uow.SaveChanges();
|
||||
}
|
||||
|
||||
await ReplyConfirmLocalizedAsync(strs.alias_removed(Format.Code(trigger)));
|
||||
await Response().Confirm(strs.alias_removed(Format.Code(trigger))).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ public partial class Utility
|
||||
return map;
|
||||
});
|
||||
|
||||
await ReplyConfirmLocalizedAsync(strs.alias_added(Format.Code(trigger), Format.Code(mapping)));
|
||||
await Response().Confirm(strs.alias_added(Format.Code(trigger), Format.Code(mapping))).SendAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ public partial class Utility
|
||||
|
||||
if (!_service.AliasMaps.TryGetValue(ctx.Guild.Id, out var maps) || !maps.Any())
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.aliases_none);
|
||||
await Response().Error(strs.aliases_none).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public partial class Utility
|
||||
await ctx.SendPaginatedConfirmAsync(page,
|
||||
curPage =>
|
||||
{
|
||||
return _eb.Create()
|
||||
return new EmbedBuilder()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.alias_list))
|
||||
.WithDescription(string.Join("\n",
|
||||
|
@@ -9,13 +9,16 @@ namespace NadekoBot.Modules.Utility.Services;
|
||||
public class AliasService : IInputTransformer, INService
|
||||
{
|
||||
public ConcurrentDictionary<ulong, ConcurrentDictionary<string, string>> AliasMaps { get; } = new();
|
||||
private readonly IEmbedBuilderService _eb;
|
||||
|
||||
private readonly DbService _db;
|
||||
private readonly IMessageSenderService _sender;
|
||||
|
||||
public AliasService(DiscordSocketClient client, DbService db, IEmbedBuilderService eb)
|
||||
public AliasService(
|
||||
DiscordSocketClient client,
|
||||
DbService db,
|
||||
IMessageSenderService sender)
|
||||
{
|
||||
_eb = eb;
|
||||
_sender = sender;
|
||||
|
||||
using var uow = db.GetDbContext();
|
||||
var guildIds = client.Guilds.Select(x => x.Id).ToList();
|
||||
@@ -53,7 +56,7 @@ public class AliasService : IInputTransformer, INService
|
||||
{
|
||||
if (guild is null || string.IsNullOrWhiteSpace(input))
|
||||
return null;
|
||||
|
||||
|
||||
if (AliasMaps.TryGetValue(guild.Id, out var maps))
|
||||
{
|
||||
string newInput = null;
|
||||
@@ -75,7 +78,9 @@ public class AliasService : IInputTransformer, INService
|
||||
{
|
||||
try
|
||||
{
|
||||
var toDelete = await channel.SendConfirmAsync(_eb, $"{input} => {newInput}");
|
||||
var toDelete = await _sender.Response(channel)
|
||||
.Confirm($"{input} => {newInput}")
|
||||
.SendAsync();
|
||||
toDelete.DeleteAfter(1.5f);
|
||||
}
|
||||
catch
|
||||
|
@@ -16,9 +16,9 @@ public partial class Utility
|
||||
expr.EvaluateParameter += Expr_EvaluateParameter;
|
||||
var result = expr.Evaluate();
|
||||
if (!expr.HasErrors())
|
||||
await SendConfirmAsync("⚙ " + GetText(strs.result), result.ToString());
|
||||
await Response().Confirm("⚙ " + GetText(strs.result), result.ToString()).SendAsync();
|
||||
else
|
||||
await SendErrorAsync("⚙ " + GetText(strs.error), expr.Error);
|
||||
await Response().Error("⚙ " + GetText(strs.error), expr.Error).SendAsync();
|
||||
}
|
||||
|
||||
private static void Expr_EvaluateParameter(string name, ParameterArgs args)
|
||||
@@ -42,7 +42,7 @@ public partial class Utility
|
||||
.DistinctBy(x => x.Name)
|
||||
.Select(x => x.Name)
|
||||
.Except(new[] { "ToString", "Equals", "GetHashCode", "GetType" });
|
||||
await SendConfirmAsync(GetText(strs.calcops(prefix)), string.Join(", ", selection));
|
||||
await Response().Confirm(GetText(strs.calcops(prefix)), string.Join(", ", selection)).SendAsync();
|
||||
}
|
||||
}
|
||||
}
|
@@ -20,12 +20,12 @@ public partial class Utility
|
||||
if (setting is null)
|
||||
{
|
||||
var configNames = _settingServices.Select(x => x.Name);
|
||||
var embed = _eb.Create()
|
||||
var embed = new EmbedBuilder()
|
||||
.WithErrorColor()
|
||||
.WithDescription(GetText(strs.config_not_found(Format.Code(name))))
|
||||
.AddField(GetText(strs.config_list), string.Join("\n", configNames));
|
||||
|
||||
await EmbedAsync(embed);
|
||||
await Response().Embed(embed).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -43,12 +43,12 @@ public partial class Utility
|
||||
name = name?.ToLowerInvariant();
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
var embed = _eb.Create()
|
||||
var embed = new EmbedBuilder()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.config_list))
|
||||
.WithDescription(string.Join("\n", configNames));
|
||||
|
||||
await EmbedAsync(embed);
|
||||
await Response().Embed(embed).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -58,12 +58,12 @@ public partial class Utility
|
||||
// if config name is not found, print error and the list of configs
|
||||
if (setting is null)
|
||||
{
|
||||
var embed = _eb.Create()
|
||||
var embed = new EmbedBuilder()
|
||||
.WithErrorColor()
|
||||
.WithDescription(GetText(strs.config_not_found(Format.Code(name))))
|
||||
.AddField(GetText(strs.config_list), string.Join("\n", configNames));
|
||||
|
||||
await EmbedAsync(embed);
|
||||
await Response().Embed(embed).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -75,10 +75,10 @@ public partial class Utility
|
||||
if (string.IsNullOrWhiteSpace(prop))
|
||||
{
|
||||
var propStrings = GetPropsAndValuesString(setting, propNames);
|
||||
var embed = _eb.Create().WithOkColor().WithTitle($"⚙️ {setting.Name}").WithDescription(propStrings);
|
||||
var embed = new EmbedBuilder().WithOkColor().WithTitle($"⚙️ {setting.Name}").WithDescription(propStrings);
|
||||
|
||||
|
||||
await EmbedAsync(embed);
|
||||
await Response().Embed(embed).SendAsync();
|
||||
return;
|
||||
}
|
||||
// if the prop is invalid -> print error and list of
|
||||
@@ -88,13 +88,13 @@ public partial class Utility
|
||||
if (!exists)
|
||||
{
|
||||
var propStrings = GetPropsAndValuesString(setting, propNames);
|
||||
var propErrorEmbed = _eb.Create()
|
||||
var propErrorEmbed = new EmbedBuilder()
|
||||
.WithErrorColor()
|
||||
.WithDescription(GetText(
|
||||
strs.config_prop_not_found(Format.Code(prop), Format.Code(name))))
|
||||
.AddField($"⚙️ {setting.Name}", propStrings);
|
||||
|
||||
await EmbedAsync(propErrorEmbed);
|
||||
await Response().Embed(propErrorEmbed).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ public partial class Utility
|
||||
if (prop != "currency.sign")
|
||||
value = Format.Code(Format.Sanitize(value.TrimTo(1000)), "json");
|
||||
|
||||
var embed = _eb.Create()
|
||||
var embed = new EmbedBuilder()
|
||||
.WithOkColor()
|
||||
.AddField("Config", Format.Code(setting.Name), true)
|
||||
.AddField("Prop", Format.Code(prop), true)
|
||||
@@ -120,7 +120,7 @@ public partial class Utility
|
||||
if (!string.IsNullOrWhiteSpace(comment))
|
||||
embed.AddField("Comment", comment);
|
||||
|
||||
await EmbedAsync(embed);
|
||||
await Response().Embed(embed).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ public partial class Utility
|
||||
|
||||
if (!success)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.config_edit_fail(Format.Code(prop), Format.Code(value)));
|
||||
await Response().Error(strs.config_edit_fail(Format.Code(prop), Format.Code(value))).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -13,16 +13,16 @@ public partial class Utility
|
||||
{
|
||||
if (duration > TimeSpan.FromDays(30))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.giveaway_duration_invalid);
|
||||
await Response().Error(strs.giveaway_duration_invalid).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var eb = _eb.Create(ctx)
|
||||
var eb = new EmbedBuilder()
|
||||
.WithPendingColor()
|
||||
.WithTitle(GetText(strs.giveaway_starting))
|
||||
.WithDescription(message);
|
||||
|
||||
var startingMsg = await EmbedAsync(eb);
|
||||
var startingMsg = await Response().Embed(eb).SendAsync();
|
||||
|
||||
var maybeId =
|
||||
await _service.StartGiveawayAsync(ctx.Guild.Id, ctx.Channel.Id, startingMsg.Id, duration, message);
|
||||
@@ -31,7 +31,7 @@ public partial class Utility
|
||||
if (maybeId is not int id)
|
||||
{
|
||||
await startingMsg.DeleteAsync();
|
||||
await ReplyErrorLocalizedAsync(strs.giveaway_max_amount_reached);
|
||||
await Response().Error(strs.giveaway_max_amount_reached).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public partial class Utility
|
||||
|
||||
if(!success)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.giveaway_not_found);
|
||||
await Response().Error(strs.giveaway_not_found).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public partial class Utility
|
||||
var success = await _service.RerollGiveawayAsync(ctx.Guild.Id, id);
|
||||
if (!success)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.giveaway_not_found);
|
||||
await Response().Error(strs.giveaway_not_found).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -84,11 +84,11 @@ public partial class Utility
|
||||
|
||||
if (!success)
|
||||
{
|
||||
await ReplyConfirmLocalizedAsync(strs.giveaway_not_found);
|
||||
await Response().Confirm(strs.giveaway_not_found).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
await ReplyConfirmLocalizedAsync(strs.giveaway_cancelled);
|
||||
await Response().Confirm(strs.giveaway_cancelled).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -99,11 +99,11 @@ public partial class Utility
|
||||
|
||||
if (!giveaways.Any())
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.no_givaways);
|
||||
await Response().Error(strs.no_givaways).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var eb = _eb.Create(ctx)
|
||||
var eb = new EmbedBuilder()
|
||||
.WithTitle(GetText(strs.giveaway_list))
|
||||
.WithOkColor();
|
||||
|
||||
@@ -112,7 +112,7 @@ public partial class Utility
|
||||
eb.AddField($"id: {new kwum(g.Id)}", g.Message, true);
|
||||
}
|
||||
|
||||
await EmbedAsync(eb);
|
||||
await Response().Embed(eb).SendAsync();
|
||||
}
|
||||
}
|
||||
}
|
@@ -54,7 +54,7 @@ public partial class Utility
|
||||
if (string.IsNullOrWhiteSpace(features))
|
||||
features = "-";
|
||||
|
||||
var embed = _eb.Create()
|
||||
var embed = new EmbedBuilder()
|
||||
.WithAuthor(GetText(strs.server_info))
|
||||
.WithTitle(guild.Name)
|
||||
.AddField(GetText(strs.id), guild.Id.ToString(), true)
|
||||
@@ -75,7 +75,7 @@ public partial class Utility
|
||||
string.Join(" ", guild.Emotes.Shuffle().Take(20).Select(e => $"{e.Name} {e}")).TrimTo(1020));
|
||||
}
|
||||
|
||||
await EmbedAsync(embed);
|
||||
await Response().Embed(embed).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -87,14 +87,14 @@ public partial class Utility
|
||||
return;
|
||||
var createdAt = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(ch.Id >> 22);
|
||||
var usercount = (await ch.GetUsersAsync().FlattenAsync()).Count();
|
||||
var embed = _eb.Create()
|
||||
var embed = new EmbedBuilder()
|
||||
.WithTitle(ch.Name)
|
||||
.WithDescription(ch.Topic?.SanitizeMentions(true))
|
||||
.AddField(GetText(strs.id), ch.Id.ToString(), true)
|
||||
.AddField(GetText(strs.created_at), $"{createdAt:dd.MM.yyyy HH:mm}", true)
|
||||
.AddField(GetText(strs.users), usercount.ToString(), true)
|
||||
.WithOkColor();
|
||||
await EmbedAsync(embed);
|
||||
await Response().Embed(embed).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -107,7 +107,7 @@ public partial class Utility
|
||||
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()
|
||||
var embed = new EmbedBuilder()
|
||||
.WithTitle(role.Name.TrimTo(128))
|
||||
.WithDescription(role.Permissions.ToList().Join(" | "))
|
||||
.AddField(GetText(strs.id), role.Id.ToString(), true)
|
||||
@@ -121,7 +121,7 @@ public partial class Utility
|
||||
if (!string.IsNullOrWhiteSpace(role.GetIconUrl()))
|
||||
embed = embed.WithThumbnailUrl(role.GetIconUrl());
|
||||
|
||||
await EmbedAsync(embed);
|
||||
await Response().Embed(embed).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -133,7 +133,7 @@ public partial class Utility
|
||||
if (user is null)
|
||||
return;
|
||||
|
||||
var embed = _eb.Create().AddField(GetText(strs.name), $"**{user.Username}**#{user.Discriminator}", true);
|
||||
var embed = new EmbedBuilder().AddField(GetText(strs.name), $"**{user.Username}**#{user.Discriminator}", true);
|
||||
if (!string.IsNullOrWhiteSpace(user.Nickname))
|
||||
embed.AddField(GetText(strs.nickname), user.Nickname, true);
|
||||
|
||||
@@ -165,7 +165,7 @@ public partial class Utility
|
||||
if (av.IsAbsoluteUri)
|
||||
embed.WithThumbnailUrl(av.ToString());
|
||||
|
||||
await EmbedAsync(embed);
|
||||
await Response().Embed(embed).SendAsync();
|
||||
}
|
||||
|
||||
private DateTimeOffset? GetJoinedAt(IGuildUser user)
|
||||
@@ -204,12 +204,12 @@ public partial class Utility
|
||||
kvp.Value)));
|
||||
}
|
||||
|
||||
await EmbedAsync(_eb.Create()
|
||||
await Response().Embed(new EmbedBuilder()
|
||||
.WithTitle(GetText(strs.activity_page(page + 1)))
|
||||
.WithOkColor()
|
||||
.WithFooter(GetText(
|
||||
strs.activity_users_total(_cmdHandler.UserMessagesSent.Count)))
|
||||
.WithDescription(str.ToString()));
|
||||
.WithDescription(str.ToString())).SendAsync();
|
||||
}
|
||||
}
|
||||
}
|
@@ -22,7 +22,7 @@ public partial class Utility
|
||||
var ch = (ITextChannel)ctx.Channel;
|
||||
var invite = await ch.CreateInviteAsync(opts.Expire, opts.MaxUses, opts.Temporary, opts.Unique);
|
||||
|
||||
await SendConfirmAsync($"{ctx.User.Mention} https://discord.gg/{invite.Code}");
|
||||
await Response().Confirm($"{ctx.User.Mention} https://discord.gg/{invite.Code}").SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -44,9 +44,9 @@ public partial class Utility
|
||||
var invs = invites.Skip(cur * 9).Take(9).ToList();
|
||||
|
||||
if (!invs.Any())
|
||||
return _eb.Create().WithErrorColor().WithDescription(GetText(strs.no_invites));
|
||||
return new EmbedBuilder().WithErrorColor().WithDescription(GetText(strs.no_invites));
|
||||
|
||||
var embed = _eb.Create().WithOkColor();
|
||||
var embed = new EmbedBuilder().WithOkColor();
|
||||
foreach (var inv in invites)
|
||||
{
|
||||
var expiryString = inv.MaxAge is null or 0 || inv.CreatedAt is null
|
||||
|
@@ -14,24 +14,24 @@ public partial class Utility
|
||||
{
|
||||
private const string PREPEND_EXPORT =
|
||||
"""
|
||||
# Keys are keywords, Each key has a LIST of quotes in the following format:
|
||||
# - id: Alphanumeric id used for commands related to the quote. (Note, when using .quotesimport, a new id will be generated.)
|
||||
# an: Author name
|
||||
# aid: Author id
|
||||
# txt: Quote text
|
||||
# Keys are keywords, Each key has a LIST of quotes in the following format:
|
||||
# - id: Alphanumeric id used for commands related to the quote. (Note, when using .quotesimport, a new id will be generated.)
|
||||
# an: Author name
|
||||
# aid: Author id
|
||||
# txt: Quote text
|
||||
|
||||
""";
|
||||
""";
|
||||
|
||||
private static readonly ISerializer _exportSerializer = new SerializerBuilder()
|
||||
.WithEventEmitter(args
|
||||
=> new MultilineScalarFlowStyleEmitter(args))
|
||||
.WithNamingConvention(
|
||||
CamelCaseNamingConvention.Instance)
|
||||
.WithIndentedSequences()
|
||||
.ConfigureDefaultValuesHandling(DefaultValuesHandling
|
||||
.OmitDefaults)
|
||||
.DisableAliases()
|
||||
.Build();
|
||||
.WithEventEmitter(args
|
||||
=> new MultilineScalarFlowStyleEmitter(args))
|
||||
.WithNamingConvention(
|
||||
CamelCaseNamingConvention.Instance)
|
||||
.WithIndentedSequences()
|
||||
.ConfigureDefaultValuesHandling(DefaultValuesHandling
|
||||
.OmitDefaults)
|
||||
.DisableAliases()
|
||||
.Build();
|
||||
|
||||
private readonly DbService _db;
|
||||
private readonly IHttpClientFactory _http;
|
||||
@@ -67,13 +67,15 @@ public partial class Utility
|
||||
|
||||
if (quotes.Any())
|
||||
{
|
||||
await SendConfirmAsync(GetText(strs.quotes_page(page + 1)),
|
||||
string.Join("\n",
|
||||
quotes.Select(q
|
||||
=> $"`#{q.Id}` {Format.Bold(q.Keyword.SanitizeAllMentions()),-20} by {q.AuthorName.SanitizeAllMentions()}")));
|
||||
await Response()
|
||||
.Confirm(GetText(strs.quotes_page(page + 1)),
|
||||
string.Join("\n",
|
||||
quotes.Select(q
|
||||
=> $"`#{q.Id}` {Format.Bold(q.Keyword.SanitizeAllMentions()),-20} by {q.AuthorName.SanitizeAllMentions()}")))
|
||||
.SendAsync();
|
||||
}
|
||||
else
|
||||
await ReplyErrorLocalizedAsync(strs.quotes_page_none);
|
||||
await Response().Error(strs.quotes_page_none).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -121,7 +123,7 @@ public partial class Utility
|
||||
|
||||
if (quote is null)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.quotes_notfound);
|
||||
await Response().Error(strs.quotes_notfound).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -130,26 +132,26 @@ public partial class Utility
|
||||
|
||||
private async Task ShowQuoteData(Quote data)
|
||||
{
|
||||
var eb = _eb.Create(ctx)
|
||||
.WithOkColor()
|
||||
.WithTitle($"{GetText(strs.quote_id($"#{data.Id}"))} | {GetText(strs.response)}:")
|
||||
.WithDescription(Format.Sanitize(data.Text).Replace("](", "]\\(").TrimTo(4096))
|
||||
.AddField(GetText(strs.trigger), data.Keyword)
|
||||
.WithFooter(
|
||||
GetText(strs.created_by($"{data.AuthorName} ({data.AuthorId})")))
|
||||
.Build();
|
||||
var eb = new EmbedBuilder()
|
||||
.WithOkColor()
|
||||
.WithTitle($"{GetText(strs.quote_id($"#{data.Id}"))} | {GetText(strs.response)}:")
|
||||
.WithDescription(Format.Sanitize(data.Text).Replace("](", "]\\(").TrimTo(4096))
|
||||
.AddField(GetText(strs.trigger), data.Keyword)
|
||||
.WithFooter(
|
||||
GetText(strs.created_by($"{data.AuthorName} ({data.AuthorId})")))
|
||||
.Build();
|
||||
|
||||
if (!(data.Text.Length > 4096))
|
||||
{
|
||||
await ctx.Channel.SendMessageAsync(embed: eb);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
await ctx.Channel.SendFileAsync(
|
||||
attachment: new FileAttachment(await data.Text.ToStream(), "quote.txt"),
|
||||
embed: eb);
|
||||
}
|
||||
|
||||
|
||||
private async Task QuoteSearchinternalAsync(string? keyword, string textOrAuthor)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(textOrAuthor))
|
||||
@@ -177,7 +179,7 @@ public partial class Utility
|
||||
[Priority(0)]
|
||||
public Task QuoteSearch(string textOrAuthor)
|
||||
=> QuoteSearchinternalAsync(null, textOrAuthor);
|
||||
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[Priority(1)]
|
||||
@@ -202,7 +204,7 @@ public partial class Utility
|
||||
|
||||
if (quote is null || quote.GuildId != ctx.Guild.Id)
|
||||
{
|
||||
await SendErrorAsync(GetText(strs.quotes_notfound));
|
||||
await Response().Error(GetText(strs.quotes_notfound)).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -228,18 +230,19 @@ public partial class Utility
|
||||
Quote q;
|
||||
await using (var uow = _db.GetDbContext())
|
||||
{
|
||||
uow.Set<Quote>().Add(q = new()
|
||||
{
|
||||
AuthorId = ctx.Message.Author.Id,
|
||||
AuthorName = ctx.Message.Author.Username,
|
||||
GuildId = ctx.Guild.Id,
|
||||
Keyword = keyword,
|
||||
Text = text
|
||||
});
|
||||
uow.Set<Quote>()
|
||||
.Add(q = new()
|
||||
{
|
||||
AuthorId = ctx.Message.Author.Id,
|
||||
AuthorName = ctx.Message.Author.Username,
|
||||
GuildId = ctx.Guild.Id,
|
||||
Keyword = keyword,
|
||||
Text = text
|
||||
});
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
|
||||
await ReplyConfirmLocalizedAsync(strs.quote_added_new(Format.Code(q.Id.ToString())));
|
||||
await Response().Confirm(strs.quote_added_new(Format.Code(q.Id.ToString()))).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -266,16 +269,16 @@ public partial class Utility
|
||||
}
|
||||
|
||||
if (success)
|
||||
await SendConfirmAsync(response);
|
||||
await Response().Confirm(response).SendAsync();
|
||||
else
|
||||
await SendErrorAsync(response);
|
||||
await Response().Error(response).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public Task QuoteDeleteAuthor(IUser user)
|
||||
=> QuoteDeleteAuthor(user.Id);
|
||||
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task QuoteDeleteAuthor(ulong userId)
|
||||
@@ -285,11 +288,11 @@ public partial class Utility
|
||||
if (userId == ctx.User.Id || hasManageMessages)
|
||||
{
|
||||
var deleted = await _qs.DeleteAllAuthorQuotesAsync(ctx.Guild.Id, userId);
|
||||
await ReplyConfirmLocalizedAsync(strs.quotes_deleted_count(deleted));
|
||||
await Response().Confirm(strs.quotes_deleted_count(deleted)).SendAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.insuf_perms_u);
|
||||
await Response().Error(strs.insuf_perms_u).SendAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,7 +313,7 @@ public partial class Utility
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
|
||||
await ReplyConfirmLocalizedAsync(strs.quotes_deleted(Format.Bold(keyword.SanitizeAllMentions())));
|
||||
await Response().Confirm(strs.quotes_deleted(Format.Bold(keyword.SanitizeAllMentions()))).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -325,7 +328,7 @@ public partial class Utility
|
||||
}
|
||||
|
||||
var exprsDict = quotes.GroupBy(x => x.Keyword)
|
||||
.ToDictionary(x => x.Key, x => x.Select(ExportedQuote.FromModel));
|
||||
.ToDictionary(x => x.Key, x => x.Select(ExportedQuote.FromModel));
|
||||
|
||||
var text = PREPEND_EXPORT + _exportSerializer.Serialize(exprsDict).UnescapeUnicodeCodePoints();
|
||||
|
||||
@@ -351,7 +354,7 @@ public partial class Utility
|
||||
var attachment = ctx.Message.Attachments.FirstOrDefault();
|
||||
if (attachment is null)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.expr_import_no_input);
|
||||
await Response().Error(strs.expr_import_no_input).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -360,7 +363,7 @@ public partial class Utility
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.expr_import_no_input);
|
||||
await Response().Error(strs.expr_import_no_input).SendAsync();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -368,7 +371,7 @@ public partial class Utility
|
||||
var succ = await ImportExprsAsync(ctx.Guild.Id, input);
|
||||
if (!succ)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.expr_import_invalid_data);
|
||||
await Response().Error(strs.expr_import_invalid_data).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -393,15 +396,16 @@ public partial class Utility
|
||||
foreach (var entry in data)
|
||||
{
|
||||
var keyword = entry.Key;
|
||||
await uow.Set<Quote>().AddRangeAsync(entry.Value.Where(quote => !string.IsNullOrWhiteSpace(quote.Txt))
|
||||
.Select(quote => new Quote
|
||||
{
|
||||
GuildId = guildId,
|
||||
Keyword = keyword,
|
||||
Text = quote.Txt,
|
||||
AuthorId = quote.Aid,
|
||||
AuthorName = quote.An
|
||||
}));
|
||||
await uow.Set<Quote>()
|
||||
.AddRangeAsync(entry.Value.Where(quote => !string.IsNullOrWhiteSpace(quote.Txt))
|
||||
.Select(quote => new Quote
|
||||
{
|
||||
GuildId = guildId,
|
||||
Keyword = keyword,
|
||||
Text = quote.Txt,
|
||||
AuthorId = quote.Aid,
|
||||
AuthorName = quote.An
|
||||
}));
|
||||
}
|
||||
|
||||
await uow.SaveChangesAsync();
|
||||
|
@@ -41,10 +41,10 @@ public partial class Utility
|
||||
{
|
||||
if (!_service.TryParseRemindMessage(remindString, out var remindData))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.remind_invalid);
|
||||
await Response().Error(strs.remind_invalid).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ulong target;
|
||||
target = meorhere == MeOrHere.Me ? ctx.User.Id : ctx.Channel.Id;
|
||||
if (!await RemindInternal(target,
|
||||
@@ -52,7 +52,7 @@ public partial class Utility
|
||||
remindData.Time,
|
||||
remindData.What,
|
||||
ReminderType.User))
|
||||
await ReplyErrorLocalizedAsync(strs.remind_too_long);
|
||||
await Response().Error(strs.remind_too_long).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -64,19 +64,19 @@ public partial class Utility
|
||||
var perms = ((IGuildUser)ctx.User).GetPermissions(channel);
|
||||
if (!perms.SendMessages || !perms.ViewChannel)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.cant_read_or_send);
|
||||
await Response().Error(strs.cant_read_or_send).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_service.TryParseRemindMessage(remindString, out var remindData))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.remind_invalid);
|
||||
await Response().Error(strs.remind_invalid).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!await RemindInternal(channel.Id, false, remindData.Time, remindData.What, ReminderType.User))
|
||||
await ReplyErrorLocalizedAsync(strs.remind_too_long);
|
||||
await Response().Error(strs.remind_too_long).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -96,7 +96,7 @@ public partial class Utility
|
||||
if (--page < 0)
|
||||
return;
|
||||
|
||||
var embed = _eb.Create()
|
||||
var embed = new EmbedBuilder()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(isServer ? strs.reminder_server_list : strs.reminder_list));
|
||||
|
||||
@@ -128,7 +128,7 @@ public partial class Utility
|
||||
embed.WithDescription(GetText(strs.reminders_none));
|
||||
|
||||
embed.AddPaginatedFooter(page + 1, null);
|
||||
await EmbedAsync(embed);
|
||||
await Response().Embed(embed).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -165,9 +165,9 @@ public partial class Utility
|
||||
}
|
||||
|
||||
if (rem is null)
|
||||
await ReplyErrorLocalizedAsync(strs.reminder_not_exist);
|
||||
await Response().Error(strs.reminder_not_exist).SendAsync();
|
||||
else
|
||||
await ReplyConfirmLocalizedAsync(strs.reminder_deleted(index + 1));
|
||||
await Response().Confirm(strs.reminder_deleted(index + 1)).SendAsync();
|
||||
}
|
||||
|
||||
private async Task<bool> RemindInternal(
|
||||
@@ -208,13 +208,14 @@ public partial class Utility
|
||||
var gTime = ctx.Guild is null ? time : TimeZoneInfo.ConvertTime(time, _tz.GetTimeZoneOrUtc(ctx.Guild.Id));
|
||||
try
|
||||
{
|
||||
await SendConfirmAsync("⏰ "
|
||||
+ GetText(strs.remind(
|
||||
Format.Bold(!isPrivate ? $"<#{targetId}>" : ctx.User.Username),
|
||||
Format.Bold(message),
|
||||
ts.Humanize(3, minUnit: TimeUnit.Second, culture: Culture),
|
||||
gTime,
|
||||
gTime)));
|
||||
await Response()
|
||||
.Confirm($"\u23f0 {GetText(strs.remind(
|
||||
Format.Bold(!isPrivate ? $"<#{targetId}>" : ctx.User.Username),
|
||||
Format.Bold(message),
|
||||
ts.Humanize(3, minUnit: TimeUnit.Second, culture: Culture),
|
||||
gTime,
|
||||
gTime))}")
|
||||
.SendAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@@ -205,7 +205,7 @@ public class RemindService : INService, IReadyExecutor, IRemindService
|
||||
}
|
||||
else
|
||||
{
|
||||
await ch.EmbedAsync(_eb.Create()
|
||||
await ch.EmbedAsync(new EmbedBuilder()
|
||||
.WithOkColor()
|
||||
.WithTitle("Reminder")
|
||||
.AddField("Created At",
|
||||
|
@@ -21,17 +21,17 @@ public partial class Utility
|
||||
|
||||
if (result is null)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.index_out_of_range);
|
||||
await Response().Error(strs.index_out_of_range).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
if (result is true)
|
||||
{
|
||||
await ReplyConfirmLocalizedAsync(strs.repeater_skip_next);
|
||||
await Response().Confirm(strs.repeater_skip_next).SendAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyConfirmLocalizedAsync(strs.repeater_dont_skip_next);
|
||||
await Response().Confirm(strs.repeater_dont_skip_next).SendAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public partial class Utility
|
||||
|
||||
var success = await _service.TriggerExternal(ctx.Guild.Id, index);
|
||||
if (!success)
|
||||
await ReplyErrorLocalizedAsync(strs.repeat_invoke_none);
|
||||
await Response().Error(strs.repeat_invoke_none).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -59,15 +59,15 @@ public partial class Utility
|
||||
var removed = await _service.RemoveByIndexAsync(ctx.Guild.Id, index);
|
||||
if (removed is null)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.repeater_remove_fail);
|
||||
await Response().Error(strs.repeater_remove_fail).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var description = GetRepeaterInfoString(removed);
|
||||
await EmbedAsync(_eb.Create()
|
||||
await Response().Embed(new EmbedBuilder()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.repeater_removed(index + 1)))
|
||||
.WithDescription(description));
|
||||
.WithDescription(description)).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -82,14 +82,14 @@ public partial class Utility
|
||||
|
||||
if (result is null)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.index_out_of_range);
|
||||
await Response().Error(strs.index_out_of_range).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.Value)
|
||||
await ReplyErrorLocalizedAsync(strs.repeater_redundant_no(index + 1));
|
||||
await Response().Error(strs.repeater_redundant_no(index + 1)).SendAsync();
|
||||
else
|
||||
await ReplyConfirmLocalizedAsync(strs.repeater_redundant_yes(index + 1));
|
||||
await Response().Confirm(strs.repeater_redundant_yes(index + 1)).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -182,15 +182,15 @@ public partial class Utility
|
||||
|
||||
if (runner is null)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.repeater_exceed_limit(5));
|
||||
await Response().Error(strs.repeater_exceed_limit(5)).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var description = GetRepeaterInfoString(runner);
|
||||
await EmbedAsync(_eb.Create()
|
||||
await Response().Embed(new EmbedBuilder()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.repeater_created))
|
||||
.WithDescription(description));
|
||||
.WithDescription(description)).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -201,11 +201,11 @@ public partial class Utility
|
||||
var repeaters = _service.GetRepeaters(ctx.Guild.Id);
|
||||
if (repeaters.Count == 0)
|
||||
{
|
||||
await ReplyConfirmLocalizedAsync(strs.repeaters_none);
|
||||
await Response().Confirm(strs.repeaters_none).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var embed = _eb.Create().WithTitle(GetText(strs.list_of_repeaters)).WithOkColor();
|
||||
var embed = new EmbedBuilder().WithTitle(GetText(strs.list_of_repeaters)).WithOkColor();
|
||||
|
||||
var i = 0;
|
||||
foreach (var runner in repeaters.OrderBy(r => r.Repeater.Id))
|
||||
@@ -215,7 +215,7 @@ public partial class Utility
|
||||
embed.AddField(name, description);
|
||||
}
|
||||
|
||||
await EmbedAsync(embed);
|
||||
await Response().Embed(embed).SendAsync();
|
||||
}
|
||||
|
||||
private string GetRepeaterInfoString(RunningRepeater runner)
|
||||
|
@@ -16,8 +16,8 @@ public partial class Utility
|
||||
{
|
||||
await _service.SetStreamRole(fromRole, addRole);
|
||||
|
||||
await ReplyConfirmLocalizedAsync(strs.stream_role_enabled(Format.Bold(fromRole.ToString()),
|
||||
Format.Bold(addRole.ToString())));
|
||||
await Response().Confirm(strs.stream_role_enabled(Format.Bold(fromRole.ToString()),
|
||||
Format.Bold(addRole.ToString()))).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -27,7 +27,7 @@ public partial class Utility
|
||||
public async Task StreamRole()
|
||||
{
|
||||
await _service.StopStreamRole(ctx.Guild);
|
||||
await ReplyConfirmLocalizedAsync(strs.stream_role_disabled);
|
||||
await Response().Confirm(strs.stream_role_disabled).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -39,9 +39,9 @@ public partial class Utility
|
||||
var kw = await _service.SetKeyword(ctx.Guild, keyword);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(keyword))
|
||||
await ReplyConfirmLocalizedAsync(strs.stream_role_kw_reset);
|
||||
await Response().Confirm(strs.stream_role_kw_reset).SendAsync();
|
||||
else
|
||||
await ReplyConfirmLocalizedAsync(strs.stream_role_kw_set(Format.Bold(kw)));
|
||||
await Response().Confirm(strs.stream_role_kw_set(Format.Bold(kw))).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -59,14 +59,14 @@ public partial class Utility
|
||||
if (action == AddRemove.Add)
|
||||
{
|
||||
if (success)
|
||||
await ReplyConfirmLocalizedAsync(strs.stream_role_bl_add(Format.Bold(user.ToString())));
|
||||
await Response().Confirm(strs.stream_role_bl_add(Format.Bold(user.ToString()))).SendAsync();
|
||||
else
|
||||
await ReplyConfirmLocalizedAsync(strs.stream_role_bl_add_fail(Format.Bold(user.ToString())));
|
||||
await Response().Confirm(strs.stream_role_bl_add_fail(Format.Bold(user.ToString()))).SendAsync();
|
||||
}
|
||||
else if (success)
|
||||
await ReplyConfirmLocalizedAsync(strs.stream_role_bl_rem(Format.Bold(user.ToString())));
|
||||
await Response().Confirm(strs.stream_role_bl_rem(Format.Bold(user.ToString()))).SendAsync();
|
||||
else
|
||||
await ReplyErrorLocalizedAsync(strs.stream_role_bl_rem_fail(Format.Bold(user.ToString())));
|
||||
await Response().Error(strs.stream_role_bl_rem_fail(Format.Bold(user.ToString()))).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -84,14 +84,14 @@ public partial class Utility
|
||||
if (action == AddRemove.Add)
|
||||
{
|
||||
if (success)
|
||||
await ReplyConfirmLocalizedAsync(strs.stream_role_wl_add(Format.Bold(user.ToString())));
|
||||
await Response().Confirm(strs.stream_role_wl_add(Format.Bold(user.ToString()))).SendAsync();
|
||||
else
|
||||
await ReplyConfirmLocalizedAsync(strs.stream_role_wl_add_fail(Format.Bold(user.ToString())));
|
||||
await Response().Confirm(strs.stream_role_wl_add_fail(Format.Bold(user.ToString()))).SendAsync();
|
||||
}
|
||||
else if (success)
|
||||
await ReplyConfirmLocalizedAsync(strs.stream_role_wl_rem(Format.Bold(user.ToString())));
|
||||
await Response().Confirm(strs.stream_role_wl_rem(Format.Bold(user.ToString()))).SendAsync();
|
||||
else
|
||||
await ReplyErrorLocalizedAsync(strs.stream_role_wl_rem_fail(Format.Bold(user.ToString())));
|
||||
await Response().Error(strs.stream_role_wl_rem_fail(Format.Bold(user.ToString()))).SendAsync();
|
||||
}
|
||||
}
|
||||
}
|
@@ -13,7 +13,7 @@ public partial class Utility
|
||||
var result = await _service.AddAsync(ctx.User.Id, todo);
|
||||
if (result == TodoAddResult.MaxLimitReached)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.todo_add_max_limit);
|
||||
await Response().Error(strs.todo_add_max_limit).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public partial class Utility
|
||||
{
|
||||
if (!await _service.EditAsync(ctx.User.Id, todoId, newMessage))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.todo_not_found);
|
||||
await Response().Error(strs.todo_not_found).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public partial class Utility
|
||||
|
||||
if (todos.Length == 0)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.todo_list_empty);
|
||||
await Response().Error(strs.todo_list_empty).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public partial class Utility
|
||||
{
|
||||
if (!await _service.CompleteTodoAsync(ctx.User.Id, todoId))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.todo_not_found);
|
||||
await Response().Error(strs.todo_not_found).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public partial class Utility
|
||||
{
|
||||
if (!await _service.DeleteTodoAsync(ctx.User.Id, todoId))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.todo_not_found);
|
||||
await Response().Error(strs.todo_not_found).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public partial class Utility
|
||||
{
|
||||
await _service.ClearTodosAsync(ctx.User.Id);
|
||||
|
||||
await ReplyConfirmLocalizedAsync(strs.todo_cleared);
|
||||
await Response().Confirm(strs.todo_cleared).SendAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ public partial class Utility
|
||||
await ctx.SendPaginatedConfirmAsync(0,
|
||||
(curPage) =>
|
||||
{
|
||||
var eb = _eb.Create()
|
||||
var eb = new EmbedBuilder()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.todo_list));
|
||||
|
||||
@@ -97,7 +97,7 @@ public partial class Utility
|
||||
9);
|
||||
}
|
||||
|
||||
private static void ShowTodoItem(IReadOnlyCollection<TodoModel> todos, int curPage, IEmbedBuilder eb)
|
||||
private static void ShowTodoItem(IReadOnlyCollection<TodoModel> todos, int curPage, EmbedBuilder eb)
|
||||
{
|
||||
foreach (var todo in todos.Skip(curPage * 9).Take(9))
|
||||
{
|
||||
@@ -119,13 +119,13 @@ public partial class Utility
|
||||
var result = await _service.ArchiveTodosAsync(ctx.User.Id, name);
|
||||
if (result == ArchiveTodoResult.NoTodos)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.todo_no_todos);
|
||||
await Response().Error(strs.todo_no_todos).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
if (result == ArchiveTodoResult.MaxLimitReached)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.todo_archive_max_limit);
|
||||
await Response().Error(strs.todo_archive_max_limit).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -142,14 +142,14 @@ public partial class Utility
|
||||
|
||||
if (archivedTodoLists.Count == 0)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.todo_archive_empty);
|
||||
await Response().Error(strs.todo_archive_empty).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
await ctx.SendPaginatedConfirmAsync(page,
|
||||
(curPage) =>
|
||||
{
|
||||
var eb = _eb.Create()
|
||||
var eb = new EmbedBuilder()
|
||||
.WithTitle(GetText(strs.todo_archive_list))
|
||||
.WithOkColor();
|
||||
|
||||
@@ -171,14 +171,14 @@ public partial class Utility
|
||||
var list = await _service.GetArchivedTodoListAsync(ctx.User.Id, id);
|
||||
if (list == null || list.Items.Count == 0)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.todo_archive_not_found);
|
||||
await Response().Error(strs.todo_archive_not_found).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
await ctx.SendPaginatedConfirmAsync(0,
|
||||
(curPage) =>
|
||||
{
|
||||
var eb = _eb.Create()
|
||||
var eb = new EmbedBuilder()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.todo_list));
|
||||
|
||||
|
@@ -13,7 +13,7 @@ public partial class Utility
|
||||
{
|
||||
var units = await _service.GetUnitsAsync();
|
||||
|
||||
var embed = _eb.Create().WithTitle(GetText(strs.convertlist)).WithOkColor();
|
||||
var embed = new EmbedBuilder().WithTitle(GetText(strs.convertlist)).WithOkColor();
|
||||
|
||||
|
||||
foreach (var g in units.GroupBy(x => x.UnitType))
|
||||
@@ -22,7 +22,7 @@ public partial class Utility
|
||||
string.Join(", ", g.Select(x => x.Triggers.FirstOrDefault()).OrderBy(x => x)));
|
||||
}
|
||||
|
||||
await EmbedAsync(embed);
|
||||
await Response().Embed(embed).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -36,14 +36,16 @@ public partial class Utility
|
||||
=> x.Triggers.Select(y => y.ToUpperInvariant()).Contains(target.ToUpperInvariant()));
|
||||
if (originUnit is null || targetUnit is null)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.convert_not_found(Format.Bold(origin), Format.Bold(target)));
|
||||
await Response().Error(strs.convert_not_found(Format.Bold(origin), Format.Bold(target))).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
if (originUnit.UnitType != targetUnit.UnitType)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.convert_type_error(Format.Bold(originUnit.Triggers.First()),
|
||||
Format.Bold(targetUnit.Triggers.First())));
|
||||
await Response()
|
||||
.Error(strs.convert_type_error(Format.Bold(originUnit.Triggers.First()),
|
||||
Format.Bold(targetUnit.Triggers.First())))
|
||||
.SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -87,10 +89,12 @@ public partial class Utility
|
||||
|
||||
res = Math.Round(res, 4);
|
||||
|
||||
await SendConfirmAsync(GetText(strs.convert(value,
|
||||
originUnit.Triggers.Last(),
|
||||
res,
|
||||
targetUnit.Triggers.Last())));
|
||||
await Response()
|
||||
.Confirm(GetText(strs.convert(value,
|
||||
originUnit.Triggers.Last(),
|
||||
res,
|
||||
targetUnit.Triggers.Last())))
|
||||
.SendAsync();
|
||||
}
|
||||
}
|
||||
}
|
@@ -70,13 +70,13 @@ public partial class Utility : NadekoModule
|
||||
{
|
||||
if (!((IGuildUser)ctx.User).GetPermissions(channel).SendMessages)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.insuf_perms_u);
|
||||
await Response().Error(strs.insuf_perms_u).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!((ctx.Guild as SocketGuild)?.CurrentUser.GetPermissions(channel).SendMessages ?? false))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.insuf_perms_i);
|
||||
await Response().Error(strs.insuf_perms_i).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -122,14 +122,16 @@ public partial class Utility : NadekoModule
|
||||
|
||||
var i = 0;
|
||||
if (arr.Length == 0)
|
||||
await ReplyErrorLocalizedAsync(strs.nobody_playing_game);
|
||||
await Response().Error(strs.nobody_playing_game).SendAsync();
|
||||
else
|
||||
{
|
||||
await SendConfirmAsync("```css\n"
|
||||
+ string.Join("\n",
|
||||
arr.GroupBy(_ => i++ / 2)
|
||||
.Select(ig => string.Concat(ig.Select(el => $"• {el,-27}"))))
|
||||
+ "\n```");
|
||||
await Response()
|
||||
.Confirm("```css\n"
|
||||
+ string.Join("\n",
|
||||
arr.GroupBy(_ => i++ / 2)
|
||||
.Select(ig => string.Concat(ig.Select(el => $"• {el,-27}"))))
|
||||
+ "\n```")
|
||||
.SendAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,9 +160,9 @@ public partial class Utility : NadekoModule
|
||||
var pageUsers = roleUsers.Skip(cur * 20).Take(20).ToList();
|
||||
|
||||
if (pageUsers.Count == 0)
|
||||
return _eb.Create().WithOkColor().WithDescription(GetText(strs.no_user_on_this_page));
|
||||
return new EmbedBuilder().WithOkColor().WithDescription(GetText(strs.no_user_on_this_page));
|
||||
|
||||
return _eb.Create()
|
||||
return new EmbedBuilder()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.inrole_list(Format.Bold(role?.Name ?? "No Role"), roleUsers.Length)))
|
||||
.WithDescription(string.Join("\n", pageUsers));
|
||||
@@ -192,7 +194,7 @@ public partial class Utility : NadekoModule
|
||||
return !method.GetParameters().Any();
|
||||
}))
|
||||
builder.AppendLine($"{p.Name} : {p.GetValue(perms, null)}");
|
||||
await SendConfirmAsync(builder.ToString());
|
||||
await Response().Confirm(builder.ToString()).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -200,26 +202,30 @@ public partial class Utility : NadekoModule
|
||||
public async Task UserId([Leftover] IGuildUser target = null)
|
||||
{
|
||||
var usr = target ?? ctx.User;
|
||||
await ReplyConfirmLocalizedAsync(strs.userid("🆔",
|
||||
Format.Bold(usr.ToString()),
|
||||
Format.Code(usr.Id.ToString())));
|
||||
await Response()
|
||||
.Confirm(strs.userid("🆔",
|
||||
Format.Bold(usr.ToString()),
|
||||
Format.Code(usr.Id.ToString())))
|
||||
.SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task RoleId([Leftover] IRole role)
|
||||
=> await ReplyConfirmLocalizedAsync(strs.roleid("🆔",
|
||||
Format.Bold(role.ToString()),
|
||||
Format.Code(role.Id.ToString())));
|
||||
=> await Response()
|
||||
.Confirm(strs.roleid("🆔",
|
||||
Format.Bold(role.ToString()),
|
||||
Format.Code(role.Id.ToString())))
|
||||
.SendAsync();
|
||||
|
||||
[Cmd]
|
||||
public async Task ChannelId()
|
||||
=> await ReplyConfirmLocalizedAsync(strs.channelid("🆔", Format.Code(ctx.Channel.Id.ToString())));
|
||||
=> await Response().Confirm(strs.channelid("🆔", Format.Code(ctx.Channel.Id.ToString()))).SendAsync();
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task ServerId()
|
||||
=> await ReplyConfirmLocalizedAsync(strs.serverid("🆔", Format.Code(ctx.Guild.Id.ToString())));
|
||||
=> await Response().Confirm(strs.serverid("🆔", Format.Code(ctx.Guild.Id.ToString()))).SendAsync();
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
@@ -241,11 +247,13 @@ public partial class Utility : NadekoModule
|
||||
.Take(rolesPerPage)
|
||||
.ToArray();
|
||||
if (!roles.Any())
|
||||
await ReplyErrorLocalizedAsync(strs.no_roles_on_page);
|
||||
await Response().Error(strs.no_roles_on_page).SendAsync();
|
||||
else
|
||||
{
|
||||
await SendConfirmAsync(GetText(strs.roles_page(page, Format.Bold(target.ToString()))),
|
||||
"\n• " + string.Join("\n• ", (IEnumerable<IRole>)roles).SanitizeMentions(true));
|
||||
await Response()
|
||||
.Confirm(GetText(strs.roles_page(page, Format.Bold(target.ToString()))),
|
||||
"\n• " + string.Join("\n• ", (IEnumerable<IRole>)roles))
|
||||
.SendAsync();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -256,11 +264,13 @@ public partial class Utility : NadekoModule
|
||||
.Take(rolesPerPage)
|
||||
.ToArray();
|
||||
if (!roles.Any())
|
||||
await ReplyErrorLocalizedAsync(strs.no_roles_on_page);
|
||||
await Response().Error(strs.no_roles_on_page).SendAsync();
|
||||
else
|
||||
{
|
||||
await SendConfirmAsync(GetText(strs.roles_all_page(page)),
|
||||
"\n• " + string.Join("\n• ", (IEnumerable<IRole>)roles).SanitizeMentions(true));
|
||||
await Response()
|
||||
.Confirm(GetText(strs.roles_all_page(page)),
|
||||
"\n• " + string.Join("\n• ", (IEnumerable<IRole>)roles).SanitizeMentions(true))
|
||||
.SendAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -279,9 +289,9 @@ public partial class Utility : NadekoModule
|
||||
|
||||
var topic = channel.Topic;
|
||||
if (string.IsNullOrWhiteSpace(topic))
|
||||
await ReplyErrorLocalizedAsync(strs.no_topic_set);
|
||||
await Response().Error(strs.no_topic_set).SendAsync();
|
||||
else
|
||||
await SendConfirmAsync(GetText(strs.channel_topic), topic);
|
||||
await Response().Confirm(GetText(strs.channel_topic), topic).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -291,7 +301,7 @@ public partial class Utility : NadekoModule
|
||||
if (string.IsNullOrWhiteSpace(ownerIds))
|
||||
ownerIds = "-";
|
||||
|
||||
await EmbedAsync(_eb.Create()
|
||||
await Response().Embed(new EmbedBuilder()
|
||||
.WithOkColor()
|
||||
.WithAuthor($"NadekoBot v{StatsService.BotVersion}",
|
||||
"https://nadeko-pictures.nyc3.digitaloceanspaces.com/other/avatar.png",
|
||||
@@ -314,7 +324,7 @@ public partial class Utility : NadekoModule
|
||||
GetText(strs.presence_txt(_coord.GetGuildCount(),
|
||||
_stats.TextChannels,
|
||||
_stats.VoiceChannels)),
|
||||
true));
|
||||
true)).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -325,7 +335,7 @@ public partial class Utility : NadekoModule
|
||||
var result = string.Join("\n", tags.Select(m => GetText(strs.showemojis(m, m.Url))));
|
||||
|
||||
if (string.IsNullOrWhiteSpace(result))
|
||||
await ReplyErrorLocalizedAsync(strs.showemojis_none);
|
||||
await Response().Error(strs.showemojis_none).SendAsync();
|
||||
else
|
||||
await ctx.Channel.SendMessageAsync(result.TrimTo(2000));
|
||||
}
|
||||
@@ -364,7 +374,7 @@ public partial class Utility : NadekoModule
|
||||
using var res = await http.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
|
||||
if (!res.IsImage() || res.GetContentLength() > 262_144)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.invalid_emoji_link);
|
||||
await Response().Error(strs.invalid_emoji_link).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -378,11 +388,11 @@ public partial class Utility : NadekoModule
|
||||
{
|
||||
Log.Warning(ex, "Error adding emoji on server {GuildId}", ctx.Guild.Id);
|
||||
|
||||
await ReplyErrorLocalizedAsync(strs.emoji_add_error);
|
||||
await Response().Error(strs.emoji_add_error).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
await ConfirmLocalizedAsync(strs.emoji_added(em.ToString()));
|
||||
await Response().Confirm(strs.emoji_added(em.ToString())).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -413,7 +423,7 @@ public partial class Utility : NadekoModule
|
||||
|
||||
if (fails.Count > 0)
|
||||
{
|
||||
await ReplyPendingLocalizedAsync(strs.emoji_not_removed(fails.Select(x => x.ToString()).Join(" ")));
|
||||
await Response().Pending(strs.emoji_not_removed(fails.Select(x => x.ToString()).Join(" "))).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -442,7 +452,7 @@ public partial class Utility : NadekoModule
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.sticker_error);
|
||||
await Response().Error(strs.sticker_error).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -464,7 +474,7 @@ public partial class Utility : NadekoModule
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Error occurred while adding a sticker: {Message}", ex.Message);
|
||||
await ReplyErrorLocalizedAsync(strs.error_occured);
|
||||
await Response().Error(strs.error_occured).SendAsync();
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -503,15 +513,15 @@ public partial class Utility : NadekoModule
|
||||
|
||||
if (!guilds.Any())
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.listservers_none);
|
||||
await Response().Error(strs.listservers_none).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var embed = _eb.Create().WithOkColor();
|
||||
var embed = new EmbedBuilder().WithOkColor();
|
||||
foreach (var guild in guilds)
|
||||
embed.AddField(guild.Name, GetText(strs.listservers(guild.Id, guild.MemberCount, guild.OwnerId)));
|
||||
|
||||
await EmbedAsync(embed);
|
||||
await Response().Embed(embed).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -527,20 +537,20 @@ public partial class Utility : NadekoModule
|
||||
var perms = user.GetPermissions(ch);
|
||||
if (!perms.ReadMessageHistory || !perms.ViewChannel)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.insuf_perms_u);
|
||||
await Response().Error(strs.insuf_perms_u).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var msg = await ch.GetMessageAsync(messageId);
|
||||
if (msg is null)
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.msg_not_found);
|
||||
await Response().Error(strs.msg_not_found).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!msg.Embeds.Any())
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.not_found);
|
||||
await Response().Error(strs.not_found).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -551,7 +561,7 @@ public partial class Utility : NadekoModule
|
||||
.Map(x => new SmartEmbedArrayElementText(x))
|
||||
}.ToJson(_showEmbedSerializerOptions);
|
||||
|
||||
await SendConfirmAsync(Format.Code(json, "json").Replace("](", "]\\("));
|
||||
await Response().Confirm(Format.Code(json, "json").Replace("](", "]\\(")).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -607,7 +617,9 @@ public partial class Utility : NadekoModule
|
||||
sw.Stop();
|
||||
msg.DeleteAfter(0);
|
||||
|
||||
await SendConfirmAsync($"{Format.Bold(ctx.User.ToString())} 🏓 {(int)sw.Elapsed.TotalMilliseconds}ms");
|
||||
await Response()
|
||||
.Confirm($"{Format.Bold(ctx.User.ToString())} 🏓 {(int)sw.Elapsed.TotalMilliseconds}ms")
|
||||
.SendAsync();
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -623,9 +635,9 @@ public partial class Utility : NadekoModule
|
||||
var state = _veService.ToggleVerboseErrors(ctx.Guild.Id, newstate);
|
||||
|
||||
if (state)
|
||||
await ReplyConfirmLocalizedAsync(strs.verbose_errors_enabled);
|
||||
await Response().Confirm(strs.verbose_errors_enabled).SendAsync();
|
||||
else
|
||||
await ReplyConfirmLocalizedAsync(strs.verbose_errors_disabled);
|
||||
await Response().Confirm(strs.verbose_errors_disabled).SendAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -671,17 +683,17 @@ public partial class Utility : NadekoModule
|
||||
var output = result.ReturnValue?.ToString();
|
||||
if (!string.IsNullOrWhiteSpace(output))
|
||||
{
|
||||
var eb = _eb.Create(ctx)
|
||||
var eb = new EmbedBuilder()
|
||||
.WithOkColor()
|
||||
.AddField("Code", scriptText)
|
||||
.AddField("Output", output.TrimTo(512)!);
|
||||
|
||||
_ = EmbedAsync(eb);
|
||||
_ = Response().Embed(eb).SendAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await SendErrorAsync(ex.Message);
|
||||
await Response().Error(ex.Message).SendAsync();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user