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); }
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); } } }
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; } } }
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); }
public override void Hook_OnSelf(Channel channel, libirc.UserInfo self, string message, bool is_act = false) { if (channel == null || channel.PrimaryInstance == null) { return; } ChanLog(message, channel, channel.PrimaryInstance.Nick, "", !is_act); }
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); }
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); }
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) { if (message == Configuration.System.CommandPrefix + "ping") { Info i = new Info { channel = channel }; Thread thrd = new Thread(Ping); thrd.Start(i); } }
/// <summary> /// Send a message to a given target /// </summary> /// <param name="text">Message</param> /// <param name="target">User</param> /// <param name="priority">Priority</param> 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); }
private void ProcessInput(Channel channel, libirc.UserInfo invoker, string message) { string l_message = message.ToLower(); string ns_message = NoSpecials(message); if (this.AutoResponses.ContainsKey(ns_message)) { this.Respond(channel, invoker, this.AutoResponses[ns_message]); return; } bool start_with_question = false; foreach (string question in this.questionStarts) { if (ns_message.StartsWith(question, StringComparison.InvariantCulture)) { start_with_question = true; break; } } if (start_with_question || l_message.EndsWith("?", StringComparison.InvariantCulture)) { string question = ns_message; if (start_with_question) { foreach (string qs in this.questionStarts) { if (question.StartsWith(qs, StringComparison.InvariantCulture)) { question.Substring(qs.Length); break; } } } if (question.EndsWith("?", StringComparison.InvariantCulture)) { question = question.Substring(0, question.Length - 1); } if (this.processQuestion(channel, invoker, question)) { return; } } this.Respond(channel, invoker, "Sorry, but I don't know to respond to this. Please keep in mind I am just a stupid robot, I can't hold an intelligent conversation."); }
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 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); } }
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); this.Deliver(result); lock (Notification.NotificationList) { Notification.NotificationList.Remove(result); } result = Notification.RetrieveTarget(user); } }
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 override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message) { if (message == Configuration.System.CommandPrefix + "link") { if (GetConfig(channel, "Link.Last", "") == "") { IRC.DeliverMessage(messages.Localize("Linkie-E1", channel.Language), channel); return; } string xx = MakeTemplate(GetConfig(channel, "Link.Last", ""), GetConfig(channel, "Link.Default", "en"), false) + MakeLink(GetConfig(channel, "Link.Last", ""), GetConfig(channel, "Link.Default", "en"), true); if (xx != "") { IRC.DeliverMessage(xx, channel); return; } IRC.DeliverMessage(messages.Localize("Linkie-E2", channel.Language), channel); return; } if (message.StartsWith(Configuration.System.CommandPrefix + "link ", System.StringComparison.InvariantCulture)) { string link = message.Substring(6); string xx = MakeTemplate(link, GetConfig(channel, "Link.Default", "en"), false) + MakeLink(link, GetConfig(channel, "Link.Default", "en"), true); if (xx.Length > 0) { IRC.DeliverMessage(xx, channel); return; } IRC.DeliverMessage(messages.Localize("Linkie-E3", channel.Language), channel); return; } if (GetConfig(channel, "Link.Enable", false)) { string result = MakeTemplate(message, GetConfig(channel, "Link.Default", "en"), false) + MakeLink(message, GetConfig(channel, "Link.Default", "en"), true); if (result.Length > 0) { IRC.DeliverMessage(result, channel); return; } } if (ContainsLink(message)) { SetConfig(channel, "Link.Last", message); } }
public override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message) { ChanLog(message, channel, invoker.Nick, invoker.Host); if (message == Configuration.System.CommandPrefix + "logon") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (GetConfig(channel, "Logging.Enabled", false)) { IRC.DeliverMessage(messages.Localize("ChannelLogged", channel.Language), channel.Name); return; } IRC.DeliverMessage(messages.Localize("LoggingOn", channel.Language), channel.Name); SetConfig(channel, "Logging.Enabled", true); channel.SaveConfig(); UpdateConfig(channel); return; } if (!channel.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, libirc.Defs.Priority.Low); } return; } if (message == Configuration.System.CommandPrefix + "logoff") { if (channel.SystemUsers.IsApproved(invoker.Nick, invoker.Host, "admin")) { if (!GetConfig(channel, "Logging.Enabled", false)) { IRC.DeliverMessage(messages.Localize("LogsE1", channel.Language), channel.Name); return; } SetConfig(channel, "Logging.Enabled", false); channel.SaveConfig(); UpdateConfig(channel); IRC.DeliverMessage(messages.Localize("NotLogged", channel.Language), channel.Name); return; } if (!channel.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, libirc.Defs.Priority.Low); } } }
public override void Hook_PRIV(Channel channel, libirc.UserInfo invoker, string message) { if (!GetConfig(channel, "AI.Enabled", false)) { return; } // These are commands sent directly to bot if (!message.StartsWith(channel.PrimaryInstance.Nick + ": ", StringComparison.InvariantCulture)) { return; } message = message.Substring(channel.PrimaryInstance.Nick.Length + 2); this.ProcessInput(channel, invoker, message); }
public override void Hook_Join(Channel channel, libirc.UserInfo user) { if (GetConfig(channel, "Logging.Enabled", false)) { Item item = new Item(); item.channel = channel; item.act = false; item.host = user.Host; item.message = ""; item.time = DateTime.Now; item.type = 2; item.username = user.Nick; lock (DJ) { DJ.Add(item); } } }
public override void Hook_Kick(wmib.Channel channel, libirc.UserInfo source, string user) { if (GetConfig(channel, "Logging.Enabled", false)) { Item item = new Item(); item.channel = channel; item.act = false; item.host = source.Host; item.message = source.Nick; item.time = DateTime.Now; item.type = 4; item.username = user; lock (DJ) { DJ.Add(item); } } }
public override void Hook_Nick(Channel channel, libirc.UserInfo Target, string OldNick, string NewNick) { if (GetConfig(channel, "Logging.Enabled", false)) { Item item = new Item(); item.channel = channel; item.act = false; item.host = Target.Host; item.message = OldNick; item.time = DateTime.Now; item.type = 6; item.username = NewNick; lock (DJ) { DJ.Add(item); } } }
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_PRIV(Channel channel, libirc.UserInfo invoker, string message) { List <string> channels = new List <string> { "#huggle", "#wikidata", "#wikimedia", "#wikitech", "#wikipedia", "#wm-bot", "#wikibooks", "#mediawiki", "#wikinews", "#wikisource", "#wikiquote", "#wikivoyage", "#wiktionary", "#wikiversity" }; if (message.StartsWith("!ops")) { string ln = channel.Name.ToLower(); foreach (string channel_name in channels) { if (ln.StartsWith(channel_name)) { DebugLog(invoker.ToString() + " used !ops in " + channel.Name + " forwarding message to op bot"); IRC.DeliverMessage("OPS " + invoker.ToString() + " in " + channel.Name + ": " + message, "wmopbot"); return; } } } }
private bool processQuestion(Channel channel, libirc.UserInfo invoker, string question) { if (question.StartsWith(" ")) { question = question.Substring(1); } if (question.StartsWith("what is ")) { question = question.Substring("what is ".Length); } if (autoQuestionResponses.ContainsKey(question)) { this.Respond(channel, invoker, autoQuestionResponses[question]); return(true); } return(false); }
public override bool Hook_OnPrivateFromUser(string message, libirc.UserInfo user) { WriteStatus(user.Nick, user.Host, "<private message>", item.Action.Talk); if (message.StartsWith(Configuration.System.CommandPrefix + "seen ")) { string parameter = message.Substring(message.IndexOf(" ") + 1); if (parameter != "") { RetrieveStatus(parameter, null, user.Nick); return(true); } } if (message.StartsWith(Configuration.System.CommandPrefix + "seenrx ")) { IRC.DeliverMessage("Sorry but this command can be used in channels only (it's cpu expensive so it can be used on public by trusted users only)", user); return(true); } return(false); }
public override void Hook_Nick(Channel channel, libirc.UserInfo Target, string OldNick, string NewNick) { if (GetConfig(channel, "Logging.Enabled", false)) { Item item = new Item { channel = channel, act = false, host = Target.Host, message = OldNick, time = DateTime.Now, type = 6, username = NewNick }; lock (DJ) { DJ.Add(item); } } }
public override bool Hook_SetConfig(Channel chan, libirc.UserInfo invoker, string config, string value) { if (config == "default-link-wiki") { if (value != "") { SetConfig(chan, "Link.Default", value); chan.SaveConfig(); IRC.DeliverMessage(messages.Localize("configuresave", chan.Language, new List <string> { value, config }), chan.Name); return(true); } IRC.DeliverMessage(messages.Localize("configure-va", chan.Language, new List <string> { config, value }), chan.Name); return(true); } return(false); }
public override void Hook_Kick(wmib.Channel channel, libirc.UserInfo source, string user) { if (GetConfig(channel, "Logging.Enabled", false)) { Item item = new Item { channel = channel, act = false, host = source.Host, message = source.Nick, time = DateTime.Now, type = 4, username = user }; lock (DJ) { DJ.Add(item); } } }
public override void Hook_Join(Channel channel, libirc.UserInfo user) { if (GetConfig(channel, "Logging.Enabled", false)) { Item item = new Item { channel = channel, act = false, host = user.Host, message = "", time = DateTime.Now, type = 2, username = user.Nick }; lock (DJ) { DJ.Add(item); } } }
/// <summary> /// Display admin command /// </summary> /// <param name="chan">Channel</param> /// <param name="user">User name</param> /// <param name="host">Host</param> /// <param name="message">Message</param> public static void ParseAdmin(Channel chan, string user, string host, string message) { libirc.UserInfo invoker = new libirc.UserInfo(user, "", host); if (message == Configuration.System.CommandPrefix + "reload") { if (chan.SystemUsers.IsApproved(invoker, "admin")) { chan.LoadConfig(); SystemHooks.IrcReloadChannelConf(chan); IRC.DeliverMessage(messages.Localize("Config", chan.Language), chan); return; } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", chan.Language), chan); } return; } if (message == Configuration.System.CommandPrefix + "info") { IRC.DeliverMessage(Configuration.WebPages.WebpageURL + Configuration.Paths.DumpDir + "/" + HttpUtility.UrlEncode(chan.Name) + ".htm", chan); return; } if (message.StartsWith(Configuration.System.CommandPrefix + "part ")) { string channel = message.Substring(6); if (channel != "") { Channel _Channel = Core.GetChannel(channel); if (_Channel == null) { IRC.DeliverMessage(messages.Localize("UnknownChan", chan.Language), chan, libirc.Defs.Priority.Low); return; } PartChannel(_Channel, invoker.Nick, invoker.Host, Configuration.System.CommandPrefix + "part", chan.Name); return; } IRC.DeliverMessage(messages.Localize("Responses-PartFail", chan.Language), chan, libirc.Defs.Priority.Low); return; } if (message.StartsWith(Configuration.System.CommandPrefix + "drop ")) { string channel = message.Substring(6); if (channel != "") { Channel _Channel = Core.GetChannel(channel); if (_Channel == null) { IRC.DeliverMessage(messages.Localize("UnknownChan", chan.Language), chan, libirc.Defs.Priority.Low); return; } PartChannel(_Channel, invoker.Nick, invoker.Host, Configuration.System.CommandPrefix + "drop", chan.Name); return; } IRC.DeliverMessage(messages.Localize("Responses-PartFail", chan.Language), chan, libirc.Defs.Priority.Low); return; } if (message.StartsWith(Configuration.System.CommandPrefix + "language")) { if (chan.SystemUsers.IsApproved(invoker, "admin")) { string parameter = ""; if (message.Contains(" ")) { parameter = message.Substring(message.IndexOf(" ") + 1).ToLower(); } if (parameter != "") { if (messages.Exists(parameter)) { chan.Language = parameter; IRC.DeliverMessage(messages.Localize("Language", chan.Language), chan); chan.SaveConfig(); return; } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("InvalidCode", chan.Language), chan); } return; } IRC.DeliverMessage(messages.Localize("LanguageInfo", chan.Language), chan); return; } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", chan.Language), chan, libirc.Defs.Priority.Low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "help")) { string parameter = ""; if (message.Contains(" ")) { parameter = message.Substring(message.IndexOf(" ") + 1); } if (parameter != "") { Core.ShowHelp(parameter, chan); return; } IRC.DeliverMessage("I am running http://meta.wikimedia.org/wiki/WM-Bot version " + Configuration.System.Version + " my source code is licensed " + "under GPL and located at https://github.com/benapetr/wikimedia-bot " + "I will be very happy if you fix my bugs or implement new features", chan); return; } if (message == Configuration.System.CommandPrefix + "suppress-off") { if (chan.SystemUsers.IsApproved(invoker, "admin")) { if (!chan.Suppress) { IRC.DeliverMessage(messages.Localize("Silence1", chan.Language), chan); return; } chan.Suppress = false; IRC.DeliverMessage(messages.Localize("Silence2", chan.Language), chan); chan.SaveConfig(); Configuration.Save(); return; } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", chan.Language), chan, libirc.Defs.Priority.Low); } return; } if (message == Configuration.System.CommandPrefix + "suppress-on") { if (chan.SystemUsers.IsApproved(invoker, "admin")) { if (chan.Suppress) { //Message("Channel had already quiet mode disabled", chan.name); return; } IRC.DeliverMessage(messages.Localize("SilenceBegin", chan.Language), chan); chan.Suppress = true; chan.SaveConfig(); return; } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", chan.Language), chan, libirc.Defs.Priority.Low); } return; } if (message == Configuration.System.CommandPrefix + "whoami") { SystemUser current = chan.SystemUsers.GetUser(user + "!@" + host); if (current.Role == "null") { IRC.DeliverMessage(messages.Localize("Unknown", chan.Language), chan); return; } IRC.DeliverMessage(messages.Localize("usr1", chan.Language, new List<string> { current.Role, current.Name }), chan); return; } if (message.StartsWith(Configuration.System.CommandPrefix + "instance ")) { if (chan.SystemUsers.IsApproved(invoker, "root")) { message = message.Substring(".instance ".Length); if (!message.Contains(" ")) { IRC.DeliverMessage("This command need 2 parameters", chan); return; } string channel = message.Substring(message.IndexOf(" ") + 1); string instance = message.Substring(0, message.IndexOf(" ")); Channel ch = Core.GetChannel(channel); if (ch == null) { IRC.DeliverMessage("This channel I never heard of :'(", chan); return; } Instance _instance; lock (Instance.Instances) { if (!Instance.Instances.ContainsKey(instance)) { IRC.DeliverMessage("This instance I never heard of :'(", chan); return; } _instance = Instance.Instances[instance]; } if (_instance == ch.PrimaryInstance) { IRC.DeliverMessage("This channel is already in this instance", chan); return; } ch.PrimaryInstance.Network.Transfer("PART " + ch.Name + " :Switching instance"); ch.PrimaryInstance = _instance; ch.PrimaryInstance.Network.Transfer("JOIN " + ch.Name); ch.DefaultInstance = ch.PrimaryInstance.Nick; ch.SaveConfig(); IRC.DeliverMessage("Changed default instance of " + channel + " to " + instance, chan); return; } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", chan.Language), chan, libirc.Defs.Priority.Low); } } if (message == Configuration.System.CommandPrefix + "traffic-off") { if (chan.SystemUsers.IsApproved(invoker, "root")) { Configuration.Network.Logging = false; IRC.DeliverMessage("Logging stopped", chan); return; } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", chan.Language), chan, libirc.Defs.Priority.Low); } } if (message == Configuration.System.CommandPrefix + "traffic-on") { if (chan.SystemUsers.IsApproved(invoker, "root")) { Configuration.Network.Logging = true; IRC.DeliverMessage("Logging traf", chan.Name); return; } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", chan.Language), chan, libirc.Defs.Priority.Low); } } if (message == Configuration.System.CommandPrefix + "restart") { if (chan.SystemUsers.IsApproved(invoker, "root")) { IRC.DeliverMessage("System is shutting down, requested by " + invoker.Nick + " from " + chan.Name, Configuration.System.DebugChan, libirc.Defs.Priority.High); Syslog.Log("System is shutting down, requested by " + invoker.Nick + " from " + chan.Name); Core.Kill(); return; } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", chan.Language), chan.Name, libirc.Defs.Priority.Low); } } if (message == Configuration.System.CommandPrefix + "channellist") { IRC.DeliverMessage(messages.Localize("Responses-List", chan.Language, new List<string> { Configuration.Channels.Count.ToString() }), chan); return; } if (message.StartsWith(Configuration.System.CommandPrefix + "configure ")) { if (chan.SystemUsers.IsApproved(invoker, "admin")) { string text = message.Substring("@configure ".Length); if (string.IsNullOrEmpty(text)) { return; } if (text.Contains("=") && !text.EndsWith("=")) { string name = text.Substring(0, text.IndexOf("=")); string value = text.Substring(text.IndexOf("=") + 1); bool _temp_a; switch (name) { case "ignore-unknown": if (bool.TryParse(value, out _temp_a)) { chan.IgnoreUnknown = _temp_a; IRC.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, name }), chan); chan.SaveConfig(); return; } IRC.DeliverMessage(messages.Localize("configure-va", chan.Language, new List<string> { name, value }), chan); return; case "respond-wait": int _temp_b; if (int.TryParse(value, out _temp_b)) { if (_temp_b > 1 && _temp_b < 364000) { chan.RespondWait = _temp_b; IRC.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, name }), chan); chan.SaveConfig(); return; } } IRC.DeliverMessage(messages.Localize("configure-va", chan.Language, new List<string> { name, value }), chan); return; case "respond-message": if (bool.TryParse(value, out _temp_a)) { chan.RespondMessage = _temp_a; IRC.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, name }), chan); chan.SaveConfig(); return; } IRC.DeliverMessage(messages.Localize("configure-va", chan.Language, new List<string> { name, value }), chan); return; case "suppress-warnings": if (bool.TryParse(value, out _temp_a)) { chan.SuppressWarnings = _temp_a; IRC.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, name }), chan); chan.SaveConfig(); return; } IRC.DeliverMessage(messages.Localize("configure-va", chan.Language, new List<string> { name, value }), chan); return; } bool exist = false; lock (ExtensionHandler.Extensions) { foreach (Module curr in ExtensionHandler.Extensions) { try { if (curr.IsWorking) { if (curr.Hook_SetConfig(chan, invoker, name, value)) { exist = true; } } } catch (Exception fail) { Syslog.Log("Error on Hook_SetConfig module " + curr.Name); Core.HandleException(fail, curr.Name); } } } if (!chan.SuppressWarnings && !exist) { IRC.DeliverMessage(messages.Localize("configure-wrong", chan.Language), chan); } return; } if (!text.Contains(" ")) { switch (text) { case "ignore-unknown": IRC.DeliverMessage(messages.Localize("Responses-Conf", chan.Language, new List<string> { text, chan.IgnoreUnknown.ToString() } ), chan); return; case "respond-message": IRC.DeliverMessage(messages.Localize("Responses-Conf", chan.Language, new List<string> { text, chan.RespondMessage.ToString() }), chan); return; case "suppress-warnings": IRC.DeliverMessage(messages.Localize("Responses-Conf", chan.Language, new List<string> { text, chan.SuppressWarnings.ToString() } ), chan); return; } bool exist = false; lock (ExtensionHandler.Extensions) { foreach (Module curr in ExtensionHandler.Extensions) { try { if (curr.IsWorking) { if (curr.Hook_GetConfig(chan, invoker, text)) { exist = true; } } } catch (Exception fail) { Syslog.Log("Error on Hook_GetConfig module " + curr.Name); Core.HandleException(fail); } } } if (exist) { return; } } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("configure-wrong", chan.Language), chan); } return; } if (!chan.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("PermissionDenied", chan.Language), chan, libirc.Defs.Priority.Low); } return; } #if FALSE if (message.StartsWith(Configuration.System.CommandPrefix + "system-lm ")) { if (chan.SystemUsers.IsApproved(invoker, "root")) { string module = message.Substring("@system-lm ".Length); if (module.EndsWith(".bin")) { Module _m = ExtensionHandler.RetrieveModule(module); if (_m != null) { Core.irc.Queue.DeliverMessage("This module was already loaded and you can't load one module twice," +" module will be reloaded now", chan, IRC.priority.high); _m.Exit(); } if (module.EndsWith(".bin")) { module = "modules" + Path.DirectorySeparatorChar + module; if (File.Exists(module)) { if (ExtensionHandler.LoadAllModulesInLibrary(module)) { Core.irc.Queue.DeliverMessage("Loaded module " + module, chan, IRC.priority.high); return; } Core.irc.Queue.DeliverMessage("Unable to load module " + module, chan, IRC.priority.high); return; } Core.irc.Queue.DeliverMessage("File not found " + module, chan, IRC.priority.high); return; } Core.irc.Queue.DeliverMessage("Loaded module " + module, chan, IRC.priority.high); return; } Core.irc.Queue.DeliverMessage("This module is not currently loaded in core", chan, IRC.priority.high); return; } } #endif if (message == Configuration.System.CommandPrefix + "verbosity--") { if (chan.SystemUsers.IsApproved(invoker, "root")) { if (Configuration.System.SelectedVerbosity > 0) { Configuration.System.SelectedVerbosity--; } IRC.DeliverMessage("Verbosity: " + Configuration.System.SelectedVerbosity, chan, libirc.Defs.Priority.High); } } if (message == Configuration.System.CommandPrefix + "verbosity++") { if (chan.SystemUsers.IsApproved(invoker, "root")) { Configuration.System.SelectedVerbosity++; IRC.DeliverMessage("Verbosity: " + Configuration.System.SelectedVerbosity, chan, libirc.Defs.Priority.High); } } if (message.StartsWith(Configuration.System.CommandPrefix + "system-rm ")) { if (chan.SystemUsers.IsApproved(invoker, "root")) { string module = message.Substring("@system-lm ".Length); Module _m = ExtensionHandler.RetrieveModule(module); if (_m == null) { IRC.DeliverMessage("This module is not currently loaded in core", chan, libirc.Defs.Priority.High); return; } _m.Exit(); IRC.DeliverMessage("Unloaded module " + module, chan, libirc.Defs.Priority.High); } } if (message == Configuration.System.CommandPrefix + "commands") { IRC.DeliverMessage("Commands: there is too many commands to display on one line," + " see http://meta.wikimedia.org/wiki/wm-bot for a list of" + " commands and help", chan); } }
/// <summary> /// Change rights of user /// </summary> /// <param name="message">Message</param> /// <param name="channel">Channel</param> /// <param name="user">User</param> /// <param name="host">Host</param> /// <returns></returns> public static int ModifyRights(string message, Channel channel, string user, string host) { try { libirc.UserInfo invoker = new libirc.UserInfo(user, "", host); if (message.StartsWith(Configuration.System.CommandPrefix + "trustadd")) { string[] rights_info = message.Split(' '); if (channel.SystemUsers.IsApproved(invoker, "trustadd")) { if (rights_info.Length < 3) { IRC.DeliverMessage(messages.Localize("Trust1", channel.Language), channel); return 0; } if (!Security.Roles.ContainsKey(rights_info[2])) { IRC.DeliverMessage(messages.Localize("Unknown1", channel.Language), channel); return 2; } int level = Security.GetLevelOfRole(rights_info[2]); // This optional hack disallow to grant roles like "root" to anyone so that this role can be granted only to users // with shell access to server and hard-inserting it to admins file. If you wanted to allow granting of root, just // change System.MaxGrantableRoleLevel to 65535, this isn't very secure though if (level > Configuration.System.MaxGrantableRoleLevel) { IRC.DeliverMessage("You can't grant this role because it's over the maximum grantable role level, sorry", channel); return 2; } // now we check if role that user is to grant doesn't have higher level than the role they have // if we didn't do that, users with low roles could grant admin to someone and exploit this // to grant admins to themselve if (level > channel.SystemUsers.GetLevel(invoker)) { IRC.DeliverMessage(messages.Localize("RoleMismatch", channel.Language), channel); return 2; } if (channel.SystemUsers.AddUser(rights_info[2], rights_info[1])) { IRC.DeliverMessage(messages.Localize("UserSc", channel.Language) + rights_info[1], channel); return 0; } } else { IRC.DeliverMessage(messages.Localize("Authorization", channel.Language), channel); return 0; } } if (message.StartsWith(Configuration.System.CommandPrefix + "trusted")) { IRC.DeliverMessage(messages.Localize("TrustedUserList", channel.Language) + channel.SystemUsers.ListAll(), channel); return 0; } if (message.StartsWith(Configuration.System.CommandPrefix + "trustdel")) { string[] rights_info = message.Split(' '); if (rights_info.Length > 1) { if (channel.SystemUsers.IsApproved(user, host, "trustdel")) { channel.SystemUsers.DeleteUser(channel.SystemUsers.GetUser(user + "!@" + host), rights_info[1]); return 0; } IRC.DeliverMessage(messages.Localize("Authorization", channel.Language), channel); return 0; } IRC.DeliverMessage(messages.Localize("InvalidUser", channel.Language), channel); } } catch (Exception b) { Core.HandleException(b); } return 0; }