public static void Main(string[] args) { var stdin = new TTY(0); stdin.Read(Encoding.ASCII, (str) => { str = str.TrimEnd(new char[] { '\r', '\n' }); if (str.StartsWith("fib ")) { int n; if (!int.TryParse(str.Substring("fib ".Length), out n)) { Console.WriteLine("Supply an integer to the fib command"); return; } TimeSpan span = TimeSpan.Zero; BigInteger res = 0; Console.WriteLine("{0}: fib({1}) starting", span, n); Loop.Default.QueueUserWorkItem(() => { var stopwatch = Stopwatch.StartNew(); res = Fibonacci(n); stopwatch.Stop(); span = stopwatch.Elapsed; }, () => { Console.WriteLine("{0}: fib({1}) = {2}", span, n, res); }); } else if (str == "quit") { Loop.Default.Stop(); stdin.Close(); } else if (str == "help") { Console.WriteLine("Available commands: "); Console.WriteLine("fib <n:int> - start a thread which calculates fib"); Console.WriteLine("help - displays help"); Console.WriteLine("quit - quits the program"); } else { Console.WriteLine("Unknown command"); } }); stdin.Resume(); Loop.Default.Run(); }
public static void Main(string[] args) { var client = new UVIrcClient(); var bot = new IrcBot <UVIrcClient>(client); bot.Client.Connect("127.0.0.1", new IrcUserRegistrationInfo() { NickName = "txdv-bot", UserName = "******", RealName = "txdv bot", }); var adminPlugin = new AdminPlugin <UVIrcClient>("bentkus"); bot.Plugin(adminPlugin); bot.Plugin(new Greeter <UVIrcClient>()); bot.Plugin(new DatabasePlugin <UVIrcClient>(adminPlugin)); bot.Plugin(new JoinPlugin <UVIrcClient>(adminPlugin)); UVTimer.Once(TimeSpan.FromSeconds(1), () => client.Channels.Join("#help")); var stdin = new TTY(0); stdin.Read(Encoding.Default, (line) => { line = line.Trim(); switch (line) { case "quit": Loop.Default.Stop(); break; default: break; } }); stdin.Resume(); Loop.Default.Run(); }