Exemple #1
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);
        }
Exemple #2
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}!");
        }
Exemple #3
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());
        }