예제 #1
0
        public bool RemovePage(string wiki, string page)
        {
            page = page.Replace("_", " ");
            IWatch currpage = null;

            lock (MonitoredPages)
            {
                foreach (IWatch iw in MonitoredPages)
                {
                    if (iw.Page == page && wiki == iw.Site)
                    {
                        currpage = iw;
                        break;
                    }
                }
                if (MonitoredPages.Contains(currpage))
                {
                    MonitoredPages.Remove(currpage);
                    Module.SetConfig(channel, "HTML.Update", true);
                    Save();
                    IRC.DeliverMessage(messages.Localize("rcfeed4", channel.Language), channel);
                    return(true);
                }
            }
            IRC.DeliverMessage(messages.Localize("rcfeed5", channel.Language), channel);
            return(true);
        }
예제 #2
0
        private void UnnotifyUser(string message, libirc.UserInfo invoker, libirc.Target target_)
        {
            string parameter = message.Substring(message.IndexOf(" ") + 1).Trim().ToLower();

            if (String.IsNullOrEmpty(parameter))
            {
                IRC.DeliverMessage("This command requires exactly 1 parameter", target_.TargetName);
                return;
            }
            if (parameter.Contains(" "))
            {
                IRC.DeliverMessage("That's not a valid nickname (spaces present)", target_.TargetName);
                return;
            }
            foreach (Notification n in Notification.NotificationList)
            {
                if (n.Source_Name == invoker.Nick && n.Target.ToLower() == parameter)
                {
                    string original_nick = n.Target;
                    Notification.NotificationList.Remove(n);
                    IRC.DeliverMessage("You notification about " + original_nick + " was removed!", target_.TargetName);
                    return;
                }
            }
        }
예제 #3
0
 public void RegEx2(string nick, Channel channel, string source)
 {
     try
     {
         temp_nick    = nick;
         temp_source  = source;
         chan         = channel;
         SearchThread = new Thread(Search)
         {
             Name = "Module:Seen/Search"
         };
         wmib.Core.ThreadManager.RegisterThread(SearchThread);
         SearchThread.Start();
         Working = true;
         int curr = 0;
         while (Working)
         {
             Thread.Sleep(10);
             curr++;
             if (curr > 80)
             {
                 Core.ThreadManager.KillThread(SearchThread);
                 IRC.DeliverMessage("This search took too much time, please optimize query", channel.Name);
                 Working = false;
                 break;
             }
         }
     }
     catch (Exception fail)
     {
         HandleException(fail);
     }
 }
예제 #4
0
 public override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message)
 {
     if (message.StartsWith("!") && message.Contains("|"))
     {
         DebugLog("Parsing: " + message, 6);
         string user = message.Substring(message.IndexOf("|") + 1);
         user = user.Trim();
         DebugLog("Parsed user - " + user, 6);
         if (user.Contains(" "))
         {
             user = user.Substring(0, user.IndexOf(" "));
         }
         if (user != "")
         {
             DebugLog("Adding user to list " + user, 6);
             Ring.Add(new Buffer.Item(invoker.Nick, user));
         }
     }
     else
     {
         message = message.ToLower();
         if (message.Contains(channel.PrimaryInstance.Nick) && !message.Contains("thanks to") && (message.Contains("thanks") || message.Contains("thank you")) && !message.Contains("no thank"))
         {
             string      response = "Hey " + invoker.Nick + ", you are welcome!";
             Buffer.Item x        = Ring.getUser(invoker.Nick);
             DebugLog("Checking if user was recently informed using infobot");
             if (x != null)
             {
                 response = "Hey " + invoker.Nick + ", you are welcome, but keep in mind I am just a stupid bot, it was actually " + x.User + " who helped you :-)";
                 Ring.Delete(x);
             }
             IRC.DeliverMessage(response, channel);
         }
     }
 }
예제 #5
0
 public void CreateSnapshot(Channel chan, string name)
 {
     try
     {
         if (!IsValid(name))
         {
             IRC.DeliverMessage("This is not a valid name for snapshot, you can only use a-zA-Z and 0-9 chars", chan.Name);
             return;
         }
         if (SnapshotManager != null)
         {
             if (SnapshotManager.ThreadState == ThreadState.Running)
             {
                 IRC.DeliverMessage("There is already another snapshot operation running for this channel", chan.Name);
                 return;
             }
         }
         string datafile = InfobotModule.SnapshotsDirectory + Path.DirectorySeparatorChar + pChannel.Name + Path.DirectorySeparatorChar + name;
         if (File.Exists(datafile))
         {
             IRC.DeliverMessage("The requested snapshot " + name + " already exist", chan.Name, libirc.Defs.Priority.Low);
             return;
         }
         SnapshotManager      = new Thread(SnapshotStart);
         temporary_data       = datafile;
         SnapshotManager.Name = "Snapshot";
         SnapshotManager.Start();
     }
     catch (Exception fail)
     {
         Parent.HandleException(fail);
     }
 }
예제 #6
0
        public override bool Hook_OnPrivateFromUser(string message, libirc.UserInfo user)
        {
            Notification result = Notification.RetrieveTarget(user.Nick);

            while (result != null)
            {
                IRC.DeliverMessage(result.Source_Name + "! " + user.Nick + " just sent me a private message. This message was delivered to you because you asked me to notify you about this user's activity. For more information, see https://meta.wikimedia.org/wiki/WM-Bot", result.Source_Name);
                this.Deliver(result);
                lock (Notification.NotificationList)
                {
                    Notification.NotificationList.Remove(result);
                }
                result = Notification.RetrieveTarget(user.Nick);
            }

            if (message.StartsWith(Configuration.System.CommandPrefix + "notify "))
            {
                this.NotifyUser(message, user, user);
                return(true);
            }

            if (message.StartsWith(Configuration.System.CommandPrefix + "unnotify "))
            {
                this.UnnotifyUser(message, user, user);
                return(true);
            }

            return(false);
        }
예제 #7
0
 /// <summary>
 /// Alias
 /// </summary>
 /// <param name="key">Key</param>
 /// <param name="al">Alias</param>
 /// <param name="user">User</param>
 /// <param name="chan"></param>
 /// <param name="enforced"></param>
 private void aliasKey(string key, string al, string user, Channel chan, bool enforced = false)
 {
     lock (this)
     {
         foreach (InfobotAlias stakey in Aliases)
         {
             if (stakey.Name == al)
             {
                 if (!chan.SuppressWarnings)
                 {
                     IRC.DeliverMessage(messages.Localize("infobot7", chan.Language), chan.Name);
                 }
                 return;
             }
         }
         if (!KeyExists(key))
         {
             if (!enforced)
             {
                 if (AliasExists(key))
                 {
                     IRC.DeliverMessage("Unable to create alias for " + key + " because the target is alias, but not a key, if you really want to create this broken alias do !" + al + " force-alias " + key, chan.Name);
                     return;
                 }
                 IRC.DeliverMessage("Unable to create alias for " + key + " because there is no such key, if you really want to create this broken alias do !" + al + " force-alias " + key, chan.Name);
                 return;
             }
         }
         Aliases.Add(new InfobotAlias(al, key));
     }
     IRC.DeliverMessage(messages.Localize("infobot8", chan.Language), chan.Name);
     this.StoreDB();
 }
예제 #8
0
 private void replaceKey(string Text, string key, string user, Channel chan)
 {
     lock (this)
     {
         try
         {
             bool newkey = !KeyExists(key, Sensitive);
             if (!newkey)
             {
                 this.DeleteKey(key);
             }
             Keys.Add(new InfobotKey(key, Text, user, "false"));
             if (newkey)
             {
                 IRC.DeliverMessage(messages.Localize("infobot6", chan.Language), chan);
             }
             else
             {
                 IRC.DeliverMessage("Successfully replaced " + key, chan);
             }
             this.StoreDB();
         }
         catch (Exception b)
         {
             Core.HandleException(b, "infobot");
         }
     }
 }
예제 #9
0
        private void translate(CommandParams p)
        {
            if (string.IsNullOrEmpty(p.Parameters))
            {
                return;
            }


            List <string> parts = new List <string>(p.Parameters.Split(' '));

            if (parts.Count < 3)
            {
                IRC.DeliverMessage("Invalid number of parameters", p.SourceChannel);
                return;
            }
            string target          = null;
            string source_language = parts[0];
            string target_language = parts[1];

            if (!IsValid(source_language) || !IsValid(target_language))
            {
                IRC.DeliverMessage(p.User.Nick + ": invalid language!", p.SourceChannel);
                return;
            }
            string text = p.Parameters.Substring(p.Parameters.IndexOf(parts[1]) + parts[1].Length + 1);

            if (text.Contains("|"))
            {
                target = text.Substring(text.IndexOf("|") + 1).Trim();
                text   = text.Substring(0, text.IndexOf("|"));
            }
            // schedule a message
            Ring.Add(new Buffer.Item(p.SourceChannel, source_language, target_language, target, text));
        }
예제 #10
0
        private void time(CommandParams p)
        {
            DateTime time = DateTime.UtcNow;

            //DateTime eastern = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.UtcNow, "Eastern Standard Time");
            IRC.DeliverMessage(p.User.Nick + ": It is " + time + " UTC", p.SourceChannel);
        }
예제 #11
0
        private void StartSearch()
        {
            Regex   value    = new Regex(search_key, RegexOptions.Compiled);
            Channel _channel = Core.GetChannel(pChannel.Name);
            string  results  = "";
            int     count    = 0;

            lock (this)
            {
                foreach (InfobotKey data in Keys)
                {
                    if (data.Key == search_key || value.Match(data.Text).Success)
                    {
                        count++;
                        results = results + data.Key + ", ";
                    }
                }
            }
            if (String.IsNullOrEmpty(results))
            {
                IRC.DeliverMessage(messages.Localize("ResultsWereNotFound", ReplyChan.Language), ReplyChan.Name);
            }
            else
            {
                IRC.DeliverMessage(messages.Localize("Results", _channel.Language, new List <string> {
                    count.ToString()
                }) + results, ReplyChan.Name);
            }
            // ??
            InfobotModule.running = false;
        }
예제 #12
0
        private void cmRevoke(CommandParams pm)
        {
            if (String.IsNullOrEmpty(pm.Parameters))
            {
                return;
            }

            string        name       = pm.Parameters.Trim();
            List <string> parameters = new List <string>(name.Split(' '));

            if (parameters.Count != 2)
            {
                IRC.DeliverMessage("Invalid number of parameters", pm.SourceChannel);
                return;
            }
            string role = pm.SourceChannel.Name + "." + parameters[0];

            lock (Security.Roles)
            {
                if (!Security.Roles.ContainsKey(role))
                {
                    IRC.DeliverMessage("There is no role of that name", pm.SourceChannel);
                    return;
                }
                Security.Roles[role].Revoke(parameters[1]);
            }
            IRC.DeliverMessage("Successfuly revoked " + parameters[1] + " from " + role, pm.SourceChannel);
            IsUpdated = true;
            return;
        }
예제 #13
0
 public void RecoverStart()
 {
     try
     {
         while (!this.stored)
         {
             Thread.Sleep(100);
         }
         lock (this)
         {
             Syslog.Log("Recovering snapshot " + temporary_data);
             File.Copy(temporary_data, datafile_xml, true);
             this.Keys.Clear();
             this.Aliases.Clear();
             Parent.Log("Loading snapshot of " + pChannel.Name);
             LoadData();
             IRC.DeliverMessage("Snapshot " + temporary_data + " was loaded and previous database was permanently deleted", pChannel);
         }
     }
     catch (Exception fail)
     {
         Parent.Log("Unable to recover a snapshot for " + pChannel.Name + " the db is likely broken now", true);
         Parent.HandleException(fail);
     }
 }
예제 #14
0
 public void InsertItem(string name, string url, bool scan = false)
 {
     if (url == "")
     {
         if (Contains(name))
         {
             foreach (Subscription curr in RssProviders)
             {
                 if (curr.Name == name)
                 {
                     IRC.DeliverMessage("This item was enabled now", owner.Name);
                     curr.Reset();
                     return;
                 }
             }
         }
         IRC.DeliverMessage("There is no such item, if you want to define new item, please use 2 parameters", owner.Name);
         return;
     }
     if (!Contains(name))
     {
         Subscription item = new Subscription {
             Name = name, ScannerOnly = scan, URL = url, template = ""
         };
         lock (RssProviders)
         {
             RssProviders.Add(item);
         }
         Save();
         IRC.DeliverMessage("Item was inserted to feed", owner.Name);
         return;
     }
     IRC.DeliverMessage("This item already exist", owner.Name);
 }
예제 #15
0
        public void RemoveItem(string Name)
        {
            if (!Contains(Name))
            {
                IRC.DeliverMessage("I don't have this item in a db", owner.Name);
                return;
            }
            Subscription rm = null;

            lock (RssProviders)
            {
                foreach (Subscription Item in RssProviders)
                {
                    if (Item.Name == Name)
                    {
                        rm = Item;
                        break;
                    }
                }
                if (rm != null)
                {
                    RssProviders.Remove(rm);
                    Save();
                    IRC.DeliverMessage("Item was removed from db", owner.Name);
                    return;
                }
            }
            IRC.DeliverMessage("Unable to remove this item from db", owner.Name);
        }
예제 #16
0
        public void StyleItem(string Name, string temp)
        {
            if (!Contains(Name))
            {
                IRC.DeliverMessage("I don't have this item in a db", owner.Name);
                return;
            }
            Subscription rm = null;

            lock (RssProviders)
            {
                foreach (Subscription Item in RssProviders)
                {
                    if (Item.Name == Name)
                    {
                        rm = Item;
                        break;
                    }
                }
                if (rm != null)
                {
                    rm.template = temp;
                    Save();
                    IRC.DeliverMessage("Item now has a different style you can restore the default style by removing this value", owner.Name);
                }
            }
        }
예제 #17
0
        private void list_keys(CommandParams p)
        {
            Infobot info = (Infobot)p.SourceChannel.RetrieveObject("Infobot");

            if (info == null)
            {
                return;
            }

            string result = "";

            if (info.Keys.Count == 0)
            {
                result = "No keys defined";
            }
            else
            {
                foreach (Infobot.InfobotKey key in info.Keys)
                {
                    result += key.Key + ", ";
                }
            }

            if (result.EndsWith(", ", StringComparison.InvariantCulture))
            {
                result = result.Substring(0, result.Length - 2);
            }

            if (result.Length > 450)
            {
                result = result.Substring(0, 450) + "...";
            }
            IRC.DeliverMessage(result, p.SourceChannel);
        }
예제 #18
0
파일: AI.cs 프로젝트: lziad/wikimedia-bot
        private void Respond(Channel channel, libirc.UserInfo invoker, string message)
        {
            message = message.Replace("$invoker.nick", invoker.Nick)
                      .Replace("$invoker.host", invoker.Host)
                      .Replace("$invoker.ident", invoker.Ident);

            IRC.DeliverMessage(invoker.Nick + ": " + message, channel);
        }
예제 #19
0
 private void github_Insert(CommandParams p)
 {
     if (string.IsNullOrEmpty(p.Parameters))
     {
         IRC.DeliverMessage("This command requires exactly 1 parameter", p.SourceChannel);
         return;
     }
     lock (Core.DB.DatabaseLock)
     {
         string error = "unknown";
         Core.DB.Connect();
         if (!Core.DB.IsConnected)
         {
             if (Core.DB.ErrorBuffer != null)
             {
                 error = Core.DB.ErrorBuffer;
             }
             IRC.DeliverMessage("Unable to connect to SQL: " + error, p.SourceChannel);
             return;
         }
         // first check if repository isn't already there
         List <List <string> > result = Core.DB.Select("github_repo_info", "name, channel", "WHERE name = '" + Core.DB.EscapeInput(p.Parameters) + "' AND channel = '" +
                                                       Core.DB.EscapeInput(p.SourceChannel.Name) + "'");
         if (result.Count != 0)
         {
             IRC.DeliverMessage("This repository is already in DB", p.SourceChannel);
             Core.DB.Disconnect();
             return;
         }
         Database.Row row = new Database.Row();
         row.Values.Add(new Database.Row.Value(0));
         row.Values.Add(new Database.Row.Value(p.Parameters, Database.DataType.Varchar));
         row.Values.Add(new Database.Row.Value(p.SourceChannel.Name, Database.DataType.Varchar));
         if (GetConfig(p.SourceChannel, "NetCat.Token", false))
         {
             row.Values.Add(new Database.Row.Value(GetConfig(p.SourceChannel, "NetCat.TokenData", ""), Database.DataType.Varchar));
         }
         else
         {
             row.Values.Add(new Database.Row.Value("", Database.DataType.Varchar));
         }
         row.Values.Add(new Database.Row.Value(true));
         if (!Core.DB.InsertRow("github_repo_info", row))
         {
             if (Core.DB.ErrorBuffer != null)
             {
                 error = Core.DB.ErrorBuffer;
             }
             IRC.DeliverMessage("Failed to insert row: " + error, p.SourceChannel);
             Core.DB.Disconnect();
             return;
         }
         Core.DB.Commit();
         Core.DB.Disconnect();
     }
     IRC.DeliverMessage("Hooks from " + p.Parameters + " will be now displayed in this channel", p.SourceChannel);
 }
예제 #20
0
 private void Deliver(Notification notification)
 {
     if (notification.Message == null)
     {
         return;
     }
     IRC.DeliverMessage("Hi " + notification.User + ", " + notification.Source_Name + " was looking for you and wanted me to tell you this when you are here: " +
                        notification.Message, notification.User);
 }
예제 #21
0
        private bool DeliverKey(InfobotKey Key, string OriginalText, Channel chan, libirc.UserInfo fu)
        {
            if (Key == null)
            {
                return(false);
            }
            string Target_ = "";
            string text    = OriginalText;

            // we remove the key name from message so that only parameters remain
            if (text.Contains(" "))
            {
                text = text.Substring(text.IndexOf(" ") + 1);
            }
            else
            {
                text = "";
            }
            if (text.Contains("|"))
            {
                Target_ = OriginalText.Substring(OriginalText.IndexOf("|") + 1);
                if (Module.GetConfig(chan, "Infobot.Trim-white-space-in-name", true))
                {
                    Target_ = Target_.Trim();
                }
                text = text.Substring(0, text.IndexOf("|"));
            }
            List <string> Parameters = new List <string>(text.Split(' '));
            string        value_     = ParseInfo(Parameters, text, Key, fu);

            if (Key.IsAct)
            {
                if (String.IsNullOrEmpty(Target_))
                {
                    IRC.DeliverAction(value_, chan);
                }
                else
                {
                    IRC.DeliverAction(Target_ + ": " + value_, chan);
                }
            }
            else
            {
                if (String.IsNullOrEmpty(Target_))
                {
                    IRC.DeliverMessage(value_, chan);
                }
                else
                {
                    IRC.DeliverMessage(Target_ + ": " + value_, chan);
                }
            }
            Key.Displayed++;
            Key.LastTime = DateTime.Now;
            this.StoreDB();
            return(true);
        }
예제 #22
0
        /// <summary>
        /// Search
        /// </summary>
        /// <param name="key">Key</param>
        /// <param name="Chan"></param>
        public void RSearch(string key, Channel Chan)
        {
            if (key == Configuration.System.CommandPrefix + "regsearch")
            {
                IRC.DeliverMessage(messages.Localize("Search1", Chan.Language), Chan.Name);
                return;
            }
            if (!key.StartsWith(Configuration.System.CommandPrefix + "regsearch "))
            {
                return;
            }
            if (!misc.IsValidRegex(key))
            {
                IRC.DeliverMessage(messages.Localize("Error1", Chan.Language), Chan.Name);
                return;
            }
            if (key.Length < 12)
            {
                IRC.DeliverMessage(messages.Localize("Search1", Chan.Language), Chan.Name);
                return;
            }
            Channel data    = RetrieveMasterDBChannel(Chan);
            bool    Allowed = (data != null);

            if (!Allowed)
            {
                IRC.DeliverMessage(messages.Localize("db7", Chan.Language), Chan.Name);
                return;
            }
            Infobot infobot = (Infobot)data.RetrieveObject("Infobot");

            if (infobot == null)
            {
                Syslog.Log("Unable to perform regsearch because the Infobot doesn't exist in " + Chan.Name, true);
                return;
            }
            infobot.search_key    = key.Substring(11);
            InfobotModule.running = true;
            ReplyChan             = Chan;
            tSearch = new Thread(infobot.StartSearch);
            tSearch.Start();
            int check = 1;

            while (InfobotModule.running)
            {
                check++;
                Thread.Sleep(100);
                if (check > 8)
                {
                    tSearch.Abort();
                    IRC.DeliverMessage(messages.Localize("Error2", Chan.Language), Chan.Name);
                    InfobotModule.running = false;
                    return;
                }
            }
        }
예제 #23
0
        private void token_on(CommandParams p)
        {
            string token = GenerateToken();

            SetConfig(p.SourceChannel, "NetCat.Token", true);
            SetConfig(p.SourceChannel, "NetCat.TokenData", token);
            p.SourceChannel.SaveConfig();
            IRC.DeliverMessage("New token was generated for this channel, and it was sent to you in a private message", p.SourceChannel.Name);
            IRC.DeliverMessage("Token for " + p.SourceChannel.Name + " is: " + token, p.SourceUser.Nick);
        }
예제 #24
0
 public override bool Hook_GetConfig(Channel chan, libirc.UserInfo invoker, string config)
 {
     switch (config)
     {
     case "recent-changes-template":
         IRC.DeliverMessage("Value of " + config + " is: " + GetConfig(chan, "RC.Template", "<default value>"), chan);
         return(true);
     }
     return(false);
 }
예제 #25
0
 private void On(CommandParams p)
 {
     if (GetConfig(p.SourceChannel, "OP.Enabled", false))
     {
         IRC.DeliverMessage(messages.Localize("OpE1", p.SourceChannel.Language), p.SourceChannel);
         return;
     }
     IRC.DeliverMessage(messages.Localize("OpM1", p.SourceChannel.Language), p.SourceChannel.Name);
     SetConfig(p.SourceChannel, "OP.Enabled", true);
     p.SourceChannel.SaveConfig();
 }
예제 #26
0
 private void PermanentOff(CommandParams p)
 {
     if (!GetConfig(p.SourceChannel, "OP.Permanent", false))
     {
         IRC.DeliverMessage(messages.Localize("OpE2", p.SourceChannel.Language), p.SourceChannel);
         return;
     }
     IRC.DeliverMessage(messages.Localize("OpM2", p.SourceChannel.Language), p.SourceChannel);
     SetConfig(p.SourceChannel, "OP.Permanent", false);
     p.SourceChannel.SaveConfig();
 }
예제 #27
0
 private void minor_on(CommandParams pm)
 {
     if (GetConfig(pm.SourceChannel, "Minor.Enabled", false))
     {
         IRC.DeliverMessage(messages.Localize("Feed13", pm.SourceChannel.Language), pm.SourceChannel);
         return;
     }
     IRC.DeliverMessage(messages.Localize("Feed9", pm.SourceChannel.Language), pm.SourceChannel);
     SetConfig(pm.SourceChannel, "Minor.Enabled", true);
     pm.SourceChannel.SaveConfig();
 }
예제 #28
0
 private void bot_off(CommandParams pm)
 {
     if (!GetConfig(pm.SourceChannel, "Bot.Enabled", false))
     {
         IRC.DeliverMessage(messages.Localize("Feed16", pm.SourceChannel.Language), pm.SourceChannel);
         return;
     }
     IRC.DeliverMessage(messages.Localize("Feed12", pm.SourceChannel.Language), pm.SourceChannel);
     SetConfig(pm.SourceChannel, "Bot.Enabled", false);
     pm.SourceChannel.SaveConfig();
 }
예제 #29
0
 private void rmKey(string key, string user, Channel _ch)
 {
     if (this.DeleteKey(key))
     {
         IRC.DeliverMessage(messages.Localize("infobot9", _ch.Language) + key, _ch.Name);
     }
     else
     {
         IRC.DeliverMessage(messages.Localize("infobot10", _ch.Language), _ch.Name);
     }
 }
예제 #30
0
 private void cmSeenOff(CommandParams parameters)
 {
     if (!GetConfig(parameters.SourceChannel, "Seen.Enabled", false))
     {
         IRC.DeliverMessage(messages.Localize("seen-e2", parameters.SourceChannel.Language), parameters.SourceChannel.Name);
         return;
     }
     IRC.DeliverMessage(messages.Localize("seen-off", parameters.SourceChannel.Language), parameters.SourceChannel.Name);
     SetConfig(parameters.SourceChannel, "Seen.Enabled", false);
     parameters.SourceChannel.SaveConfig();
 }