Beispiel #1
0
        void Bot_onCommand(object sender, CommandEventArgs e)
        {
            string[] parameters;
            UInt32 ChannelID = e.ChannelID;
            int parsedInt;
            _channelid = ChannelID;

            if (e.ChannelName == null)
            {
                ChannelID = Bot.ChannelID;
                _channelid = ChannelID;
            }

            switch (e.Command)
            {
                case "category":
                    if (_inprogress)
                    {
                        Bot.SendChannelMessage(ChannelID, "{0}The current trivia category is: {1}" + _categoryname + "{0}!");
                    }
                    else
                    {
                        Bot.SendChannelMessage(ChannelID, "{0}Trivia is not in progress!");
                    }
                    break;

                case "question":
                    if (_inprogress)
                    {
                        Bot.SendChannelMessage(ChannelID, "{0}Question #" + _questionnumber + " of " + _questioncount + ": [{1}" + _categorykey + "{0}] {1}" + _question);
                    }
                    else
                    {
                        Bot.SendChannelMessage(ChannelID, "{0}Trivia is not in progress!");
                    }
                    break;

                case "trivia":
                    if (e.GetParameters(2, out parameters))
                    {
                        switch (parameters[0])
                        {
                            default:
                                if (int.TryParse(parameters[1], out parsedInt))
                                {
                                    if (!_inprogress)
                                    {
                                        _inprogress = true;

                                        if (ExtractCategory(parameters[0], parsedInt))
                                        {
                                            _questionnumber = 0;
                                            _votes.Clear();
                                            _scores.Clear();

                                            GetQuestion();
                                            Bot.SendChannelMessage(ChannelID, "{0}The category is... {1}" + _categoryname + "{0}!");
                                            Bot.SendChannelMessage(ChannelID, "{0}Hints: {1}" + _hints + " {2}| {0}Auto-Correct: {1}" + _autocorrect);
                                            Bot.SendChannelMessage(ChannelID, "{0}Question #1 of " + parsedInt + ": [{1}" + _categorykey + "{0}] {1}" + _question);
                                            tmrHint.Start();

                                            _questioncount = parsedInt;
                                        }
                                        else
                                        {
                                            _inprogress = false;
                                            Bot.SendChannelMessage(ChannelID, _error);
                                        }
                                    }
                                }
                                else
                                {
                                    Bot.SendChannelMessage(ChannelID, "{0}Command does either {1}not exist {0}or using an {1}incorrect format{0}.");
                                }
                                break;
                        }
                    }
                    else if (e.GetParameters(1, out parameters))
                    {
                        switch (parameters[0])
                        {
                            case "end":
                                if (_inprogress)
                                {
                                    _inprogress = false;
                                    tmrHint.Stop();
                                    Bot.SendChannelMessage(ChannelID, "{0}Trivia has ended, thanks for playing!");
                                }
                                else
                                {
                                    Bot.SendChannelMessage(ChannelID, "{0}Trivia is not in progress!");
                                }
                                break;
                        }
                    }
                    break;
            }
        }
Beispiel #2
0
        void Core_onCommand(object sender, CommandEventArgs e)
        {
            string[] parameters;
            UInt32 ChannelID = e.ChannelID;
            List<char> botflags;
            byte flags;
            string whois = "";

            if (e.ChannelName == null)
            {
                ChannelID = this.ChannelID[CurrentChannel];
            }

            switch (e.Command)
            {
                case "admin":
                    if (Program.Core.GetBotFlags(e.Username, 'a'))
                    {
                        if (e.GetParameters(2, out parameters))
                        {
                            XmlDocument xmlDoc = new XmlDocument();
                            XmlNodeList users;

                            xmlDoc.Load(Application.StartupPath + "/newerthbot.xml");
                            users = xmlDoc.SelectNodes("/newerthbot/users/user");

                            switch (parameters[0])
                            {
                                case "add":
                                    if (e.GetParameters(3, out parameters))
                                    {
                                        XmlNode user = xmlDoc.CreateElement("user");
                                        XmlAttribute _botflags = xmlDoc.CreateAttribute("flags");
                                        XmlAttribute _userid = xmlDoc.CreateAttribute("userid");
                                        _botflags.Value = parameters[2];
                                        _userid.Value = Program.Core.GetUserID(parameters[1]).ToString();
                                        user.InnerText = parameters[1];
                                        user.Attributes.Append(_botflags);
                                        xmlDoc.SelectSingleNode("/newerthbot/users").AppendChild(user);
                                    }
                                    break;

                                case "remove":
                                    foreach (XmlNode user in users)
                                    {
                                        if (user.InnerText.ToLower() == parameters[1].ToLower())
                                        {
                                            xmlDoc.SelectSingleNode("/newerthbot/users").RemoveChild(user);
                                            break;
                                        }
                                    }
                                    break;

                                case "update":
                                    if (e.GetParameters(3, out parameters))
                                    {
                                        foreach (XmlNode user in users)
                                        {
                                            if (user.InnerText.ToLower() == parameters[1].ToLower())
                                            {
                                                user.Attributes[0].Value = parameters[2];
                                            }
                                        }
                                    }
                                    break;
                            }
                        }
                    }
                    else
                    {
                        Program.Core.SendChannelMessage(ChannelID, "{0}You do not have permission to use this command, you require the '{1}a{0}' flag!");
                    }
                    break;

                case "join":
                    if (Program.Core.GetBotFlags(e.Username, 'c'))
                    {
                        if (!radChannel[8].Visible)
                            Program.Core.JoinChannel(e.Parameters);
                    }
                    else
                    {
                        Program.Core.SendChannelMessage(ChannelID, "{0}You do not have permission to use this command, you require the '{1}c{0}' flag!");
                    }
                    break;

                case "leave":
                    if (Program.Core.GetBotFlags(e.Username, 'c'))
                    {
                        if (e.Parameters != radChannel[1].Text)
                            Program.Core.LeaveChannel(e.Parameters);
                    }
                    else
                    {
                        Program.Core.SendChannelMessage(ChannelID, "{0}You do not have permission to use this command, you require the '{1}c{0}' flag!");
                    }
                    break;

                case "say":
                    if (Program.Core.GetBotFlags(e.Username, 's'))
                    {
                        Program.Core.SendChannelMessage(ChannelID, e.Parameters);
                    }
                    else
                    {
                        Program.Core.SendChannelMessage(ChannelID, "{0}You do not have permission to use this command, you require the '{1}s{0}' flag!");
                    }
                    break;

                case "uptime":
                    TimeSpan span = DateTime.Now - Process.GetCurrentProcess().StartTime;
                    string uptime;

                    if (span.Days > 0)
                    {
                        uptime = "{0}I've been online for {1}" + span.Days + " {0}day(s), {1}" + span.Hours + " {0}hour(s), {1}" + span.Minutes + " {0}minute(s) and {1}" + span.Seconds + " {0}second(s).";
                    }
                    else if (span.Hours > 0)
                    {
                        uptime = "{0}I've been online for {1}" + span.Hours + " {0}hour(s), {1}" + span.Minutes + " {0}minute(s) and {1}" + span.Seconds + " {0}second(s).";
                    }
                    else if (span.Minutes > 0)
                    {
                        uptime = "{0}I've been online for {1}" + span.Minutes + " {0}minute(s) and {1}" + span.Seconds + " {0}second(s).";
                    }
                    else
                    {
                        uptime = "{0}I've been online for {1}" + span.Seconds + " {0}second(s).";
                    }

                    Program.Core.SendChannelMessage(ChannelID, uptime);
                    break;

                case "whoami":
                    botflags = Program.Core.GetBotFlags(e.Username);
                    whois = "{0}You are {1}" + e.Username + " {0}and you have the '{1}";

                    if (botflags.Count > 0)
                    {
                        foreach (char flag in botflags)
                        {
                            whois += flag;
                        }

                        whois += "{0}' flags.";
                        Program.Core.SendChannelMessage(ChannelID, whois);
                    }
                    else
                    {
                        Program.Core.SendChannelMessage(ChannelID, "{0}You are {1}" + e.Username + " {0}and you have {1}no {0}flags.");
                    }
                    break;

                case "whois":
                    if (e.Parameters != "")
                    {
                        if (e.Parameters == Program.Username)
                        {
                            whois = "{0}I'm {1}" + Program.Username + "{0}!";
                        }
                        else
                        {
                            flags = Program.Core.GetFlags(e.Parameters);
                            botflags = Program.Core.GetBotFlags(e.Username);

                            if (botflags.Count > 0)
                            {
                                whois = "{1}" + e.Parameters + " has the '{1}";

                                foreach (char flag in botflags)
                                {
                                    whois += flag;
                                }

                                whois += "{0}' flags.";
                                Program.Core.SendChannelMessage(ChannelID, whois);
                            }
                            else
                            {
                                Program.Core.SendChannelMessage(ChannelID, "{1}" + e.Parameters + " {0}either has {1}no {0}flags or I have not seen him/her before.");
                            }
                        }

                        Program.Core.SendChannelMessage(ChannelID, whois);
                    }
                    break;
            }
        }