Ejemplo n.º 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}");
        }
Ejemplo n.º 2
0
        public async Task Gang([Remainder] string gangName = null)
        {
            if (gangName == null && !GangRepository.InGang(Context.User.Id, Context.Guild.Id))
            {
                throw new Exception($"You are not in a gang.");
            }
            Gang gang;

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

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

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

            await ReplyAsync("", embed : builder);
        }
Ejemplo n.º 3
0
        public async Task KickFromGang([Remainder] IGuildUser user)
        {
            if (!GangRepository.IsMemberOf(Context.User.Id, Context.Guild.Id, user.Id))
            {
                throw new Exception("This user is not a member of your gang!");
            }
            var gang = GangRepository.FetchGang(Context);

            GangRepository.RemoveMember(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}.");
        }
Ejemplo n.º 4
0
        public async Task AddToGang(IGuildUser user)
        {
            if (GangRepository.InGang(user.Id, Context.Guild.Id))
            {
                throw new Exception("This user is already in a gang.");
            }
            if (GangRepository.IsFull(Context.User.Id, Context.Guild.Id))
            {
                throw new Exception("Your gang is already full!");
            }
            GangRepository.AddMember(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 {GangRepository.FetchGang(Context).Name}!");
        }
Ejemplo n.º 5
0
        public async Task LeaveGang()
        {
            var gang   = GangRepository.FetchGang(Context);
            var prefix = GuildRepository.FetchGuild(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.");
            }
            GangRepository.RemoveMember(Context.User.Id, Context.Guild.Id);
            await ReplyAsync($"{Context.User.Mention}, You have successfully left {gang.Name}");

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

            await channel.SendMessageAsync($"{Context.User} has left {gang.Name}.");
        }
Ejemplo n.º 6
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)}");
        }
Ejemplo n.º 7
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)}");
        }
Ejemplo n.º 8
0
        public override async Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IDependencyMap map)
        {
            var user   = context.User as IGuildUser;
            var dbUser = UserRepository.FetchUser(context as SocketCommandContext);
            var guild  = GuildRepository.FetchGuild(context.Guild.Id);

            foreach (var attribute in attributes)
            {
                switch (attribute)
                {
                case Attributes.BotOwner:
                    if (!DEABot.Credentials.OwnerIds.Any(x => x == context.User.Id))
                    {
                        return(PreconditionResult.FromError("Only an owner of this bot may use this command."));
                    }
                    break;

                case Attributes.ServerOwner:
                    if (user.Guild.OwnerId != user.Id && guild.ModRoles != null && !user.RoleIds.Any(x => guild.ModRoles.Any(y => y.Name == x.ToString() && y.Value.AsInt32 >= 3)))
                    {
                        return(PreconditionResult.FromError("Only the owners of this server may use this command."));
                    }
                    break;

                case Attributes.Admin:
                    if (!(context.User as IGuildUser).GuildPermissions.Administrator && guild.ModRoles != null && !user.RoleIds.Any(x => guild.ModRoles.Any(y => y.Name == x.ToString() && y.Value.AsInt32 >= 2)))
                    {
                        return(PreconditionResult.FromError("The administrator permission is required to use this command."));
                    }
                    break;

                case Attributes.Moderator:
                    if (guild.ModRoles != null && !user.RoleIds.Any(x => guild.ModRoles.Any(y => y.Name == x.ToString())))
                    {
                        return(PreconditionResult.FromError("Only a moderator may use this command."));
                    }
                    break;

                case Attributes.Nsfw:
                    if (!guild.Nsfw)
                    {
                        return(PreconditionResult.FromError($"This command may not be used while NSFW is disabled. An administrator may enable with the " +
                                                            $"`{guild.Prefix}ChangeNSFWSettings` command."));
                    }
                    var nsfwChannel = await context.Guild.GetChannelAsync(guild.NsfwId);

                    if (nsfwChannel != null && context.Channel.Id != guild.NsfwId)
                    {
                        return(PreconditionResult.FromError($"You may only use this command in {(nsfwChannel as ITextChannel).Mention}."));
                    }
                    var nsfwRole = context.Guild.GetRole(guild.NsfwRoleId);
                    if (nsfwRole != null && (context.User as IGuildUser).RoleIds.All(x => x != guild.NsfwRoleId))
                    {
                        return(PreconditionResult.FromError($"You do not have permission to use this command.\nRequired role: {nsfwRole.Mention}"));
                    }
                    break;

                case Attributes.InGang:
                    if (!GangRepository.InGang(context.User.Id, context.Guild.Id))
                    {
                        return(PreconditionResult.FromError("You must be in a gang to use this command."));
                    }
                    break;

                case Attributes.NoGang:
                    if (GangRepository.InGang(context.User.Id, context.Guild.Id))
                    {
                        return(PreconditionResult.FromError("You may not use this command while in a gang."));
                    }
                    break;

                case Attributes.GangLeader:
                    if (GangRepository.FetchGang(context.User.Id, context.Guild.Id).LeaderId != context.User.Id)
                    {
                        return(PreconditionResult.FromError("You must be the leader of a gang to use this command."));
                    }
                    break;

                case Attributes.Jump:
                    if (dbUser.Cash < guild.JumpRequirement)
                    {
                        return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {guild.JumpRequirement.ToString("C", Config.CI)}."));
                    }
                    break;

                case Attributes.Steal:
                    if (dbUser.Cash < guild.StealRequirement)
                    {
                        return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {guild.StealRequirement.ToString("C", Config.CI)}."));
                    }
                    break;

                case Attributes.Bully:
                    if (dbUser.Cash < guild.BullyRequirement)
                    {
                        return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {guild.BullyRequirement.ToString("C", Config.CI)}."));
                    }
                    break;

                case Attributes.Rob:
                    if (dbUser.Cash < guild.RobRequirement)
                    {
                        return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {guild.RobRequirement.ToString("C", Config.CI)}."));
                    }
                    break;

                case Attributes.FiftyX2:
                    if (dbUser.Cash < guild.FiftyX2Requirement)
                    {
                        return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {guild.FiftyX2Requirement.ToString("C", Config.CI)}."));
                    }
                    break;

                default:
                    throw new Exception($"ERROR: The {attribute} attribute does not exist!");
                }
            }
            return(PreconditionResult.FromSuccess());
        }