Exemple #1
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 = GangRepository.FetchGang(Context);

            if (!GangRepository.IsMemberOf(Context.User.Id, Context.Guild.Id, user.Id))
            {
                throw new Exception("This user is not a member of your gang!");
            }
            for (int i = 0; i < gang.Members.Length; i++)
            {
                if (gang.Members[i] == user.Id)
                {
                    gang.Members[i] = Context.User.Id;
                    GangRepository.Modify(DEABot.GangUpdateBuilder.Combine(
                                              DEABot.GangUpdateBuilder.Set(x => x.LeaderId, user.Id),
                                              DEABot.GangUpdateBuilder.Set(x => x.Members, gang.Members)), Context);
                    break;
                }
            }
            await ReplyAsync($"{Context.User.Mention}, You have successfully transferred the leadership of {gang.Name} to {user.Mention}");
        }
Exemple #2
0
        public async Task ChangeGangName([Remainder] string name)
        {
            var user = UserRepository.FetchUser(Context);

            if (user.Cash < Config.GANG_NAME_CHANGE_COST)
            {
                throw new Exception($"You do not have {Config.GANG_NAME_CHANGE_COST.ToString("C", Config.CI)}. Balance: {user.Cash.ToString("C", Config.CI)}.");
            }
            var gangs = await(await DEABot.Gangs.FindAsync(y => y.GuildId == Context.Guild.Id)).ToListAsync();

            if (!gangs.Any(x => x.Name.ToLower() == name.ToLower()))
            {
                throw new Exception($"There is already a gang by the name {name}.");
            }
            await UserRepository.EditCashAsync(Context, -Config.GANG_NAME_CHANGE_COST);

            GangRepository.Modify(DEABot.GangUpdateBuilder.Set(x => x.Name, name), Context);
            await ReplyAsync($"You have successfully changed your gang name to {name} at the cost of {Config.GANG_NAME_CHANGE_COST.ToString("C", Config.CI)}.");
        }
Exemple #3
0
        public async Task Deposit(double cash)
        {
            var user = UserRepository.FetchUser(Context);

            if (cash < Config.MIN_DEPOSIT)
            {
                throw new Exception($"The lowest deposit is {Config.MIN_DEPOSIT.ToString("C", Config.CI)}.");
            }
            if (user.Cash < cash)
            {
                throw new Exception($"You do not have enough money. Balance: {user.Cash.ToString("C", Config.CI)}.");
            }
            await UserRepository.EditCashAsync(Context, -cash);

            var gang = GangRepository.FetchGang(Context);

            GangRepository.Modify(DEABot.GangUpdateBuilder.Set(x => x.Wealth, gang.Wealth + cash), Context.User.Id, Context.Guild.Id);
            await ReplyAsync($"{Context.User.Mention}, You have successfully deposited {cash.ToString("C", Config.CI)}. " +
                             $"{gang.Name}'s Wealth: {(gang.Wealth + cash).ToString("C", Config.CI)}");
        }
Exemple #4
0
        public async Task Withdraw(double cash)
        {
            var gang = GangRepository.FetchGang(Context);
            var user = UserRepository.FetchUser(Context);

            if (cash < Config.MIN_WITHDRAW)
            {
                throw new Exception($"The minimum withdrawal is {Config.MIN_WITHDRAW.ToString("C", Config.CI)}.");
            }
            if (cash > gang.Wealth * Config.WITHDRAW_CAP)
            {
                throw new Exception($"You may only withdraw {Config.WITHDRAW_CAP.ToString("P")} of your gang's wealth, " +
                                    $"that is {(gang.Wealth * Config.WITHDRAW_CAP).ToString("C", Config.CI)}.");
            }
            UserRepository.Modify(DEABot.UserUpdateBuilder.Set(x => x.Withdraw, DateTime.UtcNow), Context);
            GangRepository.Modify(DEABot.GangUpdateBuilder.Set(x => x.Wealth, gang.Wealth - cash), Context.User.Id, Context.Guild.Id);
            await UserRepository.EditCashAsync(Context, +cash);

            await ReplyAsync($"{Context.User.Mention}, You have successfully withdrawn {cash.ToString("C", Config.CI)}. " +
                             $"{gang.Name}'s Wealth: {(gang.Wealth - cash).ToString("C", Config.CI)}");
        }