public void TestVariable() { // Test field property var @var = new TestVariables(); @var.SetValue(10); Assert.That(TestVariables.VALUE, Is.EqualTo(10)); }
public async Task EvalCS(CommandContext ctx, [RemainingText] string code) { DiscordMessage msg = ctx.Message; int cs1 = code.IndexOf("```") + 3; cs1 = code.IndexOf('\n', cs1) + 1; int cs2 = code.LastIndexOf("```"); if (cs1 is - 1 || cs2 is - 1) { throw new ArgumentException("You need to wrap the code into a code block."); } string cs = code.Substring(cs1, cs2 - cs1); msg = await ctx.RespondAsync("", embed : new DiscordEmbedBuilder() .WithColor(new DiscordColor("#FF007F")) .WithDescription("Evaluating...") .Build()) .ConfigureAwait(false); try { var globals = new TestVariables(ctx.Message, ctx.Client, ctx); var sopts = ScriptOptions.Default; sopts = sopts.WithImports("System", "System.Collections.Generic", "System.Linq", "System.Text", "System.Threading.Tasks", "DSharpPlus", "DSharpPlus.Entities", "Silk.Core", "Silk.Extensions", "DSharpPlus.CommandsNext", "DSharpPlus.Interactivity", "Microsoft.Extensions.Logging"); sopts = sopts.WithReferences(AppDomain.CurrentDomain.GetAssemblies() .Where(xa => !xa.IsDynamic && !string.IsNullOrWhiteSpace(xa.Location))); Script <object> script = CSharpScript.Create(cs, sopts, typeof(TestVariables)); script.Compile(); ScriptState <object> result = await script.RunAsync(globals).ConfigureAwait(false); if (result?.ReturnValue is not null && !string.IsNullOrWhiteSpace(result.ReturnValue.ToString())) { await msg.ModifyAsync(embed : new DiscordEmbedBuilder { Title = "Evaluation Result", Description = result.ReturnValue.ToString(), Color = new DiscordColor("#007FFF") }.Build()) .ConfigureAwait(false); } else { await msg.ModifyAsync(embed : new DiscordEmbedBuilder { Title = "Evaluation Successful", Description = "No result was returned.", Color = new DiscordColor("#007FFF") }.Build()) .ConfigureAwait(false); } }
public async Task EvalCS(CommandContext ctx, [RemainingText] string code) { if (!Bot.BotOwnerIds.Contains(ctx.User.Id)) { return; } var msg = ctx.Message; var cs1 = code.IndexOf("```") + 3; cs1 = code.IndexOf('\n', cs1) + 1; var cs2 = code.LastIndexOf("```"); if (cs1 == -1 || cs2 == -1) { throw new ArgumentException("You need to wrap the code into a code block."); } var cs = code.Substring(cs1, cs2 - cs1); msg = await ctx.RespondAsync("", embed : new DiscordEmbedBuilder() .WithColor(new DiscordColor("#FF007F")) .WithDescription("Evaluating...") .Build()).ConfigureAwait(false); try { var globals = new TestVariables(ctx.Message, ctx.Client, ctx); var sopts = ScriptOptions.Default; sopts = sopts.WithImports("System", "System.Collections.Generic", "System.Linq", "System.Text", "System.Threading.Tasks", "DSharpPlus", "DSharpPlus.CommandsNext", "DSharpPlus.Interactivity"); sopts = sopts.WithReferences(AppDomain.CurrentDomain.GetAssemblies().Where(xa => !xa.IsDynamic && !string.IsNullOrWhiteSpace(xa.Location))); var script = CSharpScript.Create(cs, sopts, typeof(TestVariables)); script.Compile(); var result = await script.RunAsync(globals).ConfigureAwait(false); if (result != null && result.ReturnValue != null && !string.IsNullOrWhiteSpace(result.ReturnValue.ToString())) { await msg.ModifyAsync(embed : new DiscordEmbedBuilder { Title = "Evaluation Result", Description = result.ReturnValue.ToString(), Color = new DiscordColor("#007FFF") }.Build()).ConfigureAwait(false); } else { await msg.ModifyAsync(embed : new DiscordEmbedBuilder { Title = "Evaluation Successful", Description = "No result was returned.", Color = new DiscordColor("#007FFF") }.Build()).ConfigureAwait(false); } } catch (Exception ex) { await msg.ModifyAsync(embed : new DiscordEmbedBuilder { Title = "Evaluation Failure", Description = string.Concat("**", ex.GetType().ToString(), "**: ", ex.Message), Color = new DiscordColor("#FF0000") }.Build()).ConfigureAwait(false); } }
public void TestVariable() { // Test field property var @var = new TestVariables(); @var.Value = 10; Assert.That(TestVariables.VALUE, Is.EqualTo(10)); }