change: Quotes will now use easier to write, alphanumerical ids (same as expressions)

This commit is contained in:
Kwoth
2024-05-18 22:47:25 +00:00
parent 0c167a9382
commit d2c7563c5c

View File

@@ -71,7 +71,7 @@ public partial class Utility
.Confirm(GetText(strs.quotes_page(page + 1)), .Confirm(GetText(strs.quotes_page(page + 1)),
string.Join("\n", string.Join("\n",
quotes.Select(q quotes.Select(q
=> $"`#{q.Id}` {Format.Bold(q.Keyword.SanitizeAllMentions()),-20} by {q.AuthorName.SanitizeAllMentions()}"))) => $"`{new kwum(q.Id)}` {Format.Bold(q.Keyword.SanitizeAllMentions()),-20} by {q.AuthorName.SanitizeAllMentions()}")))
.SendAsync(); .SendAsync();
} }
else else
@@ -107,19 +107,19 @@ public partial class Utility
text = await repSvc.ReplaceAsync(text, repCtx); text = await repSvc.ReplaceAsync(text, repCtx);
await Response() await Response()
.Text($"`#{quote.Id}` 📣 " + text) .Text($"`{new kwum(quote.Id)}` 📣 " + text)
.Sanitize() .Sanitize()
.SendAsync(); .SendAsync();
} }
[Cmd] [Cmd]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task QuoteShow(int id) public async Task QuoteShow(kwum quoteId)
{ {
Quote? quote; Quote? quote;
await using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
quote = uow.Set<Quote>().GetById(id); quote = uow.Set<Quote>().GetById(quoteId);
if (quote?.GuildId != ctx.Guild.Id) if (quote?.GuildId != ctx.Guild.Id)
quote = null; quote = null;
} }
@@ -137,7 +137,7 @@ public partial class Utility
{ {
var eb = _sender.CreateEmbed() var eb = _sender.CreateEmbed()
.WithOkColor() .WithOkColor()
.WithTitle($"{GetText(strs.quote_id($"#{data.Id}"))} | {GetText(strs.response)}:") .WithTitle($"{GetText(strs.quote_id($"`{new kwum(data.Id)}"))}`")
.WithDescription(Format.Sanitize(data.Text).Replace("](", "]\\(").TrimTo(4096)) .WithDescription(Format.Sanitize(data.Text).Replace("](", "]\\(").TrimTo(4096))
.AddField(GetText(strs.trigger), data.Keyword) .AddField(GetText(strs.trigger), data.Keyword)
.WithFooter( .WithFooter(
@@ -174,7 +174,7 @@ public partial class Utility
return; return;
await Response() await Response()
.Confirm($"`#{quote.Id}` 💬 ", .Confirm($"`{new kwum(quote.Id)}` 💬 ",
quote.Keyword.ToLowerInvariant() quote.Keyword.ToLowerInvariant()
+ ": " + ": "
+ quote.Text.SanitizeAllMentions()) + quote.Text.SanitizeAllMentions())
@@ -195,9 +195,9 @@ public partial class Utility
[Cmd] [Cmd]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task QuoteId(int id) public async Task QuoteId(kwum quoteId)
{ {
if (id < 0) if (quoteId < 0)
return; return;
Quote quote; Quote quote;
@@ -206,7 +206,7 @@ public partial class Utility
await using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
quote = uow.Set<Quote>().GetById(id); quote = uow.Set<Quote>().GetById(quoteId);
} }
if (quote is null || quote.GuildId != ctx.Guild.Id) if (quote is null || quote.GuildId != ctx.Guild.Id)
@@ -215,7 +215,7 @@ public partial class Utility
return; return;
} }
var infoText = $"`#{quote.Id} added by {quote.AuthorName.SanitizeAllMentions()}` 🗯️ " var infoText = $"*`{new kwum(quote.Id)}` added by {quote.AuthorName.SanitizeAllMentions()}* 🗯️ "
+ quote.Keyword.ToLowerInvariant().SanitizeAllMentions() + quote.Keyword.ToLowerInvariant().SanitizeAllMentions()
+ ":\n"; + ":\n";
@@ -252,12 +252,12 @@ public partial class Utility
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
} }
await Response().Confirm(strs.quote_added_new(Format.Code(q.Id.ToString()))).SendAsync(); await Response().Confirm(strs.quote_added_new(Format.Code(new kwum(q.Id).ToString()))).SendAsync();
} }
[Cmd] [Cmd]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task QuoteDelete(int id) public async Task QuoteDelete(kwum quoteId)
{ {
var hasManageMessages = ((IGuildUser)ctx.Message.Author).GuildPermissions.ManageMessages; var hasManageMessages = ((IGuildUser)ctx.Message.Author).GuildPermissions.ManageMessages;
@@ -265,7 +265,7 @@ public partial class Utility
string response; string response;
await using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var q = uow.Set<Quote>().GetById(id); var q = uow.Set<Quote>().GetById(quoteId);
if (q?.GuildId != ctx.Guild.Id || (!hasManageMessages && q.AuthorId != ctx.Message.Author.Id)) if (q?.GuildId != ctx.Guild.Id || (!hasManageMessages && q.AuthorId != ctx.Message.Author.Id))
response = GetText(strs.quotes_remove_none); response = GetText(strs.quotes_remove_none);
@@ -274,7 +274,7 @@ public partial class Utility
uow.Set<Quote>().Remove(q); uow.Set<Quote>().Remove(q);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
success = true; success = true;
response = GetText(strs.quote_deleted(id)); response = GetText(strs.quote_deleted(new kwum(quoteId)));
} }
} }