public bool WarnPunish(ulong guildId, int number, PunishmentAction punish, StoopidTime time)
        {
            if ((punish != PunishmentAction.Ban && punish != PunishmentAction.Mute) && time != null)
            {
                return(false);
            }
            if (number <= 0 || (time != null && time.Time > TimeSpan.FromDays(49)))
            {
                return(false);
            }

            using (var uow = _db.GetDbContext())
            {
                var ps       = uow.GuildConfigs.ForId(guildId, set => set.Include(x => x.WarnPunishments)).WarnPunishments;
                var toDelete = ps.Where(x => x.Count == number);

                uow._context.RemoveRange(toDelete);

                ps.Add(new WarningPunishment()
                {
                    Count      = number,
                    Punishment = punish,
                    Time       = (int?)(time?.Time.TotalMinutes) ?? 0,
                });
                uow.SaveChanges();
            }
            return(true);
        }
Beispiel #2
0
        public bool WarnPunish(ulong guildId, int number, PunishmentAction punish, StoopidTime time)
        {
            if ((punish != PunishmentAction.Ban && punish != PunishmentAction.Mute) && time != null)
            {
                return(false);
            }
            if (number <= 0 || (time != null && time.Time > TimeSpan.FromDays(49)))
            {
                return(false);
            }

            using (var uow = _db.UnitOfWork)
            {
                var ps = uow.GuildConfigs.ForId(guildId, set => set.Include(x => x.WarnPunishments)).WarnPunishments;
                ps.RemoveAll(x => x.Count == number);

                ps.Add(new WarningPunishment()
                {
                    Count      = number,
                    Punishment = punish,
                    Time       = (int?)(time?.Time.TotalMinutes) ?? 0,
                });
                uow.Complete();
            }
            return(true);
        }
Beispiel #3
0
            public async Task InternalAntiSpam(int messageCount, PunishmentAction action,
                                               StoopidTime timeData = null, IRole role = null)
            {
                if (messageCount < 2 || messageCount > 10)
                {
                    return;
                }

                if (!(timeData is null))
                {
                    if (!_service.IsDurationAllowed(action))
                    {
                        await ReplyErrorLocalizedAsync("prot_cant_use_time");
                    }
                }

                var time = (int?)timeData?.Time.TotalMinutes ?? 0;

                if (time < 0 || time > 60 * 24)
                {
                    return;
                }

                var stats = await _service.StartAntiSpamAsync(ctx.Guild.Id, messageCount, action, time, role?.Id).ConfigureAwait(false);

                await ctx.Channel.SendConfirmAsync(GetText("prot_enable", "Anti-Spam"),
                                                   $"{ctx.User.Mention} {GetAntiSpamString(stats)}").ConfigureAwait(false);
            }
            public async Task WarnPunish(int number, PunishmentAction punish, StoopidTime time = null)
            {
                // this should never happen. Addrole has its own method with higher priority
                if (punish == PunishmentAction.AddRole)
                {
                    return;
                }

                var success = _service.WarnPunish(ctx.Guild.Id, number, punish, time);

                if (!success)
                {
                    return;
                }

                if (time is null)
                {
                    await ReplyConfirmLocalizedAsync("warn_punish_set",
                                                     Format.Bold(punish.ToString()),
                                                     Format.Bold(number.ToString())).ConfigureAwait(false);
                }
                else
                {
                    await ReplyConfirmLocalizedAsync("warn_punish_set_timed",
                                                     Format.Bold(punish.ToString()),
                                                     Format.Bold(number.ToString()),
                                                     Format.Bold(time.Input)).ConfigureAwait(false);
                }
            }
Beispiel #5
0
            public async Task WarnPunish(int number, AddRole _, IRole role, StoopidTime time = null)
            {
                var punish  = PunishmentAction.AddRole;
                var success = _service.WarnPunish(ctx.Guild.Id, number, punish, time, role);

                if (ctx.Guild.OwnerId != ctx.User.Id &&
                    role.Position >= ((IGuildUser)ctx.User).GetRoles().Max(x => x.Position))
                {
                    await ReplyErrorLocalizedAsync("role_too_high");

                    return;
                }

                if (!success)
                {
                    return;
                }

                if (time is null)
                {
                    await ReplyConfirmLocalizedAsync("warn_punish_set",
                                                     Format.Bold(punish.ToString()),
                                                     Format.Bold(number.ToString())).ConfigureAwait(false);
                }
                else
                {
                    await ReplyConfirmLocalizedAsync("warn_punish_set_timed",
                                                     Format.Bold(punish.ToString()),
                                                     Format.Bold(number.ToString()),
                                                     Format.Bold(time.Input)).ConfigureAwait(false);
                }
            }
            public async Task Ban(StoopidTime time, IGuildUser user, [Leftover] string msg = null)
            {
                if (time.Time > TimeSpan.FromDays(49))
                {
                    return;
                }
                if (ctx.User.Id != user.Guild.OwnerId && (user.GetRoles().Select(r => r.Position).Max() >= ((IGuildUser)ctx.User).GetRoles().Select(r => r.Position).Max()))
                {
                    await ReplyErrorLocalizedAsync("hierarchy").ConfigureAwait(false);

                    return;
                }
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    try
                    {
                        await user.SendErrorAsync(GetText("bandm", Format.Bold(ctx.Guild.Name), msg)).ConfigureAwait(false);
                    }
                    catch
                    {
                        // ignored
                    }
                }

                await _mute.TimedBan(user, time.Time, ctx.User.ToString() + " | " + msg).ConfigureAwait(false);

                await ctx.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
                                             .WithTitle("⛔️ " + GetText("banned_user"))
                                             .AddField(efb => efb.WithName(GetText("username")).WithValue(user.ToString()).WithIsInline(true))
                                             .AddField(efb => efb.WithName("ID").WithValue(user.Id.ToString()).WithIsInline(true))
                                             .WithFooter($"{time.Time.Days}d {time.Time.Hours}h {time.Time.Minutes}m"))
                .ConfigureAwait(false);
            }
Beispiel #7
0
            public async Task Remind(MeOrHere meorhere, StoopidTime time, [Remainder] string message)
            {
                ulong target;

                target = meorhere == MeOrHere.Me ? Context.User.Id : Context.Channel.Id;
                await RemindInternal(target, meorhere == MeOrHere.Me, time.Time, message).ConfigureAwait(false);
            }
Beispiel #8
0
            public async Task WarnPunish(int number, PunishmentAction punish, StoopidTime time = null)
            {
                if ((punish != PunishmentAction.Ban && punish != PunishmentAction.Mute) && time != null)
                {
                    return;
                }
                if (number <= 0 || (time != null && time.Time > TimeSpan.FromDays(49)))
                {
                    return;
                }

                using (var uow = _db.UnitOfWork)
                {
                    var ps = uow.GuildConfigs.ForId(Context.Guild.Id, set => set.Include(x => x.WarnPunishments)).WarnPunishments;
                    ps.RemoveAll(x => x.Count == number);

                    ps.Add(new WarningPunishment()
                    {
                        Count      = number,
                        Punishment = punish,
                        Time       = (int?)(time?.Time.TotalMinutes) ?? 0,
                    });
                    uow.Complete();
                }

                await ReplyConfirmLocalized("warn_punish_set",
                                            Format.Bold(punish.ToString()),
                                            Format.Bold(number.ToString())).ConfigureAwait(false);
            }
            public async Task Remind(MeOrHere meorhere, StoopidTime time, [Remainder] string message)
            {
                ulong target;

                target = meorhere == MeOrHere.Me ? Context.User.Id : Context.Channel.Id;
                if (!await RemindInternal(target, meorhere == MeOrHere.Me || Context.Guild == null, time.Time, message).ConfigureAwait(false))
                {
                    await ReplyErrorLocalizedAsync("remind_too_long").ConfigureAwait(false);
                }
            }
Beispiel #10
0
            public async Task AntiAlt(StoopidTime minAge, PunishmentAction action, [Leftover] IRole role)
            {
                var minAgeMinutes = (int)minAge.Time.TotalMinutes;

                if (minAgeMinutes < 1)
                {
                    return;
                }

                await _service.StartAntiAltAsync(ctx.Guild.Id, minAgeMinutes, action, roleId : role.Id);

                await ctx.OkAsync();
            }
            public async Task WarnPunish(int number, PunishmentAction punish, StoopidTime time = null)
            {
                var success = _service.WarnPunish(Context.Guild.Id, number, punish, time);

                if (!success)
                {
                    return;
                }

                await ReplyConfirmLocalizedAsync("warn_punish_set",
                                                 Format.Bold(punish.ToString()),
                                                 Format.Bold(number.ToString())).ConfigureAwait(false);
            }
Beispiel #12
0
            public async Task Ban(StoopidTime time, IUser user, [Leftover] string msg = null)
            {
                if (time.Time > TimeSpan.FromDays(49))
                {
                    return;
                }

                var guildUser = await((DiscordSocketClient)Context.Client).Rest.GetGuildUserAsync(Context.Guild.Id, user.Id);

                if (guildUser != null && !await CheckRoleHierarchy(guildUser))
                {
                    return;
                }

                var dmFailed = false;

                if (guildUser != null)
                {
                    try
                    {
                        var defaultMessage = GetText("bandm", Format.Bold(ctx.Guild.Name), msg);
                        var embed          = _service.GetBanUserDmEmbed(Context, guildUser, defaultMessage, msg, time.Time);
                        if (!(embed is null))
                        {
                            var userChannel = await guildUser.GetOrCreateDMChannelAsync();

                            await userChannel.EmbedAsync(embed);
                        }
                    }
                    catch
                    {
                        dmFailed = true;
                    }
                }

                await _mute.TimedBan(Context.Guild, user, time.Time, ctx.User.ToString() + " | " + msg).ConfigureAwait(false);

                var toSend = new EmbedBuilder().WithOkColor()
                             .WithTitle("⛔️ " + GetText("banned_user"))
                             .AddField(efb => efb.WithName(GetText("username")).WithValue(user.ToString()).WithIsInline(true))
                             .AddField(efb => efb.WithName("ID").WithValue(user.Id.ToString()).WithIsInline(true))
                             .AddField(efb => efb.WithName(GetText("duration")).WithValue($"{time.Time.Days}d {time.Time.Hours}h {time.Time.Minutes}m").WithIsInline(true));

                if (dmFailed)
                {
                    toSend.WithFooter("⚠️ " + GetText("unable_to_dm_user"));
                }

                await ctx.Channel.EmbedAsync(toSend)
                .ConfigureAwait(false);
            }
Beispiel #13
0
            public async Task AntiAlt(StoopidTime minAge, PunishmentAction action, [Leftover] StoopidTime punishTime = null)
            {
                var minAgeMinutes     = (int)minAge.Time.TotalMinutes;
                var punishTimeMinutes = (int?)punishTime?.Time.TotalMinutes ?? 0;

                if (minAgeMinutes < 1 || punishTimeMinutes < 0)
                {
                    return;
                }

                await _service.StartAntiAltAsync(ctx.Guild.Id, minAgeMinutes, action, (int?)punishTime?.Time.TotalMinutes ?? 0);

                await ctx.OkAsync();
            }
Beispiel #14
0
            public async Task Remind(ITextChannel channel, StoopidTime time, [Remainder] string message)
            {
                var perms = ((IGuildUser)Context.User).GetPermissions((ITextChannel)channel);

                if (!perms.SendMessages || !perms.ViewChannel)
                {
                    await ReplyErrorLocalized("cant_read_or_send").ConfigureAwait(false);

                    return;
                }
                else
                {
                    var _ = RemindInternal(channel.Id, false, time.Time, message).ConfigureAwait(false);
                }
            }
Beispiel #15
0
        public async Task Slowmode(StoopidTime time = null)
        {
            var seconds = (int?)time?.Time.TotalSeconds ?? 0;

            if (!(time is null) && (time.Time < TimeSpan.FromSeconds(0) || time.Time > TimeSpan.FromHours(6)))
            {
                return;
            }


            await((ITextChannel)Context.Channel).ModifyAsync(tcp =>
            {
                tcp.SlowModeInterval = seconds;
            });

            await Context.OkAsync();
        }
Beispiel #16
0
 public async Task Mute(StoopidTime time, IGuildUser user)
 {
     if (time.Time < TimeSpan.FromMinutes(1) || time.Time > TimeSpan.FromDays(1))
     {
         return;
     }
     try
     {
         await _service.TimedMute(user, time.Time).ConfigureAwait(false);
         await ReplyConfirmLocalized("user_muted_time", Format.Bold(user.ToString()), (int)time.Time.TotalMinutes).ConfigureAwait(false);
     }
     catch (Exception ex)
     {
         _log.Warn(ex);
         await ReplyErrorLocalized("mute_error").ConfigureAwait(false);
     }
 }
            public async Task Ban(StoopidTime time, IUser user, [Leftover] string msg = null)
            {
                if (time.Time > TimeSpan.FromDays(49))
                {
                    return;
                }

                // if guild user is null, then that means that user is not in the guild
                var guildUser = await Context.Guild.GetUserAsync(user.Id).ConfigureAwait(false);

                if (ctx.User.Id != Context.Guild.OwnerId && (guildUser != null && guildUser.GetRoles().Select(r => r.Position).Max() >= ((IGuildUser)ctx.User).GetRoles().Select(r => r.Position).Max()))
                {
                    await ReplyErrorLocalizedAsync("hierarchy").ConfigureAwait(false);

                    return;
                }

                var dmFailed = false;

                try
                {
                    await user.SendErrorAsync(GetText("bandm", Format.Bold(ctx.Guild.Name), msg)).ConfigureAwait(false);
                }
                catch
                {
                    dmFailed = true;
                }


                await _mute.TimedBan(Context.Guild, user, time.Time, ctx.User.ToString() + " | " + msg).ConfigureAwait(false);

                var toSend = new EmbedBuilder().WithOkColor()
                             .WithTitle("⛔️ " + GetText("banned_user"))
                             .AddField(efb => efb.WithName(GetText("username")).WithValue(user.ToString()).WithIsInline(true))
                             .AddField(efb => efb.WithName("ID").WithValue(user.Id.ToString()).WithIsInline(true))
                             .AddField(efb => efb.WithName(GetText("duration")).WithValue($"{time.Time.Days}d {time.Time.Hours}h {time.Time.Minutes}m").WithIsInline(true));

                if (dmFailed)
                {
                    toSend.WithFooter("⚠️ " + GetText("unable_to_dm_user"));
                }

                await ctx.Channel.EmbedAsync(toSend)
                .ConfigureAwait(false);
            }
Beispiel #18
0
            public async Task VoiceMute(StoopidTime time, IGuildUser user, [Leftover] string reason = "")
            {
                if (time.Time < TimeSpan.FromMinutes(1) || time.Time > TimeSpan.FromDays(49))
                {
                    return;
                }
                try
                {
                    if (!await VerifyMutePermissions((IGuildUser)ctx.User, user))
                    {
                        return;
                    }

                    await _service.TimedMute(user, ctx.User, time.Time, MuteType.Voice, reason : reason).ConfigureAwait(false);
                    await ReplyConfirmLocalizedAsync("user_voice_mute_time", Format.Bold(user.ToString()), (int)time.Time.TotalMinutes).ConfigureAwait(false);
                }
                catch
                {
                    await ReplyErrorLocalizedAsync("mute_error").ConfigureAwait(false);
                }
            }
            public async Task WarnPunish(int number, AddRole _, IRole role, StoopidTime time = null)
            {
                var punish  = PunishmentAction.AddRole;
                var success = _service.WarnPunish(ctx.Guild.Id, number, punish, time, role);

                if (!success)
                {
                    return;
                }

                if (time is null)
                {
                    await ReplyConfirmLocalizedAsync("warn_punish_set",
                                                     Format.Bold(punish.ToString()),
                                                     Format.Bold(number.ToString())).ConfigureAwait(false);
                }
                else
                {
                    await ReplyConfirmLocalizedAsync("warn_punish_set_timed",
                                                     Format.Bold(punish.ToString()),
                                                     Format.Bold(number.ToString()),
                                                     Format.Bold(time.Input)).ConfigureAwait(false);
                }
            }
Beispiel #20
0
 public Task BanMessageTest(StoopidTime duration, [Leftover] string reason = null)
 => InternalBanMessageTest(reason, duration.Time);
Beispiel #21
0
 public Task Repeat(StoopidTime interval, [Leftover] string message)
 => Repeat(null, interval, message);
Beispiel #22
0
 public Task AntiRaid(int userThreshold, int seconds,
                      PunishmentAction action, [Leftover] StoopidTime punishTime)
 => InternalAntiRaid(userThreshold, seconds, action, punishTime: punishTime);
Beispiel #23
0
 public Task AntiSpam(int messageCount, PunishmentAction action, [Leftover] StoopidTime punishTime)
 => InternalAntiSpam(messageCount, action, punishTime, null);
Beispiel #24
0
            private async Task InternalAntiRaid(int userThreshold, int seconds = 10,
                                                PunishmentAction action        = PunishmentAction.Mute, StoopidTime punishTime = null)
            {
                if (action == PunishmentAction.AddRole)
                {
                    await ReplyErrorLocalizedAsync("punishment_unsupported", action);

                    return;
                }

                if (userThreshold < 2 || userThreshold > 30)
                {
                    await ReplyErrorLocalizedAsync("raid_cnt", 2, 30).ConfigureAwait(false);

                    return;
                }

                if (seconds < 2 || seconds > 300)
                {
                    await ReplyErrorLocalizedAsync("raid_time", 2, 300).ConfigureAwait(false);

                    return;
                }

                if (!(punishTime is null))
                {
                    if (!_service.IsDurationAllowed(action))
                    {
                        await ReplyErrorLocalizedAsync("prot_cant_use_time");
                    }
                }

                var time = (int?)punishTime?.Time.TotalMinutes ?? 0;

                if (time < 0 || time > 60 * 24)
                {
                    return;
                }

                var stats = await _service.StartAntiRaidAsync(ctx.Guild.Id, userThreshold, seconds,
                                                              action, time).ConfigureAwait(false);

                if (stats == null)
                {
                    return;
                }

                await ctx.Channel.SendConfirmAsync(GetText("prot_enable", "Anti-Raid"),
                                                   $"{ctx.User.Mention} {GetAntiRaidString(stats)}")
                .ConfigureAwait(false);
            }
Beispiel #25
0
 public Task Delete(ulong messageId, StoopidTime time = null)
 => Delete((ITextChannel)ctx.Channel, messageId, time);
Beispiel #26
0
 public async Task Delete(ITextChannel channel, ulong messageId, StoopidTime time = null)
 {
     await InternalMessageAction(channel, messageId, time, (msg) => msg.DeleteAsync());
 }
Beispiel #27
0
            public async Task Ban(IGuildUser user, StoopidTime time, [Remainder] string msg = null)
            {
                var tm = DateTime.UtcNow;

                tm = TimeZoneInfo.ConvertTime(tm, _tz.GetTimeZoneOrUtc(user.Guild.Id));
                var mod         = _images.ImageUrls.Moderation;
                Uri imageToSend = mod.Ban[0];

                if (time.Time > TimeSpan.FromDays(49))
                {
                    return;
                }
                if (Context.User.Id != user.Guild.OwnerId && (user.GetRoles().Select(r => r.Position).Max() >= ((IGuildUser)Context.User).GetRoles().Select(r => r.Position).Max()))
                {
                    await ReplyErrorLocalized("hierarchy").ConfigureAwait(false);

                    return;
                }
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    try
                    {
                        await(await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).EmbedAsync(new EmbedBuilder().WithErrorColor()
                                                                                                       .WithAuthor(GetText("baned_on", Context.Guild.ToString()))
                                                                                                       .WithThumbnailUrl(imageToSend.ToString())
                                                                                                       .WithFooter("ID: " + user.Id + " → " + $"[{tm:dd.MM.yyyy HH:mm:ss}]")
                                                                                                       .AddField(efb => efb.WithName(GetText("moderator")).WithValue(Context.User.ToString()))
                                                                                                       .AddField(efb => efb.WithName(GetText("p_time")).WithValue(_service.GetTime(time.Time.TotalHours)).WithIsInline(true))
                                                                                                       .AddField(efb => efb.WithName(GetText("reason")).WithValue(msg ?? "-")))
                        .ConfigureAwait(false);
                    }
                    catch
                    {
                        // ignored
                    }
                }

                var log = new ModLog()
                {
                    UserId    = user.Id,
                    GuildId   = Context.Guild.Id,
                    Type      = "Ban",
                    Reason    = msg,
                    Moderator = Context.User.Id,
                };

                await _mute.TimedBan(user, time.Time, Context.User.ToString() + " | " + msg).ConfigureAwait(false);

                using (var uow = _db.UnitOfWork)
                {
                    uow.ModLog.Add(log);
                    uow.Complete();
                }

                var embed = new EmbedBuilder().WithErrorColor()
                            .WithFooter("ID: " + user.Id + " → " + $"[{tm:dd.MM.yyyy HH:mm:ss}]")
                            .WithThumbnailUrl(imageToSend.ToString())
                            .WithAuthor(name: user.ToString() + GetText("ban"), iconUrl: user.GetAvatarUrl())
                            .AddField(efb => efb.WithName(GetText("user")).WithValue(user.Mention).WithIsInline(true))
                            .AddField(efb => efb.WithName(GetText("moderator")).WithValue(Context.User.Mention).WithIsInline(true))
                            .AddField(efb => efb.WithName(GetText("p_time")).WithValue(_service.GetTime(time.Time.TotalHours)).WithIsInline(true))
                            .AddField(efb => efb.WithName(GetText("reason")).WithValue(msg ?? "-").WithIsInline(true));

                await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
            }
Beispiel #28
0
        private async Task InternalMessageAction(ITextChannel channel, ulong messageId, StoopidTime time, Func <IMessage, Task> func)
        {
            var userPerms = ((SocketGuildUser)ctx.User).GetPermissions(channel);
            var botPerms  = ((SocketGuild)ctx.Guild).CurrentUser.GetPermissions(channel);

            if (!userPerms.Has(ChannelPermission.ManageMessages))
            {
                await ReplyErrorLocalizedAsync("insuf_perms_u").ConfigureAwait(false);

                return;
            }

            if (!botPerms.Has(ChannelPermission.ManageMessages))
            {
                await ReplyErrorLocalizedAsync("insuf_perms_i").ConfigureAwait(false);

                return;
            }


            var msg = await channel.GetMessageAsync(messageId).ConfigureAwait(false);

            if (msg == null)
            {
                await ReplyErrorLocalizedAsync("msg_not_found").ConfigureAwait(false);

                return;
            }

            if (time == null)
            {
                await msg.DeleteAsync().ConfigureAwait(false);
            }
            else if (time.Time <= TimeSpan.FromDays(7))
            {
                var _ = Task.Run(async() =>
                {
                    await Task.Delay(time.Time).ConfigureAwait(false);
                    await msg.DeleteAsync().ConfigureAwait(false);
                });
            }
            else
            {
                await ReplyErrorLocalizedAsync("time_too_long").ConfigureAwait(false);

                return;
            }
            var conf = await ReplyAsync("👌").ConfigureAwait(false);

            conf.DeleteAfter(3);
        }