// TODO refactor this and MuteTimerManager to have a common abstract class or at least an interface public async Task <RuntimeResult> SetupTimers() { TimeSpan thisMidnight = DateTime.Today.AddDays(1) - DateTime.Now; int secondsToDelay = (int)thisMidnight.TotalSeconds; await Task.Delay(secondsToDelay * 1000); await DecayWarnings(); System.Timers.Timer timer = new System.Timers.Timer(1000 * 60 * 60 * 24); timer.Elapsed += new System.Timers.ElapsedEventHandler(TriggerDecay); timer.Enabled = true; return(CustomResult.FromSuccess()); }
// TODO refactor this and MuteTimerManager to have a common abstract class or at least an interface public async Task <RuntimeResult> SetupTimers() { await ExecuteReminderLogic(true); await Extensions.DelayUntilNextFullHour(); await ExecuteReminderLogic(false); System.Timers.Timer timer1 = new System.Timers.Timer(1000 * 60 * 60); timer1.Elapsed += new System.Timers.ElapsedEventHandler(TriggerTimer); timer1.Enabled = true; return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> SetupTimers() { TimeSpan sinceMidnight = DateTime.Now.TimeOfDay; TimeSpan nextMinute = TimeSpan.FromMinutes(Math.Ceiling(sinceMidnight.TotalMinutes)); TimeSpan timeSpanToDelay = (nextMinute - sinceMidnight); // dont trigger exactly on the zero second, but on the :30 second and do the minute before int secondsToDelay = (int)timeSpanToDelay.TotalSeconds + 30; await Task.Delay(secondsToDelay * 1000); await PersistExp(); System.Timers.Timer timer = new System.Timers.Timer(1000 * 60 * 1); timer.Elapsed += new System.Timers.ElapsedEventHandler(TriggerPersitence); timer.Enabled = true; return(CustomResult.FromSuccess()); }
public async Task <RuntimeResult> SetupTimers() { if (CommandHandler.FeatureFlagDisabled(FeatureFlag.MODERATION)) { return(CustomResult.FromSuccess()); } await ExecuteMuteLogic(true); await Extensions.DelayUntilNextFullHour(); await ExecuteMuteLogic(false); System.Timers.Timer timer1 = new System.Timers.Timer(1000 * 60 * 60); timer1.Elapsed += new System.Timers.ElapsedEventHandler(TriggerTimer); timer1.Enabled = true; return(CustomResult.FromSuccess()); }
public static async Task <RuntimeResult> SetupTimers(Boolean startup) { var bot = Global.Bot; var guild = bot.GetGuild(Global.ServerID); var iGuildObj = (IGuild)guild; using (var db = new Database()) { var maxDate = DateTime.Now.AddHours(1); var allusers = await iGuildObj.GetUsersAsync(); var mutesInFuture = db.Mutes.Where(x => x.UnmuteDate < maxDate && !x.MuteEnded).ToList(); if (mutesInFuture.Any()) { foreach (var futureUnmute in mutesInFuture) { var userObj = allusers.FirstOrDefault(x => x.Id == futureUnmute.MutedUserID); await Task.Delay(1 * 1000); var timeToUnmute = futureUnmute.UnmuteDate - DateTime.Now; if (timeToUnmute.TotalMilliseconds < 0) { timeToUnmute = TimeSpan.FromSeconds(1); } // the reason why I am dragging the IDs into the function call is to be sure, that the objects are still valid when the unmute function is executed UnmuteUserIn(userObj.Id, timeToUnmute, futureUnmute.ID); } } } if (startup) { System.Timers.Timer timer1 = new System.Timers.Timer(1000 * 60 * 60); timer1.Elapsed += new System.Timers.ElapsedEventHandler(TriggerTimer); timer1.Enabled = true; } return(CustomResult.FromSuccess()); }