private void OnNews(BotShell bot, CommandArgs e) { try { using (IDbCommand command = this._database.Connection.CreateCommand()) { RichTextWindow window = new RichTextWindow(bot); window.AppendTitle(); bool titleSticky = false; bool titleNormal = false; Int64 lastPost = 0; command.CommandText = "SELECT [news_id], [news_name] , [news_date], [news_text], [news_icon], [news_sticky] FROM [news] ORDER BY [news_sticky] DESC, [news_date] DESC LIMIT 15"; IDataReader reader = command.ExecuteReader(); while (reader.Read()) { if (reader.GetInt64(2) > lastPost) { lastPost = reader.GetInt64(2); } if (reader.GetInt64(5) == 1) { if (!titleSticky) { window.AppendHeader("Sticky News Posts"); window.AppendLineBreak(); titleSticky = true; } } else { if (!titleNormal) { window.AppendHeader("Current News Posts"); window.AppendLineBreak(); titleNormal = true; } } window.AppendBotCommandStart("news id " + reader.GetInt64(0).ToString()); if (reader.GetInt64(5) == 1) { window.AppendImage("GFX_GUI_WINDOW_ICON_POPUP"); } else { window.AppendImage(_iconList[reader.GetInt64(4)]); } window.AppendLinkEnd(); window.AppendHighlight(" " + Format.DateTime(reader.GetInt64(2), FormatStyle.Compact) + " GMT by " + reader.GetString(1)); window.AppendLineBreak(true); window.AppendNormal(reader.GetString(3)); if ((reader.GetString(1) == e.Sender || bot.Users.Authorized(e.Sender, UserLevel.Admin))) { window.AppendLineBreak(true); window.AppendNormal("["); window.AppendBotCommand("Remove", "news remove " + reader.GetInt64(0)); window.AppendNormal("]"); } window.AppendLineBreak(2); } if (lastPost == 0) { bot.SendReply(e, "There's currently no news"); return; } else { bot.SendReply(e, "News last edited on " + HTML.CreateColorString(bot.ColorHeaderHex, Format.DateTime(lastPost, FormatStyle.Compact)) + " »» ", window); return; } } } catch { bot.SendReply(e, "Error during news fetching. Please try again later"); return; } }
public void BuildList(BotShell bot, string[] users, ref RichTextWindow window, ref int results, string profs) { if (window == null) { return; } if (users.Length == 0) { return; } SortedDictionary <string, SortedDictionary <string, WhoisResult> > list = new SortedDictionary <string, SortedDictionary <string, WhoisResult> >(); Dictionary <string, WhoisResult> whoisResults = new Dictionary <string, WhoisResult>(); foreach (string user in users) { if (user == null || user == string.Empty) { continue; } string header; WhoisResult whois = XML.GetWhois(user, bot.Dimension); if (profs != null && profs != string.Empty) { if (whois == null || whois.Stats == null) { continue; } if (!whois.Stats.Profession.StartsWith(profs, StringComparison.CurrentCultureIgnoreCase)) { continue; } } if (whois != null && whois.Stats != null) { if (this.DisplayMode == "Level") { header = whois.Stats.Level.ToString(); } else { header = whois.Stats.Profession; } if (!whoisResults.ContainsKey(user.ToLower())) { whoisResults.Add(user.ToLower(), whois); } } else if (this.DisplayMode == "Level") { header = "0"; } else { header = "Unknown"; } if (this.DisplayMode == "Alphabetical") { header = user.ToUpper().ToCharArray()[0].ToString(); } if (!list.ContainsKey(header)) { list.Add(header, new SortedDictionary <string, WhoisResult>()); } list[header].Add(user, whois); } results = 0; foreach (KeyValuePair <string, SortedDictionary <string, WhoisResult> > prof in list) { if (this.DisplayHeaders == "Text") { window.AppendHighlight(prof.Key); window.AppendLineBreak(); } else if (this.DisplayHeaders == "Icons") { window.AppendImage("GFX_GUI_FRIENDLIST_SPLITTER"); window.AppendLineBreak(); window.AppendIcon(Icons[prof.Key]); window.AppendHighlight(prof.Key); window.AppendLineBreak(); window.AppendImage("GFX_GUI_FRIENDLIST_SPLITTER"); window.AppendLineBreak(); } foreach (KeyValuePair <string, WhoisResult> user in prof.Value) { // Name window.AppendNormalStart(); window.AppendString(" "); int level = 0; int ailevel = 0; string name = Format.UppercaseFirst(user.Key); // Level if (user.Value != null && user.Value.Stats != null) { level = user.Value.Stats.Level; ailevel = user.Value.Stats.DefenderLevel; } if (level < 10) { window.AppendColorString("000000", "00"); } else if (level < 100) { window.AppendColorString("000000", "0"); } window.AppendString(level + " "); if (ailevel < 10) { window.AppendColorString("000000", "0"); } window.AppendColorString(RichTextWindow.ColorGreen, ailevel + " "); window.AppendString(name); // Organization bool displayOrganization = false; if (this.DisplayOrganization == "Always") { displayOrganization = true; } if (this.DisplayOrganization == "Foreign") { displayOrganization = true; if (bot.InOrganization && whoisResults.ContainsKey(name.ToLower()) && whoisResults[name.ToLower()].InOrganization && bot.Organization == whoisResults[name.ToLower()].Organization.Name) { displayOrganization = false; } } if (displayOrganization) { if (!whoisResults.ContainsKey(name.ToLower())) { window.AppendString(" (Unknown)"); } else if (whoisResults[name.ToLower()].InOrganization) { window.AppendString(" (" + whoisResults[name.ToLower()].Organization.ToString() + ")"); } else { window.AppendString(" (Not Guilded)"); } } // Rank if (this.DisplayRanks) { UserLevel userLevel = bot.Users.GetUser(name); if (userLevel > UserLevel.Member) { window.AppendString(" ("); window.AppendColorString(RichTextWindow.ColorRed, bot.Users.GetUser(name).ToString()); window.AppendString(")"); } } // Alts if (this.DisplayAlts) { string main = bot.Users.GetMain(name); string[] alts = bot.Users.GetAlts(main); if (alts.Length > 0) { window.AppendString(" :: "); if (main == name) { window.AppendBotCommand("Alts", "alts " + main); } else { window.AppendBotCommand(main + "'s Alts", "alts " + main); } } } // Afk if (this.DisplayAfk) { lock (this.Afk) { if (this.Afk.ContainsKey(name)) { window.AppendString(" :: "); window.AppendColorString(RichTextWindow.ColorRed, "AFK"); } } } window.AppendColorEnd(); window.AppendLineBreak(); results++; } if (this.DisplayHeaders == "Text" || this.DisplayHeaders == "Icons") { window.AppendLineBreak(); } } if (this.DisplayHeaders == "Off") { window.AppendLineBreak(); } }
private void OnNewsID(BotShell bot, CommandArgs e) { double d; if (e.Args.Length == 0) { bot.SendReply(e, "Correct Usage: news id [id]"); return; } if (double.TryParse(e.Args[0], System.Globalization.NumberStyles.Integer, _cultureInfo, out d) == true) { try { using (IDbCommand command = this._database.Connection.CreateCommand()) { command.CommandText = "SELECT [news_name], [news_sticky] FROM [news] WHERE [news_id] = " + e.Args[0]; IDataReader reader = command.ExecuteReader(); if (reader.Read()) { if ((reader.GetString(0) == e.Sender || bot.Users.Authorized(e.Sender, UserLevel.Admin)) && e.Type == CommandType.Tell) { RichTextWindow window = new RichTextWindow(bot); window.AppendTitle("News Options"); window.AppendHighlight("Sticky: "); if (reader.GetInt64(1) == 1) { window.AppendColorString(RichTextWindow.ColorGreen, "Enabled"); window.AppendNormal(" ["); window.AppendBotCommand("Disable", "news sticky " + e.Args[0] + " 0"); window.AppendNormal("]"); } else { window.AppendColorString(RichTextWindow.ColorOrange, "Disabled"); window.AppendNormal(" ["); window.AppendBotCommand("Enable", "news sticky " + e.Args[0] + " 1"); window.AppendNormal("]"); } window.AppendLineBreak(2); window.AppendHeader("Icon"); if (reader.GetInt64(1) == 1) { window.AppendNormal("There are no icons available for sticky posts"); } else { int counter = 0; foreach (string Icon in _iconList) { window.AppendBotCommandStart("news icon " + e.Args[0] + " " + counter.ToString()); window.AppendImage(Icon); window.AppendLinkEnd(); window.AppendNormal(" "); counter = counter + 1; } } bot.SendReply(e, "News Options »» ", window); return; } else { bot.SendReply(e, "You don't own this news post"); return; } } else { bot.SendReply(e, "No such news post"); return; } } } catch { bot.SendReply(e, "Error during news fetching. Please try again later"); return; } } bot.SendReply(e, "Invalid ID"); }
private void OnServerCommand(BotShell bot, CommandArgs e) { bot.SendReply(e, "Server Status »» Gathering Data..."); ServerStatusResult server = XML.GetServerStatus(); if (server == null || server.Dimensions == null) { bot.SendReply(e, "Unable to gather server information " + this.TimeoutError); return; } ServerStatusResult_Dimension dimension = server.GetDimension(bot.Dimension); RichTextWindow window = new RichTextWindow(bot); window.AppendTitle("Server Information"); window.AppendHighlight("Server Manager: "); if (dimension.ServerManager.Online) { window.AppendColorString(RichTextWindow.ColorGreen, "Online"); } else { window.AppendColorString(RichTextWindow.ColorRed, "Offline"); } window.AppendLineBreak(); window.AppendHighlight("Client Manager: "); if (dimension.ClientManager.Online) { window.AppendColorString(RichTextWindow.ColorGreen, "Online"); } else { window.AppendColorString(RichTextWindow.ColorRed, "Offline"); } window.AppendLineBreak(); window.AppendHighlight("Chat Server: "); if (dimension.ChatServer.Online) { window.AppendColorString(RichTextWindow.ColorGreen, "Online"); } else { window.AppendColorString(RichTextWindow.ColorRed, "Offline"); } window.AppendLineBreak(2); window.AppendHeader("Alignment"); window.AppendHighlight("Clan: "); window.AppendNormal(dimension.Distribution.Clan.Percent + "%"); window.AppendLineBreak(); window.AppendHighlight("Neutral: "); window.AppendNormal(dimension.Distribution.Neutral.Percent + "%"); window.AppendLineBreak(); window.AppendHighlight("Omni: "); window.AppendNormal(dimension.Distribution.Omni.Percent + "%"); window.AppendLineBreak(2); foreach (ServerStatusResult_Playfield pf in dimension.Playfields) { bool skip = false; foreach (string arg in e.Args) { if (!pf.Name.ToLower().Contains(arg.ToLower())) { skip = true; } } if (skip) { continue; } switch (pf.Status) { case PlayfieldStatus.Online: window.AppendImage("GFX_GUI_FRIENDLIST_STATUS_GREEN"); break; default: window.AppendImage("GFX_GUI_FRIENDLIST_STATUS_RED"); break; } window.AppendNormalStart(); window.AppendString(" "); window.AppendColorStart(RichTextWindow.ColorGreen); double players = 0; while (players <= pf.Players && players <= 8 && pf.Players != 0) { players += 0.5; window.AppendString("l"); } window.AppendColorEnd(); while (players <= 8) { players += 0.5; window.AppendString("l"); } window.AppendString(" "); window.AppendColorEnd(); window.AppendHighlight(pf.Name); window.AppendNormal(string.Format(" (ID: {0} Players: {1}%)", pf.ID, pf.Players)); window.AppendLineBreak(); } bot.SendReply(e, "Server Status »» ", window); }