public void Complete(ISchedulerContext context, bool wasCancelled) { if (context.Guild == null) { return; } var data = TitanLordTimerData.FromJson(context.Record.Data); var settings = context.GuildSettings.Get <TitanLordSettings>(data.GroupId); var messageChannel = context.Client.GetChannel(data.MessageChannelId) as IMessageChannel; if (messageChannel == null || context.Author == null) { return; } if (data.MessageId != 0) { var message = messageChannel?.GetMessageAsync(data.MessageId)?.Result as IUserMessage; message?.DeleteAsync().Wait(); } if (!wasCancelled) { context.Replier.Reply(messageChannel, context.Author).WithMessage((RawString)settings.NowText.Contextualise(settings.CQ, context.Record, context.Record.EndTime, context.GeneralGuildSetting.DateTimeFormat)).Send(); var history = Database?.AddOrGet(context.Guild.Id, () => new TitanLordHistory()).Result; history?.SpawnTimes.Add(context.CycleTime); Database?.Upsert(history); } }
public bool Handle(ISchedulerContext context) { if (_lastCall.TryGetValue(context.Record.Id, out var lastTime) && lastTime > DateTime.Now.AddSeconds(-5)) { return(true); } _lastCall.AddOrUpdate(context.Record.Id, DateTime.Now, (u, d) => DateTime.Now > d ? DateTime.Now : d); if (context.Guild == null) { return(false); } var data = TitanLordTimerData.FromJson(context.Record.Data); var settings = context.GuildSettings.Get <TitanLordSettings>(data.GroupId); var actualTime = context.Record.EndTime.AddTicks(-((context.Record.EndTime - context.CycleTime + context.Delay).Ticks / context.Record.Interval.Ticks) * context.Record.Interval.Ticks); var messageChannel = context.Client.GetChannel(data.MessageChannelId) as IMessageChannel; if (messageChannel == null || context.Author == null) { return(false); } if (data.MessageId != 0) { if (messageChannel?.GetMessageAsync(data.MessageId)?.Result is IUserMessage message) { context.Replier.Modify(message, context.Author).ChangeMessage((RawString)settings.TimerText.Contextualise(settings.CQ, context.Record, actualTime, context.GeneralGuildSetting.DateTimeFormat)).Modify(); } } foreach (var ping in settings.PrePings) { var pingTime = context.Record.EndTime.AddTicks(-ping * TimeSpan.TicksPerSecond); if (pingTime.Between(context.CycleTime, context.CycleTime + context.Delay + context.Record.Interval)) { context.Replier.Reply(messageChannel, context.Author).WithMessage((RawString)settings.InXText.Contextualise(settings.CQ, context.Record, pingTime, context.GeneralGuildSetting.DateTimeFormat)).Send(); } } return(true); }
private async Task TitanLordNowAsync() { CancelCurrent(); var startTime = DateTime.Now.AddHours(-6); var data = new TitanLordTimerData { MessageChannelId = Client.GetChannel(TitanLordSettings.Channel ?? Channel.Id).Id }; StartTimers(startTime, data); await ReplyAsync("Ill let everyone know", ReplyType.Success); }
private async Task TitanLordNowAsync([CallFlag('g', "Group", Flag.TITANLORD_G)] string group = null) { var groupId = GetGroup(group); CancelCurrent(groupId); var startTime = DateTime.Now.Add(-BossDelay); var data = new TitanLordTimerData { MessageChannelId = Client.GetChannel(TitanLordSettings(groupId).Channel ?? Channel.Id).Id, GroupId = groupId }; StartTimers(startTime, data); await ReplyAsync(TitanLordText.NOW_SUCCESS, ReplyType.Success); }
public bool Handle(ISchedulerContext context) { if (context.Guild == null) { return(false); } var data = TitanLordTimerData.FromJson(context.Record.Data); var settings = context.GuildSettings.Get <TitanLordSettings>(data.GroupId); var messageChannel = context.Client.GetChannel(data.MessageChannelId) as IMessageChannel; if (settings.RoundPings && messageChannel != null && context.Author != null) { context.Replier.Reply(messageChannel, context.Author).WithMessage((RawString)settings.RoundText.Contextualise(settings.CQ, context.Record, context.CycleTime, context.GeneralGuildSetting.DateTimeFormat)).Send(); } return(true); }
private async Task LockedTitanLordIn(TimeSpan time) { if (time > new TimeSpan(6, 0, 0)) { await ReplyAsync("You cannot set a timer for longer than 6 hours", ReplyType.Error); return; } (var ticks, var rounds) = CancelCurrent(); var startTime = DateTime.Now.Add(time).AddHours(-6); var tlChannel = Client.GetChannel(TitanLordSettings.Channel ?? Channel.Id) as IMessageChannel; if (ticks.Length == 0) { var mostRecent = Scheduler.GetMostRecent <TitanLordTickCallback>(Guild.Id); if (mostRecent != null && mostRecent.EndTime > mostRecent.StartTime.AddHours(6)) { await ReplyAsync(tlChannel, "", embed : NewBoss(time)); } } var timer = await ReplyAsync(tlChannel, "Loading timer...\n_If this takes longer than 20s please let Titansmasher know_"); var data = new TitanLordTimerData { MessageChannelId = tlChannel.Id, MessageId = timer.Id }; StartTimers(startTime, data); await ReplyAsync($"Set a timer running for {time}", ReplyType.Success); }
private async Task LockedTitanLordIn(TimeSpan time, string group) { var groupId = GetGroup(group); if (time > BossDelay) { await ReplyAsync(TitanLordText.TIMER_TOOLONG, ReplyType.Error); return; } ISchedulerRecord[] ticks, rounds; try { (ticks, rounds) = CancelCurrent(groupId); } catch (Exception) { // Send error msg to user const string errorStr = "Unfortunately a critical, and thankfully very rare, bug has occured with regards to the use of the titanlord command in this discord server. " + "Unfortunately the only known fix for now is to wait it out. It can take around 24 hours for the bug to go away on its own. " + "If you have any questions feel free to join our developer server. If you find a way to reproduce the bug, we'd very much like to hear from you!"; var builderUser = new EmbedBuilder { Color = Color.Red, Timestamp = DateTime.Now, Title = "An error occured", Description = errorStr }; await ReplyAsync(builderUser); // Send error info to developer channel var channel = Client.GetChannel(347122777897041921) as IMessageChannel; var builder = new EmbedBuilder { Author = new EmbedAuthorBuilder { Name = $"{Author?.Username}#{Author?.Discriminator}" }, Timestamp = DateTime.Now } .AddField("Message", $"Failed to cancel current titanlord for **unknown** group with groupId {groupId}") .AddField("Guild", $"Failed in guild id {Guild?.Id} with name: {Guild?.Name}"); await Reply(channel).WithEmbedable((Embedable)builder).SendAsync(); return; } var startTime = DateTime.Now.Add(time).Add(-BossDelay); var tlChannel = Client.GetChannel(TitanLordSettings(groupId).Channel ?? Channel.Id) as IMessageChannel; if (ticks.Length == 1) { var history = await Database.AddOrGet(Guild.Id, () => new TitanLordHistory()); if (history.SpawnTimes.Count != 0) { await Reply(tlChannel).WithEmbedable(NewBoss(history.SpawnTimes.Max(), time, TitanLordSettings(groupId))).SendAsync(); } } var timer = await Reply(tlChannel).WithMessage((LocalisedString)TitanLordText.TIMER_LOADING) .SendAsync(); if (TitanLordSettings(groupId).PinTimer) { try { await timer.PinAsync(); } catch { } // ... This needs to be logged } var data = new TitanLordTimerData { MessageChannelId = tlChannel.Id, MessageId = timer.Id, GroupId = groupId }; StartTimers(startTime, data); await ReplyAsync(TitanLordText.TIMER_SET, ReplyType.Success, time); }