public override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message) { if (message.StartsWith(Configuration.System.CommandPrefix + "translate ")) { message = message.Substring(11); List<string> parts = new List<string>(message.Split(' ')); if (parts.Count < 3) { IRC.DeliverMessage("Invalid number of parameters", channel); return; } string target = null; string source_language = parts[0]; string target_language = parts[1]; if (!IsValid(source_language) || !IsValid(target_language)) { IRC.DeliverMessage(invoker.Nick + ": invalid language!", channel); return; } string text = message.Substring(message.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(channel, source_language, target_language, target, text)); } }
public static void DeliverMessage(string text, string target, libirc.Defs.Priority priority = libirc.Defs.Priority.Normal) { // get a target instance if (target.StartsWith("#")) { // it's a channel Channel ch = Core.GetChannel(target); if (ch == null) { Syslog.Log("Not sending message to unknown channel: " + target); return; } if (!ch.PrimaryInstance.IsConnected) { Syslog.Log("Not sending message using disconnected instance: " + ch.PrimaryInstance.Nick + " target: " + target + " message: " + text); return; } if (!ch.Suppress) { Self(text, ch); ch.PrimaryInstance.Network.Message(text, target, priority); } } else { lock (Instance.TargetBuffer) { if (Instance.TargetBuffer.ContainsKey(target)) { Instance.TargetBuffer[target].Network.Message(text, target, priority); return; } } Instance.PrimaryInstance.Network.Message(text, target, priority); } }
public override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message) { if (message == "@replag") { IRC.DeliverMessage("Replication lag is approximately " + GetReplag(), channel); } }
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); } } }
/// <summary> /// Send a message to a given target /// </summary> /// <param name="text">Text of a message</param> /// <param name="target">Channel</param> /// <param name="priority">Priority</param> public static void DeliverMessage(string text, Channel target, libirc.Defs.Priority priority = libirc.Defs.Priority.Normal) { if (!target.Suppress) { Self(text, target); target.PrimaryInstance.Network.Message(text, target.Name, priority); } }
public override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message) { if (message == Configuration.System.CommandPrefix + "ping") { Info i = new Info {channel = channel}; Thread thrd = new Thread(Ping); thrd.Start(i); } }
public override void Hook_Kick(Channel channel, libirc.UserInfo source, string user) { Notification result = Notification.RetrieveTarget(user); while (result != null) { IRC.DeliverMessage(result.Source_Name + "! " + user + " just got kicked from " + 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); lock (Notification.NotificationList) { Notification.NotificationList.Remove(result); } result = Notification.RetrieveTarget(user); } }
public static void DeliverMessage(string text, libirc.UserInfo target, libirc.Defs.Priority priority = libirc.Defs.Priority.Normal) { // this is a private message lock (Instance.TargetBuffer) { if (Instance.TargetBuffer.ContainsKey(target.Nick)) { Instance.TargetBuffer[target.Nick].Network.Message(text, target.Nick, priority); return; } } Instance.PrimaryInstance.Network.Message(text, target.Nick, priority); }
public static void IrcKick(Channel Channel, libirc.UserInfo Source, string Target) { foreach (Module module in ExtensionHandler.ExtensionList) { if (!module.IsWorking) { continue; } try { module.Hook_Kick(Channel, Source, Target); } catch (Exception fail) { Syslog.Log("MODULE: exception at Hook_Kick in " + module.Name, true); Core.HandleException(fail, module.Name); } } }
public override void Hook_Nick(Channel channel, libirc.UserInfo Target, string OldNick) { Notification result = Notification.RetrieveTarget(Target.Nick); while (result != null) { IRC.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); lock (Notification.NotificationList) { Notification.NotificationList.Remove(result); } result = Notification.RetrieveTarget(Target.Nick); } result = Notification.RetrieveTarget(OldNick); while (result != null) { IRC.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); 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); } } }
public override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message) { Notification result = Notification.RetrieveTarget(invoker.Nick); while (result != null) { IRC.DeliverMessage(result.Source_Name + "! " + invoker.Nick + " just said something 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); lock (Notification.NotificationList) { Notification.NotificationList.Remove(result); } result = Notification.RetrieveTarget(invoker.Nick); } if (message.StartsWith(Configuration.System.CommandPrefix + "notify ")) { string parameter = message.Substring(message.IndexOf(" ") + 1).Trim(); if (parameter != "") { if (!isValid(parameter)) { IRC.DeliverMessage("I doubt that anyone could have such a nick '" + parameter + "'", channel); return; } if (Notification.Contains(parameter, invoker.Nick)) { IRC.DeliverMessage("You've already asked me to watch this user", channel); return; } foreach (Channel item in Configuration.ChannelList) { if (item.ContainsUser(parameter)) { IRC.DeliverMessage("This user is now online in " + item.Name + ". I'll let you know when they show some activity (talk, etc.)", channel); lock(Notification.NotificationList) { Notification.NotificationList.Add(new Notification(parameter, invoker.Nick, invoker.Host)); } return; } } lock (Notification.NotificationList) { Notification.NotificationList.Add(new Notification(parameter, invoker.Nick, invoker.Host)); } IRC.DeliverMessage("I'll let you know when I see " + parameter + " around here", channel); } } }
public override void Hook_Join(Channel channel, libirc.UserInfo user) { WriteStatus(user.Nick, user.Host, channel.Name, item.Action.Join); }
public override void Hook_Kick(Channel channel, libirc.UserInfo source, string user) { WriteStatus(user, "", channel.Name, item.Action.Kick); }
public bool IsKnown(libirc.UserInfo user) { return this.IsKnown(user.Nick, user.Host); }
public SystemUser GetUser(libirc.UserInfo user) { return GetUser(user.Nick + "!@" + user.Host); }
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; }
private void NotifyUser(string message, libirc.UserInfo invoker, libirc.Target target_) { string parameter = message.Substring(message.IndexOf(" ") + 1).Trim(); if (String.IsNullOrEmpty(parameter) != true) { string nick = parameter; string text = null; if (nick.Contains(" ")) { text = parameter.Substring(parameter.IndexOf(" ") + 1); nick = nick.Substring(0, nick.IndexOf(" ")); } if (nick.Contains("@")) { IRC.DeliverMessage("I doubt that anyone could have such a nick '" + nick + "'", target_.TargetName); return; } if (Notification.Contains(nick, invoker.Nick)) { IRC.DeliverMessage("You've already asked me to watch this user", target_.TargetName); return; } foreach (Channel item in Configuration.ChannelList) { if (item.ContainsUser(nick)) { IRC.DeliverMessage("This user is now online in " + item.Name + ". I'll let you know when they show some activity (talk, etc.)", target_.TargetName); lock (Notification.NotificationList) { Notification.NotificationList.Add(new Notification(nick, invoker.Nick, invoker.Host, text)); } return; } } lock (Notification.NotificationList) { Notification.NotificationList.Add(new Notification(nick, invoker.Nick, invoker.Host, text)); } if (text == null) IRC.DeliverMessage("I will let you know when I see " + nick + " around here", target_.TargetName); else IRC.DeliverMessage("I will let you know when I see " + nick + " and I will deliver that message to them", target_.TargetName); } }
public static void DeliverMessage(string text, string target, libirc.Defs.Priority priority = libirc.Defs.Priority.Normal) { dm(text, target, priority); }
/// <summary> /// Check if user is approved to do operation requested /// </summary> /// <param name="user"></param> /// <param name="command"></param> /// <returns></returns> public bool IsApproved(libirc.UserInfo user, string command) { return IsApproved(user.Nick, user.Host, command); }
public override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message) { if (message == Configuration.System.CommandPrefix + "relay-off") { if (channel.SystemUsers.IsApproved(invoker.Nick, invoker.Host, "admin")) { if (!GetConfig(channel, "NetCat.Enabled", false)) { IRC.DeliverMessage("Relay is already disabled", channel.Name); return; } SetConfig(channel, "NetCat.Enabled", false); channel.SaveConfig(); IRC.DeliverMessage("Relay was disabled", channel.Name); return; } if (!channel.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, libirc.Defs.Priority.Low); } return; } if (message == Configuration.System.CommandPrefix + "token-on") { if (channel.SystemUsers.IsApproved(invoker.Nick, invoker.Host, "admin")) { string token = GenerateToken(); SetConfig(channel, "NetCat.Token", true); SetConfig(channel, "NetCat.TokenData", token); channel.SaveConfig(); IRC.DeliverMessage("New token was generated for this channel, and it was sent to you in a private message", channel.Name); IRC.DeliverMessage("Token for " + channel.Name + " is: " + token, invoker.Nick); return; } if (!channel.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, libirc.Defs.Priority.Low); } return; } if (message == Configuration.System.CommandPrefix + "token-off") { if (channel.SystemUsers.IsApproved(invoker.Nick, invoker.Host, "admin")) { SetConfig(channel, "NetCat.Token", false); channel.SaveConfig(); IRC.DeliverMessage("This channel will no longer require a token in order to relay messages into it", channel.Name); return; } if (!channel.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, libirc.Defs.Priority.Low); } return; } if (message == Configuration.System.CommandPrefix + "token-remind") { if (channel.SystemUsers.IsApproved(invoker.Nick, invoker.Host, "admin")) { if (!GetConfig(channel, "NetCat.Token", false)) { IRC.DeliverMessage("This channel doesn't require a token", channel.Name); return; } string token = GetConfig(channel, "NetCat.TokenData", "<invalid>"); IRC.DeliverMessage("Token for " + channel.Name + " is: " + token, invoker.Nick); return; } if (!channel.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, libirc.Defs.Priority.Low); } return; } if (message == Configuration.System.CommandPrefix + "relay-on") { if (channel.SystemUsers.IsApproved(invoker.Nick, invoker.Host, "admin")) { if (GetConfig(channel, "NetCat.Enabled", false)) { IRC.DeliverMessage("Relay is already enabled", channel.Name); return; } SetConfig(channel, "NetCat.Enabled", true); channel.SaveConfig(); IRC.DeliverMessage("Relay was enabled", channel.Name); return; } if (!channel.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, libirc.Defs.Priority.Low); } } }
public override bool Hook_SetConfig(Channel chan, libirc.UserInfo invoker, string config, string value) { switch (config) { case "recent-changes-template": if (value != "null") { SetConfig(chan, "RC.Template", value); IRC.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, config }), chan); chan.SaveConfig(); return true; } SetConfig(chan, "RC.Template", ""); IRC.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { "null", config }), chan); chan.SaveConfig(); return true; } return false; }
public override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message) { if (message.StartsWith(Configuration.System.CommandPrefix + "RC-")) { if (channel.SystemUsers.IsApproved(invoker, "recentchanges-remove")) { if (GetConfig(channel, "RC.Enabled", false)) { string[] a = message.Split(' '); if (a.Length < 3) { IRC.DeliverMessage(messages.Localize("Feed8", channel.Language, new List<string> { invoker.Nick }), channel.Name); return; } string wiki = a[1]; string Page = a[2]; RecentChanges rc = (RecentChanges)channel.RetrieveObject("RC"); if (rc != null) { rc.RemovePage(wiki, Page); } return; } IRC.DeliverMessage(messages.Localize("Feed3", channel.Language), channel); return; } if (!channel.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "RC+ ")) { if (channel.SystemUsers.IsApproved(invoker, "recentchanges-add")) { if (GetConfig(channel, "RC.Enabled", false)) { string[] a = message.Split(' '); if (a.Length < 3) { IRC.DeliverMessage(messages.Localize("Feed4", channel.Language) + invoker.Nick + messages.Localize("Feed5", channel.Language), channel); return; } string wiki = a[1]; string Page = a[2]; if (wiki.Contains("_")) { IRC.DeliverMessage("Underscore in wiki name is not supported, new format is for example: en.wikipedia.org instead of en_wikipedia", channel); return; } RecentChanges rc = (RecentChanges)channel.RetrieveObject("RC"); if (rc != null) { rc.MonitorPage(wiki, Page); } return; } IRC.DeliverMessage(messages.Localize("Feed3", channel.Language), channel); return; } if (!channel.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel); } return; } }
public override void Hook_Quit(libirc.UserInfo user, string Message) { Notification result = Notification.RetrieveSource(user.Nick); while (result != null) { lock (Notification.NotificationList) { if (Notification.NotificationList.Contains(result)) { Notification.NotificationList.Remove(result); } } result = Notification.RetrieveSource(user.Nick); } }
public static bool IsGloballyApproved(libirc.UserInfo user, string permission) { SystemUser current = GetGlobalUser(user.Nick + "!@" + user.Host); if (current == null) return false; return IsGloballyApproved(current, permission); }
public override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message) { // security hardening string channel_name = channel.Name; if (string.IsNullOrEmpty(channel_name)) return; if (message.StartsWith(Configuration.System.CommandPrefix + "revoke ")) { if (channel.SystemUsers.IsApproved(invoker, "revoke")) { string name = message.Substring("@revoke ".Length); List<string> parameters = new List<string>(name.Split(' ')); if (parameters.Count != 2) { IRC.DeliverMessage("Invalid number of parameters", channel); return; } string role = channel_name + "." + parameters[0]; lock(Security.Roles) { if (!Security.Roles.ContainsKey(role)) { IRC.DeliverMessage("There is no role of that name", channel); return; } Security.Roles[role].Revoke(parameters[1]); } IRC.DeliverMessage("Successfuly revoked " + parameters[1] + " from " + role, channel); IsUpdated = true; return; } if (!channel.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "grant ")) { if (channel.SystemUsers.IsApproved(invoker, "grant")) { string name = message.Substring("@grant ".Length); List<string> parameters = new List<string>(name.Split(' ')); if (parameters.Count != 2) { IRC.DeliverMessage("Invalid number of parameters", channel); return; } switch (parameters[1]) { case "root": case "terminal": case "halt": IRC.DeliverMessage("This permission can't be granted to anyone, sorry", channel); return; } string role = channel_name + "." + parameters[0]; lock(Security.Roles) { if (!Security.Roles.ContainsKey(role)) { Security.Roles.Add(role, new Security.Role(1)); } Security.Roles[role].Grant(parameters[1]); } IsUpdated = true; IRC.DeliverMessage("Successfuly granted " + parameters[1] + " to " + role, channel); return; } if (!channel.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel); } return; } }
public static void DeliverAction(string text, string target, libirc.Defs.Priority priority = libirc.Defs.Priority.Normal) { dm(text, target, priority, true); }
/// <summary> /// Return a level of role that this user posses /// </summary> /// <param name="user"></param> /// <returns></returns> public int GetLevel(libirc.UserInfo user) { SystemUser current = GetUser(user.Nick + "!@" + user.Host); return GetLevelOfRole(current.Role); }
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 http://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; } return false; }
public override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message) { if (!message.StartsWith(Configuration.System.CommandPrefix) && GetConfig(channel, "Slap.Enabled", false)) { string ms = message.Trim(); ms = ms.Replace("!", ""); ms = ms.Replace("?", ""); ms = ms.ToLower(); if (ms.StartsWith("hi ")) ms = ms.Substring(3); if (ms.StartsWith("hi, ")) ms = ms.Substring(4); if (ms.StartsWith("hello ")) ms = ms.Substring(6); if (ms.StartsWith("hello, ")) ms = ms.Substring(7); if (ms.EndsWith(":ping") || ms.EndsWith(": ping")) { string target = message.Substring(0, message.IndexOf(":")); if (GetConfig(channel, "Slap.Ping." + target, false)) { IRC.DeliverMessage("Hi " + invoker.Nick + ", you just managed to say pointless nick: ping. Now please try again with some proper meaning of your request, something like nick: I need this and that. Or don't do that at all, it's very annoying. Thank you", channel); return; } } if (!channel.SystemUsers.IsKnown(invoker)) { if (ms == "i have a question" || ms == "can i ask a question" || ms == "is anyone willing to help" || ms == "can i ask" || ms == "i got a question" || ms == "can i have a question" || ms == "can someone help me" || ms == "i need help") { IRC.DeliverMessage("Hi " + invoker.Nick + ", just ask! There is no need to ask if you can ask", channel); return; } if (ms == "is anyone here" || ms == "is anybody here" || ms == "is anybody there" || ms == "is some one there" || ms == "is someone there" || ms == "is someone here" || ms == "anyone here" || ms == "someone here") { IRC.DeliverMessage("Hi " + invoker.Nick + ", I am here, if you need anything, please ask, otherwise no one is going to help you... Thank you", channel); return; } } } if (message == Configuration.System.CommandPrefix + "slap" || message == Configuration.System.CommandPrefix + "slap-on") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { SetConfig(channel, "Slap.Enabled", true); IRC.DeliverMessage("I will be slapping annoying people since now", channel); channel.SaveConfig(); return; } if (!channel.SuppressWarnings) IRC.DeliverMessage("Permission denied", channel); } if (message == Configuration.System.CommandPrefix + "noslap" || message == Configuration.System.CommandPrefix + "slap-off") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { SetConfig(channel, "Slap.Enabled", false); IRC.DeliverMessage("I will not be slapping people since now", channel); channel.SaveConfig(); return; } if (!channel.SuppressWarnings) IRC.DeliverMessage("Permission denied", channel); } if (message == Configuration.System.CommandPrefix + "nopingslap") { if (channel.SystemUsers.IsApproved(invoker, "trust")) { SetConfig(channel, "Slap.Ping." + invoker.Nick.ToLower(), false); IRC.DeliverMessage("I will not be slapping people who slap you now", channel); channel.SaveConfig(); return; } if (!channel.SuppressWarnings) IRC.DeliverMessage("Permission denied", channel); } if (message == Configuration.System.CommandPrefix + "pingslap") { if (channel.SystemUsers.IsApproved(invoker, "trust")) { SetConfig(channel, "Slap.Ping." + invoker.Nick.ToLower(), true); IRC.DeliverMessage("I will be slapping people who ping you now", channel); channel.SaveConfig(); return; } if (!channel.SuppressWarnings) IRC.DeliverMessage("Permission denied", channel); } }
public override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message) { Notification result = Notification.RetrieveTarget(invoker.Nick); while (result != null) { IRC.DeliverMessage(result.Source_Name + "! " + invoker.Nick + " just said something 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); this.Deliver(result); lock (Notification.NotificationList) { Notification.NotificationList.Remove(result); } result = Notification.RetrieveTarget(invoker.Nick); } }