You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Program.cs 2.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Threading.Tasks;
  7. using Microsoft.CodeAnalysis.CSharp.Scripting;
  8. using Microsoft.CodeAnalysis.Scripting;
  9. using Discord;
  10. namespace idn
  11. {
  12. public class Program
  13. {
  14. public static readonly string[] Imports =
  15. {
  16. "System",
  17. "System.Collections.Generic",
  18. "System.Linq",
  19. "System.Threading.Tasks",
  20. "System.Diagnostics",
  21. "System.IO",
  22. "Discord",
  23. "Discord.Rest",
  24. "Discord.Socket",
  25. "idn"
  26. };
  27. static async Task Main(string[] args)
  28. {
  29. var token = File.ReadAllText("token.ignore");
  30. var client = IDiscordClient.Create(token);
  31. // client.start
  32. var options = ScriptOptions.Default
  33. .AddReferences(GetAssemblies().ToArray())
  34. .AddImports(Imports);
  35. var globals = new ScriptGlobals
  36. {
  37. Client = client,
  38. };
  39. while (true)
  40. {
  41. Console.Write("> ");
  42. string input = Console.ReadLine();
  43. if (input == "quit")
  44. {
  45. break;
  46. }
  47. object eval;
  48. try
  49. {
  50. eval = await CSharpScript.EvaluateAsync(input, options, globals);
  51. }
  52. catch (Exception e)
  53. {
  54. eval = e;
  55. }
  56. Console.WriteLine(Inspector.Inspect(eval));
  57. }
  58. // client.Stop
  59. client.Dispose();
  60. }
  61. static IEnumerable<Assembly> GetAssemblies()
  62. {
  63. var Assemblies = Assembly.GetEntryAssembly().GetReferencedAssemblies();
  64. foreach (var a in Assemblies)
  65. {
  66. var asm = Assembly.Load(a);
  67. yield return asm;
  68. }
  69. yield return Assembly.GetEntryAssembly();
  70. }
  71. public class ScriptGlobals
  72. {
  73. public IDiscordClient Client { get; set; }
  74. }
  75. }
  76. }