public static void command(string[] args, string Channel, string Nick, IrcClient irc) { if (args.Length != 2) { irc.SendMessage(SendType.Message, Channel, String.Format("({0}) Usage: " + Program.GlobalVar.bot_comm_char + "join #<channel>", Nick)); } else { //make sure entry is a valid channel if (args[1].StartsWith("#")) { //see if the channel already exists bool chanCheck = false; MySqlCommand command = Program.GlobalVar.conn.CreateCommand(); command.CommandText = "SELECT Channel FROM channels where Channel='" + args[1].ToLower() + "'"; try { Program.GlobalVar.conn.Open(); } catch (Exception e) { Console.WriteLine(e.Message); } MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { if (reader["Channel"].ToString() == args[1].ToLower()) { chanCheck = true; } } Program.GlobalVar.conn.Close(); if (chanCheck == true) { irc.SendMessage(SendType.Message, Channel, String.Format("I am already in {0} sir", args[1])); } //channel is not in the database so add it else { command.CommandText = "INSERT into channels (Channel,ChanOP,SuperUsers,Quiet,secret) values('" + args[1].ToLower() + "','" + Nick + "','','0','0')"; Program.GlobalVar.conn.Open(); command.ExecuteNonQuery(); Program.GlobalVar.conn.Close(); //Console message/info here irc.SendMessage(SendType.Notice, Nick, String.Format("I am now joining {0} sir", args[1])); irc.RfcJoin(args[1]); } } else { irc.SendMessage(SendType.Message, Channel, String.Format("Please input a valid channel name sir")); } } }
private static void Run() { while( !stopRequested ) { try { irc = new IrcClient(); irc.Encoding = System.Text.Encoding.UTF8; irc.SendDelay = 200; irc.ActiveChannelSyncing = true; irc.OnRawMessage += new IrcEventHandler( irc_OnRawMessage ); irc.Connect( settings.IrcHost, settings.IrcPort ); irc.Login( NICK, NICK, 0, NICK, settings.IrcPassword ); irc.RfcJoin( settings.IrcChannelName ); irc.Listen(); if( irc.IsConnected ) { irc.Disconnect(); } } catch( Exception e ) { Console.WriteLine( e.Message ); } if( !stopRequested ) { Thread.Sleep( TimeSpan.FromSeconds( 10 ) ); } } }
public override void Loop() { while (true) { _client = new IrcClient { AutoJoinOnInvite = true, AutoReconnect = true, AutoRejoin = true, AutoRejoinOnKick = true, AutoRelogin = true, AutoRetry = true }; var mre = new ManualResetEvent(false); _client.OnJoin += (sender, args) => Output("I have joined " + args.Channel); _client.OnChannelMessage += (sender, args) => Handle(args.Data.Message); _client.OnConnected += (sender, args) => { mre.Set(); _client.RfcJoin("#jarvis"); }; _client.Connect("irc.clossit.com", 6668); _client.Login("Jarvis", "Jarvis"); new Thread(() => _client.Listen()).Start(); mre.WaitOne(30.Seconds()); while (_client.IsConnected) { 5.Seconds().Sleep(); } Output("I have lost connection to I.R.C"); } }
public override void Initialize() { if (Init) return; try { _irc = new IrcClient(); _irc.OnRawMessage += OnRawMessage; // Chat.Battleground += ChatSpec; Chat.BattlegroundLeader += ChatSpec; Chat.Guild += Chat_Guild; Chat.Officer += ChatSpec; Chat.Raid += ChatSpec; Chat.Channel += ChatSpec; Chat.Party += ChatSpec; Chat.PartyLeader += ChatSpec; Chat.Say += ChatSpec; Chat.Yell += ChatSpec; Chat.Whisper += Chat_Whisper; Chat.WhisperTo += ChatSpec; // Logging.OnLogMessage += Logging_OnLogMessage; // Lua.Events.AttachEvent("CHAT_MSG_LOOT", LootChatMonitor); Lua.Events.AttachEvent("ACHIEVEMENT_EARNED", AchievementMonitor); Lua.Events.AttachEvent("CHAT_MSG_BN_WHISPER", BnChatMonitor); Lua.Events.AttachEvent("CHAT_MSG_BN_CONVERSATION", BnChatMonitor); Lua.Events.AttachEvent("BN_FRIEND_ACCOUNT_ONLINE", BnFriendsOn); Lua.Events.AttachEvent("BN_FRIEND_ACCOUNT_OFFLINE", BnFriendsOff); Lua.Events.AttachEvent("CHAT_MSG_BN_WHISPER_INFORM", BnInform); // BotEvents.OnBotStopped += BotEvents_OnBotStopped; BotEvents.OnBotStarted += BotEvents_OnBotStarted; BotEvents.OnBotChanged += BotEvents_OnBotChanged; BotEvents.Player.OnLevelUp += Player_OnLevelUp; BotEvents.Player.OnPlayerDied += Player_OnPlayerDied; BotEvents.Player.OnMobKilled += Player_OnMobKilled; // _irc.Connect(ConfigValues.Instance.IrcAddress, ConfigValues.Instance.IrcPort); _irc.Login(ConfigValues.Instance.IrcUsername, ConfigValues.Instance.IrcUsername[0]); _irc.RfcJoin(ConfigValues.Instance.IrcChannel); _listener = new Thread(Listen) {IsBackground = true}; _listener.Start(); } catch (Exception ex) { Logging.WriteException(ex); Init = false; return; } finally { Logging.Write("GeekyIrc version: {0} started.",Version); } Init = true; }
public IdentityChannel(IrcClient client, dynamic channel) { client.RfcJoin(channel); }
/// <summary> /// just testing the IRC chat connection stability... /// </summary> private static void TestConnectionStability() { while (true) { try { irc_test = new IrcClient(); irc_test.AutoRetry = true; irc_test.AutoReconnect = true; irc_test.OnChannelMessage += new IrcEventHandler(irc_test_OnChannelMessage); irc_test.OnRawMessage += new IrcEventHandler(irc_test_OnRawMessage); // here we try to connect to the server and exceptions get handled irc_test.Connect(serverlist, port); } catch (ConnectionException e) { // something went wrong, the reason will be shown logger.Trace("couldn't connect! Reason: " + e.Message); //Exit(); } try { // here we logon and register our nickname and so on irc_test.Login(nick, real); // join the channel irc_test.RfcJoin(channel); // here we tell the IRC API to go into a receive mode, all events // will be triggered by _this_ thread (main thread in this case) // Listen() blocks by default, you can also use ListenOnce() if you // need that does one IRC operation and then returns, so you need then // an own loop irc_test.Listen(); // when Listen() returns our IRC session is over, to be sure we call // disconnect manually irc_test.Disconnect(); } catch (ConnectionException e) { // this exception is handled becaused Disconnect() can throw a not // connected exception logger.Trace("Connection exception: " + e.Message); //Exit(); } catch (Exception e) { // this should not happen by just in case we handle it nicely logger.Trace("Error occurred! Message: " + e.Message); logger.Trace("Exception: " + e.StackTrace); //Exit(); } logger.Trace("Going to sleep"); System.Threading.Thread.Sleep(5*60000); logger.Trace("==========================================="); } }
public static void Main(string[] args) { //this method is just for some tests //TestConnectionStability(); //return; int cycle_cnt = 0; while (true) { cycle_cnt++; //Console.Clear(); Console.WriteLine("Cycle: " + cycle_cnt); Thread.CurrentThread.Name = "Main"; #region Settings string startupPath = Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); if (File.Exists(startupPath + "\\settings.ini")) profile = new Ini(startupPath + "\\settings.ini"); else { logger.Trace("Did not find" + startupPath); } channel = (string)profile.GetValue("Main", "Channel"); nick = (string)profile.GetValue("Main", "Nick"); real = (string)profile.GetValue("Main", "Real"); #endregion #region IRC Setup irc = new IrcClient(); irc.SendDelay = 500; irc.ActiveChannelSyncing = true; irc.OnChannelMessage += new IrcEventHandler(OnChannelMessage); irc.OnQueryMessage += new IrcEventHandler(OnQueryMessage); irc.OnBan += new BanEventHandler(OnBanMessage); irc.OnError += new Meebey.SmartIrc4net.ErrorEventHandler(OnError); irc.OnPart += new PartEventHandler(irc_OnPart); irc.OnRawMessage += new IrcEventHandler(OnRawMessage); if (proactiveMode) { timer = new System.Timers.Timer(); timer.Elapsed += new System.Timers.ElapsedEventHandler(autoAnswering); } #endregion sl = new SortedList(); Console.WriteLine("**********************************************************"); Console.WriteLine("These are my settings: "); Console.WriteLine("Trying to connect to " + serverlist[0] + " on port " + port + " - joining channel: " + channel); Console.WriteLine("My nickname is: " + nick + " and my real name is: " + real); Console.WriteLine("**********************************************************"); try { irc.AutoRetry = true; irc.AutoReconnect = true; irc.Connect(serverlist, port); } catch (ConnectionException e) { logger.Trace("couldn't connect! Reason: " + e.Message); } try { // here we logon and register our nickname and so on irc.OnRawMessage += new IrcEventHandler(irc_OnRawMessage); irc.Login(nick, real); //load all channels irc.RfcList(""); Dictionary<string, int> chann = new Dictionary<string, int>(); // join the channel irc.RfcJoin(channel); irc.OnChannelAction += new ActionEventHandler(irc_OnChannelAction); #region Prelude Setup //initialize interface logger.Trace("Loading Prelude..."); pi = new PreLudeInterface(); //define path to mind file pi.loadedMind = "mind.mdu"; pi.avoidLearnByRepeating = true; pi.initializedAssociater = Mind.MatchingAlgorithm.Dice; //start your engine ... pi.initializeEngine(); logger.Trace("Prelude loaded and initialized..."); #endregion // spawn a new thread to read the stdin of the console, this we use // for reading IRC commands from the keyboard while the IRC connection // stays in its own thread new Thread(new ThreadStart(ReadCommands)).Start(); irc.Listen(); // when Listen() returns our IRC session is over, to be sure we call // disconnect manually irc.Disconnect(); } catch (ConnectionException) { logger.Trace("Connection exception"); pi.stopPreludeEngine(); } catch (Exception e) { logger.Trace("Error occurred! Message: " + e.Message); logger.Trace("Exception: " + e.StackTrace); pi.stopPreludeEngine(); } logger.Trace("Going to sleep"); System.Threading.Thread.Sleep(5 * 60000); logger.Trace("==========================================="); } }
/// <summary> /// Creates and sets up an IrcClient instance and connects to a server according to "server" /// </summary> public void Connect(ServerDescriptor server) { if (server == null) throw new ArgumentNullException("server"); IrcClient irc = new IrcClient(); // Settings irc.AutoReconnect = true; irc.Encoding = System.Text.Encoding.UTF8; irc.SendDelay = config.GetInt("send-delay", 200); irc.ActiveChannelSyncing = config.GetBoolean("use-active-channel-syncing", false); irc.UseSsl = server.UseSsl; // Bind event handlers irc.OnChannelMessage += OnChannelMessage; irc.OnQueryMessage += OnQueryMessage; irc.OnQueryNotice += OnQueryNotice; irc.OnDisconnected += OnDisconnected; // Create scrollback buffer scrollback[server.Host] = new C5.CircularQueue<string>(1000); try { log.Info("Connecting to server " + server.Host); irc.Connect(server.Host, server.Port); } catch (ConnectionException e) { log.Error("Could not connect to server " + irc.Address, e); Exit(); } try { irc.Login(server.Nick, config.GetString("realname", "slave"), 0, config.GetString("username", "slave") ); foreach (string channel in server.Channels) irc.RfcJoin(channel); ircs[irc.Address] = irc; } catch (ConnectionException e) { log.Error("Connection error", e); Exit(); } catch (Exception e) { Exit(); } }
public void Connect() { while (true) { _irc = new IrcClient(); Logger.InfoFormat("Connecting to: {0}:{1}", _settings.Server, _settings.Port); try { _irc.Encoding = System.Text.Encoding.UTF8; _irc.SendDelay = 500; _irc.ActiveChannelSyncing = true; _irc.AutoReconnect = false; _irc.AutoRejoinOnKick = true; _irc.AutoRetry = true; _irc.AutoRetryDelay = 10000; _irc.OnQueryMessage += OnQueryMessage; _irc.OnQueryNotice += OnQueryMessage; _irc.OnError += OnError; _irc.OnChannelMessage += OnChannelMessage; //_irc.OnRawMessage += (x, e) => Logger.Info(e.Data.RawMessage); _irc.Connect(_settings.Server, _settings.Port); } catch (Exception e) { // Log this shit Logger.Error(e.ToString()); } Logger.Info("Connected! Joining channels"); try { _irc.Login(_settings.Nickname, "Name"); if (!String.IsNullOrWhiteSpace(_settings.Password)) { _irc.RfcPrivmsg("NickServ", "identify " + _settings.Password); } foreach (var channel in _settings.GetAllChannels()) { _irc.RfcJoin(channel); } _checkTimer.Change(TimeSpan.Zero, _settings.Period); } catch (Exception e) { Logger.Error(e.ToString()); } try { _irc.Listen(); Logger.Error("Lost connection to IRC (Automatically reconnecting in 10 seconds)"); Thread.Sleep(10000); if (_irc.IsConnected) { _irc.Disconnect(); } } catch (Exception e) { Logger.Error(e.ToString()); } } }
public override void JoinChannel(string channelName) => _ircClient.RfcJoin(channelName);
/// <summary> /// Creates and sets up an IrcClient instance and connects to a server according to "server" /// </summary> public void Connect(ServerDescriptor server) { if (server == null) throw new ArgumentNullException(); Thread.CurrentThread.Name = server.Host; irc = new IrcClient(); // Settings irc.Encoding = System.Text.Encoding.UTF8; irc.SendDelay = config.GetInt("send-delay", 200); irc.ActiveChannelSyncing = config.GetBoolean("use-active-channel-syncing", false); irc.UseSsl = server.UseSsl; // Bind event handlers irc.OnQueryMessage += new IrcEventHandler(OnQueryMessage); irc.OnChannelMessage += new IrcEventHandler(OnChannelMessage); irc.OnError += new Meebey.SmartIrc4net.ErrorEventHandler(OnError); irc.OnRawMessage += new IrcEventHandler(OnRawMessage); irc.OnPart += new PartEventHandler(OnPart); log.Info("Initializing plugins..."); foreach (var plugin in Plugins) { plugin.Initialize(config); irc.OnChannelMessage += new IrcEventHandler(plugin.OnChannelMessage); irc.OnRawMessage += new IrcEventHandler(plugin.OnRawMessage); } try { log.Info("Connecting to server " + irc.Address); irc.Connect(server.Host, server.Port); } catch (ConnectionException e) { log.Error("Could not connect to server " + irc.Address, e); Exit(); } try { irc.Login(config.GetString("nick", "slave"), config.GetString("realname", "slave"), 0, config.GetString("username", "slave") ); foreach (string channel in server.Channels) irc.RfcJoin(channel); irc.Listen(); irc.Disconnect(); } catch (ThreadAbortException e) { log.Info("Aborting thread", e); irc.Disconnect(); Thread.CurrentThread.Abort(); } catch (ConnectionException e) { log.Error("Error", e); Thread.CurrentThread.Abort(); } catch (Exception e) { log.Error("Error", e); Thread.CurrentThread.Abort(); } }