コード例 #1
0
ファイル: Banroulette.cs プロジェクト: ta1H3n/Namiko
        public async Task Banroulette()
        {
            var banroulette = BanrouletteDb.GetBanroulette(Context.Channel.Id);

            if (banroulette == null)
            {
                await Context.Channel.SendMessageAsync($"There is no running Ban Roulette in this channel. `{Program.GetPrefix(Context)}nbr` to start a new one.");

                return;
            }

            var    users        = BasicUtil.UserList(Context.Client, BanrouletteDb.GetParticipants(banroulette));
            var    role         = Context.Guild.GetRole(banroulette.RoleReqId);
            string participants = users.Count > 0 ? $"\n\nParticipants:\n{BanrouletteUtil.BanrouletteParticipants(users)}" : "";
            await Context.Channel.SendMessageAsync($"{BanrouletteUtil.BanrouletteDetails(banroulette, role, users.Count)}" + participants);
        }
コード例 #2
0
ファイル: Banroulette.cs プロジェクト: ta1H3n/Namiko
        public async Task JoinBanroulette()
        {
            var banroulette = BanrouletteDb.GetBanroulette(Context.Channel.Id);

            if (banroulette == null)
            {
                await Context.Channel.SendMessageAsync(":x: There is no running Ban Roulette in this channel.");

                return;
            }

            if (banroulette.RoleReqId != 0)
            {
                var user = Context.User as SocketGuildUser;
                if (!user.Roles.Any(x => x.Id == banroulette.RoleReqId))
                {
                    await Context.Channel.SendMessageAsync(":x: You do not have the required role to join!");

                    return;
                }
            }


            var userIds = BanrouletteDb.GetParticipants(banroulette);

            if (userIds.Count >= banroulette.MaxParticipants - 1 && banroulette.MaxParticipants != 0)
            {
                await Context.Channel.SendMessageAsync("Ban Roulette is full!");

                return;
            }

            bool joined = await BanrouletteDb.AddParticipant(Context.User.Id, banroulette);

            if (!joined)
            {
                await Context.Channel.SendMessageAsync("You are already participating! Eager to get smoked, aren't you?");

                return;
            }

            var users = BasicUtil.UserList(Context.Client, userIds);

            users.Add(Context.User);
            string response = "You joined the Ban Roulette. *Heh.*" + (users.Count > 10 ? "" : "\n\nList of Participants:\n" + BanrouletteUtil.BanrouletteParticipants(users));
            await Context.Channel.SendMessageAsync(response);
        }
コード例 #3
0
ファイル: Banroulette.cs プロジェクト: ta1H3n/Namiko
        public async Task EndBanroulette()
        {
            var banroulette = BanrouletteDb.GetBanroulette(Context.Channel.Id);

            if (banroulette == null)
            {
                await Context.Channel.SendMessageAsync(":x: There is no running Ban Roulette in this channel.");

                return;
            }

            var userIds = BanrouletteDb.GetParticipants(banroulette);

            if (userIds.Count < banroulette.MinParticipants)
            {
                await Context.Channel.SendMessageAsync($"Not enough participants! {userIds.Count}/{banroulette.MinParticipants}");

                return;
            }

            var users = BasicUtil.UserList(Context.Client, userIds);
            var user  = users[new Random().Next(users.Count)];

            var ban = new BannedUser
            {
                Active       = true,
                ServerId     = Context.Guild.Id,
                UserId       = user.Id,
                DateBanStart = DateTime.UtcNow,
                DateBanEnd   = DateTime.UtcNow.AddHours(banroulette.BanLengthHours)
            };

            string msg = $"{user.Mention} won! Bai baaaaaai! See you in {banroulette.BanLengthHours} hours!\n\n";

            users.Remove(user);
            if (users.Count > 0 && banroulette.RewardPool > 0)
            {
                int prize = banroulette.RewardPool / users.Count;
                msg += $"Prize pool of {banroulette.RewardPool} ({prize} each) split between: ";
                foreach (var x in users)
                {
                    await BalanceDb.AddToasties(x.Id, prize, Context.Guild.Id);

                    msg += x.Mention + " ";
                }
            }
            await Context.Channel.SendMessageAsync(msg);

            await user.SendMessageAsync($"You won the ban roulette! You are banned from **{Context.Guild.Name}** for {banroulette.BanLengthHours} hours! Bai baaaai!");

            await BanrouletteDb.EndBanroulette(banroulette.Id);

            if (banroulette.BanLengthHours > 0)
            {
                await BanDb.AddBan(ban);

                try
                {
                    await Context.Guild.AddBanAsync(user, 0, $"Banroulette {banroulette.Id}, {banroulette.BanLengthHours} hours.");
                } catch { }
                {
                    await Context.Channel.SendMessageAsync($"I couldn't ban {user}, they are too powerful. *Wipes off blood.* This usually means that their role is higher than mine.");
                }
            }
        }