示例#1
0
 public void SaveData()
 {
     lock (config.channels)
     {
         foreach (config.channel x in config.channels)
         {
             infobot_core infobot = (infobot_core)x.RetrieveObject("Infobot");
             if (infobot != null)
             {
                 if (infobot.stored == false)
                 {
                     infobot.stored = true;
                     infobot.Save();
                 }
             }
         }
     }
 }
示例#2
0
        public override string Extension_DumpHtml(config.channel channel)
        {
            string       HTML = "";
            infobot_core info = (infobot_core)channel.RetrieveObject("Infobot");

            if (info != null)
            {
                HTML += "\n<table border=1 class=\"infobot\" width=100%>\n<tr><th width=10%>Key</th><th>Value</th></tr>\n";
                List <infobot_core.InfobotKey> list = new List <infobot_core.InfobotKey>();
                lock (info)
                {
                    if (Module.GetConfig(channel, "Infobot.Sorted", false) != false)
                    {
                        list = info.SortedItem();
                    }
                    else
                    {
                        list.AddRange(info.Keys);
                    }
                }
                if (info.Keys.Count > 0)
                {
                    foreach (infobot_core.InfobotKey Key in list)
                    {
                        HTML += core.HTML.AddKey(Key.Key, Key.Text);
                    }
                }
                HTML += "</table>\n";
                HTML += "<h4>Aliases</h4>\n<table class=\"infobot\" border=1 width=100%>\n";
                lock (info)
                {
                    foreach (infobot_core.InfobotAlias data in info.Alias)
                    {
                        HTML += core.HTML.AddLink(data.Name, data.Key);
                    }
                }
                HTML += "</table><br>\n";
            }
            return(HTML);
        }
示例#3
0
 public override void Load()
 {
     try
     {
         Unwritable = false;
         while (Disabled != true)
         {
             if (Unwritable)
             {
                 Thread.Sleep(200);
             }
             else if (jobs.Count > 0)
             {
                 Unwritable = true;
                 List <infobot_core.InfoItem> list = new List <infobot_core.InfoItem>();
                 list.AddRange(jobs);
                 jobs.Clear();
                 Unwritable = false;
                 foreach (infobot_core.InfoItem item in list)
                 {
                     infobot_core infobot = (infobot_core)item.Channel.RetrieveObject("Infobot");
                     if (infobot != null)
                     {
                         infobot.print(item.Name, item.User, item.Channel, item.Host);
                     }
                 }
             }
             Thread.Sleep(200);
         }
     }
     catch (Exception b)
     {
         Unwritable = false;
         Console.WriteLine(b.InnerException);
     }
     return;
 }
示例#4
0
        public override bool Hook_SetConfig(config.channel chan, User invoker, string config, string value)
        {
            bool _temp_a;

            switch (config)
            {
            case "infobot-trim-white-space-in-name":
                if (bool.TryParse(value, out _temp_a))
                {
                    Module.SetConfig(chan, "Infobot.Trim-white-space-in-name", _temp_a);
                    core.irc._SlowQueue.DeliverMessage(messages.get("configuresave", chan.Language, new List <string> {
                        value, config
                    }), chan.Name);
                    chan.SaveConfig();
                    return(true);
                }
                core.irc._SlowQueue.DeliverMessage(messages.get("configure-va", chan.Language, new List <string> {
                    config, value
                }), chan.Name);
                return(true);

            case "infobot-auto-complete":
                if (bool.TryParse(value, out _temp_a))
                {
                    Module.SetConfig(chan, "Infobot.auto-complete", _temp_a);
                    core.irc._SlowQueue.DeliverMessage(messages.get("configuresave", chan.Language, new List <string> {
                        value, config
                    }), chan.Name);
                    chan.SaveConfig();
                    return(true);
                }
                core.irc._SlowQueue.DeliverMessage(messages.get("configure-va", chan.Language, new List <string> {
                    config, value
                }), chan.Name);
                return(true);

            case "infobot-sorted":
                if (bool.TryParse(value, out _temp_a))
                {
                    Module.SetConfig(chan, "Infobot.Sorted", _temp_a);
                    core.irc._SlowQueue.DeliverMessage(messages.get("configuresave", chan.Language, new List <string> {
                        value, config
                    }), chan.Name);
                    chan.SaveConfig();
                    return(true);
                }
                core.irc._SlowQueue.DeliverMessage(messages.get("configure-va", chan.Language, new List <string> {
                    config, value
                }), chan.Name);
                return(true);

            case "infobot-help":
                if (bool.TryParse(value, out _temp_a))
                {
                    Module.SetConfig(chan, "Infobot.Help", _temp_a);
                    core.irc._SlowQueue.DeliverMessage(messages.get("configuresave", chan.Language, new List <string> {
                        value, config
                    }), chan.Name);
                    chan.SaveConfig();
                    return(true);
                }
                core.irc._SlowQueue.DeliverMessage(messages.get("configure-va", chan.Language, new List <string> {
                    config, value
                }), chan.Name);
                return(true);

            case "infobot-case":
                if (bool.TryParse(value, out _temp_a))
                {
                    Module.SetConfig(chan, "Infobot.Case", _temp_a);
                    core.irc._SlowQueue.DeliverMessage(messages.get("configuresave", chan.Language, new List <string> {
                        value, config
                    }), chan.Name);
                    chan.SaveConfig();
                    infobot_core infobot = (infobot_core)chan.RetrieveObject("Infobot");
                    if (infobot != null)
                    {
                        infobot.Sensitive = _temp_a;
                    }
                    return(true);
                }
                core.irc._SlowQueue.DeliverMessage(messages.get("configure-va", chan.Language, new List <string> {
                    config, value
                }), chan.Name);
                return(true);
            }
            return(false);
        }
示例#5
0
        public override void Hook_PRIV(config.channel channel, User invoker, string message)
        {
            // "\uff01" is the full-width version of "!".
            if ((message.StartsWith("!") || message.StartsWith("\uff01")) && GetConfig(channel, "Infobot.Enabled", true))
            {
                while (Unwritable)
                {
                    Thread.Sleep(10);
                }
                Unwritable = true;
                infobot_core.InfoItem item = new infobot_core.InfoItem();
                item.Channel = channel;
                item.Name    = "!" + message.Substring(1); // Normalizing "!".
                item.User    = invoker.Nick;
                item.Host    = invoker.Host;
                jobs.Add(item);
                Unwritable = false;
            }

            infobot_core infobot = null;

            if (message.StartsWith(config.CommandPrefix))
            {
                infobot = (infobot_core)channel.RetrieveObject("Infobot");
                if (infobot == null)
                {
                    core.Log("Object Infobot in " + channel.Name + " doesn't exist", true);
                }
                if (GetConfig(channel, "Infobot.Enabled", true))
                {
                    if (infobot != null)
                    {
                        infobot.Find(message, channel);
                        infobot.RSearch(message, channel);
                    }
                }
            }

            if (Snapshots)
            {
                if (message.StartsWith(config.CommandPrefix + "infobot-recovery "))
                {
                    if (channel.Users.IsApproved(invoker, "admin"))
                    {
                        string name = message.Substring("@infobot-recovery ".Length);
                        if (!GetConfig(channel, "Infobot.Enabled", true))
                        {
                            core.irc._SlowQueue.DeliverMessage("Infobot is not enabled in this channel", channel, IRC.priority.low);
                            return;
                        }
                        if (infobot != null)
                        {
                            infobot.RecoverSnapshot(channel, name);
                        }
                        return;
                    }
                    if (!channel.suppress_warnings)
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low);
                    }
                    return;
                }

                if (message.StartsWith(config.CommandPrefix + "infobot-snapshot "))
                {
                    if (channel.Users.IsApproved(invoker, "admin"))
                    {
                        string name = message.Substring("@infobot-snapshot ".Length);
                        if (!GetConfig(channel, "Infobot.Enabled", true))
                        {
                            core.irc._SlowQueue.DeliverMessage("Infobot is not enabled in this channel", channel, IRC.priority.low);
                            return;
                        }
                        if (infobot != null)
                        {
                            infobot.CreateSnapshot(channel, name);
                        }
                        return;
                    }
                    if (!channel.suppress_warnings)
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low);
                    }
                    return;
                }

                if (message.StartsWith(config.CommandPrefix + "infobot-set-raw "))
                {
                    if (channel.Users.IsApproved(invoker, "trust"))
                    {
                        string name = message.Substring("@infobot-set-raw ".Length);
                        if (!GetConfig(channel, "Infobot.Enabled", true))
                        {
                            core.irc._SlowQueue.DeliverMessage("Infobot is not enabled in this channel", channel, IRC.priority.low);
                            return;
                        }
                        if (infobot != null)
                        {
                            infobot.setRaw(name, invoker.Nick, channel);
                            return;
                        }
                    }
                    if (!channel.suppress_warnings)
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low);
                    }
                    return;
                }

                if (message.StartsWith(config.CommandPrefix + "infobot-unset-raw "))
                {
                    if (channel.Users.IsApproved(invoker, "trust"))
                    {
                        string name = message.Substring("@infobot-unset-raw ".Length);
                        if (!GetConfig(channel, "Infobot.Enabled", true))
                        {
                            core.irc._SlowQueue.DeliverMessage("Infobot is not enabled in this channel", channel, IRC.priority.low);
                            return;
                        }
                        if (infobot != null)
                        {
                            infobot.unsetRaw(name, invoker.Nick, channel);
                            return;
                        }
                    }
                    if (!channel.suppress_warnings)
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low);
                    }
                    return;
                }

                if (message.StartsWith(config.CommandPrefix + "infobot-snapshot-rm "))
                {
                    if (channel.Users.IsApproved(invoker, "admin"))
                    {
                        string name = message.Substring("@infobot-snapshot-rm ".Length);
                        name.Replace(".", "");
                        name.Replace("/", "");
                        name.Replace("\\", "");
                        name.Replace("*", "");
                        name.Replace("?", "");
                        if (name == "")
                        {
                            core.irc._SlowQueue.DeliverMessage("You should specify a file name", channel, IRC.priority.normal);
                            return;
                        }
                        if (!File.Exists(SnapshotsDirectory + Path.DirectorySeparatorChar + channel.Name + Path.DirectorySeparatorChar + name))
                        {
                            core.irc._SlowQueue.DeliverMessage("File not found", channel, IRC.priority.normal);
                            return;
                        }
                        File.Delete(SnapshotsDirectory + Path.DirectorySeparatorChar + channel.Name + Path.DirectorySeparatorChar + name);
                        core.irc._SlowQueue.DeliverMessage("Requested file was removed", channel, IRC.priority.normal);
                        return;
                    }
                    if (!channel.suppress_warnings)
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low);
                    }
                    return;
                }

                if (message == config.CommandPrefix + "infobot-snapshot-ls")
                {
                    string        files      = "";
                    DirectoryInfo di         = new DirectoryInfo(SnapshotsDirectory + Path.DirectorySeparatorChar + channel.Name);
                    FileInfo[]    rgFiles    = di.GetFiles("*");
                    int           curr       = 0;
                    int           displaying = 0;
                    foreach (FileInfo fi in rgFiles)
                    {
                        curr++;
                        if (files.Length < 200)
                        {
                            files += fi.Name + " ";
                            displaying++;
                        }
                    }
                    string response = "";
                    if (curr == displaying)
                    {
                        response = "There are " + displaying.ToString() + " files: " + files;
                    }
                    else
                    {
                        response = "There are " + curr.ToString() + " files, but displaying only " + displaying.ToString() + " of them: " + files;
                    }
                    if (curr == 0)
                    {
                        response = "There is no snapshot so far, create one!:)";
                    }
                    core.irc._SlowQueue.DeliverMessage(response, channel.Name, IRC.priority.normal);
                    return;
                }
            }

            if (message.StartsWith(config.CommandPrefix + "infobot-share-trust+ "))
            {
                if (channel.Users.IsApproved(invoker, "admin"))
                {
                    if (channel.shared != "local")
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("infobot16", channel.Language), channel);
                        return;
                    }
                    if (channel.shared != "local" && channel.shared != "")
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("infobot15", channel.Language), channel);
                        return;
                    }
                    else
                    {
                        if (message.Length <= "@infobot-share-trust+ ".Length)
                        {
                            core.irc._SlowQueue.DeliverMessage(messages.get("db6", channel.Language), channel.Name);
                            return;
                        }
                        string         name  = message.Substring("@infobot-share-trust+ ".Length);
                        config.channel guest = core.getChannel(name);
                        if (guest == null)
                        {
                            core.irc._SlowQueue.DeliverMessage(messages.get("db8", channel.Language), channel.Name);
                            return;
                        }
                        if (channel.SharedLinkedChan.Contains(guest))
                        {
                            core.irc._SlowQueue.DeliverMessage(messages.get("db14", channel.Language), channel.Name);
                            return;
                        }
                        core.irc._SlowQueue.DeliverMessage(messages.get("db1", channel.Language, new List <string> {
                            name
                        }), channel.Name);
                        lock (channel.SharedLinkedChan)
                        {
                            channel.SharedLinkedChan.Add(guest);
                        }
                        channel.SaveConfig();
                        return;
                    }
                }
                if (!channel.suppress_warnings)
                {
                    core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel.Name, IRC.priority.low);
                }
                return;
            }

            if (message.StartsWith(config.CommandPrefix + "infobot-ignore- "))
            {
                if (channel.Users.IsApproved(invoker, "trust"))
                {
                    string item = message.Substring("@infobot-ignore+ ".Length);
                    if (item != "")
                    {
                        if (!channel.Infobot_IgnoredNames.Contains(item))
                        {
                            core.irc._SlowQueue.DeliverMessage(messages.get("infobot-ignore-found", channel.Language, new List <string> {
                                item
                            }), channel);
                            return;
                        }
                        channel.Infobot_IgnoredNames.Remove(item);
                        core.irc._SlowQueue.DeliverMessage(messages.get("infobot-ignore-rm", channel.Language, new List <string> {
                            item
                        }), channel);
                        channel.SaveConfig();
                        return;
                    }
                }
                else
                {
                    if (!channel.suppress_warnings)
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low);
                    }
                }
            }

            if (message.StartsWith(config.CommandPrefix + "infobot-ignore+ "))
            {
                if (channel.Users.IsApproved(invoker, "trust"))
                {
                    string item = message.Substring("@infobot-ignore+ ".Length);
                    if (item != "")
                    {
                        if (channel.Infobot_IgnoredNames.Contains(item))
                        {
                            core.irc._SlowQueue.DeliverMessage(messages.get("infobot-ignore-exist", channel.Language, new List <string> {
                                item
                            }), channel);
                            return;
                        }
                        channel.Infobot_IgnoredNames.Add(item);
                        core.irc._SlowQueue.DeliverMessage(messages.get("infobot-ignore-ok", channel.Language, new List <string> {
                            item
                        }), channel);
                        channel.SaveConfig();
                        return;
                    }
                }
                else
                {
                    if (!channel.suppress_warnings)
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low);
                    }
                }
            }

            if (message == config.CommandPrefix + "infobot-off")
            {
                if (channel.Users.IsApproved(invoker, "admin"))
                {
                    if (!GetConfig(channel, "Infobot.Enabled", true))
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("infobot1", channel.Language), channel);
                        return;
                    }
                    else
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("infobot2", channel.Language), channel, IRC.priority.high);
                        SetConfig(channel, "Infobot.Enabled", false);
                        channel.SaveConfig();
                        return;
                    }
                }
                if (!channel.suppress_warnings)
                {
                    core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low);
                }
                return;
            }

            if (message.StartsWith(config.CommandPrefix + "infobot-share-trust- "))
            {
                if (channel.Users.IsApproved(invoker, "admin"))
                {
                    if (channel.shared != "local")
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("infobot16", channel.Language), channel);
                        return;
                    }
                    else
                    {
                        if (message.Length <= "@infobot-share-trust+ ".Length)
                        {
                            core.irc._SlowQueue.DeliverMessage(messages.get("db6", channel.Language), channel);
                            return;
                        }
                        string         name   = message.Substring("@infobot-share-trust- ".Length);
                        config.channel target = core.getChannel(name);
                        if (target == null)
                        {
                            core.irc._SlowQueue.DeliverMessage(messages.get("db8", channel.Language), channel);
                            return;
                        }
                        if (channel.SharedLinkedChan.Contains(target))
                        {
                            channel.SharedLinkedChan.Remove(target);
                            core.irc._SlowQueue.DeliverMessage(messages.get("db2", channel.Language, new List <string> {
                                name
                            }), channel);
                            channel.SaveConfig();
                            return;
                        }
                        core.irc._SlowQueue.DeliverMessage(messages.get("db4", channel.Language), channel);
                        return;
                    }
                }
                if (!channel.suppress_warnings)
                {
                    core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low);
                }
                return;
            }

            if (message.StartsWith(config.CommandPrefix + "infobot-detail "))
            {
                if ((message.Length) <= "@infobot-detail ".Length)
                {
                    core.irc._SlowQueue.DeliverMessage(messages.get("db6", channel.Language), channel);
                    return;
                }
                if (GetConfig(channel, "Infobot.Enabled", true))
                {
                    if (channel.shared == "local" || channel.shared == "")
                    {
                        if (infobot != null)
                        {
                            infobot.Info(message.Substring(16), channel);
                        }
                        return;
                    }
                    if (channel.shared != "")
                    {
                        config.channel db = core.getChannel(channel.shared);
                        if (db == null)
                        {
                            core.irc._SlowQueue.DeliverMessage("Error, null pointer to shared channel", channel, IRC.priority.low);
                            return;
                        }
                        if (infobot != null)
                        {
                            infobot.Info(message.Substring(16), channel);
                        }
                        return;
                    }
                    return;
                }
                core.irc._SlowQueue.DeliverMessage("Infobot is not enabled on this channel", channel, IRC.priority.low);
                return;
            }

            if (message.StartsWith(config.CommandPrefix + "infobot-link "))
            {
                if (channel.Users.IsApproved(invoker, "admin"))
                {
                    if (channel.shared == "local")
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("infobot17", channel.Language), channel);
                        return;
                    }
                    if (channel.shared != "")
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("infobot18", channel.Language, new List <string> {
                            channel.shared
                        }), channel);
                        return;
                    }
                    if ((message.Length - 1) < "@infobot-link ".Length)
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("db6", channel.Language), channel);
                        return;
                    }
                    string         name = message.Substring("@infobot-link ".Length);
                    config.channel db   = core.getChannel(name);
                    if (db == null)
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("db8", channel.Language), channel);
                        return;
                    }
                    if (!infobot_core.Linkable(db, channel))
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("db9", channel.Language), channel);
                        return;
                    }
                    channel.shared = name.ToLower();
                    core.irc._SlowQueue.DeliverMessage(messages.get("db10", channel.Language), channel);
                    channel.SaveConfig();
                    return;
                }
                if (!channel.suppress_warnings)
                {
                    core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low);
                }
                return;
            }

            if (message == config.CommandPrefix + "infobot-share-off")
            {
                if (channel.Users.IsApproved(invoker, "admin"))
                {
                    if (channel.shared == "")
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("infobot14", channel.Language), channel);
                        return;
                    }
                    else
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("infobot13", channel.Language), channel);
                        foreach (config.channel curr in config.channels)
                        {
                            if (curr.shared == channel.Name.ToLower())
                            {
                                curr.shared = "";
                                curr.SaveConfig();
                                core.irc._SlowQueue.DeliverMessage(messages.get("infobot19", curr.Language, new List <string> {
                                    invoker.Nick
                                }), curr);
                            }
                        }
                        channel.shared = "";
                        channel.SaveConfig();
                        return;
                    }
                }
                if (!channel.suppress_warnings)
                {
                    core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low);
                }
                return;
            }

            if (message == config.CommandPrefix + "infobot-on")
            {
                if (channel.Users.IsApproved(invoker, "admin"))
                {
                    if (GetConfig(channel, "Infobot.Enabled", true))
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("infobot3", channel.Language), channel);
                        return;
                    }
                    SetConfig(channel, "Infobot.Enabled", true);
                    channel.SaveConfig();
                    core.irc._SlowQueue.DeliverMessage(messages.get("infobot4", channel.Language), channel, IRC.priority.high);
                    return;
                }
                if (!channel.suppress_warnings)
                {
                    core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low);
                }
                return;
            }

            if (message == config.CommandPrefix + "infobot-share-on")
            {
                if (channel.Users.IsApproved(invoker, "admin"))
                {
                    if (channel.shared == "local")
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("infobot11", channel.Language), channel, IRC.priority.high);
                        return;
                    }
                    if (channel.shared != "local" && channel.shared != "")
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("infobot15", channel.Language), channel, IRC.priority.high);
                        return;
                    }
                    else
                    {
                        core.irc._SlowQueue.DeliverMessage(messages.get("infobot12", channel.Language), channel);
                        channel.shared = "local";
                        channel.SaveConfig();
                        return;
                    }
                }
                if (!channel.suppress_warnings)
                {
                    core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low);
                }
                return;
            }
        }