Example #1
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 may not use this command while being a member of a gang."));
         }
     }
     return(PreconditionResult.FromSuccess());
 }
Example #2
0
        /// <summary>
        /// Getes the guild and user database information for the custom context object.
        /// </summary>
        public async Task InitializeAsync()
        {
            DbUser = await _userRepo.GetUserAsync(GUser);

            DbGuild = await _guildRepo.GetGuildAsync(Guild.Id);

            if (await _gangRepo.InGangAsync(GUser))
            {
                Gang = await _gangRepo.GetGangAsync(GUser);
            }
            Prefix = DbGuild.Prefix;
            Cash   = DbUser.Cash;
        }
Example #3
0
        public async Task Rob(decimal resources, [Remainder] IGuildUser user)
        {
            if (user.Id == Context.User.Id)
            {
                ReplyError("Only the *retards* try to rob themselves. Are you a retard?");
            }
            else if (resources < Config.MIN_RESOURCES)
            {
                ReplyError($"The minimum amount of money to spend on resources for a robbery is {Config.MIN_RESOURCES.USD()}.");
            }
            else if (Context.Cash < resources)
            {
                ReplyError($"You don't have enough money. Balance: {Context.Cash.USD()}.");
            }

            var raidedDbUser = await _userRepo.GetUserAsync(user);

            if (resources > Math.Round(raidedDbUser.Cash * Config.MAX_ROB_PERCENTAGE / 2, 2))
            {
                ReplyError($"You are overkilling it. You only need {(raidedDbUser.Cash * Config.MAX_ROB_PERCENTAGE / 2).USD()} " +
                           $"to rob {Config.MAX_ROB_PERCENTAGE.ToString("P")} of their cash, that is {(raidedDbUser.Cash * Config.MAX_ROB_PERCENTAGE).USD()}.");
            }

            var stolen = resources * 2;

            int roll = Config.RAND.Next(1, 101);

            var successOdds = await _gangRepo.InGangAsync(Context.GUser) ? Config.ROB_SUCCESS_ODDS - 5 : Config.ROB_SUCCESS_ODDS;

            if (successOdds > roll)
            {
                await _userRepo.EditCashAsync(user, Context.DbGuild, raidedDbUser, -stolen);

                await _userRepo.EditCashAsync(Context, stolen);

                await user.Id.DMAsync(Context.Client, $"{Context.User} just robbed you and managed to walk away with {stolen.USD()}.");

                await ReplyAsync($"With a {successOdds}.00% chance of success, you successfully stole {stolen.USD()}. Balance: {Context.Cash.USD()}.");
            }
            else
            {
                await _userRepo.EditCashAsync(Context, -resources);

                await user.Id.DMAsync(Context.Client, $"{Context.User} tried to rob your sweet cash, but the n***a slipped on a banana peel and got arrested :joy: :joy: :joy:.");

                await ReplyAsync($"With a {successOdds}.00% chance of success, you failed to steal {stolen.USD()} " +
                                 $"and lost all resources in the process. Balance: {Context.Cash.USD()}.");
            }
            await _userRepo.ModifyAsync(Context.DbUser, x => x.Rob = DateTime.UtcNow);
        }
Example #4
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);
        }
Example #5
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());
 }
Example #6
0
        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***");
            }
        }
Example #7
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}!");
        }
Example #8
0
        public async Task Cooldowns([Remainder] IGuildUser user = null)
        {
            user = user ?? Context.GUser;
            var dbUser = Context.User.Id == user.Id ? Context.DbUser : await _userRepo.GetUserAsync(user);

            var cooldowns = new Dictionary <String, TimeSpan>
            {
                { "W***e", Config.WHORE_COOLDOWN.Subtract(DateTime.UtcNow.Subtract(dbUser.W***e)) },
                { "Jump", Config.JUMP_COOLDOWN.Subtract(DateTime.UtcNow.Subtract(dbUser.Jump)) },
                { "Steal", Config.STEAL_COOLDOWN.Subtract(DateTime.UtcNow.Subtract(dbUser.Steal)) },
                { "Rob", Config.ROB_COOLDOWN.Subtract(DateTime.UtcNow.Subtract(dbUser.Rob)) },
                { "Withdraw", Config.WITHDRAW_COOLDOWN.Subtract(DateTime.UtcNow.Subtract(dbUser.Withdraw)) }
            };

            if (await _gangRepo.InGangAsync(user))
            {
                cooldowns.Add("Raid", Config.RAID_COOLDOWN.Subtract(DateTime.UtcNow.Subtract(Context.User.Id == user.Id ? Context.Gang.Raid : (await _gangRepo.GetGangAsync(user)).Raid)));
            }

            var description = string.Empty;

            foreach (var cooldown in cooldowns)
            {
                if (cooldown.Value.TotalMilliseconds > 0)
                {
                    description += $"{cooldown.Key}: {cooldown.Value.Hours}:{cooldown.Value.Minutes.ToString("D2")}:{cooldown.Value.Seconds.ToString("D2")}\n";
                }
            }

            if (description.Length == 0)
            {
                ReplyError("All commands are available for use!");
            }

            await SendAsync(description, $"All cooldowns for {user}");
        }
Example #9
0
        public override async Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IDependencyMap map)
        {
            var user   = context.User as IGuildUser;
            var dbUser = await UserRepository.FetchUserAsync(context as SocketCommandContext);

            var guild = await GuildRepository.FetchGuildAsync(context.Guild.Id);

            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 && !user.RoleIds.Any(x => guild.ModRoles.Any(y => y.RoleId == x && y.PermissionLevel >= 3)))
                {
                    return(PreconditionResult.FromError("Only the owner of this server may use this command."));
                }
                break;

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

            case Attributes.Moderator:
                if (!user.RoleIds.Any(x => guild.ModRoles.Any(y => y.RoleId == x)))
                {
                    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((ulong)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((ulong)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 (!(await GangRepository.InGangAsync(context.User.Id, context.Guild.Id)))
                {
                    return(PreconditionResult.FromError("You must be in a gang to use this command."));
                }
                break;

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

            case Attributes.GangLeader:
                if (!(await GangRepository.InGangAsync(context.User.Id, context.Guild.Id)))
                {
                    return(PreconditionResult.FromError("You must be in 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());
        }
Example #10
0
        public override async Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider serviceProvider)
        {
            _serviceProvider   = serviceProvider;
            _credentials       = _serviceProvider.GetService <Credentials>();
            _userRepo          = _serviceProvider.GetService <UserRepository>();
            _moderationService = serviceProvider.GetService <ModerationService>();
            _guildRepo         = _serviceProvider.GetService <GuildRepository>();
            _gangRepo          = _serviceProvider.GetService <GangRepository>();

            var guildUser = context.User as IGuildUser;
            var DbUser    = await _userRepo.GetUserAsync(guildUser);

            var DbGuild = await _guildRepo.GetGuildAsync(context.Guild.Id);

            foreach (var attribute in _attributes)
            {
                switch (attribute)
                {
                case Attributes.BotOwner:
                    if (!_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 (context.Guild.OwnerId != guildUser.Id && DbGuild.ModRoles.ElementCount == 0)
                    {
                        return(PreconditionResult.FromError("Only the owners of this server may use this command."));
                    }
                    else if (guildUser.Guild.OwnerId != context.User.Id && DbGuild.ModRoles != null && !guildUser.RoleIds.Any(x => DbGuild.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 (!guildUser.GuildPermissions.Administrator && DbGuild.ModRoles.ElementCount == 0)
                    {
                        return(PreconditionResult.FromError("The administrator permission is required to use this command."));
                    }
                    else if (!guildUser.GuildPermissions.Administrator && DbGuild.ModRoles.ElementCount != 0 && !guildUser.RoleIds.Any(x => DbGuild.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 (_moderationService.GetPermLevel(DbGuild, context.User as IGuildUser) == 0)
                    {
                        return(PreconditionResult.FromError("Only a moderator may use this command."));
                    }
                    break;

                case Attributes.Nsfw:
                    if (!DbGuild.Nsfw)
                    {
                        return(PreconditionResult.FromError($"This command may not be used while NSFW is disabled. An administrator may enable with the " +
                                                            $"`{DbGuild.Prefix}ChangeNSFWSettings` command."));
                    }

                    var nsfwChannel = await context.Guild.GetChannelAsync(DbGuild.NsfwChannelId);

                    if (nsfwChannel != null && context.Channel.Id != DbGuild.NsfwChannelId)
                    {
                        return(PreconditionResult.FromError($"You may only use this command in {(nsfwChannel as ITextChannel).Mention}."));
                    }

                    break;

                case Attributes.InGang:
                    if (!await _gangRepo.InGangAsync(guildUser))
                    {
                        return(PreconditionResult.FromError("You must be in a gang to use this command."));
                    }

                    break;

                case Attributes.NoGang:
                    if (await _gangRepo.InGangAsync(guildUser))
                    {
                        return(PreconditionResult.FromError("You may not use this command while in a gang."));
                    }

                    break;

                case Attributes.GangLeader:
                    if ((await _gangRepo.GetGangAsync(guildUser)).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 < Config.JUMP_REQUIREMENT)
                    {
                        return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {Config.JUMP_REQUIREMENT.USD()}."));
                    }

                    break;

                case Attributes.Steal:
                    if (DbUser.Cash < Config.STEAL_REQUIREMENT)
                    {
                        return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {Config.STEAL_REQUIREMENT.USD()}."));
                    }

                    break;

                case Attributes.Rob:
                    if (DbUser.Cash < Config.ROB_REQUIREMENT)
                    {
                        return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {Config.ROB_REQUIREMENT.USD()}."));
                    }

                    break;

                case Attributes.Bully:
                    if (DbUser.Cash < Config.BULLY_REQUIREMENT)
                    {
                        return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {Config.BULLY_REQUIREMENT.USD()}."));
                    }

                    break;

                case Attributes.FiftyX2:
                    if (DbUser.Cash < Config.FIFTYX2_REQUIREMENT)
                    {
                        return(PreconditionResult.FromError($"You do not have the permission to use this command.\nRequired cash: {Config.FIFTYX2_REQUIREMENT.USD()}."));
                    }

                    break;

                default:
                    return(PreconditionResult.FromError($"ERROR: The {attribute} attribute is not being handled!"));
                }
            }

            return(PreconditionResult.FromSuccess());
        }
Example #11
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);
                }
            }
        }