Example #1
0
            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);
            }
Example #2
0
            public async Task Repeat(GuildDateTime dt, params string[] options)
            {
                if (!_service.RepeaterReady)
                {
                    return;
                }

                var(opts, _) = OptionsParser.ParseFrom(new Repeater.Options(), options);

                if (string.IsNullOrWhiteSpace(opts.Message) || opts.Interval >= 50001)
                {
                    return;
                }

                var toAdd = new Repeater()
                {
                    ChannelId      = ctx.Channel.Id,
                    GuildId        = ctx.Guild.Id,
                    Interval       = TimeSpan.FromMinutes(opts.Interval),
                    Message        = opts.Message,
                    NoRedundant    = opts.NoRedundant,
                    StartTimeOfDay = dt?.InputTimeUtc.TimeOfDay,
                };

                using (var uow = _db.GetDbContext())
                {
                    var gc = uow.GuildConfigs.ForId(ctx.Guild.Id, set => set.Include(x => x.GuildRepeaters));

                    if (gc.GuildRepeaters.Count >= 5)
                    {
                        return;
                    }
                    gc.GuildRepeaters.Add(toAdd);

                    await uow.SaveChangesAsync();
                }

                var rep = new RepeatRunner((SocketGuild)ctx.Guild, toAdd, _service);

                _service.Repeaters.AddOrUpdate(ctx.Guild.Id,
                                               new ConcurrentDictionary <int, RepeatRunner>(new[] { new KeyValuePair <int, RepeatRunner>(toAdd.Id, rep) }), (key, old) =>
                {
                    old.TryAdd(rep.Repeater.Id, 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 ctx.Channel.SendConfirmAsync(
                    "🔁 " + GetText("repeater",
                                   Format.Bold(((IGuildUser)ctx.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);
            }
Example #3
0
            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);
            }
Example #4
0
            public async Task Repeat(GuildDateTime dt, params string[] options)
            {
                if (!_service.RepeaterReady)
                {
                    return;
                }

                var(opts, _) = OptionsParser.ParseFrom(new Repeater.Options(), options);

                if (string.IsNullOrWhiteSpace(opts.Message) || opts.Interval >= 50001)
                {
                    return;
                }

                var startTimeOfDay = dt?.InputTimeUtc.TimeOfDay;

                // if interval not null, that means user specified it (don't change it)

                // if interval is null set the default to:
                // if time of day is specified: 24 * 60 (24h)
                // else 5
                var realInterval = opts.Interval ?? (startTimeOfDay is null ? 5 : 24 * 60);

                var toAdd = new Repeater()
                {
                    ChannelId      = ctx.Channel.Id,
                    GuildId        = ctx.Guild.Id,
                    Interval       = TimeSpan.FromMinutes(realInterval),
                    Message        = opts.Message,
                    NoRedundant    = opts.NoRedundant,
                    StartTimeOfDay = startTimeOfDay,
                };

                using (var uow = _db.GetDbContext())
                {
                    var gc = uow.GuildConfigs.ForId(ctx.Guild.Id, set => set.Include(x => x.GuildRepeaters));

                    if (gc.GuildRepeaters.Count >= 5)
                    {
                        return;
                    }
                    gc.GuildRepeaters.Add(toAdd);

                    await uow.SaveChangesAsync();
                }

                var runner = new RepeatRunner(_client, (SocketGuild)ctx.Guild, toAdd, _service);

                _service.Repeaters.AddOrUpdate(ctx.Guild.Id,
                                               new ConcurrentDictionary <int, RepeatRunner>(new[] { new KeyValuePair <int, RepeatRunner>(toAdd.Id, runner) }), (key, old) =>
                {
                    old.TryAdd(runner.Repeater.Id, runner);
                    return(old);
                });

                var description = GetRepeaterInfoString(runner);
                await ctx.Channel.EmbedAsync(new EmbedBuilder()
                                             .WithOkColor()
                                             .WithTitle(GetText("repeater_created"))
                                             .WithDescription(description));
            }
Example #5
0
 public Task Repeat(GuildDateTime dt, [Leftover] string message)
 => Repeat(dt, null, message);