/// <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, config.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); } }
public override bool Hook_OnRegister() { bool success = true; DebugLog("Registering channels"); try { if (!Directory.Exists(SnapshotsDirectory)) { core.Log("Creating snapshot directory for infobot"); Directory.CreateDirectory(SnapshotsDirectory); } } catch (Exception fail) { Snapshots = false; core.handleException(fail); } writer = new infobot_writer(); writer.Construct(); core.InitialiseMod(writer); lock (config.channels) { foreach (config.channel channel in config.channels) { config.channel curr = channel; bool cs = Module.GetConfig(curr, "Infobot.Case", true); if (!channel.RegisterObject(new infobot_core(getDB(ref curr), channel.Name, cs), "Infobot")) { success = false; } if (Snapshots) { try { if (Directory.Exists(SnapshotsDirectory + Path.DirectorySeparatorChar + channel.Name) == false) { core.Log("Creating directory for infobot for " + channel.Name); Directory.CreateDirectory(SnapshotsDirectory + Path.DirectorySeparatorChar + channel.Name); } } catch (Exception fail) { core.handleException(fail); } } } } if (!success) { core.Log("Failed to register infobot objects in some channels", true); } return(success); }
public override string Extension_DumpHtml(config.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_PRIV(config.channel channel, User invoker, string message) { ChanLog(message, channel, invoker.Nick, invoker.Host); if (message == config.CommandPrefix + "logon") { if (channel.Users.IsApproved(invoker, "admin")) { if (Module.GetConfig(channel, "Logging.Enabled", false)) { core.irc._SlowQueue.DeliverMessage(messages.get("ChannelLogged", channel.Language), channel.Name); return; } else { core.irc._SlowQueue.DeliverMessage(messages.get("LoggingOn", channel.Language), channel.Name); Module.SetConfig(channel, "Logging.Enabled", true); channel.SaveConfig(); return; } } if (!channel.suppress_warnings) { core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } if (message == config.CommandPrefix + "logoff") { if (channel.Users.IsApproved(invoker.Nick, invoker.Host, "admin")) { if (!Module.GetConfig(channel, "Logging.Enabled", false)) { core.irc._SlowQueue.DeliverMessage(messages.get("LogsE1", channel.Language), channel.Name); return; } else { Module.SetConfig(channel, "Logging.Enabled", false); channel.SaveConfig(); core.irc._SlowQueue.DeliverMessage(messages.get("NotLogged", channel.Language), channel.Name); return; } } if (!channel.suppress_warnings) { core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } }
public override void Hook_Join(config.channel channel, User user) { if (Module.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_Nick(config.channel channel, User Target, string OldNick) { if (Module.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 = Target.Nick; lock (DJ) { DJ.Add(item); } } }
public override string Extension_DumpHtml(config.channel channel) { string HTML = ""; infobot_core info = (infobot_core)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_core.InfobotKey> list = new List <infobot_core.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_core.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_core.InfobotAlias data in info.Alias) { HTML += core.HTML.AddLink(data.Name, data.Key); } } HTML += "</table><br>\n"; } return(HTML); }
public bool Fetch() { try { lock (Content) { foreach (Item curr in Content) { if (!curr.disabled && curr.data == null) { curr.data = RssManager.ReadFeed(curr.URL, curr, owner.Name); continue; } if (!curr.disabled) { List <RssFeedItem> feed = RssManager.ReadFeed(curr.URL, curr, owner.Name); if (feed == null) { core.DebugLog("NULL feed for " + curr.name, 6); continue; } if (feed.Count == 0) { core.DebugLog("0 items for " + curr.name, 6); continue; } core.DebugLog("there are " + feed.Count.ToString() + "feed:" + curr.name, 6); if (!RssManager.CompareLists(curr.data, feed)) { List <RssFeedItem> diff = new List <RssFeedItem>(); foreach (RssFeedItem item in feed) { if (!RssManager.ContainsItem(curr.data, item)) { diff.Add(item); } } curr.data = feed; diff.Reverse(); foreach (RssFeedItem di in diff) { string message = ""; string description = di.Description.Replace("\n", " "); if (description.Length > 200) { description = description.Substring(0, 200); } if (curr.ScannerOnly) { if (!Matches(di.Title) && !Matches(di.Description)) { continue; } } string temp = Module.GetConfig(owner, "Rss.Style", "[$name] $title: $description $link"); if (curr.template != "") { temp = curr.template; } message = temp.Replace("$link", di.Link) .Replace("$title", di.Title) .Replace("$name", curr.name) .Replace("$author", di.Author) .Replace("$description", description) .Replace("$bugzilla_assignee", di.bugzilla_assignee) .Replace("$bugzilla_component", di.bugzilla_component) .Replace("$bugzilla_creation", di.bugzilla_creation) .Replace("$bugzilla_priority", di.bugzilla_priority) .Replace("$bugzilla_product", di.bugzilla_product) .Replace("$bugzilla_reporter", di.bugzilla_reporter) .Replace("$bugzilla_resolution", di.bugzilla_reso) .Replace("$bugzilla_severity", di.bugzilla_severity) .Replace("$bugzilla_status", di.bugzilla_status) .Replace("$bugzilla_target", di.bugzilla_target); core.irc._SlowQueue.DeliverMessage(message, owner.Name, IRC.priority.low); } } } } } } catch (Exception fail) { RSS.m.Log("Unable to handle rss in " + owner.Name, true); RSS.m.handleException(fail, "Feed"); } return(true); }
/// <summary> /// Part a channel /// </summary> /// <param name="chan">Channel object</param> /// <param name="user">User</param> /// <param name="host">Host</param> /// <param name="message">Message</param> /// <param name="origin"></param> public static void partChannel(config.channel chan, string user, string host, string message, string origin = "NULL") { try { if (origin == "NULL") { origin = chan.Name; } if (chan.Name == config.DebugChan && (message == config.CommandPrefix + "part" || message == config.CommandPrefix + "drop")) { chan.instance.irc._SlowQueue.DeliverMessage("Cowardly refusing to part this channel, because I love it :3", chan); return; } if (message == config.CommandPrefix + "drop") { if (chan.Users.IsApproved(user, host, "admin")) { while (!core.FinishedJoining) { core.Log("Postponing request to part " + chan.Name + " because bot is still loading", true); Thread.Sleep(2000); } chan.instance.irc.SendData("PART " + chan.Name + " :" + "dropped by " + user + " from " + origin); Program.Log("Dropped " + chan.Name + " dropped by " + user + " from " + origin); Thread.Sleep(100); try { // let's try to remove channel logs string logdir = Module.GetConfig(chan, "Logs.Path", "null"); if (logdir == "null") { logdir = chan.LogDir; } if (Directory.Exists(logdir)) { Directory.Delete(logdir, true); } } catch (Exception fail) { Log(fail.ToString(), true); } try { File.Delete(variables.config + Path.DirectorySeparatorChar + chan.Name + ".setting"); File.Delete(chan.Users.File); if (File.Exists(variables.config + Path.DirectorySeparatorChar + chan.Name + ".list")) { File.Delete(variables.config + Path.DirectorySeparatorChar + chan.Name + ".list"); } if (File.Exists(variables.config + Path.DirectorySeparatorChar + chan.Name + ".statistics")) { File.Delete(variables.config + Path.DirectorySeparatorChar + chan.Name + ".statistics"); } lock (Module.module) { foreach (Module curr in Module.module) { try { if (curr.working) { curr.Hook_ChannelDrop(chan); } } catch (Exception fail) { core.Log("MODULE: exception at Hook_ChannelDrop in " + curr.Name, true); core.handleException(fail); } } } } catch (Exception error) { Log(error.ToString(), true); } lock (config.channels) { chan.Remove(); config.channels.Remove(chan); } config.Save(); return; } irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", chan.Language), origin); return; } if (message == config.CommandPrefix + "part") { if (chan.Users.IsApproved(user, host, "admin")) { while (!core.FinishedJoining) { core.Log("Postponing request to part " + chan.Name + " because bot is still loading", true); Thread.Sleep(2000); } chan.instance.irc.SendData("PART " + chan.Name + " :" + "removed by " + user + " from " + origin); Program.Log("Removed " + chan.Name + " removed by " + user + " from " + origin); Thread.Sleep(100); config.channels.Remove(chan); config.Save(); return; } irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", chan.Language), origin); } } catch (Exception x) { handleException(x); } }
/// <summary> /// Generate a dump file /// </summary> public void Make() { try { Dictionary <string, string> ModuleData = new Dictionary <string, string>(); lock (Module.module) { foreach (Module xx in Module.module) { try { if (xx.working) { string html = xx.Extension_DumpHtml(Channel); if (html != null && html != "") { ModuleData.Add(xx.Name.ToLower(), xx.Extension_DumpHtml(Channel)); } } } catch (Exception fail) { core.Log("Unable to retrieve web data", true); core.handleException(fail); } } } string text = CreateHeader(Channel.Name); if (ModuleData.ContainsKey("infobot core")) { if (Module.GetConfig(Channel, "Infobot.Enabled", true)) { text += "<h4>Infobot</h4>\n"; if (Channel.shared != "" && Channel.shared != "local") { config.channel temp = core.getChannel(Channel.shared); if (temp != null) { text += "Linked to <a href=" + System.Web.HttpUtility.UrlEncode(temp.Name) + ".htm>" + temp.Name + "</a>\n"; } else { text += "Channel is linked to " + Channel.shared + " which isn't in my db, that's weird"; } } else { text += ModuleData["infobot core"]; } } ModuleData.Remove("infobot core"); } if (ModuleData.ContainsKey("rc")) { if (Module.GetConfig(Channel, "RC.Enabled", false)) { text += "\n<br><h4>Recent changes</h4>"; text += ModuleData["rc"]; ModuleData.Remove("rc"); } } if (ModuleData.ContainsKey("statistics") && ModuleData["statistics"] != null) { if (Module.GetConfig(Channel, "Statistics.Enabled", false)) { text += ModuleData["statistics"]; ModuleData.Remove("statistics"); } } if (ModuleData.ContainsKey("feed")) { if (Module.GetConfig(Channel, "Rss.Enable", false)) { text += ModuleData["feed"]; ModuleData.Remove("feed"); } } foreach (KeyValuePair <string, string> item in ModuleData) { if (item.Value != null && item.Value != "") { text += item.Value; } } text += CreateFooter(); File.WriteAllText(dumpname, text); } catch (Exception b) { core.handleException(b); } }
/// <summary> /// Create stat for bot /// </summary> public static void Stat() { try { Thread.Sleep(2000); string text = CreateHeader("System info"); text += "<h1>System data</h1><p class=info>List of channels:</p>\n"; text += "<table class=\"channels\">\n<tr><th>Channel name</th><th>Options</th></tr>\n"; foreach (config.channel chan in config.ChannelList) { text = text + "<tr>"; text = text + "<td><a href=\"" + System.Web.HttpUtility.UrlEncode(chan.Name) + ".htm\">" + chan.Name + "</a></td><td>"; text += "infobot: " + Module.GetConfig(chan, "Infobot.Enabled", true).ToString() + ", Recent Changes: " + Module.GetConfig(chan, "RC.Enabled", false).ToString() + ", Logs: " + Module.GetConfig(chan, "Logging.Enabled", false).ToString() + ", Suppress: " + chan.suppress.ToString() + ", Seen: " + Module.GetConfig(chan, "Seen.Enabled", false).ToString() + ", rss: " + Module.GetConfig(chan, "Rss.Enabled", false).ToString() + ", statistics: " + Module.GetConfig(chan, "Statistics.Enabled", false).ToString() + " Instance: " + chan.instance.Nick + "</td></tr>\n"; } text += "</table>Uptime: " + core.getUptime() + " Memory usage: " + (System.Diagnostics.Process.GetCurrentProcess().PrivateMemorySize64 / 1024).ToString() + "kb Database size: " + getSize(); lock (Module.module) { foreach (Module mm in Module.module) { mm.Hook_BeforeSysWeb(ref text); } text += "<br>Core version: " + config.Version + "<br>\n"; text += "<h2>Bots</h2><table class=\"text\"><th>Name</th><th>Status</th><th>Bouncer</th>"; lock (core.Instances) { foreach (Instance xx in core.Instances.Values) { string status = "Online in " + xx.ChannelCount.ToString() + " channels"; if (!xx.IsWorking || !xx.irc.IsConnected) { status = "Disconnected"; } text += "<tr><td>" + xx.Nick + "</td><td>" + status + "</td><td>" + xx.Port.ToString() + "</td></tr>"; } } text += "</table>"; text += "<h2>Plugins</h2><table class=\"modules\">"; foreach (Module module in Module.module) { string status = "Terminated"; if (module.working) { status = "OK"; if (module.Warning) { status += " - RECOVERING"; } } text = text + "<tr><td>" + module.Name + " (" + module.Version + ")</td><td>" + status + " (startup date: " + module.Date.ToString() + ")</td></tr>\n"; } } text += "</table>\n\n</body></html>"; File.WriteAllText(config.DumpDir + "/systemdata.htm", text); } catch (Exception b) { core.handleException(b); } }
public string getDB(ref config.channel chan) { return(Module.GetConfig(chan, "Infobot.Keydb", (string)variables.config + Path.DirectorySeparatorChar + chan.Name + ".db")); }
public override void Hook_PRIV(config.channel channel, User invoker, string message) { if (Module.GetConfig(channel, "Statistics.Enabled", false)) { Statistics st = (Statistics)channel.RetrieveObject("Statistics"); if (st != null) { st.Stat(invoker.Nick, message, invoker.Host); } } if (message == config.CommandPrefix + "statistics-off") { if (channel.Users.IsApproved(invoker, "admin")) { if (!Module.GetConfig(channel, "Statistics.Enabled", false)) { core.irc._SlowQueue.DeliverMessage(messages.get("StatE2", channel.Language), channel); return; } else { Module.SetConfig(channel, "Statistics.Enabled", false); channel.SaveConfig(); core.irc._SlowQueue.DeliverMessage(messages.get("Stat-off", channel.Language), channel); return; } } if (!channel.suppress_warnings) { core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message == config.CommandPrefix + "statistics-reset") { if (channel.Users.IsApproved(invoker, "admin")) { Statistics st = (Statistics)channel.RetrieveObject("Statistics"); if (st != null) { st.Delete(); } core.irc._SlowQueue.DeliverMessage(messages.get("Statdt", channel.Language), channel); return; } if (!channel.suppress_warnings) { core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel, IRC.priority.low); } return; } if (message == config.CommandPrefix + "statistics-on") { if (channel.Users.IsApproved(invoker, "admin")) { if (Module.GetConfig(channel, "Statistics.Enabled", false)) { core.irc._SlowQueue.DeliverMessage(messages.get("StatE1", channel.Language), channel); return; } else { Module.SetConfig(channel, "Statistics.Enabled", true); channel.SaveConfig(); core.irc._SlowQueue.DeliverMessage(messages.get("Stat-on", channel.Language), channel); return; } } if (!channel.suppress_warnings) { core.irc._SlowQueue.DeliverMessage(messages.get("PermissionDenied", channel.Language), channel.Name, IRC.priority.low); } return; } }