light cleanup
This commit is contained in:
parent
ff46c4eab6
commit
15fafc577d
1 changed files with 77 additions and 78 deletions
|
@ -4,13 +4,9 @@ using EllieBot.Db.Models;
|
||||||
namespace EllieBot.Modules.EllieExpressions;
|
namespace EllieBot.Modules.EllieExpressions;
|
||||||
|
|
||||||
[Name("Expressions")]
|
[Name("Expressions")]
|
||||||
public partial class EllieExpressions(IBotCreds creds, IHttpClientFactory clientFactory) : EllieModule<EllieExpressionsService>
|
public sealed class EllieExpressions(IBotCreds creds, IHttpClientFactory clientFactory)
|
||||||
|
: EllieModule<EllieExpressionsService>
|
||||||
{
|
{
|
||||||
public enum All
|
|
||||||
{
|
|
||||||
All
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool AdminInGuildOrOwnerInDm()
|
private bool AdminInGuildOrOwnerInDm()
|
||||||
=> (ctx.Guild is null && creds.IsOwner(ctx.User))
|
=> (ctx.Guild is null && creds.IsOwner(ctx.User))
|
||||||
|| (ctx.Guild is not null && ((IGuildUser)ctx.User).GuildPermissions.Administrator);
|
|| (ctx.Guild is not null && ((IGuildUser)ctx.User).GuildPermissions.Administrator);
|
||||||
|
@ -25,14 +21,14 @@ public partial class EllieExpressions(IBotCreds creds, IHttpClientFactory client
|
||||||
var ex = await _service.AddAsync(ctx.Guild?.Id, key, message);
|
var ex = await _service.AddAsync(ctx.Guild?.Id, key, message);
|
||||||
|
|
||||||
await Response()
|
await Response()
|
||||||
.Embed(CreateEmbed()
|
.Embed(CreateEmbed()
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithTitle(GetText(strs.expr_new))
|
.WithTitle(GetText(strs.expr_new))
|
||||||
.WithDescription($"#{new kwum(ex.Id)}")
|
.WithDescription($"#{new kwum(ex.Id)}")
|
||||||
.AddField(GetText(strs.trigger), key)
|
.AddField(GetText(strs.trigger), key)
|
||||||
.AddField(GetText(strs.response),
|
.AddField(GetText(strs.response),
|
||||||
message.Length > 1024 ? GetText(strs.redacted_too_long) : message))
|
message.Length > 1024 ? GetText(strs.redacted_too_long) : message))
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
|
@ -95,14 +91,14 @@ public partial class EllieExpressions(IBotCreds creds, IHttpClientFactory client
|
||||||
if (ex is not null)
|
if (ex is not null)
|
||||||
{
|
{
|
||||||
await Response()
|
await Response()
|
||||||
.Embed(CreateEmbed()
|
.Embed(CreateEmbed()
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithTitle(GetText(strs.expr_edited))
|
.WithTitle(GetText(strs.expr_edited))
|
||||||
.WithDescription($"#{id}")
|
.WithDescription($"#{id}")
|
||||||
.AddField(GetText(strs.trigger), ex.Trigger)
|
.AddField(GetText(strs.trigger), ex.Trigger)
|
||||||
.AddField(GetText(strs.response),
|
.AddField(GetText(strs.response),
|
||||||
message.Length > 1024 ? GetText(strs.redacted_too_long) : message))
|
message.Length > 1024 ? GetText(strs.redacted_too_long) : message))
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -124,8 +120,8 @@ public partial class EllieExpressions(IBotCreds creds, IHttpClientFactory client
|
||||||
}
|
}
|
||||||
|
|
||||||
var allExpressions = _service.GetExpressionsFor(ctx.Guild?.Id)
|
var allExpressions = _service.GetExpressionsFor(ctx.Guild?.Id)
|
||||||
.OrderBy(x => x.Trigger)
|
.OrderBy(x => x.Trigger)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
if (!allExpressions.Any())
|
if (!allExpressions.Any())
|
||||||
{
|
{
|
||||||
|
@ -134,25 +130,25 @@ public partial class EllieExpressions(IBotCreds creds, IHttpClientFactory client
|
||||||
}
|
}
|
||||||
|
|
||||||
await Response()
|
await Response()
|
||||||
.Paginated()
|
.Paginated()
|
||||||
.Items(allExpressions)
|
.Items(allExpressions)
|
||||||
.PageSize(20)
|
.PageSize(20)
|
||||||
.CurrentPage(page)
|
.CurrentPage(page)
|
||||||
.Page((exprs, _) =>
|
.Page((exprs, _) =>
|
||||||
{
|
{
|
||||||
var desc = exprs
|
var desc = exprs
|
||||||
.Select(ex => $"{(ex.ContainsAnywhere ? "🗯" : "◾")}"
|
.Select(ex => $"{(ex.ContainsAnywhere ? "🗯" : "◾")}"
|
||||||
+ $"{(ex.DmResponse ? "✉" : "◾")}"
|
+ $"{(ex.DmResponse ? "✉" : "◾")}"
|
||||||
+ $"{(ex.AutoDeleteTrigger ? "❌" : "◾")}"
|
+ $"{(ex.AutoDeleteTrigger ? "❌" : "◾")}"
|
||||||
+ $"`{(kwum)ex.Id}` {ex.Trigger}"
|
+ $"`{(kwum)ex.Id}` {ex.Trigger}"
|
||||||
+ (string.IsNullOrWhiteSpace(ex.Reactions)
|
+ (string.IsNullOrWhiteSpace(ex.Reactions)
|
||||||
? string.Empty
|
? string.Empty
|
||||||
: " // " + string.Join(" ", ex.GetReactions())))
|
: " // " + string.Join(" ", ex.GetReactions())))
|
||||||
.Join('\n');
|
.Join('\n');
|
||||||
|
|
||||||
return CreateEmbed().WithOkColor().WithTitle(GetText(strs.expressions)).WithDescription(desc);
|
return CreateEmbed().WithOkColor().WithTitle(GetText(strs.expressions)).WithDescription(desc);
|
||||||
})
|
})
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
|
@ -169,27 +165,27 @@ public partial class EllieExpressions(IBotCreds creds, IHttpClientFactory client
|
||||||
var inter = CreateEditInteraction(id, found);
|
var inter = CreateEditInteraction(id, found);
|
||||||
|
|
||||||
await Response()
|
await Response()
|
||||||
.Interaction(IsValidExprEditor() ? inter : null)
|
.Interaction(IsValidExprEditor() ? inter : null)
|
||||||
.Embed(CreateEmbed()
|
.Embed(CreateEmbed()
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithDescription($"#{id}")
|
.WithDescription($"#{id}")
|
||||||
.AddField(GetText(strs.trigger), found.Trigger.TrimTo(1024))
|
.AddField(GetText(strs.trigger), found.Trigger.TrimTo(1024))
|
||||||
.AddField(GetText(strs.response),
|
.AddField(GetText(strs.response),
|
||||||
found.Response.TrimTo(1000).Replace("](", "]\\(")))
|
found.Response.TrimTo(1000).Replace("](", "]\\(")))
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private EllieInteractionBase CreateEditInteraction(kwum id, EllieExpression found)
|
private EllieInteractionBase CreateEditInteraction(kwum id, EllieExpression found)
|
||||||
{
|
{
|
||||||
var modal = new ModalBuilder()
|
var modal = new ModalBuilder()
|
||||||
.WithCustomId("expr:edit_modal")
|
.WithCustomId("expr:edit_modal")
|
||||||
.WithTitle($"Edit expression {id}")
|
.WithTitle($"Edit expression {id}")
|
||||||
.AddTextInput(new TextInputBuilder()
|
.AddTextInput(new TextInputBuilder()
|
||||||
.WithLabel(GetText(strs.response))
|
.WithLabel(GetText(strs.response))
|
||||||
.WithValue(found.Response)
|
.WithValue(found.Response)
|
||||||
.WithMinLength(1)
|
.WithMinLength(1)
|
||||||
.WithCustomId("expr:edit_modal:response")
|
.WithCustomId("expr:edit_modal:response")
|
||||||
.WithStyle(TextInputStyle.Paragraph));
|
.WithStyle(TextInputStyle.Paragraph));
|
||||||
|
|
||||||
var inter = _inter.Create(ctx.User.Id,
|
var inter = _inter.Create(ctx.User.Id,
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
|
@ -215,13 +211,13 @@ public partial class EllieExpressions(IBotCreds creds, IHttpClientFactory client
|
||||||
if (ex is not null)
|
if (ex is not null)
|
||||||
{
|
{
|
||||||
await Response()
|
await Response()
|
||||||
.Embed(CreateEmbed()
|
.Embed(CreateEmbed()
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithTitle(GetText(strs.expr_deleted))
|
.WithTitle(GetText(strs.expr_deleted))
|
||||||
.WithDescription($"#{id}")
|
.WithDescription($"#{id}")
|
||||||
.AddField(GetText(strs.trigger), ex.Trigger.TrimTo(1024))
|
.AddField(GetText(strs.trigger), ex.Trigger.TrimTo(1024))
|
||||||
.AddField(GetText(strs.response), ex.Response.TrimTo(1024)))
|
.AddField(GetText(strs.response), ex.Response.TrimTo(1024)))
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -287,7 +283,9 @@ public partial class EllieExpressions(IBotCreds creds, IHttpClientFactory client
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { }
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (succ.Count == 0)
|
if (succ.Count == 0)
|
||||||
|
@ -300,9 +298,9 @@ public partial class EllieExpressions(IBotCreds creds, IHttpClientFactory client
|
||||||
|
|
||||||
|
|
||||||
await Response()
|
await Response()
|
||||||
.Confirm(strs.expr_set(Format.Bold(id.ToString()),
|
.Confirm(strs.expr_set(Format.Bold(id.ToString()),
|
||||||
succ.Select(static x => x.ToString()).Join(", ")))
|
succ.Select(static x => x.ToString()).Join(", ")))
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
|
@ -348,16 +346,16 @@ public partial class EllieExpressions(IBotCreds creds, IHttpClientFactory client
|
||||||
if (newVal)
|
if (newVal)
|
||||||
{
|
{
|
||||||
await Response()
|
await Response()
|
||||||
.Confirm(strs.option_enabled(Format.Code(option.ToString()),
|
.Confirm(strs.option_enabled(Format.Code(option.ToString()),
|
||||||
Format.Code(id.ToString())))
|
Format.Code(id.ToString())))
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await Response()
|
await Response()
|
||||||
.Confirm(strs.option_disabled(Format.Code(option.ToString()),
|
.Confirm(strs.option_disabled(Format.Code(option.ToString()),
|
||||||
Format.Code(id.ToString())))
|
Format.Code(id.ToString())))
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,8 +365,8 @@ public partial class EllieExpressions(IBotCreds creds, IHttpClientFactory client
|
||||||
public async Task ExprClear()
|
public async Task ExprClear()
|
||||||
{
|
{
|
||||||
if (await PromptUserConfirmAsync(CreateEmbed()
|
if (await PromptUserConfirmAsync(CreateEmbed()
|
||||||
.WithTitle("Expression clear")
|
.WithTitle("Expression clear")
|
||||||
.WithDescription("This will delete all expressions on this server.")))
|
.WithDescription("This will delete all expressions on this server.")))
|
||||||
{
|
{
|
||||||
var count = _service.DeleteAllExpressions(ctx.Guild.Id);
|
var count = _service.DeleteAllExpressions(ctx.Guild.Id);
|
||||||
await Response().Confirm(strs.exprs_cleared(count)).SendAsync();
|
await Response().Confirm(strs.exprs_cleared(count)).SendAsync();
|
||||||
|
@ -388,7 +386,8 @@ public partial class EllieExpressions(IBotCreds creds, IHttpClientFactory client
|
||||||
|
|
||||||
var serialized = _service.ExportExpressions(ctx.Guild?.Id);
|
var serialized = _service.ExportExpressions(ctx.Guild?.Id);
|
||||||
await using var stream = await serialized.ToStream();
|
await using var stream = await serialized.ToStream();
|
||||||
await ctx.User.SendFileAsync(stream, $"exprs-export_{DateTime.UtcNow:yyyy-MM-dd-HH-mm-ss}_{(ctx.Guild?.Id.ToString() ?? "global")}.yml");
|
await ctx.User.SendFileAsync(stream,
|
||||||
|
$"exprs-export_{DateTime.UtcNow:yyyy-MM-dd-HH-mm-ss}_{(ctx.Guild?.Id.ToString() ?? "global")}.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue