Example #1
0
 private void get_answer(string channel, bot ircbot)
 {
     if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "8ball" + Path.DirectorySeparatorChar + "answers.txt"))
     {
         string[] answer_file     = System.IO.File.ReadAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "8ball" + Path.DirectorySeparatorChar + "answers.txt");
         int      number_of_lines = answer_file.GetUpperBound(0) + 1;
         if (number_of_lines > 0)
         {
             string line = "";
             while (line == "")
             {
                 Random random = new Random();
                 int    index  = random.Next(0, number_of_lines);
                 line = answer_file[index];
             }
             ircbot.sendData("PRIVMSG", channel + " :" + line);
         }
         else
         {
             ircbot.sendData("PRIVMSG", channel + " :I don't know!");
         }
     }
     else
     {
         ircbot.sendData("PRIVMSG", channel + " :I don't know!");
     }
 }
Example #2
0
        public void check_intro(string nick, string channel, bot ircbot)
        {
            string list_file = ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "intro" + Path.DirectorySeparatorChar + ircbot.server_name + "_list.txt";

            if (File.Exists(list_file))
            {
                string line;

                // Read the file and display it line by line.
                System.IO.StreamReader file = new System.IO.StreamReader(list_file);
                while ((line = file.ReadLine()) != null)
                {
                    char[]   charSeparator = new char[] { ':' };
                    string[] intro_nick    = line.Split(charSeparator, 3);
                    if (nick.Equals(intro_nick[0]) && channel.Equals(intro_nick[1]))
                    {
                        string[] intro_line          = intro_nick[2].Split('|');
                        int      number_of_responses = intro_line.GetUpperBound(0) + 1;
                        Random   random = new Random();
                        int      index  = random.Next(0, number_of_responses);
                        ircbot.sendData("PRIVMSG", channel + " :\u200B" + intro_line[index]);
                    }
                }
                file.Close();
            }
        }
Example #3
0
        private void get_rules(string nick, string channel, bot ircbot)
        {
            string pattern  = "[^a-zA-Z0-9]"; //regex pattern
            string tab_name = Regex.Replace(channel, pattern, "_");

            if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "rules" + Path.DirectorySeparatorChar + ircbot.server_name + "_" + tab_name + "_rules.txt"))
            {
                string[] answer_file     = System.IO.File.ReadAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "rules" + Path.DirectorySeparatorChar + ircbot.server_name + "_" + tab_name + "_rules.txt");
                int      number_of_lines = answer_file.GetUpperBound(0) + 1;
                if (number_of_lines > 0)
                {
                    int index = 1;
                    foreach (string line in answer_file)
                    {
                        ircbot.sendData("NOTICE", nick + " :Rule " + index + ") " + line);
                        index++;
                    }
                    if (index == 1)
                    {
                        ircbot.sendData("NOTICE", nick + " :There are no Rules");
                    }
                }
                else
                {
                    ircbot.sendData("NOTICE", nick + " :There are no Rules");
                }
            }
            else
            {
                ircbot.sendData("NOTICE", nick + " :There are no Rules");
            }
        }
Example #4
0
        public void find_message(string nick, bot ircbot)
        {
            string list_file = ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "messaging" + Path.DirectorySeparatorChar + ircbot.server_name + "_messages.txt";

            if (File.Exists(list_file))
            {
                string[]      old_file = System.IO.File.ReadAllLines(list_file);
                List <string> new_file = new List <string>();
                foreach (string file_line in old_file)
                {
                    char[]   charSeparator = new char[] { '*' };
                    string[] intro_nick    = file_line.Split(charSeparator, 4);
                    if (intro_nick.GetUpperBound(0) > 0)
                    {
                        if (nick.Equals(intro_nick[1]))
                        {
                            ircbot.sendData("PRIVMSG", nick + " :" + intro_nick[0] + " has left you a message on: " + intro_nick[2]);
                            ircbot.sendData("PRIVMSG", nick + " :\"" + intro_nick[3] + "\"");
                            ircbot.sendData("PRIVMSG", nick + " :If you would like to reply to them, please type .message " + intro_nick[0] + " <your_message>");
                        }
                        else
                        {
                            new_file.Add(file_line);
                        }
                    }
                }
                System.IO.File.WriteAllLines(@list_file, new_file);
                // Read the file and display it line by line.
            }
        }
Example #5
0
        public static void add_log(string nick, string channel, string[] line, bot ircbot)
        {
            string file_name = "";
            string msg       = "";

            file_name = ircbot.Conf.Server_Name + ".log";
            DateTime current_date = DateTime.Now;

            if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "logging" + Path.DirectorySeparatorChar + "") == false)
            {
                Directory.CreateDirectory(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "logging");
            }
            if (line.GetUpperBound(0) > 3)
            {
                msg = line[4];
            }
            if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "logging" + Path.DirectorySeparatorChar + file_name))
            {
                StreamWriter log = File.AppendText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "logging" + Path.DirectorySeparatorChar + file_name);
                log.WriteLine(nick + "*" + channel + "*" + current_date.ToString("yyyy-MM-dd HH:mm:ss") + "*" + line[3].TrimStart(':').TrimStart('.') + "*" + msg);
                log.Close();
            }
            else
            {
                StreamWriter log_file = File.CreateText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "logging" + Path.DirectorySeparatorChar + file_name);
                log_file.WriteLine(nick + "*" + channel + "*" + current_date.ToString("yyyy-MM-dd HH:mm:ss") + "*" + line[3].TrimStart(':').TrimStart('.') + "*" + msg);
                log_file.Close();
            }
        }
Example #6
0
        public void log_error(Exception ex, string server_name)
        {
            bot bot = get_bot_instance(server_name);

            if (bot != null && bot.Conf.Keep_Logs.Equals("True") && ex != null)
            {
                string errorMessage =
                    "Unhandled Exception:\n\n" +
                    ex.Message + "\n\n" +
                    ex.GetType() +
                    "\n\nStack Trace:\n" +
                    ex.StackTrace;

                string file_name = "";
                file_name = "Errors.log";
                string time_stamp = DateTime.Now.ToString("hh:mm tt");
                string date_stamp = DateTime.Now.ToString("yyyy-MM-dd");
                string cur_dir    = Directory.GetCurrentDirectory();

                if (Directory.Exists(cur_dir + Path.DirectorySeparatorChar + "errors"))
                {
                    StreamWriter log_file = File.AppendText(cur_dir + Path.DirectorySeparatorChar + "errors" + Path.DirectorySeparatorChar + file_name);
                    log_file.WriteLine("[" + date_stamp + " " + time_stamp + "] " + errorMessage);
                    log_file.Close();
                }
                else
                {
                    Directory.CreateDirectory(cur_dir + Path.DirectorySeparatorChar + "errors");
                    StreamWriter log_file = File.AppendText(cur_dir + Path.DirectorySeparatorChar + "errors" + Path.DirectorySeparatorChar + file_name);
                    log_file.WriteLine("[" + date_stamp + " " + time_stamp + "] " + errorMessage);
                    log_file.Close();
                }
            }
        }
Example #7
0
        public void run_command(string server_name, string nick, string channel, string command, string[] args)
        {
            bool bot_command = true;

            char[] charSeparator = new char[] { ' ' };
            string type          = "channel";
            string msg           = "";

            if (!channel.StartsWith("#"))
            {
                type = "query";
            }
            bot bot = get_bot_instance(server_name);

            if (bot != null)
            {
                if (args != null)
                {
                    foreach (string arg in args)
                    {
                        msg += " " + arg;
                    }
                }
                string   line = ":" + nick + " PRIVMSG " + channel + " :" + bot.Conf.Command + command + msg;
                string[] ex   = line.Split(charSeparator, 5);
                //Run Enabled Modules
                foreach (Bot.Modules.Module module in bot.Conf.Modules)
                {
                    if (module.Loaded)
                    {
                        module.control(bot, bot.Conf, ex, command, bot.get_nick_access(nick, channel), nick, channel, bot_command, type);
                    }
                }
            }
        }
Example #8
0
 private void get_wa(string search, string channel, bot ircbot, BotConfig Conf)
 {
     string URL = "http://api.wolframalpha.com/v2/query?input=" + System.Web.HttpUtility.UrlEncode(search) + "&appid=" + this.Options["API"] + "&format=plaintext";
     XmlNodeList xnList = null;
     try
     {
         WebClient web = new WebClient();
         web.Encoding = Encoding.UTF8;
         string results = web.DownloadString(URL);
         XmlDocument xmlDoc = new XmlDocument();
         xmlDoc.LoadXml(results);
         xnList = xmlDoc.SelectNodes("/queryresult/pod");
     }
     catch
     {
         ircbot.sendData("PRIVMSG", channel + " :Could not fetch results");
     }
     if (xnList.Count > 1)
     {
         ircbot.sendData("PRIVMSG", channel + " :Result for: " + xnList[0]["subpod"]["plaintext"].InnerText);
         ircbot.sendData("PRIVMSG", channel + " :" + xnList[1]["subpod"]["plaintext"].InnerText);
     }
     else
     {
         ircbot.sendData("PRIVMSG", channel + " :No Results Found.");
     }
 }
Example #9
0
        public void ring_alarm(object sender, EventArgs e, bot ircbot, string nick, string full_nick, int nick_access, string channel, string type, string msg)
        {
            BotConfig Conf = tmp_conf;

            System.Timers.Timer alarm_trigger = (System.Timers.Timer)sender;
            alarm_trigger.Enabled = false;
            if (msg.StartsWith(ircbot.Conf.Command))
            {
                char[]   charSplit = new char[] { ' ' };
                string[] ex        = msg.TrimStart(Convert.ToChar(Conf.Command)).Split(charSplit, 2);
                string[] args;
                if (ex.GetUpperBound(0) > 0)
                {
                    args = ex[1].Split(charSplit);
                }
                else
                {
                    args = null;
                }
                ircbot.controller.run_command(Conf.Server_Name, nick, channel, ex[0], args);
            }
            else
            {
                ircbot.sendData("PRIVMSG", nick + " :ALARM: " + msg);
            }
        }
Example #10
0
        public string get_access_list(string nick, string channel, bot ircbot)
        {
            string file_name = ircbot.server_name + "_list.txt";
            string access    = "";

            if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "access" + Path.DirectorySeparatorChar + file_name))
            {
                string[] log_file        = System.IO.File.ReadAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "access" + Path.DirectorySeparatorChar + file_name);
                int      number_of_lines = log_file.GetUpperBound(0) + 1;
                if (number_of_lines > 0)
                {
                    foreach (string line in log_file)
                    {
                        char[]   sep      = new char[] { '*' };
                        string[] new_line = line.Split(sep, 3);
                        if (new_line.GetUpperBound(0) > 1)
                        {
                            if (new_line[0].Trim().Equals(nick.Trim()) && new_line[1].Trim().Equals(channel))
                            {
                                access = new_line[2];
                                break;
                            }
                        }
                    }
                }
            }
            return(access);
        }
Example #11
0
        public void check_intro(string nick, string channel, bot ircbot)
        {
            string list_file = ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "intro" + Path.DirectorySeparatorChar + ircbot.server_name + "_list.txt";
            if (File.Exists(list_file))
            {
                string line;

                // Read the file and display it line by line.
                System.IO.StreamReader file = new System.IO.StreamReader(list_file);
                while ((line = file.ReadLine()) != null)
                {
                    char[] charSeparator = new char[] { ':' };
                    string[] intro_nick = line.Split(charSeparator, 3);
                    if (nick.Equals(intro_nick[0]) && channel.Equals(intro_nick[1]))
                    {
                        string[] intro_line = intro_nick[2].Split('|');
                        int number_of_responses = intro_line.GetUpperBound(0) + 1;
                        Random random = new Random();
                        int index = random.Next(0, number_of_responses);
                        ircbot.sendData("PRIVMSG", channel + " :\u200B" + intro_line[index]);
                    }
                }
                file.Close();
            }
        }
Example #12
0
 public void add_log(string nick, string channel, string[] line, bot ircbot)
 {
     string file_name = "";
     string msg = "";
     file_name = ircbot.server_name + ".log";
     DateTime current_date = DateTime.Now;
     if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "logging" + Path.DirectorySeparatorChar + "") == false)
     {
         Directory.CreateDirectory(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "logging");
     }
     if (line.GetUpperBound(0) > 3)
     {
         msg = line[4];
     }
     if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "logging" + Path.DirectorySeparatorChar + file_name))
     {
         StreamWriter log = File.AppendText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "logging" + Path.DirectorySeparatorChar + file_name);
         log.WriteLine(nick + "*" + channel + "*" + current_date.ToString("yyyy-MM-dd HH:mm:ss") + "*" + line[3].TrimStart(':').TrimStart('.') + "*" + msg);
         log.Close();
     }
     else
     {
         StreamWriter log_file = File.CreateText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "logging" + Path.DirectorySeparatorChar + file_name);
         log_file.WriteLine(nick + "*" + channel + "*" + current_date.ToString("yyyy-MM-dd HH:mm:ss") + "*" + line[3].TrimStart(':').TrimStart('.') + "*" + msg);
         log_file.Close();
     }
 }
Example #13
0
        private void get_quote(string channel, bot ircbot, IRCConfig conf)
        {
            string tab_name = channel.TrimStart('#');
            string pattern  = "[^a-zA-Z0-9]"; //regex pattern

            tab_name = Regex.Replace(tab_name, pattern, "_");
            string file_name = ircbot.server_name + "_#" + tab_name + ".log";

            if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "quotes" + Path.DirectorySeparatorChar + "logs" + Path.DirectorySeparatorChar + file_name))
            {
                string[] log_file        = System.IO.File.ReadAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "quotes" + Path.DirectorySeparatorChar + "logs" + Path.DirectorySeparatorChar + file_name);
                int      number_of_lines = log_file.GetUpperBound(0) + 1;
                if (number_of_lines > 0)
                {
                    string line = "";
                    while (line == "")
                    {
                        Random random = new Random();
                        int    index  = random.Next(0, number_of_lines);
                        line = log_file[index];
                    }
                    char[]   charSep = new char[] { '*' };
                    string[] lines   = line.Split(charSep, 2);
                    ircbot.sendData("PRIVMSG", channel + " :" + lines[1] + " [" + lines[0] + "]");
                }
                else
                {
                    ircbot.sendData("PRIVMSG", channel + " :There are currently no logs for " + channel);
                }
            }
            else
            {
                ircbot.sendData("PRIVMSG", channel + " :There are currently no logs for " + channel);
            }
        }
Example #14
0
        } // end HttpPost

        private string get_user_info(bot ircbot, string uri, string title, string description, string assignee, List <string> labels)
        {
            Issues issue = new Issues {
                title = title, body = description, assignee = assignee, labels = labels.ToArray()
            };

            string         jsonString = issue.ToJSON();
            HttpWebRequest request    = (HttpWebRequest)WebRequest.Create(uri);

            request.Method = "POST";
            request.Headers.Add("Authorization: Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(this.Options["username"] + ":" + this.Options["api"])));
            request.UserAgent = "IRCBot";
            byte[] postBytes = Encoding.ASCII.GetBytes(jsonString);
            // this is important - make sure you specify type this way
            request.ContentLength = postBytes.Length;

            Stream requestStream = request.GetRequestStream();

            requestStream.Write(postBytes, 0, postBytes.Length);
            requestStream.Close();

            string reply = "";

            try
            {
                // grab te response and print it out to the console along with the status code
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                new StreamReader(response.GetResponseStream()).ReadToEnd();
            }
            catch (WebException ex)
            {
                reply = ex.Message;
            }
            return(reply);
        } // end HttpPost
Example #15
0
 public override void control(bot ircbot, BotConfig Conf, string[] line, string command, int nick_access, string nick, string channel, bool bot_command, string type)
 {
     if ((type.Equals("channel") || type.Equals("query")) && bot_command == true)
     {
         foreach (Command tmp_command in this.Commands)
         {
             bool blocked    = tmp_command.Blacklist.Contains(channel) || tmp_command.Blacklist.Contains(nick);
             bool cmd_found  = false;
             bool spam_check = ircbot.get_spam_check(channel, nick, tmp_command.Spam_Check);
             if (spam_check == true)
             {
                 blocked = blocked || ircbot.get_spam_status(channel);
             }
             cmd_found = tmp_command.Triggers.Contains(command);
             if (blocked == true && cmd_found == true)
             {
                 ircbot.sendData("NOTICE", nick + " :I am currently too busy to process that.");
             }
             if (blocked == false && cmd_found == true)
             {
                 foreach (string trigger in tmp_command.Triggers)
                 {
                     switch (trigger)
                     {
                     case "isitup":
                         if (spam_check == true)
                         {
                             ircbot.add_spam_count(channel);
                         }
                         if (nick_access >= tmp_command.Access)
                         {
                             if (line.GetUpperBound(0) > 3)
                             {
                                 bool isitup = CheckConnection(line[4]);
                                 if (isitup)
                                 {
                                     ircbot.sendData("PRIVMSG", channel + " :" + line[4] + " is up for me!");
                                 }
                                 else
                                 {
                                     ircbot.sendData("PRIVMSG", channel + " :" + line[4] + " looks down for me too.");
                                 }
                             }
                             else
                             {
                                 ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you need to include more info.");
                             }
                         }
                         else
                         {
                             ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                         }
                         break;
                     }
                 }
             }
         }
     }
 }
Example #16
0
        private void get_specific_quote(string channel, string nick, bot ircbot, IRCConfig conf)
        {
            string tab_name = channel.TrimStart('#');
            string pattern  = "[^a-zA-Z0-9]"; //regex pattern

            tab_name = Regex.Replace(tab_name, pattern, "_");
            string file_name = ircbot.server_name + "_#" + tab_name + ".log";

            if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "quotes" + Path.DirectorySeparatorChar + "logs" + Path.DirectorySeparatorChar + file_name))
            {
                string[] log_file        = System.IO.File.ReadAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "quotes" + Path.DirectorySeparatorChar + "logs" + Path.DirectorySeparatorChar + file_name);
                int      number_of_lines = log_file.GetUpperBound(0) + 1;
                if (number_of_lines > 0)
                {
                    string        line       = "";
                    string        line_nick  = "";
                    bool          nick_found = false;
                    List <string> quote_list = new List <string>();
                    foreach (string file_line in log_file)
                    {
                        char[]   charSep  = new char[] { '*' };
                        string[] tmp_line = file_line.Split(charSep, 2);
                        line_nick = tmp_line[0];
                        if (nick.Trim().ToLower().Equals(line_nick.Trim().ToLower()))
                        {
                            nick_found = true;
                            quote_list.Add(file_line);
                        }
                    }
                    line_nick = "";
                    line      = "";
                    if (nick_found == true)
                    {
                        while (line == "")
                        {
                            Random random = new Random();
                            number_of_lines = quote_list.Count();
                            int index = random.Next(1, number_of_lines + 1);
                            line = quote_list[index - 1];
                        }
                        char[]   charSep = new char[] { '*' };
                        string[] lines   = line.Split(charSep, 2);
                        ircbot.sendData("PRIVMSG", channel + " :" + lines[1] + " [" + lines[0] + "]");
                    }
                    else
                    {
                        ircbot.sendData("PRIVMSG", channel + " :There are currently no logs for " + nick);
                    }
                }
                else
                {
                    ircbot.sendData("PRIVMSG", channel + " :There are currently no logs for " + channel);
                }
            }
            else
            {
                ircbot.sendData("PRIVMSG", channel + " :There are currently no logs for " + channel);
            }
        }
Example #17
0
        public void send_data(string server_name, string cmd, string param)
        {
            bot bot = get_bot_instance(server_name);

            if (bot != null)
            {
                bot.sendData(cmd, param);
            }
        }
Example #18
0
 public override void control(bot ircbot, BotConfig Conf, string[] line, string command, int nick_access, string nick, string channel, bool bot_command, string type)
 {
     if (type.Equals("channel") && bot_command == true)
     {
         foreach (Command tmp_command in this.Commands)
         {
             bool blocked    = tmp_command.Blacklist.Contains(channel) || tmp_command.Blacklist.Contains(nick);
             bool cmd_found  = false;
             bool spam_check = ircbot.get_spam_check(channel, nick, tmp_command.Spam_Check);
             if (spam_check == true)
             {
                 blocked = blocked || ircbot.get_spam_status(channel);
             }
             cmd_found = tmp_command.Triggers.Contains(command);
             if (blocked == true && cmd_found == true)
             {
                 ircbot.sendData("NOTICE", nick + " :I am currently too busy to process that.");
             }
             if (blocked == false && cmd_found == true)
             {
                 foreach (string trigger in tmp_command.Triggers)
                 {
                     switch (trigger)
                     {
                     case "rollcall":
                         if (spam_check == true)
                         {
                             ircbot.add_spam_count(channel);
                         }
                         if (nick_access >= tmp_command.Access)
                         {
                             if (line.GetUpperBound(0) > 3)
                             {
                                 if (line[4].StartsWith("#"))
                                 {
                                     channel = line[4];
                                 }
                                 else
                                 {
                                     ircbot.sendData("PRIVMSG", nick + " :Please specify a valid channel");
                                 }
                             }
                             string       nicks     = "";
                             Channel_Info chan_info = ircbot.get_chan_info(channel);
                             foreach (Nick_Info info in chan_info.Nicks)
                             {
                                 nicks += info.Nick + ", ";
                             }
                             ircbot.sendData("PRIVMSG", channel + " :" + this.Options["roll_call_message"] + ": " + nicks.Trim().TrimEnd(','));
                         }
                         break;
                     }
                 }
             }
         }
     }
 }
Example #19
0
 public override void control(bot ircbot, BotConfig Conf, string[] line, string command, int nick_access, string nick, string channel, bool bot_command, string type)
 {
     if (type.Equals("channel") && bot_command == true)
     {
         foreach (Command tmp_command in this.Commands)
         {
             bool blocked = tmp_command.Blacklist.Contains(channel) || tmp_command.Blacklist.Contains(nick);
             bool cmd_found = false;
             bool spam_check = ircbot.get_spam_check(channel, nick, tmp_command.Spam_Check);
             if (spam_check == true)
             {
                 blocked = blocked || ircbot.get_spam_status(channel);
             }
             cmd_found = tmp_command.Triggers.Contains(command);
             if (blocked == true && cmd_found == true)
             {
                 ircbot.sendData("NOTICE", nick + " :I am currently too busy to process that.");
             }
             if (blocked == false && cmd_found == true)
             {
                 foreach (string trigger in tmp_command.Triggers)
                 {
                     switch (trigger)
                     {
                         case "rollcall":
                             if (spam_check == true)
                             {
                                 ircbot.add_spam_count(channel);
                             }
                             if (nick_access >= tmp_command.Access)
                             {
                                 if (line.GetUpperBound(0) > 3)
                                 {
                                     if (line[4].StartsWith("#"))
                                     {
                                         channel = line[4];
                                     }
                                     else
                                     {
                                         ircbot.sendData("PRIVMSG", nick + " :Please specify a valid channel");
                                     }
                                 }
                                 string nicks = "";
                                 Channel_Info chan_info = ircbot.get_chan_info(channel);
                                 foreach (Nick_Info info in chan_info.Nicks)
                                 {
                                     nicks += info.Nick + ", ";
                                 }
                                 ircbot.sendData("PRIVMSG", channel + " :" + this.Options["roll_call_message"] + ": " + nicks.Trim().TrimEnd(','));
                             }
                             break;
                     }
                 }
             }
         }
     }
 }
Example #20
0
        private void pass_hbomb(string pass_nick, string channel, string nick, bot ircbot, IRCConfig conf, ref hbomb_info tmp_info, int index)
        {
            string tab_name = channel.TrimStart('#');
            string pattern  = "[^a-zA-Z0-9]"; //regex pattern

            tab_name = Regex.Replace(tab_name, pattern, "_");
            string file_name = ircbot.server_name + "_#" + tab_name + ".log";
            bool   nick_idle = true;

            if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "seen" + Path.DirectorySeparatorChar + file_name))
            {
                string[] log_file        = System.IO.File.ReadAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "seen" + Path.DirectorySeparatorChar + file_name);
                int      number_of_lines = log_file.GetUpperBound(0) + 1;
                if (number_of_lines > 0)
                {
                    foreach (string file_line in log_file)
                    {
                        char[]   sep      = new char[] { '*' };
                        string[] new_line = file_line.Split(sep, 4);
                        if (new_line.GetUpperBound(0) > 0)
                        {
                            if (new_line[0].Equals(pass_nick) && new_line[1].Equals(channel))
                            {
                                DateTime current_date      = DateTime.Now;
                                DateTime past_date         = DateTime.Parse(new_line[2]);
                                double   difference_second = 0;
                                difference_second = current_date.Subtract(past_date).TotalSeconds;
                                if (difference_second <= 600)
                                {
                                    nick_idle = false;
                                }
                                break;
                            }
                        }
                    }
                }
            }
            if (nick_idle == false)
            {
                tmp_info.bomb_holder          = pass_nick;
                tmp_info.previous_bomb_holder = nick;
                hbombs[index] = tmp_info;
                ircbot.sendData("PRIVMSG", channel + " :" + nick + " passed the bomb to " + pass_nick);
                ircbot.sendData("NOTICE", pass_nick + " :You now have the bomb!  Type " + conf.command + "pass <nick> to pass it to someone else, or type " + conf.command + "defuse <color> to try to defuse it.");
                string colors = "";
                foreach (string wire in tmp_info.wire_colors)
                {
                    colors += wire + ",";
                }
                ircbot.sendData("NOTICE", pass_nick + " :The colors of the wires are: " + colors);
            }
            else
            {
                ircbot.sendData("PRIVMSG", channel + " :Dang, you missed them! (Idle)");
            }
        }
Example #21
0
        private static void display_last_log(string channel, string requst_nick, bot ircbot, BotConfig Conf)
        {
            string file_name = ircbot.Conf.Server_Name + ".log";
            bool   cmd_found = false;

            if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "logging" + Path.DirectorySeparatorChar + file_name))
            {
                string[] log_file        = System.IO.File.ReadAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "logging" + Path.DirectorySeparatorChar + file_name);
                int      number_of_lines = log_file.GetUpperBound(0) + 1;
                if (number_of_lines > 0)
                {
                    string parameters = "";
                    string date       = "";
                    string inside     = "";
                    string nick       = "";
                    string command    = "";
                    foreach (string line in log_file)
                    {
                        char[]   sep      = new char[] { '*' };
                        string[] new_line = line.Split(sep, 5);
                        if (new_line.GetUpperBound(0) > 0)
                        {
                            if (!String.IsNullOrEmpty(new_line[4]))
                            {
                                parameters = " with the following argument: " + new_line[4];
                            }
                            else
                            {
                                parameters = "";
                            }
                            date      = new_line[2];
                            inside    = new_line[1];
                            nick      = new_line[0];
                            command   = new_line[3];
                            cmd_found = true;
                        }
                    }
                    if (cmd_found == true)
                    {
                        ircbot.sendData("NOTICE", requst_nick + " :The last command used was " + ircbot.Conf.Command + command + " by " + nick + " on " + date + " in " + inside + parameters);
                    }
                    else
                    {
                        ircbot.sendData("NOTICE", requst_nick + " :No commands have been used");
                    }
                }
                else
                {
                    ircbot.sendData("NOTICE", requst_nick + " :No commands have been used");
                }
            }
            else
            {
                ircbot.sendData("NOTICE", requst_nick + " :No commands have been used");
            }
        }
Example #22
0
 public override void control(bot ircbot, BotConfig Conf, string[] line, string command, int nick_access, string nick, string channel, bool bot_command, string type)
 {
     if ((type.Equals("channel") || type.Equals("query")) && bot_command == true)
     {
         foreach (Command tmp_command in this.Commands)
         {
             bool blocked    = tmp_command.Blacklist.Contains(channel) || tmp_command.Blacklist.Contains(nick);
             bool cmd_found  = false;
             bool spam_check = ircbot.get_spam_check(channel, nick, tmp_command.Spam_Check);
             if (spam_check == true)
             {
                 blocked = blocked || ircbot.get_spam_status(channel);
             }
             cmd_found = tmp_command.Triggers.Contains(command);
             if (blocked == true && cmd_found == true)
             {
                 ircbot.sendData("NOTICE", nick + " :I am currently too busy to process that.");
             }
             if (blocked == false && cmd_found == true)
             {
                 foreach (string trigger in tmp_command.Triggers)
                 {
                     switch (trigger)
                     {
                     case "pingme":
                         if (spam_check == true)
                         {
                             ircbot.add_spam_count(channel);
                         }
                         if (nick_access >= tmp_command.Access)
                         {
                             int           epoch        = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
                             List <string> tmp_list     = new List <string>();
                             string        current_time = DateTime.Now.ToLongTimeString();
                             tmp_list.Add(nick);
                             tmp_list.Add(channel);
                             tmp_list.Add(current_time);
                             ping_list.Add(tmp_list);
                             ircbot.sendData("PRIVMSG", nick + " :\u0001PING " + epoch.ToString() + "\u0001");
                         }
                         else
                         {
                             ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                         }
                         break;
                     }
                 }
             }
         }
     }
     if (type.Equals("line") || type.Equals("query"))
     {
         check_ping(line, ircbot, nick);
     }
 }
Example #23
0
        private void add_anonmessage(string nick, string[] line, string channel, bot ircbot)
        {
            string list_file = ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "messaging" + Path.DirectorySeparatorChar + ircbot.Conf.Server_Name + "_messages.txt";

            char[]   charS      = new char[] { ' ' };
            string[] tmp        = line[4].Split(charS, 2);
            string   to_nick    = tmp[0];
            string   add_line   = nick + "*Anon*" + to_nick + "*" + DateTime.Now.ToString("MMMM d, yyyy h:mm:ss tt") + "*";
            bool     added_nick = false;

            if (tmp.GetUpperBound(0) >= 1)
            {
                add_line += tmp[1];
                if (!Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "messaging"))
                {
                    Directory.CreateDirectory(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "messaging");
                }
                if (File.Exists(list_file))
                {
                    string[]      old_file = System.IO.File.ReadAllLines(list_file);
                    List <string> new_file = new List <string>();
                    int           num_msg  = 0;
                    foreach (string file_line in old_file)
                    {
                        char[]   charSeparator = new char[] { '*' };
                        string[] intro_nick    = file_line.Split(charSeparator, 4);
                        if (nick.Equals(intro_nick[0], StringComparison.InvariantCultureIgnoreCase) && to_nick.Equals(intro_nick[1], StringComparison.InvariantCultureIgnoreCase))
                        {
                            num_msg++;
                        }
                        new_file.Add(file_line);
                    }
                    if (Convert.ToInt32(this.Options["max_messages"]) > num_msg)
                    {
                        new_file.Add(add_line);
                        added_nick = true;
                    }
                    System.IO.File.WriteAllLines(@list_file, new_file);
                }
                else
                {
                    System.IO.File.WriteAllText(@list_file, add_line);
                    added_nick = true;
                }
                if (added_nick)
                {
                    ircbot.sendData("NOTICE", nick + " :I will send your message as soon as I can.");
                }
                else
                {
                    ircbot.sendData("NOTICE", nick + " :You have reached the maximum number of messages you are able to send to " + to_nick + ".  Please try again after they have read them.");
                }
            }
        }
Example #24
0
        private void add_intro(string nick, string channel, string[] line, bot ircbot, int char_limit)
        {
            string list_file  = ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "intro" + Path.DirectorySeparatorChar + ircbot.server_name + "_list.txt";
            string add_line   = nick + ":" + channel + ":";
            bool   found_nick = false;

            if (line.GetUpperBound(0) > 3)
            {
                int intro_length = line[4].Length;
                if (intro_length <= char_limit)
                {
                    add_line += line[4] + " ";
                    if (!Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "intro"))
                    {
                        Directory.CreateDirectory(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "intro");
                    }
                    if (File.Exists(list_file))
                    {
                        string[]      old_file = System.IO.File.ReadAllLines(list_file);
                        List <string> new_file = new List <string>();
                        foreach (string file_line in old_file)
                        {
                            char[]   charSeparator = new char[] { ':' };
                            string[] intro_nick    = file_line.Split(charSeparator, 3);
                            if (nick.Equals(intro_nick[0]) && channel.Equals(intro_nick[1]))
                            {
                                new_file.Add(add_line);
                                found_nick = true;
                            }
                            else
                            {
                                new_file.Add(file_line);
                            }
                        }
                        if (found_nick == false)
                        {
                            new_file.Add(add_line);
                        }
                        System.IO.File.WriteAllLines(@list_file, new_file);
                    }
                    else
                    {
                        System.IO.File.WriteAllText(@list_file, add_line);
                    }
                    ircbot.sendData("NOTICE", nick + " :Your introduction is as follows: " + line[4]);
                }
                else
                {
                    ircbot.sendData("PRIVMSG", channel + " :Your introduction is too long.  The max length is " + char_limit.ToString() + " characters.");
                }
            }
        }
Example #25
0
 public override void control(bot ircbot, BotConfig Conf, string[] line, string command, int nick_access, string nick, string channel, bool bot_command, string type)
 {
     if ((type.Equals("channel") || type.Equals("query")) && bot_command == true)
     {
         foreach (Command tmp_command in this.Commands)
         {
             bool blocked = tmp_command.Blacklist.Contains(channel) || tmp_command.Blacklist.Contains(nick);
             bool cmd_found = false;
             bool spam_check = ircbot.get_spam_check(channel, nick, tmp_command.Spam_Check);
             if (spam_check == true)
             {
                 blocked = blocked || ircbot.get_spam_status(channel);
             }
             cmd_found = tmp_command.Triggers.Contains(command);
             if (blocked == true && cmd_found == true)
             {
                 ircbot.sendData("NOTICE", nick + " :I am currently too busy to process that.");
             }
             if (blocked == false && cmd_found == true)
             {
                 foreach (string trigger in tmp_command.Triggers)
                 {
                     switch (trigger)
                     {
                         case "wa":
                             if (spam_check == true)
                             {
                                 ircbot.add_spam_count(channel);
                             }
                             if (nick_access >= tmp_command.Access)
                             {
                                 if (line.GetUpperBound(0) > 3)
                                 {
                                     // Get Urban Dictionary Info
                                     get_wa(line[4], line[2], ircbot, Conf);
                                 }
                                 else
                                 {
                                     ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you need to include more info.");
                                 }
                             }
                             else
                             {
                                 ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                             }
                             break;
                     }
                 }
             }
         }
     }
 }
Example #26
0
        private void add_message(string nick, string[] line, string channel, bot ircbot)
        {
            string list_file = ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "messaging" + Path.DirectorySeparatorChar + ircbot.server_name + "_messages.txt";

            char[]   charS      = new char[] { ' ' };
            string[] tmp        = line[4].Split(charS, 2);
            string   to_nick    = tmp[0].ToLower();
            string   add_line   = nick + "*" + to_nick + "*" + DateTime.Now.ToString("MMMM d, yyyy h:mm:ss tt") + "*";
            bool     found_nick = false;

            if (tmp.GetUpperBound(0) >= 1)
            {
                add_line += tmp[1];
                if (File.Exists(list_file))
                {
                    string[]      old_file = System.IO.File.ReadAllLines(list_file);
                    List <string> new_file = new List <string>();
                    foreach (string file_line in old_file)
                    {
                        char[]   charSeparator = new char[] { '*' };
                        string[] intro_nick    = file_line.Split(charSeparator, 4);
                        if (nick.Equals(intro_nick[0]) && to_nick.Equals(intro_nick[1]))
                        {
                            new_file.Add(add_line);
                            found_nick = true;
                        }
                        else
                        {
                            new_file.Add(file_line);
                        }
                    }
                    if (found_nick == false)
                    {
                        new_file.Add(add_line);
                    }
                    System.IO.File.WriteAllLines(@list_file, new_file);
                }
                else
                {
                    System.IO.File.WriteAllText(@list_file, add_line);
                }
                if (channel != null)
                {
                    ircbot.sendData("PRIVMSG", channel + " :" + nick + ", I will send your message as soon as I can.");
                }
                else
                {
                    ircbot.sendData("PRIVMSG", nick + " :I will send your message as soon as I can.");
                }
            }
        }
Example #27
0
 public void check_auto(string nick, string channel, string hostname, bot ircbot)
 {
     string list_file = ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "auto_kb" + Path.DirectorySeparatorChar + ircbot.server_name + "_list.txt";
     if (File.Exists(list_file))
     {
         int counter = 0;
         string[] old_file = System.IO.File.ReadAllLines(list_file);
         string[] new_file = new string[old_file.GetUpperBound(0) + 1];
         foreach (string file_line in old_file)
         {
             char[] charSeparator = new char[] { '*' };
             string[] auto_nick = file_line.Split(charSeparator, 6);
             if (auto_nick.GetUpperBound(0) > 0)
             {
                 if ((nick.Equals(auto_nick[0]) == true || hostname.Equals(auto_nick[1])) && channel.Equals(auto_nick[2]))
                 {
                     string ban = "*!*@" + hostname;
                     if (hostname.Equals(""))
                     {
                         ban = nick + "!*@*";
                     }
                     if (auto_nick[4] == "")
                     {
                         auto_nick[4] = "Auto " + auto_nick[3];
                     }
                     if (auto_nick[3].Equals("k"))
                     {
                         ircbot.sendData("KICK", channel + " " + nick + " :" + auto_nick[4]);
                     }
                     else if (auto_nick[3].Equals("b"))
                     {
                         ircbot.sendData("MODE", channel + " +b " + ban + " :" + auto_nick[4]);
                     }
                     else if (auto_nick[3].Equals("kb"))
                     {
                         ircbot.sendData("MODE", channel + " +b " + ban + " :" + auto_nick[4]);
                         ircbot.sendData("KICK", channel + " " + nick + " :" + auto_nick[4]);
                     }
                     else
                     {
                     }
                 }
                 else
                 {
                     new_file[counter] = file_line;
                     counter++;
                 }
             }
         }
     }
 }
Example #28
0
        public bool start_bot(string server_name)
        {
            bool server_started = false;
            bot  bot            = get_bot_instance(server_name);

            if (bot != null)
            {
                if (bot.connected == false && bot.connecting == false && bot.disconnected == true && bot.Conf.Server_Name.Equals(server_name))
                {
                    server_started = true;
                    bot.start_bot();
                }
            }
            return(server_started);
        }
Example #29
0
 public override void control(bot ircbot, BotConfig Conf, string[] line, string command, int nick_access, string nick, string channel, bool bot_command, string type)
 {
     if ((type.Equals("channel") || type.Equals("query")) && bot_command == true)
     {
         foreach (Command tmp_command in this.Commands)
         {
             bool blocked = tmp_command.Blacklist.Contains(channel) || tmp_command.Blacklist.Contains(nick);
             bool cmd_found = false;
             bool spam_check = ircbot.get_spam_check(channel, nick, tmp_command.Spam_Check);
             if (spam_check == true)
             {
                 blocked = blocked || ircbot.get_spam_status(channel);
             }
             cmd_found = tmp_command.Triggers.Contains(command);
             if (blocked == true && cmd_found == true)
             {
                 ircbot.sendData("NOTICE", nick + " :I am currently too busy to process that.");
             }
             if (blocked == false && cmd_found == true)
             {
                 foreach (string trigger in tmp_command.Triggers)
                 {
                     switch (trigger)
                     {
                         case "fortune":
                             if (spam_check == true)
                             {
                                 ircbot.add_spam_count(channel);
                             }
                             if (nick_access >= tmp_command.Access)
                             {
                                 get_quote(channel, ircbot);
                             }
                             else
                             {
                                 ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                             }
                             break;
                     }
                 }
             }
         }
     }
 }
Example #30
0
 public static void add_quote(string nick, string channel, string[] line, bot ircbot, BotConfig Conf)
 {
     string tab_name = channel.TrimStart('#');
     string pattern = "[^a-zA-Z0-9]"; //regex pattern
     string new_tab_name = Regex.Replace(tab_name, pattern, "_");
     string file_name = ircbot.Conf.Server_Name + "_#" + new_tab_name + ".log";
     if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "quotes" + Path.DirectorySeparatorChar + "logs") == false)
     {
         Directory.CreateDirectory(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "quotes" + Path.DirectorySeparatorChar + "logs");
     }
     StreamWriter log_file = File.AppendText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "quotes" + Path.DirectorySeparatorChar + "logs" + Path.DirectorySeparatorChar + file_name);
     if (line.GetUpperBound(0) > 3)
     {
         log_file.WriteLine(nick + "*" + line[3].Remove(0, 1) + " " + line[4]);
     }
     else
     {
         log_file.WriteLine(nick + "*" + line[3].Remove(0, 1));
     }
     log_file.Close();
 }
Example #31
0
 public void check_ping(string[] line, bot ircbot, string nick)
 {
     if (line.GetUpperBound(0) > 3)
     {
         if (line[3].Equals(":\u0001PING"))
         {
             for (int x = 0; x < ping_list.Count(); x++)
             {
                 if (ping_list[x][0].Equals(nick))
                 {
                     DateTime current_time = DateTime.Now;
                     DateTime ping_time = Convert.ToDateTime(ping_list[x][2]);
                     string dif_time = current_time.Subtract(ping_time).ToString();
                     ircbot.sendData("PRIVMSG", ping_list[x][1] + " :" + nick + ", your ping is " + dif_time);
                     ping_list.RemoveAt(x);
                     break;
                 }
             }
         }
     }
 }
Example #32
0
 public static void find_message(string nick, bot ircbot)
 {
     string list_file = ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "messaging" + Path.DirectorySeparatorChar + ircbot.Conf.Server_Name + "_messages.txt";
     if (File.Exists(list_file))
     {
         string[] old_file = System.IO.File.ReadAllLines(list_file);
         List<string> new_file = new List<string>();
         foreach (string file_line in old_file)
         {
             char[] charSeparator = new char[] { '*' };
             string[] intro_nick = file_line.Split(charSeparator, 5);
             if (intro_nick.GetUpperBound(0) > 3)
             {
                 if (nick.Equals(intro_nick[2], StringComparison.InvariantCultureIgnoreCase))
                 {
                     if (intro_nick[1].Equals("Reg"))
                     {
                         ircbot.sendData("PRIVMSG", nick + " :" + intro_nick[0] + " has left you a message on: " + intro_nick[3]);
                         ircbot.sendData("PRIVMSG", nick + " :\"" + intro_nick[4] + "\"");
                         ircbot.sendData("PRIVMSG", nick + " :If you would like to reply to them, please type .message " + intro_nick[0] + " <your_message>");
                     }
                     else if (intro_nick[1].Equals("Anon"))
                     {
                         ircbot.sendData("PRIVMSG", nick + " :" + "An anonymous sender has left you a message on: " + intro_nick[3]);
                         ircbot.sendData("PRIVMSG", nick + " :\"" + intro_nick[4] + "\"");
                     }
                     else
                     {
                     }
                 }
                 else
                 {
                     new_file.Add(file_line);
                 }
             }
         }
         System.IO.File.WriteAllLines(@list_file, new_file);
         // Read the file and display it line by line.
     }
 }
Example #33
0
 private static void get_quote(string channel, bot ircbot)
 {
     if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "fortune" + Path.DirectorySeparatorChar + "list.txt"))
     {
         string[] answer_file = System.IO.File.ReadAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "fortune" + Path.DirectorySeparatorChar + "list.txt");
         int number_of_lines = answer_file.GetUpperBound(0) + 1;
         if (number_of_lines > 0)
         {
             string line = "";
             Random random = new Random();
             int index = random.Next(0, number_of_lines);
             line = answer_file[index];
             if (!String.IsNullOrEmpty(line))
             {
                 ircbot.sendData("PRIVMSG", channel + " :" + line);
             }
             else
             {
                 ircbot.sendData("PRIVMSG", channel + " :No fortune for you!");
             }
         }
         else
         {
             ircbot.sendData("PRIVMSG", channel + " :No fortune for you!");
         }
     }
     else
     {
         if (!Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "fortune"))
         {
             Directory.CreateDirectory(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "fortune");
         }
         List<string> contents = new List<string>();
         contents.Add("You will find fortune soon.");
         File.WriteAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "fortune" + Path.DirectorySeparatorChar + "list.txt", contents.ToArray());
         ircbot.sendData("PRIVMSG", channel + " :No fortune for you!");
     }
 }
Example #34
0
        public void scripts_control(string[] line, bot ircbot, IRCConfig conf, int conf_id, int nick_access, string nick, string channel, string event_type)
        {
            if (pyEngine == null)
            {
                pyEngine = Python.CreateEngine();
                pyScope = pyEngine.CreateScope();

                string msg = "";
                if(line.GetUpperBound(0) > 3)
                {
                    msg = line[3] + " " + line[4];
                }
                else
                {
                    msg = line[3];
                }
                pyScope.SetVariable("line", msg);
                pyScope.SetVariable("event", event_type);
                pyScope.SetVariable("nick", nick);
                pyScope.SetVariable("channel", channel);
                pyScope.SetVariable("bot", ircbot);
                pyScope.SetVariable("conf", conf);
            }
        }
Example #35
0
 private void display_log_nick(string nick, string channel, string requst_nick, string command, bot ircbot, IRCConfig conf)
 {
     string file_name = ircbot.server_name + ".log";
     bool cmd_found = false;
     if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "logging" + Path.DirectorySeparatorChar + file_name))
     {
         string[] log_file = System.IO.File.ReadAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "logging" + Path.DirectorySeparatorChar + file_name);
         int number_of_lines = log_file.GetUpperBound(0) + 1;
         if (number_of_lines > 0)
         {
             int num_uses = 0;
             string parameters = "";
             string date = "";
             string inside = "";
             foreach (string line in log_file)
             {
                 char[] sep = new char[] { '*' };
                 string[] new_line = line.Split(sep, 5);
                 if (new_line.GetUpperBound(0) > 0)
                 {
                     if (new_line[0].Equals(nick) && new_line[3].Equals(command))
                     {
                         if (new_line[4] != "")
                         {
                             parameters = " with the following argument: " + new_line[4];
                         }
                         else
                         {
                             parameters = "";
                         }
                         date = new_line[2];
                         inside = new_line[1];
                         num_uses++;
                         cmd_found = true;
                     }
                 }
             }
             if (cmd_found == true)
             {
                 ircbot.sendData("NOTICE", requst_nick + " :" + nick + " has used " + conf.command + command + " " + num_uses + " times.");
                 ircbot.sendData("NOTICE", requst_nick + " :They last used " + conf.command + command + " on " + date + " in " + inside + parameters);
             }
             else
             {
                 ircbot.sendData("NOTICE", requst_nick + " :" + nick + " has not used " + conf.command + command);
             }
         }
         else
         {
             ircbot.sendData("NOTICE", requst_nick + " :" + nick + " has not used any commands");
         }
     }
     else
     {
         ircbot.sendData("NOTICE", requst_nick + " :" + nick + " has not used any commands");
     }
 }
Example #36
0
        public override void control(bot ircbot, ref IRCConfig conf, int module_id, string[] line, string command, int nick_access, string nick, string channel, bool bot_command, string type)
        {
            string module_name = ircbot.conf.module_config[module_id][0];
            if (type.Equals("channel") || type.Equals("query") && bot_command == true)
            {
                foreach (List<string> tmp_command in conf.command_list)
                {
                    if (module_name.Equals(tmp_command[0]))
                    {
                        string[] triggers = tmp_command[3].Split('|');
                        int command_access = Convert.ToInt32(tmp_command[5]);
                        string[] blacklist = tmp_command[6].Split(',');
                        bool blocked = false;
                        bool cmd_found = false;
                        bool spam_check = Convert.ToBoolean(tmp_command[8]);
                        foreach (string bl_chan in blacklist)
                        {
                            if (bl_chan.Equals(channel))
                            {
                                blocked = true;
                                break;
                            }
                        }
                        if (spam_check == true)
                        {
                            blocked = ircbot.get_spam_status(channel, nick);
                        }
                        foreach (string trigger in triggers)
                        {
                            if (trigger.Equals(command))
                            {
                                cmd_found = true;
                                break;
                            }
                        }
                        if (blocked == true && cmd_found == true)
                        {
                            ircbot.sendData("NOTICE", nick + " :I am currently too busy to process that.");
                        }
                        if (blocked == false && cmd_found == true)
                        {
                            foreach (string trigger in triggers)
                            {
                                switch (trigger)
                                {
                                    case "addresponse":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                string list_file = ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response" + Path.DirectorySeparatorChar + "dictionary.txt";
                                                if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response" + Path.DirectorySeparatorChar + "") == false)
                                                {
                                                    Directory.CreateDirectory(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response");
                                                }
                                                if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response" + Path.DirectorySeparatorChar + "dictionary.txt"))
                                                {
                                                    StreamWriter log = File.AppendText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response" + Path.DirectorySeparatorChar + "dictionary.txt");
                                                    log.WriteLine(line[4]);
                                                    log.Close();
                                                }
                                                else
                                                {
                                                    StreamWriter log_file = File.CreateText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response" + Path.DirectorySeparatorChar + "dictionary.txt");
                                                    log_file.WriteLine(line[4]);
                                                    log_file.Close();
                                                }
                                                ircbot.sendData("PRIVMSG", channel + " :Response added successfully");
                                            }
                                            else
                                            {
                                                ircbot.sendData("NOTICE", nick + " :" + nick + ", you need to include more info.");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                }
                            }
                        }
                    }
                }
            }
            if (type.Equals("channel") && bot_command == false)
            {
                if (nick != conf.nick)
                {
                    try
                    {
                        string[] file;
                        string list_file = ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response" + Path.DirectorySeparatorChar + "dictionary.txt";
                        if (File.Exists(list_file))
                        {
                            file = System.IO.File.ReadAllLines(list_file);
                        }
                        else
                        {
                            file = null;
                        }

                        string tmp_line = line[3];
                        if (line.GetUpperBound(0) > 3)
                        {
                            tmp_line += " " + line[4];
                        }
                        tmp_line = tmp_line.Remove(0, 1);
                        string new_line = tmp_line.ToLowerInvariant();
                        bool triggered = false;
                        if (file.GetUpperBound(0) >= 0)
                        {
                            foreach (string tmp_new_line in file)
                            {
                                string file_line = tmp_new_line.Replace("<nick>", nick);
                                file_line = file_line.Replace("<me>", conf.nick);
                                char[] split_type = new char[] { ':' };
                                char[] trigger_split = new char[] { '*' };
                                char[] triggered_split = new char[] { '&' };
                                string[] split = file_line.Split(split_type, 2);
                                string[] triggers = split[0].Split('|');
                                string[] responses = split[1].Split('|');
                                int index = 0;
                                for (int x = 0; x <= triggers.GetUpperBound(0); x++)
                                {
                                    string[] terms = triggers[x].Split(trigger_split, StringSplitOptions.RemoveEmptyEntries);
                                    for (int y = 0; y <= terms.GetUpperBound(0); y++)
                                    {
                                        triggered = false;
                                        terms[y] = terms[y].ToLowerInvariant();
                                        if (triggers[x].StartsWith("*") == false && triggers[x].EndsWith("*") == false && terms.GetUpperBound(0) == 0)
                                        {
                                            if (new_line.Equals(terms[y]) == true)
                                            {
                                                triggered = true;
                                            }
                                            else
                                            {
                                                triggered = false;
                                                break;
                                            }
                                        }
                                        else if (triggers[x].StartsWith("*") == false && y == 0)
                                        {
                                            if (new_line.StartsWith(terms[y]) == true && index <= new_line.IndexOf(terms[y]))
                                            {
                                                triggered = true;
                                                index = new_line.IndexOf(terms[y]);
                                            }
                                            else
                                            {
                                                triggered = false;
                                                break;
                                            }
                                        }
                                        else if (triggers[x].EndsWith("*") == false && y == terms.GetUpperBound(0))
                                        {
                                            if (new_line.EndsWith(terms[y]) == true && index <= new_line.IndexOf(terms[y]))
                                            {
                                                triggered = true;
                                                index = new_line.IndexOf(terms[y]);
                                            }
                                            else
                                            {
                                                triggered = false;
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            if (new_line.Contains(terms[y]) == true && index <= new_line.IndexOf(terms[y]))
                                            {
                                                triggered = true;
                                                index = new_line.IndexOf(terms[y]);
                                            }
                                            else
                                            {
                                                triggered = false;
                                                break;
                                            }
                                        }
                                    }
                                    if (triggered == true)
                                    {
                                        break;
                                    }
                                }
                                if (triggered == true)
                                {
                                    ircbot.add_spam_count(channel);
                                    int number_of_responses = responses.GetUpperBound(0) + 1;
                                    Random random = new Random();
                                    index = random.Next(0, number_of_responses);
                                    string[] events = responses[index].Split(triggered_split, StringSplitOptions.RemoveEmptyEntries);
                                    for (int y = 0; y <= events.GetUpperBound(0); y++)
                                    {
                                        if (events[y].StartsWith("<action>") == true)
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :\u0001ACTION " + events[y].Remove(0, 8) + "\u0001");
                                        }
                                        else if (events[y].StartsWith("<delay>") == true)
                                        {
                                            Thread.Sleep(Convert.ToInt32(events[y].Remove(0, 7)));
                                        }
                                        else if (events[y].StartsWith("<part>") == true)
                                        {
                                            ircbot.sendData("PART", channel);
                                        }
                                        else if (events[y].StartsWith("<join>") == true)
                                        {
                                            ircbot.sendData("JOIN", channel);
                                        }
                                        else if (events[y].StartsWith("<kick>") == true)
                                        {
                                            if (events[y].Length > 6)
                                            {
                                                ircbot.sendData("KICK", channel + " " + nick + " :" + events[y].Remove(0, 6));
                                            }
                                            else
                                            {
                                                ircbot.sendData("KICK", channel + " " + nick + " :No Reason");
                                            }
                                        }
                                        else if (events[y].StartsWith("<ban>") == true)
                                        {
                                            string target_host = ircbot.get_user_host(nick);
                                            string ban = "*!*@" + target_host;
                                            if (target_host.Equals("was"))
                                            {
                                                ban = nick + "!*@*";
                                            }
                                            if (events[y].Length > 6)
                                            {
                                                ircbot.sendData("MODE", channel + " +b " + ban + " :" + events[y].Remove(0, 6));
                                            }
                                            else
                                            {
                                                ircbot.sendData("MODE", channel + " +b " + ban + " :No Reason");
                                            }
                                        }
                                        else if (events[y].StartsWith("<kickban>") == true)
                                        {
                                            string target_host = ircbot.get_user_host(nick);
                                            string ban = "*!*@" + target_host;
                                            if (target_host.Equals("was"))
                                            {
                                                ban = nick + "!*@*";
                                            }
                                            if (events[y].Length > 6)
                                            {
                                                ircbot.sendData("MODE", channel + " +b " + ban + " :" + events[y].Remove(0, 6));
                                                ircbot.sendData("KICK", channel + " " + nick + " :" + events[y].Remove(0, 6));
                                            }
                                            else
                                            {
                                                ircbot.sendData("MODE", channel + " +b " + ban + " :No Reason");
                                                ircbot.sendData("KICK", channel + " " + nick + " :No Reason");
                                            }
                                        }
                                        else if (events[y].StartsWith("<timeban>") == true)
                                        {
                                            string[] mod_line = new string[] { conf.nick, "0", channel, ":tb", events[y].Remove(0, 9) };
                                            Modules.moderation mod = new Modules.moderation();
                                            mod.control(ircbot, ref conf, module_id, mod_line, "tb", conf.owner_level, nick, channel, true, "channel");
                                        }
                                        else if (events[y].StartsWith("<timekickban>") == true)
                                        {
                                            string[] mod_line = new string[] { conf.nick, "0", channel, ":tkb", events[y].Remove(0, 13) };
                                            Modules.moderation mod = new Modules.moderation();
                                            mod.control(ircbot, ref conf, module_id, mod_line, "tkb", conf.owner_level, nick, channel, true, "channel");
                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :" + events[y]);
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ircbot.sendData("PRIVMSG", channel + " :" + ex.ToString());
                    }
                }
            }
        }
Example #37
0
 public override void control(bot ircbot, ref IRCConfig conf, int module_id, string[] line, string command, int nick_access, string nick, string channel, bool bot_command, string type)
 {
     char[] charS = new char[] { ' ' };
     string module_name = ircbot.conf.module_config[module_id][0];
     if ((type.Equals("channel") || type.Equals("query")) && bot_command == true)
     {
         foreach (List<string> tmp_command in conf.command_list)
         {
             if (module_name.Equals(tmp_command[0]))
             {
                 string[] triggers = tmp_command[3].Split('|');
                 int command_access = Convert.ToInt32(tmp_command[5]);
                 string[] blacklist = tmp_command[6].Split(',');
                 bool blocked = false;
                 bool cmd_found = false;
                 bool spam_check = Convert.ToBoolean(tmp_command[8]);
                 foreach (string bl_chan in blacklist)
                 {
                     if (bl_chan.Equals(channel))
                     {
                         blocked = true;
                         break;
                     }
                 }
                 if (spam_check == true)
                 {
                     blocked = ircbot.get_spam_status(channel, nick);
                 }
                 foreach (string trigger in triggers)
                 {
                     if (trigger.Equals(command))
                     {
                         cmd_found = true;
                         break;
                     }
                 }
                 if (blocked == true && cmd_found == true)
                 {
                     ircbot.sendData("NOTICE", nick + " :I am currently too busy to process that.");
                 }
                 if (blocked == false && cmd_found == true)
                 {
                     foreach (string trigger in triggers)
                     {
                         switch (trigger)
                         {
                             case "bug":
                                 if (spam_check == true)
                                 {
                                     ircbot.add_spam_count(channel);
                                 }
                                 if (nick_access >= command_access)
                                 {
                                     if (line.GetUpperBound(0) > 3)
                                     {
                                         string title = "";
                                         string description = "";
                                         string[] split = line[4].Split('|');
                                         title = "[" + nick + "] " + split[0];
                                         if (split.GetUpperBound(0) > 0)
                                         {
                                             description = split[1];
                                         }
                                         List<string> label = new List<string>() { "bug" };
                                         string uri = "https://api.github.com/repos/" + ircbot.conf.module_config[module_id][3] + "/" + ircbot.conf.module_config[module_id][5] + "/issues";
                                         string response = post_issue(ircbot, module_id, uri, title, description, ircbot.conf.module_config[module_id][3], label);
                                         if (response.Equals(""))
                                         {
                                             ircbot.sendData("NOTICE", nick + " :Issue Added Successfully");
                                         }
                                         else
                                         {
                                             ircbot.sendData("NOTICE", nick + " :" + response);
                                         }
                                     }
                                     else
                                     {
                                         ircbot.sendData("NOTICE", nick + " :" + nick + ", you need to include more info.");
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                 }
                                 break;
                             case "request":
                                 if (spam_check == true)
                                 {
                                     ircbot.add_spam_count(channel);
                                 }
                                 if (nick_access >= command_access)
                                 {
                                     if (line.GetUpperBound(0) > 3)
                                     {
                                         string title = "";
                                         string description = "";
                                         string[] split = line[4].Split('|');
                                         title = "[" + nick + "] " + split[0];
                                         if (split.GetUpperBound(0) > 0)
                                         {
                                             description = split[1];
                                         }
                                         List<string> label = new List<string>() { "Feature Request" };
                                         string uri = "https://api.github.com/repos/" + ircbot.conf.module_config[module_id][3] + "/" + ircbot.conf.module_config[module_id][5] + "/issues";
                                         string response = post_issue(ircbot, module_id, uri, title, description, ircbot.conf.module_config[module_id][3], label);
                                         if (response.Equals(""))
                                         {
                                             ircbot.sendData("NOTICE", nick + " :Feature Request Added Successfully");
                                         }
                                         else
                                         {
                                             ircbot.sendData("NOTICE", nick + " :" + response);
                                         }
                                     }
                                     else
                                     {
                                         ircbot.sendData("NOTICE", nick + " :" + nick + ", you need to include more info.");
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                 }
                                 break;
                         }
                     }
                 }
             }
         }
     }
 }
Example #38
0
        private string post_issue(bot ircbot, int module_id, string uri, string title, string description, string assignee, List<string> labels)
        {
            Issues issue = new Issues { title = title, body = description, assignee = assignee, labels = labels.ToArray() };

            string jsonString = issue.ToJSON();
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
            request.Method = "POST";
            request.Headers.Add("Authorization: Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(ircbot.conf.module_config[module_id][3] + ":" + ircbot.conf.module_config[module_id][4])));
            request.UserAgent = "IRCBot";
            byte[] postBytes = Encoding.ASCII.GetBytes(jsonString);
            // this is important - make sure you specify type this way
            request.ContentLength = postBytes.Length;

            Stream requestStream = request.GetRequestStream();
            requestStream.Write(postBytes, 0, postBytes.Length);
            requestStream.Close();

            string reply = "";
            try
            {
                // grab te response and print it out to the console along with the status code
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                new StreamReader(response.GetResponseStream()).ReadToEnd();
            }
            catch (WebException ex)
            {
                reply = ex.Message;
            }
            return reply;
        }
Example #39
0
        public override void control(bot ircbot, BotConfig Conf, string[] line, string command, int nick_access, string nick, string channel, bool bot_command, string type)
        {
            if ((type.Equals("channel") || type.Equals("query")) && bot_command == true)
            {
                foreach (Command tmp_command in this.Commands)
                {
                    bool blocked = tmp_command.Blacklist.Contains(channel) || tmp_command.Blacklist.Contains(nick);
                    bool cmd_found = false;
                    bool spam_check = ircbot.get_spam_check(channel, nick, tmp_command.Spam_Check);
                    if (spam_check == true)
                    {
                        blocked = blocked || ircbot.get_spam_status(channel);
                    }
                    cmd_found = tmp_command.Triggers.Contains(command);
                    if (blocked == true && cmd_found == true)
                    {
                        ircbot.sendData("NOTICE", nick + " :I am currently too busy to process that.");
                    }
                    if (blocked == false && cmd_found == true)
                    {
                        foreach (string trigger in tmp_command.Triggers)
                        {
                            switch (trigger)
                            {
                                case "addresponse":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= tmp_command.Access)
                                    {
                                        if (line.GetUpperBound(0) > 3)
                                        {
                                            string list_file = ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response" + Path.DirectorySeparatorChar + "dictionary.txt";
                                            if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response" + Path.DirectorySeparatorChar + "") == false)
                                            {
                                                Directory.CreateDirectory(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response");
                                            }
                                            if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response" + Path.DirectorySeparatorChar + "dictionary.txt"))
                                            {
                                                StreamWriter log = File.AppendText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response" + Path.DirectorySeparatorChar + "dictionary.txt");
                                                log.WriteLine(line[4]);
                                                log.Close();
                                            }
                                            else
                                            {
                                                StreamWriter log_file = File.CreateText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response" + Path.DirectorySeparatorChar + "dictionary.txt");
                                                log_file.WriteLine(line[4]);
                                                log_file.Close();
                                            }
                                            ircbot.sendData("PRIVMSG", channel + " :Response added successfully");
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :" + nick + ", you need to include more info.");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;
                                case "delresponse":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= tmp_command.Access)
                                    {
                                        if (line.GetUpperBound(0) > 3)
                                        {
                                            try
                                            {
                                                bool response_found = false;
                                                string list_file = ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response" + Path.DirectorySeparatorChar + "dictionary.txt";
                                                if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response" + Path.DirectorySeparatorChar + "") == false)
                                                {
                                                    Directory.CreateDirectory(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response");
                                                }
                                                if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response" + Path.DirectorySeparatorChar + "dictionary.txt"))
                                                {
                                                    string[] file = System.IO.File.ReadAllLines(list_file);

                                                    if (file.GetUpperBound(0) >= 0)
                                                    {
                                                        List<string> new_file = new List<string>();
                                                        int index = 1;
                                                        foreach (string tmp_new_line in file)
                                                        {
                                                            if (index == Convert.ToInt32(line[4]))
                                                            {
                                                                ircbot.sendData("NOTICE", nick + " :Response removed successfully.");
                                                                response_found = true;
                                                            }
                                                            else
                                                            {
                                                                new_file.Add(tmp_new_line);
                                                            }
                                                            index++;
                                                        }
                                                        System.IO.File.WriteAllLines(@list_file, new_file);
                                                    }
                                                    if (!response_found)
                                                    {
                                                        ircbot.sendData("NOTICE", nick + " :Unable to delete desired response.");
                                                    }
                                                }
                                                else
                                                {
                                                    StreamWriter log_file = File.CreateText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response" + Path.DirectorySeparatorChar + "dictionary.txt");
                                                    log_file.Close();
                                                }
                                            }
                                            catch
                                            {
                                                ircbot.sendData("NOTICE", nick + " :Please specify a valid number.");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :" + nick + ", you need to include more info.");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;
                                case "listresponse":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= tmp_command.Access)
                                    {
                                        string list_file = ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response" + Path.DirectorySeparatorChar + "dictionary.txt";
                                        if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response" + Path.DirectorySeparatorChar + "") == false)
                                        {
                                            Directory.CreateDirectory(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response");
                                        }
                                        if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response" + Path.DirectorySeparatorChar + "dictionary.txt"))
                                        {
                                            string[] file = System.IO.File.ReadAllLines(list_file);

                                            if (file.GetUpperBound(0) >= 0)
                                            {
                                                int index = 1;
                                                foreach (string tmp_new_line in file)
                                                {
                                                    ircbot.sendData("NOTICE", nick + " :[" + index + "] " + tmp_new_line);
                                                    Thread.Sleep(100);
                                                    index++;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            StreamWriter log_file = File.CreateText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response" + Path.DirectorySeparatorChar + "dictionary.txt");
                                            log_file.Close();
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;
                            }
                        }
                    }
                }
            }
            if (type.Equals("channel") && !bot_command)
            {
                if (!nick.Equals(ircbot.Nick, StringComparison.InvariantCultureIgnoreCase))
                {
                    string[] file;
                    string list_file = ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response" + Path.DirectorySeparatorChar + "dictionary.txt";
                    if (File.Exists(list_file))
                    {
                        file = System.IO.File.ReadAllLines(list_file);

                        string tmp_line = line[3];
                        if (line.GetUpperBound(0) > 3)
                        {
                            tmp_line += " " + line[4];
                        }
                        tmp_line = tmp_line.Remove(0, 1);
                        string new_line = tmp_line.ToLowerInvariant();
                        bool triggered = false;
                        if (file.GetUpperBound(0) >= 0)
                        {
                            foreach (string tmp_new_line in file)
                            {
                                char[] split_type = new char[] { ':' };
                                char[] trigger_split = new char[] { '*' };
                                char[] triggered_split = new char[] { '&' };
                                string[] split = tmp_new_line.Split(split_type, 3);
                                string[] channels = split[0].Split(',');
                                string[] triggers = split[1].Split('|');
                                string[] responses = split[2].Split('|');
                                bool response_allowed = false;
                                foreach (string chan in channels)
                                {
                                    if (chan.Equals(channel, StringComparison.InvariantCultureIgnoreCase) || chan.Equals(nick, StringComparison.InvariantCultureIgnoreCase) || chan.Equals("<all>"))
                                    {
                                        response_allowed = true;
                                    }
                                    if(chan.Equals("!" + nick, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        response_allowed = false;
                                        break;
                                    }
                                    if (chan.Equals("!" + channel, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        response_allowed = false;
                                        break;
                                    }
                                }
                                if (response_allowed)
                                {
                                    int index = 0;
                                    for (int x = 0; x <= triggers.GetUpperBound(0); x++)
                                    {
                                        string[] terms = triggers[x].Split(trigger_split, StringSplitOptions.RemoveEmptyEntries);
                                        for (int y = 0; y <= terms.GetUpperBound(0); y++)
                                        {
                                            triggered = false;
                                            terms[y] = terms[y].ToLowerInvariant();
                                            if (triggers[x].StartsWith("*") == false && triggers[x].EndsWith("*") == false && terms.GetUpperBound(0) == 0)
                                            {
                                                if (new_line.Equals(terms[y]) == true)
                                                {
                                                    triggered = true;
                                                }
                                                else
                                                {
                                                    triggered = false;
                                                    break;
                                                }
                                            }
                                            else if (triggers[x].StartsWith("*") == false && y == 0)
                                            {
                                                if (new_line.StartsWith(terms[y]) == true && index <= new_line.IndexOf(terms[y]))
                                                {
                                                    triggered = true;
                                                    index = new_line.IndexOf(terms[y]);
                                                }
                                                else
                                                {
                                                    triggered = false;
                                                    break;
                                                }
                                            }
                                            else if (triggers[x].EndsWith("*") == false && y == terms.GetUpperBound(0))
                                            {
                                                if (new_line.EndsWith(terms[y]) == true && index <= new_line.IndexOf(terms[y]))
                                                {
                                                    triggered = true;
                                                    index = new_line.IndexOf(terms[y]);
                                                }
                                                else
                                                {
                                                    triggered = false;
                                                    break;
                                                }
                                            }
                                            else
                                            {
                                                if (new_line.Contains(terms[y]) == true && index <= new_line.IndexOf(terms[y]))
                                                {
                                                    triggered = true;
                                                    index = new_line.IndexOf(terms[y]);
                                                }
                                                else
                                                {
                                                    triggered = false;
                                                    break;
                                                }
                                            }
                                        }
                                        if (triggered == true)
                                        {
                                            break;
                                        }
                                    }
                                    if (triggered == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                        int number_of_responses = responses.GetUpperBound(0) + 1;
                                        Random random = new Random();
                                        index = random.Next(0, number_of_responses);
                                        string file_line = responses[index].Replace("<nick>", nick);
                                        file_line = file_line.Replace("<me>", Conf.Nick);
                                        file_line = file_line.Replace("<chan>", channel);
                                        string[] events = file_line.Split(triggered_split, StringSplitOptions.RemoveEmptyEntries);
                                        for (int y = 0; y <= events.GetUpperBound(0); y++)
                                        {
                                            if (events[y].StartsWith("<cmd>") == true)
                                            {
                                                char[] charSplit = new char[] { ' ' };
                                                string[] ex = events[y].Remove(0, 5).Split(charSplit, 2);
                                                string[] args;
                                                if (ex.GetUpperBound(0) > 0)
                                                {
                                                    args = ex[1].Split(charSplit);
                                                }
                                                else
                                                {
                                                    args = null;
                                                }
                                                ircbot.controller.run_command(Conf.Server_Name, channel, ex[0], args);
                                            }
                                            else if (events[y].StartsWith("<delay>") == true)
                                            {
                                                Thread.Sleep(Convert.ToInt32(events[y].Remove(0, 7)));
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :" + events[y]);
                                            }
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (!Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response"))
                        {
                            Directory.CreateDirectory(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "Response");
                        }
                        File.Create(list_file);
                    }
                }
            }
        }
Example #40
0
        public override void control(bot ircbot, ref IRCConfig conf, int module_id, string[] line, string command, int nick_access, string nick, string channel, bool bot_command, string type)
        {
            string module_name = ircbot.conf.module_config[module_id][0];
            if (type.Equals("channel") && bot_command == true)
            {
                foreach (List<string> tmp_command in conf.command_list)
                {
                    if (module_name.Equals(tmp_command[0]))
                    {
                        string[] triggers = tmp_command[3].Split('|');
                        int command_access = Convert.ToInt32(tmp_command[5]);
                        string[] blacklist = tmp_command[6].Split(',');
                        bool blocked = false;
                        bool cmd_found = false;
                        bool spam_check = Convert.ToBoolean(tmp_command[8]);
                        foreach (string bl_chan in blacklist)
                        {
                            if (bl_chan.Equals(channel))
                            {
                                blocked = true;
                                break;
                            }
                        }
                        if (spam_check == true)
                        {
                            blocked = ircbot.get_spam_status(channel, nick);
                        }
                        foreach (string trigger in triggers)
                        {
                            if (trigger.Equals(command))
                            {
                                cmd_found = true;
                                break;
                            }
                        }
                        if (blocked == true && cmd_found == true)
                        {
                            ircbot.sendData("NOTICE", nick + " :I am currently too busy to process that.");
                        }
                        if (blocked == false && cmd_found == true)
                        {
                            foreach (string trigger in triggers)
                            {
                                switch (trigger)
                                {
                                    case "hbomb":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            int module_index = 0;
                                            foreach (Modules.Module module in ircbot.module_list)
                                            {
                                                string module_type = module.GetType().ToString();
                                                if (module_type.Equals("IRCBot.Modules.idle"))
                                                {
                                                    break;
                                                }
                                                else
                                                {
                                                    module_index++;
                                                }
                                            }
                                            Modules.idle idle;
                                            if (module_index < ircbot.module_list.Count())
                                            {
                                                idle = (Modules.idle)ircbot.module_list[module_index];
                                            }
                                            else
                                            {
                                                idle = new Modules.idle();
                                            }
                                            if (idle.check_idle(nick) == false)
                                            {
                                                bool hbomb_active = false;
                                                hbomb_info tmp_info = new hbomb_info();
                                                foreach (hbomb_info bomb in hbombs)
                                                {
                                                    if (bomb.bomb_channel.Equals(channel))
                                                    {
                                                        tmp_info = bomb;
                                                        hbomb_active = true;
                                                        break;
                                                    }
                                                }
                                                if (hbomb_active == false)
                                                {
                                                    tmp_info.bomb_locked = false;
                                                    tmp_info.bomb_trigger = new System.Timers.Timer();
                                                    tmp_info.wire_colors = ircbot.conf.module_config[module_id][3].Split(',');
                                                    tmp_info.bomb_channel = channel;

                                                    Random random_color = new Random();
                                                    int color_index = random_color.Next(0, tmp_info.wire_colors.GetUpperBound(0) + 1);
                                                    tmp_info.wire_color = tmp_info.wire_colors[color_index];

                                                    Random random = new Random();
                                                    int index = random.Next(10, 60);

                                                    tmp_info.bomb_trigger.Elapsed += (System, EventArgs) => activate_bomb(channel);
                                                    tmp_info.bomb_trigger.Interval = (index * 1000);
                                                    tmp_info.bomb_trigger.Enabled = true;
                                                    tmp_info.bomb_trigger.AutoReset = false;

                                                    main = ircbot;

                                                    tmp_info.previous_bomb_holder = nick;
                                                    tmp_info.bomb_holder = nick;

                                                    ircbot.sendData("PRIVMSG", channel + " :" + nick + " has started the timer!  If the bomb gets passed to you, type " + conf.command + "pass <nick> to pass it to someone else, or type " + conf.command + "defuse <color> to try to defuse it.");
                                                    string colors = "";
                                                    foreach (string wire in tmp_info.wire_colors)
                                                    {
                                                        colors += wire + ",";
                                                    }
                                                    ircbot.sendData("NOTICE", nick + " :You need to hurry and pass the bomb before it blows up!  Or you can try to defuse it yourself.  The colors are: " + colors.TrimEnd(','));
                                                    hbombs.Add(tmp_info);
                                                }
                                                else
                                                {
                                                    if (tmp_info.bomb_channel.Equals(channel))
                                                    {
                                                        ircbot.sendData("PRIVMSG", channel + " :There is already a bomb counting down.");
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("PRIVMSG", line[2] + " :There is already a bomb counting down in " + tmp_info.bomb_channel + ".");
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :You can not start a HBomb when you are idle.");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                    case "pass":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            int index = 0;
                                            bool hbomb_active = false;
                                            hbomb_info tmp_info = new hbomb_info();
                                            foreach (hbomb_info bomb in hbombs)
                                            {
                                                if (bomb.bomb_channel.Equals(channel))
                                                {
                                                    tmp_info = bomb;
                                                    hbomb_active = true;
                                                    break;
                                                }
                                                index++;
                                            }
                                            if (hbomb_active == true)
                                            {
                                                if (!tmp_info.bomb_locked)
                                                {
                                                    int module_index = 0;
                                                    foreach (Modules.Module module in ircbot.module_list)
                                                    {
                                                        string module_type = module.GetType().ToString();
                                                        if (module_type.Equals("IRCBot.Modules.idle"))
                                                        {
                                                            break;
                                                        }
                                                        else
                                                        {
                                                            module_index++;
                                                        }
                                                    }
                                                    Modules.idle idle;
                                                    if (module_index < ircbot.module_list.Count())
                                                    {
                                                        idle = (Modules.idle)ircbot.module_list[module_index];
                                                    }
                                                    else
                                                    {
                                                        idle = new Modules.idle();
                                                    }
                                                    if (idle.check_idle(nick) == false)
                                                    {
                                                        if (tmp_info.bomb_holder.Equals(nick))
                                                        {
                                                            if (line.GetUpperBound(0) > 3)
                                                            {
                                                                if (line[4].TrimEnd(' ').ToLower().Equals(conf.nick.ToLower()))
                                                                {
                                                                    ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you can't pass it to me!");
                                                                }
                                                                else
                                                                {
                                                                    int user_access = ircbot.get_user_access(line[4].TrimEnd(' ').ToLower(), channel);
                                                                    if (user_access > 0 && idle.check_idle(line[4].TrimEnd(' ').ToLower()) == false)
                                                                    {
                                                                        pass_hbomb(line[4].TrimEnd(' ').ToLower(), channel, nick, ircbot, conf, ref tmp_info, index);
                                                                    }
                                                                    else
                                                                    {
                                                                        ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you can't pass to them!");
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you need to pass the bomb to someone.");
                                                            }
                                                        }
                                                        else
                                                        {
                                                            ircbot.sendData("PRIVMSG", channel + " :You don't have the bomb!");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("PRIVMSG", channel + " :You can not pass the HBomb when you are idle.");
                                                    }
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :You can not pass a locked bomb.");
                                                }
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to pass!");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                    case "set_bomb":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            int index = 0;
                                            bool hbomb_active = false;
                                            hbomb_info tmp_info = new hbomb_info();
                                            foreach (hbomb_info bomb in hbombs)
                                            {
                                                if (bomb.bomb_channel.Equals(channel))
                                                {
                                                    tmp_info = bomb;
                                                    hbomb_active = true;
                                                    break;
                                                }
                                                index++;
                                            }
                                            if (hbomb_active == true)
                                            {
                                                if (line.GetUpperBound(0) > 3)
                                                {
                                                    if (line[4].TrimEnd(' ').ToLower().Equals(conf.nick.ToLower()))
                                                    {
                                                        ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you can't pass it to me!");
                                                    }
                                                    else
                                                    {
                                                        int user_access = ircbot.get_user_access(line[4].TrimEnd(' ').ToLower(), channel);
                                                        if (user_access > 0)
                                                        {
                                                            pass_hbomb(line[4].TrimEnd(' ').ToLower(), channel, nick, ircbot, conf, ref tmp_info, index);
                                                        }
                                                        else
                                                        {
                                                            ircbot.sendData("PRIVMSG", channel + " :" + nick + ", that user isn't online!");
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you need to pass the bomb to someone.");
                                                }

                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to pass!");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                    case "lock_bomb":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            int index = 0;
                                            bool hbomb_active = false;
                                            hbomb_info tmp_info = new hbomb_info();
                                            foreach (hbomb_info bomb in hbombs)
                                            {
                                                if (bomb.bomb_channel.Equals(channel))
                                                {
                                                    tmp_info = bomb;
                                                    hbomb_active = true;
                                                    break;
                                                }
                                                index++;
                                            }
                                            if (hbomb_active == true)
                                            {
                                                if (line.GetUpperBound(0) > 3)
                                                {
                                                    if (line[4].TrimEnd(' ').ToLower().Equals(conf.nick.ToLower()))
                                                    {
                                                        ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you can't pass it to me!");
                                                    }
                                                    else
                                                    {
                                                        int user_access = ircbot.get_user_access(line[4].TrimEnd(' ').ToLower(), channel);
                                                        if (user_access > 0)
                                                        {
                                                            pass_hbomb(line[4].TrimEnd(' ').ToLower(), channel, nick, ircbot, conf, ref tmp_info, index);
                                                            tmp_info.bomb_locked = true;
                                                        }
                                                        else
                                                        {
                                                            ircbot.sendData("PRIVMSG", channel + " :" + nick + ", that user isn't online!");
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    tmp_info.bomb_locked = true;
                                                }

                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to lock!");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                    case "unlock_bomb":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            int index = 0;
                                            bool hbomb_active = false;
                                            hbomb_info tmp_info = new hbomb_info();
                                            foreach (hbomb_info bomb in hbombs)
                                            {
                                                if (bomb.bomb_channel.Equals(channel))
                                                {
                                                    tmp_info = bomb;
                                                    hbomb_active = true;
                                                    break;
                                                }
                                                index++;
                                            }
                                            if (hbomb_active == true)
                                            {
                                                tmp_info.bomb_locked = false;
                                                hbombs[index] = tmp_info;
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to unlock!");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                    case "detonate":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            bool hbomb_active = false;
                                            foreach (hbomb_info bomb in hbombs)
                                            {
                                                if (bomb.bomb_channel.Equals(channel))
                                                {
                                                    hbomb_active = true;
                                                    break;
                                                }
                                            }
                                            if (hbomb_active == true)
                                            {
                                                main = ircbot;
                                                activate_bomb(channel);
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to blow up!");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                    case "stop_bomb":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            int index = 0;
                                            bool hbomb_active = false;
                                            hbomb_info tmp_info = new hbomb_info();
                                            foreach (hbomb_info bomb in hbombs)
                                            {
                                                if (bomb.bomb_channel.Equals(channel))
                                                {
                                                    tmp_info = bomb;
                                                    hbomb_active = true;
                                                    break;
                                                }
                                                index++;
                                            }
                                            if (hbomb_active == true)
                                            {
                                                hbombs.RemoveAt(index);
                                                ircbot.sendData("PRIVMSG", channel + " :Bomb has been defused and thrown away.");
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to stop!");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                    case "defuse":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            int index = 0;
                                            bool hbomb_active = false;
                                            hbomb_info tmp_info = new hbomb_info();
                                            foreach (hbomb_info bomb in hbombs)
                                            {
                                                if (bomb.bomb_channel.Equals(channel))
                                                {
                                                    tmp_info = bomb;
                                                    hbomb_active = true;
                                                    break;
                                                }
                                                index++;
                                            }
                                            if (hbomb_active == true)
                                            {
                                                if (!tmp_info.bomb_locked)
                                                {
                                                    int module_index = 0;
                                                    foreach (Modules.Module module in ircbot.module_list)
                                                    {
                                                        string module_type = module.GetType().ToString();
                                                        if (module_type.Equals("IRCBot.Modules.idle"))
                                                        {
                                                            break;
                                                        }
                                                        else
                                                        {
                                                            module_index++;
                                                        }
                                                    }
                                                    Modules.idle idle;
                                                    if (module_index < ircbot.module_list.Count())
                                                    {
                                                        idle = (Modules.idle)ircbot.module_list[module_index];
                                                    }
                                                    else
                                                    {
                                                        idle = new Modules.idle();
                                                    }
                                                    if (idle.check_idle(nick) == false)
                                                    {
                                                        if (tmp_info.bomb_holder.Equals(nick))
                                                        {
                                                            if (line.GetUpperBound(0) > 3)
                                                            {
                                                                if (line[4].ToLower().Equals(tmp_info.wire_color.ToLower()))
                                                                {
                                                                    ircbot.sendData("PRIVMSG", channel + " :You have successfully defused the bomb!");
                                                                    if (tmp_info.previous_bomb_holder.Equals(tmp_info.bomb_holder))
                                                                    {
                                                                    }
                                                                    else
                                                                    {
                                                                        ircbot.sendData("KICK", tmp_info.bomb_channel + " " + tmp_info.previous_bomb_holder + " :BOOM!!!");
                                                                    }
                                                                    hbombs.RemoveAt(index);
                                                                }
                                                                else
                                                                {
                                                                    main = ircbot;
                                                                    activate_bomb(channel);
                                                                }
                                                            }
                                                            else
                                                            {
                                                                ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you need to cut a wire.");
                                                            }
                                                        }
                                                        else
                                                        {
                                                            ircbot.sendData("PRIVMSG", channel + " :You don't have the bomb!");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("PRIVMSG", channel + " :You can not defuse the HBomb when you are idle.");
                                                    }
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :You can not defuse the HBomb when it is locked.");
                                                }
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to defuse!");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                }
                            }
                        }
                    }
                }
            }
        }
Example #41
0
        private void pass_hbomb(string pass_nick, string channel, string nick, bot ircbot, BotConfig Conf, ref hbomb_info tmp_info, int index)
        {
            string tab_name = channel.TrimStart('#');
            string pattern = "[^a-zA-Z0-9]"; //regex pattern
            tab_name = Regex.Replace(tab_name, pattern, "_");
            bool nick_idle = false;

            Modules.seen seen = (Modules.seen)ircbot.get_module("seen");
            DateTime current_date = DateTime.Now;
            DateTime past_date = seen.get_seen_time(nick, channel, ircbot);
            double difference_second = 0;
            difference_second = current_date.Subtract(past_date).TotalSeconds;
            if (difference_second >= 600)
            {
                nick_idle = true;
            }
            if (nick_idle == false)
            {
                tmp_info.bomb_holder = pass_nick;
                tmp_info.previous_bomb_holder = nick;
                hbombs[index] = tmp_info;
                ircbot.sendData("PRIVMSG", channel + " :" + nick + " passed the bomb to " + pass_nick);
                ircbot.sendData("NOTICE", pass_nick + " :You now have the bomb!  Type " + ircbot.Conf.Command + "pass <nick> to pass it to someone else, or type " + ircbot.Conf.Command + "defuse <color> to try to defuse it.");
                string colors = "";
                foreach (string wire in tmp_info.wire_colors)
                {
                    colors += wire + ",";
                }
                ircbot.sendData("NOTICE", pass_nick + " :The colors of the wires are: " + colors);
            }
            else
            {
                ircbot.sendData("PRIVMSG", channel + " :Dang, you missed them! (Idle)");
            }
        }
Example #42
0
        public void set_access_list(string nick, string channel, string access, bot ircbot)
        {
            string file_name = ircbot.Conf.Server_Name + "_list.txt";

            if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "access" + Path.DirectorySeparatorChar + "") == false)
            {
                Directory.CreateDirectory(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "access");
            }
            if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "access" + Path.DirectorySeparatorChar + file_name))
            {
                string[] log_file = System.IO.File.ReadAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "access" + Path.DirectorySeparatorChar + file_name);
                int number_of_lines = log_file.GetUpperBound(0) + 1;
                List<string> new_file = new List<string>();
                int index = 0;
                bool nick_found = false;
                if (number_of_lines > 0)
                {
                    foreach (string lines in log_file)
                    {
                        char[] sep = new char[] { '*' };
                        string[] new_line = lines.Split(sep, 3);
                        if (new_line.GetUpperBound(0) > 0)
                        {
                            if (new_line[0].Trim().Equals(nick, StringComparison.InvariantCultureIgnoreCase) && new_line[1].Trim().Equals(channel, StringComparison.InvariantCultureIgnoreCase))
                            {
                                string[] tmp_line = new_line[2].Trim().Split(',');
                                bool access_found = false;
                                foreach (string line in tmp_line)
                                {
                                    if (line.Equals(access))
                                    {
                                        access_found = true;
                                    }
                                }
                                if (access_found == false)
                                {
                                    if (String.IsNullOrEmpty(new_line[2].Trim()))
                                    {
                                        new_file.Add(new_line[0].Trim() + "*" + new_line[1].Trim() + "*" + access);
                                    }
                                    else
                                    {
                                        new_file.Add(new_line[0].Trim() + "*" + new_line[1].Trim() + "*" + new_line[2].Trim() + "," + access);
                                    }
                                }
                                nick_found = true;
                            }
                            else
                            {
                                new_file.Add(lines);
                            }
                            index++;
                        }
                    }
                    if (nick_found == false)
                    {
                        StreamWriter log = File.AppendText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "access" + Path.DirectorySeparatorChar + file_name);
                        log.WriteLine(nick + "*" + channel + "*" + access);
                        log.Close();
                    }
                    else
                    {
                        System.IO.File.WriteAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "access" + Path.DirectorySeparatorChar + file_name, new_file);
                    }
                }
                else
                {
                    StreamWriter log = File.AppendText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "access" + Path.DirectorySeparatorChar + file_name);
                    log.WriteLine(nick + "*" + channel + "*" + access);
                    log.Close();
                }
            }
            else
            {
                StreamWriter log_file = File.CreateText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "access" + Path.DirectorySeparatorChar + file_name);
                log_file.WriteLine(nick.Trim() + "*" + channel + "*" + access.Trim());
                log_file.Close();
            }
        }
Example #43
0
        public List<int> get_access_list(string nick, string channel, bot ircbot)
        {
            string file_name = ircbot.Conf.Server_Name + "_list.txt";
            List<int> access = new List<int>();

            if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "access" + Path.DirectorySeparatorChar + file_name))
            {
                string[] log_file = System.IO.File.ReadAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "access" + Path.DirectorySeparatorChar + file_name);
                int number_of_lines = log_file.GetUpperBound(0) + 1;
                if (number_of_lines > 0)
                {
                    foreach (string line in log_file)
                    {
                        char[] sep = new char[] { '*' };
                        string[] new_line = line.Split(sep, 3);
                        if (new_line.GetUpperBound(0) > 1)
                        {
                            if (channel != null)
                            {
                                if (new_line[0].Trim().Equals(nick, StringComparison.InvariantCultureIgnoreCase) && new_line[1].Trim().Equals(channel, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    try
                                    {
                                        access.Add(Convert.ToInt32(new_line[2]));
                                    }
                                    catch { }
                                }
                            }
                        }
                    }
                }
            }
            return access;
        }
Example #44
0
 public override void control(bot ircbot, BotConfig Conf, string[] line, string command, int nick_access, string nick, string channel, bool bot_command, string type)
 {
     if ((type.Equals("channel") || type.Equals("query")) && bot_command == true)
     {
         foreach (Command tmp_command in this.Commands)
         {
             bool blocked = tmp_command.Blacklist.Contains(channel) || tmp_command.Blacklist.Contains(nick);
             bool cmd_found = false;
             bool spam_check = ircbot.get_spam_check(channel, nick, tmp_command.Spam_Check);
             if (spam_check == true)
             {
                 blocked = blocked || ircbot.get_spam_status(channel);
             }
             cmd_found = tmp_command.Triggers.Contains(command);
             if (blocked == true && cmd_found == true)
             {
                 ircbot.sendData("NOTICE", nick + " :I am currently too busy to process that.");
             }
             if (blocked == false && cmd_found == true)
             {
                 foreach (string trigger in tmp_command.Triggers)
                 {
                     switch (trigger)
                     {
                         case "setaccess":
                             if (spam_check == true)
                             {
                                 ircbot.add_spam_count(channel);
                             }
                             if (nick_access >= tmp_command.Access)
                             {
                                 if (line.GetUpperBound(0) > 3)
                                 {
                                     string[] parse = line[4].Split(' ');
                                     if (type.Equals("query") && parse.GetUpperBound(0) > 1)
                                     {
                                         if (Convert.ToInt32(parse[2]) <= nick_access)
                                         {
                                             set_access_list(parse[0].Trim(), parse[1], parse[2], ircbot);
                                             ircbot.sendData("NOTICE", nick + " :" + parse[0].Trim() + " has been added to access level " + parse[2]);
                                         }
                                         else
                                         {
                                             ircbot.sendData("NOTICE", nick + " :You do not have permission to change their access.");
                                         }
                                     }
                                     else if (type.Equals("channel") && parse.GetUpperBound(0) > 0)
                                     {
                                         if (Convert.ToInt32(parse[1]) <= nick_access)
                                         {
                                             set_access_list(parse[0].Trim(), channel, parse[1], ircbot);
                                             ircbot.sendData("NOTICE", nick + " :" + parse[0].Trim() + " has been added to access level " + parse[1]);
                                         }
                                         else
                                         {
                                             ircbot.sendData("NOTICE", nick + " :You do not have permission to change their access.");
                                         }
                                     }
                                     else
                                     {
                                         ircbot.sendData("NOTICE", nick + " :" + nick + ", you need to include more info.");
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :" + nick + ", you need to include more info.");
                                 }
                             }
                             else
                             {
                                 ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                             }
                             break;
                         case "delaccess":
                             if (spam_check == true)
                             {
                                 ircbot.add_spam_count(channel);
                             }
                             if (nick_access >= tmp_command.Access)
                             {
                                 if (line.GetUpperBound(0) > 3)
                                 {
                                     string[] parse = line[4].Split(' ');
                                     if (type.Equals("query") && parse.GetUpperBound(0) > 1)
                                     {
                                         if (Convert.ToInt32(parse[2]) <= nick_access)
                                         {
                                             del_access_list(parse[0].Trim(), parse[1], parse[2], ircbot);
                                             ircbot.sendData("NOTICE", nick + " :" + parse[0].Trim() + " has been removed from access level " + parse[2]);
                                         }
                                         else
                                         {
                                             ircbot.sendData("NOTICE", nick + " :You do not have permission to change their access.");
                                         }
                                     }
                                     else if (type.Equals("channel") && parse.GetUpperBound(0) > 0)
                                     {
                                         if (Convert.ToInt32(parse[1]) <= nick_access)
                                         {
                                             del_access_list(parse[0].Trim(), channel, parse[1], ircbot);
                                             ircbot.sendData("NOTICE", nick + " :" + parse[0].Trim() + " has been removed from access level " + parse[1]);
                                         }
                                         else
                                         {
                                             ircbot.sendData("NOTICE", nick + " :You do not have permission to change their access.");
                                         }
                                     }
                                     else
                                     {
                                         ircbot.sendData("NOTICE", nick + " :" + nick + ", you need to include more info.");
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :" + nick + ", you need to include more info.");
                                 }
                             }
                             else
                             {
                                 ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                             }
                             break;
                         case "listaccess":
                             if (spam_check == true)
                             {
                                 ircbot.add_spam_count(channel);
                             }
                             if (nick_access >= tmp_command.Access)
                             {
                                 if (type.Equals("query") && line.GetUpperBound(0) > 3)
                                 {
                                     list_access_list(nick, line[4], ircbot);
                                 }
                                 else if (type.Equals("channel"))
                                 {
                                     list_access_list(nick, channel, ircbot);
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :" + nick + ", you need to include more info.");
                                 }
                             }
                             else
                             {
                                 ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                             }
                             break;
                         case "getaccess":
                             if (spam_check == true)
                             {
                                 ircbot.add_spam_count(channel);
                             }
                             if (nick_access >= tmp_command.Access)
                             {
                                 if (line.GetUpperBound(0) > 3)
                                 {
                                     string[] new_line = line[4].Split(' ');
                                     if (new_line.GetUpperBound(0) > 0 && new_line[0].StartsWith("#"))
                                     {
                                         int viewed_access = ircbot.get_nick_access(new_line[1].Trim(), new_line[0].Trim());
                                         ircbot.sendData("NOTICE", nick + " :" + new_line[1].Trim() + " has access level " + viewed_access.ToString());
                                     }
                                     else if (type.Equals("channel"))
                                     {
                                         int viewed_access = ircbot.get_nick_access(line[4].Trim(), channel);
                                         ircbot.sendData("NOTICE", nick + " :" + line[4].Trim() + " has access level " + viewed_access.ToString());
                                     }
                                     else
                                     {
                                         int viewed_access = Conf.Default_Level;
                                         foreach (Channel_Info chan in Conf.Channel_List)
                                         {
                                             int tmp_nick_access = ircbot.get_nick_access(line[4].Trim(), chan.Channel);
                                             if (tmp_nick_access > viewed_access)
                                             {
                                                 viewed_access = tmp_nick_access;
                                             }
                                         }
                                         ircbot.sendData("NOTICE", nick + " :" + line[4].Trim() + " has access level " + viewed_access.ToString());
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :" + nick + ", you need to include more info.");
                                 }
                             }
                             else
                             {
                                 ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                             }
                             break;
                     }
                 }
             }
         }
     }
 }
Example #45
0
        public void del_access_list(string nick, string channel, string access, bot ircbot)
        {
            string file_name = ircbot.Conf.Server_Name + "_list.txt";

            if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "access" + Path.DirectorySeparatorChar + "") == false)
            {
                Directory.CreateDirectory(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "access");
            }
            if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "access" + Path.DirectorySeparatorChar + file_name))
            {
                string[] log_file = System.IO.File.ReadAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "access" + Path.DirectorySeparatorChar + file_name);
                int number_of_lines = log_file.GetUpperBound(0) + 1;
                List<string> new_file = new List<string>();
                if (number_of_lines > 0)
                {
                    foreach (string lines in log_file)
                    {
                        char[] sep = new char[] { '*' };
                        string[] new_line = lines.Split(sep, 3);
                        if (new_line.GetUpperBound(0) > 0)
                        {
                            if (new_line[0].Trim().Equals(nick, StringComparison.InvariantCultureIgnoreCase) && new_line[1].Trim().Equals(channel, StringComparison.InvariantCultureIgnoreCase))
                            {
                                string[] tmp_line = new_line[2].Trim().Split(',');
                                string new_access = "";
                                foreach (string line in tmp_line)
                                {
                                    if (line.Equals(access))
                                    {
                                    }
                                    else
                                    {
                                        new_access += "," + line;
                                    }
                                }
                                if (String.IsNullOrEmpty(new_access.TrimStart(',').TrimEnd(',')))
                                {
                                    new_file.Add(new_line[0].Trim() + "*" + new_line[1].Trim() + "*" + new_access.TrimStart(',').TrimEnd(','));
                                }
                            }
                            else
                            {
                                new_file.Add(lines);
                            }
                        }
                    }
                    System.IO.File.WriteAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "access" + Path.DirectorySeparatorChar + file_name, new_file);
                }
            }
        }
Example #46
0
 public override void control(bot ircbot, ref IRCConfig conf, int module_id, string[] line, string command, int nick_access, string nick, string channel, bool bot_command, string type)
 {
     string module_name = ircbot.conf.module_config[module_id][0];
     if ((type.Equals("channel") || type.Equals("query")) && bot_command == true)
     {
         foreach (List<string> tmp_command in conf.command_list)
         {
             if (module_name.Equals(tmp_command[0]))
             {
                 string[] triggers = tmp_command[3].Split('|');
                 int command_access = Convert.ToInt32(tmp_command[5]);
                 string[] blacklist = tmp_command[6].Split(',');
                 bool blocked = false;
                 bool cmd_found = false;
                 bool spam_check = Convert.ToBoolean(tmp_command[8]);
                 foreach (string bl_chan in blacklist)
                 {
                     if (bl_chan.Equals(channel))
                     {
                         blocked = true;
                         break;
                     }
                 }
                 if (spam_check == true)
                 {
                     blocked = ircbot.get_spam_status(channel, nick);
                 }
                 foreach (string trigger in triggers)
                 {
                     if (trigger.Equals(command))
                     {
                         cmd_found = true;
                         break;
                     }
                 }
                 if (blocked == true && cmd_found == true)
                 {
                     ircbot.sendData("NOTICE", nick + " :I am currently too busy to process that.");
                 }
                 if (blocked == false && cmd_found == true)
                 {
                     foreach (string trigger in triggers)
                     {
                         switch (trigger)
                         {
                             case "last":
                                 if (spam_check == true)
                                 {
                                     ircbot.add_spam_count(channel);
                                 }
                                 if (nick_access >= command_access)
                                 {
                                     if (line.GetUpperBound(0) > 3)
                                     {
                                         string[] args = line[4].Split(' ');
                                         if (type.Equals("channel"))
                                         {
                                             if (args.GetUpperBound(0) > 1)
                                             {
                                                 int n;
                                                 bool isNumeric = int.TryParse(args[2], out n);
                                                 if (isNumeric)
                                                 {
                                                     display_log_nick_num(args[1], Convert.ToInt32(args[2]), channel, nick, args[0], ircbot, conf);
                                                 }
                                                 else
                                                 {
                                                     ircbot.sendData("NOTICE", nick + " :" + nick + ", you need to specify a valid number.");
                                                 }
                                             }
                                             else if (args.GetUpperBound(0) > 0)
                                             {
                                                 int n;
                                                 bool isNumeric = int.TryParse(args[1], out n);
                                                 if (isNumeric)
                                                 {
                                                     display_log_number(Convert.ToInt32(args[1]), channel, nick, args[0], ircbot, conf);
                                                 }
                                                 else
                                                 {
                                                     display_log_nick(args[1], channel, nick, args[0], ircbot, conf);
                                                 }
                                             }
                                             else
                                             {
                                                 display_log(channel, nick, line[4], ircbot, conf);
                                             }
                                         }
                                         else
                                         {
                                             if (args.GetUpperBound(0) > 0)
                                             {
                                                 display_log_nick(args[1], channel, nick, args[0], ircbot, conf);
                                             }
                                             else
                                             {
                                                 display_log(channel, nick, line[4], ircbot, conf);
                                             }
                                         }
                                     }
                                     else
                                     {
                                         display_last_log(channel, nick, ircbot, conf);
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                 }
                                 break;
                         }
                     }
                 }
             }
         }
     }
     if (type.Equals("query") && bot_command == true)
     {
         bool command_valid = false;
         foreach (List<string> tmp_command in conf.command_list)
         {
             string[] triggers = tmp_command[3].Split('|');
             foreach (string trigger in triggers)
             {
                 if (command.Equals(trigger))
                 {
                     command_valid = true;
                     break;
                 }
             }
             if (command_valid == true)
             {
                 break;
             }
         }
         if (command_valid == true)
         {
             add_log(nick, "a private message", line, ircbot);
         }
     }
     if (type.Equals("channel") && bot_command == true)
     {
         bool command_valid = false;
         foreach (List<string> tmp_command in conf.command_list)
         {
             string[] triggers = tmp_command[3].Split('|');
             foreach (string trigger in triggers)
             {
                 if (command.Equals(trigger))
                 {
                     command_valid = true;
                     break;
                 }
             }
             if (command_valid == true)
             {
                 break;
             }
         }
         if (command_valid == true)
         {
             add_log(nick, channel, line, ircbot);
         }
     }
 }
Example #47
0
        public void list_access_list(string nick, string channel, bot ircbot)
        {
            string file_name = ircbot.Conf.Server_Name + "_list.txt";

            if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "access" + Path.DirectorySeparatorChar + file_name))
            {
                string[] log_file = System.IO.File.ReadAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "access" + Path.DirectorySeparatorChar + file_name);
                int number_of_lines = log_file.GetUpperBound(0) + 1;
                if (number_of_lines > 0)
                {
                    string access_msg = "";
                    foreach (string line in log_file)
                    {
                        char[] sep = new char[] { '*' };
                        string[] new_line = line.Split(sep, 3);
                        if (new_line.GetUpperBound(0) > 0)
                        {
                            if (new_line[1].Equals(channel))
                            {
                                access_msg += " | " + new_line[0] + ": " + new_line[2];
                            }
                        }
                    }
                    if (!String.IsNullOrEmpty(access_msg))
                    {
                        ircbot.sendData("NOTICE", nick + " :" + access_msg.Trim().TrimStart('|').Trim());
                        ircbot.sendData("NOTICE", nick + " :End of Access List");
                    }
                    else
                    {
                        ircbot.sendData("NOTICE", nick + " :No users in Access List.");
                    }
                }
                else
                {
                    ircbot.sendData("NOTICE", nick + " :No users in Access List.");
                }
            }
            else
            {
                ircbot.sendData("NOTICE", nick + " :No users in Access List.");
            }
        }
Example #48
0
 private void display_log_number(int number, string channel, string requst_nick, string command, bot ircbot, IRCConfig conf)
 {
     string file_name = ircbot.server_name + ".log";
     bool cmd_found = false;
     if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "logging" + Path.DirectorySeparatorChar + file_name))
     {
         string[] log_file = System.IO.File.ReadAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "logging" + Path.DirectorySeparatorChar + file_name);
         int number_of_lines = log_file.GetUpperBound(0) + 1;
         List<List<string>> command_list = new List<List<string>>();
         if (number_of_lines > 0)
         {
             int num_uses = 0;
             string parameters = "";
             string date = "";
             string inside = "";
             string nick = "";
             foreach (string line in log_file)
             {
                 List<string> tmp_list = new List<string>();
                 char[] sep = new char[] { '*' };
                 string[] new_line = line.Split(sep, 5);
                 if (new_line.GetUpperBound(0) > 0)
                 {
                     if (new_line[3].Equals(command))
                     {
                         tmp_list.Add(new_line[0]);
                         tmp_list.Add(new_line[1]);
                         tmp_list.Add(new_line[2]);
                         tmp_list.Add(new_line[3]);
                         tmp_list.Add(new_line[4]);
                         command_list.Add(tmp_list);
                         num_uses++;
                         cmd_found = true;
                     }
                 }
             }
             if (cmd_found == true)
             {
                 if (number < num_uses && number >= 0)
                 {
                     if (command_list[number][4] != "")
                     {
                         parameters = " with the following argument: " + command_list[number][4];
                     }
                     else
                     {
                         parameters = "";
                     }
                     date = command_list[number][2];
                     inside = command_list[number][1];
                     nick = command_list[number][0];
                     ircbot.sendData("NOTICE", requst_nick + " :" + conf.command + command + " was used by " + nick + " on " + date + " in " + inside + parameters);
                 }
                 else
                 {
                     ircbot.sendData("NOTICE", requst_nick + " :The command has not been used that many times");
                 }
             }
             else
             {
                 foreach (string line in log_file)
                 {
                     List<string> tmp_list = new List<string>();
                     char[] sep = new char[] { '*' };
                     string[] new_line = line.Split(sep, 5);
                     if (new_line.GetUpperBound(0) > 0)
                     {
                         if (new_line[0].Equals(command))
                         {
                             tmp_list.Add(new_line[0]);
                             tmp_list.Add(new_line[1]);
                             tmp_list.Add(new_line[2]);
                             tmp_list.Add(new_line[3]);
                             tmp_list.Add(new_line[4]);
                             command_list.Add(tmp_list);
                             num_uses++;
                             cmd_found = true;
                         }
                     }
                 }
                 if (number < num_uses && number >= 0)
                 {
                     if (command_list[number][4] != "")
                     {
                         parameters = " with the following argument: " + command_list[number][4];
                     }
                     else
                     {
                         parameters = "";
                     }
                     date = command_list[number][2];
                     inside = command_list[number][1];
                     nick = command_list[number][0];
                     ircbot.sendData("NOTICE", requst_nick + " :" + nick + " used " + conf.command + command_list[number][3] + " on " + date + " in " + inside + parameters);
                 }
                 else
                 {
                     ircbot.sendData("NOTICE", requst_nick + " :The command has not been used that many times");
                 }
             }
         }
         else
         {
             ircbot.sendData("NOTICE", requst_nick + " :" + conf.command + command + " has not been used");
         }
     }
     else
     {
         ircbot.sendData("NOTICE", requst_nick + " :" + conf.command + command + " has not been used");
     }
 }
        public bool IsSafeToFinish(bot.BotState state)
        {
            bool finishableSuperRegion = true;
            string opponentName = state.OpponentPlayerName;
            string myName = state.MyPlayerName;

            // if superregion has enemy or is already bordered by enemy, then its not very safe
            // might aswell not consider it finishable and don't waste armies on it
            // unless it is only bordering in a single territory and we have stack advantage/equality on it
            foreach (Region reg in SubRegions)
            {
                Region rn = state.FullMap.GetRegion(reg.Id);
                if (rn.OwnedByPlayer(opponentName))
                {
                    finishableSuperRegion = false;
                    break;
                }
                foreach (Region neigh in rn.Neighbors)
                {
                    Region ni = state.FullMap.GetRegion(neigh.Id);
                    if (ni.OwnedByPlayer(opponentName))
                    {
                        // enemy is bordering, beware

                        // check with how many armies and how many areas is the enemy bordering us
                        int nborders = 0;
                        int enarmies = 0;
                        int ourarmies = 0;
                        foreach (Region ourregions in ni.Neighbors)
                        {
                            Region our = state.FullMap.GetRegion(ourregions.Id);
                            if (our.OwnedByPlayer(myName))
                            {
                                nborders++;
                                ourarmies = our.Armies;
                                enarmies = ni.Armies;
                            }
                        }

                        // if it's a 1 on 1 border and we have stack equality give or take a couple armies
                        // or stacks are higher then 20
                        // let it proceed (superregion is still finishable)
                        if (((nborders == 1) && (ourarmies + 2 >= enarmies)) || ((nborders == 1) && (ourarmies > 20))) continue;

                        // else, it's a bad idea to finish this region
                        finishableSuperRegion = false;
                        break;
                    }
                }
                if (!finishableSuperRegion) break;
            }

            return finishableSuperRegion;
        }
        public List<DeployArmies> DeployBorderingEnemy(bot.BotState state, int armiesLeft)
        {
            String myName = state.MyPlayerName;
            List<DeployArmies> deployArmies = new List<DeployArmies>();

            if (state.EnemyBorders.Count > 0)
            {

                List<Region> listofregions = new List<Region>();

                foreach (Region reg in state.EnemyBorders)
                {
                    bool enemysr = state.FullMap.RegionBelongsToEnemySuperRegion(reg.Id, myName);

                    // let's assume enemy will never finish asia
                    // yes, it might be dangerous on games that drag out
                    // but a lot less dangerous then deploying in egypt and leaving north africa wide open on a regular basis
                    if (reg.SuperRegion.Id == 5) enemysr = false;

                    foreach (Region regn in reg.Neighbors)
                    {
                        Region rn = state.FullMap.GetRegion(regn.Id);
                        if (rn.OwnedByPlayer(myName))
                        {
                            int count = 1;

                            // if the threat is coming from a superregion the enemy owns
                            if (enemysr)
                            {
                                count += 10;
                            }

                            // if the threat is to a region belonging to a superregion we own
                            if (state.FullMap.RegionBelongsToOurSuperRegion(rn.Id, myName))
                            {
                                count += 12;
                            }

                            // if the threat is to a region bordering a superregion we own
                            if (state.FullMap.RegionBordersOneOfOurOwnSuperRegions(rn.Id))
                            {
                                count += 8;
                            }

                            // if the threat is to a region being double bordered by enemy
                            int countenemy = 0;
                            foreach (Region nnnn in rn.Neighbors)
                            {
                                Region nnn = state.FullMap.GetRegion(nnnn.Id);
                                if (nnn.OwnedByPlayer(state.OpponentPlayerName)) countenemy++;
                            }
                            if (countenemy > 1) count += 1;

                            // if the threat is to a crucial area like brazil or north africa, little boost
                            if ((rn.Id == 12) || (rn.Id == 21))
                            {
                                count++;
                            }

                            // the more armies it has the more it should be the source of our income
                            count += rn.Armies % 6;

                            rn.tempSortValue = count;

                            if (!listofregions.Contains(rn)) listofregions.Add(rn);
                        }
                    }
                }

                List<Region> lst = listofregions.OrderByDescending(p => p.tempSortValue).ToList();

                state.HotStackZone = lst[0].Id;

                // dispel hotstackzone if it has double the number of armies of all the enemy neighbours combined
                Region hreg = state.FullMap.GetRegion(state.HotStackZone);
                int enemycount = 0;
                foreach (Region regn in hreg.Neighbors)
                {
                    Region nn = state.FullMap.GetRegion(regn.Id);
                    if (nn.OwnedByPlayer(state.OpponentPlayerName))
                    {
                        enemycount += nn.Armies;
                    }
                }
                if (hreg.Armies > enemycount * 2) state.HotStackZone = -1;

                while (armiesLeft > 0)
                {
                    foreach (Region rn in lst)
                    {
                        // higher distribution to top of heap
                        int rand = Random.Next(lst[0].tempSortValue + 1);
                        if (rand > rn.tempSortValue) continue;

                        // while we have armies left, use them
                        if (rn.OwnedByPlayer(state.MyPlayerName))
                        {
                            deployArmies.Add(new DeployArmies(state.MyPlayerName, rn, 1));
                            rn.PledgedArmies += 1;
                            armiesLeft--;
                            if (armiesLeft == 0) break;
                        }
                    }

                }
            }
            return deployArmies;
        }
Example #51
0
        public override void control(bot ircbot, BotConfig Conf, string[] line, string command, int nick_access, string nick, string channel, bool bot_command, string type)
        {
            if (type.Equals("channel") && bot_command == true)
            {
                foreach (Command tmp_command in this.Commands)
                {
                    bool blocked = tmp_command.Blacklist.Contains(channel) || tmp_command.Blacklist.Contains(nick);
                    bool cmd_found = false;
                    bool spam_check = ircbot.get_spam_check(channel, nick, tmp_command.Spam_Check);
                    if (spam_check == true)
                    {
                        blocked = blocked || ircbot.get_spam_status(channel);
                    }
                    cmd_found = tmp_command.Triggers.Contains(command);
                    if (blocked == true && cmd_found == true)
                    {
                        ircbot.sendData("NOTICE", nick + " :I am currently too busy to process that.");
                    }
                    if (blocked == false && cmd_found == true)
                    {
                        foreach (string trigger in tmp_command.Triggers)
                        {
                            switch (trigger)
                            {
                                case "hbomb":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= tmp_command.Access)
                                    {
                                        Modules.idle idle = (Modules.idle)ircbot.get_module("idle");
                                        if (idle.check_idle(nick) == false)
                                        {
                                            bool hbomb_active = false;
                                            hbomb_info tmp_info = new hbomb_info();
                                            foreach (hbomb_info bomb in hbombs)
                                            {
                                                if (bomb.bomb_channel.Equals(channel))
                                                {
                                                    tmp_info = bomb;
                                                    hbomb_active = true;
                                                    break;
                                                }
                                            }
                                            if (hbomb_active == false)
                                            {
                                                tmp_info.bomb_locked = false;
                                                tmp_info.bomb_trigger = new System.Timers.Timer();
                                                tmp_info.wire_colors = this.Options["wire_colors"].Split(',');
                                                tmp_info.bomb_channel = channel;

                                                Random random_color = new Random();
                                                int color_index = random_color.Next(0, tmp_info.wire_colors.GetUpperBound(0) + 1);
                                                tmp_info.wire_color = tmp_info.wire_colors[color_index];

                                                Random random = new Random();
                                                int index = random.Next(10, 60);

                                                tmp_info.bomb_trigger.Elapsed += (System, EventArgs) => activate_bomb(channel);
                                                tmp_info.bomb_trigger.Interval = (index * 1000);
                                                tmp_info.bomb_trigger.Enabled = true;
                                                tmp_info.bomb_trigger.AutoReset = false;

                                                main = ircbot;

                                                tmp_info.previous_bomb_holder = nick;
                                                tmp_info.bomb_holder = nick;

                                                ircbot.sendData("PRIVMSG", channel + " :" + nick + " has started the timer!  If the bomb gets passed to you, type " + ircbot.Conf.Command + "pass <nick> to pass it to someone else, or type " + ircbot.Conf.Command + "defuse <color> to try to defuse it.");
                                                string colors = "";
                                                foreach (string wire in tmp_info.wire_colors)
                                                {
                                                    colors += wire + ",";
                                                }
                                                ircbot.sendData("NOTICE", nick + " :You need to hurry and pass the bomb before it blows up!  Or you can try to defuse it yourself.  The colors are: " + colors.TrimEnd(','));
                                                hbombs.Add(tmp_info);
                                            }
                                            else
                                            {
                                                if (tmp_info.bomb_channel.Equals(channel))
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :There is already a bomb counting down.");
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :There is already a bomb counting down in " + tmp_info.bomb_channel + ".");
                                                }
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :You can not start a HBomb when you are idle.");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;
                                case "pass":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= tmp_command.Access)
                                    {
                                        int index = 0;
                                        bool hbomb_active = false;
                                        hbomb_info tmp_info = new hbomb_info();
                                        foreach (hbomb_info bomb in hbombs)
                                        {
                                            if (bomb.bomb_channel.Equals(channel))
                                            {
                                                tmp_info = bomb;
                                                hbomb_active = true;
                                                break;
                                            }
                                            index++;
                                        }
                                        if (hbomb_active == true)
                                        {
                                            if (!tmp_info.bomb_locked)
                                            {
                                                Modules.idle idle = (Modules.idle)ircbot.get_module("idle");
                                                if (idle.check_idle(nick) == false)
                                                {
                                                    if (tmp_info.bomb_holder.Equals(nick, StringComparison.InvariantCultureIgnoreCase))
                                                    {
                                                        if (line.GetUpperBound(0) > 3)
                                                        {
                                                            if (line[4].Trim().Equals(ircbot.Nick, StringComparison.InvariantCultureIgnoreCase))
                                                            {
                                                                ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you can't pass it to me!");
                                                            }
                                                            else
                                                            {
                                                                int user_access = ircbot.get_nick_access(line[4].Trim(), channel);
                                                                if (user_access > 0 && idle.check_idle(line[4].Trim()) == false)
                                                                {
                                                                    pass_hbomb(line[4].Trim(), channel, nick, ircbot, Conf, ref tmp_info, index);
                                                                }
                                                                else
                                                                {
                                                                    ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you can't pass to them!");
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you need to pass the bomb to someone.");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("PRIVMSG", channel + " :You don't have the bomb!");
                                                    }
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :You can not pass the HBomb when you are idle.");
                                                }
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :You can not pass a locked bomb.");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to pass!");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;
                                case "set_bomb":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= tmp_command.Access)
                                    {
                                        int index = 0;
                                        bool hbomb_active = false;
                                        hbomb_info tmp_info = new hbomb_info();
                                        foreach (hbomb_info bomb in hbombs)
                                        {
                                            if (bomb.bomb_channel.Equals(channel))
                                            {
                                                tmp_info = bomb;
                                                hbomb_active = true;
                                                break;
                                            }
                                            index++;
                                        }
                                        if (hbomb_active == true)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                if (line[4].Trim().Equals(ircbot.Nick, StringComparison.InvariantCultureIgnoreCase))
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you can't pass it to me!");
                                                }
                                                else
                                                {
                                                    int user_access = ircbot.get_nick_access(line[4].Trim(), channel);
                                                    if (user_access > 0)
                                                    {
                                                        pass_hbomb(line[4].Trim(), channel, nick, ircbot, Conf, ref tmp_info, index);
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("PRIVMSG", channel + " :" + nick + ", that user isn't online!");
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you need to pass the bomb to someone.");
                                            }

                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to pass!");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;
                                case "lock_bomb":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= tmp_command.Access)
                                    {
                                        int index = 0;
                                        bool hbomb_active = false;
                                        hbomb_info tmp_info = new hbomb_info();
                                        foreach (hbomb_info bomb in hbombs)
                                        {
                                            if (bomb.bomb_channel.Equals(channel))
                                            {
                                                tmp_info = bomb;
                                                hbomb_active = true;
                                                break;
                                            }
                                            index++;
                                        }
                                        if (hbomb_active == true)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                if (line[4].Trim().Equals(ircbot.Nick, StringComparison.InvariantCultureIgnoreCase))
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you can't pass it to me!");
                                                }
                                                else
                                                {
                                                    int user_access = ircbot.get_nick_access(line[4].Trim(), channel);
                                                    if (user_access > 0)
                                                    {
                                                        pass_hbomb(line[4].Trim(), channel, nick, ircbot, Conf, ref tmp_info, index);
                                                        tmp_info.bomb_locked = true;
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("PRIVMSG", channel + " :" + nick + ", that user isn't online!");
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                tmp_info.bomb_locked = true;
                                            }
                                            hbombs[index] = tmp_info;
                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to lock!");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;
                                case "unlock_bomb":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= tmp_command.Access)
                                    {
                                        int index = 0;
                                        bool hbomb_active = false;
                                        hbomb_info tmp_info = new hbomb_info();
                                        foreach (hbomb_info bomb in hbombs)
                                        {
                                            if (bomb.bomb_channel.Equals(channel))
                                            {
                                                tmp_info = bomb;
                                                hbomb_active = true;
                                                break;
                                            }
                                            index++;
                                        }
                                        if (hbomb_active == true)
                                        {
                                            tmp_info.bomb_locked = false;
                                            hbombs[index] = tmp_info;
                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to unlock!");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;
                                case "detonate":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= tmp_command.Access)
                                    {
                                        bool hbomb_active = false;
                                        foreach (hbomb_info bomb in hbombs)
                                        {
                                            if (bomb.bomb_channel.Equals(channel))
                                            {
                                                hbomb_active = true;
                                                break;
                                            }
                                        }
                                        if (hbomb_active == true)
                                        {
                                            main = ircbot;
                                            activate_bomb(channel);
                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to blow up!");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;
                                case "stop_bomb":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= tmp_command.Access)
                                    {
                                        int index = 0;
                                        bool hbomb_active = false;
                                        hbomb_info tmp_info = new hbomb_info();
                                        foreach (hbomb_info bomb in hbombs)
                                        {
                                            if (bomb.bomb_channel.Equals(channel))
                                            {
                                                tmp_info = bomb;
                                                hbomb_active = true;
                                                break;
                                            }
                                            index++;
                                        }
                                        if (hbomb_active == true)
                                        {
                                            hbombs.RemoveAt(index);
                                            ircbot.sendData("PRIVMSG", channel + " :Bomb has been defused and thrown away.");
                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to stop!");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;
                                case "defuse":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= tmp_command.Access)
                                    {
                                        int index = 0;
                                        bool hbomb_active = false;
                                        hbomb_info tmp_info = new hbomb_info();
                                        foreach (hbomb_info bomb in hbombs)
                                        {
                                            if (bomb.bomb_channel.Equals(channel))
                                            {
                                                tmp_info = bomb;
                                                hbomb_active = true;
                                                break;
                                            }
                                            index++;
                                        }
                                        if (hbomb_active == true)
                                        {
                                            if (!tmp_info.bomb_locked)
                                            {
                                                Modules.idle idle = (Modules.idle)ircbot.get_module("idle");
                                                if (idle.check_idle(nick) == false)
                                                {
                                                    if (tmp_info.bomb_holder.Equals(nick, StringComparison.InvariantCultureIgnoreCase))
                                                    {
                                                        if (line.GetUpperBound(0) > 3)
                                                        {
                                                            if (line[4].Trim().Equals(tmp_info.wire_color, StringComparison.InvariantCultureIgnoreCase))
                                                            {
                                                                ircbot.sendData("PRIVMSG", channel + " :You have successfully defused the bomb!");
                                                                if (tmp_info.previous_bomb_holder.Equals(tmp_info.bomb_holder))
                                                                {
                                                                }
                                                                else
                                                                {
                                                                    ircbot.sendData("KICK", tmp_info.bomb_channel + " " + tmp_info.previous_bomb_holder + " :BOOM!!!");
                                                                }
                                                                hbombs.RemoveAt(index);
                                                            }
                                                            else
                                                            {
                                                                main = ircbot;
                                                                activate_bomb(channel);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you need to cut a wire.");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("PRIVMSG", channel + " :You don't have the bomb!");
                                                    }
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :You can not defuse the HBomb when you are idle.");
                                                }
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :You can not defuse the HBomb when it is locked.");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to defuse!");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;
                            }
                        }
                    }
                }
            }
        }
Example #52
0
        private void pass_hbomb(string pass_nick, string channel, string nick, bot ircbot, IRCConfig conf, ref hbomb_info tmp_info, int index)
        {
            string tab_name = channel.TrimStart('#');
            string pattern = "[^a-zA-Z0-9]"; //regex pattern
            tab_name = Regex.Replace(tab_name, pattern, "_");
            string file_name = ircbot.server_name + "_#" + tab_name + ".log";
            bool nick_idle = true;

            if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "seen" + Path.DirectorySeparatorChar + file_name))
            {
                string[] log_file = System.IO.File.ReadAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "seen" + Path.DirectorySeparatorChar + file_name);
                int number_of_lines = log_file.GetUpperBound(0) + 1;
                if (number_of_lines > 0)
                {
                    foreach (string file_line in log_file)
                    {
                        char[] sep = new char[] { '*' };
                        string[] new_line = file_line.Split(sep, 4);
                        if (new_line.GetUpperBound(0) > 0)
                        {
                            if (new_line[0].Equals(pass_nick) && new_line[1].Equals(channel))
                            {
                                DateTime current_date = DateTime.Now;
                                DateTime past_date = DateTime.Parse(new_line[2]);
                                double difference_second = 0;
                                difference_second = current_date.Subtract(past_date).TotalSeconds;
                                if (difference_second <= 600)
                                {
                                    nick_idle = false;
                                }
                                break;
                            }
                        }
                    }
                }
            }
            if (nick_idle == false)
            {
                tmp_info.bomb_holder = pass_nick;
                tmp_info.previous_bomb_holder = nick;
                hbombs[index] = tmp_info;
                ircbot.sendData("PRIVMSG", channel + " :" + nick + " passed the bomb to " + pass_nick);
                ircbot.sendData("NOTICE", pass_nick + " :You now have the bomb!  Type " + conf.command + "pass <nick> to pass it to someone else, or type " + conf.command + "defuse <color> to try to defuse it.");
                string colors = "";
                foreach (string wire in tmp_info.wire_colors)
                {
                    colors += wire + ",";
                }
                ircbot.sendData("NOTICE", pass_nick + " :The colors of the wires are: " + colors);
            }
            else
            {
                ircbot.sendData("PRIVMSG", channel + " :Dang, you missed them! (Idle)");
            }
        }