Exemplo n.º 1
0
 public RepeatRunner(Repeater repeater, ITextChannel channel = null)
 {
     _log = LogManager.GetCurrentClassLogger();
     this.Repeater = repeater;
     this.Channel = channel ?? NadekoBot.Client.GetGuild(repeater.GuildId)?.GetTextChannel(repeater.ChannelId);
     if (Channel == null)
         return;
     Task.Run(Run);
 }
Exemplo n.º 2
0
            public async Task Repeat(IUserMessage imsg, int minutes, [Remainder] string message)
            {
                var channel = (ITextChannel)imsg.Channel;

                if (minutes < 1 || minutes > 10080)
                    return;

                if (string.IsNullOrWhiteSpace(message))
                    return;

                RepeatRunner rep;

                rep = repeaters.AddOrUpdate(channel.Id, (cid) =>
                {
                    using (var uow = DbHandler.UnitOfWork())
                    {
                        var localRep = new Repeater
                        {
                            ChannelId = channel.Id,
                            GuildId = channel.Guild.Id,
                            Interval = TimeSpan.FromMinutes(minutes),
                            Message = message,
                        };
                        uow.Repeaters.Add(localRep);
                        uow.Complete();
                        return new RepeatRunner(localRep, channel);
                    }
                }, (cid, old) =>
                {
                    using (var uow = DbHandler.UnitOfWork())
                    {
                        old.Repeater.Message = message;
                        old.Repeater.Interval = TimeSpan.FromMinutes(minutes);
                        uow.Repeaters.Update(old.Repeater);
                        uow.Complete();
                    }
                    old.Reset();
                    return old;
                });

                await channel.SendMessageAsync($"🔁 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);
            }