Пример #1
0
        public IRCQwitter(IRCConfig conf, string master)
        {
            this.master = master;
            this.config = conf;
            try
            {
                IRCConnection = new TcpClient(config.server, config.port);
            }
            catch
            {
                Console.WriteLine("Connection Error");
            }

            try
            {
                ns = IRCConnection.GetStream();
                sr = new StreamReader(ns);
                sw = new StreamWriter(ns);

                sendData("USER", config.nick + " amazdong.com amzdong.com :" + config.name);
                sendData("NICK", config.nick);
            }
            catch
            {
                Console.WriteLine("Communication Error");
            }
        }
Пример #2
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);
            }
        }
Пример #3
0
        public static void Load()
        {
            if (!System.IO.File.Exists(Files.ConfigurationPath))
            {
                Logger.Write("Configuration does not exist. Loading defaults.", LogType.System);
                LoadDefaults();
                return;
            }
            string     json = System.IO.File.ReadAllText(Files.ConfigurationPath);
            ConfigFile file = JsonConvert.DeserializeObject <ConfigFile>(json);

            if (file == null)
            {
                Logger.Write("Unable to load Config. Loading defaults.", LogType.Warning);
                LoadDefaults();
            }
            else
            {
                Basic    = file.Basic;
                Chat     = file.Chat;
                Worlds   = file.Worlds;
                Security = file.Security;
                Logging  = file.Logging;
                Advanced = file.Advanced;
                IRC      = file.IRC;
                Misc     = file.Misc;
            }
        }
Пример #4
0
        public IRCQwitter(IRCConfig conf, string master)
        {
            this.master = master;
            this.config = conf;
            try
            {
                IRCConnection = new TcpClient(config.server, config.port);
            }
            catch
            {
                Console.WriteLine("Connection Error");
            }

            try
            {
                ns = IRCConnection.GetStream();
                sr = new StreamReader(ns);
                sw = new StreamWriter(ns);

                sendData("USER", config.nick + " amazdong.com amzdong.com :" + config.name);
                sendData("NICK", config.nick);
            }
            catch
            {
                Console.WriteLine("Communication Error");
            }
        }
Пример #5
0
 public IRCBot(IRCConfig config, UInt64 associatedId, List <IrcCommand> commands)
 {
     this.config    = config;
     this.discordId = associatedId;
     LaunchCommands = commands;
     this.queue     = new List <QueueObject>(); //Queue is where all incoming IRC messages as seen by this instance are stored
 }
Пример #6
0
        private void get_wa(string search, string channel, bot ircbot, IRCConfig conf, int conf_id)
        {
            string      URL    = "http://api.wolframalpha.com/v2/query?input=" + System.Web.HttpUtility.UrlEncode(search) + "&appid=" + conf.module_config[conf_id][3] + "&format=plaintext";
            XmlNodeList xnList = null;

            try
            {
                string      results = new WebClient().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.");
            }
        }
Пример #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
 /// <summary>
 /// Loads the default configs
 /// </summary>
 public static void LoadDefaults()
 {
     Basic    = new BasicConfig();
     Chat     = new ChatConfig();
     Worlds   = new WorldConfig();
     Security = new SecurityConfig();
     Logging  = new LoggingConfig();
     Advanced = new AdvancedConfig();
     IRC      = new IRCConfig();
     Misc     = new MiscConfig();
 }
Пример #9
0
 public static void Main(string[] arg)
 {
     IRCConfig conf = new IRCConfig();
     conf.name = "Qwitt";
     conf.nick = "Qwitt";
     conf.port = 6667;
     conf.server = "irc.amazdong.com";
     string master = "suroi";
     IRCQwitter bot = new IRCQwitter(conf, master);
     bot.keepAliveAndRun();
     bot.kill();
     Console.WriteLine("Bot quit/crashed");
     Console.ReadLine();
 }
Пример #10
0
        public static void Main(string[] arg)
        {
            IRCConfig conf = new IRCConfig();

            conf.name   = "Qwitt";
            conf.nick   = "Qwitt";
            conf.port   = 6667;
            conf.server = "irc.amazdong.com";
            string     master = "suroi";
            IRCQwitter bot    = new IRCQwitter(conf, master);

            bot.keepAliveAndRun();
            bot.kill();
            Console.WriteLine("Bot quit/crashed");
            Console.ReadLine();
        }
Пример #11
0
 public void add_quote(string nick, string channel, string[] line, bot ircbot, IRCConfig conf)
 {
     string tab_name = channel.TrimStart('#');
     string pattern = "[^a-zA-Z0-9]"; //regex pattern
     string new_tab_name = Regex.Replace(tab_name, pattern, "_");
     string file_name = ircbot.server_name + "_#" + new_tab_name + ".log";
     if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "quotes" + Path.DirectorySeparatorChar + "logs") == false)
     {
         Directory.CreateDirectory(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "quotes" + Path.DirectorySeparatorChar + "logs");
     }
     StreamWriter log_file = File.AppendText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "quotes" + Path.DirectorySeparatorChar + "logs" + Path.DirectorySeparatorChar + file_name);
     if (line.GetUpperBound(0) > 3)
     {
         log_file.WriteLine(nick + "*" + line[3].Remove(0, 1) + " " + line[4]);
     }
     else
     {
         log_file.WriteLine(nick + "*" + line[3].Remove(0, 1));
     }
     log_file.Close();
 }
Пример #12
0
        public void scripts_control(string[] line, bot ircbot, IRCConfig conf, int conf_id, int nick_access, string nick, string channel, string event_type)
        {
            if (pyEngine == null)
            {
                pyEngine = Python.CreateEngine();
                pyScope  = pyEngine.CreateScope();

                string msg = "";
                if (line.GetUpperBound(0) > 3)
                {
                    msg = line[3] + " " + line[4];
                }
                else
                {
                    msg = line[3];
                }
                pyScope.SetVariable("line", msg);
                pyScope.SetVariable("event", event_type);
                pyScope.SetVariable("nick", nick);
                pyScope.SetVariable("channel", channel);
                pyScope.SetVariable("bot", ircbot);
                pyScope.SetVariable("conf", conf);
            }
        }
Пример #13
0
        public void scripts_control(string[] line, bot ircbot, IRCConfig conf, int conf_id, int nick_access, string nick, string channel, string event_type)
        {
            if (pyEngine == null)
            {
                pyEngine = Python.CreateEngine();
                pyScope = pyEngine.CreateScope();

                string msg = "";
                if(line.GetUpperBound(0) > 3)
                {
                    msg = line[3] + " " + line[4];
                }
                else
                {
                    msg = line[3];
                }
                pyScope.SetVariable("line", msg);
                pyScope.SetVariable("event", event_type);
                pyScope.SetVariable("nick", nick);
                pyScope.SetVariable("channel", channel);
                pyScope.SetVariable("bot", ircbot);
                pyScope.SetVariable("conf", conf);
            }
        }
Пример #14
0
 public override void control(bot ircbot, ref IRCConfig conf, int module_id, string[] line, string command, int nick_access, string nick, string channel, bool bot_command, string type)
 {
     char[] charS = new char[] { ' ' };
     string module_name = ircbot.conf.module_config[module_id][0];
     if ((type.Equals("channel") || type.Equals("query")) && bot_command == true)
     {
         foreach (List<string> tmp_command in conf.command_list)
         {
             if (module_name.Equals(tmp_command[0]))
             {
                 string[] triggers = tmp_command[3].Split('|');
                 int command_access = Convert.ToInt32(tmp_command[5]);
                 string[] blacklist = tmp_command[6].Split(',');
                 bool blocked = false;
                 bool cmd_found = false;
                 bool spam_check = Convert.ToBoolean(tmp_command[8]);
                 foreach (string bl_chan in blacklist)
                 {
                     if (bl_chan.Equals(channel))
                     {
                         blocked = true;
                         break;
                     }
                 }
                 if (spam_check == true)
                 {
                     blocked = ircbot.get_spam_status(channel, nick);
                 }
                 foreach (string trigger in triggers)
                 {
                     if (trigger.Equals(command))
                     {
                         cmd_found = true;
                         break;
                     }
                 }
                 if (blocked == true && cmd_found == true)
                 {
                     ircbot.sendData("NOTICE", nick + " :I am currently too busy to process that.");
                 }
                 if (blocked == false && cmd_found == true)
                 {
                     foreach (string trigger in triggers)
                     {
                         switch (trigger)
                         {
                             case "bug":
                                 if (spam_check == true)
                                 {
                                     ircbot.add_spam_count(channel);
                                 }
                                 if (nick_access >= command_access)
                                 {
                                     if (line.GetUpperBound(0) > 3)
                                     {
                                         string title = "";
                                         string description = "";
                                         string[] split = line[4].Split('|');
                                         title = "[" + nick + "] " + split[0];
                                         if (split.GetUpperBound(0) > 0)
                                         {
                                             description = split[1];
                                         }
                                         List<string> label = new List<string>() { "bug" };
                                         string uri = "https://api.github.com/repos/" + ircbot.conf.module_config[module_id][3] + "/" + ircbot.conf.module_config[module_id][5] + "/issues";
                                         string response = post_issue(ircbot, module_id, uri, title, description, ircbot.conf.module_config[module_id][3], label);
                                         if (response.Equals(""))
                                         {
                                             ircbot.sendData("NOTICE", nick + " :Issue Added Successfully");
                                         }
                                         else
                                         {
                                             ircbot.sendData("NOTICE", nick + " :" + response);
                                         }
                                     }
                                     else
                                     {
                                         ircbot.sendData("NOTICE", nick + " :" + nick + ", you need to include more info.");
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                 }
                                 break;
                             case "request":
                                 if (spam_check == true)
                                 {
                                     ircbot.add_spam_count(channel);
                                 }
                                 if (nick_access >= command_access)
                                 {
                                     if (line.GetUpperBound(0) > 3)
                                     {
                                         string title = "";
                                         string description = "";
                                         string[] split = line[4].Split('|');
                                         title = "[" + nick + "] " + split[0];
                                         if (split.GetUpperBound(0) > 0)
                                         {
                                             description = split[1];
                                         }
                                         List<string> label = new List<string>() { "Feature Request" };
                                         string uri = "https://api.github.com/repos/" + ircbot.conf.module_config[module_id][3] + "/" + ircbot.conf.module_config[module_id][5] + "/issues";
                                         string response = post_issue(ircbot, module_id, uri, title, description, ircbot.conf.module_config[module_id][3], label);
                                         if (response.Equals(""))
                                         {
                                             ircbot.sendData("NOTICE", nick + " :Feature Request Added Successfully");
                                         }
                                         else
                                         {
                                             ircbot.sendData("NOTICE", nick + " :" + response);
                                         }
                                     }
                                     else
                                     {
                                         ircbot.sendData("NOTICE", nick + " :" + nick + ", you need to include more info.");
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                 }
                                 break;
                         }
                     }
                 }
             }
         }
     }
 }
Пример #15
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)
        {
            IRCConfig conf = tmp_conf;

            System.Timers.Timer alarm_trigger = (System.Timers.Timer)sender;
            alarm_trigger.Enabled = false;
            if (msg.StartsWith(conf.command))
            {
                bool   bot_command = true;
                string line        = "";
                if (type.Equals("channel"))
                {
                    line = ":" + full_nick + " PRIVMSG " + channel + " :" + msg;
                }
                else
                {
                    line = ":" + full_nick + " PRIVMSG " + conf.nick + " :" + msg;
                }

                char[]   charSplit     = new char[] { ' ' };
                string[] ex            = line.Split(charSplit, 5);
                string[] ignored_nicks = conf.ignore_list.Split(',');
                bool     run_modules   = true;
                foreach (string ignore_nick in ignored_nicks)
                {
                    if (ignore_nick.ToLower().Equals(nick))
                    {
                        run_modules = false;
                        break;
                    }
                }
                if (run_modules)
                {
                    //Run Enabled Modules
                    List <Modules.Module> tmp_module_list = new List <Modules.Module>();
                    tmp_module_list.AddRange(ircbot.module_list);
                    foreach (Modules.Module module in tmp_module_list)
                    {
                        int    index            = 0;
                        bool   module_found     = false;
                        string module_blacklist = "";
                        foreach (List <string> conf_module in conf.module_config)
                        {
                            if (module.ToString().Equals("IRCBot.Modules." + conf_module[0]))
                            {
                                module_blacklist = conf_module[2];
                                module_found     = true;
                                break;
                            }
                            index++;
                        }
                        if (module_found == true)
                        {
                            char[]   sepComma       = new char[] { ',' };
                            char[]   sepSpace       = new char[] { ' ' };
                            string[] blacklist      = module_blacklist.Split(sepComma, StringSplitOptions.RemoveEmptyEntries);
                            bool     module_allowed = true;
                            foreach (string blacklist_node in blacklist)
                            {
                                string[] nodes = blacklist_node.Split(sepSpace, StringSplitOptions.RemoveEmptyEntries);
                                foreach (string node in nodes)
                                {
                                    if (node.ToLower().Equals(nick) || node.ToLower().TrimStart('#').Equals(channel.ToLower().TrimStart('#')))
                                    {
                                        module_allowed = false;
                                        break;
                                    }
                                }
                                if (module_allowed == false)
                                {
                                    break;
                                }
                            }
                            if (module_allowed == true)
                            {
                                module.control(ircbot, ref conf, index, ex, ex[3].TrimStart(':').TrimStart(Convert.ToChar(conf.command)), nick_access, nick, channel, bot_command, type);
                            }
                        }
                    }
                }
            }
            else
            {
                ircbot.sendData("PRIVMSG", nick + " :ALARM: " + msg);
            }
        }
Пример #16
0
        public override void control(bot ircbot, ref IRCConfig conf, int module_id, string[] line, string command, int nick_access, string nick, string channel, bool bot_command, string type)
        {
            string module_name = ircbot.conf.module_config[module_id][0];
            if (type.Equals("channel") && bot_command == true)
            {
                foreach (List<string> tmp_command in conf.command_list)
                {
                    if (module_name.Equals(tmp_command[0]))
                    {
                        string[] triggers = tmp_command[3].Split('|');
                        int command_access = Convert.ToInt32(tmp_command[5]);
                        string[] blacklist = tmp_command[6].Split(',');
                        bool blocked = false;
                        bool cmd_found = false;
                        bool spam_check = Convert.ToBoolean(tmp_command[8]);
                        foreach (string bl_chan in blacklist)
                        {
                            if (bl_chan.Equals(channel))
                            {
                                blocked = true;
                                break;
                            }
                        }
                        if (spam_check == true)
                        {
                            blocked = ircbot.get_spam_status(channel, nick);
                        }
                        foreach (string trigger in triggers)
                        {
                            if (trigger.Equals(command))
                            {
                                cmd_found = true;
                                break;
                            }
                        }
                        if (blocked == true && cmd_found == true)
                        {
                            ircbot.sendData("NOTICE", nick + " :I am currently too busy to process that.");
                        }
                        if (blocked == false && cmd_found == true)
                        {
                            foreach (string trigger in triggers)
                            {
                                switch (trigger)
                                {
                                    case "hbomb":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            int module_index = 0;
                                            foreach (Modules.Module module in ircbot.module_list)
                                            {
                                                string module_type = module.GetType().ToString();
                                                if (module_type.Equals("IRCBot.Modules.idle"))
                                                {
                                                    break;
                                                }
                                                else
                                                {
                                                    module_index++;
                                                }
                                            }
                                            Modules.idle idle;
                                            if (module_index < ircbot.module_list.Count())
                                            {
                                                idle = (Modules.idle)ircbot.module_list[module_index];
                                            }
                                            else
                                            {
                                                idle = new Modules.idle();
                                            }
                                            if (idle.check_idle(nick) == false)
                                            {
                                                bool hbomb_active = false;
                                                hbomb_info tmp_info = new hbomb_info();
                                                foreach (hbomb_info bomb in hbombs)
                                                {
                                                    if (bomb.bomb_channel.Equals(channel))
                                                    {
                                                        tmp_info = bomb;
                                                        hbomb_active = true;
                                                        break;
                                                    }
                                                }
                                                if (hbomb_active == false)
                                                {
                                                    tmp_info.bomb_locked = false;
                                                    tmp_info.bomb_trigger = new System.Timers.Timer();
                                                    tmp_info.wire_colors = ircbot.conf.module_config[module_id][3].Split(',');
                                                    tmp_info.bomb_channel = channel;

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

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

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

                                                    main = ircbot;

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

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

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

                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to lock!");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                    case "unlock_bomb":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            int index = 0;
                                            bool hbomb_active = false;
                                            hbomb_info tmp_info = new hbomb_info();
                                            foreach (hbomb_info bomb in hbombs)
                                            {
                                                if (bomb.bomb_channel.Equals(channel))
                                                {
                                                    tmp_info = bomb;
                                                    hbomb_active = true;
                                                    break;
                                                }
                                                index++;
                                            }
                                            if (hbomb_active == true)
                                            {
                                                tmp_info.bomb_locked = false;
                                                hbombs[index] = tmp_info;
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to unlock!");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                    case "detonate":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            bool hbomb_active = false;
                                            foreach (hbomb_info bomb in hbombs)
                                            {
                                                if (bomb.bomb_channel.Equals(channel))
                                                {
                                                    hbomb_active = true;
                                                    break;
                                                }
                                            }
                                            if (hbomb_active == true)
                                            {
                                                main = ircbot;
                                                activate_bomb(channel);
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to blow up!");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                    case "stop_bomb":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            int index = 0;
                                            bool hbomb_active = false;
                                            hbomb_info tmp_info = new hbomb_info();
                                            foreach (hbomb_info bomb in hbombs)
                                            {
                                                if (bomb.bomb_channel.Equals(channel))
                                                {
                                                    tmp_info = bomb;
                                                    hbomb_active = true;
                                                    break;
                                                }
                                                index++;
                                            }
                                            if (hbomb_active == true)
                                            {
                                                hbombs.RemoveAt(index);
                                                ircbot.sendData("PRIVMSG", channel + " :Bomb has been defused and thrown away.");
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to stop!");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                    case "defuse":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            int index = 0;
                                            bool hbomb_active = false;
                                            hbomb_info tmp_info = new hbomb_info();
                                            foreach (hbomb_info bomb in hbombs)
                                            {
                                                if (bomb.bomb_channel.Equals(channel))
                                                {
                                                    tmp_info = bomb;
                                                    hbomb_active = true;
                                                    break;
                                                }
                                                index++;
                                            }
                                            if (hbomb_active == true)
                                            {
                                                if (!tmp_info.bomb_locked)
                                                {
                                                    int module_index = 0;
                                                    foreach (Modules.Module module in ircbot.module_list)
                                                    {
                                                        string module_type = module.GetType().ToString();
                                                        if (module_type.Equals("IRCBot.Modules.idle"))
                                                        {
                                                            break;
                                                        }
                                                        else
                                                        {
                                                            module_index++;
                                                        }
                                                    }
                                                    Modules.idle idle;
                                                    if (module_index < ircbot.module_list.Count())
                                                    {
                                                        idle = (Modules.idle)ircbot.module_list[module_index];
                                                    }
                                                    else
                                                    {
                                                        idle = new Modules.idle();
                                                    }
                                                    if (idle.check_idle(nick) == false)
                                                    {
                                                        if (tmp_info.bomb_holder.Equals(nick))
                                                        {
                                                            if (line.GetUpperBound(0) > 3)
                                                            {
                                                                if (line[4].ToLower().Equals(tmp_info.wire_color.ToLower()))
                                                                {
                                                                    ircbot.sendData("PRIVMSG", channel + " :You have successfully defused the bomb!");
                                                                    if (tmp_info.previous_bomb_holder.Equals(tmp_info.bomb_holder))
                                                                    {
                                                                    }
                                                                    else
                                                                    {
                                                                        ircbot.sendData("KICK", tmp_info.bomb_channel + " " + tmp_info.previous_bomb_holder + " :BOOM!!!");
                                                                    }
                                                                    hbombs.RemoveAt(index);
                                                                }
                                                                else
                                                                {
                                                                    main = ircbot;
                                                                    activate_bomb(channel);
                                                                }
                                                            }
                                                            else
                                                            {
                                                                ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you need to cut a wire.");
                                                            }
                                                        }
                                                        else
                                                        {
                                                            ircbot.sendData("PRIVMSG", channel + " :You don't have the bomb!");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("PRIVMSG", channel + " :You can not defuse the HBomb when you are idle.");
                                                    }
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :You can not defuse the HBomb when it is locked.");
                                                }
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to defuse!");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #17
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 "ver":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        if (line.GetUpperBound(0) > 3)
                                        {
                                            ircbot.sendData("PRIVMSG", line[4].Trim().ToLower() + " :\u0001VERSION\u0001");
                                            List <string> tmp_list = new List <string>();
                                            tmp_list.Add(line[4].Trim().ToLower());
                                            tmp_list.Add(channel);
                                            version_list.Add(tmp_list);
                                        }
                                        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("query"))
            {
                string version = ":\u0001VERSION\u0001";
                if (line[3] == version)
                {
                    AboutBox1 about = new AboutBox1();
                    ircbot.sendData("NOTICE", nick + " :\u0001VERSION IRCBot v" + about.AssemblyVersion + " on " + conf.module_config[module_id][3] + "\u0001");
                }
            }
            if (type.Equals("line"))
            {
                string version_reply = ":\u0001VERSION";
                if (line.GetUpperBound(0) > 3)
                {
                    if (line[3].Equals(version_reply))
                    {
                        for (int x = 0; x < version_list.Count(); x++)
                        {
                            if (version_list[x][0].Equals(nick))
                            {
                                string response = "[" + nick + "] Using version: " + line[4].Replace("\u0001", "");
                                ircbot.sendData("PRIVMSG", version_list[x][1] + " :" + response);
                                version_list.RemoveAt(x);
                                break;
                            }
                        }
                    }
                }
            }
        }
Пример #18
0
 public override void control(bot ircbot, ref IRCConfig conf, int module_id, string[] line, string command, int nick_access, string nick, string channel, bool bot_command, string type)
 {
     string module_name = ircbot.conf.module_config[module_id][0];
     if ((type.Equals("channel") || type.Equals("query")) && bot_command == true)
     {
         foreach (List<string> tmp_command in conf.command_list)
         {
             if (module_name.Equals(tmp_command[0]))
             {
                 string[] triggers = tmp_command[3].Split('|');
                 int command_access = Convert.ToInt32(tmp_command[5]);
                 string[] blacklist = tmp_command[6].Split(',');
                 bool blocked = false;
                 bool cmd_found = false;
                 bool spam_check = Convert.ToBoolean(tmp_command[8]);
                 foreach (string bl_chan in blacklist)
                 {
                     if (bl_chan.Equals(channel))
                     {
                         blocked = true;
                         break;
                     }
                 }
                 if (spam_check == true)
                 {
                     blocked = ircbot.get_spam_status(channel, nick);
                 }
                 foreach (string trigger in triggers)
                 {
                     if (trigger.Equals(command))
                     {
                         cmd_found = true;
                         break;
                     }
                 }
                 if (blocked == true && cmd_found == true)
                 {
                     ircbot.sendData("NOTICE", nick + " :I am currently too busy to process that.");
                 }
                 if (blocked == false && cmd_found == true)
                 {
                     foreach (string trigger in triggers)
                     {
                         switch (trigger)
                         {
                             case "last":
                                 if (spam_check == true)
                                 {
                                     ircbot.add_spam_count(channel);
                                 }
                                 if (nick_access >= command_access)
                                 {
                                     if (line.GetUpperBound(0) > 3)
                                     {
                                         string[] args = line[4].Split(' ');
                                         if (type.Equals("channel"))
                                         {
                                             if (args.GetUpperBound(0) > 1)
                                             {
                                                 int n;
                                                 bool isNumeric = int.TryParse(args[2], out n);
                                                 if (isNumeric)
                                                 {
                                                     display_log_nick_num(args[1], Convert.ToInt32(args[2]), channel, nick, args[0], ircbot, conf);
                                                 }
                                                 else
                                                 {
                                                     ircbot.sendData("NOTICE", nick + " :" + nick + ", you need to specify a valid number.");
                                                 }
                                             }
                                             else if (args.GetUpperBound(0) > 0)
                                             {
                                                 int n;
                                                 bool isNumeric = int.TryParse(args[1], out n);
                                                 if (isNumeric)
                                                 {
                                                     display_log_number(Convert.ToInt32(args[1]), channel, nick, args[0], ircbot, conf);
                                                 }
                                                 else
                                                 {
                                                     display_log_nick(args[1], channel, nick, args[0], ircbot, conf);
                                                 }
                                             }
                                             else
                                             {
                                                 display_log(channel, nick, line[4], ircbot, conf);
                                             }
                                         }
                                         else
                                         {
                                             if (args.GetUpperBound(0) > 0)
                                             {
                                                 display_log_nick(args[1], channel, nick, args[0], ircbot, conf);
                                             }
                                             else
                                             {
                                                 display_log(channel, nick, line[4], ircbot, conf);
                                             }
                                         }
                                     }
                                     else
                                     {
                                         display_last_log(channel, nick, ircbot, conf);
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                 }
                                 break;
                         }
                     }
                 }
             }
         }
     }
     if (type.Equals("query") && bot_command == true)
     {
         bool command_valid = false;
         foreach (List<string> tmp_command in conf.command_list)
         {
             string[] triggers = tmp_command[3].Split('|');
             foreach (string trigger in triggers)
             {
                 if (command.Equals(trigger))
                 {
                     command_valid = true;
                     break;
                 }
             }
             if (command_valid == true)
             {
                 break;
             }
         }
         if (command_valid == true)
         {
             add_log(nick, "a private message", line, ircbot);
         }
     }
     if (type.Equals("channel") && bot_command == true)
     {
         bool command_valid = false;
         foreach (List<string> tmp_command in conf.command_list)
         {
             string[] triggers = tmp_command[3].Split('|');
             foreach (string trigger in triggers)
             {
                 if (command.Equals(trigger))
                 {
                     command_valid = true;
                     break;
                 }
             }
             if (command_valid == true)
             {
                 break;
             }
         }
         if (command_valid == true)
         {
             add_log(nick, channel, line, ircbot);
         }
     }
 }
Пример #19
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 "poll":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        bool poll_active = false;
                                        foreach (poll_info tmp_poll in poll_list)
                                        {
                                            if (tmp_poll.channel.Equals(channel))
                                            {
                                                poll_active = true;
                                                break;
                                            }
                                        }
                                        if (poll_active == false)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                poll_info temp_poll = new poll_info();
                                                poll_active = true;
                                                string[] lines = line[4].Split('|');
                                                temp_poll.question       = lines[0];
                                                temp_poll.owner          = nick;
                                                temp_poll.channel        = channel;
                                                temp_poll.answers        = new List <List <string> >();
                                                temp_poll.nick_responses = new List <List <string> >();
                                                for (int x = 1; x <= lines.GetUpperBound(0); x++)
                                                {
                                                    List <string> tmp_list = new List <string>();
                                                    tmp_list.Add(lines[x]);
                                                    tmp_list.Add("0");
                                                    temp_poll.answers.Add(tmp_list);
                                                }
                                                ircbot.sendData("PRIVMSG", channel + " :Poll has been started by " + temp_poll.owner + ": " + temp_poll.question);
                                                for (int x = 0; x < temp_poll.answers.Count(); x++)
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :" + (x + 1).ToString() + ") " + temp_poll.answers[x][0]);
                                                }
                                                ircbot.sendData("PRIVMSG", channel + " :To Vote, type " + conf.command + "vote <answer_number>.  You may only vote once per poll.  You can change your vote by voting for a different answer.");
                                                poll_list.Add(temp_poll);
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", line[2] + " :" + nick + ", you need to include more info.");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :There is currently a poll active right now.  To view the current results, type " + conf.command + "results");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;

                                case "addanswer":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        bool      poll_active = false;
                                        poll_info cur_poll    = new poll_info();
                                        foreach (poll_info tmp_poll in poll_list)
                                        {
                                            if (tmp_poll.channel.Equals(channel))
                                            {
                                                cur_poll    = tmp_poll;
                                                poll_active = true;
                                                break;
                                            }
                                        }
                                        if (poll_active == true)
                                        {
                                            if (cur_poll.owner.Equals(nick))
                                            {
                                                if (line.GetUpperBound(0) > 3)
                                                {
                                                    List <string> tmp_list = new List <string>();
                                                    tmp_list.Add(line[4]);
                                                    tmp_list.Add("0");
                                                    cur_poll.answers.Add(tmp_list);
                                                    ircbot.sendData("PRIVMSG", channel + " :An Answer has been added to the poll.");
                                                    ircbot.sendData("PRIVMSG", channel + " :" + cur_poll.answers.Count().ToString() + ")" + line[4]);
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :" + nick + ", you need to include more info.");
                                                }
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :You are not the poll owner.");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :There is currently no poll active right now");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;

                                case "delanswer":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        bool      poll_active = false;
                                        poll_info cur_poll    = new poll_info();
                                        foreach (poll_info tmp_poll in poll_list)
                                        {
                                            if (tmp_poll.channel.Equals(channel))
                                            {
                                                cur_poll    = tmp_poll;
                                                poll_active = true;
                                                break;
                                            }
                                        }
                                        if (poll_active == true)
                                        {
                                            if (cur_poll.owner.Equals(nick))
                                            {
                                                if (line.GetUpperBound(0) > 3)
                                                {
                                                    for (int x = 0; x < cur_poll.answers.Count(); x++)
                                                    {
                                                        if (x == Convert.ToInt32(line[4]))
                                                        {
                                                            ircbot.sendData("PRIVMSG", channel + " :Answer " + x.ToString() + " has been removed.");
                                                            cur_poll.answers.RemoveAt(x);
                                                            break;
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :" + nick + ", you need to include more info.");
                                                }
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :You are not the poll owner.");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :There is currently no poll active right now");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;

                                case "stoppoll":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        bool      poll_active = false;
                                        int       index       = 0;
                                        poll_info cur_poll    = new poll_info();
                                        foreach (poll_info tmp_poll in poll_list)
                                        {
                                            if (tmp_poll.channel.Equals(channel))
                                            {
                                                cur_poll    = tmp_poll;
                                                poll_active = true;
                                                break;
                                            }
                                            index++;
                                        }
                                        if (poll_active == true)
                                        {
                                            if (cur_poll.owner.Equals(nick) || nick_access > Convert.ToInt32(ircbot.get_user_access(cur_poll.owner, channel)))
                                            {
                                                poll_active = false;

                                                ircbot.sendData("PRIVMSG", channel + " :Results of poll by " + cur_poll.owner + ": " + cur_poll.question);
                                                for (int x = 0; x < cur_poll.answers.Count(); x++)
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :" + (x + 1).ToString() + ") " + cur_poll.answers[x][0] + " | " + cur_poll.answers[x][1] + " votes");
                                                }
                                                poll_list.RemoveAt(index);
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :You are not the poll owner.");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :There is currently no poll active right now");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;

                                case "results":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        bool      poll_active = false;
                                        poll_info cur_poll    = new poll_info();
                                        foreach (poll_info tmp_poll in poll_list)
                                        {
                                            if (tmp_poll.channel.Equals(channel))
                                            {
                                                cur_poll    = tmp_poll;
                                                poll_active = true;
                                                break;
                                            }
                                        }
                                        if (poll_active == true)
                                        {
                                            ircbot.sendData("NOTICE", nick + " :Poll by " + cur_poll.owner + ": " + cur_poll.question);
                                            for (int x = 0; x < cur_poll.answers.Count(); x++)
                                            {
                                                ircbot.sendData("NOTICE", nick + " :" + (x + 1).ToString() + ") " + cur_poll.answers[x][0] + " | " + cur_poll.answers[x][1] + " votes");
                                            }
                                            ircbot.sendData("NOTICE", nick + " :To Vote, type .vote <answer_number>.  You may only vote once per poll.  You can change your vote by voting for a different answer.");
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :There is currently no poll active right now");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;

                                case "vote":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        if (line.GetUpperBound(0) > 3)
                                        {
                                            bool      poll_active = false;
                                            poll_info cur_poll    = new poll_info();
                                            foreach (poll_info tmp_poll in poll_list)
                                            {
                                                if (tmp_poll.channel.Equals(channel))
                                                {
                                                    cur_poll    = tmp_poll;
                                                    poll_active = true;
                                                    break;
                                                }
                                            }
                                            if (poll_active == true)
                                            {
                                                try
                                                {
                                                    int vote = Convert.ToInt32(line[4]);
                                                    if (vote > 0 && vote <= cur_poll.answers.Count())
                                                    {
                                                        bool   nick_voted = false;
                                                        int    index      = 0;
                                                        string nick_host  = ircbot.get_user_host(nick);
                                                        if (nick_host.Equals(""))
                                                        {
                                                            nick_host = nick;
                                                        }
                                                        for (int x = 0; x < cur_poll.nick_responses.Count(); x++)
                                                        {
                                                            if (cur_poll.nick_responses[x][0].Equals(nick_host))
                                                            {
                                                                nick_voted = true;
                                                                index      = Convert.ToInt32(cur_poll.nick_responses[x][1]);
                                                                cur_poll.nick_responses[x][1]  = vote.ToString();
                                                                cur_poll.answers[index - 1][1] = (Convert.ToInt32(cur_poll.answers[index - 1][1]) - 1).ToString();
                                                                cur_poll.answers[vote - 1][1]  = (Convert.ToInt32(cur_poll.answers[vote - 1][1]) + 1).ToString();
                                                                break;
                                                            }
                                                        }
                                                        if (nick_voted == false)
                                                        {
                                                            List <string> tmp_list = new List <string>();
                                                            tmp_list.Add(nick_host);
                                                            tmp_list.Add(vote.ToString());
                                                            cur_poll.nick_responses.Add(tmp_list);
                                                            cur_poll.answers[vote - 1][1] = (Convert.ToInt32(cur_poll.answers[vote - 1][1]) + 1).ToString();
                                                        }
                                                        ircbot.sendData("PRIVMSG", channel + " :Thank you for voting for " + vote.ToString());
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("PRIVMSG", channel + " :You need to vote for a valid answer.");
                                                    }
                                                }
                                                catch
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :You need to vote for a valid answer.");
                                                }
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :There is currently no poll active right now");
                                            }
                                        }
                                        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;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #20
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;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #21
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;
                         }
                     }
                 }
             }
         }
     }
 }
Пример #22
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)
        {
            access access = new access();

            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 "alarm":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                string[] new_line = line[4].Split(charS, 2, StringSplitOptions.RemoveEmptyEntries);
                                                if (new_line.GetUpperBound(0) > 0)
                                                {
                                                    bool int_allowed = true;
                                                    int time = 0;
                                                    try
                                                    {
                                                        time = Convert.ToInt32(new_line[0]);
                                                        if ((time * 1000) <= 0)
                                                        {
                                                            int_allowed = false;
                                                        }
                                                    }
                                                    catch
                                                    {
                                                        int_allowed = false;
                                                    }
                                                    if (int_allowed == true)
                                                    {
                                                        char[] charSplit = new char[] { ' ' };
                                                        string[] ex = new_line[1].Split(charSplit);
                                                        if (ex[0].TrimStart(Convert.ToChar(conf.command)).Equals("alarm"))
                                                        {
                                                            if (type.Equals("channel"))
                                                            {
                                                                ircbot.sendData("PRIVMSG", line[2] + " :Recursion is bad.");
                                                            }
                                                            else
                                                            {
                                                                ircbot.sendData("PRIVMSG", nick + " :Recursion is bad.");
                                                            }
                                                        }
                                                        else
                                                        {
                                                            tmp_conf = conf;
                                                            Timer alarm_trigger = new Timer();
                                                            alarm_trigger.Interval = (time * 1000);
                                                            alarm_trigger.Enabled = true;
                                                            alarm_trigger.AutoReset = false;
                                                            alarm_trigger.Elapsed += (sender, e) => ring_alarm(sender, e, ircbot, nick, line[0], nick_access, channel, type, new_line[1]);
                                                            alarms.Add(alarm_trigger);

                                                            if (type.Equals("channel"))
                                                            {
                                                                ircbot.sendData("PRIVMSG", line[2] + " :Alarm added for " + new_line[0] + " seconds from now.");
                                                            }
                                                            else
                                                            {
                                                                ircbot.sendData("PRIVMSG", nick + " :Alarm added for " + new_line[0] + " seconds from now.");
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (type.Equals("channel"))
                                                        {
                                                            ircbot.sendData("PRIVMSG", line[2] + " :" + nick + ", please pick a valid time.");
                                                        }
                                                        else
                                                        {
                                                            ircbot.sendData("PRIVMSG", nick + " :" + nick + ", please pick a valid time.");
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    if (type.Equals("channel"))
                                                    {
                                                        ircbot.sendData("PRIVMSG", line[2] + " :" + nick + ", you need to include more info.");
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("PRIVMSG", nick + " :" + nick + ", you need to include more info.");
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (type.Equals("channel"))
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :" + nick + ", you need to include more info.");
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", nick + " :" + nick + ", you need to include more info.");
                                                }
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #23
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 "stopchat":
                                 if (spam_check == true)
                                 {
                                     ircbot.add_spam_count(channel);
                                 }
                                 if (nick_access >= command_access)
                                 {
                                     foreach (string chat_nick in chatting_nick)
                                     {
                                         if (chat_nick.Equals(nick))
                                         {
                                             still_chatting = false;
                                             chatting_nick.Clear();
                                             chat_time.Enabled = false;
                                             chat_time.Stop();
                                             ircbot.sendData("PRIVMSG", channel + " :Ok, I will stop.");
                                             break;
                                         }
                                     }
                                     if (still_chatting == true)
                                     {
                                         ircbot.sendData("PRIVMSG", channel + " :You are not currently talking to me.");
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                 }
                                 break;
                         }
                     }
                 }
             }
         }
     }
     if (type.Equals("channel") && bot_command == false)
     {
         chat_time.Interval = Convert.ToInt32(conf.module_config[module_id][3]) * 1000;
         if (line.GetUpperBound(0) >= 3)
         {
             string msg = "";
             if (line.GetUpperBound(0) > 3)
             {
                 msg = line[3].TrimStart(':') + " " + line[4];
             }
             else
             {
                 msg = line[3].TrimStart(':');
             }
             string[] words = msg.Split(' ');
             bool me_in = false;
             foreach (string word in words)
             {
                 if (word.ToLower().Contains(conf.nick.ToLower()))
                 {
                     me_in = true;
                     break;
                 }
             }
             if (me_in == true || still_chatting == true)
             {
                 bool nick_found = false;
                 for (int x = 0; x < chatting_nick.Count(); x++)
                 {
                     if (chatting_nick[x].Equals(nick))
                     {
                         nick_found = true;
                     }
                 }
                 if (me_in == true && nick_found == false)
                 {
                     chatting_nick.Add(nick);
                     nick_found = true;
                 }
                 if (nick_found == true)
                 {
                     // Start Chatting
                     still_chatting = false;
                     chat_time.Stop();
                     Request r = new Request(msg, myUser, myBot);
                     Result res = myBot.Chat(r);
                     AboutBox1 about = new AboutBox1();
                     ircbot.sendData("PRIVMSG", channel + " :" + res.Output.Replace("[nick]", nick).Replace("[me]", conf.nick).Replace("[owner]", conf.owner.TrimStart(',').TrimEnd(',').Replace(",", " and ")).Replace("[version]", about.AssemblyVersion).Replace("\n", " "));
                     chat_time.Start();
                     still_chatting = true;
                 }
             }
         }
     }
 }
Пример #24
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 == false)
            {
                string text = "";
                if(line.GetUpperBound(0) > 3)
                {
                    text = line[3] + " " + line[4];
                }
                else
                {
                    text = line[3];
                }
                try
                {
                    Regex regex = new Regex("(((https?|ftp|file)://|www\\.)([A-Z0-9.-:]{1,})\\.[0-9A-Z?;~&#=\\-_\\./]{2,})", RegexOptions.Compiled | RegexOptions.IgnoreCase);

                    //get the first match
                    MatchCollection matches = regex.Matches(text);

                    foreach (Match match in matches)
                    {
                        string testMatch = match.Value.ToString();
                        if (!testMatch.Contains("://"))
                        {
                            testMatch = "http://" + testMatch;
                        }
                        Uri url = new Uri(testMatch);
                        var request = WebRequest.Create(url);
                        request.Timeout = 5000;
                        using (var response = request.GetResponse())
                        {
                            string[] content_type = response.ContentType.Split('/');
                            switch (content_type[0])
                            {
                                case "text":
                                    WebClient x = new WebClient();
                                    string source = x.DownloadString(url.OriginalString);
                                    string title_regex = @"(?<=<title.*>)(.*?)(?=</title>)";
                                    Regex title_ex = new Regex(title_regex, RegexOptions.IgnoreCase);
                                    MatchCollection title_matches = title_ex.Matches(source);
                                    string title = title_matches[0].Value.Trim();
                                    if (url.OriginalString.Contains("youtube.com/watch?") && ircbot.conf.module_config[module_id][4].Equals("True"))
                                    {
                                        string YouTubeVideoID = ExtractYouTubeVideoIDFromUrl(url.OriginalString);
                                        Uri videoEntryUrl = new Uri(string.Format("https://gdata.youtube.com/feeds/api/videos/{0}", YouTubeVideoID));
                                        YouTubeRequestSettings settings = new YouTubeRequestSettings("YouTube Video Duration Sample App", developerKey);
                                        YouTubeRequest yt_request = new YouTubeRequest(settings);
                                        Video video = yt_request.Retrieve<Video>(videoEntryUrl);
                                        int duration = int.Parse(video.Contents.First().Duration);
                                        string yt_title = video.Title;
                                        int views = video.ViewCount;
                                        double rateavg = video.RatingAverage;
                                        string uploader = video.Uploader;
                                        DateTime date = video.Updated;
                                        string total_duration = "";
                                        TimeSpan t = TimeSpan.FromSeconds(duration);
                                        if (t.Hours > 0)
                                        {
                                            total_duration += t.Hours.ToString() + "h ";
                                        }
                                        if (t.Minutes > 0)
                                        {
                                            total_duration += t.Minutes.ToString() + "m ";
                                        }
                                        if (t.Seconds > 0)
                                        {
                                            total_duration += t.Seconds.ToString() + "s ";
                                        }
                                        ircbot.sendData("PRIVMSG", channel + " :[Youtube] Title: " + HttpUtility.HtmlDecode(yt_title) + " | Length: " + total_duration.TrimEnd(' ') + " | Views: " + string.Format("{0:#,###0}", views) + " | Rated: " + Math.Round(rateavg, 2).ToString() + "/5.0 | Uploaded By: " + uploader + " on " + date.ToString("yyyy-MM-dd"));
                                    }
                                    else if (url.OriginalString.Contains("youtu.be") && ircbot.conf.module_config[module_id][4].Equals("True"))
                                    {
                                        string[] url_parsed = url.OriginalString.Split('/');
                                        string YouTubeVideoID = url_parsed[url_parsed.GetUpperBound(0)];
                                        Uri videoEntryUrl = new Uri(string.Format("https://gdata.youtube.com/feeds/api/videos/{0}", YouTubeVideoID));
                                        YouTubeRequestSettings settings = new YouTubeRequestSettings("YouTube Video Duration Sample App", developerKey);
                                        YouTubeRequest yt_request = new YouTubeRequest(settings);
                                        Video video = yt_request.Retrieve<Video>(videoEntryUrl);
                                        int duration = int.Parse(video.Contents.First().Duration);
                                        string yt_title = video.Title;
                                        int views = video.ViewCount;
                                        double rateavg = video.RatingAverage;
                                        string uploader = video.Uploader;
                                        DateTime date = video.Updated;
                                        string total_duration = "";
                                        TimeSpan t = TimeSpan.FromSeconds(duration);
                                        if (t.Hours > 0)
                                        {
                                            total_duration += t.Hours.ToString() + "h ";
                                        }
                                        if (t.Minutes > 0)
                                        {
                                            total_duration += t.Minutes.ToString() + "m ";
                                        }
                                        if (t.Seconds > 0)
                                        {
                                            total_duration += t.Seconds.ToString() + "s ";
                                        }
                                        ircbot.sendData("PRIVMSG", channel + " :[Youtube] Title: " + HttpUtility.HtmlDecode(yt_title) + " | Length: " + total_duration.TrimEnd(' ') + " | Views: " + string.Format("{0:#,###0}", views) + " | Rated: " + Math.Round(rateavg, 2).ToString() + "/5.0 | Uploaded By: " + uploader + " on " + date.ToString("yyyy-MM-dd"));
                                    }
                                    else if ((url.OriginalString.Contains("boards.4chan.org") && url.Segments.GetUpperBound(0) > 2) && ircbot.conf.module_config[module_id][5].Equals("True"))
                                    {
                                        string board = url.Segments[1].TrimEnd('/');
                                        string uri = "https://api.4chan.org/" + board + "/res/" + url.Segments[3] + ".json";
                                        WebClient chan = new WebClient();
                                        var json_data = string.Empty;
                                        json_data = chan.DownloadString(uri);
                                        XmlDocument xmlDoc = JsonConvert.DeserializeXmlNode(json_data, board + "-" + url.Segments[3]);
                                        XmlNodeList post_list = xmlDoc.SelectNodes(board + "-" + url.Segments[3] + "/posts");
                                        string thread = "";
                                        if (!url.Fragment.Equals(string.Empty))
                                        {
                                            thread = url.Fragment.TrimStart('#').TrimStart('p');
                                        }
                                        else
                                        {
                                            thread = url.Segments[3];
                                        }
                                        foreach (XmlNode post in post_list)
                                        {
                                            string post_num = post["no"].InnerText;
                                            if (post_num.Equals(thread))
                                            {
                                                string date = post["now"].InnerText;
                                                string parsed_date = date.Split('(')[0] + " " + date.Split(')')[1];
                                                DateTime post_date = DateTime.Parse(parsed_date);
                                                TimeSpan difference = DateTime.UtcNow - post_date;
                                                difference = difference.Subtract(TimeSpan.FromHours(4));
                                                string total_duration = "";
                                                TimeSpan t = TimeSpan.FromSeconds(difference.TotalSeconds);
                                                if (t.Hours > 0)
                                                {
                                                    total_duration += t.Hours.ToString() + "h ";
                                                }
                                                if (t.Minutes > 0)
                                                {
                                                    total_duration += t.Minutes.ToString() + "m ";
                                                }
                                                if (t.Seconds > 0)
                                                {
                                                    total_duration += t.Seconds.ToString() + "s ";
                                                }
                                                string post_name = "", post_comment = "", tripcode = "", ID = "", email = "", subject = "", replies = "", images = "", image_ext = "", image_name = "", image_width = "", image_height = "";
                                                try
                                                {
                                                    post_name = post["name"].InnerText;
                                                }
                                                catch { }
                                                try
                                                {
                                                    post_comment = post["com"].InnerText;
                                                }
                                                catch { }
                                                try
                                                {
                                                    tripcode = post["trip"].InnerText;
                                                }
                                                catch { }
                                                try
                                                {
                                                    ID = post["id"].InnerText;
                                                }
                                                catch { }
                                                try
                                                {
                                                    email = post["email"].InnerText;
                                                }
                                                catch { }
                                                try
                                                {
                                                    subject = post["sub"].InnerText;
                                                }
                                                catch { }
                                                try
                                                {
                                                    replies = post["replies"].InnerText;
                                                }
                                                catch { }
                                                try
                                                {
                                                    images = post["images"].InnerText;
                                                }
                                                catch { }
                                                try
                                                {
                                                    image_ext = post["ext"].InnerText;
                                                }
                                                catch { }
                                                try
                                                {
                                                    image_name = post["tim"].InnerText;
                                                }
                                                catch { }
                                                try
                                                {
                                                    image_width = post["w"].InnerText;
                                                }
                                                catch { }
                                                try
                                                {
                                                    image_height = post["h"].InnerText;
                                                }
                                                catch { }

                                                if (!ID.Trim().Equals(string.Empty))
                                                {
                                                    ID = "[" + ID + "]";
                                                }

                                                string post_message = "";
                                                if (!subject.Equals(string.Empty))
                                                {
                                                    post_message += "Subject: " + subject + " | ";
                                                }
                                                string[] words = post_comment.Split(' ');
                                                if (words.GetUpperBound(0) > 10)
                                                {
                                                    post_message += " Comment: ";
                                                    for (int i = 0; i < 15; i++)
                                                    {
                                                        post_message += words[i] + " ";
                                                    }
                                                    post_message += "...";
                                                }
                                                else if (!post_comment.Equals(string.Empty))
                                                {
                                                    post_message += " Comment: " + post_comment;
                                                }

                                                string[] tmp_post = Regex.Split(post_message, "<br>");
                                                post_message = "";
                                                foreach (string tmp in tmp_post)
                                                {
                                                    if (!tmp.Trim().Equals(string.Empty))
                                                    {
                                                        post_message += HttpUtility.HtmlDecode(tmp) + " | ";
                                                    }
                                                }

                                                string image_url = "";
                                                if (!image_name.Equals(string.Empty))
                                                {
                                                    image_url = "http://images.4chan.org/" + board + "/src/" + image_name + image_ext;
                                                }

                                                if (!image_url.Equals(string.Empty))
                                                {
                                                    image_url = " | Posted Image: " + image_url + " (" + image_width + "x" + image_height + ")";
                                                }

                                                if (!replies.Equals(string.Empty))
                                                {
                                                    replies = " | Replies: " + replies;
                                                }

                                                if (!images.Equals(string.Empty))
                                                {
                                                    images = " | Images: " + images;
                                                }

                                                ircbot.sendData("PRIVMSG", channel + " :[4chan] /" + board + "/ | Posted by: " + post_name + tripcode + ID + " " + total_duration.Trim() + " ago" + replies + images + image_url);
                                                string re = @"<a [^>]+>(.*?)<\/a>(.*?)";
                                                if (!post_message.Equals(string.Empty))
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :" + Regex.Replace(post_message.Trim().TrimEnd('|').Trim(), re, "$1"));
                                                }
                                                break;
                                            }
                                        }
                                    }
                                    else if (ircbot.conf.module_config[module_id][3].Equals("True"))
                                    {
                                        ircbot.sendData("PRIVMSG", channel + " :[URL] " + HttpUtility.HtmlDecode(title) + " (" + url.Host.ToLower() + ")");
                                    }
                                    break;
                                case "image":
                                    if (ircbot.conf.module_config[module_id][6].Equals("True"))
                                    {
                                        Image _image = null;
                                        _image = DownloadImage(url.OriginalString);
                                        if (_image != null)
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :[" + response.ContentType + "] Size: " + ToFileSize(response.ContentLength) + " | Width: " + _image.Width.ToString() + "px | Height: " + _image.Height.ToString() + "px");
                                        }
                                    }
                                    break;
                                case "video":
                                    if (ircbot.conf.module_config[module_id][7].Equals("True"))
                                    {
                                        ircbot.sendData("PRIVMSG", channel + " :[Video] Type: " + content_type[1] + " | Size: " + ToFileSize(response.ContentLength));
                                    }
                                    break;
                                case "application":
                                    if (ircbot.conf.module_config[module_id][8].Equals("True"))
                                    {
                                        ircbot.sendData("PRIVMSG", channel + " :[Application] Type: " + content_type[1] + " | Size: " + ToFileSize(response.ContentLength));
                                    }
                                    break;
                                case "audio":
                                    if (ircbot.conf.module_config[module_id][9].Equals("True"))
                                    {
                                        ircbot.sendData("PRIVMSG", channel + " :[Audio] Type: " + content_type[1] + " | Size: " + ToFileSize(response.ContentLength));
                                    }
                                    break;
                                default:
                                    if (ircbot.conf.module_config[module_id][10].Equals("True"))
                                    {
                                        ircbot.sendData("PRIVMSG", channel + " :[URL] " + HttpUtility.HtmlDecode(response.ContentType) + " (" + url.Host.ToLower() + ")");
                                    }
                                    break;
                            }

                        }
                    }
                }
                catch
                {
                }
            }
        }
Пример #25
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 == false)
            {
                string full_line = "";
                if (line.GetUpperBound(0) > 3)
                {
                    full_line = line[3].TrimStart(':') + " " + line[4];
                }
                else
                {
                    full_line = line[3].TrimStart(':');
                }
                Regex reg = new Regex(@"((^s\/)(([^\/]*)+|([^\/]*)+\/\/([^\/]*)+)\/(([^\/]*)+|([^\/]*)+\/\/([^\/]*)+)\/(([g|I]+)|$))", RegexOptions.None);
                MatchCollection matches = reg.Matches(full_line);
                if (matches.Count > 0)
                {
                    bool nick_found = false;
                    string past_line = "";
                    foreach (List<string> nick_log in nick_logs)
                    {
                        if (nick_log[0].Equals(channel) && nick_log[1].Equals(nick))
                        {
                            nick_found = true;
                            past_line = nick_log[2];
                            break;
                        }
                    }
                    if (nick_found)
                    {
                        string[] parts = matches[0].ToString().Split('/');
                        string pattern = parts[1];
                        string replace = parts[2];
                        string order = "";
                        if (parts.GetUpperBound(0) > 2)
                        {
                            order = parts[3];
                        }

                        RegexOptions reg_options = new RegexOptions();
                        reg_options = RegexOptions.Singleline;
                        bool recurse = false;
                        foreach (char c in order.ToCharArray())
                        {
                            if (c.Equals('I'))
                            {
                                reg_options = RegexOptions.IgnoreCase;
                            }
                            else if (c.Equals('g'))
                            {
                                recurse = true;
                            }
                        }

                        Regex line_reg = new Regex(pattern, reg_options);
                        string result = "";
                        if (recurse)
                        {
                            result = line_reg.Replace(past_line, replace);
                        }
                        else
                        {
                            result = line_reg.Replace(past_line, replace, 1);
                        }
                        for (int x = 0; x < nick_logs.Count(); x++)
                        {
                            if (nick_logs[x][0].Equals(channel) && nick_logs[x][1].Equals(nick))
                            {
                                nick_logs[x][2] = result;
                                break;
                            }
                        }
                        ircbot.sendData("PRIVMSG", channel + " :[" + nick + "] " + result);
                    }
                    else
                    {
                        ircbot.sendData("PRIVMSG", channel + " :I don't remember what you said earlier.");
                    }
                }
                else
                {
                    bool nick_found = false;
                    for (int x = 0; x < nick_logs.Count(); x++)
                    {
                        if (nick_logs[x][0].Equals(channel) && nick_logs[x][1].Equals(nick))
                        {
                            nick_found = true;
                            nick_logs[x][2] = full_line;
                            break;
                        }
                    }
                    if (!nick_found)
                    {
                        List<string> tmp_list = new List<string>();
                        tmp_list.Add(channel);
                        tmp_list.Add(nick);
                        tmp_list.Add(full_line);
                        nick_logs.Add(tmp_list);
                    }
                }
            }
        }
Пример #26
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 "poll":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            bool poll_active = false;
                                            foreach (poll_info tmp_poll in poll_list)
                                            {
                                                if (tmp_poll.channel.Equals(channel))
                                                {
                                                    poll_active = true;
                                                    break;
                                                }
                                            }
                                            if (poll_active == false)
                                            {
                                                if (line.GetUpperBound(0) > 3)
                                                {
                                                    poll_info temp_poll = new poll_info();
                                                    poll_active = true;
                                                    string[] lines = line[4].Split('|');
                                                    temp_poll.question = lines[0];
                                                    temp_poll.owner = nick;
                                                    temp_poll.channel = channel;
                                                    temp_poll.answers = new List<List<string>>();
                                                    temp_poll.nick_responses = new List<List<string>>();
                                                    for (int x = 1; x <= lines.GetUpperBound(0); x++)
                                                    {
                                                        List<string> tmp_list = new List<string>();
                                                        tmp_list.Add(lines[x]);
                                                        tmp_list.Add("0");
                                                        temp_poll.answers.Add(tmp_list);
                                                    }
                                                    ircbot.sendData("PRIVMSG", channel + " :Poll has been started by " + temp_poll.owner + ": " + temp_poll.question);
                                                    for (int x = 0; x < temp_poll.answers.Count(); x++)
                                                    {
                                                        ircbot.sendData("PRIVMSG", channel + " :" + (x + 1).ToString() + ") " + temp_poll.answers[x][0]);
                                                    }
                                                    ircbot.sendData("PRIVMSG", channel + " :To Vote, type " + conf.command + "vote <answer_number>.  You may only vote once per poll.  You can change your vote by voting for a different answer.");
                                                    poll_list.Add(temp_poll);
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :" + nick + ", you need to include more info.");
                                                }
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :There is currently a poll active right now.  To view the current results, type " + conf.command + "results");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                    case "addanswer":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            bool poll_active = false;
                                            poll_info cur_poll = new poll_info();
                                            foreach (poll_info tmp_poll in poll_list)
                                            {
                                                if (tmp_poll.channel.Equals(channel))
                                                {
                                                    cur_poll = tmp_poll;
                                                    poll_active = true;
                                                    break;
                                                }
                                            }
                                            if (poll_active == true)
                                            {
                                                if (cur_poll.owner.Equals(nick))
                                                {
                                                    if (line.GetUpperBound(0) > 3)
                                                    {
                                                            List<string> tmp_list = new List<string>();
                                                            tmp_list.Add(line[4]);
                                                            tmp_list.Add("0");
                                                            cur_poll.answers.Add(tmp_list);
                                                            ircbot.sendData("PRIVMSG", channel + " :An Answer has been added to the poll.");
                                                            ircbot.sendData("PRIVMSG", channel + " :" + cur_poll.answers.Count().ToString() + ")" + line[4]);
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("PRIVMSG", line[2] + " :" + nick + ", you need to include more info.");
                                                    }
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :You are not the poll owner.");
                                                }
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :There is currently no poll active right now");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                    case "delanswer":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            bool poll_active = false;
                                            poll_info cur_poll = new poll_info();
                                            foreach (poll_info tmp_poll in poll_list)
                                            {
                                                if (tmp_poll.channel.Equals(channel))
                                                {
                                                    cur_poll = tmp_poll;
                                                    poll_active = true;
                                                    break;
                                                }
                                            }
                                            if (poll_active == true)
                                            {
                                                if (cur_poll.owner.Equals(nick))
                                                {
                                                    if (line.GetUpperBound(0) > 3)
                                                    {
                                                        for (int x = 0; x < cur_poll.answers.Count(); x++)
                                                        {
                                                            if (x == Convert.ToInt32(line[4]))
                                                            {
                                                                ircbot.sendData("PRIVMSG", channel + " :Answer " + x.ToString() + " has been removed.");
                                                                cur_poll.answers.RemoveAt(x);
                                                                break;
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("PRIVMSG", line[2] + " :" + nick + ", you need to include more info.");
                                                    }
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :You are not the poll owner.");
                                                }
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :There is currently no poll active right now");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                    case "stoppoll":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            bool poll_active = false;
                                            int index = 0;
                                            poll_info cur_poll = new poll_info();
                                            foreach (poll_info tmp_poll in poll_list)
                                            {
                                                if (tmp_poll.channel.Equals(channel))
                                                {
                                                    cur_poll = tmp_poll;
                                                    poll_active = true;
                                                    break;
                                                }
                                                index++;
                                            }
                                            if (poll_active == true)
                                            {
                                                if (cur_poll.owner.Equals(nick) || nick_access > Convert.ToInt32(ircbot.get_user_access(cur_poll.owner, channel)))
                                                {
                                                    poll_active = false;

                                                    ircbot.sendData("PRIVMSG", channel + " :Results of poll by " + cur_poll.owner + ": " + cur_poll.question);
                                                    for (int x = 0; x < cur_poll.answers.Count(); x++)
                                                    {
                                                        ircbot.sendData("PRIVMSG", channel + " :" + (x + 1).ToString() + ") " + cur_poll.answers[x][0] + " | " + cur_poll.answers[x][1] + " votes");
                                                    }
                                                    poll_list.RemoveAt(index);
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :You are not the poll owner.");
                                                }
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :There is currently no poll active right now");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                    case "results":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            bool poll_active = false;
                                            poll_info cur_poll = new poll_info();
                                            foreach (poll_info tmp_poll in poll_list)
                                            {
                                                if (tmp_poll.channel.Equals(channel))
                                                {
                                                    cur_poll = tmp_poll;
                                                    poll_active = true;
                                                    break;
                                                }
                                            }
                                            if (poll_active == true)
                                            {
                                                ircbot.sendData("NOTICE", nick + " :Poll by " + cur_poll.owner + ": " + cur_poll.question);
                                                for (int x = 0; x < cur_poll.answers.Count(); x++)
                                                {
                                                    ircbot.sendData("NOTICE", nick + " :" + (x + 1).ToString() + ") " + cur_poll.answers[x][0] + " | " + cur_poll.answers[x][1] + " votes");
                                                }
                                                ircbot.sendData("NOTICE", nick + " :To Vote, type .vote <answer_number>.  You may only vote once per poll.  You can change your vote by voting for a different answer.");
                                            }
                                            else
                                            {
                                                ircbot.sendData("NOTICE", nick + " :There is currently no poll active right now");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                    case "vote":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                bool poll_active = false;
                                                poll_info cur_poll = new poll_info();
                                                foreach (poll_info tmp_poll in poll_list)
                                                {
                                                    if (tmp_poll.channel.Equals(channel))
                                                    {
                                                        cur_poll = tmp_poll;
                                                        poll_active = true;
                                                        break;
                                                    }
                                                }
                                                if (poll_active == true)
                                                {
                                                    try
                                                    {
                                                        int vote = Convert.ToInt32(line[4]);
                                                        if (vote > 0 && vote <= cur_poll.answers.Count())
                                                        {
                                                            bool nick_voted = false;
                                                            int index = 0;
                                                            string nick_host = ircbot.get_user_host(nick);
                                                            if (nick_host.Equals(""))
                                                            {
                                                                nick_host = nick;
                                                            }
                                                            for (int x = 0; x < cur_poll.nick_responses.Count(); x++)
                                                            {
                                                                if (cur_poll.nick_responses[x][0].Equals(nick_host))
                                                                {
                                                                    nick_voted = true;
                                                                    index = Convert.ToInt32(cur_poll.nick_responses[x][1]);
                                                                    cur_poll.nick_responses[x][1] = vote.ToString();
                                                                    cur_poll.answers[index - 1][1] = (Convert.ToInt32(cur_poll.answers[index - 1][1]) - 1).ToString();
                                                                    cur_poll.answers[vote - 1][1] = (Convert.ToInt32(cur_poll.answers[vote - 1][1]) + 1).ToString();
                                                                    break;
                                                                }
                                                            }
                                                            if (nick_voted == false)
                                                            {
                                                                List<string> tmp_list = new List<string>();
                                                                tmp_list.Add(nick_host);
                                                                tmp_list.Add(vote.ToString());
                                                                cur_poll.nick_responses.Add(tmp_list);
                                                                cur_poll.answers[vote - 1][1] = (Convert.ToInt32(cur_poll.answers[vote - 1][1]) + 1).ToString();
                                                            }
                                                            ircbot.sendData("PRIVMSG", channel + " :Thank you for voting for " + vote.ToString());
                                                        }
                                                        else
                                                        {
                                                            ircbot.sendData("PRIVMSG", channel + " :You need to vote for a valid answer.");
                                                        }
                                                    }
                                                    catch
                                                    {
                                                        ircbot.sendData("PRIVMSG", channel + " :You need to vote for a valid answer.");
                                                    }
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :There is currently no poll active right now");
                                                }
                                            }
                                            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;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #27
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 "rollcall":
                                 if (spam_check == true)
                                 {
                                     ircbot.add_spam_count(channel);
                                 }
                                 if (nick_access >= 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 = "";
                                     for (int x = 0; x < ircbot.nick_list.Count(); x++)
                                     {
                                         if (ircbot.nick_list[x][0].Equals(channel))
                                         {
                                             for (int i = 1; i < ircbot.nick_list[x].Count(); i++)
                                             {
                                                 string[] split = ircbot.nick_list[x][i].Split(':');
                                                 if (split.GetUpperBound(0) > 0)
                                                 {
                                                     nicks += split[1] + ", ";
                                                 }
                                             }
                                             break;
                                         }
                                     }
                                     ircbot.sendData("PRIVMSG", channel + " :" + conf.module_config[module_id][3] + ": " + nicks.Trim().TrimEnd(','));
                                 }
                                 break;
                         }
                     }
                 }
             }
         }
     }
 }
Пример #28
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;
                         }
                     }
                 }
             }
         }
     }
 }
Пример #29
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 == false)
            {
                string full_line = "";
                if (line.GetUpperBound(0) > 3)
                {
                    full_line = line[3].TrimStart(':') + " " + line[4];
                }
                else
                {
                    full_line = line[3].TrimStart(':');
                }
                Regex           reg     = new Regex(@"((^s\/)(([^\/]*)+|([^\/]*)+\/\/([^\/]*)+)\/(([^\/]*)+|([^\/]*)+\/\/([^\/]*)+)\/(([g|I]+)|$))", RegexOptions.None);
                MatchCollection matches = reg.Matches(full_line);
                if (matches.Count > 0)
                {
                    bool   nick_found = false;
                    string past_line  = "";
                    foreach (List <string> nick_log in nick_logs)
                    {
                        if (nick_log[0].Equals(channel) && nick_log[1].Equals(nick))
                        {
                            nick_found = true;
                            past_line  = nick_log[2];
                            break;
                        }
                    }
                    if (nick_found)
                    {
                        string[] parts   = matches[0].ToString().Split('/');
                        string   pattern = parts[1];
                        string   replace = parts[2];
                        string   order   = "";
                        if (parts.GetUpperBound(0) > 2)
                        {
                            order = parts[3];
                        }

                        RegexOptions reg_options = new RegexOptions();
                        reg_options = RegexOptions.Singleline;
                        bool recurse = false;
                        foreach (char c in order.ToCharArray())
                        {
                            if (c.Equals('I'))
                            {
                                reg_options = RegexOptions.IgnoreCase;
                            }
                            else if (c.Equals('g'))
                            {
                                recurse = true;
                            }
                        }

                        Regex  line_reg = new Regex(pattern, reg_options);
                        string result   = "";
                        if (recurse)
                        {
                            result = line_reg.Replace(past_line, replace);
                        }
                        else
                        {
                            result = line_reg.Replace(past_line, replace, 1);
                        }
                        for (int x = 0; x < nick_logs.Count(); x++)
                        {
                            if (nick_logs[x][0].Equals(channel) && nick_logs[x][1].Equals(nick))
                            {
                                nick_logs[x][2] = result;
                                break;
                            }
                        }
                        ircbot.sendData("PRIVMSG", channel + " :[" + nick + "] " + result);
                    }
                    else
                    {
                        ircbot.sendData("PRIVMSG", channel + " :I don't remember what you said earlier.");
                    }
                }
                else
                {
                    bool nick_found = false;
                    for (int x = 0; x < nick_logs.Count(); x++)
                    {
                        if (nick_logs[x][0].Equals(channel) && nick_logs[x][1].Equals(nick))
                        {
                            nick_found      = true;
                            nick_logs[x][2] = full_line;
                            break;
                        }
                    }
                    if (!nick_found)
                    {
                        List <string> tmp_list = new List <string>();
                        tmp_list.Add(channel);
                        tmp_list.Add(nick);
                        tmp_list.Add(full_line);
                        nick_logs.Add(tmp_list);
                    }
                }
            }
        }
Пример #30
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 "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;
                         }
                     }
                 }
             }
         }
     }
 }
Пример #31
0
        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.");
                }
            }
        }
Пример #32
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 "4chan":
                                    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 (args.GetUpperBound(0) > 1)
                                            {
                                                try
                                                {
                                                    bool thread_id = false;
                                                    bool reply_id  = false;
                                                    if (args[1].StartsWith("#"))
                                                    {
                                                        thread_id = true;
                                                        args[1]   = args[1].TrimStart('#');
                                                    }
                                                    if (args[2].StartsWith("#"))
                                                    {
                                                        reply_id = true;
                                                        args[2]  = args[2].TrimStart('#');
                                                    }
                                                    bool thread_found = get_reply(channel, ircbot, args[0], args[1], args[2], thread_id, reply_id);
                                                    if (!thread_found)
                                                    {
                                                        ircbot.sendData("PRIVMSG", channel + " :Could not find the thread specified");
                                                    }
                                                }
                                                catch
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :Could not find the thread specified");
                                                }
                                            }
                                            else if (args.GetUpperBound(0) > 0)
                                            {
                                                try
                                                {
                                                    bool thread_id = false;
                                                    if (args[1].StartsWith("#"))
                                                    {
                                                        thread_id = true;
                                                        args[1]   = args[1].TrimStart('#');
                                                    }
                                                    bool thread_found = get_thread(channel, ircbot, args[0], args[1], thread_id);
                                                    if (!thread_found)
                                                    {
                                                        ircbot.sendData("PRIVMSG", channel + " :Could not find the thread specified");
                                                    }
                                                }
                                                catch
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :Could not find the thread specified");
                                                }
                                            }
                                            else
                                            {
                                                bool thread_found = get_thread(channel, ircbot, args[0], "0", false);
                                                if (!thread_found)
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :Could not find the board specified");
                                                }
                                            }
                                        }
                                        else
                                        {
                                            string    uri       = "https://api.4chan.org/boards.json";
                                            WebClient chan      = new WebClient();
                                            var       json_data = string.Empty;
                                            json_data = chan.DownloadString(uri);
                                            XmlDocument xmlDoc     = JsonConvert.DeserializeXmlNode(json_data, "_4chan");
                                            XmlNodeList board_list = xmlDoc.SelectNodes("_4chan/boards");
                                            string      msg        = "";
                                            foreach (XmlNode tmp_board in board_list)
                                            {
                                                msg += " /" + tmp_board["board"].InnerText + "/,";
                                            }
                                            if (!msg.Equals(string.Empty))
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :Boards Available:" + msg.TrimEnd(','));
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :No Boards Available");
                                            }
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;

                                case "next_thread":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        bool   chan_found = false;
                                        string board      = "";
                                        string thread     = "";
                                        bool   thread_id  = false;
                                        for (int x = 0; x < Board_stats.Count(); x++)
                                        {
                                            if (Board_stats[x].channel.Equals(channel))
                                            {
                                                chan_found = true;
                                                board      = Board_stats[x].cur_board;
                                                thread     = (Board_stats[x].cur_OP_num + 1).ToString();
                                            }
                                        }
                                        if (!chan_found)
                                        {
                                            string    uri       = "https://api.4chan.org/boards.json";
                                            WebClient chan      = new WebClient();
                                            var       json_data = string.Empty;
                                            json_data = chan.DownloadString(uri);
                                            XmlDocument xmlDoc     = JsonConvert.DeserializeXmlNode(json_data, "_4chan");
                                            XmlNodeList board_list = xmlDoc.SelectNodes("_4chan/boards");
                                            Random      rand       = new Random();
                                            int         stop       = rand.Next(board_list.Count);
                                            int         index      = 0;
                                            foreach (XmlNode tmp_board in board_list)
                                            {
                                                if (stop == index)
                                                {
                                                    board = tmp_board["board"].InnerText;
                                                    break;
                                                }
                                                index++;
                                            }
                                            thread = "0";
                                        }
                                        bool thread_found = get_thread(channel, ircbot, board, thread, thread_id);
                                        if (!thread_found)
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :Could not find the thread specified");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;

                                case "next_reply":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        bool   chan_found = false;
                                        string board      = "";
                                        string thread     = "";
                                        string reply      = "";
                                        bool   thread_id  = false;
                                        bool   reply_id   = false;
                                        for (int x = 0; x < Board_stats.Count(); x++)
                                        {
                                            if (Board_stats[x].channel.Equals(channel))
                                            {
                                                chan_found = true;
                                                board      = Board_stats[x].cur_board;
                                                thread     = Board_stats[x].cur_thread;
                                                thread_id  = true;
                                                reply      = (Board_stats[x].cur_reply_num + 1).ToString();
                                            }
                                        }
                                        if (!chan_found)
                                        {
                                            string    uri       = "https://api.4chan.org/boards.json";
                                            WebClient chan      = new WebClient();
                                            var       json_data = string.Empty;
                                            json_data = chan.DownloadString(uri);
                                            XmlDocument xmlDoc     = JsonConvert.DeserializeXmlNode(json_data, "_4chan");
                                            XmlNodeList board_list = xmlDoc.SelectNodes("_4chan/boards");
                                            Random      rand       = new Random();
                                            int         stop       = rand.Next(board_list.Count);
                                            int         index      = 0;
                                            foreach (XmlNode tmp_board in board_list)
                                            {
                                                if (stop == index)
                                                {
                                                    board = tmp_board["board"].InnerText;
                                                    break;
                                                }
                                                index++;
                                            }
                                            thread = "0";
                                            reply  = "0";
                                        }
                                        bool thread_found = get_reply(channel, ircbot, board, thread, reply, thread_id, reply_id);
                                        if (!thread_found)
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :Could not find the thread specified");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #33
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 "love":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        if (line.GetUpperBound(0) > 3)
                                        {
                                            Random random  = new Random();
                                            int    ran_num = random.Next(0, 3);
                                            switch (ran_num)
                                            {
                                            case 0:
                                                ircbot.sendData("PRIVMSG", channel + " :\u0001ACTION Gently makes love to " + line[4] + "\u0001");
                                                break;

                                            case 1:
                                                ircbot.sendData("PRIVMSG", channel + " :\u0001ACTION sings a love ballad to " + line[4] + "\u0001");
                                                break;

                                            case 2:
                                                ircbot.sendData("PRIVMSG", channel + " :\u0001ACTION slowly sneaks up behind " + line[4] + "\u0001");
                                                ircbot.sendData("PRIVMSG", channel + " :\u0001ACTION squeezes " + line[4] + " tightly\u0001");
                                                ircbot.sendData("PRIVMSG", line[4] + " :I'll give you some more later tonight.  ;)");
                                                break;

                                            case 3:
                                                ircbot.sendData("PRIVMSG", channel + " :I love you " + line[4] + "!  Sooo much!");
                                                break;
                                            }
                                        }
                                        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;

                                case "hug":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        if (line.GetUpperBound(0) > 3)
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :\u0001ACTION hugs " + line[4] + "\u0001");
                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :\u0001ACTION hugs " + nick + "\u0001");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;

                                case "slap":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        if (line.GetUpperBound(0) > 3)
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :\u0001ACTION slaps " + line[4] + " with a large trout\u0001");
                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :\u0001ACTION slaps " + nick + " with a large trout\u0001");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;

                                case "bots":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        ircbot.sendData("PRIVMSG", channel + " :Reporting in!");
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;

                                case "br":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        ircbot.sendData("PRIVMSG", channel + " :HUEHUEHUE");
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;

                                case "net":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        ircbot.sendData("PRIVMSG", channel + " :Sure is enterprise quality in here");
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #34
0
 public void setConfig(IRCConfig conf)
 {
     config = conf;
 }
Пример #35
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.");
     }
 }
Пример #36
0
        public override void control(bot ircbot, ref IRCConfig conf, int module_id, string[] line, string command, int nick_access, string nick, string channel, bool bot_command, string type)
        {
            access access = new access();

            char[] charS = new char[] { ' ' };
            string module_name = ircbot.conf.module_config[module_id][0];
            string disallowed_modes = ircbot.conf.module_config[module_id][3];
            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 "founder":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                ircbot.sendData("MODE", line[2] + " +q " + line[4].ToLower());
                                                access.set_access_list(line[4].ToLower(), line[2], conf.founder_level.ToString(), ircbot);
                                            }
                                            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;
                                    case "defounder":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                ircbot.sendData("MODE", line[2] + " -q " + line[4].ToLower());
                                                access.del_access_list(line[4].ToLower(), line[2], conf.founder_level.ToString(), ircbot);
                                            }
                                            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;
                                    case "sop":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                ircbot.sendData("MODE", line[2] + " +a " + line[4].ToLower());
                                                access.set_access_list(line[4].ToLower(), line[2], conf.sop_level.ToString(), ircbot);
                                            }
                                            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;
                                    case "asop":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                ircbot.sendData("MODE", line[2] + " +a " + line[4].ToLower());
                                                ircbot.sendData("PRIVMSG", "chanserv :SOP " + line[2] + " add " + line[4].ToLower());
                                                access.set_access_list(line[4].ToLower(), line[2], conf.sop_level.ToString(), ircbot);
                                            }
                                            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;
                                    case "deasop":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                ircbot.sendData("MODE", line[2] + " -a " + line[4].ToLower());
                                                ircbot.sendData("PRIVMSG", "chanserv :SOP " + line[2] + " del " + line[4].ToLower());
                                                access.del_access_list(line[4].ToLower(), line[2], conf.sop_level.ToString(), ircbot);
                                            }
                                            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;
                                    case "desop":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                ircbot.sendData("MODE", line[2] + " -a " + line[4].ToLower());
                                                access.del_access_list(line[4].ToLower(), line[2], conf.sop_level.ToString(), ircbot);
                                            }
                                            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;
                                    case "op":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                ircbot.sendData("MODE", line[2] + " +o " + line[4].ToLower());
                                                access.set_access_list(line[4].ToLower(), line[2], conf.op_level.ToString(), ircbot);
                                            }
                                            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;
                                    case "aop":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                ircbot.sendData("MODE", line[2] + " +o " + line[4].ToLower());
                                                ircbot.sendData("PRIVMSG", "chanserv :AOP " + line[2] + " add " + line[4].ToLower());
                                                access.set_access_list(line[4].ToLower(), line[2], conf.op_level.ToString(), ircbot);
                                            }
                                            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;
                                    case "deaop":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                ircbot.sendData("MODE", line[2] + " -o " + line[4].ToLower());
                                                ircbot.sendData("PRIVMSG", "chanserv :AOP " + line[2] + " del " + line[4].ToLower());
                                                access.del_access_list(line[4].ToLower(), line[2], conf.op_level.ToString(), ircbot);
                                            }
                                            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;
                                    case "deop":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                ircbot.sendData("MODE", line[2] + " -o " + line[4].ToLower());
                                                access.del_access_list(line[4].ToLower(), line[2], conf.op_level.ToString(), ircbot);
                                            }
                                            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;
                                    case "ahop":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                ircbot.sendData("MODE", line[2] + " +h " + line[4].ToLower());
                                                ircbot.sendData("PRIVMSG", "chanserv :HOP " + line[2] + " add " + line[4].ToLower());
                                                access.set_access_list(line[4].ToLower(), line[2], conf.hop_level.ToString(), ircbot);
                                            }
                                            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;
                                    case "deahop":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                ircbot.sendData("MODE", line[2] + " -h " + line[4].ToLower());
                                                ircbot.sendData("PRIVMSG", "chanserv :HOP " + line[2] + " del " + line[4].ToLower());
                                                access.del_access_list(line[4].ToLower(), line[2], conf.hop_level.ToString(), ircbot);
                                            }
                                            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;
                                    case "hop":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                ircbot.sendData("MODE", line[2] + " +h " + line[4].ToLower());
                                                access.set_access_list(line[4].ToLower(), line[2], conf.hop_level.ToString(), ircbot);
                                            }
                                            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;
                                    case "dehop":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                ircbot.sendData("MODE", line[2] + " -h " + line[4].ToLower());
                                                access.del_access_list(line[4].ToLower(), line[2], conf.hop_level.ToString(), ircbot);
                                            }
                                            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;
                                    case "avoice":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                ircbot.sendData("MODE", line[2] + " +v " + line[4].ToLower());
                                                ircbot.sendData("PRIVMSG", "chanserv :VOP " + line[2] + " add " + line[4].ToLower());
                                                access.set_access_list(line[4].ToLower(), line[2], conf.voice_level.ToString(), ircbot);
                                            }
                                            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;
                                    case "deavoice":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                ircbot.sendData("MODE", line[2] + " -v " + line[4].ToLower());
                                                ircbot.sendData("PRIVMSG", "chanserv :VOP " + line[2] + " del " + line[4].ToLower());
                                                access.del_access_list(line[4].ToLower(), line[2], conf.voice_level.ToString(), ircbot);
                                            }
                                            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;
                                    case "voice":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                ircbot.sendData("MODE", line[2] + " +v " + line[4].ToLower());
                                                access.set_access_list(line[4].ToLower(), line[2], conf.voice_level.ToString(), ircbot);
                                            }
                                            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;
                                    case "devoice":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                ircbot.sendData("MODE", line[2] + " -v " + line[4].ToLower());
                                                access.del_access_list(line[4].ToLower(), line[2], conf.voice_level.ToString(), ircbot);
                                            }
                                            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;
                                    case "mode":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                string[] new_line = line[4].Split(charS, 2);
                                                char[] arr = new_line[0].ToCharArray();

                                                bool mode_allowed = true;
                                                bool positive = true;
                                                int mode_index = 0;
                                                foreach (char c in arr)
                                                {
                                                    if (!c.Equals('+') && !c.Equals('-'))
                                                    {
                                                        char[] modes_disallowed = disallowed_modes.ToCharArray();
                                                        foreach (char m in modes_disallowed)
                                                        {
                                                            if (m.Equals(c))
                                                            {
                                                                mode_allowed = false;
                                                                break;
                                                            }
                                                        }
                                                        if (mode_allowed == true)
                                                        {
                                                            if (c.Equals('q') || c.Equals('a') || c.Equals('o') || c.Equals('h') || c.Equals('v'))
                                                            {
                                                                int mode_access = ircbot.get_access_num(c.ToString(), true);
                                                                if (nick_access < mode_access)
                                                                {
                                                                    mode_allowed = false;
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                        if (mode_allowed)
                                                        {
                                                            string leading_cmd = "";
                                                            if (positive)
                                                            {
                                                                leading_cmd = "+";
                                                            }
                                                            else
                                                            {
                                                                leading_cmd = "-";
                                                            }
                                                            bool nick_needed = false;
                                                            if (new_line.GetUpperBound(0) > 0)
                                                            {
                                                                string[] nicks = new_line[1].Split(charS);
                                                                if (nicks.GetUpperBound(0) >= mode_index)
                                                                {
                                                                    nick_needed = true;
                                                                }
                                                            }
                                                            if (nick_needed)
                                                            {
                                                                string[] nicks = new_line[1].Split(charS);
                                                                ircbot.sendData("MODE", line[2] + " " + leading_cmd + c.ToString() + " :" + nicks[mode_index]);
                                                            }
                                                            else
                                                            {
                                                                ircbot.sendData("MODE", line[2] + " " + leading_cmd + c.ToString());
                                                            }
                                                        }
                                                        mode_index++;
                                                    }
                                                    else if (c.Equals('+'))
                                                    {
                                                        positive = true;
                                                    }
                                                    else if (c.Equals('-'))
                                                    {
                                                        positive = false;
                                                    }
                                                }
                                                if (!mode_allowed)
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :You do not have permission to use that command.");
                                                }
                                            }
                                            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;
                                    case "topic":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                string[] new_line = line[4].Split(charS, 2);
                                                if (new_line.GetUpperBound(0) > 0)
                                                {
                                                    ircbot.sendData("TOPIC", line[2] + " :" + new_line[0] + " " + new_line[1]);
                                                }
                                                else
                                                {
                                                    ircbot.sendData("TOPIC", line[2] + " :" + new_line[0]);
                                                }
                                            }
                                            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;
                                    case "invite":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                string[] new_line = line[4].ToLower().Split(charS, 2);
                                                if (new_line.GetUpperBound(0) > 0)
                                                {
                                                    ircbot.sendData("INVITE", new_line[0] + " " + new_line[1]);
                                                }
                                                else
                                                {
                                                    ircbot.sendData("INVITE", new_line[0] + " " + line[2]);
                                                }
                                            }
                                            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;
                                    case "b":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                string[] new_line = line[4].ToLower().Split(charS, 2);
                                                string nicks = new_line[0].TrimStart(':');
                                                char[] charSep = new char[] { ',' };
                                                string[] total_nicks = new_line[0].Split(charSep, StringSplitOptions.RemoveEmptyEntries);
                                                int sent_nick_access = ircbot.get_user_access(total_nicks[0], line[2]);

                                                bool tmp_me = false;
                                                for (int y = 0; y <= total_nicks.GetUpperBound(0); y++)
                                                {
                                                    if (total_nicks[y].Equals(conf.name, StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        tmp_me = true;
                                                    }
                                                }
                                                if (sent_nick_access == conf.owner_level)
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :You can't ban my owner!");
                                                }
                                                else if (tmp_me == true)
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :You can't ban me!");
                                                }
                                                else
                                                {
                                                    if (nick_access >= sent_nick_access)
                                                    {
                                                        string target_host = ircbot.get_user_host(total_nicks[0]);
                                                        string ban = "*!*@" + target_host;
                                                        if (target_host.Equals(""))
                                                        {
                                                            ban = new_line[0] + "!*@*";
                                                        }
                                                        if (new_line.GetUpperBound(0) > 0)
                                                        {
                                                            ircbot.sendData("MODE", line[2] + " +b " + ban + " :" + new_line[1]);
                                                        }
                                                        else
                                                        {
                                                            ircbot.sendData("MODE", line[2] + " +b " + ban + " :No Reason");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                                    }
                                                }
                                            }
                                            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;
                                    case "ub":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                string[] new_line = line[4].ToLower().Split(charS, 2);
                                                char[] charSep = new char[] { ',' };
                                                string[] total_nicks = new_line[0].Split(charSep, StringSplitOptions.RemoveEmptyEntries);
                                                int sent_nick_access = ircbot.get_user_access(total_nicks[0].TrimStart(':'), line[2]);

                                                if (nick_access >= sent_nick_access)
                                                {
                                                    string target_host = ircbot.get_user_host(total_nicks[0]);
                                                    string ban = "*!*@" + target_host;
                                                    if (target_host.Equals(""))
                                                    {
                                                        ban = new_line[0] + "!*@*";
                                                    }
                                                    if (new_line.GetUpperBound(0) > 0)
                                                    {
                                                        ircbot.sendData("MODE", line[2] + " -b " + ban + " :" + new_line[1]);
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("MODE", line[2] + " -b " + ban + " :No Reason");
                                                    }
                                                }
                                                else
                                                {
                                                    ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                                }
                                            }
                                            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;
                                    case "clearban":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            ircbot.sendData("PRIVMSG", "chanserv :clear " + channel + " bans");
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                        }
                                        break;
                                    case "kb":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                string[] new_line = line[4].ToLower().Split(charS, 2);
                                                string nicks = new_line[0].TrimStart(':');
                                                char[] charSep = new char[] { ',' };
                                                string[] total_nicks = nicks.Split(charSep, StringSplitOptions.RemoveEmptyEntries);
                                                int sent_nick_access = ircbot.get_user_access(total_nicks[0], line[2]);

                                                bool tmp_me = false;
                                                for (int y = 0; y <= total_nicks.GetUpperBound(0); y++)
                                                {
                                                    if (total_nicks[y].Equals(conf.name, StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        tmp_me = true;
                                                    }
                                                }
                                                if (sent_nick_access == conf.owner_level)
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :You can't kick-ban my owner!");
                                                }
                                                else if (tmp_me == true)
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :You can't kick-ban me!");
                                                }
                                                else
                                                {
                                                    if (nick_access >= sent_nick_access)
                                                    {
                                                        string target_host = ircbot.get_user_host(total_nicks[0]);
                                                        string ban = "*!*@" + target_host;
                                                        if (target_host.Equals(""))
                                                        {
                                                            ban = new_line[0] + "!*@*";
                                                        }
                                                        if (new_line.GetUpperBound(0) > 0)
                                                        {
                                                            ircbot.sendData("MODE", line[2] + " +b " + ban + " :" + new_line[1]);
                                                            ircbot.sendData("KICK", line[2] + " " + total_nicks[0] + " :" + new_line[1]);
                                                        }
                                                        else
                                                        {
                                                            ircbot.sendData("MODE", line[2] + " +b " + ban + " :No Reason");
                                                            ircbot.sendData("KICK", line[2] + " " + total_nicks[0] + " :No Reason");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                                    }
                                                }
                                            }
                                            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;
                                    case "tb":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                string[] new_line = line[4].ToLower().Split(charS, 3, StringSplitOptions.RemoveEmptyEntries);
                                                if (new_line.GetUpperBound(0) > 0)
                                                {
                                                    int time = Convert.ToInt32(new_line[0].TrimStart(':'));
                                                    string nicks = new_line[1];
                                                    char[] charSep = new char[] { ',' };
                                                    string[] total_nicks = nicks.Split(charSep, StringSplitOptions.RemoveEmptyEntries);
                                                    string target_host = ircbot.get_user_host(total_nicks[0]);
                                                    int sent_nick_access = ircbot.get_user_access(total_nicks[0], line[2]);

                                                    bool tmp_me = false;
                                                    for (int y = 0; y <= total_nicks.GetUpperBound(0); y++)
                                                    {
                                                        if (total_nicks[y].Equals(conf.name, StringComparison.OrdinalIgnoreCase))
                                                        {
                                                            tmp_me = true;
                                                        }
                                                    }
                                                    if (sent_nick_access == conf.owner_level)
                                                    {
                                                        ircbot.sendData("PRIVMSG", line[2] + " :You can't ban my owner!");
                                                    }
                                                    else if (tmp_me == true)
                                                    {
                                                        ircbot.sendData("PRIVMSG", line[2] + " :You can't ban me!");
                                                    }
                                                    else
                                                    {
                                                        if (nick_access >= sent_nick_access)
                                                        {
                                                            string ban = "*!*@" + target_host;
                                                            if (target_host.Equals(""))
                                                            {
                                                                ban = total_nicks[0] + "!*@*";
                                                            }
                                                            if (new_line.GetUpperBound(0) > 1)
                                                            {
                                                                ircbot.sendData("MODE", line[2] + " +b " + ban + " :" + new_line[2]);
                                                            }
                                                            else
                                                            {
                                                                ircbot.sendData("MODE", line[2] + " +b " + ban + " :No Reason");
                                                            }
                                                            Timer unban_trigger = new Timer();
                                                            unban_trigger.Interval = (Convert.ToInt32(new_line[0]) * 1000);
                                                            unban_trigger.Enabled = true;
                                                            unban_trigger.AutoReset = false;
                                                            unban_trigger.Elapsed += (sender, e) => unban_nick(sender, e, total_nicks[0], target_host, line[2]);
                                                            unban_triggers.Add(unban_trigger);
                                                            main = ircbot;
                                                        }
                                                        else
                                                        {
                                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :" + nick + ", you need to include more info.");
                                                }
                                            }
                                            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;
                                    case "tkb":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                string[] new_line = line[4].ToLower().Split(charS, 3, StringSplitOptions.RemoveEmptyEntries);
                                                if (new_line.GetUpperBound(0) > 0)
                                                {
                                                    int time = Convert.ToInt32(new_line[0].TrimStart(':'));
                                                    string nicks = new_line[1];
                                                    char[] charSep = new char[] { ',' };
                                                    string[] total_nicks = nicks.Split(charSep, StringSplitOptions.RemoveEmptyEntries);
                                                    int sent_nick_access = ircbot.get_user_access(total_nicks[0], line[2]);
                                                    string target_host = ircbot.get_user_host(total_nicks[0]);

                                                    bool tmp_me = false;
                                                    for (int y = 0; y <= total_nicks.GetUpperBound(0); y++)
                                                    {
                                                        if (total_nicks[y].Equals(conf.name, StringComparison.OrdinalIgnoreCase))
                                                        {
                                                            tmp_me = true;
                                                        }
                                                    }
                                                    if (sent_nick_access == conf.owner_level)
                                                    {
                                                        ircbot.sendData("PRIVMSG", line[2] + " :You can't kick-ban my owner!");
                                                    }
                                                    else if (tmp_me == true)
                                                    {
                                                        ircbot.sendData("PRIVMSG", line[2] + " :You can't kick-ban me!");
                                                    }
                                                    else
                                                    {
                                                        if (nick_access >= sent_nick_access)
                                                        {
                                                            string ban = "*!*@" + target_host;
                                                            if (target_host.Equals(""))
                                                            {
                                                                ban = new_line[1] + "!*@*";
                                                            }
                                                            if (new_line.GetUpperBound(0) > 1)
                                                            {
                                                                ircbot.sendData("MODE", line[2] + " +b " + ban + " :" + new_line[2]);
                                                                ircbot.sendData("KICK", line[2] + " " + total_nicks[0] + " :" + new_line[2]);
                                                            }
                                                            else
                                                            {
                                                                ircbot.sendData("MODE", line[2] + " +b " + ban + " :No Reason");
                                                                ircbot.sendData("KICK", line[2] + " " + total_nicks[0] + " :No Reason");
                                                            }
                                                            System.Timers.Timer unban_trigger = new System.Timers.Timer();
                                                            unban_trigger.Interval = (Convert.ToInt32(new_line[0]) * 1000);
                                                            unban_trigger.Enabled = true;
                                                            unban_trigger.AutoReset = false;
                                                            unban_trigger.Elapsed += (sender, e) => unban_nick(sender, e, total_nicks[0], target_host, line[2]);
                                                            unban_triggers.Add(unban_trigger);
                                                            main = ircbot;
                                                        }
                                                        else
                                                        {
                                                            ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :" + nick + ", you need to include more info.");
                                                }
                                            }
                                            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;
                                    case "ak":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                string[] new_line = line[4].ToLower().Split(charS, 2);
                                                string nicks = new_line[0].TrimStart(':');
                                                char[] charSep = new char[] { ',' };
                                                string[] total_nicks = nicks.Split(charSep, StringSplitOptions.RemoveEmptyEntries);
                                                int sent_nick_access = ircbot.get_user_access(total_nicks[0], line[2]);
                                                bool tmp_me = false;
                                                for (int y = 0; y <= total_nicks.GetUpperBound(0); y++)
                                                {
                                                    if (total_nicks[y].Equals(conf.name, StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        tmp_me = true;
                                                    }
                                                }
                                                if (sent_nick_access == conf.owner_level)
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :You can't kick my owner!");
                                                }
                                                else if (tmp_me == true)
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :You can't kick me!");
                                                }
                                                else
                                                {
                                                    if (nick_access >= sent_nick_access)
                                                    {
                                                        string target_host = ircbot.get_user_host(total_nicks[0]);
                                                        if (new_line.GetUpperBound(0) > 0)
                                                        {
                                                            add_auto(total_nicks[0], line[2], target_host, "k", new_line[1], ircbot);
                                                        }
                                                        else
                                                        {
                                                            add_auto(total_nicks[0], line[2], target_host, "k", "No Reason", ircbot);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                                    }
                                                }
                                            }
                                            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;
                                    case "ab":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                string[] new_line = line[4].ToLower().Split(charS, 2);
                                                string target_host = ircbot.get_user_host(new_line[0]);
                                                string nicks = new_line[0].TrimStart(':');
                                                char[] charSep = new char[] { ',' };
                                                string[] total_nicks = nicks.Split(charSep, StringSplitOptions.RemoveEmptyEntries);
                                                int sent_nick_access = ircbot.get_user_access(total_nicks[0], line[2]);
                                                bool tmp_me = false;
                                                for (int y = 0; y <= total_nicks.GetUpperBound(0); y++)
                                                {
                                                    if (total_nicks[y].Equals(conf.name, StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        tmp_me = true;
                                                    }
                                                }
                                                if (sent_nick_access == conf.owner_level)
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :You can't ban my owner!");
                                                }
                                                else if (tmp_me == true)
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :You can't ban me!");
                                                }
                                                else
                                                {
                                                    if (nick_access >= sent_nick_access)
                                                    {
                                                        if (new_line.GetUpperBound(0) > 0)
                                                        {
                                                            add_auto(total_nicks[0], line[2], target_host, "b", new_line[1], ircbot);
                                                        }
                                                        else
                                                        {
                                                            add_auto(total_nicks[0], line[2], target_host, "b", "No Reason", ircbot);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                                    }
                                                }
                                            }
                                            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;
                                    case "akb":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                string[] new_line = line[4].ToLower().Split(charS, 2);
                                                string target_host = ircbot.get_user_host(new_line[0]);
                                                string nicks = new_line[0].TrimStart(':');
                                                char[] charSep = new char[] { ',' };
                                                string[] total_nicks = nicks.Split(charSep, StringSplitOptions.RemoveEmptyEntries);
                                                int sent_nick_access = ircbot.get_user_access(total_nicks[0], line[2]);
                                                bool tmp_me = false;
                                                for (int y = 0; y <= total_nicks.GetUpperBound(0); y++)
                                                {
                                                    if (total_nicks[y].Equals(conf.name, StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        tmp_me = true;
                                                    }
                                                }
                                                if (sent_nick_access == conf.owner_level)
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :You can't kick-ban my owner!");
                                                }
                                                else if (tmp_me == true)
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :You can't kick-ban me!");
                                                }
                                                else
                                                {
                                                    if (nick_access >= sent_nick_access)
                                                    {
                                                        if (new_line.GetUpperBound(0) > 0)
                                                        {
                                                            add_auto(total_nicks[0], line[2], target_host, "kb", new_line[1], ircbot);
                                                        }
                                                        else
                                                        {
                                                            add_auto(total_nicks[0], line[2], target_host, "kb", "No Reason", ircbot);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                                    }
                                                }
                                            }
                                            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;
                                    case "deak":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                string target_host = ircbot.get_user_host(line[4].ToLower());
                                                del_auto(line[4].ToLower(), line[2], target_host, "k", ircbot);
                                            }
                                            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;
                                    case "deab":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                string target_host = ircbot.get_user_host(line[4].ToLower());
                                                del_auto(line[4].ToLower(), line[2], target_host, "b", ircbot);
                                            }
                                            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;
                                    case "deakb":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                string target_host = ircbot.get_user_host(line[4].ToLower());
                                                del_auto(line[4].ToLower(), line[2], target_host, "kb", ircbot);
                                            }
                                            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;
                                    case "k":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                string[] new_line = line[4].ToLower().Split(charS, 2);
                                                string nicks = new_line[0].TrimStart(':');
                                                char[] charSep = new char[] { ',' };
                                                string[] total_nicks = nicks.Split(charSep, StringSplitOptions.RemoveEmptyEntries);
                                                int sent_nick_access = ircbot.get_user_access(total_nicks[0], line[2]);
                                                bool tmp_me = false;
                                                for (int y = 0; y <= total_nicks.GetUpperBound(0); y++)
                                                {
                                                    if (total_nicks[y].Equals(conf.name, StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        tmp_me = true;
                                                    }
                                                }
                                                if (sent_nick_access == conf.owner_level)
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :You can't kick my owner!");
                                                }
                                                else if (tmp_me == true)
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :You can't kick me!");
                                                }
                                                else
                                                {
                                                    if (nick_access >= sent_nick_access)
                                                    {
                                                        if (new_line.GetUpperBound(0) > 0)
                                                        {
                                                            ircbot.sendData("KICK", line[2] + " " + total_nicks[0] + " :" + new_line[1]);
                                                        }
                                                        else
                                                        {
                                                            ircbot.sendData("KICK", line[2] + " " + total_nicks[0] + " :No Reason");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                                    }
                                                }
                                            }
                                            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;
                                    case "kme":
                                        if (spam_check == true)
                                        {
                                            ircbot.add_spam_count(channel);
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                ircbot.sendData("KICK", line[2] + " " + nick + " :" + line[4]);
                                            }
                                            else
                                            {
                                                ircbot.sendData("KICK", line[2] + " " + nick + " :No Reason");
                                            }
                                        }
                                        break;
                                }
                            }
                        }
                    }
                }
            }
            if (type.Equals("join"))
            {
                string[] user_info = line[0].Split('@');
                string nick_host = user_info[1];
                check_auto(nick, channel.TrimStart(':'), nick_host, ircbot);
            }
        }
Пример #37
0
 private void display_log_nick(string nick, string channel, string requst_nick, string command, bot ircbot, IRCConfig conf)
 {
     string file_name = ircbot.server_name + ".log";
     bool cmd_found = false;
     if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "logging" + Path.DirectorySeparatorChar + file_name))
     {
         string[] log_file = System.IO.File.ReadAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "logging" + Path.DirectorySeparatorChar + file_name);
         int number_of_lines = log_file.GetUpperBound(0) + 1;
         if (number_of_lines > 0)
         {
             int num_uses = 0;
             string parameters = "";
             string date = "";
             string inside = "";
             foreach (string line in log_file)
             {
                 char[] sep = new char[] { '*' };
                 string[] new_line = line.Split(sep, 5);
                 if (new_line.GetUpperBound(0) > 0)
                 {
                     if (new_line[0].Equals(nick) && new_line[3].Equals(command))
                     {
                         if (new_line[4] != "")
                         {
                             parameters = " with the following argument: " + new_line[4];
                         }
                         else
                         {
                             parameters = "";
                         }
                         date = new_line[2];
                         inside = new_line[1];
                         num_uses++;
                         cmd_found = true;
                     }
                 }
             }
             if (cmd_found == true)
             {
                 ircbot.sendData("NOTICE", requst_nick + " :" + nick + " has used " + conf.command + command + " " + num_uses + " times.");
                 ircbot.sendData("NOTICE", requst_nick + " :They last used " + conf.command + command + " on " + date + " in " + inside + parameters);
             }
             else
             {
                 ircbot.sendData("NOTICE", requst_nick + " :" + nick + " has not used " + conf.command + command);
             }
         }
         else
         {
             ircbot.sendData("NOTICE", requst_nick + " :" + nick + " has not used any commands");
         }
     }
     else
     {
         ircbot.sendData("NOTICE", requst_nick + " :" + nick + " has not used any commands");
     }
 }
Пример #38
0
        public override void control(bot ircbot, ref IRCConfig conf, int module_id, string[] line, string command, int nick_access, string nick, string channel, bool bot_command, string type)
        {
            string module_name = ircbot.conf.module_config[module_id][0];

            if (type.Equals("channel") && bot_command == true)
            {
                foreach (List <string> tmp_command in conf.command_list)
                {
                    if (module_name.Equals(tmp_command[0]))
                    {
                        string[] triggers       = tmp_command[3].Split('|');
                        int      command_access = Convert.ToInt32(tmp_command[5]);
                        string[] blacklist      = tmp_command[6].Split(',');
                        bool     blocked        = false;
                        bool     cmd_found      = false;
                        bool     spam_check     = Convert.ToBoolean(tmp_command[8]);
                        foreach (string bl_chan in blacklist)
                        {
                            if (bl_chan.Equals(channel))
                            {
                                blocked = true;
                                break;
                            }
                        }
                        if (spam_check == true)
                        {
                            blocked = ircbot.get_spam_status(channel, nick);
                        }
                        foreach (string trigger in triggers)
                        {
                            if (trigger.Equals(command))
                            {
                                cmd_found = true;
                                break;
                            }
                        }
                        if (blocked == true && cmd_found == true)
                        {
                            ircbot.sendData("NOTICE", nick + " :I am currently too busy to process that.");
                        }
                        if (blocked == false && cmd_found == true)
                        {
                            foreach (string trigger in triggers)
                            {
                                switch (trigger)
                                {
                                case "hbomb":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        int module_index = 0;
                                        foreach (Modules.Module module in ircbot.module_list)
                                        {
                                            string module_type = module.GetType().ToString();
                                            if (module_type.Equals("IRCBot.Modules.idle"))
                                            {
                                                break;
                                            }
                                            else
                                            {
                                                module_index++;
                                            }
                                        }
                                        Modules.idle idle;
                                        if (module_index < ircbot.module_list.Count())
                                        {
                                            idle = (Modules.idle)ircbot.module_list[module_index];
                                        }
                                        else
                                        {
                                            idle = new Modules.idle();
                                        }
                                        if (idle.check_idle(nick) == false)
                                        {
                                            bool       hbomb_active = false;
                                            hbomb_info tmp_info     = new hbomb_info();
                                            foreach (hbomb_info bomb in hbombs)
                                            {
                                                if (bomb.bomb_channel.Equals(channel))
                                                {
                                                    tmp_info     = bomb;
                                                    hbomb_active = true;
                                                    break;
                                                }
                                            }
                                            if (hbomb_active == false)
                                            {
                                                tmp_info.bomb_locked  = false;
                                                tmp_info.bomb_trigger = new System.Timers.Timer();
                                                tmp_info.wire_colors  = ircbot.conf.module_config[module_id][3].Split(',');
                                                tmp_info.bomb_channel = channel;

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

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

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

                                                main = ircbot;

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

                                                ircbot.sendData("PRIVMSG", channel + " :" + nick + " has started the timer!  If the bomb gets passed to you, type " + conf.command + "pass <nick> to pass it to someone else, or type " + conf.command + "defuse <color> to try to defuse it.");
                                                string colors = "";
                                                foreach (string wire in tmp_info.wire_colors)
                                                {
                                                    colors += wire + ",";
                                                }
                                                ircbot.sendData("NOTICE", nick + " :You need to hurry and pass the bomb before it blows up!  Or you can try to defuse it yourself.  The colors are: " + colors.TrimEnd(','));
                                                hbombs.Add(tmp_info);
                                            }
                                            else
                                            {
                                                if (tmp_info.bomb_channel.Equals(channel))
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :There is already a bomb counting down.");
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :There is already a bomb counting down in " + tmp_info.bomb_channel + ".");
                                                }
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :You can not start a HBomb when you are idle.");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;

                                case "pass":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        int        index        = 0;
                                        bool       hbomb_active = false;
                                        hbomb_info tmp_info     = new hbomb_info();
                                        foreach (hbomb_info bomb in hbombs)
                                        {
                                            if (bomb.bomb_channel.Equals(channel))
                                            {
                                                tmp_info     = bomb;
                                                hbomb_active = true;
                                                break;
                                            }
                                            index++;
                                        }
                                        if (hbomb_active == true)
                                        {
                                            if (!tmp_info.bomb_locked)
                                            {
                                                int module_index = 0;
                                                foreach (Modules.Module module in ircbot.module_list)
                                                {
                                                    string module_type = module.GetType().ToString();
                                                    if (module_type.Equals("IRCBot.Modules.idle"))
                                                    {
                                                        break;
                                                    }
                                                    else
                                                    {
                                                        module_index++;
                                                    }
                                                }
                                                Modules.idle idle;
                                                if (module_index < ircbot.module_list.Count())
                                                {
                                                    idle = (Modules.idle)ircbot.module_list[module_index];
                                                }
                                                else
                                                {
                                                    idle = new Modules.idle();
                                                }
                                                if (idle.check_idle(nick) == false)
                                                {
                                                    if (tmp_info.bomb_holder.Equals(nick))
                                                    {
                                                        if (line.GetUpperBound(0) > 3)
                                                        {
                                                            if (line[4].TrimEnd(' ').ToLower().Equals(conf.nick.ToLower()))
                                                            {
                                                                ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you can't pass it to me!");
                                                            }
                                                            else
                                                            {
                                                                int user_access = ircbot.get_user_access(line[4].TrimEnd(' ').ToLower(), channel);
                                                                if (user_access > 0 && idle.check_idle(line[4].TrimEnd(' ').ToLower()) == false)
                                                                {
                                                                    pass_hbomb(line[4].TrimEnd(' ').ToLower(), channel, nick, ircbot, conf, ref tmp_info, index);
                                                                }
                                                                else
                                                                {
                                                                    ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you can't pass to them!");
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you need to pass the bomb to someone.");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("PRIVMSG", channel + " :You don't have the bomb!");
                                                    }
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :You can not pass the HBomb when you are idle.");
                                                }
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :You can not pass a locked bomb.");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to pass!");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;

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

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

                                case "unlock_bomb":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        int        index        = 0;
                                        bool       hbomb_active = false;
                                        hbomb_info tmp_info     = new hbomb_info();
                                        foreach (hbomb_info bomb in hbombs)
                                        {
                                            if (bomb.bomb_channel.Equals(channel))
                                            {
                                                tmp_info     = bomb;
                                                hbomb_active = true;
                                                break;
                                            }
                                            index++;
                                        }
                                        if (hbomb_active == true)
                                        {
                                            tmp_info.bomb_locked = false;
                                            hbombs[index]        = tmp_info;
                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to unlock!");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;

                                case "detonate":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        bool hbomb_active = false;
                                        foreach (hbomb_info bomb in hbombs)
                                        {
                                            if (bomb.bomb_channel.Equals(channel))
                                            {
                                                hbomb_active = true;
                                                break;
                                            }
                                        }
                                        if (hbomb_active == true)
                                        {
                                            main = ircbot;
                                            activate_bomb(channel);
                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to blow up!");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;

                                case "stop_bomb":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        int        index        = 0;
                                        bool       hbomb_active = false;
                                        hbomb_info tmp_info     = new hbomb_info();
                                        foreach (hbomb_info bomb in hbombs)
                                        {
                                            if (bomb.bomb_channel.Equals(channel))
                                            {
                                                tmp_info     = bomb;
                                                hbomb_active = true;
                                                break;
                                            }
                                            index++;
                                        }
                                        if (hbomb_active == true)
                                        {
                                            hbombs.RemoveAt(index);
                                            ircbot.sendData("PRIVMSG", channel + " :Bomb has been defused and thrown away.");
                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to stop!");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;

                                case "defuse":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        int        index        = 0;
                                        bool       hbomb_active = false;
                                        hbomb_info tmp_info     = new hbomb_info();
                                        foreach (hbomb_info bomb in hbombs)
                                        {
                                            if (bomb.bomb_channel.Equals(channel))
                                            {
                                                tmp_info     = bomb;
                                                hbomb_active = true;
                                                break;
                                            }
                                            index++;
                                        }
                                        if (hbomb_active == true)
                                        {
                                            if (!tmp_info.bomb_locked)
                                            {
                                                int module_index = 0;
                                                foreach (Modules.Module module in ircbot.module_list)
                                                {
                                                    string module_type = module.GetType().ToString();
                                                    if (module_type.Equals("IRCBot.Modules.idle"))
                                                    {
                                                        break;
                                                    }
                                                    else
                                                    {
                                                        module_index++;
                                                    }
                                                }
                                                Modules.idle idle;
                                                if (module_index < ircbot.module_list.Count())
                                                {
                                                    idle = (Modules.idle)ircbot.module_list[module_index];
                                                }
                                                else
                                                {
                                                    idle = new Modules.idle();
                                                }
                                                if (idle.check_idle(nick) == false)
                                                {
                                                    if (tmp_info.bomb_holder.Equals(nick))
                                                    {
                                                        if (line.GetUpperBound(0) > 3)
                                                        {
                                                            if (line[4].ToLower().Equals(tmp_info.wire_color.ToLower()))
                                                            {
                                                                ircbot.sendData("PRIVMSG", channel + " :You have successfully defused the bomb!");
                                                                if (tmp_info.previous_bomb_holder.Equals(tmp_info.bomb_holder))
                                                                {
                                                                }
                                                                else
                                                                {
                                                                    ircbot.sendData("KICK", tmp_info.bomb_channel + " " + tmp_info.previous_bomb_holder + " :BOOM!!!");
                                                                }
                                                                hbombs.RemoveAt(index);
                                                            }
                                                            else
                                                            {
                                                                main = ircbot;
                                                                activate_bomb(channel);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            ircbot.sendData("PRIVMSG", channel + " :" + nick + ", you need to cut a wire.");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("PRIVMSG", channel + " :You don't have the bomb!");
                                                    }
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", channel + " :You can not defuse the HBomb when you are idle.");
                                                }
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", channel + " :You can not defuse the HBomb when it is locked.");
                                            }
                                        }
                                        else
                                        {
                                            ircbot.sendData("PRIVMSG", channel + " :There isn't a bomb to defuse!");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #39
0
 private void display_log_number(int number, string channel, string requst_nick, string command, bot ircbot, IRCConfig conf)
 {
     string file_name = ircbot.server_name + ".log";
     bool cmd_found = false;
     if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "logging" + Path.DirectorySeparatorChar + file_name))
     {
         string[] log_file = System.IO.File.ReadAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "logging" + Path.DirectorySeparatorChar + file_name);
         int number_of_lines = log_file.GetUpperBound(0) + 1;
         List<List<string>> command_list = new List<List<string>>();
         if (number_of_lines > 0)
         {
             int num_uses = 0;
             string parameters = "";
             string date = "";
             string inside = "";
             string nick = "";
             foreach (string line in log_file)
             {
                 List<string> tmp_list = new List<string>();
                 char[] sep = new char[] { '*' };
                 string[] new_line = line.Split(sep, 5);
                 if (new_line.GetUpperBound(0) > 0)
                 {
                     if (new_line[3].Equals(command))
                     {
                         tmp_list.Add(new_line[0]);
                         tmp_list.Add(new_line[1]);
                         tmp_list.Add(new_line[2]);
                         tmp_list.Add(new_line[3]);
                         tmp_list.Add(new_line[4]);
                         command_list.Add(tmp_list);
                         num_uses++;
                         cmd_found = true;
                     }
                 }
             }
             if (cmd_found == true)
             {
                 if (number < num_uses && number >= 0)
                 {
                     if (command_list[number][4] != "")
                     {
                         parameters = " with the following argument: " + command_list[number][4];
                     }
                     else
                     {
                         parameters = "";
                     }
                     date = command_list[number][2];
                     inside = command_list[number][1];
                     nick = command_list[number][0];
                     ircbot.sendData("NOTICE", requst_nick + " :" + conf.command + command + " was used by " + nick + " on " + date + " in " + inside + parameters);
                 }
                 else
                 {
                     ircbot.sendData("NOTICE", requst_nick + " :The command has not been used that many times");
                 }
             }
             else
             {
                 foreach (string line in log_file)
                 {
                     List<string> tmp_list = new List<string>();
                     char[] sep = new char[] { '*' };
                     string[] new_line = line.Split(sep, 5);
                     if (new_line.GetUpperBound(0) > 0)
                     {
                         if (new_line[0].Equals(command))
                         {
                             tmp_list.Add(new_line[0]);
                             tmp_list.Add(new_line[1]);
                             tmp_list.Add(new_line[2]);
                             tmp_list.Add(new_line[3]);
                             tmp_list.Add(new_line[4]);
                             command_list.Add(tmp_list);
                             num_uses++;
                             cmd_found = true;
                         }
                     }
                 }
                 if (number < num_uses && number >= 0)
                 {
                     if (command_list[number][4] != "")
                     {
                         parameters = " with the following argument: " + command_list[number][4];
                     }
                     else
                     {
                         parameters = "";
                     }
                     date = command_list[number][2];
                     inside = command_list[number][1];
                     nick = command_list[number][0];
                     ircbot.sendData("NOTICE", requst_nick + " :" + nick + " used " + conf.command + command_list[number][3] + " on " + date + " in " + inside + parameters);
                 }
                 else
                 {
                     ircbot.sendData("NOTICE", requst_nick + " :The command has not been used that many times");
                 }
             }
         }
         else
         {
             ircbot.sendData("NOTICE", requst_nick + " :" + conf.command + command + " has not been used");
         }
     }
     else
     {
         ircbot.sendData("NOTICE", requst_nick + " :" + conf.command + command + " has not been used");
     }
 }
Пример #40
0
        private void pass_hbomb(string pass_nick, string channel, string nick, bot ircbot, IRCConfig conf, ref hbomb_info tmp_info, int index)
        {
            string tab_name = channel.TrimStart('#');
            string pattern  = "[^a-zA-Z0-9]"; //regex pattern

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

            if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "seen" + Path.DirectorySeparatorChar + file_name))
            {
                string[] log_file        = System.IO.File.ReadAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "seen" + Path.DirectorySeparatorChar + file_name);
                int      number_of_lines = log_file.GetUpperBound(0) + 1;
                if (number_of_lines > 0)
                {
                    foreach (string file_line in log_file)
                    {
                        char[]   sep      = new char[] { '*' };
                        string[] new_line = file_line.Split(sep, 4);
                        if (new_line.GetUpperBound(0) > 0)
                        {
                            if (new_line[0].Equals(pass_nick) && new_line[1].Equals(channel))
                            {
                                DateTime current_date      = DateTime.Now;
                                DateTime past_date         = DateTime.Parse(new_line[2]);
                                double   difference_second = 0;
                                difference_second = current_date.Subtract(past_date).TotalSeconds;
                                if (difference_second <= 600)
                                {
                                    nick_idle = false;
                                }
                                break;
                            }
                        }
                    }
                }
            }
            if (nick_idle == false)
            {
                tmp_info.bomb_holder          = pass_nick;
                tmp_info.previous_bomb_holder = nick;
                hbombs[index] = tmp_info;
                ircbot.sendData("PRIVMSG", channel + " :" + nick + " passed the bomb to " + pass_nick);
                ircbot.sendData("NOTICE", pass_nick + " :You now have the bomb!  Type " + conf.command + "pass <nick> to pass it to someone else, or type " + conf.command + "defuse <color> to try to defuse it.");
                string colors = "";
                foreach (string wire in tmp_info.wire_colors)
                {
                    colors += wire + ",";
                }
                ircbot.sendData("NOTICE", pass_nick + " :The colors of the wires are: " + colors);
            }
            else
            {
                ircbot.sendData("PRIVMSG", channel + " :Dang, you missed them! (Idle)");
            }
        }
Пример #41
0
        private void pass_hbomb(string pass_nick, string channel, string nick, bot ircbot, IRCConfig conf, ref hbomb_info tmp_info, int index)
        {
            string tab_name = channel.TrimStart('#');
            string pattern = "[^a-zA-Z0-9]"; //regex pattern
            tab_name = Regex.Replace(tab_name, pattern, "_");
            string file_name = ircbot.server_name + "_#" + tab_name + ".log";
            bool nick_idle = true;

            if (File.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "seen" + Path.DirectorySeparatorChar + file_name))
            {
                string[] log_file = System.IO.File.ReadAllLines(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "seen" + Path.DirectorySeparatorChar + file_name);
                int number_of_lines = log_file.GetUpperBound(0) + 1;
                if (number_of_lines > 0)
                {
                    foreach (string file_line in log_file)
                    {
                        char[] sep = new char[] { '*' };
                        string[] new_line = file_line.Split(sep, 4);
                        if (new_line.GetUpperBound(0) > 0)
                        {
                            if (new_line[0].Equals(pass_nick) && new_line[1].Equals(channel))
                            {
                                DateTime current_date = DateTime.Now;
                                DateTime past_date = DateTime.Parse(new_line[2]);
                                double difference_second = 0;
                                difference_second = current_date.Subtract(past_date).TotalSeconds;
                                if (difference_second <= 600)
                                {
                                    nick_idle = false;
                                }
                                break;
                            }
                        }
                    }
                }
            }
            if (nick_idle == false)
            {
                tmp_info.bomb_holder = pass_nick;
                tmp_info.previous_bomb_holder = nick;
                hbombs[index] = tmp_info;
                ircbot.sendData("PRIVMSG", channel + " :" + nick + " passed the bomb to " + pass_nick);
                ircbot.sendData("NOTICE", pass_nick + " :You now have the bomb!  Type " + conf.command + "pass <nick> to pass it to someone else, or type " + conf.command + "defuse <color> to try to defuse it.");
                string colors = "";
                foreach (string wire in tmp_info.wire_colors)
                {
                    colors += wire + ",";
                }
                ircbot.sendData("NOTICE", pass_nick + " :The colors of the wires are: " + colors);
            }
            else
            {
                ircbot.sendData("PRIVMSG", channel + " :Dang, you missed them! (Idle)");
            }
        }
Пример #42
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 "quote":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        if (conf.module_config[module_id][3].Equals("True"))
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                get_specific_quote(line[2], line[4].ToLower(), ircbot, conf);
                                            }
                                            else
                                            {
                                                get_quote(line[2], ircbot, conf);
                                            }
                                        }
                                        else
                                        {
                                            get_quote(line[2], ircbot, conf);
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            if (type.Equals("channel") && bot_command == false && nick != conf.nick)
            {
                add_quote(nick, channel, line, ircbot, conf);
            }
        }
Пример #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)
                        {
                            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 "pingme":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        int epoch = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
                                        ircbot.sendData("PRIVMSG", nick + " :\u0001PING " + epoch.ToString() + "\u0001");
                                        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);
                                    }
                                    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);
            }
        }
Пример #44
0
        public void JoinChatAndListen()
        {
            this.Focus();
            this.ConnectToChat.IsEnabled = false;
            this.ConnectToChat.Opacity = 0;

            chatJoined = true;
            try
            {
                ChatList.Add(new ChatLine { Message = "Connecting to chat...", UserName = "", Color = "#ffffff" });
                this.ChatBox.ItemsSource = this.ChatList;

                IRCConfig config;
                if (isLoggedIn)
                {
                    config = new IRCConfig
                    {
                        channel = App.ViewModel.stream.channel.name,
                        nick = App.ViewModel.user.Name,
                        pass = "******" + App.ViewModel.user.Oauth,
                        server = "irc.twitch.tv",
                        port = 6667
                    };
                }
                else
                {
                    config = new IRCConfig
                    {
                        channel = App.ViewModel.stream.channel.name,
                        nick = "justinfan"+random.Next(0,999999)+random.Next(0,99999999),
                        pass = "******",
                        server = "irc.twitch.tv",
                        port = 6667
                    };
                }

                client = new ChatClient(config);
                client.sendData("JOIN", "#" + config.channel);

                backgroundWorker.RunWorkerAsync();
            }

            catch
            {
                MessageBox.Show("Connecting to chat has run into issues", "Well, this is embarrassing...", MessageBoxButton.OK);
            }
        }
Пример #45
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)
        {
            access access = new access();

            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 "alarm":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        if (line.GetUpperBound(0) > 3)
                                        {
                                            string[] new_line = line[4].Split(charS, 2, StringSplitOptions.RemoveEmptyEntries);
                                            if (new_line.GetUpperBound(0) > 0)
                                            {
                                                bool int_allowed = true;
                                                int  time        = 0;
                                                try
                                                {
                                                    time = Convert.ToInt32(new_line[0]);
                                                    if ((time * 1000) <= 0)
                                                    {
                                                        int_allowed = false;
                                                    }
                                                }
                                                catch
                                                {
                                                    int_allowed = false;
                                                }
                                                if (int_allowed == true)
                                                {
                                                    char[]   charSplit = new char[] { ' ' };
                                                    string[] ex        = new_line[1].Split(charSplit);
                                                    if (ex[0].TrimStart(Convert.ToChar(conf.command)).Equals("alarm"))
                                                    {
                                                        if (type.Equals("channel"))
                                                        {
                                                            ircbot.sendData("PRIVMSG", line[2] + " :Recursion is bad.");
                                                        }
                                                        else
                                                        {
                                                            ircbot.sendData("PRIVMSG", nick + " :Recursion is bad.");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        tmp_conf = conf;
                                                        Timer alarm_trigger = new Timer();
                                                        alarm_trigger.Interval  = (time * 1000);
                                                        alarm_trigger.Enabled   = true;
                                                        alarm_trigger.AutoReset = false;
                                                        alarm_trigger.Elapsed  += (sender, e) => ring_alarm(sender, e, ircbot, nick, line[0], nick_access, channel, type, new_line[1]);
                                                        alarms.Add(alarm_trigger);

                                                        if (type.Equals("channel"))
                                                        {
                                                            ircbot.sendData("PRIVMSG", line[2] + " :Alarm added for " + new_line[0] + " seconds from now.");
                                                        }
                                                        else
                                                        {
                                                            ircbot.sendData("PRIVMSG", nick + " :Alarm added for " + new_line[0] + " seconds from now.");
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    if (type.Equals("channel"))
                                                    {
                                                        ircbot.sendData("PRIVMSG", line[2] + " :" + nick + ", please pick a valid time.");
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("PRIVMSG", nick + " :" + nick + ", please pick a valid time.");
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (type.Equals("channel"))
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :" + nick + ", you need to include more info.");
                                                }
                                                else
                                                {
                                                    ircbot.sendData("PRIVMSG", nick + " :" + nick + ", you need to include more info.");
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (type.Equals("channel"))
                                            {
                                                ircbot.sendData("PRIVMSG", line[2] + " :" + nick + ", you need to include more info.");
                                            }
                                            else
                                            {
                                                ircbot.sendData("PRIVMSG", nick + " :" + nick + ", you need to include more info.");
                                            }
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #46
0
        public override void control(bot ircbot, ref IRCConfig conf, int module_id, string[] line, string command, int nick_access, string nick, string channel, bool bot_command, string type)
        {
            string module_name   = ircbot.conf.module_config[module_id][0];
            int    max_lines     = Convert.ToInt32(ircbot.conf.module_config[module_id][3]);
            int    check_timeout = Convert.ToInt32(ircbot.conf.module_config[module_id][4]);
            bool   warn          = Convert.ToBoolean(ircbot.conf.module_config[module_id][5]);
            string warn_msg      = ircbot.conf.module_config[module_id][6];
            bool   kick          = Convert.ToBoolean(ircbot.conf.module_config[module_id][7]);
            string kick_msg      = ircbot.conf.module_config[module_id][8];
            bool   ban           = Convert.ToBoolean(ircbot.conf.module_config[module_id][9]);
            string ban_msg       = ircbot.conf.module_config[module_id][10];

            if (type.Equals("channel"))
            {
                bool nick_found = false;
                int  cur_lines  = 0;
                int  index      = 0;
                foreach (spam_check spam_log in spam_logs)
                {
                    if (spam_log.channel.Equals(channel) && spam_log.nick.Equals(nick))
                    {
                        nick_found = true;
                        cur_lines  = spam_log.lines;
                        break;
                    }
                    index++;
                }
                if (cur_lines >= max_lines)
                {
                    if (warn)
                    {
                        ircbot.sendData("PRIVMSG", channel + " :" + warn_msg);
                    }
                    if (ban)
                    {
                        string target_host = ircbot.get_user_host(nick);
                        string tmp_ban     = "*!*@" + target_host;
                        if (target_host.Equals(""))
                        {
                            tmp_ban = nick + "!*@*";
                        }
                        ircbot.sendData("MODE", line[2] + " +b " + tmp_ban + " :" + ban_msg);
                    }
                    if (kick)
                    {
                        ircbot.sendData("KICK", channel + " " + nick + " :" + kick_msg);
                    }
                    spam_logs[index].timer.Enabled = false;
                    spam_logs.RemoveAt(index);
                }
                else
                {
                    if (nick_found)
                    {
                        spam_logs[index].lines++;
                    }
                    else
                    {
                        spam_check tmp_spam = new spam_check();
                        tmp_spam.channel = channel;
                        tmp_spam.nick    = nick;
                        tmp_spam.lines   = 1;
                        Timer tmp_timer = new Timer();
                        tmp_timer.Interval  = check_timeout;
                        tmp_timer.Elapsed  += (sender, e) => spam_tick(sender, e, channel, nick);
                        tmp_timer.Enabled   = true;
                        tmp_timer.AutoReset = false;
                        tmp_spam.timer      = tmp_timer;
                        spam_logs.Add(tmp_spam);
                    }
                }
            }
        }
Пример #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") || 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());
                    }
                }
            }
        }
Пример #48
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 "access":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        if (line.GetUpperBound(0) > 3)
                                        {
                                            string[] parse = line[4].Split(' ');
                                            if (parse.GetUpperBound(0) > 1)
                                            {
                                                if (Convert.ToInt32(parse[2]) <= nick_access)
                                                {
                                                    set_access_list(parse[0].Trim().ToLower(), 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().ToLower(), line[2], 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 >= command_access)
                                    {
                                        if (line.GetUpperBound(0) > 3)
                                        {
                                            string[] parse = line[4].Split(' ');
                                            if (parse.GetUpperBound(0) > 1)
                                            {
                                                if (Convert.ToInt32(parse[2]) <= nick_access)
                                                {
                                                    del_access_list(parse[0].Trim().ToLower(), 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().ToLower(), line[2], 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 >= command_access)
                                    {
                                        if (line.GetUpperBound(0) > 3)
                                        {
                                            list_access_list(nick, line[4], ircbot);
                                        }
                                        else if (type.Equals("channel"))
                                        {
                                            list_access_list(nick, 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;

                                case "getaccess":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        if (line.GetUpperBound(0) > 3)
                                        {
                                            string[] new_line = line[4].ToLower().Split(' ');
                                            if (new_line.GetUpperBound(0) > 0 && new_line[0].StartsWith("#"))
                                            {
                                                int viewed_access = ircbot.get_user_access(new_line[1].Trim().ToLower(), 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_user_access(line[4].Trim().ToLower(), channel);
                                                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 + " :" + nick + ", you need to include more info.");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #49
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 "survey":
                                 if (spam_check == true)
                                 {
                                     ircbot.add_spam_count(channel);
                                 }
                                 if (nick_access >= command_access)
                                 {
                                     if (line.GetUpperBound(0) > 3)
                                     {
                                         int num_survey = 1;
                                         try
                                         {
                                             num_survey = Convert.ToInt32(line[4].Trim());
                                             start_survey(nick, nick_access, num_survey - 1, ircbot, conf);
                                         }
                                         catch
                                         {
                                             ircbot.sendData("NOTICE", nick + " :You need to choose a valid survey.  To view all surveys, please type " + conf.command + "surveys");
                                         }
                                     }
                                     else
                                     {
                                         ircbot.sendData("NOTICE", nick + " :You need to choose a valid survey.  To view all surveys, please type " + conf.command + "surveys");
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                 }
                                 break;
                             case "nextquestion":
                                 if (spam_check == true)
                                 {
                                     ircbot.add_spam_count(channel);
                                 }
                                 if (nick_access >= command_access)
                                 {
                                     continue_survey(nick, nick_access, ircbot, conf);
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                 }
                                 break;
                             case "finishsurvey":
                                 if (spam_check == true)
                                 {
                                     ircbot.add_spam_count(channel);
                                 }
                                 if (nick_access >= command_access)
                                 {
                                     int index = 0;
                                     foreach (survey_info survey in active_surveys)
                                     {
                                         if (nick.Equals(survey.nick) && survey.user_submission == 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.survey_number)
                                                 {
                                                     string[] questions = File.ReadAllLines(fsi[survey.survey_number].FullName);
                                                     if (questions.GetUpperBound(0) > 2)
                                                     {
                                                         ircbot.sendData("PRIVMSG", nick + " :Thank you for submitting the survey.  It is survey #" + (survey.survey_number + 1).ToString());
                                                         active_surveys.RemoveAt(index);
                                                     }
                                                     else
                                                     {
                                                         ircbot.sendData("PRIVMSG", nick + " :You need to submit at least one question for your survey.");
                                                     }
                                                 }
                                                 else
                                                 {
                                                     ircbot.sendData("PRIVMSG", nick + " :The survey no longer exists.  Please retry adding your survey.");
                                                 }
                                             }
                                             else
                                             {
                                                 ircbot.sendData("PRIVMSG", nick + " :The survey no longer exists.  Please retry adding your survey.");
                                             }
                                             break;
                                         }
                                         index++;
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                 }
                                 break;
                             case "cancelsurvey":
                                 if (spam_check == true)
                                 {
                                     ircbot.add_spam_count(channel);
                                 }
                                 if (nick_access >= command_access)
                                 {
                                     int index = 0;
                                     foreach (survey_info survey in active_surveys)
                                     {
                                         if (nick.Equals(survey.nick) && survey.user_submission == 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.survey_number)
                                                 {
                                                     File.Delete(fsi[survey.survey_number].FullName);
                                                     string[] owners = File.ReadAllLines(fsi[survey.survey_number].FullName)[2].Split(',');
                                                     foreach (string owner in owners)
                                                     {
                                                         ircbot.sendData("NOTICE", owner + " :" + nick + " has canceled your survey, " + File.ReadAllLines(fsi[survey.survey_number].FullName)[1]);
                                                     }
                                                     active_surveys.RemoveAt(index);
                                                 }
                                                 else
                                                 {
                                                     ircbot.sendData("NOTICE", nick + " :The survey does not exist.");
                                                 }
                                             }
                                             else
                                             {
                                                 ircbot.sendData("NOTICE", nick + " :The survey does not exist.");
                                             }
                                             break;
                                         }
                                         else if(nick.Equals(survey.nick) && survey.user_submission == true)
                                         {
                                             if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "answers" + Path.DirectorySeparatorChar + survey.name + Path.DirectorySeparatorChar + nick))
                                             {
                                                 Directory.Delete(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "answers" + Path.DirectorySeparatorChar + survey.name + Path.DirectorySeparatorChar + nick, true);
                                                 active_surveys.RemoveAt(index);
                                             }
                                             else
                                             {
                                                 ircbot.sendData("NOTICE", nick + " :The survey does not exist.");
                                             }
                                             break;
                                         }
                                         index++;
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                 }
                                 break;
                             case "surveys":
                                 if (spam_check == true)
                                 {
                                     ircbot.add_spam_count(channel);
                                 }
                                 if (nick_access >= command_access)
                                 {
                                     if (line.GetUpperBound(0) > 3)
                                     {
                                         int num_survey = 1;
                                         char[] sep = new char[] { ' ' };
                                         string[] new_line = line[4].Split(sep, StringSplitOptions.RemoveEmptyEntries);
                                         if (new_line.GetUpperBound(0) > 0)
                                         {
                                             try
                                             {
                                                 num_survey = Convert.ToInt32(new_line[0].Trim());
                                                 view_survey(num_survey - 1, nick_access, nick, new_line[1].ToLower(), ircbot, conf);
                                             }
                                             catch
                                             {
                                                 ircbot.sendData("NOTICE", nick + " :You need to choose a valid survey.  To view all surveys, please type " + conf.command + "surveys");
                                             }
                                         }
                                         else
                                         {
                                             try
                                             {
                                                 num_survey = Convert.ToInt32(new_line[0].Trim());
                                                 view_survey(num_survey - 1, nick_access, nick, null, ircbot, conf);
                                             }
                                             catch
                                             {
                                                 ircbot.sendData("NOTICE", nick + " :You need to choose a valid survey.  To view all surveys, please type " + conf.command + "surveys");
                                             }
                                         }
                                     }
                                     else
                                     {
                                         view_survey(-1, nick_access, nick, null, ircbot, conf);
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                 }
                                 break;
                             case "addsurveyowner":
                                 if (spam_check == true)
                                 {
                                     ircbot.add_spam_count(channel);
                                 }
                                 if (nick_access >= command_access)
                                 {
                                     if (line.GetUpperBound(0) > 3)
                                     {
                                         int num_survey = 1;
                                         string[] new_line = line[4].Split(' ');
                                         try
                                         {
                                             num_survey = Convert.ToInt32(new_line[0]);
                                             add_survey_owner(num_survey - 1, nick, new_line[1].ToLower(), ircbot, conf);
                                         }
                                         catch
                                         {
                                             ircbot.sendData("NOTICE", nick + " :You need to choose a valid survey.  To view all surveys, please type " + conf.command + "surveys");
                                         }
                                     }
                                     else
                                     {
                                         ircbot.sendData("NOTICE", nick + " :You need to choose a valid survey.  To view all surveys, please type " + conf.command + "surveys");
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                 }
                                 break;
                             case "delsurveyowner":
                                 if (spam_check == true)
                                 {
                                     ircbot.add_spam_count(channel);
                                 }
                                 if (nick_access >= command_access)
                                 {
                                     if (line.GetUpperBound(0) > 3)
                                     {
                                         int num_survey = 1;
                                         string[] new_line = line[4].Split(' ');
                                         try
                                         {
                                             num_survey = Convert.ToInt32(new_line[0]);
                                             del_survey_owner(num_survey - 1, nick, new_line[1].ToLower(), ircbot, conf);
                                         }
                                         catch
                                         {
                                             ircbot.sendData("NOTICE", nick + " :You need to choose a valid survey.  To view all surveys, please type " + conf.command + "surveys");
                                         }
                                     }
                                     else
                                     {
                                         ircbot.sendData("NOTICE", nick + " :You need to choose a valid survey.  To view all surveys, please type " + conf.command + "surveys");
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                 }
                                 break;
                             case "addsurvey":
                                 if (spam_check == true)
                                 {
                                     ircbot.add_spam_count(channel);
                                 }
                                 if (nick_access >= command_access)
                                 {
                                     if (line.GetUpperBound(0) > 3)
                                     {
                                         char[] charSep = new char[] { ' ' };
                                         string[] new_line = line[4].Split(charSep, 2);
                                         if (new_line.GetUpperBound(0) > 0)
                                         {
                                             int survey_access = conf.user_level - 1;
                                             bool access_valid = true;
                                             try
                                             {
                                                 survey_access = Convert.ToInt32(new_line[0]);
                                             }
                                             catch
                                             {
                                                 access_valid = false;
                                                 ircbot.sendData("NOTICE", nick + " :Please choose a valid access level.");
                                             }
                                             if (access_valid == true)
                                             {
                                                 add_survey(nick, survey_access, new_line[1], ircbot, conf);
                                             }
                                             else
                                             {
                                                 ircbot.sendData("NOTICE", nick + " :Please include the survey access level and title for the survey.  Ex: " + conf.command + "addsurvey 1 Title of Survey");
                                             }
                                         }
                                         else
                                         {
                                             ircbot.sendData("NOTICE", nick + " :Please include the survey access level and title for the survey.  Ex: " + conf.command + "addsurvey 1 Title of Survey");
                                         }
                                     }
                                     else
                                     {
                                         ircbot.sendData("NOTICE", nick + " :Please include the survey access level and title for the survey.  Ex: " + conf.command + "addsurvey 1 Title of Survey");
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                 }
                                 break;
                             case "delsurvey":
                                 if (spam_check == true)
                                 {
                                     ircbot.add_spam_count(channel);
                                 }
                                 if (nick_access >= command_access)
                                 {
                                     if (line.GetUpperBound(0) > 3)
                                     {
                                         int num_survey = 1;
                                         try
                                         {
                                             num_survey = Convert.ToInt32(line[4].Trim());
                                             del_survey(nick, num_survey - 1, ircbot, conf);
                                         }
                                         catch
                                         {
                                             ircbot.sendData("NOTICE", nick + " :You need to choose a valid survey.  To view all surveys, please type " + conf.command + "surveys");
                                         }
                                     }
                                     else
                                     {
                                         ircbot.sendData("NOTICE", nick + " :You need to choose a valid survey.  To view all surveys, please type " + conf.command + "surveys");
                                     }
                                 }
                                 else
                                 {
                                     ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                 }
                                 break;
                         }
                     }
                 }
             }
         }
     }
     if (type.Equals("query") && bot_command == false)
     {
         foreach (survey_info survey in active_surveys)
         {
             if (nick.Equals(survey.nick))
             {
                 string answer = "";
                 if (line.GetUpperBound(0) > 3)
                 {
                     answer = line[3].Remove(0,1) + " " + line[4] + Environment.NewLine;
                 }
                 else
                 {
                     answer = line[3].Remove(0, 1) + Environment.NewLine;
                 }
                 if (survey.user_submission == true)
                 {
                     if (!Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "answers" + Path.DirectorySeparatorChar + survey.name + Path.DirectorySeparatorChar + survey.nick + Path.DirectorySeparatorChar + ""))
                     {
                         Directory.CreateDirectory(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "answers" + Path.DirectorySeparatorChar + survey.name + Path.DirectorySeparatorChar + survey.nick + Path.DirectorySeparatorChar + "");
                     }
                     File.AppendAllText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "answers" + Path.DirectorySeparatorChar + survey.name + Path.DirectorySeparatorChar + survey.nick + " " + Path.DirectorySeparatorChar + survey.current_question + ".txt", answer);
                 }
                 else
                 {
                     if (!Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "surveys" + Path.DirectorySeparatorChar + ""))
                     {
                         Directory.CreateDirectory(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "surveys" + Path.DirectorySeparatorChar + "");
                     }
                     File.AppendAllText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "surveys" + Path.DirectorySeparatorChar + survey.name + ".txt", answer);
                 }
                 break;
             }
         }
     }
 }
Пример #50
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 "isitup":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= 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", line[2] + " :" + nick + ", you need to include more info.");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #51
0
        public void add_quote(string nick, string channel, string[] line, bot ircbot, IRCConfig conf)
        {
            string tab_name     = channel.TrimStart('#');
            string pattern      = "[^a-zA-Z0-9]"; //regex pattern
            string new_tab_name = Regex.Replace(tab_name, pattern, "_");
            string file_name    = ircbot.server_name + "_#" + new_tab_name + ".log";

            if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "quotes" + Path.DirectorySeparatorChar + "logs") == false)
            {
                Directory.CreateDirectory(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "quotes" + Path.DirectorySeparatorChar + "logs");
            }
            StreamWriter log_file = File.AppendText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "quotes" + Path.DirectorySeparatorChar + "logs" + Path.DirectorySeparatorChar + file_name);

            if (line.GetUpperBound(0) > 3)
            {
                log_file.WriteLine(nick + "*" + line[3].Remove(0, 1) + " " + line[4]);
            }
            else
            {
                log_file.WriteLine(nick + "*" + line[3].Remove(0, 1));
            }
            log_file.Close();
        }
Пример #52
0
        private void add_survey(string nick, int survey_access, string survey_name, bot ircbot, IRCConfig conf)
        {
            bool survey_found = false;

            foreach (survey_info survey in active_surveys)
            {
                if (nick.Equals(survey.nick))
                {
                    survey_found = true;
                    break;
                }
            }
            if (survey_found == false)
            {
                if (!Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "surveys" + Path.DirectorySeparatorChar + ""))
                {
                    Directory.CreateDirectory(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();
                File.AppendAllText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "surveys" + Path.DirectorySeparatorChar + "survey_" + (fsi.GetUpperBound(0) + 1).ToString() + ".txt", survey_access.ToString() + Environment.NewLine);
                File.AppendAllText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "surveys" + Path.DirectorySeparatorChar + "survey_" + (fsi.GetUpperBound(0) + 1).ToString() + ".txt", survey_name + Environment.NewLine);
                File.AppendAllText(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "surveys" + Path.DirectorySeparatorChar + "survey_" + (fsi.GetUpperBound(0) + 1).ToString() + ".txt", nick + Environment.NewLine);

                survey_info tmp_info = new survey_info();
                tmp_info.name = "survey_" + (fsi.GetUpperBound(0) + 1).ToString();
                tmp_info.nick = nick;
                tmp_info.survey_number = (fsi.GetUpperBound(0) + 1);
                tmp_info.current_question = 1;
                tmp_info.user_submission = false;

                active_surveys.Add(tmp_info);

                ircbot.sendData("PRIVMSG", nick + " :Please type out a question per line.  Once you are finished adding all the questions you want, type " + conf.command + "finishsurvey to submit the finished survey.");
                ircbot.sendData("PRIVMSG", nick + " :If at any time during the survey you wish to cancel, type " + conf.command + "cancelsurvey to cancel your current survey submission.");
            }
            else
            {
                ircbot.sendData("PRIVMSG", nick + " :You already have a survey active.  Please finish the current survey or cancel it to create a new survey.");
            }
        }
Пример #53
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 "google":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        if (line.GetUpperBound(0) > 3)
                                        {
                                            if (line[4].StartsWith("DCC SEND"))
                                            {
                                                ircbot.sendData("PRIVMSG", line[2] + " :Invalid Search Term");
                                            }
                                            else
                                            {
                                                ISearchResult searchClass = new GoogleSearch(line[4]);
                                                try
                                                {
                                                    var list = searchClass.Search();
                                                    if (list.Count > 0)
                                                    {
                                                        foreach (var searchType in list)
                                                        {
                                                            ircbot.sendData("PRIVMSG", line[2] + " :" + searchType.title.Replace("<b>", "").Replace("</b>", "").Replace("&quot;", "\"").Replace("&#39", "'").Replace("&amp;", "&") + ": " + searchType.content.Replace("<b>", "").Replace("</b>", "").Replace("&quot;", "\"").Replace("&#39", "'").Replace("&amp;", "&"));

                                                            if (conf.module_config[module_id][3].Equals("True"))
                                                            {
                                                                ircbot.sendData("PRIVMSG", line[2] + " :" + searchType.url);
                                                            }
                                                            break;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        ircbot.sendData("PRIVMSG", line[2] + " :No Results Found");
                                                    }
                                                }
                                                catch
                                                {
                                                    ircbot.sendData("PRIVMSG", line[2] + " :I can't search atm.");
                                                }
                                            }
                                        }
                                        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;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #54
0
        private void continue_survey(string nick, int nick_access, bot ircbot, IRCConfig conf)
        {
            int cur_survey = 0;
            List<survey_info> new_survey = new List<survey_info>();
            new_survey = active_surveys;
            foreach (survey_info tmp_survey in new_survey)
            {
                if (nick.Equals(tmp_survey.nick))
                {
                    survey_info this_survey = active_surveys[cur_survey];
                    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();
                    bool survey_found = false;
                    if (Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "surveys" + Path.DirectorySeparatorChar + ""))
                    {
                        if (fsi.GetUpperBound(0) >= 0 && fsi.GetUpperBound(0) >= tmp_survey.survey_number)
                        {
                            string[] questions = File.ReadAllLines(fsi[tmp_survey.survey_number].FullName);
                            if (questions.GetUpperBound(0) > 2)
                            {
                                if (Convert.ToInt32(questions[0]) <= nick_access)
                                {
                                    survey_found = true;
                                    this_survey.current_question = tmp_survey.current_question + 1;
                                    active_surveys[cur_survey] = this_survey;
                                    if (questions.GetUpperBound(0) > this_survey.current_question + 1)
                                    {
                                        if (!Directory.Exists(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "answers" + Path.DirectorySeparatorChar + tmp_survey.name + Path.DirectorySeparatorChar + tmp_survey.nick + Path.DirectorySeparatorChar + ""))
                                        {
                                            Directory.CreateDirectory(ircbot.cur_dir + Path.DirectorySeparatorChar + "modules" + Path.DirectorySeparatorChar + "survey" + Path.DirectorySeparatorChar + "answers" + Path.DirectorySeparatorChar + tmp_survey.name + Path.DirectorySeparatorChar + tmp_survey.nick + Path.DirectorySeparatorChar + "");
                                        }

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

                                        ircbot.sendData("PRIVMSG", nick + " :" + questions[this_survey.current_question + 2]);
                                    }
                                    else
                                    {
                                        ircbot.sendData("PRIVMSG", nick + " :Thank you for completing the survey!  Your answers have been recorded and sent to the survey owner.");

                                        string[] owners = questions[2].Split(',');
                                        foreach (string owner in owners)
                                        {
                                            ircbot.sendData("PRIVMSG", owner + " :" + nick + " has finished your survey, \"" + questions[1] + "\"");
                                            ircbot.sendData("PRIVMSG", owner + " :To view his answers, please type " + conf.command + "surveys " + (tmp_survey.survey_number + 1).ToString() + " " + tmp_survey.nick);
                                        }
                                        active_surveys.RemoveAt(cur_survey);
                                    }
                                }
                            }
                        }
                    }
                    if (survey_found == false)
                    {
                        ircbot.sendData("PRIVMSG", nick + " :Sorry, but that survey is not available to you anymore.  To view all surveys available to you, please type .surveys");
                        active_surveys.RemoveAt(cur_survey);
                    }
                    break;
                }
                cur_survey++;
            }
        }
Пример #55
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 "idle":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        bool nick_found = false;
                                        foreach (string idle_nick in idle_list)
                                        {
                                            if (idle_nick.Equals(nick))
                                            {
                                                nick_found = true;
                                                break;
                                            }
                                        }
                                        if (nick_found == false)
                                        {
                                            idle_list.Add(nick);
                                            ircbot.sendData("NOTICE", nick + " :You are now set as idle.  Type .deidle to come back.");
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You are already idle.  Type .deidle to come back.");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;

                                case "deidle":
                                    if (spam_check == true)
                                    {
                                        ircbot.add_spam_count(channel);
                                    }
                                    if (nick_access >= command_access)
                                    {
                                        bool nick_found = false;
                                        foreach (string idle_nick in idle_list)
                                        {
                                            if (idle_nick.Equals(nick))
                                            {
                                                nick_found = true;
                                                break;
                                            }
                                        }
                                        if (nick_found == true)
                                        {
                                            idle_list.Remove(nick);
                                            ircbot.sendData("NOTICE", nick + " :Welcome back!");
                                        }
                                        else
                                        {
                                            ircbot.sendData("NOTICE", nick + " :You are already idle.  Type .deidle to come back.");
                                        }
                                    }
                                    else
                                    {
                                        ircbot.sendData("NOTICE", nick + " :You do not have permission to use that command.");
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #56
0
        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");
                }
            }
        }
Пример #57
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 "weather":
                                    if (conf.module_config[module_id][3].Equals("True"))
                                    {
                                        if (spam_check == true)
                                        {
                                            lock (ircbot.spamlock)
                                            {
                                                bool spam_added = false;
                                                int  index      = 0;
                                                foreach (spam_info spam in conf.spam_check)
                                                {
                                                    if (spam.spam_channel.Equals(channel))
                                                    {
                                                        spam_added = true;
                                                        index++;
                                                        break;
                                                    }
                                                }
                                                if (spam_added)
                                                {
                                                    conf.spam_check[index].spam_count++;
                                                }
                                                else
                                                {
                                                    spam_info new_spam = new spam_info();
                                                    new_spam.spam_channel   = channel;
                                                    new_spam.spam_activated = false;
                                                    new_spam.spam_count     = 1;
                                                    conf.spam_check.Add(new_spam);
                                                }
                                            }
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                // Add introduction
                                                get_weather(line[4], line[2], ircbot);
                                            }
                                            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;

                                case "forecast":
                                    if (conf.module_config[module_id][4].Equals("True"))
                                    {
                                        if (spam_check == true)
                                        {
                                            lock (ircbot.spamlock)
                                            {
                                                bool spam_added = false;
                                                int  index      = 0;
                                                foreach (spam_info spam in conf.spam_check)
                                                {
                                                    if (spam.spam_channel.Equals(channel))
                                                    {
                                                        spam_added = true;
                                                        index++;
                                                        break;
                                                    }
                                                }
                                                if (spam_added)
                                                {
                                                    conf.spam_check[index].spam_count++;
                                                }
                                                else
                                                {
                                                    spam_info new_spam = new spam_info();
                                                    new_spam.spam_channel   = channel;
                                                    new_spam.spam_activated = false;
                                                    new_spam.spam_count     = 1;
                                                    conf.spam_check.Add(new_spam);
                                                }
                                            }
                                        }
                                        if (nick_access >= command_access)
                                        {
                                            if (line.GetUpperBound(0) > 3)
                                            {
                                                // Add introduction
                                                get_forecast(line[4], line[2], ircbot, Convert.ToInt32(conf.module_config[module_id][5]));
                                            }
                                            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;
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #58
0
        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.");
            }
        }
Пример #59
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());
                    }
                }
            }
        }
Пример #60
0
        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");
            }
        }