mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-11-02 15:54:27 -05:00
.cmds <module name> looks better
This commit is contained in:
@@ -16,7 +16,12 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
|
||||
- `.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.
|
||||
- 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`
|
||||
- `.cmds <module name>` looks better / simpler
|
||||
|
||||
## [4.3.22] - 23.04.2023
|
||||
|
||||
|
||||
@@ -279,25 +279,17 @@ public sealed class Help : NadekoModule<HelpService>
|
||||
if (opts.View == CommandsOptions.ViewType.Cross)
|
||||
{
|
||||
return
|
||||
$"{(succ.Contains(x) ? "✅" : "❌")}{prefix + x.Aliases.First(),-15} {"[" + x.Aliases.Skip(1).FirstOrDefault() + "]",-8}";
|
||||
$"{(succ.Contains(x) ? "✅" : "❌")} {prefix + x.Aliases[0]}";
|
||||
}
|
||||
|
||||
return
|
||||
$"{prefix + x.Aliases.First(),-15} {"[" + x.Aliases.Skip(1).FirstOrDefault() + "]",-8}";
|
||||
if (x.Aliases.Count == 1)
|
||||
return prefix + x.Aliases[0];
|
||||
|
||||
return prefix + x.Aliases[0] + " / " + prefix + x.Aliases[1];
|
||||
|
||||
});
|
||||
|
||||
if (i == last - 1 && (i + 1) % 2 != 0)
|
||||
{
|
||||
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);
|
||||
embed.AddField(g.ElementAt(i).Key, "" + string.Join("\n", transformed) + "", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.CodeAnalysis.CSharp.Scripting;
|
||||
using Microsoft.CodeAnalysis.Scripting;
|
||||
using NadekoBot.Modules.Searches.Common;
|
||||
|
||||
namespace NadekoBot.Modules.Utility;
|
||||
@@ -17,7 +19,11 @@ public partial class Utility : NadekoModule
|
||||
New
|
||||
}
|
||||
|
||||
public enum MeOrBot { Me, Bot }
|
||||
public enum MeOrBot
|
||||
{
|
||||
Me,
|
||||
Bot
|
||||
}
|
||||
|
||||
private static readonly JsonSerializerOptions _showEmbedSerializerOptions = new()
|
||||
{
|
||||
@@ -34,6 +40,7 @@ public partial class Utility : NadekoModule
|
||||
private readonly DownloadTracker _tracker;
|
||||
private readonly IHttpClientFactory _httpFactory;
|
||||
private readonly VerboseErrorsService _veService;
|
||||
private readonly IServiceProvider _services;
|
||||
|
||||
public Utility(
|
||||
DiscordSocketClient client,
|
||||
@@ -42,7 +49,8 @@ public partial class Utility : NadekoModule
|
||||
IBotCredentials creds,
|
||||
DownloadTracker tracker,
|
||||
IHttpClientFactory httpFactory,
|
||||
VerboseErrorsService veService)
|
||||
VerboseErrorsService veService,
|
||||
IServiceProvider services)
|
||||
{
|
||||
_client = client;
|
||||
_coord = coord;
|
||||
@@ -51,6 +59,7 @@ public partial class Utility : NadekoModule
|
||||
_tracker = tracker;
|
||||
_httpFactory = httpFactory;
|
||||
_veService = veService;
|
||||
_services = services;
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -639,4 +648,61 @@ public partial class Utility : NadekoModule
|
||||
else
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace NadekoBot.Modules.Utility;
|
||||
public class EvalGlobals
|
||||
{
|
||||
public ICommandContext ctx;
|
||||
public Utility.EvalCommands self;
|
||||
public Utility self;
|
||||
public IUser user;
|
||||
public IMessageChannel channel;
|
||||
public IGuild guild;
|
||||
Reference in New Issue
Block a user