public override void Hook_PRIV(config.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_core.InfoItem item = new infobot_core.InfoItem(); item.Channel = channel; item.Name = "!" + message.Substring(1); // Normalizing "!". item.User = invoker.Nick; item.Host = invoker.Host; jobs.Add(item); Unwritable = false; } infobot_core infobot = null; if (message.StartsWith(config.CommandPrefix)) { infobot = (infobot_core)channel.RetrieveObject("Infobot"); if (infobot == null) { core.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(config.CommandPrefix + "infobot-recovery ")) { if (channel.Users.IsApproved(invoker, "admin")) { string name = message.Substring("@infobot-recovery ".Length); if (!GetConfig(channel, "Infobot.Enabled", true)) { core.irc._SlowQueue.DeliverMessage("Infobot is not enabled in this channel", channel, IRC.priority.low); return; } if (infobot != null) { infobot.RecoverSnapshot(channel, name); } return; } if (!channel.suppress_warnings) { core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message.StartsWith(config.CommandPrefix + "infobot-snapshot ")) { if (channel.Users.IsApproved(invoker, "admin")) { string name = message.Substring("@infobot-snapshot ".Length); if (!GetConfig(channel, "Infobot.Enabled", true)) { core.irc._SlowQueue.DeliverMessage("Infobot is not enabled in this channel", channel, IRC.priority.low); return; } if (infobot != null) { infobot.CreateSnapshot(channel, name); } return; } if (!channel.suppress_warnings) { core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message.StartsWith(config.CommandPrefix + "infobot-set-raw ")) { if (channel.Users.IsApproved(invoker, "trust")) { string name = message.Substring("@infobot-set-raw ".Length); if (!GetConfig(channel, "Infobot.Enabled", true)) { core.irc._SlowQueue.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.suppress_warnings) { core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message.StartsWith(config.CommandPrefix + "infobot-unset-raw ")) { if (channel.Users.IsApproved(invoker, "trust")) { string name = message.Substring("@infobot-unset-raw ".Length); if (!GetConfig(channel, "Infobot.Enabled", true)) { core.irc._SlowQueue.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.suppress_warnings) { core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message.StartsWith(config.CommandPrefix + "infobot-snapshot-rm ")) { if (channel.Users.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._SlowQueue.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._SlowQueue.DeliverMessage("File not found", channel, IRC.priority.normal); return; } File.Delete(SnapshotsDirectory + Path.DirectorySeparatorChar + channel.Name + Path.DirectorySeparatorChar + name); core.irc._SlowQueue.DeliverMessage("Requested file was removed", channel, IRC.priority.normal); return; } if (!channel.suppress_warnings) { core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message == config.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._SlowQueue.DeliverMessage(response, channel.Name, IRC.priority.normal); return; } } if (message.StartsWith(config.CommandPrefix + "infobot-share-trust+ ")) { if (channel.Users.IsApproved(invoker, "admin")) { if (channel.shared != "local") { core.irc._SlowQueue.DeliverMessage(messages.get("infobot16", channel.Language), channel); return; } if (channel.shared != "local" && channel.shared != "") { core.irc._SlowQueue.DeliverMessage(messages.get("infobot15", channel.Language), channel); return; } else { if (message.Length <= "@infobot-share-trust+ ".Length) { core.irc._SlowQueue.DeliverMessage(messages.get("db6", channel.Language), channel.Name); return; } string name = message.Substring("@infobot-share-trust+ ".Length); config.channel guest = core.getChannel(name); if (guest == null) { core.irc._SlowQueue.DeliverMessage(messages.get("db8", channel.Language), channel.Name); return; } if (channel.SharedLinkedChan.Contains(guest)) { core.irc._SlowQueue.DeliverMessage(messages.get("db14", channel.Language), channel.Name); return; } core.irc._SlowQueue.DeliverMessage(messages.get("db1", channel.Language, new List <string> { name }), channel.Name); lock (channel.SharedLinkedChan) { channel.SharedLinkedChan.Add(guest); } channel.SaveConfig(); return; } } if (!channel.suppress_warnings) { core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message.StartsWith(config.CommandPrefix + "infobot-ignore- ")) { if (channel.Users.IsApproved(invoker, "trust")) { string item = message.Substring("@infobot-ignore+ ".Length); if (item != "") { if (!channel.Infobot_IgnoredNames.Contains(item)) { core.irc._SlowQueue.DeliverMessage(messages.get("infobot-ignore-found", channel.Language, new List <string> { item }), channel); return; } channel.Infobot_IgnoredNames.Remove(item); core.irc._SlowQueue.DeliverMessage(messages.get("infobot-ignore-rm", channel.Language, new List <string> { item }), channel); channel.SaveConfig(); return; } } else { if (!channel.suppress_warnings) { core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low); } } } if (message.StartsWith(config.CommandPrefix + "infobot-ignore+ ")) { if (channel.Users.IsApproved(invoker, "trust")) { string item = message.Substring("@infobot-ignore+ ".Length); if (item != "") { if (channel.Infobot_IgnoredNames.Contains(item)) { core.irc._SlowQueue.DeliverMessage(messages.get("infobot-ignore-exist", channel.Language, new List <string> { item }), channel); return; } channel.Infobot_IgnoredNames.Add(item); core.irc._SlowQueue.DeliverMessage(messages.get("infobot-ignore-ok", channel.Language, new List <string> { item }), channel); channel.SaveConfig(); return; } } else { if (!channel.suppress_warnings) { core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low); } } } if (message == config.CommandPrefix + "infobot-off") { if (channel.Users.IsApproved(invoker, "admin")) { if (!GetConfig(channel, "Infobot.Enabled", true)) { core.irc._SlowQueue.DeliverMessage(messages.get("infobot1", channel.Language), channel); return; } else { core.irc._SlowQueue.DeliverMessage(messages.get("infobot2", channel.Language), channel, IRC.priority.high); SetConfig(channel, "Infobot.Enabled", false); channel.SaveConfig(); return; } } if (!channel.suppress_warnings) { core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message.StartsWith(config.CommandPrefix + "infobot-share-trust- ")) { if (channel.Users.IsApproved(invoker, "admin")) { if (channel.shared != "local") { core.irc._SlowQueue.DeliverMessage(messages.get("infobot16", channel.Language), channel); return; } else { if (message.Length <= "@infobot-share-trust+ ".Length) { core.irc._SlowQueue.DeliverMessage(messages.get("db6", channel.Language), channel); return; } string name = message.Substring("@infobot-share-trust- ".Length); config.channel target = core.getChannel(name); if (target == null) { core.irc._SlowQueue.DeliverMessage(messages.get("db8", channel.Language), channel); return; } if (channel.SharedLinkedChan.Contains(target)) { channel.SharedLinkedChan.Remove(target); core.irc._SlowQueue.DeliverMessage(messages.get("db2", channel.Language, new List <string> { name }), channel); channel.SaveConfig(); return; } core.irc._SlowQueue.DeliverMessage(messages.get("db4", channel.Language), channel); return; } } if (!channel.suppress_warnings) { core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message.StartsWith(config.CommandPrefix + "infobot-detail ")) { if ((message.Length) <= "@infobot-detail ".Length) { core.irc._SlowQueue.DeliverMessage(messages.get("db6", channel.Language), channel); return; } if (GetConfig(channel, "Infobot.Enabled", true)) { if (channel.shared == "local" || channel.shared == "") { if (infobot != null) { infobot.Info(message.Substring(16), channel); } return; } if (channel.shared != "") { config.channel db = core.getChannel(channel.shared); if (db == null) { core.irc._SlowQueue.DeliverMessage("Error, null pointer to shared channel", channel, IRC.priority.low); return; } if (infobot != null) { infobot.Info(message.Substring(16), channel); } return; } return; } core.irc._SlowQueue.DeliverMessage("Infobot is not enabled on this channel", channel, IRC.priority.low); return; } if (message.StartsWith(config.CommandPrefix + "infobot-link ")) { if (channel.Users.IsApproved(invoker, "admin")) { if (channel.shared == "local") { core.irc._SlowQueue.DeliverMessage(messages.get("infobot17", channel.Language), channel); return; } if (channel.shared != "") { core.irc._SlowQueue.DeliverMessage(messages.get("infobot18", channel.Language, new List <string> { channel.shared }), channel); return; } if ((message.Length - 1) < "@infobot-link ".Length) { core.irc._SlowQueue.DeliverMessage(messages.get("db6", channel.Language), channel); return; } string name = message.Substring("@infobot-link ".Length); config.channel db = core.getChannel(name); if (db == null) { core.irc._SlowQueue.DeliverMessage(messages.get("db8", channel.Language), channel); return; } if (!infobot_core.Linkable(db, channel)) { core.irc._SlowQueue.DeliverMessage(messages.get("db9", channel.Language), channel); return; } channel.shared = name.ToLower(); core.irc._SlowQueue.DeliverMessage(messages.get("db10", channel.Language), channel); channel.SaveConfig(); return; } if (!channel.suppress_warnings) { core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message == config.CommandPrefix + "infobot-share-off") { if (channel.Users.IsApproved(invoker, "admin")) { if (channel.shared == "") { core.irc._SlowQueue.DeliverMessage(messages.get("infobot14", channel.Language), channel); return; } else { core.irc._SlowQueue.DeliverMessage(messages.get("infobot13", channel.Language), channel); foreach (config.channel curr in config.channels) { if (curr.shared == channel.Name.ToLower()) { curr.shared = ""; curr.SaveConfig(); core.irc._SlowQueue.DeliverMessage(messages.get("infobot19", curr.Language, new List <string> { invoker.Nick }), curr); } } channel.shared = ""; channel.SaveConfig(); return; } } if (!channel.suppress_warnings) { core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message == config.CommandPrefix + "infobot-on") { if (channel.Users.IsApproved(invoker, "admin")) { if (GetConfig(channel, "Infobot.Enabled", true)) { core.irc._SlowQueue.DeliverMessage(messages.get("infobot3", channel.Language), channel); return; } SetConfig(channel, "Infobot.Enabled", true); channel.SaveConfig(); core.irc._SlowQueue.DeliverMessage(messages.get("infobot4", channel.Language), channel, IRC.priority.high); return; } if (!channel.suppress_warnings) { core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message == config.CommandPrefix + "infobot-share-on") { if (channel.Users.IsApproved(invoker, "admin")) { if (channel.shared == "local") { core.irc._SlowQueue.DeliverMessage(messages.get("infobot11", channel.Language), channel, IRC.priority.high); return; } if (channel.shared != "local" && channel.shared != "") { core.irc._SlowQueue.DeliverMessage(messages.get("infobot15", channel.Language), channel, IRC.priority.high); return; } else { core.irc._SlowQueue.DeliverMessage(messages.get("infobot12", channel.Language), channel); channel.shared = "local"; channel.SaveConfig(); return; } } if (!channel.suppress_warnings) { core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } }