public async Task Repeat(GuildDateTime gt, [Remainder] string message) { if (!_service.RepeaterReady) { return; } if (string.IsNullOrWhiteSpace(message)) { return; } var toAdd = new GuildRepeater() { ChannelId = Context.Channel.Id, GuildId = Context.Guild.Id, Interval = TimeSpan.FromHours(24), StartTimeOfDay = gt.InputTimeUtc.TimeOfDay, Message = message }; using (var uow = _db.UnitOfWork) { var gc = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.GuildRepeaters)); if (gc.GuildRepeaters.Count >= 5) { return; } gc.GuildRepeaters.Add(toAdd); await uow.CompleteAsync().ConfigureAwait(false); } var rep = new RepeatRunner(_client, (SocketGuild)Context.Guild, toAdd); _service.Repeaters.AddOrUpdate(Context.Guild.Id, new ConcurrentQueue <RepeatRunner>(new[] { rep }), (key, old) => { old.Enqueue(rep); return(old); }); var secondPart = GetText("repeater_initial", Format.Bold(rep.InitialInterval.Hours.ToString()), Format.Bold(rep.InitialInterval.Minutes.ToString())); await Context.Channel.SendConfirmAsync( "🔁 " + GetText("repeater", Format.Bold(((IGuildUser)Context.User).GuildPermissions.MentionEveryone ? rep.Repeater.Message : rep.Repeater.Message.SanitizeMentions()), Format.Bold(rep.Repeater.Interval.Days.ToString()), Format.Bold(rep.Repeater.Interval.Hours.ToString()), Format.Bold(rep.Repeater.Interval.Minutes.ToString())) + " " + secondPart).ConfigureAwait(false); }
public async Task Repeat(int minutes, [Remainder] string message) { if (!_ready) { return; } if (minutes < 1 || minutes > 10080) { return; } if (string.IsNullOrWhiteSpace(message)) { return; } var toAdd = new GuildRepeater() { ChannelId = Context.Channel.Id, GuildId = Context.Guild.Id, Interval = TimeSpan.FromMinutes(minutes), Message = message }; using (var uow = DbHandler.UnitOfWork()) { var gc = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.GuildRepeaters)); if (gc.GuildRepeaters.Count >= 5) { return; } gc.GuildRepeaters.Add(toAdd); await uow.CompleteAsync().ConfigureAwait(false); } var rep = new RepeatRunner(toAdd, (ITextChannel)Context.Channel); Repeaters.AddOrUpdate(Context.Guild.Id, new ConcurrentQueue <RepeatRunner>(new[] { rep }), (key, old) => { old.Enqueue(rep); return(old); }); await Context.Channel.SendConfirmAsync( "🔁 " + GetText("repeater", Format.Bold(((IGuildUser)Context.User).GuildPermissions.MentionEveryone ? rep.Repeater.Message : rep.Repeater.Message.SanitizeMentions()), Format.Bold(rep.Repeater.Interval.Days.ToString()), Format.Bold(rep.Repeater.Interval.Hours.ToString()), Format.Bold(rep.Repeater.Interval.Minutes.ToString()))).ConfigureAwait(false); }
public async Task Repeat(int minutes, [Remainder] string message) { if (minutes < 1 || minutes > 10080) { return; } if (string.IsNullOrWhiteSpace(message)) { return; } var toAdd = new GuildRepeater() { ChannelId = Context.Channel.Id, GuildId = Context.Guild.Id, Interval = TimeSpan.FromMinutes(minutes), Message = message }; using (var uow = DbHandler.UnitOfWork()) { var gc = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.GuildRepeaters)); if (gc.GuildRepeaters.Count >= 5) { return; } gc.GuildRepeaters.Add(toAdd); await uow.CompleteAsync().ConfigureAwait(false); } var rep = new RepeatRunner(toAdd, (ITextChannel)Context.Channel); repeaters.AddOrUpdate(Context.Guild.Id, new ConcurrentQueue <RepeatRunner>(new[] { rep }), (key, old) => { old.Enqueue(rep); return(old); }); await Context.Channel.SendConfirmAsync($"🔁 Repeating **\"{rep.Repeater.Message}\"** every `{rep.Repeater.Interval.Days} day(s), {rep.Repeater.Interval.Hours} hour(s) and {rep.Repeater.Interval.Minutes} minute(s)`.").ConfigureAwait(false); }
public async Task Repeat(GuildDateTime dt, params string[] options) { if (!_service.RepeaterReady) { return; } var(opts, _) = OptionsParser.Default.ParseFrom(new Repeater.Options(), options); if (string.IsNullOrWhiteSpace(opts.Message)) { return; } var toAdd = new GuildRepeater() { ChannelId = Context.Channel.Id, GuildId = Context.Guild.Id, Interval = TimeSpan.FromMinutes(opts.Interval), Message = opts.Message, NoRedundant = opts.NoRedundant, StartTimeOfDay = dt?.InputTimeUtc.TimeOfDay, }; using (var uow = _db.UnitOfWork) { var gc = uow.GuildConfigs.For(Context.Guild.Id, set => set.Include(x => x.GuildRepeaters)); if (gc.GuildRepeaters.Count >= 5) { return; } gc.GuildRepeaters.Add(toAdd); await uow.CompleteAsync().ConfigureAwait(false); } var rep = new RepeatRunner(_client, (SocketGuild)Context.Guild, toAdd); _service.Repeaters.AddOrUpdate(Context.Guild.Id, new ConcurrentQueue <RepeatRunner>(new[] { rep }), (key, old) => { old.Enqueue(rep); return(old); }); string secondPart = ""; if (dt != null) { secondPart = GetText("repeater_initial", Format.Bold(rep.InitialInterval.Hours.ToString()), Format.Bold(rep.InitialInterval.Minutes.ToString())); } await Context.Channel.SendConfirmAsync( "🔁 " + GetText("repeater", Format.Bold(((IGuildUser)Context.User).GuildPermissions.MentionEveryone ? rep.Repeater.Message : rep.Repeater.Message.SanitizeMentions()), Format.Bold(rep.Repeater.Interval.Days.ToString()), Format.Bold(rep.Repeater.Interval.Hours.ToString()), Format.Bold(rep.Repeater.Interval.Minutes.ToString())) + " " + secondPart).ConfigureAwait(false); }