Пример #1
0
        public async Task TempMute(CommandContext ctx, DiscordMember user, TimeSpan duration, [RemainingText] string reason = "Not Given.")
        {
            DiscordMember bot = ctx.Guild.CurrentMember;

            if (user.IsAbove(bot))
            {
                await ctx.RespondAsync($"{user.Username} is {user.Roles.Last().Position - bot.Roles.Last().Position} roles above me!")
                .ConfigureAwait(false);

                return;
            }

            GuildConfigModel config = (await _dbService.GetConfigAsync(ctx.Guild.Id)) !;

            if (config.MuteRoleId is 0)
            {
                await ThrowHelper.MuteRoleNotFoundInDatabase(ctx.Channel);

                return;
            }

            UserInfractionModel infraction = await _infractionService.CreateTemporaryInfractionAsync(user, ctx.Member,
                                                                                                     InfractionType.Mute, reason, DateTime.Now.Add(duration));

            await _infractionService.MuteAsync(user, ctx.Channel, infraction);
        }
Пример #2
0
        public async Task TempBan(
            CommandContext ctx, DiscordMember user, string duration,
            [RemainingText] string reason = "Not provided.")
        {
            SilkDbContext       db          = DbFactory.CreateDbContext();
            DiscordMember       bot         = ctx.Guild.CurrentMember;
            DateTime            now         = DateTime.Now;
            TimeSpan            banDuration = GetTimeFromInput(duration);
            BanFailureReason?   banFailed   = CanBan(bot, ctx.Member, user);
            DiscordEmbedBuilder embed       =
                new DiscordEmbedBuilder().WithAuthor(bot.Username, ctx.GetBotUrl(), ctx.Client.CurrentUser.AvatarUrl);

            if (banFailed is not null)
            {
                await SendFailureMessage(ctx, user, embed, banFailed);
            }
            else
            {
                DiscordEmbedBuilder banEmbed = new DiscordEmbedBuilder()
                                               .WithAuthor(ctx.User.Username, ctx.User.GetUrl(), ctx.User.AvatarUrl)
                                               .WithDescription($"You've been temporarily banned from {ctx.Guild.Name} for {duration} days.")
                                               .AddField("Reason:", reason);

                await user.SendMessageAsync(embed : banEmbed);

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

                GuildModel guild = db.Guilds.First(g => g.Id == ctx.Guild.Id);

                UserModel?bannedUser         = db.Users.FirstOrDefault(u => u.Id == user.Id);
                string    formattedBanReason = InfractionFormatHandler.ParseInfractionFormat("temporarily banned",
                                                                                             banDuration.TotalDays + " days", user.Mention, reason, guild.Configuration.InfractionFormat ?? defaultFormat);
                UserInfractionModel infraction = CreateInfraction(formattedBanReason, ctx.User.Id, now);
                if (bannedUser is null)
                {
                    bannedUser = new UserModel
                    {
                        Infractions = new List <UserInfractionModel>()
                    };
                    db.Users.Add(bannedUser);
                    bannedUser.Infractions.Add(infraction);
                }

                if (guild.Configuration.GeneralLoggingChannel != default)
                {
                    embed.WithDescription(formattedBanReason);
                    embed.WithColor(DiscordColor.Green);
                    await ctx.Guild.GetChannel(guild.Configuration.GeneralLoggingChannel).SendMessageAsync(embed: embed);
                }

                EventService.Events.Add(new TimedInfraction(user.Id, ctx.Guild.Id, DateTime.Now.Add(banDuration),
                                                            reason, e => _ = OnBanExpiration((TimedInfraction)e)));
            }
        }