예제 #1
0
        public async Task Collect()
        {
            if (!CommandHandler.IsPostedInCorrectChannel(Context.Message, GetType().Name))
            {
                return;
            }

            using (var db = new CurrencyContext())
            {
                var account   = db.UserAccounts.AsQueryable().Where(u => u.Id == Context.User.Id).FirstOrDefault();
                var cooldowns = db.Cooldowns.AsQueryable().Where(c => c.Id == Context.User.Id).FirstOrDefault();
                if (account != null && cooldowns != null)
                {
                    if (account.Inventory.ContainsKey("bitcoin_miner"))
                    {
                        var collect         = cooldowns.Collect;
                        var cooldownHandler = new CooldownHandler();
                        var isCooledDown    = cooldownHandler.IsCooledDown(collect, "h", _collectCooldown);
                        if (isCooledDown)
                        {
                            var collected = _collectAmount * account.Inventory["bitcoin_miner"];
                            account.AddBalance(collected);
                            cooldowns.Collect = DateTime.Now;

                            db.Update(account);
                            db.Update(cooldowns);
                            await db.SaveChangesAsync();
                            await ReplyAsync($"You've collected {collected} Kredits!");
                        }
                        else
                        {
                            var cooldown = cooldownHandler.GetDifference(DateTime.Now, collect.AddHours(_collectCooldown));
                            await ReplyAsync($"You can only collect once every {_collectCooldown} hours!\n" +
                                             $"You still have to wait for {cooldown}!");
                        }
                    }
                    else
                    {
                        await ReplyAsync("You dont generate any passive income yet! Buy a device from the store does!");
                    }
                }
                else
                {
                    await ReplyAsync("You dont have an account yet, type $acc to create one!");
                }
            }
        }
예제 #2
0
        public async Task Work()
        {
            if (!CommandHandler.IsPostedInCorrectChannel(Context.Message, GetType().Name))
            {
                return;
            }

            using (var db = new CurrencyContext())
            {
                var account   = db.UserAccounts.AsQueryable().Where(u => u.Id == Context.User.Id).FirstOrDefault();
                var cooldowns = db.Cooldowns.AsQueryable().Where(c => c.Id == Context.User.Id).FirstOrDefault();
                if (account != null && cooldowns != null)
                {
                    var pay = _workAmount;
                    if (account.Inventory.ContainsKey("working_tools"))
                    {
                        pay += (25 * account.Inventory["working_tools"]);
                    }
                    if (account.Inventory.ContainsKey("doctors_license"))
                    {
                        pay *= (1 + account.Inventory["doctors_license"]);
                    }

                    var work            = cooldowns.Work;
                    var cooldownHandler = new CooldownHandler();
                    var isCooledDown    = cooldownHandler.IsCooledDown(work, "m", _workCooldown);
                    if (isCooledDown)
                    {
                        var rng    = new Random();
                        var randNr = rng.Next(0, 3);

                        if (randNr == 0 && account.Inventory.ContainsKey("vaccine"))
                        {
                            randNr = 1;
                        }

                        if (randNr > 0)
                        {
                            account.AddBalance(pay);
                            cooldowns.Work = DateTime.Now;

                            db.Update(account);
                            db.Update(cooldowns);
                            await db.SaveChangesAsync();
                            await ReplyAsync($"You've earned {pay} Kredits!");
                        }
                        else
                        {
                            cooldowns.Work = DateTime.Now;

                            db.Update(cooldowns);
                            await db.SaveChangesAsync();
                            await ReplyAsync("You got covid and could not show up to work. Unlucky, I guess.");
                        }
                    }
                    else
                    {
                        var cooldown = cooldownHandler.GetDifference(DateTime.Now, work.AddMinutes(_workCooldown));
                        await ReplyAsync($"You can only work once every {_workCooldown} minutes!\n" +
                                         $"You still have to wait for {cooldown}!");
                    }
                }
                else
                {
                    await ReplyAsync("You dont have an account yet, type $acc to create one!");
                }
            }
        }
예제 #3
0
        public async Task Rob(IUser user)
        {
            if (!CommandHandler.IsPostedInCorrectChannel(Context.Message, GetType().Name))
            {
                return;
            }

            if (user.Id != Context.Message.Author.Id)
            {
                using (var db = new CurrencyContext())
                {
                    var account         = db.UserAccounts.AsQueryable().Where(u => u.Id == Context.User.Id).FirstOrDefault();
                    var cooldowns       = db.Cooldowns.AsQueryable().Where(c => c.Id == Context.User.Id).FirstOrDefault();
                    var targetAccount   = db.UserAccounts.AsQueryable().Where(u => u.Id == user.Id).FirstOrDefault();
                    var targetCooldowns = db.Cooldowns.AsQueryable().Where(c => c.Id == user.Id).FirstOrDefault();
                    if (account != null && cooldowns != null)
                    {
                        if (account.Inventory.ContainsKey("beat_stick"))
                        {
                            if (targetAccount != null && targetCooldowns != null)
                            {
                                var rob                = cooldowns.Rob;
                                var robbed             = targetCooldowns.Robbed;
                                var cooldownHandler    = new CooldownHandler();
                                var isCooledDown       = cooldownHandler.IsCooledDown(rob, "m", _robCooldown);
                                var isCooledDownTarget = cooldownHandler.IsCooledDown(robbed, "m", _robCooldown);
                                if (isCooledDown)
                                {
                                    if (isCooledDownTarget)
                                    {
                                        var rng       = new Random();
                                        var robAmount = rng.Next(_minRob, _maxRob);

                                        if (rng.Next(0, 3) > 0)
                                        {
                                            robAmount = (targetAccount.Balance >= robAmount) ? robAmount : targetAccount.Balance;
                                            account.AddBalance(robAmount);
                                            targetAccount.SubtractBalance(robAmount);
                                            await ReplyAsync($"You stole: {robAmount} Kredits!");
                                        }
                                        else
                                        {
                                            robAmount = (account.Balance >= robAmount) ? robAmount : account.Balance;
                                            account.SubtractBalance(robAmount);
                                            targetAccount.AddBalance(robAmount);
                                            await ReplyAsync($"You were beaten up and lost: {robAmount} Kredits!");
                                        }
                                        cooldowns.Rob          = DateTime.Now;
                                        targetCooldowns.Robbed = DateTime.Now;

                                        db.Update(account);
                                        db.Update(cooldowns);
                                        db.Update(targetAccount);
                                        db.Update(targetCooldowns);
                                        await db.SaveChangesAsync();
                                    }
                                    else
                                    {
                                        var cooldown = cooldownHandler.GetDifference(DateTime.Now, robbed.AddMinutes(_robCooldown));
                                        await ReplyAsync($"Your target can only be robbed once every {_robCooldown} minutes! \n" +
                                                         $"You still have to wait for: {cooldown}!");
                                    }
                                }
                                else
                                {
                                    var cooldown = cooldownHandler.GetDifference(DateTime.Now, rob.AddMinutes(_robCooldown));
                                    await ReplyAsync($"You can only rob once every {_robCooldown} minutes! \n" +
                                                     $"You still have to wait for: {cooldown}!");
                                }
                            }
                            else
                            {
                                await ReplyAsync("Your target does not have an account yet!");
                            }
                        }
                        else
                        {
                            await ReplyAsync("You need a beat stick to rob people with!");
                        }
                    }
                    else
                    {
                        await ReplyAsync("You dont have an account yet, type $acc to create one!");
                    }
                }
            }
            else
            {
                await ReplyAsync("You can't rob yourself you idiota!");
            }
        }
예제 #4
0
        public async Task StartTrivia()
        {
            if (!CommandHandler.IsPostedInCorrectChannel(Context.Message, GetType().Name))
            {
                return;
            }

            if (!Running)
            {
                using (var db = new CurrencyContext())
                {
                    var account   = db.UserAccounts.AsQueryable().Where(u => u.Id == Context.User.Id).FirstOrDefault();
                    var cooldowns = db.Cooldowns.AsQueryable().Where(c => c.Id == Context.User.Id).FirstOrDefault();

                    if (account != null && cooldowns != null)
                    {
                        var lastTrivia      = cooldowns.Trivia;
                        var cooldownHandler = new CooldownHandler();

                        if (account.Inventory.ContainsKey("trivia_license"))
                        {
                            var isCooledDown = cooldownHandler.IsCooledDown(lastTrivia, "m", _triviaCooldown);

                            if (isCooledDown)
                            {
                                Running = true;

                                cooldowns.Trivia = DateTime.Now;
                                db.Update(cooldowns);
                                await db.SaveChangesAsync();

                                var response = await Client.GetAsync(TriviaUrl);

                                var responseString = await response.Content.ReadAsStringAsync();

                                var responseJson = JObject.Parse(responseString);
                                var score        = new Dictionary <ulong, int>();
                                var stopwatch    = new Stopwatch();

                                await ReplyAsync("A trivia session is starting in 30 seconds...");

                                await Task.Delay(10000);
                                await ReplyAsync("A trivia session is starting in 20 seconds...");

                                await Task.Delay(10000);
                                await ReplyAsync("A trivia session is starting in 10 seconds...");

                                await Task.Delay(7000);
                                await ReplyAsync("A trivia session is starting in 3 seconds...");

                                await Task.Delay(1000);
                                await ReplyAsync("A trivia session is starting in 2 seconds...");

                                await Task.Delay(1000);
                                await ReplyAsync("A trivia session is starting in 1 seconds...");

                                await Task.Delay(1000);
                                await ReplyAsync("Trivia is starting!");

                                foreach (var result in responseJson["results"])
                                {
                                    await Task.Delay(2000);
                                    await ReplyAsync(HttpUtility.HtmlDecode(result["question"].ToString()));

                                    this.result = result;

                                    await Task.Delay(2000);

                                    var answers = new List <string>();
                                    answers.Add(result["correct_answer"].ToString());
                                    foreach (var incorrectAnswer in result["incorrect_answers"])
                                    {
                                        answers.Add((string)incorrectAnswer);
                                    }

                                    answers = answers.OrderBy(a => Guid.NewGuid()).ToList();
                                    var answersMessage = string.Join(", ", answers.ToArray());
                                    await ReplyAsync("Answers: " + HttpUtility.HtmlDecode(answersMessage));

                                    Context.Client.MessageReceived += tryAnswer;

                                    stopwatch.Start();

                                    var timeout = false;

                                    while (winnerId == 0)
                                    {
                                        if (stopwatch.ElapsedMilliseconds > 15000)
                                        {
                                            timeout = true;
                                            break;
                                        }
                                    }

                                    stopwatch.Stop();
                                    stopwatch.Reset();

                                    Context.Client.MessageReceived -= tryAnswer;

                                    if (timeout)
                                    {
                                        var correctAnswer = HttpUtility.HtmlDecode((string)result["correct_answer"]);
                                        await ReplyAsync($"The answer was: {correctAnswer}!");
                                        await ReplyAsync("No answer was found, skipping to next question!");

                                        continue;
                                    }

                                    await ReplyAsync($"<@{winnerId}> has found the correct answer!");

                                    if (score.ContainsKey(winnerId))
                                    {
                                        score[winnerId]++;
                                    }
                                    else
                                    {
                                        score.Add(winnerId, 1);
                                    }

                                    winnerId = 0;

                                    if (score.ContainsValue(4) || result == responseJson["results"].Last)
                                    {
                                        break;
                                    }
                                }

                                var sortedScores = score.OrderBy(s => s.Value).ToList();

                                var winners = "";

                                foreach (var points in sortedScores)
                                {
                                    winners += $"<@{points.Key}> : {points.Value} points\n";
                                }

                                var embed = new EmbedBuilder();
                                embed.WithColor(new Color(0, 255, 0));
                                embed.WithTitle("Trivia score");
                                embed.WithDescription(winners);
                                await ReplyAsync("", false, embed.Build());

                                Running = false;
                            }
                            else
                            {
                                var cooldown = cooldownHandler.GetDifference(DateTime.Now, lastTrivia.AddMinutes(_triviaCooldown));
                                await ReplyAsync($"You can only start a trivia session once every {_triviaCooldown} minutes! \n" +
                                                 $"You still have to wait for: {cooldown}!");
                            }
                        }
                        else
                        {
                            await ReplyAsync("You can't start a trivia session without a license! Check the $shop.");
                        }
                    }
                    else
                    {
                        await ReplyAsync("You dont have an account yet, type $acc to create one!");
                    }
                }
            }
            else
            {
                await ReplyAsync("A trivia session is already running!");
            }
        }
예제 #5
0
        public async Task SpinRoulette(int bet)
        {
            if (!CommandHandler.IsPostedInCorrectChannel(Context.Message, GetType().Name))
            {
                return;
            }

            using (var db = new CurrencyContext())
            {
                var account   = db.UserAccounts.AsQueryable().Where(u => u.Id == Context.User.Id).FirstOrDefault();
                var cooldowns = db.Cooldowns.AsQueryable().Where(c => c.Id == Context.User.Id).FirstOrDefault();
                if (bet >= _minWager && bet <= _maxWager)
                {
                    if (account != null && cooldowns != null)
                    {
                        if (bet <= account.Balance)
                        {
                            var lastRoulette    = cooldowns.Roulette;
                            var cooldownHandler = new CooldownHandler();
                            var isCooledDown    = cooldownHandler.IsCooledDown(lastRoulette, "s", _rouletteCooldown);
                            if (isCooledDown)
                            {
                                var rng = new Random();
                                if (rng.Next(0, 2) > 0)
                                {
                                    account.AddBalance(bet);
                                    await ReplyAsync($"You won: {bet} Kredits!");
                                }
                                else
                                {
                                    account.SubtractBalance(bet);
                                    await ReplyAsync($"You lost: {bet} Kredits!");
                                }
                                cooldowns.Roulette = DateTime.Now;
                                db.Update(account);
                                db.Update(cooldowns);
                                await db.SaveChangesAsync();
                            }
                            else
                            {
                                var cooldown = cooldownHandler.GetDifference(DateTime.Now, lastRoulette.AddSeconds(_rouletteCooldown));
                                await ReplyAsync($"You can only roulette once every {_rouletteCooldown} seconds! \n" +
                                                 $"You still have to wait for: {cooldown}!");
                            }
                        }
                        else
                        {
                            await ReplyAsync("You can't afford that bet!");
                        }
                    }
                    else
                    {
                        await ReplyAsync("You dont have an account yet, type $acc to create one!");
                    }
                }
                else
                {
                    await ReplyAsync($"Wager between {_minWager}-{_maxWager} Kredits!");
                }
            }
        }