// 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 <CustomResult> UnMuteUser(ulong userId, ulong muteId) { var bot = Global.Bot; var guild = bot.GetGuild(Global.ServerID); var user = guild.GetUser(userId); if (user == null) { UnMuteUserCompletely(userId); return(CustomResult.FromError("User is not in the server anymore. User was unmuted in the database.")); } var result = await OnePlusBot.Helpers.Extensions.UnMuteUser(user); if (!result.IsSuccess) { return(result); } using (var db = new Database()) { if (muteId == UInt64.MaxValue) { // this is in case we directly unmute a person via a command, just set all of the mutes to ended, in case there are more than one UnMuteUserCompletely(userId, db); } else { var muteObj = db.Mutes.Where(x => x.ID == muteId).ToList().First(); if (!muteObj.MuteEnded) { muteObj.MuteEnded = true; var noticeEmbed = new EmbedBuilder(); noticeEmbed.Color = Color.LightOrange; noticeEmbed.Title = "User has been unmuted!"; noticeEmbed.ThumbnailUrl = user.GetAvatarUrl(); noticeEmbed.AddField("Unmuted User", OnePlusBot.Helpers.Extensions.FormatUserName(user)) .AddField("Mute Id", muteId) .AddField("Mute duration", Extensions.FormatTimeSpan(DateTime.Now - muteObj.MuteDate)) .AddField("Muted since", $"{ muteObj.MuteDate:dd.MM.yyyy HH:mm}"); await guild.GetTextChannel(Global.Channels["mutes"]).SendMessageAsync(embed: noticeEmbed.Build()); } } db.SaveChanges(); } return(result); }
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()); }