public async Task TriggerAdd(string calendarName, string tagPrimary = null, string tagSecondary = null, bool mentionEveryone = false, IRole mentionRole = null) { if (tagPrimary == "*") { tagPrimary = null; } if (tagSecondary == "*") { tagSecondary = null; } if (_calendar[calendarName] != null) { if (_calendar[calendarName].Triggers.Any(x => x.GuildID == Context.Guild.Id && x.ChannelID == Context.Channel.Id)) { await ReplyAsync("This calendar already has a trigger in this channel!"); return; } if (mentionRole != null && !mentionRole.IsMentionable) { await ReplyAsync("The specified role is not mentionable!"); return; } _calendar[calendarName].Triggers.Add(new DICalendarTrigger() { GuildID = Context.Guild.Id, ChannelID = Context.Channel.Id, TagPrimary = tagPrimary, TagSecondary = tagSecondary, RoleId = mentionRole?.Id ?? 0, Everyone = mentionEveryone }); DICalendar.SaveCalendar(_calendar[calendarName]); await ReplyAsync("The trigger was successfully added!"); } else { await ReplyAsync("That calendar is not configured!"); } }
private void CalendarLoop(object sender, ElapsedEventArgs evt) { _timer.Enabled = false; _timer.Interval = 300000; if (_diCals == null) { _diCals = new Dictionary <string, DICalendar>(); foreach (var cal in ConfigUtil.Config.Calendars) { _diCals.Add(cal, File.Exists("calendars/" + cal) ? DICalendar.LoadCalendar(cal) : new DICalendar(cal)); } } var handler = new HttpClientHandler(); handler.CookieContainer = new CookieContainer(); ConfigUtil.Config.AuthConfig.Cookies .Select(x => new System.Net.Cookie(x.Name, x.Value, x.Path, x.Domain)) .ToList() .ForEach(x => handler.CookieContainer.Add(x)); var client = new DIHttpClient(handler); foreach (var cal in ConfigUtil.Config.Calendars) { var vCal = Calendar.Load(client .GetCalendarAsync(cal) .GetAwaiter().GetResult()); lock (_diCals[cal]) { _diCals[cal].ProcessEvents(vCal, _discord, _mdr); DICalendar.SaveCalendar(_diCals[cal]); } } _timer.Enabled = true; }
public async Task TriggerDelete(string calendarName) { if (_calendar[calendarName] != null) { if (!_calendar[calendarName].Triggers.Any(x => x.GuildID == Context.Guild.Id && x.ChannelID == Context.Channel.Id)) { await ReplyAsync("This channel has no trigger for this calendar!"); return; } _calendar[calendarName].Triggers.RemoveAll(x => x.GuildID == Context.Guild.Id && x.ChannelID == Context.Channel.Id); DICalendar.SaveCalendar(_calendar[calendarName]); await ReplyAsync("The trigger was successfully deleted!"); } else { await ReplyAsync("That calendar is not configured!"); } }