.cmds <module name> looks better

This commit is contained in:
Kwoth
2024-04-24 23:34:30 +00:00
parent a04a427af2
commit 006fa1a9fe
5 changed files with 184 additions and 197 deletions

View File

@@ -16,7 +16,12 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
- `.ga list` lists active giveaways on the current server - `.ga list` lists active giveaways on the current server
- `.ga reroll <id>` rerolls the winner on the completed giveaway. This only works for 24 hours after the giveaway has ended, or until the bot restarts. - `.ga reroll <id>` rerolls the winner on the completed giveaway. This only works for 24 hours after the giveaway has ended, or until the bot restarts.
- After the giveaway has started, user join the giveaway by adding a :tada: reaction - After the giveaway has started, user join the giveaway by adding a :tada: reaction
### Changed
- Users who have manage messages perm in the channel will now be excluded from link and invite filtering (`.sfi` and `.sfl`)
- You can now target a different channel with .repeat, for example `.repeat #some-other 1h Hello every hour` - You can now target a different channel with .repeat, for example `.repeat #some-other 1h Hello every hour`
- `.cmds <module name>` looks better / simpler
## [4.3.22] - 23.04.2023 ## [4.3.22] - 23.04.2023

View File

@@ -279,25 +279,17 @@ public sealed class Help : NadekoModule<HelpService>
if (opts.View == CommandsOptions.ViewType.Cross) if (opts.View == CommandsOptions.ViewType.Cross)
{ {
return return
$"{(succ.Contains(x) ? "" : "")}{prefix + x.Aliases.First(),-15} {"[" + x.Aliases.Skip(1).FirstOrDefault() + "]",-8}"; $"{(succ.Contains(x) ? "" : "")} {prefix + x.Aliases[0]}";
} }
return if (x.Aliases.Count == 1)
$"{prefix + x.Aliases.First(),-15} {"[" + x.Aliases.Skip(1).FirstOrDefault() + "]",-8}"; return prefix + x.Aliases[0];
return prefix + x.Aliases[0] + " / " + prefix + x.Aliases[1];
}); });
if (i == last - 1 && (i + 1) % 2 != 0) embed.AddField(g.ElementAt(i).Key, "" + string.Join("\n", transformed) + "", true);
{
transformed = transformed.Chunk(2)
.Select(x =>
{
if (x.Count() == 1)
return $"{x.First()}";
return string.Concat(x);
});
}
embed.AddField(g.ElementAt(i).Key, "```css\n" + string.Join("\n", transformed) + "\n```", true);
} }
} }

View File

@@ -5,6 +5,8 @@ using System.Diagnostics;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;
using NadekoBot.Modules.Searches.Common; using NadekoBot.Modules.Searches.Common;
namespace NadekoBot.Modules.Utility; namespace NadekoBot.Modules.Utility;
@@ -17,7 +19,11 @@ public partial class Utility : NadekoModule
New New
} }
public enum MeOrBot { Me, Bot } public enum MeOrBot
{
Me,
Bot
}
private static readonly JsonSerializerOptions _showEmbedSerializerOptions = new() private static readonly JsonSerializerOptions _showEmbedSerializerOptions = new()
{ {
@@ -34,6 +40,7 @@ public partial class Utility : NadekoModule
private readonly DownloadTracker _tracker; private readonly DownloadTracker _tracker;
private readonly IHttpClientFactory _httpFactory; private readonly IHttpClientFactory _httpFactory;
private readonly VerboseErrorsService _veService; private readonly VerboseErrorsService _veService;
private readonly IServiceProvider _services;
public Utility( public Utility(
DiscordSocketClient client, DiscordSocketClient client,
@@ -42,7 +49,8 @@ public partial class Utility : NadekoModule
IBotCredentials creds, IBotCredentials creds,
DownloadTracker tracker, DownloadTracker tracker,
IHttpClientFactory httpFactory, IHttpClientFactory httpFactory,
VerboseErrorsService veService) VerboseErrorsService veService,
IServiceProvider services)
{ {
_client = client; _client = client;
_coord = coord; _coord = coord;
@@ -51,6 +59,7 @@ public partial class Utility : NadekoModule
_tracker = tracker; _tracker = tracker;
_httpFactory = httpFactory; _httpFactory = httpFactory;
_veService = veService; _veService = veService;
_services = services;
} }
[Cmd] [Cmd]
@@ -495,7 +504,7 @@ public partial class Utility : NadekoModule
case StickerFormatType.Lottie: case StickerFormatType.Lottie:
return "lottie"; return "lottie";
default: default:
throw new ArgumentException(nameof (format)); throw new ArgumentException(nameof(format));
} }
} }
@@ -639,4 +648,61 @@ public partial class Utility : NadekoModule
else else
await ReplyConfirmLocalizedAsync(strs.verbose_errors_disabled); await ReplyConfirmLocalizedAsync(strs.verbose_errors_disabled);
} }
[Cmd]
[NoPublicBot]
[OwnerOnly]
public async Task Eval([Leftover] string scriptText)
{
_ = ctx.Channel.TriggerTypingAsync();
if (scriptText.StartsWith("```cs"))
scriptText = scriptText[5..];
else if (scriptText.StartsWith("```"))
scriptText = scriptText[3..];
if (scriptText.EndsWith("```"))
scriptText = scriptText[..^3];
var script = CSharpScript.Create(scriptText,
ScriptOptions.Default
.WithReferences(this.GetType().Assembly)
.WithImports(
"System",
"NadekoBot",
"NadekoBot.Extensions",
"Microsoft.Extensions.DependencyInjection",
"NadekoBot.Common",
"System.Text",
"System.Text.Json"),
globalsType: typeof(EvalGlobals));
try
{
var result = await script.RunAsync(new EvalGlobals()
{
ctx = this.ctx,
guild = this.ctx.Guild,
channel = this.ctx.Channel,
user = this.ctx.User,
self = this,
services = _services
});
var output = result.ReturnValue?.ToString();
if (!string.IsNullOrWhiteSpace(output))
{
var eb = _eb.Create(ctx)
.WithOkColor()
.AddField("Code", scriptText)
.AddField("Output", output.TrimTo(512)!);
_ = ctx.Channel.EmbedAsync(eb);
}
}
catch (Exception ex)
{
await SendErrorAsync(ex.Message);
}
}
} }

View File

@@ -1,76 +0,0 @@
#nullable disable
using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;
namespace NadekoBot.Modules.Utility;
public partial class Utility
{
[Group]
public partial class EvalCommands : NadekoModule
{
private readonly IServiceProvider _services;
public EvalCommands(IServiceProvider services)
{
_services = services;
}
[Cmd]
[NoPublicBot]
[OwnerOnly]
public async Task Eval([Leftover] string scriptText)
{
_ = ctx.Channel.TriggerTypingAsync();
if (scriptText.StartsWith("```cs"))
scriptText = scriptText[5..];
else if (scriptText.StartsWith("```"))
scriptText = scriptText[3..];
if (scriptText.EndsWith("```"))
scriptText = scriptText[..^3];
var script = CSharpScript.Create(scriptText,
ScriptOptions.Default
.WithReferences(this.GetType().Assembly)
.WithImports(
"System",
"NadekoBot",
"NadekoBot.Extensions",
"Microsoft.Extensions.DependencyInjection",
"NadekoBot.Common",
"System.Text",
"System.Text.Json"),
globalsType: typeof(EvalGlobals));
try
{
var result = await script.RunAsync(new EvalGlobals()
{
ctx = this.ctx,
guild = this.ctx.Guild,
channel = this.ctx.Channel,
user = this.ctx.User,
self = this,
services = _services
});
var output = result.ReturnValue?.ToString();
if (!string.IsNullOrWhiteSpace(output))
{
var eb = _eb.Create(ctx)
.WithOkColor()
.AddField("Code", scriptText)
.AddField("Output", output.TrimTo(512)!);
_ = ctx.Channel.EmbedAsync(eb);
}
}
catch (Exception ex)
{
await SendErrorAsync(ex.Message);
}
}
}
}

View File

@@ -5,7 +5,7 @@ namespace NadekoBot.Modules.Utility;
public class EvalGlobals public class EvalGlobals
{ {
public ICommandContext ctx; public ICommandContext ctx;
public Utility.EvalCommands self; public Utility self;
public IUser user; public IUser user;
public IMessageChannel channel; public IMessageChannel channel;
public IGuild guild; public IGuild guild;