public override void Hook_Channel(config.channel channel) { if (channel.RetrieveObject("RC") == null) { channel.RegisterObject(new RecentChanges(channel), "RC"); } }
private bool Part(string source, string parameters, string value) { string chan = parameters; chan = chan.Replace(" ", ""); string user = source.Substring(0, source.IndexOf("!")); string _ident; string _host; if (chan == config.DebugChan && instance.Nick != core.irc.NickName) { return(true); } _host = source.Substring(source.IndexOf("@") + 1); _ident = source.Substring(source.IndexOf("!") + 1); _ident = _ident.Substring(0, _ident.IndexOf("@")); config.channel channel = core.getChannel(chan); User us = new User(user, _host, _ident); if (channel != null) { lock (Module.module) { foreach (Module module in Module.module) { if (!module.working) { continue; } try { module.Hook_Part(channel, us); } catch (Exception fail) { core.handleException(fail); } } } User delete = null; if (channel.containsUser(user)) { lock (channel.UserList) { foreach (User User in channel.UserList) { if (User.Nick == user) { delete = User; break; } } channel.UserList.Remove(delete); } return(true); } return(true); } return(false); }
public void RetrieveStatus(string nick, config.channel channel, string source) { lock (requests) { requests.Add(new ChannelRequest(nick, source, channel, false)); } }
/// <summary> /// Search /// </summary> /// <param name="key">Key</param> /// <param name="Chan"></param> public void RSearch(string key, config.channel Chan) { if (!key.StartsWith("@regsearch")) { return; } if (key.Length < 11) { Message("Could you please tell me what I should search for :P", Chan.name); return; } key = key.Substring(11); System.Text.RegularExpressions.Regex value = new System.Text.RegularExpressions.Regex(key); string results = ""; foreach (item data in text) { if (data.key == key || value.Match(data.text).Success) { results = results + data.key + ", "; } } if (results == "") { Message("No results found! :|", Chan.name); } else { Message("Results: " + results, Chan.name); } }
public void Find(string key, config.channel Chan) { if (!key.StartsWith("@search")) { return; } if (key.Length < 9) { Message("Could you please tell me what I should search for :P", Chan.name); return; } key = key.Substring(8); string results = ""; foreach (item data in text) { if (data.key == key || data.text.Contains(key)) { results = results + data.key + ", "; } } if (results == "") { Message("No results found! :|", Chan.name); } else { Message("Results: " + results, Chan.name); } }
/// <summary> /// Part a channel /// </summary> /// <param name="chan">Channel object</param> /// <param name="user">User</param> /// <param name="host">Host</param> /// <param name="message">Message</param> public static void partChannel(config.channel chan, string user, string host, string message) { if (message.StartsWith("@drop")) { if (chan.Users.isApproved(user, host, "admin")) { wd.WriteLine("PART " + chan.name); System.Threading.Thread.Sleep(100); System.IO.File.Delete(chan.Users.File); wd.Flush(); System.IO.File.Delete(chan.name + ".setting"); config.channels.Remove(chan); config.Save(); } else { Message("Permission denied", chan.name); } } if (message.StartsWith("@part")) { if (chan.Users.isApproved(user, host, "admin")) { wd.WriteLine("PART " + chan.name); System.Threading.Thread.Sleep(100); wd.Flush(); config.channels.Remove(chan); config.Save(); } else { Message("Permission denied", chan.name); } } }
private bool FinishChan(string[] code) { if (code.Length > 2) { if (code[3] == config.DebugChan && instance.Nick != core.irc.NickName) { return(true); } config.channel channel = core.getChannel(code[3]); if (channel != null) { Program.Log("Finished parsing for " + channel.Name + " parsed totaly: " + channel.UserList.Count.ToString()); if (config.SelectedVerbosity > 8) { string list = ""; lock (channel.UserList) { foreach (User u in channel.UserList) { list = list + u.Nick + ", "; } } core.DebugLog("Parsed: " + list, 8); } channel.FreshList = true; } } return(false); }
/// <summary> /// Called when someone post a message to server /// </summary> /// <param name="channel">Channel</param> /// <param name="nick">Nick</param> /// <param name="host">Host</param> /// <param name="message">Message</param> /// <returns></returns> public static bool getMessage(string channel, string nick, string host, string message) { LastText = nick + " chan: " + channel + " " + message; config.channel curr = getChannel(channel); if (curr != null) { bool ignore = false; if (curr.IgnoreUnknown) { if (!curr.Users.IsApproved(nick, host, "trust")) { ignore = true; } } if (!ignore) { if (message.StartsWith(config.CommandPrefix)) { ModifyRights(message, curr, nick, host); addChannel(curr, nick, host, message); partChannel(curr, nick, host, message); } ParseAdmin(curr, nick, host, message); } lock (Module.module) { foreach (Module _Module in Module.module) { try { if (_Module.working) { _Module.Hook_PRIV(curr, new User(nick, host, ""), message); } } catch (Exception f) { core.Log("MODULE: exception at Hook_PRIV in " + _Module.Name, true); core.handleException(f); } } } if (curr.respond_message) { if (message.StartsWith(config.NickName + ":")) { System.DateTime time = curr.last_msg; if (System.DateTime.Now >= time.AddSeconds(curr.respond_wait)) { irc._SlowQueue.DeliverMessage(messages.get("hi", curr.Language, new List <string> { nick }), curr.Name); curr.last_msg = System.DateTime.Now; } } } } return(false); }
public void RegEx2(string nick, config.channel channel, string source) { try { temp_nick = nick; temp_source = source; chan = channel; SearchThread = new Thread(Search); SearchThread.Start(); Working = true; int curr = 0; while (Working) { Thread.Sleep(10); curr++; if (curr > 80) { SearchThread.Abort(); core.irc._SlowQueue.DeliverMessage("This search took too much time, please optimize query", channel.Name); Working = false; break; } } } catch (Exception fail) { handleException(fail); } }
public override void Hook_PRIV(config.channel channel, User 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.instance.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); } core.irc._SlowQueue.DeliverMessage(response, channel); } } }
public ChannelRequest(string _nick, string _source, config.channel Channel, bool regexp) { rg = regexp; nick = _nick; channel = Channel; source = _source; }
public override void Hook_Channel(config.channel channel) { core.Log("Loading " + channel.Name); if (channel == null) { core.Log("NULL"); } if (Snapshots) { try { if (Directory.Exists(SnapshotsDirectory + Path.DirectorySeparatorChar + channel.Name) == false) { core.Log("Creating directory for infobot for " + channel.Name); Directory.CreateDirectory(SnapshotsDirectory + Path.DirectorySeparatorChar + channel.Name); } } catch (Exception fail) { core.handleException(fail); } } if (channel.RetrieveObject("Infobot") == null) { // sensitivity bool cs = Module.GetConfig(channel, "Infobot.Case", true); channel.RegisterObject(new infobot_core(getDB(ref channel), channel.Name, cs), "Infobot"); } }
public override void Hook_Channel(config.channel channel) { if (channel.RetrieveObject("Statistics") == null) { channel.RegisterObject(new Statistics(channel), NAME); } }
/// <summary> /// Called on action /// </summary> /// <param name="message">Message</param> /// <param name="Channel">Channel</param> /// <param name="host">Host</param> /// <param name="nick">Nick</param> /// <returns></returns> public static bool getAction(string message, string Channel, string host, string nick) { config.channel channel = getChannel(Channel); if (channel != null) { lock (Module.module) { foreach (Module curr in Module.module) { if (!curr.working) { continue; } try { curr.Hook_ACTN(channel, new User(nick, host, ""), message); } catch (Exception fail) { Program.Log("Exception on Hook_ACTN in module: " + curr.Name); core.handleException(fail); } } } } return(false); }
/// <summary> /// Deliver me /// </summary> /// <param name="Message">Text</param> /// <param name="Channel">Channel</param> /// <param name="Pr">Priority</param> public void DeliverAct(string Message, string Channel, priority Pr = priority.normal) { // first of all we check if we are in correct instance if (Channel.StartsWith("#")) { config.channel ch = core.getChannel(Channel); if (ch == null) { core.Log("Not sending message to unknown channel: " + Channel); return; } // this is wrong instance so let's put this message to correct one if (ch.instance != Parent.ParentInstance) { ch.instance.irc._SlowQueue.DeliverAct(Message, Channel, Pr); return; } } Message text = new Message { _Priority = Pr, message = Message, channel = Channel }; lock (messages) { messages.Add(text); } }
/// <summary> /// Delete user /// </summary> /// <param name="origin"></param> /// <param name="user">Regex</param> /// <returns></returns> public bool delUser(core.SystemUser origin, string user) { config.channel channel = core.getChannel(ChannelName); if (channel == null) { core.irc._SlowQueue.DeliverMessage("Error: unable to get pointer of current channel", ChannelName); return(false); } foreach (core.SystemUser u in Users) { if (u.name == user) { if (getLevel(u.level) > getLevel(origin.level)) { core.irc._SlowQueue.DeliverMessage(messages.get("Trust1", channel.Language), ChannelName); return(true); } if (u.name == origin.name) { core.irc._SlowQueue.DeliverMessage(messages.get("Trust2", channel.Language), ChannelName); return(true); } Users.Remove(u); Save(); core.irc._SlowQueue.DeliverMessage(messages.get("Trust3", channel.Language), ChannelName); return(true); } } core.irc._SlowQueue.DeliverMessage(messages.get("Trust4", channel.Language), ChannelName); return(true); }
public override void Hook_Channel(config.channel channel) { if (channel.RetrieveObject("rss") == null) { channel.RegisterObject(new Feed(channel), "rss"); } }
public override bool Hook_SetConfig(config.channel chan, User invoker, string config, string value) { switch (config) { case "recent-changes-template": if (value != "null") { Module.SetConfig(chan, "RC.Template", value); core.irc._SlowQueue.DeliverMessage(messages.get("configuresave", chan.Language, new List <string> { value, config }), chan); chan.SaveConfig(); return(true); } else { Module.SetConfig(chan, "RC.Template", ""); core.irc._SlowQueue.DeliverMessage(messages.get("configuresave", chan.Language, new List <string> { "null", config }), chan); chan.SaveConfig(); return(true); } } return(false); }
public override string Extension_DumpHtml(config.channel channel) { string HTML = ""; if (GetConfig(channel, "Rss.Enable", false)) { Feed list = (Feed)channel.RetrieveObject("rss"); if (list == null) { return(""); } if (GetConfig(channel, "Rss.Enable", false) != true) { return(HTML); } HTML += "<h4>Rss feed</h4><br>"; HTML += "\n<br>\n<h4>Rss</h4>\n<br>\n\n<table class=\"infobot\" width=100% border=1>"; HTML += "<tr><th>Name</th><th>URL</th><th>Text</th><th>Enabled</th></tr>"; lock (list.Content) { foreach (Feed.Item feed in list.Content) { HTML += "\n<tr><td>" + feed.name + "</td><td><a href=\"" + feed.URL + "\">" + feed.URL + "</a></td><td>" + feed.template + "</td><td>" + (!feed.disabled).ToString() + "</td></tr>"; } } HTML += "</table>\n"; } return(HTML); }
public override void Hook_ReloadConfig(config.channel chan) { if (chan.ExtensionObjects.ContainsKey("Infobot")) { chan.ExtensionObjects["Infobot"] = new infobot_core(getDB(ref chan), chan.Name); } }
public void RegEx(string nick, config.channel channel, string source) { lock (requests) { requests.Add(new ChannelRequest(nick, source, channel, true)); } }
public override void Hook_Nick(config.channel channel, User Target, string OldNick) { Notification result = Notification.RetrieveTarget(Target.Nick); while (result != null) { core.irc._SlowQueue.DeliverMessage(result.Source_Name + "! " + OldNick + " just changed nicknames to " + Target.Nick + " which you wanted to talk with, in " + channel.Name + ". This message was delivered to you because you asked me to notify you about this user's activity. For more information, see http://meta.wikimedia.org/wiki/WM-Bot", result.Source_Name, IRC.priority.low); lock (Notification.NotificationList) { Notification.NotificationList.Remove(result); } result = Notification.RetrieveTarget(Target.Nick); } result = Notification.RetrieveTarget(OldNick); while (result != null) { core.irc._SlowQueue.DeliverMessage(result.Source_Name + "! " + OldNick + " just changed a nickname to " + Target.Nick + " which you wanted to talk with, in " + channel.Name + ". This message was delivered to you because you asked me to notify you about this user's activity. For more information, see http://meta.wikimedia.org/wiki/WM-Bot", result.Source_Name, IRC.priority.low); lock (Notification.NotificationList) { Notification.NotificationList.Remove(result); } result = Notification.RetrieveTarget(OldNick); } if (Target.Nick.ToLower() != OldNick.ToLower()) { result = Notification.RetrieveSource(OldNick); while (result != null) { result.Source_Name = Target.Nick; result = Notification.RetrieveSource(OldNick); } } }
/// <summary> /// Join channel /// </summary> /// <param name="chan">Channel</param> /// <param name="user">User</param> /// <param name="host">Host</param> /// <param name="message">Message</param> public static void addChannel(config.channel chan, string user, string host, string message) { try { if (message.StartsWith(config.CommandPrefix + "add")) { if (chan.Users.IsApproved(user, host, "admin")) { while (!core.FinishedJoining) { core.Log("Postponing request to join because bot is still loading", true); Thread.Sleep(2000); } if (message.Contains(" ")) { string channel = message.Substring(message.IndexOf(" ") + 1); if (!validFile(channel) || (channel.Contains("#") == false)) { irc._SlowQueue.DeliverMessage(messages.get("InvalidName", chan.Language), chan.Name); return; } lock (config.channels) { foreach (config.channel cu in config.channels) { if (channel == cu.Name) { irc._SlowQueue.DeliverMessage(messages.get("ChannelIn", chan.Language), chan.Name); return; } } } bool existing = config.channel.channelExist(channel); config.channel xx = new config.channel(channel); lock (config.channels) { config.channels.Add(xx); } config.Save(); xx.instance.irc.SendData("JOIN " + channel); Thread.Sleep(100); config.channel Chan = getChannel(channel); if (!existing) { Chan.Users.addUser("admin", IRCTrust.normalize(user) + "!.*@" + IRCTrust.normalize(host)); } return; } irc.Message(messages.get("InvalidName", chan.Language), chan.Name); return; } irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", chan.Language), chan.Name); } } catch (Exception b) { handleException(b); } }
/// <summary> /// Join channel /// </summary> /// <param name="chan">Channel</param> /// <param name="user">User</param> /// <param name="host">Host</param> /// <param name="message">Message</param> public static void addChannel(config.channel chan, string user, string host, string message) { try { if (message.StartsWith(config.CommandPrefix + "add")) { if (chan.Users.IsApproved(user, host, "admin")) { while (!core.FinishedJoining) { core.Log("Postponing request to join because bot is still loading", true); Thread.Sleep(2000); } if (message.Contains(" ")) { string channel = message.Substring(message.IndexOf(" ") + 1); if (!validFile(channel) || (channel.Contains("#") == false)) { irc._SlowQueue.DeliverMessage(messages.get("InvalidName", chan.Language), chan); return; } lock (config.channels) { foreach (config.channel cu in config.channels) { if (channel == cu.Name) { irc._SlowQueue.DeliverMessage(messages.get("ChannelIn", chan.Language), chan); return; } } } bool existing = config.channel.channelExist(channel); config.channel xx = new config.channel(channel); lock (config.channels) { config.channels.Add(xx); } config.Save(); xx.instance.irc.SendData("JOIN " + channel); Thread.Sleep(100); config.channel Chan = getChannel(channel); if (!existing) { Chan.Users.addUser("admin", IRCTrust.normalize(user) + "!.*@" + IRCTrust.normalize(host)); } return; } chan.instance.irc.Message(messages.get("InvalidName", chan.Language), chan.Name); return; } irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", chan.Language), chan); } } catch (Exception b) { handleException(b); } }
public override void Hook_ChannelDrop(config.channel chan) { if (File.Exists(variables.config + Path.DirectorySeparatorChar + chan.Name + ".list")) { core.Log("RC: Removing db of " + chan.Name + " RC feed"); File.Delete(variables.config + Path.DirectorySeparatorChar + chan.Name + ".list"); } }
/// <summary> /// Send a message to channel /// </summary> /// <param name="message">Message</param> /// <param name="channel">Channel</param> /// <returns></returns> public static bool Message(string message, string channel) { config.channel curr = getChannel(channel); wd.WriteLine("PRIVMSG " + channel + " :" + message); chanLog(message, curr, config.username, ""); wd.Flush(); return(true); }
public override void Hook_PRIV(config.channel channel, User invoker, string message) { if (message == "@replag") { core.irc._SlowQueue.DeliverMessage("Replication lag is approximately " + GetReplag(), channel); return; } }
private bool ParseUser(string[] code) { if (code.Length > 8) { if (code[3] == config.DebugChan && instance.Nick != core.irc.NickName) { return(true); } config.channel channel = core.getChannel(code[3]); string ident = code[4]; string host = code[5]; string nick = code[7]; string server = code[6]; char mode = '\0'; if (code[8].Length > 0) { mode = code[8][code[8].Length - 1]; if (!core.irc.UChars.Contains(mode)) { mode = '\0'; } } if (channel != null) { if (!channel.containsUser(nick)) { User _user = null; if (mode != '\0') { _user = new User(mode.ToString() + nick, host, ident); } else { _user = new User(nick, host, ident); } lock (channel.UserList) { channel.UserList.Add(_user); } return(true); } lock (channel.UserList) { foreach (User u in channel.UserList) { if (u.Nick == nick) { u.Ident = ident; u.Host = host; break; } } } } } return(false); }
/// <summary> /// Constructor /// </summary> /// <param name="channel"></param> public HtmlDump(config.channel channel) { dumpname = config.DumpDir + "/" + channel.Name + ".htm"; if (!System.IO.Directory.Exists(config.DumpDir)) { core.Log("Creating a directory for dump"); System.IO.Directory.CreateDirectory(config.DumpDir); } Channel = channel; }
public override void Hook_PRIV(config.channel channel, User invoker, string message) { if (message == config.CommandPrefix + "ping") { Info i = new Info(); i.channel = channel; Thread thread = new Thread(Ping); thread.Start(i); } }
public RecentChanges(config.channel _channel) { channel = _channel; changed = false; Load(); lock (rc) { rc.Add(this); } }
public override void Load() { try { ch = core.getChannel(RequestLabs.RequestCh); if (ch == null) { Log("CRITICAL: the bot isn't in " + RequestLabs.RequestCh + " unloading requests", true); return; } RequestCache.Load(); notifications = new Thread(Run); notifications.Start(); Site wikitech = new Site("https://wikitech.wikimedia.org", "wmib", ""); while (true) { try { List<string> shell = new List<string>(); List<string> tooldata = new List<string>(); PageList requests = new PageList(wikitech); requests.FillAllFromCategory("Shell Access Requests"); foreach (Page page in requests) { string title = page.title.Replace("Shell Request/", ""); if (RequestCache.Contains(title)) { continue; } page.Load(); if (!Matches(page.text)) { RequestCache.Insert(title); lock (Shell) { // this one was already processed RequestLabs previous = Contains(title); if (previous != null) { Shell.Remove(previous); } } continue; } else { if (!shell.Contains(title)) { shell.Add(title); } lock (Shell) { if (Contains(title) == null) { Shell.Add(new RequestLabs(title)); } } } } requests = new PageList(wikitech); requests.FillAllFromCategory("Tools_Access_Requests"); foreach (Page page in requests) { string title = page.title.Replace("Nova Resource:Tools/Access Request/", ""); if (RequestCache.ContainsLabs(title)) { continue; } page.Load(); if (!(Matches(page.text))) { RequestCache.InsertLabs(title); lock (Tools) { // this one was already processed RequestLabs previous = ContainsLabs(title); if (previous != null) { Tools.Remove(previous); } } continue; } else { if (!tooldata.Contains(title)) { tooldata.Add(title); } lock (Tools) { if (ContainsLabs(title) == null) { Tools.Add(new RequestLabs(title)); } } } } Thread.Sleep(60000); } catch (ThreadAbortException) { notifications.Abort(); return; } catch (Exception fail) { handleException(fail); } } } catch (Exception fail) { handleException(fail); notifications.Abort(); } }
public Statistics(config.channel _channel) { data = new List<list>(); channel = _channel; Load(); }
/// <summary> /// Search /// </summary> /// <param name="key">Key</param> /// <param name="Chan"></param> public void RSearch(string key, config.channel Chan) { if (!key.StartsWith("@regsearch")) { return; } if (!misc.IsValidRegex(key)) { core.irc.Message(messages.get("Error1", Chan.Language), Chan.Name); return; } if (key.Length < 11) { core.irc.Message(messages.get("Search1", Chan.Language), Chan.Name); return; } config.channel data = isAllowed(Chan); bool Allowed = (data != null); if (!Allowed) { core.irc._SlowQueue.DeliverMessage(messages.get("db7", Chan.Language), Chan.Name); return; } infobot_core infobot = (infobot_core)data.RetrieveObject("Infobot"); if (infobot == null) { core.Log("Unable to perform regsearch because the Infobot doesn't exist in " + Chan.Name, true); return; } infobot.search_key = key.Substring(11); RegularModule.running = true; Reply = Chan; Th = new Thread(infobot.StartSearch); Th.Start(); int check = 1; while (RegularModule.running) { check++; Thread.Sleep(100); if (check > 8) { Th.Abort(); core.irc.Message(messages.get("Error2", Chan.Language), Chan.Name); RegularModule.running = false; return; } } }
public Feed(config.channel _owner) { DB = variables.config + "/" + _owner.Name + "_feed.xml"; owner = _owner; Load(); }
public override void Load() { try { ch = core.getChannel("#wikimedia-labs"); if (ch == null) { core.Log("CRITICAL: the bot isn't in #wikimedia-labs unloading requests"); return; } RequestCache.Load(); notifications = new Thread(Run); notifications.Start(); while (true) { try { List<string> list = new List<string>(); Site wikitech = new Site("https://wikitech.wikimedia.org", "wmib", ""); PageList requests = new PageList(wikitech); requests.FillAllFromCategory("Shell Access Requests"); foreach (Page page in requests) { string title = page.title.Replace("Shell Request/", ""); if (RequestCache.Contains(title)) { continue; } page.Load(); if (!(page.text.Contains("|Completed=No") || page.text.Contains("|Completed=false"))) { RequestCache.Insert(title); lock (DB) { // this one was already processed RequestLabs previous = Contains(title); if (previous != null) { DB.Remove(previous); } } continue; } else { if (!list.Contains(title)) { list.Add(title); } lock (DB) { if (Contains(title) == null) { DB.Add(new RequestLabs(title)); } } } // now we need to remove all processed requests that were in a list /*List<RequestLabs> tr = new List<RequestLabs>(); lock (DB) { foreach (RequestLabs x in DB) { if (!list.Contains(x.user)) { tr.Add(x); } } foreach (RequestLabs x in tr) { DB.Remove(x); } } */ } Thread.Sleep(60000); } catch (ThreadAbortException) { notifications.Abort(); return; } catch (Exception fail) { core.handleException(fail); } } } catch (Exception fail) { core.handleException(fail); notifications.Abort(); } }