Ejemplo n.º 1
0
            public async Task MassKill([Leftover] string people)
            {
                if (string.IsNullOrWhiteSpace(people))
                {
                    return;
                }

                var(bans, missing) = _service.MassKill((SocketGuild)ctx.Guild, people);

                var missStr = string.Join("\n", missing);

                if (string.IsNullOrWhiteSpace(missStr))
                {
                    missStr = "-";
                }

                //send a message but don't wait for it
                var banningMessageTask = ctx.Channel.EmbedAsync(new EmbedBuilder()
                                                                .WithDescription(GetText("mass_kill_in_progress", bans.Count()))
                                                                .AddField(GetText("invalid", missing), missStr)
                                                                .WithOkColor());

                Bc.Reload();

                //do the banning
                await Task.WhenAll(bans
                                   .Where(x => x.Id.HasValue)
                                   .Select(x => ctx.Guild.AddBanAsync(x.Id.Value, 7, x.Reason, new RequestOptions()
                {
                    RetryMode = RetryMode.AlwaysRetry,
                })))
                .ConfigureAwait(false);

                //wait for the message and edit it
                var banningMessage = await banningMessageTask.ConfigureAwait(false);

                await banningMessage.ModifyAsync(x => x.Embed = new EmbedBuilder()
                                                 .WithDescription(GetText("mass_kill_completed", bans.Count()))
                                                 .AddField(GetText("invalid", missing), missStr)
                                                 .WithOkColor()
                                                 .Build()).ConfigureAwait(false);
            }
Ejemplo n.º 2
0
 public async Task TimelySet(int num, int period = 24)
 {
     if (num < 0 || period < 0)
     {
         return;
     }
     using (var uow = _db.UnitOfWork)
     {
         var bc = uow.BotConfig.GetOrCreate(set => set);
         bc.TimelyCurrency       = num;
         bc.TimelyCurrencyPeriod = period;
         uow.Complete();
     }
     Bc.Reload();
     if (num == 0)
     {
         await ReplyConfirmLocalized("timely_set_none").ConfigureAwait(false);
     }
     else
     {
         await ReplyConfirmLocalized("timely_set", Format.Bold(num + Bc.BotConfig.CurrencySign), Format.Bold(period.ToString())).ConfigureAwait(false);
     }
 }
Ejemplo n.º 3
0
            public async Task MassKill([Remainder] string people)
            {
                if (string.IsNullOrWhiteSpace(people))
                {
                    return;
                }

                var gusers = ((SocketGuild)Context.Guild).Users;
                //get user objects and reasons
                var bans = people.Split("\n")
                           .Select(x =>
                {
                    var split = x.Trim().Split(" ");

                    var reason = string.Join(" ", split.Skip(1));

                    if (ulong.TryParse(split[0], out var id))
                    {
                        return(Original: split[0], Id: id, Reason: reason);
                    }

                    return(Original: split[0],
                           Id: gusers
                           .FirstOrDefault(u => u.ToString().ToLowerInvariant() == x)
                           ?.Id,
                           Reason: reason);
                })
                           .ToArray();

                //if user is null, means that person couldn't be found
                var missing = bans
                              .Where(x => !x.Id.HasValue)
                              .ToArray();

                //get only data for found users
                var found = bans
                            .Where(x => x.Id.HasValue)
                            .Select(x => x.Id.Value)
                            .ToArray();

                var missStr = string.Join("\n", missing);

                if (string.IsNullOrWhiteSpace(missStr))
                {
                    missStr = "-";
                }

                //send a message but don't wait for it
                var banningMessageTask = Context.Channel.EmbedAsync(new EmbedBuilder()
                                                                    .WithDescription(GetText("mass_kill_in_progress", bans.Length))
                                                                    .AddField(GetText("invalid", missing.Length), missStr)
                                                                    .WithOkColor());

                using (var uow = _db.UnitOfWork)
                {
                    var bc = uow.BotConfig.GetOrCreate(set => set.Include(x => x.Blacklist));
                    //blacklist the users
                    bc.Blacklist.AddRange(found.Select(x =>
                                                       new BlacklistItem
                    {
                        ItemId = x,
                        Type   = BlacklistType.User,
                    }));
                    //clear their currencies
                    uow.DiscordUsers.RemoveFromMany(found.Select(x => x).ToList());
                    uow.Complete();
                }

                Bc.Reload();

                //do the banning
                await Task.WhenAll(bans
                                   .Where(x => x.Id.HasValue)
                                   .Select(x => Context.Guild.AddBanAsync(x.Id.Value, 7, x.Reason, new RequestOptions()
                {
                    RetryMode = RetryMode.AlwaysRetry,
                })))
                .ConfigureAwait(false);

                //wait for the message and edit it
                var banningMessage = await banningMessageTask.ConfigureAwait(false);

                await banningMessage.ModifyAsync(x => x.Embed = new EmbedBuilder()
                                                 .WithDescription(GetText("mass_kill_completed", bans.Length))
                                                 .AddField(GetText("invalid", missing.Length), missStr)
                                                 .WithOkColor()
                                                 .Build()).ConfigureAwait(false);
            }