예제 #1
0
        public async Task ListBansAsync(IGuildUser user)
        {
            var bans = _bans.GetBans(user);

            var appearance = PaginatedAppearanceOptions.Default;

            appearance.Title = "Bans";
            appearance.Color = Color.Orange;

            var paginatedEmbed = await PaginatedEmbedFactory.PagesFromCollectionAsync
                                 (
                _feedback,
                _interactivity,
                this.Context.User,
                bans,
                async (eb, ban) =>
            {
                eb.WithTitle($"Ban #{ban.ID} for {user.Username}:{user.Discriminator}");

                var author = await this.Context.Guild.GetUserAsync((ulong)ban.Author.DiscordID);
                eb.WithAuthor(author);

                eb.WithDescription(ban.Reason);

                eb.AddField("Created", ban.CreatedAt);

                if (ban.CreatedAt != ban.UpdatedAt)
                {
                    eb.AddField("Last Updated", ban.UpdatedAt);
                }

                if (ban.IsTemporary)
                {
                    eb.AddField("Expires On", ban.ExpiresOn);
                }

                if (!(ban.MessageID is null))
                {
                    // TODO
                }
            },
                appearance : appearance
                                 );

            await _interactivity.SendInteractiveMessageAndDeleteAsync
            (
                this.Context.Channel,
                paginatedEmbed,
                TimeSpan.FromMinutes(5)
            );
        }
        /// <inheritdoc/>
        protected override async Task OnTickAsync(CancellationToken ct)
        {
            if (this.Client.ConnectionState != ConnectionState.Connected)
            {
                // Give the client some time to start up
                await Task.Delay(TimeSpan.FromSeconds(5), ct);

                return;
            }

            var now = DateTime.UtcNow;

            foreach (var guild in this.Client.Guilds)
            {
                var warnings = _warnings.GetWarnings(guild).Where(w => w.IsTemporary);
                foreach (var warning in warnings)
                {
                    if (warning.ExpiresOn <= now)
                    {
                        await _warnings.DeleteWarningAsync(warning);
                    }
                }

                if (!guild.GetUser(this.Client.CurrentUser.Id).GuildPermissions.BanMembers)
                {
                    // No point in trying to rescind bans if the bot doesn't have ban perms
                    continue;
                }

                var bans = _bans.GetBans(guild).Where(b => b.IsTemporary);
                foreach (var ban in bans)
                {
                    if (ban.ExpiresOn <= now)
                    {
                        await _bans.DeleteBanAsync(ban);

                        await guild.RemoveBanAsync((ulong)ban.User.DiscordID);
                    }
                }
            }

            await Task.Delay(TimeSpan.FromHours(1), ct);
        }