Пример #1
0
        public void CheckMessages(IrcClient c, Channels curChan, IrcMessageEventArgs e)
        {
            if (!xmlLoaded)
            {
                LoadXML();
                xmlLoaded = true;
            }
            if (client == null)
                client = c;

            bool commandFound = false;
            if (e.Text[0] == '!')
            {
                foreach (BasicTextCommands t in textCommands)
                {
                    string chan;
                    if (t.channel[0] == '#')
                        chan = t.channel;
                    else
                        chan = string.Format("#{0}", t.channel);
                    if (chan == curChan.ChannelName || t.channel == "#anychannel")
                    {
                        if (e.Text.ToLower() == t.triggerName.ToLower())
                        {
                            client.LocalUser.SendMessage(curChan.ChannelName, t.responseText);
                            commandFound = true;
                            break;
                        }
                    }
                }
                if (!commandFound)
                {
                    if (curChan.ChannelName == "#sakegeist")
                    {
                        SakegeistCommands(curChan, e);
                    }
                }

                if (e.Source.Name.ToLower() == "moonizz" || e.Source.Name.ToLower() == curChan.ChannelName.Substring(1).ToLower())
                {
                    if (e.Text.ToLower().StartsWith("!add "))
                    {
                        string[] splitText = e.Text.Split('\"');
                        if (splitText.Length == 5)
                        {

                            BasicTextCommands t = new BasicTextCommands();
                            t.channel = curChan.ChannelName;
                            if (splitText[1][0] == '!')
                                t.triggerName = splitText[1];
                            else
                                t.triggerName = string.Format("!{0}",splitText[1]);
                            t.responseText = splitText[3];

                            string chan;
                            bool commandExist = false;
                            for (int i = 0; i < textCommands.Count; ++i)
                            {
                                if (textCommands[i].channel[0] == '#')
                                    chan = textCommands[i].channel;
                                else
                                    chan = string.Format("#{0}", textCommands[i].channel);
                                if (string.Format("#{0}", textCommands[i].channel) == chan || textCommands[i].channel == chan)
                                {
                                    if (textCommands[i].triggerName == t.triggerName)
                                    {
                                        client.LocalUser.SendMessage(curChan.ChannelName, "Command already exists! Overriding!");

                                        textCommands[i] = t;
                                        SaveXML();
                                        commandExist = true;
                                    }
                                }
                            }
                            if (!commandExist)
                            {
                                textCommands.Add(t);
                                client.LocalUser.SendMessage(curChan.ChannelName, "Command added");
                                SaveXML();
                            }
                        }
                        else{
                            client.LocalUser.SendMessage(curChan.ChannelName, "Invalid Command, use !add \"!<TriggerText>\" \"<message>\"");
                        }
                    }

                }
            }

            Console.WriteLine(curChan.ChannelName);
        }
Пример #2
0
        void LoadXML()
        {
            fileName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
            fileName += "\\TextCommands.xml";
            fileName = fileName.Substring(6);
            xmlDoc.Load(fileName);
            XmlNodeList userNodes = xmlDoc.SelectNodes("//DoC/Users");

            foreach (XmlNode userNode in userNodes)
            {
                for (int i = 0; i < userNode.ChildNodes.Count; ++i)
                {
                    userNames.Add(userNode.ChildNodes[i].InnerText);
                    Console.WriteLine(userNode.ChildNodes[i].InnerText);
                }
            }

            for (int i = 0; i < userNames.Count; ++i)
            {
                userNodes = xmlDoc.SelectNodes(string.Format("//DoC/Commands/{0}", userNames[i]));
                foreach (XmlNode userNode in userNodes)
                {
                    if (userNode.ChildNodes[0] != null)
                    {
                        foreach (XmlNode uNode in userNode.ChildNodes)
                        {
                            BasicTextCommands textCMD = new BasicTextCommands();

                            if (uNode.ChildNodes[0].Name == "trigger")
                            {
                                textCMD.triggerName = uNode.ChildNodes[0].InnerText;
                                textCMD.responseText = uNode.ChildNodes[1].InnerText;
                            }
                            else
                            {
                                textCMD.triggerName = uNode.ChildNodes[0].InnerText;
                                textCMD.responseText = uNode.ChildNodes[1].InnerText;
                            }
                            textCMD.channel = userNames[i];
                            textCommands.Add(textCMD);
                        }
                    }
                }
            }
        }