Exemplo n.º 1
0
        public async Task Withdraw(float cash)
        {
            using (var db = new SQLite.Models.DbContext())
            {
                var userRepo = new UserRepository(db);
                var gangRepo = new GangRepository(db);
                var gang     = await gangRepo.FetchGangAsync(Context.User.Id, Context.Guild.Id);

                var user = await userRepo.FetchUserAsync(Context.User.Id);

                if (cash < Config.MIN_WITHDRAW)
                {
                    throw new Exception($"The minimum withdrawal is {Config.MIN_WITHDRAW.ToString("C2")}.");
                }
                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("C2")}.");
                }
                await userRepo.ModifyAsync(x => { x.LastWithdraw = DateTime.Now.ToString(); return(Task.CompletedTask); }, Context.User.Id);

                await gangRepo.ModifyAsync(x => { x.Wealth -= cash; return(Task.CompletedTask); }, Context.User.Id, Context.Guild.Id);

                await userRepo.EditCashAsync(Context, +cash);
                await ReplyAsync($"{Context.User.Mention}, You have successfully withdrawn {cash.ToString("C2")}. " +
                                 $"{gang.Name}'s Wealth: {gang.Wealth.ToString("C2")}");
            }
        }
Exemplo n.º 2
0
        public async Task Deposit(float cash)
        {
            using (var db = new SQLite.Models.DbContext())
            {
                var userRepo = new UserRepository(db);
                var gangRepo = new GangRepository(db);
                var user     = await userRepo.FetchUserAsync(Context.User.Id);

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

                await gangRepo.ModifyAsync(x => { x.Wealth += cash; return(Task.CompletedTask); }, Context.User.Id, Context.Guild.Id);

                var gang = await gangRepo.FetchGangAsync(Context.User.Id, Context.Guild.Id);
                await ReplyAsync($"{Context.User.Mention}, You have successfully deposited {cash.ToString("C2")}. " +
                                 $"{gang.Name}'s Wealth: {gang.Wealth.ToString("C2")}");
            }
        }
Exemplo n.º 3
0
        public async Task Gang([Remainder] string gangName = null)
        {
            if (gangName == null && !(await GangRepository.InGangAsync(Context.User.Id, Context.Guild.Id)))
            {
                throw new Exception($"You are not in a gang.");
            }
            Gang gang;

            if (gangName == null)
            {
                gang = await GangRepository.FetchGangAsync(Context);
            }
            else
            {
                gang = await GangRepository.FetchGangAsync(gangName, Context.Guild.Id);
            }
            var members = "";
            var leader  = "";

            if (Context.Client.GetUser((ulong)gang.LeaderId) != null)
            {
                leader = $"<@{gang.LeaderId}>";
            }
            foreach (var member in gang.Members)
            {
                if (Context.Client.GetUser((ulong)member.UserId) != null)
                {
                    members += $"<@{member}>, ";
                }
            }
            var InterestRate = 0.025f + ((gang.Wealth / 100) * .000075f);

            if (InterestRate > 0.1)
            {
                InterestRate = 0.1f;
            }
            var builder = new EmbedBuilder()
            {
                Title       = gang.Name,
                Color       = new Color(0x00AE86),
                Description = $"__**Leader:**__ {leader}\n" +
                              $"__**Members:**__ {members.Substring(0, members.Length - 2)}\n" +
                              $"__**Wealth:**__ {gang.Wealth.ToString("C", Config.CI)}\n" +
                              $"__**Interest rate:**__ {InterestRate.ToString("P")}"
            };

            await ReplyAsync("", embed : builder);
        }
Exemplo n.º 4
0
 public override async Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IDependencyMap map)
 {
     using (var db = new DbContext())
     {
         var gangRepo = new GangRepository(db);
         if (!await gangRepo.InGangAsync(context.User.Id, context.Guild.Id))
         {
             return(PreconditionResult.FromError("You must be in a gang to use this command."));
         }
         if ((await gangRepo.FetchGangAsync(context.User.Id, context.Guild.Id)).LeaderId != context.User.Id)
         {
             return(PreconditionResult.FromError("Only the leader of a gang may use this command."));
         }
     }
     return(PreconditionResult.FromSuccess());
 }
Exemplo n.º 5
0
        public async Task KickFromGang(IGuildUser user)
        {
            if (!(await GangRepository.IsMemberOfAsync(Context.User.Id, Context.Guild.Id, user.Id)))
            {
                throw new Exception("This user is not a member of your gang!");
            }
            var gang = await GangRepository.FetchGangAsync(Context);

            await GangRepository.RemoveMemberAsync(user.Id, Context.Guild.Id);

            await ReplyAsync($"{Context.User.Mention}, You have successfully kicked {user} from {gang.Name}");

            var channel = await user.CreateDMChannelAsync();

            await channel.SendMessageAsync($"You have been kicked from {gang.Name}.");
        }
Exemplo n.º 6
0
        public async Task LeaveGang()
        {
            var gang = await GangRepository.FetchGangAsync(Context);

            var prefix = (await GuildRepository.FetchGuildAsync(Context.Guild.Id)).Prefix;

            if (gang.LeaderId == Context.User.Id)
            {
                throw new Exception($"You may not leave a gang if you are the owner. Either destroy the gang with the `{prefix}DestroyGang` command, or " +
                                    $"transfer the ownership of the gang to another member with the `{prefix}TransferLeadership` command.");
            }
            await GangRepository.RemoveMemberAsync(Context.User.Id, Context.Guild.Id);

            await ReplyAsync($"{Context.User.Mention}, You have successfully left {gang.Name}");

            var channel = await Context.Client.GetUser((ulong)gang.LeaderId).CreateDMChannelAsync();

            await channel.SendMessageAsync($"{Context.User} has left {gang.Name}.");
        }
Exemplo n.º 7
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}");
        }
Exemplo n.º 8
0
        public async Task Withdraw(double cash)
        {
            var gang = await GangRepository.FetchGangAsync(Context);

            var user = await UserRepository.FetchUserAsync(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)}.");
            }
            await UserRepository.ModifyAsync(x => { x.Withdraw = DateTimeOffset.Now; return(Task.CompletedTask); }, Context);

            await GangRepository.ModifyAsync(x => { x.Wealth -= cash; return(Task.CompletedTask); }, 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.ToString("C", Config.CI)}");
        }
Exemplo n.º 9
0
        public async Task AddToGang(IGuildUser user)
        {
            using (var db = new SQLite.Models.DbContext())
            {
                var gangRepo = new GangRepository(db);
                if (await gangRepo.InGangAsync(user.Id, Context.Guild.Id))
                {
                    throw new Exception("This user is already in a gang.");
                }
                if (await gangRepo.IsFull(Context.User.Id, Context.Guild.Id))
                {
                    throw new Exception("Your gang is already full!");
                }
                await gangRepo.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 gangRepo.FetchGangAsync(user.Id, Context.Guild.Id)).Name}!");
            }
        }
Exemplo n.º 10
0
        public async Task Gang([Remainder] string gangName = null)
        {
            using (var db = new SQLite.Models.DbContext())
            {
                var gangRepo  = new GangRepository(db);
                var guildRepo = new GuildRepository(db);
                if (gangName == null && !(await gangRepo.InGangAsync(Context.User.Id, Context.Guild.Id)))
                {
                    throw new Exception($"You are not in a gang.");
                }
                Gang gang;
                if (gangName == null)
                {
                    gang = await gangRepo.FetchGangAsync(Context.User.Id, Context.Guild.Id);
                }
                else
                {
                    gang = await gangRepo.FetchGangAsync(gangName, Context.Guild.Id);
                }
                var members = "";
                var leader  = "";
                if (Context.Client.GetUser(gang.LeaderId) != null)
                {
                    leader = Context.Client.GetUser(gang.LeaderId).Username;
                }
                SocketGuildUser member2 = Context.Guild.GetUser(gang.Member2Id), member3 = Context.Guild.GetUser(gang.Member3Id),
                                member4 = Context.Guild.GetUser(gang.Member4Id), member5 = Context.Guild.GetUser(gang.Member5Id);
                if (member2 != null)
                {
                    members += $"{member2.Username}, ";
                }
                if (member3 != null)
                {
                    members += $"{member3.Username}, ";
                }
                if (member4 != null)
                {
                    members += $"{member4.Username}, ";
                }
                if (member5 != null)
                {
                    members += $"{member5.Username}, ";
                }
                var InterestRate = 0.025f + ((gang.Wealth / 100) * .000075f);
                if (InterestRate > 0.1)
                {
                    InterestRate = 0.1f;
                }
                var builder = new EmbedBuilder()
                {
                    Title       = gang.Name,
                    Color       = new Color(0x00AE86),
                    Description = $"__**Leader:**__ {leader}\n" +
                                  $"__**Members:**__ {members.Substring(0, members.Length - 2)}\n" +
                                  $"__**Wealth:**__ {gang.Wealth.ToString("C2")}\n" +
                                  $"__**Interest rate:**__ {InterestRate.ToString("P")}"
                };
                if ((await guildRepo.FetchGuildAsync(Context.Guild.Id)).DM)
                {
                    var channel = await Context.User.CreateDMChannelAsync();

                    await channel.SendMessageAsync("", embed : builder);
                }
                else
                {
                    await ReplyAsync("", embed : builder);
                }
            }
        }