public void Start(IEnumerable <IIrcBot> bot) { using (var irc = new IrcClient(_server, _port)) { irc.Connect(_credentials); var cancelWriteSource = new CancellationTokenSource(); Task.Run(async() => { while (!cancelWriteSource.IsCancellationRequested) { var chatMessage = irc.ReadLine(); if (chatMessage.Contains("001")) { irc.Join(_credentials.Channel); } Console.Write(">> "); Console.WriteLine(chatMessage); var ircMessage = new IrcMessage(chatMessage); if (!ircMessage.IsSuccess) { continue; } var botMessage = await bot.ProceedAsync(ircMessage); if (!string.IsNullOrEmpty(botMessage)) { irc.SendMultiLineMessage(botMessage, ircMessage.IsChannelMessage() ? ircMessage.Receiver : ircMessage.Sender); } } }, cancelWriteSource.Token); while (true) { var message = Console.ReadLine(); if (message == "-q") { break; } irc.Send(message); } cancelWriteSource.Cancel(); Thread.Sleep(10); } }
static void Main(string[] args) { // load plugins foreach (string f in Directory.EnumerateFiles(Settings.Default.PluginPath, "IrcBot.*.dll", SearchOption.AllDirectories)) { Debug.WriteLine("Attempting to load " + f, "PluginLoading"); RecursiveAssemblyLoader r = new RecursiveAssemblyLoader(); // to load plugin deps Assembly file = r.GetAssembly(Path.GetFullPath(f)); try { // get types foreach (Type t in file.GetTypes()) { // see if they're a valid plugin if (t.GetInterface("IPlugin").IsEquivalentTo(typeof(IPlugin))) { // ok, i guess so - did we load it already? if (plugins.Contains(t)) { continue; } // add plugin plugins.Add(t); } } Debug.WriteLine("Loaded " + file, "PluginLoading"); } catch (InvalidCastException e) { Debug.WriteLine(e.ToString(), "PluginLoading"); } catch (ReflectionTypeLoadException e) { Debug.WriteLine(e.ToString(), "PluginLoading"); } catch (NullReferenceException e) { Debug.WriteLine(e.ToString(), "PluginLoading"); } } // assign events i.OnChannelMessage += i_OnChannelMessage; i.OnQueryMessage += i_OnQueryMessage; i.OnJoin += i_OnJoin; i.OnQuit += i_OnQuit; i.OnKick += i_OnKick; i.OnPart += i_OnPart; // init i.ActiveChannelSyncing = true; i.UseSsl = Settings.Default.SSL; i.Connect(Settings.Default.Servers.Cast <string>().ToArray(), Settings.Default.Port); i.Login(Settings.Default.Nickname, Settings.Default.RealName); i.RfcJoin(Settings.Default.Channels.Cast <string>().ToArray()); i.Listen(); }