示例#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!");
     }
 }
示例#2
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.");
            }
        }
示例#3
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.
            }
        }
示例#4
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);
            }
        }
示例#5
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");
            }
        }
示例#6
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;
                     }
                 }
             }
         }
     }
 }
示例#7
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);
            }
        }
示例#8
0
        private static void display_log_nick(string nick, string channel, string requst_nick, string command, 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)
                {
                    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, StringComparison.InvariantCultureIgnoreCase) && new_line[3].Equals(command))
                            {
                                if (!String.IsNullOrEmpty(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 " + ircbot.Conf.Command + command + " " + num_uses + " times.");
                        ircbot.sendData("NOTICE", requst_nick + " :They last used " + ircbot.Conf.Command + command + " on " + date + " in " + inside + parameters);
                    }
                    else
                    {
                        ircbot.sendData("NOTICE", requst_nick + " :" + nick + " has not used " + ircbot.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");
            }
        }
示例#9
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;
                     }
                 }
             }
         }
     }
 }
示例#10
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;
                     }
                 }
             }
         }
     }
 }
示例#11
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");
            }
        }
示例#12
0
文件: hbomb.cs 项目: Zanthas/IRCBot
        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)");
            }
        }
示例#13
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);
     }
 }
示例#14
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 "seen":
                         if (spam_check == true)
                         {
                             ircbot.add_spam_count(channel);
                         }
                         if (nick_access >= tmp_command.Access)
                         {
                             if (line.GetUpperBound(0) > 3)
                             {
                                 display_seen(line[4].Trim(), line[2], 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;
                     }
                 }
             }
         }
     }
     if (type.Equals("line") || type.Equals("channel") || type.Equals("invite") || type.Equals("join") || type.Equals("mode") || type.Equals("part") || type.Equals("quit") || type.Equals("nick"))
     {
         add_seen(nick.Trim(), channel, line, ircbot);
     }
 }
示例#15
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.");
                }
            }
        }
示例#16
0
 private void new_question(string channel, bot ircbot)
 {
     lock (trivialock)
     {
         bool   trivia_found  = false;
         string question_file = ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "trivia" + Path.DirectorySeparatorChar + "questions.txt";
         if (File.Exists(question_file))
         {
             foreach (trivia_info trivia in trivias)
             {
                 if (trivia.channel.Equals(channel, StringComparison.InvariantCultureIgnoreCase))
                 {
                     trivia_found = true;
                     trivia.questions_asked++;
                     string[] questions  = System.IO.File.ReadAllLines(question_file);
                     int      line_count = questions.GetUpperBound(0);
                     Random   random     = new Random();
                     int      index      = random.Next(0, line_count + 1);
                     char[]   sep        = new char[] { '*' };
                     string[] parts      = questions[index].Split(sep, 2);
                     trivia.question = parts[0];
                     trivia.answer   = parts[1];
                     ircbot.sendData("PRIVMSG", channel + " :" + parts[0]);
                     trivia.answer_timer.Start();
                     trivia.running = true;
                     break;
                 }
             }
             if (!trivia_found)
             {
                 trivia_info new_trivia = new trivia_info();
                 new_trivia.channel               = channel;
                 new_trivia.answer_timer          = new System.Timers.Timer();
                 new_trivia.answer_timer.Interval = 30000;
                 new_trivia.answer_timer.Enabled  = true;
                 new_trivia.answer_timer.Elapsed += (sender, e) => answer_timer_Elapsed(channel, ircbot);
                 string[] questions  = System.IO.File.ReadAllLines(question_file);
                 int      line_count = questions.GetUpperBound(0);
                 Random   random     = new Random();
                 int      index      = random.Next(0, line_count + 1);
                 char[]   sep        = new char[] { '*' };
                 string[] parts      = questions[index].Split(sep, 2);
                 new_trivia.question = parts[0];
                 new_trivia.answer   = parts[1];
                 ircbot.sendData("PRIVMSG", channel + " :" + parts[0]);
                 new_trivia.answer_timer.Start();
                 new_trivia.running = true;
                 new_trivia.scores  = new List <List <string> >();
                 trivias.Add(new_trivia);
             }
         }
     }
 }
示例#17
0
文件: intro.cs 项目: Zanthas/IRCBot
        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.");
                }
            }
        }
示例#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") || 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;
                     }
                 }
             }
         }
     }
 }
示例#19
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++;
                 }
             }
         }
     }
 }
示例#20
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.");
                }
            }
        }
示例#21
0
        private void get_weather(string term, string channel, bot ircbot)
        {
            XmlDocument doc = new XmlDocument();

            // Load data
            doc.Load("http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=" + term);

            // Get forecast with XPath
            XmlNodeList nodes = doc.SelectNodes("/current_observation");

            string location = "";
            string temp     = "";
            string weather  = "";
            string humidity = "";
            string wind     = "";
            string wind_dir = "";
            string wind_mph = "";

            if (nodes.Count > 0)
            {
                foreach (XmlNode node in nodes)
                {
                    XmlNodeList sub_node = doc.SelectNodes("/current_observation/display_location");
                    foreach (XmlNode xn in sub_node)
                    {
                        location = xn["full"].InnerText;
                    }
                    temp     = node["temperature_string"].InnerText;
                    weather  = node["weather"].InnerText;
                    humidity = node["relative_humidity"].InnerText;
                    wind     = node["wind_string"].InnerText;
                    wind_dir = node["wind_dir"].InnerText;
                    wind_mph = node["wind_mph"].InnerText;
                }
                if (location != ", ")
                {
                    ircbot.sendData("PRIVMSG", channel + " :" + location + " is currently " + weather + " with a temperature of " + temp + ".  The humidity is " + humidity + " with winds blowing " + wind_dir + " at " + wind_mph + " mph.");
                }
                else
                {
                    ircbot.sendData("PRIVMSG", channel + " :No weather information available");
                }
            }
            else
            {
                ircbot.sendData("PRIVMSG", channel + " :No weather information available");
            }
        }
示例#22
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.");
     }
 }
示例#23
0
文件: intro.cs 项目: Zanthas/IRCBot
        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();
            }
        }
示例#24
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);
            }
        }
示例#25
0
文件: intro.cs 项目: Zanthas/IRCBot
        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();
            }
        }
示例#26
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);
            }
        }
示例#27
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;
                     }
                 }
             }
         }
     }
 }
示例#28
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;
                     }
                 }
             }
         }
     }
 }
示例#29
0
        private void del_rule(string rule_num, 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"))
            {
                List <string> rules_file      = System.IO.File.ReadAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "rules" + Path.DirectorySeparatorChar + ircbot.server_name + "_" + tab_name + "_rules.txt").ToList();
                int           number_of_lines = rules_file.Count + 1;
                if (number_of_lines > 0)
                {
                    int  index      = 0;
                    bool rule_found = false;
                    foreach (string line in rules_file)
                    {
                        string[] split = line.Split('*');
                        if ((index + 1) == Convert.ToInt32(rule_num))
                        {
                            rules_file.RemoveAt(index);
                            rule_found = true;
                            break;
                        }
                        index++;
                    }
                    if (rule_found == false)
                    {
                        ircbot.sendData("NOTICE", nick + " :No Rules to Delete!");
                    }
                    else
                    {
                        System.IO.File.WriteAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "rules" + Path.DirectorySeparatorChar + ircbot.server_name + "_" + tab_name + "_rules.txt", rules_file);
                    }
                }
                else
                {
                    ircbot.sendData("NOTICE", nick + " :No Rules to Delete!");
                }
            }
            else
            {
                ircbot.sendData("NOTICE", nick + " :There are no Rules");
            }
        }
示例#30
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.");
            }
        }
示例#31
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   = "";
             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 + " :I don't know!");
             }
         }
         else
         {
             ircbot.sendData("PRIVMSG", channel + " :I don't know!");
         }
     }
     else
     {
         if (!Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "8ball"))
         {
             Directory.CreateDirectory(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "8ball");
         }
         List <string> contents = new List <string>();
         contents.Add("Yes");
         contents.Add("No");
         contents.Add("Maybe");
         File.WriteAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "8ball" + Path.DirectorySeparatorChar + "answers.txt", contents.ToArray());
         ircbot.sendData("PRIVMSG", channel + " :I don't know!");
     }
 }
示例#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.
     }
 }
示例#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!");
     }
 }
示例#34
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!");
     }
 }
示例#35
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)");
            }
        }
示例#36
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, StringComparison.InvariantCultureIgnoreCase))
                 {
                     DateTime current_time = DateTime.Now;
                     DateTime ping_time    = Convert.ToDateTime(ping_list[x][2]);
                     TimeSpan dif_time     = current_time.Subtract(ping_time);
                     string   time_string  = "";
                     if (dif_time.Days > 0)
                     {
                         time_string += dif_time.Days.ToString() + " Days, ";
                     }
                     if (dif_time.Hours > 0)
                     {
                         time_string += dif_time.Hours.ToString() + " Hours, ";
                     }
                     if (dif_time.Minutes > 0)
                     {
                         time_string += dif_time.Minutes.ToString() + " Minutes, ";
                     }
                     if (dif_time.Seconds > 0)
                     {
                         time_string += dif_time.Seconds.ToString() + " Seconds, ";
                     }
                     if (dif_time.Milliseconds > 0)
                     {
                         time_string += dif_time.Milliseconds.ToString() + " Milliseconds";
                     }
                     ircbot.sendData("PRIVMSG", ping_list[x][1] + " :" + nick + ", your ping is " + time_string.Trim().TrimEnd(','));
                     ping_list.RemoveAt(x);
                     break;
                 }
             }
         }
     }
 }
示例#37
0
文件: pingme.cs 项目: Zanthas/IRCBot
 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;
                 }
             }
         }
     }
 }
示例#38
0
文件: pingme.cs 项目: Zanthas/IRCBot
 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;
                 }
             }
         }
     }
 }
示例#39
0
        private object answer_timer_Elapsed(string channel, bot ircbot)
        {
            bool trivia_found = false;

            lock (trivialock)
            {
                foreach (trivia_info trivia in trivias)
                {
                    if (trivia.channel.Equals(channel, StringComparison.InvariantCultureIgnoreCase))
                    {
                        ircbot.sendData("PRIVMSG", channel + " :Times up!  The answer was: " + trivia.answer.Replace("*", " or "));
                        trivia.answer_timer.Stop();
                        trivia_found = true;
                        break;
                    }
                }
            }
            if (trivia_found)
            {
                new_question(channel, ircbot);
            }
            return(true);
        }
示例#40
0
文件: survey.cs 项目: Zanthas/IRCBot
        private void del_survey(string nick, int survey_num, bot ircbot, IRCConfig conf)
        {
            int current_survey = 0;
            List<survey_info> tmp_surveys = new List<survey_info>();
            tmp_surveys = active_surveys;
            foreach (survey_info survey in tmp_surveys)
            {
                if (survey_num == survey.survey_number)
                {
                    ircbot.sendData("NOTICE", survey.nick + " :Sorry, but the survey you are currently taking has been deleted.");
                    active_surveys.RemoveAt(current_survey);
                }
                else
                {
                    current_survey++;
                }
            }

            if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "surveys" + Path.DirectorySeparatorChar + ""))
            {
                FileInfo fi = new FileInfo(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "surveys" + Path.DirectorySeparatorChar + "");
                DirectoryInfo di = fi.Directory;
                FileSystemInfo[] fsi = di.GetFiles();
                if (fsi.GetUpperBound(0) >= 0 && fsi.GetUpperBound(0) >= survey_num)
                {
                    Directory.Delete(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "answers" + Path.DirectorySeparatorChar + fsi[survey_num].Name.Substring(0, fsi[survey_num].Name.Length - 4) + Path.DirectorySeparatorChar + "", true);
                    File.Delete(fsi[survey_num].FullName);
                    ircbot.sendData("NOTICE", nick + " :Survey deleted successfully");
                }
                else
                {
                    ircbot.sendData("NOTICE", nick + " :Survey not found");
                }
            }
        }
示例#41
0
文件: survey.cs 项目: Zanthas/IRCBot
        private void del_survey_owner(int survey_num, string nick, string del_owner, bot ircbot, IRCConfig conf)
        {
            bool survey_found = false;
            if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "surveys" + Path.DirectorySeparatorChar + ""))
            {
                FileInfo fi = new FileInfo(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "surveys" + Path.DirectorySeparatorChar + "");
                DirectoryInfo di = fi.Directory;
                FileSystemInfo[] fsi = di.GetFiles();
                if (fsi.GetUpperBound(0) >= 0 && fsi.GetUpperBound(0) >= survey_num)
                {
                    string[] questions = File.ReadAllLines(fsi[survey_num].FullName);
                    if (questions.GetUpperBound(0) > 2)
                    {
                        string owners = questions[2];
                        foreach (string owner in owners.Split(','))
                        {
                            if (nick.Equals(owner))
                            {
                                survey_found = true;
                                break;
                            }
                        }
                        if (survey_found == true)
                        {
                            bool owner_found = false;
                            string new_owners = "";
                            foreach (string owner in owners.Split(','))
                            {
                                bool owner_loop = false;
                                foreach (string old_owner in del_owner.Split(','))
                                {
                                    if (del_owner.Equals(owner))
                                    {
                                        owner_loop = true;
                                        owner_found = true;
                                    }
                                }
                                if (owner_loop == false)
                                {
                                    new_owners = new_owners + "," + owner;
                                }
                            }
                            if (owner_found == true)
                            {
                                questions[2] = new_owners.TrimStart(',');
                                StreamWriter sw = new StreamWriter(fsi[survey_num].FullName);
                                foreach (string line in questions)
                                {
                                    sw.Write(line + Environment.NewLine);
                                }
                                sw.Close();
                                ircbot.sendData("NOTICE", nick + " :Owner deleted successfully");
                            }
                            else
                            {
                                ircbot.sendData("NOTICE", nick + " :Owner was not found");
                            }
                        }
                        else
                        {
                            survey_found = true;
                            ircbot.sendData("NOTICE", nick + " :You do not have permission to edit this survey.");
                        }
                    }

                }
            }
            if (survey_found == false)
            {
                ircbot.sendData("NOTICE", nick + " :The specified survey does not exist.");
            }
        }
示例#42
0
文件: survey.cs 项目: Zanthas/IRCBot
        private void start_survey(string nick, int nick_access, int survey_num, bot ircbot, IRCConfig conf)
        {
            bool survey_found = false;
            if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "surveys" + Path.DirectorySeparatorChar + ""))
            {
                FileInfo fi = new FileInfo(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "surveys" + Path.DirectorySeparatorChar + "");
                DirectoryInfo di = fi.Directory;
                FileSystemInfo[] fsi = di.GetFiles();
                if (fsi.GetUpperBound(0) >= 0 && fsi.GetUpperBound(0) >= survey_num)
                {
                    foreach (survey_info survey in active_surveys)
                    {
                        if (nick.Equals(survey.nick))
                        {
                            survey_found = true;
                            break;
                        }
                    }
                    if (survey_found == false)
                    {
                        string[] questions = File.ReadAllLines(fsi[survey_num].FullName);
                        if (questions.GetUpperBound(0) > 2)
                        {
                            if (Convert.ToInt32(questions[0]) <= nick_access)
                            {
                                survey_found = true;
                                survey_info tmp_info = new survey_info();
                                tmp_info.user_submission = true;
                                tmp_info.name = fsi[survey_num].Name.Substring(0, fsi[survey_num].Name.Length - 4);
                                tmp_info.nick = nick;
                                tmp_info.survey_number = survey_num;
                                tmp_info.current_question = 1;
                                tmp_info.survey_id = survey_num;

                                active_surveys.Add(tmp_info);

                                if (!Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "answers" + Path.DirectorySeparatorChar + tmp_info.name + Path.DirectorySeparatorChar + tmp_info.nick + Path.DirectorySeparatorChar + ""))
                                {
                                    Directory.CreateDirectory(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "answers" + Path.DirectorySeparatorChar + tmp_info.name + Path.DirectorySeparatorChar + tmp_info.nick + Path.DirectorySeparatorChar + "");
                                }

                                if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "answers" + Path.DirectorySeparatorChar + tmp_info.name + Path.DirectorySeparatorChar + tmp_info.nick + Path.DirectorySeparatorChar + tmp_info.current_question + ".txt"))
                                {
                                    File.Delete(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "answers" + Path.DirectorySeparatorChar + tmp_info.name + Path.DirectorySeparatorChar + tmp_info.nick + Path.DirectorySeparatorChar + tmp_info.current_question + ".txt");
                                    File.Create(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "answers" + Path.DirectorySeparatorChar + tmp_info.name + Path.DirectorySeparatorChar + tmp_info.nick + Path.DirectorySeparatorChar + tmp_info.current_question + ".txt");
                                }
                                else
                                {
                                    File.Create(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "answers" + Path.DirectorySeparatorChar + "survey_" + tmp_info.survey_number + Path.DirectorySeparatorChar + tmp_info.nick + Path.DirectorySeparatorChar + tmp_info.current_question + ".txt");
                                }

                                ircbot.sendData("PRIVMSG", nick + " :You have chosen to take the following survey: " + questions[1]);
                                ircbot.sendData("PRIVMSG", nick + " :You will be presented with a series of questions.  After you write the answer, type " + conf.command + "nextquestion to submit your answer and view the next question.");
                                ircbot.sendData("PRIVMSG", nick + " :If at any time during the survey you wish to cancel, type " + conf.command + "cancelsurvey to cancel your current survey and any answers you may have submitted.");
                                string[] owners = questions[2].Split(',');
                                foreach (string owner in owners)
                                {
                                    ircbot.sendData("NOTICE", owner + " :" + nick + " has started your survey, \"" + questions[1] + "\"");
                                }
                                ircbot.sendData("PRIVMSG", nick + " :" + questions[3]);
                            }
                        }
                    }
                    else
                    {
                        ircbot.sendData("NOTICE", nick + " :You are already taking a survey.  Please finish the current survey or cancel it to choose a new survey.");
                    }
                }
            }
            if (survey_found == false)
            {
                ircbot.sendData("NOTICE", nick + " :Sorry, but that survey is not available to you.  To view all surveys available to you, please type " + conf.command + "surveys");
            }
        }
示例#43
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)
                 {
                     if (ircbot.spam_activated == true)
                     {
                         blocked = true;
                     }
                 }
                 foreach (string trigger in triggers)
                 {
                     if (trigger.Equals(command))
                     {
                         cmd_found = true;
                         break;
                     }
                 }
                 if (blocked == false && cmd_found == true)
                 {
                     foreach (string trigger in triggers)
                     {
                         switch (trigger)
                         {
                             case "isitup":
                                 if (spam_check == true)
                                 {
                                     ircbot.spam_count++;
                                 }
                                 if (nick_access >= command_access)
                                 {
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                 }
                                 break;
                         }
                     }
                 }
             }
         }
     }
 }
示例#44
0
文件: logging.cs 项目: Zanthas/IRCBot
 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);
         }
     }
 }
示例#45
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;
                            }
                        }
                    }
                }
            }
        }
示例#46
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.");
            }
        }
示例#47
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 "ud":
                                 if (spam_check == true)
                                 {
                                     ircbot.add_spam_count(channel);
                                 }
                                 if (nick_access >= command_access)
                                 {
                                     if (line.GetUpperBound(0) > 3)
                                     {
                                         // Get Urban Dictionary Info
                                         get_ud(line[4], line[2], ircbot, conf, module_id);
                                     }
                                     else
                                     {
                                         ircbot.sendData("PRIVMSG", line[2] + " :" + nick + ", you need to include more info.");
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                 }
                                 break;
                         }
                     }
                 }
             }
         }
     }
 }
示例#48
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);
                    }
                }
            }
        }
示例#49
0
文件: hbomb.cs 项目: Zanthas/IRCBot
        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;
                                }
                            }
                        }
                    }
                }
            }
        }
示例#50
0
文件: hbomb.cs 项目: Zanthas/IRCBot
        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)");
            }
        }
示例#51
0
文件: logging.cs 项目: Zanthas/IRCBot
 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");
     }
 }
示例#52
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 "bug":
                             if (spam_check == true)
                             {
                                 ircbot.add_spam_count(channel);
                             }
                             if (nick_access >= tmp_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/" + this.Options["username"] + "/" + this.Options["repository"] + "/issues";
                                     string response = post_issue(ircbot, uri, title, description, this.Options["username"], label);
                                     if (String.IsNullOrEmpty(response))
                                     {
                                         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 >= tmp_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/" + this.Options["username"] + "/" + this.Options["repository"] + "/issues";
                                     string response = post_issue(ircbot, uri, title, description, this.Options["username"], label);
                                     if (String.IsNullOrEmpty(response))
                                     {
                                         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;
                     }
                 }
             }
         }
     }
 }
示例#53
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;
                     }
                 }
             }
         }
     }
 }
示例#54
0
文件: github.cs 项目: Zanthas/IRCBot
 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;
                         }
                     }
                 }
             }
         }
     }
 }
示例#55
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)");
            }
        }
示例#56
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());
                    }
                }
            }
        }
示例#57
0
文件: about.cs 项目: Zanthas/IRCBot
 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 "about":
                                 if (spam_check == true)
                                 {
                                     ircbot.add_spam_count(channel);
                                 }
                                 if (nick_access >= command_access)
                                 {
                                     AboutBox1 about = new AboutBox1();
                                     string[] owners = conf.owner.TrimStart(',').TrimEnd(',').Split(',');
                                     string owner_num = " is";
                                     if (owners.GetUpperBound(0) > 0)
                                     {
                                         owner_num = "s are";
                                     }
                                     string response = "IRCBot";
                                     if (conf.module_config[module_id][3].Equals("True"))
                                     {
                                         response += " v" + about.AssemblyVersion + ".";
                                     }
                                     if (conf.module_config[module_id][4].Equals("True"))
                                     {
                                         response += " Created by Uncled1023.";
                                     }
                                     if (conf.module_config[module_id][5].Equals("True"))
                                     {
                                         response += " My owner" + owner_num + " ";
                                         if (owners.GetUpperBound(0) > 1)
                                         {
                                             int index = 0;
                                             foreach (string owner in owners)
                                             {
                                                 response += owner;
                                                 if (index == owners.GetUpperBound(0) - 1)
                                                 {
                                                     response += ", and ";
                                                 }
                                                 else if(index < owners.GetUpperBound(0))
                                                 {
                                                     response += ", ";
                                                 }
                                                 index++;
                                             }
                                         }
                                         else
                                         {
                                             response += conf.owner.TrimStart(',').TrimEnd(',').Replace(",", " and ");
                                         }
                                     }
                                     if (type.Equals("channel"))
                                     {
                                         ircbot.sendData("PRIVMSG", channel + " :" + response);
                                     }
                                     else
                                     {
                                         ircbot.sendData("NOTICE", nick + " :" + response);
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                 }
                                 break;
                             case "uptime":
                                 if (spam_check == true)
                                 {
                                     ircbot.add_spam_count(channel);
                                 }
                                 if (nick_access >= command_access)
                                 {
                                     DateTime now = new DateTime();
                                     now = DateTime.Now;
                                     int days = now.Subtract(ircbot.start_time).Days;
                                     int hours = now.Subtract(ircbot.start_time).Hours;
                                     int minutes = now.Subtract(ircbot.start_time).Minutes;
                                     int seconds = now.Subtract(ircbot.start_time).Seconds;
                                     string uptime = "";
                                     if (days > 0)
                                     {
                                         uptime += days + " days, ";
                                     }
                                     if (hours > 0)
                                     {
                                         uptime += hours + " hours, ";
                                     }
                                     if (minutes > 0)
                                     {
                                         uptime += minutes + " minutes, ";
                                     }
                                     if (seconds > 0)
                                     {
                                         uptime += seconds + " seconds, ";
                                     }
                                     if (type.Equals("channel"))
                                     {
                                         ircbot.sendData("PRIVMSG", channel + " :I have been online for " + uptime.Trim().TrimEnd(','));
                                     }
                                     else
                                     {
                                         ircbot.sendData("NOTICE", nick + " :I have been online for " + uptime.Trim().TrimEnd(','));
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                 }
                                 break;
                         }
                     }
                 }
             }
         }
     }
 }
示例#58
0
 private void get_ud(string search, string channel, bot ircbot, IRCConfig conf, int conf_id)
 {
     string URL = "http://www.urbandictionary.com/define.php?term=";
     List<KeyValuePair<string, string>> ret = new List<KeyValuePair<string, string>>();
     try
     {
         string c = new WebClient().DownloadString(URL + System.Web.HttpUtility.UrlEncode(search));
         MatchCollection mc = Regex.Matches(c, "<div class=\"definition\">(.*?)</div>");
         MatchCollection mc2 = Regex.Matches(c, "<td class='word'>(.*?)</td>", RegexOptions.Singleline);
         if (mc.Count <= mc2.Count)
         {
             for (int i = 0; i < mc.Count; i++)
             {
                 ret.Add(new KeyValuePair<string, string>(System.Web.HttpUtility.HtmlDecode(mc2[i].Groups[1].Value.Trim()), System.Web.HttpUtility.HtmlDecode(mc[i].Groups[1].Value.Trim())));
             }
         }
     }
     catch (Exception ex)
     {
         ircbot.sendData("PRIVMSG", channel + " :UrbanDictionary/Search Error: " + ex);
     }
     if (ret.Count > 0)
     {
         foreach (KeyValuePair<string, string> pair in ret)
         {
             string def = pair.Value;
             string term = pair.Key;
             while (def.IndexOf("<a href") != -1)
             {
                 int start_strip = def.IndexOf("<a href");
                 string tmp_def = def.Substring(start_strip);
                 int end_strip = tmp_def.IndexOf(">");
                 def = def.Remove(start_strip, end_strip + 1);
             }
             def = def.Replace("</a>", "").Replace("\n", "").Replace("\r", "").Replace("<strong class=\"highlight\">", "").Replace("</strong>", "");
             while (term.IndexOf("<a href") != -1)
             {
                 int start_strip = term.IndexOf("<a href");
                 string tmp_def = term.Substring(start_strip);
                 int end_strip = tmp_def.IndexOf(">");
                 term = term.Remove(start_strip, end_strip + 1);
             }
             term = term.Replace("</a>", "").Replace("\n", "").Replace("\r", "").Replace("<strong class=\"highlight\">", "").Replace("</strong>", "");
             string[] strSep = new string[] { "<br/><br/>" };
             string[] definition = def.Split(strSep, StringSplitOptions.RemoveEmptyEntries);
             string[] strSep2 = new string[] { "<br/>" };
             string[] fin_def = definition[0].Split(strSep2, StringSplitOptions.RemoveEmptyEntries);
             ircbot.sendData("PRIVMSG", channel + " :" + term + ": " + fin_def[0]);
             for (int x = 1; fin_def.GetUpperBound(0) >= x; x++)
             {
                 ircbot.sendData("PRIVMSG", channel + " :" + fin_def[x]);
             }
             break;
         }
         if (conf.module_config[conf_id][3].Equals("True"))
         {
             ircbot.sendData("PRIVMSG", channel + " :" + URL + System.Web.HttpUtility.UrlEncode(search));
         }
     }
     else
     {
         ircbot.sendData("PRIVMSG", channel + " :No Results Found.");
     }
 }
示例#59
0
文件: survey.cs 项目: Zanthas/IRCBot
        private void view_survey(int survey_num, int nick_access, string nick, string requested_nick, bot ircbot, IRCConfig conf)
        {
            bool survey_found = false;
            if (survey_num != -1)
            {
                if (requested_nick == null)
                {
                    if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "surveys" + Path.DirectorySeparatorChar + ""))
                    {
                        FileInfo fi = new FileInfo(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "surveys" + Path.DirectorySeparatorChar + "");
                        DirectoryInfo di = fi.Directory;
                        FileSystemInfo[] fsi = di.GetFiles();
                        if (fsi.GetUpperBound(0) >= 0 && fsi.GetUpperBound(0) >= survey_num)
                        {
                            string[] questions = File.ReadAllLines(fsi[survey_num].FullName);
                            if (questions.GetUpperBound(0) > 2)
                            {
                                string[] owners = questions[2].Split(',');
                                bool survey_owner = false;
                                foreach (string owner in owners)
                                {
                                    if (nick.Equals(owner))
                                    {
                                        survey_owner = true;
                                        break;
                                    }
                                }
                                if (survey_owner == true)
                                {
                                    survey_found = true;
                                    if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "answers" + Path.DirectorySeparatorChar + fsi[survey_num].Name.Substring(0, fsi[survey_num].Name.Length - 4) + Path.DirectorySeparatorChar + ""))
                                    {
                                        ircbot.sendData("NOTICE", nick + " :The following nicks have completed or are taking your survey, \"" + questions[1] + "\":");
                                        string nicks = "";
                                        foreach (string dir in Directory.GetDirectories(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "answers" + Path.DirectorySeparatorChar + fsi[survey_num].Name.Substring(0, fsi[survey_num].Name.Length - 4) + Path.DirectorySeparatorChar + ""))
                                        {
                                            nicks += "," + dir.Replace(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "answers" + Path.DirectorySeparatorChar + fsi[survey_num].Name.Substring(0, fsi[survey_num].Name.Length - 4) + Path.DirectorySeparatorChar + "", "");
                                        }
                                        ircbot.sendData("NOTICE", nick + " :" + nicks.TrimStart(','));
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :No nicks have taken that survey.");
                                    }
                                }
                            }

                        }
                    }
                }
                else
                {
                    if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "surveys" + Path.DirectorySeparatorChar + ""))
                    {
                        FileInfo fi = new FileInfo(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "surveys" + Path.DirectorySeparatorChar + "");
                        DirectoryInfo di = fi.Directory;
                        FileSystemInfo[] fsi = di.GetFiles();
                        if (fsi.GetUpperBound(0) >= 0 && fsi.GetUpperBound(0) >= survey_num)
                        {
                            string[] questions = File.ReadAllLines(fsi[survey_num].FullName);
                            if (questions.GetUpperBound(0) > 2)
                            {
                                string[] owners = questions[2].Split(',');
                                bool survey_owner = false;
                                foreach (string owner in owners)
                                {
                                    if (nick.Equals(owner))
                                    {
                                        survey_owner = true;
                                        break;
                                    }
                                }
                                if (survey_owner == true)
                                {
                                    survey_found = true;
                                    if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "answers" + Path.DirectorySeparatorChar + fsi[survey_num].Name.Substring(0, fsi[survey_num].Name.Length - 4) + Path.DirectorySeparatorChar + requested_nick + Path.DirectorySeparatorChar + ""))
                                    {
                                        ircbot.sendData("PRIVMSG", nick + " :" + requested_nick + " has supplied the following answers for your survey, \"" + questions[1] + "\":");
                                        string[] answers = Directory.GetFiles(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "answers" + Path.DirectorySeparatorChar + fsi[survey_num].Name.Substring(0, fsi[survey_num].Name.Length - 4) + Path.DirectorySeparatorChar + requested_nick + Path.DirectorySeparatorChar + "");
                                        int question_num = 0;
                                        for (int x = 3; x <= questions.GetUpperBound(0); x++)
                                        {
                                            ircbot.sendData("PRIVMSG", nick + " :\u0002" + questions[x]);
                                            foreach (string line in File.ReadAllLines(answers[question_num]))
                                            {
                                                ircbot.sendData("PRIVMSG", nick + " :" + line);
                                            }
                                            question_num++;
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :" + requested_nick + " has not taken that survey.");
                                    }
                                }
                            }

                        }
                    }
                }
                if (survey_found == false)
                {
                    ircbot.sendData("NOTICE", nick + " :Sorry, but either you are not the owner of the survey, or the survey does not exist.  To view all surveys available to you, please type " + conf.command + "surveys");
                }
            }
            else
            {
                if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "surveys" + Path.DirectorySeparatorChar + ""))
                {
                    FileInfo fi = new FileInfo(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "surveys" + Path.DirectorySeparatorChar + "");
                    DirectoryInfo di = fi.Directory;
                    FileSystemInfo[] fsi = di.GetFiles();
                    int file_number = 1;
                    foreach (FileSystemInfo survey_file in fsi)
                    {
                        string[] questions = File.ReadAllLines(survey_file.FullName);
                        if (questions.GetUpperBound(0) > 1)
                        {
                            int survey_access = Convert.ToInt32(questions[0]);
                            if (survey_access <= nick_access)
                            {
                                survey_found = true;
                                ircbot.sendData("NOTICE", nick + " :" + file_number.ToString() + ") " + questions[1]);
                            }
                            file_number++;
                        }

                    }
                }
                if (survey_found == false)
                {
                    ircbot.sendData("NOTICE", nick + " :There are no surveys available to you.");
                }
            }
        }
示例#60
0
文件: logging.cs 项目: Zanthas/IRCBot
 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");
     }
 }