public Guid AddPlugin(JavascriptPlugin plugin) { Guid id = Guid.NewGuid(); plugins.Add(id, plugin); return(id); }
static void Main(string[] args) { int RoomId = 2064239; Directory.CreateDirectory("plugins"); var files = Directory.GetFiles("plugins", "*.plugin.js"); Log("DMKEngine " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + " by Developer_ken"); Log("Loading plugins..."); foreach (string f in files) { try { string loadPath = Path.GetFullPath(f); string fname = Path.GetFileNameWithoutExtension(loadPath); Log("Loading \"" + fname + "\"..."); var js = new JavascriptPlugin(File.ReadAllText(loadPath)); pman.AddPlugin(js); Log("<" + js.Name + "> " + js.Version + " by " + js.Author); } catch (Exception e) { Log("Fail to load plugin " + f, (int)ConsoleColor.Red); Log(e.Message, (int)ConsoleColor.Yellow); Log(e.StackTrace, (int)ConsoleColor.Yellow); } } Log("Initializing engine... "); sm = new StreamMonitor(RoomId, new Func <TcpClient>(() => { return(new TcpClient()); })); sm.Start(); sm.ReceivedDanmaku += Sm_ReceivedDanmaku; pman.TriggerLoad(); JavascriptPlugin interactive = new JavascriptPlugin("" + "plugin.Name='Interactive Console';" + "plugin.Version='0000';" + "plugin.Author='Developer_ken';" + "plugin.NeedLogin=false;"); pman.AddPlugin(interactive); while (true) { try { var result = interactive.RunCode(Console.ReadLine()); Log(result); } catch (Exception e) { Log("Fail to execute:" + e.Message, (int)ConsoleColor.Red); } } }