public override void Hook_Nick(Channel channel, User Target, string OldNick) { Notification result = Notification.RetrieveTarget(Target.Nick); while (result != null) { Core.irc.Queue.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.Queue.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); } } }
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, 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.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); } Core.irc.Queue.DeliverMessage(response, channel); } } }
public override void Hook_Channel(Channel channel) { if (channel.RetrieveObject("rss") == null) { channel.RegisterObject(new Feed(channel), "rss"); } }
/// <summary> /// Join channel /// </summary> /// <param name="channel">Channel</param> /// <param name="user">User</param> /// <param name="host">Host</param> /// <param name="message">Message</param> public static void AddChannel(Channel channel, string user, string host, string message) { try { if (message.StartsWith(Configuration.System.CommandPrefix + "add ") || message.StartsWith(Configuration.System.CommandPrefix + "join ")) { if (channel.SystemUsers.IsApproved(user, host, "admin")) { while (!Core.FinishedJoining) { Syslog.Log("Postponing request to join because bot is still loading", true); Thread.Sleep(2000); } if (message.Contains(" ")) { string _channel = message.Substring(message.IndexOf(" ") + 1).Trim(); if (!Core.ValidFile(_channel) || !_channel.StartsWith("#")) { Core.irc.Queue.DeliverMessage(messages.Localize("InvalidName", channel.Language), channel); return; } lock (Configuration.Channels) { foreach (Channel cu in Configuration.Channels) { if (_channel == cu.Name) { Core.irc.Queue.DeliverMessage(messages.Localize("ChannelIn", channel.Language), channel); return; } } } bool existing = Channel.ConfigExists(_channel); Channel xx = new Channel(_channel); lock (Configuration.Channels) { Configuration.Channels.Add(xx); } Configuration.Save(); xx.PrimaryInstance.irc.SendData("JOIN " + _channel); Thread.Sleep(100); Channel Chan = Core.GetChannel(_channel); if (!existing) { Chan.SystemUsers.AddUser("admin", Security.EscapeUser(user) + "!.*@" + Security.EscapeUser(host)); } return; } channel.PrimaryInstance.irc.Message(messages.Localize("InvalidName", channel.Language), channel); return; } Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel); } } catch (Exception b) { Core.HandleException(b); } }
public override string Extension_DumpHtml(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_Channel(Channel channel) { if (channel.RetrieveObject("Statistics") == null) { channel.RegisterObject(new Statistics(channel), NAME); } }
/// <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); } }
/// <summary> /// Log file /// </summary> /// <param name="message">Message</param> /// <param name="channel">Channel</param> /// <param name="user">User</param> /// <param name="host">Host</param> /// <param name="noac">Action (if true it's logged as message, if false it's action)</param> public void ChanLog(string message, Channel channel, string user, string host, bool noac = true) { try { DateTime time = DateTime.Now; if (Module.GetConfig(channel, "Logging.Enabled", false)) { string log; //string URL = Core.Host.Host2Name(host); //updateBold(ref messagehtml); if (!noac) { log = "[" + TDToString(time.Hour) + ":" + TDToString(time.Minute) + ":" + TDToString(time.Second) + "] * " + user + " " + message + "\n"; } else { log = "[" + TDToString(time.Hour) + ":" + TDToString(time.Minute) + ":" + TDToString(time.Second) + "] " + "<" + user + ">\t " + message + "\n"; } Job line = new Job(); line.channel = channel; line.time = time; line.message = log; lock (jobs) { jobs.Add(line); } if (Core.DatabaseServerIsAvailable) { Item item = new Item(); item.channel = channel; item.time = time; item.username = user; item.act = !noac; item.host = host; item.type = 0; item.message = message; lock (DJ) { DJ.Add(item); } } } } catch (Exception er) { // nothing HandleException(er); } }
/// <summary> /// Constructor /// </summary> /// <param name="database"></param> /// <param name="channel"></param> public Infobot(string database, Channel channel, Module module, bool sensitive = true) { Sensitive = sensitive; datafile_xml = database + ".xml"; datafile_raw = database; pChannel = channel; Parent = module; prefix = Module.GetConfig(pChannel, "Infobot.Prefix", DefaultPrefix); LoadData(); }
/// <summary> /// Constructor /// </summary> /// <param name="channel"></param> public HtmlDump(Channel channel) { dumpname = Configuration.Paths.DumpDir + "/" + channel.Name + ".htm"; if (!System.IO.Directory.Exists(Configuration.Paths.DumpDir)) { Syslog.Log("Creating a directory for dump"); System.IO.Directory.CreateDirectory(Configuration.Paths.DumpDir); } _Channel = channel; }
public override void Hook_PRIV(Channel channel, User invoker, string message) { if (message == Configuration.System.CommandPrefix + "ping") { Info i = new Info(); i.channel = channel; Thread thread = new Thread(Ping); thread.Start(i); } }
public override string Extension_DumpHtml(Channel channel) { string HTML = ""; if (Module.GetConfig(channel, "Statistics.Enabled", false)) { Statistics list = (Statistics)channel.RetrieveObject(NAME); if (list != null) { HTML += "\n<br>\n<h4>Most active users :)</h4>\n<br>\n\n<table class=\"infobot\" width=100% border=1>"; HTML += "<tr><td>N.</td><th>Nick</th><th>Messages (average / day)</th><th>Number of posted messages</th><th>Active since</th></tr>"; int id = 0; int totalms = 0; DateTime startime = DateTime.Now; lock (list.data) { list.data.Sort(); list.data.Reverse(); foreach (Statistics.list user in list.data) { id++; totalms += user.messages; if (id > 100) { continue; } if (startime > user.logging_since) { startime = user.logging_since; } System.TimeSpan uptime = System.DateTime.Now - user.logging_since; float average = user.messages; average = ((float)user.messages / (float)(uptime.Days + 1)); if (user.URL != "") { HTML += "<tr><td>" + id.ToString() + ".</td><td><a target=\"_blank\" href=\"" + user.URL + "\">" + user.user + "</a></td><td>" + average.ToString() + "</td><td>" + user.messages.ToString() + "</td><td>" + user.logging_since.ToString() + "</td></tr>"; } else { HTML += "<tr><td>" + id.ToString() + ".</td><td>" + user.user + "</td><td>" + average.ToString() + "</td><td>" + user.messages.ToString() + "</td><td>" + user.logging_since.ToString() + "</td></tr>"; } HTML += " \n"; } } System.TimeSpan uptime_total = System.DateTime.Now - startime; float average2 = totalms; average2 = (float)totalms / (1 + uptime_total.Days); HTML += "<tr><td>N/A</td><th>Total:</th><th>" + average2.ToString() + "</th><th>" + totalms.ToString() + "</th><td>N/A</td></tr>"; HTML += " \n"; HTML += "</table>"; } } return HTML; }
public override void Hook_Kick(Channel channel, User source, User user) { Notification result = Notification.RetrieveTarget(user.Nick); while (result != null) { Core.irc.Queue.DeliverMessage(result.Source_Name + "! " + user.Nick + " 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, IRC.priority.low); lock (Notification.NotificationList) { Notification.NotificationList.Remove(result); } result = Notification.RetrieveTarget(user.Nick); } }
public static bool Linkable(Channel host, Channel guest) { if (host == null) { return false; } if (guest == null) { return false; } if (host.SharedLinkedChan.Contains(guest)) { return true; } return false; }
public static void IrcReloadChannelConf(Channel Channel) { foreach (Module module in ExtensionHandler.ExtensionList) { try { if (module.IsWorking) { module.Hook_ReloadConfig(Channel); } } catch (Exception fail) { Syslog.Log("MODULE: exception at Hook_Reload in " + module.Name); Core.HandleException(fail, module.Name); } } }
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 void GetOp(Channel chan) { if (!GetConfig(chan, "OP.Permanent", false)) { chan.PrimaryInstance.irc.Queue.Send("CS op " + chan.Name, IRC.priority.high); return; } // get our user User user = chan.RetrieveUser(chan.PrimaryInstance.Nick); if (user == null) { chan.PrimaryInstance.irc.Queue.Send("CS op " + chan.Name, IRC.priority.high); return; } if (!user.IsOperator) { chan.PrimaryInstance.irc.Queue.Send("CS op " + chan.Name, IRC.priority.high); } }
public override string Extension_DumpHtml(Channel channel) { string HTML = ""; Infobot info = (Infobot)channel.RetrieveObject("Infobot"); if (info != null) { HTML += "\n<table border=1 class=\"infobot\" width=100%>\n<tr><th width=10%>Key</th><th>Value</th></tr>\n"; List<Infobot.InfobotKey> list = new List<Infobot.InfobotKey>(); lock (info) { if (Module.GetConfig(channel, "Infobot.Sorted", false) != false) { list = info.SortedItem(); } else { list.AddRange(info.Keys); } } if (info.Keys.Count > 0) { foreach (Infobot.InfobotKey Key in list) { HTML += Core.HTML.AddKey(Key.Key, Key.Text); } } HTML += "</table>\n"; HTML += "<h4>Aliases</h4>\n<table class=\"infobot\" border=1 width=100%>\n"; lock (info) { foreach (Infobot.InfobotAlias data in info.Alias) { HTML += Core.HTML.AddLink(data.Name, data.Key); } } HTML += "</table><br>\n"; } return HTML; }
public override void Hook_Channel(Channel channel) { Syslog.Log("Loading " + channel.Name); if (channel == null) { Syslog.Log("NULL"); } if (Snapshots) { try { if (Directory.Exists(SnapshotsDirectory + Path.DirectorySeparatorChar + channel.Name) == false) { Syslog.Log("Creating directory for infobot for " + channel.Name); Directory.CreateDirectory(SnapshotsDirectory + Path.DirectorySeparatorChar + channel.Name); } } catch (Exception fail) { Core.HandleException(fail, "infobot"); } } if (channel.RetrieveObject("Infobot") == null) { // sensitivity bool cs = Module.GetConfig(channel, "Infobot.Case", true); channel.RegisterObject(new Infobot(getDB(ref channel), channel, this, cs), "Infobot"); } }
public string getDB(ref Channel chan) { return Module.GetConfig(chan, "Infobot.Keydb", (string)Variables.ConfigurationDirectory + Path.DirectorySeparatorChar + chan.Name + ".db"); }
public override bool Hook_SetConfig(Channel chan, User invoker, string config, string value) { bool _temp_a; switch (config) { case "infobot-trim-white-space-in-name": if (bool.TryParse(value, out _temp_a)) { Module.SetConfig(chan, "Infobot.Trim-white-space-in-name", _temp_a); Core.irc.Queue.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, config }), chan.Name); chan.SaveConfig(); return true; } Core.irc.Queue.DeliverMessage(messages.Localize("configure-va", chan.Language, new List<string> { config, value }), chan.Name); return true; case "infobot-auto-complete": if (bool.TryParse(value, out _temp_a)) { Module.SetConfig(chan, "Infobot.auto-complete", _temp_a); Core.irc.Queue.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, config }), chan.Name); chan.SaveConfig(); return true; } Core.irc.Queue.DeliverMessage(messages.Localize("configure-va", chan.Language, new List<string> { config, value }), chan.Name); return true; case "infobot-sorted": if (bool.TryParse(value, out _temp_a)) { Module.SetConfig(chan, "Infobot.Sorted", _temp_a); Core.irc.Queue.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, config }), chan.Name); chan.SaveConfig(); return true; } Core.irc.Queue.DeliverMessage(messages.Localize("configure-va", chan.Language, new List<string> { config, value }), chan.Name); return true; case "infobot-help": if (bool.TryParse(value, out _temp_a)) { Module.SetConfig(chan, "Infobot.Help", _temp_a); Core.irc.Queue.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, config }), chan.Name); chan.SaveConfig(); return true; } Core.irc.Queue.DeliverMessage(messages.Localize("configure-va", chan.Language, new List<string> { config, value }), chan.Name); return true; case "infobot-case": if (bool.TryParse(value, out _temp_a)) { Module.SetConfig(chan, "Infobot.Case", _temp_a); Core.irc.Queue.DeliverMessage(messages.Localize("configuresave", chan.Language, new List<string> { value, config }), chan.Name); chan.SaveConfig(); Infobot infobot = (Infobot)chan.RetrieveObject("Infobot"); if (infobot != null) { infobot.Sensitive = _temp_a; } return true; } Core.irc.Queue.DeliverMessage(messages.Localize("configure-va", chan.Language, new List<string> { config, value }), chan.Name); return true; } return false; }
public override void Hook_ReloadConfig(Channel chan) { if (chan.ExtensionObjects.ContainsKey("Infobot")) { chan.ExtensionObjects["Infobot"] = new Infobot(getDB(ref chan), chan, this); } }
public override void Hook_PRIV(Channel channel, User invoker, string message) { // "\uff01" is the full-width version of "!". if ((message.StartsWith("!") || message.StartsWith("\uff01")) && GetConfig(channel, "Infobot.Enabled", true)) { while (Unwritable) { Thread.Sleep(10); } Unwritable = true; Infobot.InfoItem item = new Infobot.InfoItem(); item._Channel = channel; item.Name = "!" + message.Substring(1); // Normalizing "!". item.User = invoker.Nick; item.Host = invoker.Host; jobs.Add(item); Unwritable = false; } Infobot infobot = null; if (message.StartsWith(Configuration.System.CommandPrefix)) { infobot = (Infobot)channel.RetrieveObject("Infobot"); if (infobot == null) { Syslog.Log("Object Infobot in " + channel.Name + " doesn't exist", true); } if (GetConfig(channel, "Infobot.Enabled", true)) { if (infobot != null) { infobot.Find(message, channel); infobot.RSearch(message, channel); } } } if (Snapshots) { if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-recovery ")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { string name = message.Substring("@infobot-recovery ".Length); if (!GetConfig(channel, "Infobot.Enabled", true)) { Core.irc.Queue.DeliverMessage("Infobot is not enabled in this channel", channel, IRC.priority.low); return; } if (infobot != null) { infobot.RecoverSnapshot(channel, name); } return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-snapshot ")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { string name = message.Substring("@infobot-snapshot ".Length); if (!GetConfig(channel, "Infobot.Enabled", true)) { Core.irc.Queue.DeliverMessage("Infobot is not enabled in this channel", channel, IRC.priority.low); return; } if (infobot != null) { infobot.CreateSnapshot(channel, name); } return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-set-raw ")) { if (channel.SystemUsers.IsApproved(invoker, "trust")) { string name = message.Substring("@infobot-set-raw ".Length); if (!GetConfig(channel, "Infobot.Enabled", true)) { Core.irc.Queue.DeliverMessage("Infobot is not enabled in this channel", channel, IRC.priority.low); return; } if (infobot != null) { infobot.SetRaw(name, invoker.Nick, channel); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-unset-raw ")) { if (channel.SystemUsers.IsApproved(invoker, "trust")) { string name = message.Substring("@infobot-unset-raw ".Length); if (!GetConfig(channel, "Infobot.Enabled", true)) { Core.irc.Queue.DeliverMessage("Infobot is not enabled in this channel", channel, IRC.priority.low); return; } if (infobot != null) { infobot.UnsetRaw(name, invoker.Nick, channel); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-snapshot-rm ")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { string name = message.Substring("@infobot-snapshot-rm ".Length); name.Replace(".", ""); name.Replace("/", ""); name.Replace("\\", ""); name.Replace("*", ""); name.Replace("?", ""); if (name == "") { Core.irc.Queue.DeliverMessage("You should specify a file name", channel, IRC.priority.normal); return; } if (!File.Exists(SnapshotsDirectory + Path.DirectorySeparatorChar + channel.Name + Path.DirectorySeparatorChar + name)) { Core.irc.Queue.DeliverMessage("File not found", channel, IRC.priority.normal); return; } File.Delete(SnapshotsDirectory + Path.DirectorySeparatorChar + channel.Name + Path.DirectorySeparatorChar + name); Core.irc.Queue.DeliverMessage("Requested file was removed", channel, IRC.priority.normal); return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message == Configuration.System.CommandPrefix + "infobot-snapshot-ls") { string files = ""; DirectoryInfo di = new DirectoryInfo(SnapshotsDirectory + Path.DirectorySeparatorChar + channel.Name); FileInfo[] rgFiles = di.GetFiles("*"); int curr = 0; int displaying = 0; foreach (FileInfo fi in rgFiles) { curr++; if (files.Length < 200) { files += fi.Name + " "; displaying++; } } string response = ""; if (curr == displaying) { response = "There are " + displaying.ToString() + " files: " + files; } else { response = "There are " + curr.ToString() + " files, but displaying only " + displaying.ToString() + " of them: " + files; } if (curr == 0) { response = "There is no snapshot so far, create one!:)"; } Core.irc.Queue.DeliverMessage(response, channel.Name, IRC.priority.normal); return; } } if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-share-trust+ ")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (channel.SharedDB != "local") { Core.irc.Queue.DeliverMessage(messages.Localize("infobot16", channel.Language), channel); return; } if (channel.SharedDB != "local" && channel.SharedDB != "") { Core.irc.Queue.DeliverMessage(messages.Localize("infobot15", channel.Language), channel); return; } else { if (message.Length <= "@infobot-share-trust+ ".Length) { Core.irc.Queue.DeliverMessage(messages.Localize("db6", channel.Language), channel.Name); return; } string name = message.Substring("@infobot-share-trust+ ".Length); Channel guest = Core.GetChannel(name); if (guest == null) { Core.irc.Queue.DeliverMessage(messages.Localize("db8", channel.Language), channel.Name); return; } if (channel.SharedLinkedChan.Contains(guest)) { Core.irc.Queue.DeliverMessage(messages.Localize("db14", channel.Language), channel.Name); return; } Core.irc.Queue.DeliverMessage(messages.Localize("db1", channel.Language, new List<string> { name }), channel.Name); lock (channel.SharedLinkedChan) { channel.SharedLinkedChan.Add(guest); } channel.SaveConfig(); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-ignore- ")) { if (channel.SystemUsers.IsApproved(invoker, "trust")) { string item = message.Substring("@infobot-ignore+ ".Length); if (item != "") { if (!channel.Infobot_IgnoredNames.Contains(item)) { Core.irc.Queue.DeliverMessage(messages.Localize("infobot-ignore-found", channel.Language, new List<string> { item }), channel); return; } channel.Infobot_IgnoredNames.Remove(item); Core.irc.Queue.DeliverMessage(messages.Localize("infobot-ignore-rm", channel.Language, new List<string> { item }), channel); channel.SaveConfig(); return; } } else { if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } } } if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-ignore+ ")) { if (channel.SystemUsers.IsApproved(invoker, "trust")) { string item = message.Substring("@infobot-ignore+ ".Length); if (item != "") { if (channel.Infobot_IgnoredNames.Contains(item)) { Core.irc.Queue.DeliverMessage(messages.Localize("infobot-ignore-exist", channel.Language, new List<string> { item }), channel); return; } channel.Infobot_IgnoredNames.Add(item); Core.irc.Queue.DeliverMessage(messages.Localize("infobot-ignore-ok", channel.Language, new List<string> { item }), channel); channel.SaveConfig(); return; } } else { if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } } } if (message == Configuration.System.CommandPrefix + "infobot-off") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (!GetConfig(channel, "Infobot.Enabled", true)) { Core.irc.Queue.DeliverMessage(messages.Localize("infobot1", channel.Language), channel); return; } else { Core.irc.Queue.DeliverMessage(messages.Localize("infobot2", channel.Language), channel, IRC.priority.high); SetConfig(channel, "Infobot.Enabled", false); channel.SaveConfig(); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-share-trust- ")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (channel.SharedDB != "local") { Core.irc.Queue.DeliverMessage(messages.Localize("infobot16", channel.Language), channel); return; } else { if (message.Length <= "@infobot-share-trust+ ".Length) { Core.irc.Queue.DeliverMessage(messages.Localize("db6", channel.Language), channel); return; } string name = message.Substring("@infobot-share-trust- ".Length); Channel target = Core.GetChannel(name); if (target == null) { Core.irc.Queue.DeliverMessage(messages.Localize("db8", channel.Language), channel); return; } if (channel.SharedLinkedChan.Contains(target)) { channel.SharedLinkedChan.Remove(target); Core.irc.Queue.DeliverMessage(messages.Localize("db2", channel.Language, new List<string> { name }), channel); channel.SaveConfig(); return; } Core.irc.Queue.DeliverMessage(messages.Localize("db4", channel.Language), channel); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-detail ")) { if ((message.Length) <= "@infobot-detail ".Length) { Core.irc.Queue.DeliverMessage(messages.Localize("db6", channel.Language), channel); return; } if (GetConfig(channel, "Infobot.Enabled", true)) { if (channel.SharedDB == "local" || channel.SharedDB == "") { if (infobot != null) { infobot.InfobotDetail(message.Substring(16), channel); } return; } if (channel.SharedDB != "") { Channel db = Core.GetChannel(channel.SharedDB); if (db == null) { Core.irc.Queue.DeliverMessage("Error, null pointer to shared channel", channel, IRC.priority.low); return; } if (infobot != null) { infobot.InfobotDetail(message.Substring(16), channel); } return; } return; } Core.irc.Queue.DeliverMessage("Infobot is not enabled on this channel", channel, IRC.priority.low); return; } if (message.StartsWith(Configuration.System.CommandPrefix + "infobot-link ")) { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (channel.SharedDB == "local") { Core.irc.Queue.DeliverMessage(messages.Localize("infobot17", channel.Language), channel); return; } if (channel.SharedDB != "") { Core.irc.Queue.DeliverMessage(messages.Localize("infobot18", channel.Language, new List<string> { channel.SharedDB }), channel); return; } if ((message.Length - 1) < "@infobot-link ".Length) { Core.irc.Queue.DeliverMessage(messages.Localize("db6", channel.Language), channel); return; } string name = message.Substring("@infobot-link ".Length); Channel db = Core.GetChannel(name); if (db == null) { Core.irc.Queue.DeliverMessage(messages.Localize("db8", channel.Language), channel); return; } if (!Infobot.Linkable(db, channel)) { Core.irc.Queue.DeliverMessage(messages.Localize("db9", channel.Language), channel); return; } channel.SharedDB = name.ToLower(); Core.irc.Queue.DeliverMessage(messages.Localize("db10", channel.Language), channel); channel.SaveConfig(); return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message == Configuration.System.CommandPrefix + "infobot-share-off") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (channel.SharedDB == "") { Core.irc.Queue.DeliverMessage(messages.Localize("infobot14", channel.Language), channel); return; } else { Core.irc.Queue.DeliverMessage(messages.Localize("infobot13", channel.Language), channel); lock (Configuration.Channels) { foreach (Channel curr in Configuration.Channels) { if (curr.SharedDB == channel.Name.ToLower()) { curr.SharedDB = ""; curr.SaveConfig(); Core.irc.Queue.DeliverMessage(messages.Localize("infobot19", curr.Language, new List<string> { invoker.Nick }), curr); } } } channel.SharedDB = ""; channel.SaveConfig(); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message == Configuration.System.CommandPrefix + "infobot-on") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (GetConfig(channel, "Infobot.Enabled", true)) { Core.irc.Queue.DeliverMessage(messages.Localize("infobot3", channel.Language), channel); return; } SetConfig(channel, "Infobot.Enabled", true); channel.SaveConfig(); Core.irc.Queue.DeliverMessage(messages.Localize("infobot4", channel.Language), channel, IRC.priority.high); return; } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message == Configuration.System.CommandPrefix + "infobot-share-on") { if (channel.SystemUsers.IsApproved(invoker, "admin")) { if (channel.SharedDB == "local") { Core.irc.Queue.DeliverMessage(messages.Localize("infobot11", channel.Language), channel, IRC.priority.high); return; } if (channel.SharedDB != "local" && channel.SharedDB != "") { Core.irc.Queue.DeliverMessage(messages.Localize("infobot15", channel.Language), channel, IRC.priority.high); return; } else { Core.irc.Queue.DeliverMessage(messages.Localize("infobot12", channel.Language), channel); channel.SharedDB = "local"; channel.SaveConfig(); return; } } if (!channel.SuppressWarnings) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } }
public override void Hook_ChannelDrop(Channel chan) { try { if (Directory.Exists(SnapshotsDirectory + Path.DirectorySeparatorChar + chan.Name)) { Syslog.Log("Removing snapshots for " + chan.Name); Directory.Delete(SnapshotsDirectory + Path.DirectorySeparatorChar + chan.Name, true); } } catch (Exception fail) { Core.HandleException(fail, "infobot"); } }
public Feed(Channel _owner) { DB = Variables.ConfigurationDirectory + "/" + _owner.Name + "_feed.xml"; owner = _owner; Load(); }
/// <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 { if (message.StartsWith(Configuration.System.CommandPrefix + "trustadd")) { string[] rights_info = message.Split(' '); if (channel.SystemUsers.IsApproved(user, host, "trustadd")) { if (rights_info.Length < 3) { Core.irc.Queue.DeliverMessage(messages.Localize("Trust1", channel.Language), channel); return 0; } if (!(rights_info[2] == "admin" || rights_info[2] == "trusted")) { Core.irc.Queue.DeliverMessage(messages.Localize("Unknown1", channel.Language), channel); return 2; } if (rights_info[2] == "admin") { if (!channel.SystemUsers.IsApproved(user, host, "admin")) { Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), channel); return 2; } } if (channel.SystemUsers.AddUser(rights_info[2], rights_info[1])) { Core.irc.Queue.DeliverMessage(messages.Localize("UserSc", channel.Language) + rights_info[1], channel); return 0; } } else { Core.irc.Queue.DeliverMessage(messages.Localize("Authorization", channel.Language), channel.Name); return 0; } } if (message.StartsWith(Configuration.System.CommandPrefix + "trusted")) { channel.SystemUsers.ListAll(); 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; } Core.irc.Queue.DeliverMessage(messages.Localize("Authorization", channel.Language), channel); return 0; } Core.irc.Queue.DeliverMessage(messages.Localize("InvalidUser", channel.Language), channel); } } catch (Exception b) { Core.HandleException(b); } return 0; }
/// <summary> /// Part a channel /// </summary> /// <param name="channel">Channel object</param> /// <param name="user">User</param> /// <param name="host">Host</param> /// <param name="message">Message</param> /// <param name="origin"></param> public static void PartChannel(Channel channel, string user, string host, string message, string origin = "NULL") { try { if (origin == "NULL") { origin = channel.Name; } if (channel.Name == Configuration.System.DebugChan && (message == Configuration.System.CommandPrefix + "part" || message == Configuration.System.CommandPrefix + "drop")) { channel.PrimaryInstance.irc.Queue.DeliverMessage("Cowardly refusing to part this channel, because I love it :3", channel); return; } if (message == Configuration.System.CommandPrefix + "drop") { if (channel.SystemUsers.IsApproved(user, host, "admin")) { while (!Core.FinishedJoining) { Syslog.Log("Postponing request to part " + channel.Name + " because bot is still loading", true); Thread.Sleep(2000); } channel.PrimaryInstance.irc.SendData("PART " + channel.Name + " :" + "dropped by " + user + " from " + origin); Syslog.Log("Dropped " + channel.Name + " dropped by " + user + " from " + origin); Thread.Sleep(100); try { File.Delete(Variables.ConfigurationDirectory + Path.DirectorySeparatorChar + channel.Name + ".xml"); lock (ExtensionHandler.Extensions) { foreach (Module curr in ExtensionHandler.Extensions) { try { if (curr.IsWorking) { curr.Hook_ChannelDrop(channel); } } catch (Exception fail) { Syslog.Log("MODULE: exception at Hook_ChannelDrop in " + curr.Name, true); Core.HandleException(fail, curr.Name); } } } } catch (Exception fail) { Core.HandleException(fail); } lock (Configuration.Channels) { channel.Remove(); Configuration.Channels.Remove(channel); } Configuration.Save(); return; } Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), origin); return; } if (message == Configuration.System.CommandPrefix + "part") { if (channel.SystemUsers.IsApproved(user, host, "admin")) { while (!Core.FinishedJoining) { Syslog.Log("Postponing request to part " + channel.Name + " because bot is still loading", true); Thread.Sleep(2000); } channel.PrimaryInstance.irc.SendData("PART " + channel.Name + " :" + "removed by " + user + " from " + origin); Syslog.Log("Removed " + channel.Name + " removed by " + user + " from " + origin); Thread.Sleep(100); lock (Configuration.Channels) { channel.Remove(); Configuration.Channels.Remove(channel); } Configuration.Save(); return; } Core.irc.Queue.DeliverMessage(messages.Localize("PermissionDenied", channel.Language), origin); } } catch (Exception fail) { Core.HandleException(fail); } }
public Security(Channel channel) { this._Channel = channel; }
private static User getUser(string name, Channel c) { lock (c.UserList) { foreach (User user in c.UserList) { if (name.ToLower() == user.Nick.ToLower()) { return user; } } } return null; }