예제 #1
0
파일: Gangs.cs 프로젝트: knightking100/DEA
        public async Task AddToGang([Summary("SLAM EM BOYS")][Remainder] string gangName)
        {
            var gang = await _gangRepo.GetGangAsync(gangName, Context.Guild.Id);

            if (gang.Members.Length == 4)
            {
                ReplyError("This gang is already full!");
            }

            var leader = await(Context.Guild as IGuild).GetUserAsync(gang.LeaderId);

            if (leader != null)
            {
                var leaderDM = await leader.CreateDMChannelAsync();

                var key = Config.RAND.Next();
                await leaderDM.SendAsync($"{Context.User} has requested to join your gang. Please respond with \"{key}\" within 5 minutes to add this user to your gang.");

                await ReplyAsync($"The leader of {gang.Name} has been informed of your request to join their gang.");

                var answer = await _interactiveService.WaitForMessage(leaderDM, x => x.Content == key.ToString(), TimeSpan.FromMinutes(5));

                if (answer != null)
                {
                    if (await _gangRepo.InGangAsync(Context.GUser))
                    {
                        await leaderDM.SendAsync("This user has already joined a different gang.");
                    }
                    else if ((await _gangRepo.GetGangAsync(leader)).Members.Length == 4)
                    {
                        await leaderDM.SendAsync("Your gang is already full.");
                    }
                    else
                    {
                        await _gangRepo.AddMemberAsync(gang, Context.User.Id);

                        await leaderDM.SendAsync($"You have successfully added {Context.User} as a member of your gang.");

                        await Context.User.Id.DMAsync(Context.Client, $"Congrats! {leader} has accepted your request to join {gang.Name}!");
                    }
                }
            }
            else
            {
                await ReplyAsync("The leader of that gang is no longer in this server. ***RIP GANG ROFL***");
            }
        }
예제 #2
0
        public async Task AddToGang(IGuildUser user)
        {
            if (await GangRepository.InGangAsync(user.Id, Context.Guild.Id))
            {
                throw new Exception("This user is already in a gang.");
            }
            if (await GangRepository.IsFullAsync(Context.User.Id, Context.Guild.Id))
            {
                throw new Exception("Your gang is already full!");
            }
            await GangRepository.AddMemberAsync(Context.User.Id, Context.Guild.Id, user.Id);

            await ReplyAsync($"{user} is now a new member of your gang!");

            var channel = await user.CreateDMChannelAsync();

            await channel.SendMessageAsync($"Congrats! You are now a member of {(await GangRepository.FetchGangAsync(Context)).Name}!");
        }
예제 #3
0
        public async Task TransferLeadership(IGuildUser user)
        {
            if (user.Id == Context.User.Id)
            {
                throw new Exception("You are already the leader of this gang!");
            }
            var gang = await GangRepository.FetchGangAsync(Context);

            if (!(await GangRepository.IsMemberOfAsync(Context.User.Id, Context.Guild.Id, user.Id)))
            {
                throw new Exception("This user is not a member of your gang!");
            }
            await GangRepository.RemoveMemberAsync(Context.User.Id, Context.Guild.Id);

            await GangRepository.ModifyAsync(x => { x.LeaderId = user.Id; return(Task.CompletedTask); }, Context);

            await GangRepository.AddMemberAsync(Context.User.Id, Context.Guild.Id, Context.User.Id);

            await ReplyAsync($"{Context.User.Mention}, You have successfully transferred the leadership of {gang.Name} to {user.Mention}");
        }