Ejemplo n.º 1
0
        public async Task Ganglb()
        {
            var    gangs   = (await GangRepository.AllAsync(Context.Guild.Id)).OrderByDescending(x => x.Wealth).ToList();
            string message = "```asciidoc\n= The Wealthiest Gangs =\n";
            int    longest = 0;

            for (int i = 0; i < gangs.Count(); i++)
            {
                if (i + 1 >= Config.GANGSLB_CAP)
                {
                    break;
                }
                if (gangs[i].Name.Length > longest)
                {
                    longest = $"{i + 1}. {gangs[i].Name}".Length;
                }
            }

            for (int i = 0; i < gangs.Count(); i++)
            {
                if (i + 1 >= Config.GANGSLB_CAP)
                {
                    break;
                }
                message += $"{i + 1}. {gangs[i].Name}".PadRight(longest + 2) + $" :: {gangs[i].Wealth.ToString("C", Config.CI)}\n";
            }

            await ReplyAsync($"{message}```");
        }
Ejemplo n.º 2
0
        private void InterestRate(object stateObj)
        {
            Task.Run(async() =>
            {
                Logger.Log(LogSeverity.Debug, $"Timers", "Interest Rate");
                var updateBuilder = Builders <Gang> .Update;

                foreach (var gang in await _gangRepo.AllAsync())
                {
                    try
                    {
                        await _gangRepo.Collection.UpdateOneAsync(y => y.Id == gang.Id,
                                                                  updateBuilder.Set(x => x.Wealth, Static.InterestRate.Calculate(gang.Wealth) * gang.Wealth + gang.Wealth));
                    }
                    catch (OverflowException) { }
                }
            });
        }
Ejemplo n.º 3
0
        public async Task ChangeGangName([Remainder] string name)
        {
            var user = await UserRepository.FetchUserAsync(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)}.");
            }
            if ((await GangRepository.AllAsync(Context.Guild.Id)).Any(x => x.Name == name))
            {
                throw new Exception($"There is already a gang by the name {name}.");
            }
            await UserRepository.EditCashAsync(Context, -Config.GANG_NAME_CHANGE_COST);

            await GangRepository.ModifyAsync(x => { x.Name = name; return(Task.CompletedTask); }, Context.User.Id, Context.Guild.Id);

            await ReplyAsync($"You have successfully changed your gang name to {name} at the cost of {Config.GANG_NAME_CHANGE_COST.ToString("C", Config.CI)}.");
        }
Ejemplo n.º 4
0
        private void ApplyInterestRate(object stateObj)
        {
            Task.Run(async() =>
            {
                Logger.Log(LogSeverity.Debug, $"Timers", "Interest Rate");
                var updateBuilder = Builders <Gang> .Update;

                foreach (var gang in await _gangRepo.AllAsync())
                {
                    try
                    {
                        await _gangRepo.ModifyAsync(gang, x => x.Wealth += InterestRate.Calculate(x.Wealth) * x.Wealth);
                    }
                    catch (OverflowException)
                    {
                        // Ignored.
                    }
                }
            });
        }