public void ClearData() { m_OpenMusic = true; m_OpenSound = true; m_AntiAddictionSeconds = 0; m_AntiAddictionTimeStamp = TimeStamp.FromDateTime(System.DateTime.Now); m_QuestionsCompletedTotal = 0; m_QuestionsCompletedThisTime = 0; SaveData(); }
public override void OnCommand(BotShell bot, CommandArgs e) { Int32 cycle = 7 + 7 + 7; string today = string.Empty; DateTimeFormatInfo dtfi = new CultureInfo("en-US", false).DateTimeFormat; RichTextWindow window = new RichTextWindow(bot); window.AppendTitle("Beast Days"); for (int i = 0; i < cycle; i++) { Int64 current = TimeStamp.Now + ((24 * 60 * 60) * i); Int64 secondsSinceStart = current - TimeStamp.FromDateTime(new DateTime(2006, 10, 23)); Int64 seconds = secondsSinceStart % (cycle * (24 * 60 * 60)); Int64 day = (seconds / (24 * 60 * 60)) + 1; string type = string.Empty; if (day <= 7) { type = HTML.CreateColorString(RichTextWindow.ColorBlue, "Omni"); } else if (day > 7 && day <= 14) { type = HTML.CreateColorString(RichTextWindow.ColorGreen, "FFA"); } else if (day > 14) { type = HTML.CreateColorString(RichTextWindow.ColorOrange, "Clan"); } if (type == string.Empty) { continue; } if (i == 0) { today = type; } window.AppendHighlight(TimeStamp.ToDateTime(current).ToString("[dd/MM/yyyy]", dtfi)); window.AppendNormal(TimeStamp.ToDateTime(current).ToString(" dddd: ", dtfi)); window.AppendRawString(type); window.AppendLineBreak(); } bot.SendReply(e, "Today is " + today + " day »» " + window.ToString()); }
private bool FetchWebTime(BotShell bot) { string data = HTML.GetHtml(this.Url, 3000); if (data == null || data == string.Empty) { return(false); } string[] parts = data.Split(' '); if (parts.Length < 3) { return(false); } string type = parts[0]; string[] date = parts[1].Split('-'); string[] time = parts[2].Split(':'); if (type != "GATETIME" && type != "UPTIME") { return(false); } try { int year = Convert.ToInt32(date[0]); int month = Convert.ToInt32(date[1]); int day = Convert.ToInt32(date[2]); int hour = Convert.ToInt32(time[0]); int minute = Convert.ToInt32(time[1]); int second = Convert.ToInt32(time[2]); DateTime gateTime = new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc); if (type == "UPTIME") { gateTime.AddMinutes(440); } bot.Configuration.SetInteger(this.InternalName, "gatetime", (Int32)TimeStamp.FromDateTime(gateTime)); this.LoadSettings(bot); return(true); } catch { } return(false); }
public bool Set(ConfigType type, string plugin, string key, object value) { if (!this.IsRegistered(plugin, key)) { return(false); } ConfigType dbType = this.GetType(plugin, key); if (dbType != type) { throw new InvalidCastException("Can't replace type " + dbType.ToString() + " with type " + type.ToString() + " at " + key + "@" + plugin); } if (type == ConfigType.Custom) { throw new ArgumentException("Can not set type Custom!"); } plugin = plugin.ToLower(); key = key.ToLower(); string format; if (!this.Exists(plugin, key)) { format = "INSERT INTO CORE_Settings VALUES ('{0}', '{1}', '{2}', '{3}')"; } else { format = "UPDATE CORE_Settings SET Value = '{3}', Type = '{2}' WHERE Section = '{0}' AND Key = '{1}'"; } try { string valueString; switch (type) { case ConfigType.Color: if (!Regex.Match((string)value, "^[#]?[0-9a-f]{6}$", RegexOptions.IgnoreCase).Success) { return(false); } valueString = (string)value; if (valueString.Length == 7) { valueString = valueString.Substring(1); } break; case ConfigType.String: valueString = (string)value; ConfigurationEntry stringEntry = this.GetEntry(plugin, key); if (stringEntry.Values != null && stringEntry.Values.Length > 0) { List <object> values = new List <object>(stringEntry.Values); if (!values.Contains(value)) { return(false); } } break; case ConfigType.Password: valueString = (string)value; break; case ConfigType.Integer: valueString = ((Int32)value).ToString(); ConfigurationEntry intEntry = this.GetEntry(plugin, key); bool result = (intEntry.Values.Length < 1); foreach (object intEntryValue in intEntry.Values) { try { if ((Int32)intEntryValue == (Int32)value) { result = true; } } catch { } } if (!result) { return(false); } break; case ConfigType.Boolean: valueString = "false"; if ((Boolean)value) { valueString = "true"; } break; case ConfigType.Date: valueString = TimeStamp.FromDateTime((DateTime)value).ToString(); break; case ConfigType.Time: valueString = ((TimeSpan)value).Ticks.ToString(); break; case ConfigType.Dimension: valueString = ((Server)value).ToString(); break; case ConfigType.Username: if (this.Parent.GetUserID((string)value) < 1) { return(false); } valueString = (string)value; break; default: return(false); } string query = string.Format(format, Config.EscapeString(plugin), Config.EscapeString(key), type.ToString(), Config.EscapeString(valueString)); if (this.Config.ExecuteNonQuery(query) > 0) { ConfigurationChangedArgs args = new ConfigurationChangedArgs(type, plugin, key, value); this.Parent.Events.OnConfigurationChanged(this.Parent, args); return(true); } } catch { } return(false); }
public void OnTimersAddCommand(BotShell bot, CommandArgs e) { // Check arguments if (e.Args.Length < 2) { bot.SendReply(e, "Correct Usage: timers add [duration] [description]"); return; } // Parse duration DateTime end = DateTime.UtcNow; DateTime start = DateTime.UtcNow; string[] parts = e.Args[0].Split(':'); int depth = 0; for (int i = parts.Length - 1; i >= 0; i--) { uint part; if (!uint.TryParse(parts[i], out part)) { bot.SendReply(e, "Invalid duration syntax given. The correct syntax is [[[[days:]hours:]minutes:]seconds]"); return; } depth++; switch (depth) { case 1: end = end.AddSeconds(part); break; case 2: end = end.AddMinutes(part); break; case 3: end = end.AddHours(part); break; case 4: end = end.AddDays(part); break; } } TimeSpan duration = end - start; // Save timer long endStamp = TimeStamp.FromDateTime(end); long startStamp = TimeStamp.FromDateTime(start); long durationStamp = (long)Math.Ceiling(duration.TotalSeconds); string description = e.Words[1]; string source = e.Sender; if (e.Type == CommandType.Organization) { source = "gc"; } if (e.Type == CommandType.PrivateChannel) { source = "pg"; } int id = -1; lock (this._database) { using (IDbCommand command = this._database.Connection.CreateCommand()) { command.CommandText = string.Format("INSERT INTO timers (owner, source, start, end, duration, description) VALUES ('{0}', '{1}', {2}, {3}, {4}, '{5}')", e.Sender, source, startStamp, endStamp, durationStamp, Config.EscapeString(description)); if (command.ExecuteNonQuery() < 1) { bot.SendReply(e, "An error has occurred while adding the timer to the database"); return; } command.CommandText = "SELECT LAST_INSERT_ROWID()"; id = (int)(Int64)command.ExecuteScalar(); } } // Save cache CachedTimer timer = new CachedTimer(id, source, e.Sender, start, end, duration, description); lock (this._timers) this._timers.Add(id, timer); bot.SendReply(e, "Timer " + HTML.CreateColorString(bot.ColorHeaderHex, "#" + id) + " with a duration of " + HTML.CreateColorString(bot.ColorHeaderHex, Format.Time(duration, FormatStyle.Large)) + " has been added"); }