Example #1
0
        public async Task TempBanAsync(CommandContext ctx,
                                       [Description("User (doesn't have to be a member).")] DiscordUser user,
                                       [Description("Time span.")] TimeSpan timespan,
                                       [RemainingText, Description("Reason.")] string reason = null)
        {
            if (user.Id == ctx.User.Id)
            {
                throw new CommandFailedException("You can't ban yourself.");
            }

            await ctx.Guild.BanMemberAsync(user.Id, 0, ctx.BuildInvocationDetailsString(reason));

            DateTime until = DateTime.UtcNow + timespan;

            await this.InformAsync(ctx, $"{Formatter.Bold(ctx.User.Username)} BANNED {Formatter.Bold(user.ToString())} until {Formatter.Bold(until.ToLongTimeString())} UTC!");

            var task = new UnbanTaskInfo(ctx.Guild.Id, user.Id, until);
            await SavedTaskExecutor.ScheduleAsync(this.Shared, this.Database, (DiscordClientImpl)ctx.Client, task);
        }
Example #2
0
        public async Task TempBanAsync(CommandContext ctx,
                                       [Description("Time span.")] TimeSpan timespan,
                                       [Description("Member.")] DiscordMember member,
                                       [RemainingText, Description("Reason.")] string reason = null)
        {
            if (member.Id == ctx.User.Id)
            {
                throw new CommandFailedException("You can't ban yourself.");
            }

            await member.BanAsync(delete_message_days : 0, reason : ctx.BuildInvocationDetailsString($"(tempban for {timespan.ToString()}) " + reason));

            DateTimeOffset until = DateTimeOffset.Now + timespan;

            await this.InformAsync(ctx, $"{Formatter.Bold(ctx.User.Username)} BANNED {Formatter.Bold(member.Username)} until {Formatter.Bold(until.ToString())} UTC!");

            var task = new UnbanTaskInfo(ctx.Guild.Id, member.Id, until);
            await SavedTaskExecutor.ScheduleAsync(this.Shared, this.Database, (DiscordClientImpl)ctx.Client, task);
        }
Example #3
0
        public async Task TempBanAsync(CommandContext ctx,
                                       [Description("User (doesn't have to be a member).")] DiscordUser user,
                                       [Description("Time span.")] TimeSpan timespan,
                                       [RemainingText, Description("Reason.")] string reason = null)
        {
            if (user.Id == ctx.User.Id)
            {
                throw new CommandFailedException("You can't ban yourself.");
            }

            if (timespan.TotalMinutes < 1 || timespan.TotalDays > 31)
            {
                throw new InvalidCommandUsageException("Given time period cannot be lower than 1 minute or greater than 1 month");
            }

            await ctx.Guild.BanMemberAsync(user.Id, 0, ctx.BuildInvocationDetailsString(reason));

            DateTime until = DateTime.UtcNow + timespan;

            await this.InformAsync(ctx, $"{ctx.Member.Mention} {Formatter.Bold("BANNED")} {user.ToString()} for {Formatter.Bold(timespan.Humanize(4, minUnit: TimeUnit.Second))}!");

            var task = new UnbanTaskInfo(ctx.Guild.Id, user.Id, until);
            await SavedTaskExecutor.ScheduleAsync(this.Shared, this.Database, ctx.Client, task);
        }
Example #4
0
        public async Task TempBanAsync(CommandContext ctx,
                                       [Description("Time span.")] TimeSpan timespan,
                                       [Description("Member.")] DiscordMember member,
                                       [RemainingText, Description("Reason.")] string reason = null)
        {
            if (member.Id == ctx.User.Id)
            {
                throw new CommandFailedException("You can't ban yourself.");
            }

            if (timespan.TotalMinutes < 1 || timespan.TotalDays > 31)
            {
                throw new InvalidCommandUsageException("Given time period cannot be lower than 1 minute or greater than 1 month");
            }

            await member.BanAsync(delete_message_days : 0, reason : ctx.BuildInvocationDetailsString($"(tempban for {timespan.ToString()}) " + reason));

            var until = DateTimeOffset.Now + timespan;

            await this.InformAsync(ctx, $"{ctx.Member.Mention} {Formatter.Bold("BANNED")} {member.DisplayName} for {Formatter.Bold(timespan.Humanize(4, minUnit: TimeUnit.Second))}!");

            var task = new UnbanTaskInfo(ctx.Guild.Id, member.Id, until);
            await SavedTaskExecutor.ScheduleAsync(this.Shared, this.Database, ctx.Client, task);
        }
        public async Task PunishMemberAsync(DiscordGuild guild, DiscordMember member, PunishmentActionType type)
        {
            try {
                DiscordRole   muteRole;
                SavedTaskInfo task;
                switch (type)
                {
                case PunishmentActionType.Kick:
                    await member.RemoveAsync(this.reason);

                    break;

                case PunishmentActionType.Mute:
                    muteRole = await this.GetOrCreateMuteRoleAsync(guild);

                    if (member.Roles.Contains(muteRole))
                    {
                        return;
                    }
                    await member.GrantRoleAsync(muteRole, this.reason);

                    break;

                case PunishmentActionType.PermanentBan:
                    await member.BanAsync(1, reason : this.reason);

                    break;

                case PunishmentActionType.TemporaryBan:
                    await member.BanAsync(0, reason : this.reason);

                    task = new UnbanTaskInfo(guild.Id, member.Id);
                    await SavedTaskExecutor.ScheduleAsync(this.shard.SharedData, this.shard.DatabaseService, this.shard.Client, task);

                    break;

                case PunishmentActionType.TemporaryMute:
                    muteRole = await this.GetOrCreateMuteRoleAsync(guild);

                    if (member.Roles.Contains(muteRole))
                    {
                        return;
                    }
                    await member.GrantRoleAsync(muteRole, this.reason);

                    task = new UnmuteTaskInfo(guild.Id, member.Id, muteRole.Id);
                    await SavedTaskExecutor.ScheduleAsync(this.shard.SharedData, this.shard.DatabaseService, this.shard.Client, task);

                    break;
                }
            } catch {
                DiscordChannel logchn = this.shard.SharedData.GetLogChannelForGuild(this.shard.Client, guild);
                if (logchn != null)
                {
                    var emb = new DiscordEmbedBuilder()
                    {
                        Title = "User punish attempt failed! Check my permissions",
                        Color = DiscordColor.Red
                    };
                    emb.AddField("User", member?.ToString() ?? "unknown", inline: true);
                    emb.AddField("Reason", this.reason, inline: false);
                    await logchn.SendMessageAsync(embed : emb.Build());
                }
            }
        }