Exemplo n.º 1
0
        private Task AddUserToDb(SocketMessage arg)
        {
            using (var dctx = new CwsContext())
            {
                User DbUser = dctx.Users.SingleOrDefault(x => x.UserId == arg.Author.Id);

                if (DbUser is null)
                {
                    User NewDbUser = new User
                    {
                        UserId       = arg.Author.Id,
                        Karma        = 0,
                        WarningCount = 0,
                        MessageCount = 1,
                        Tokens       = 0,
                        KarmaTime    = DateTimeOffset.Now.AddDays(-1),
                        Username     = arg.Author.Username
                    };

                    dctx.Add(NewDbUser);
                    dctx.SaveChanges();
                    return(Task.CompletedTask);
                }

                DbUser.MessageCount++;
                dctx.SaveChanges();
                return(Task.CompletedTask);
            }
        }
Exemplo n.º 2
0
        public async Task RepAsync(SocketGuildUser user)
        {
            // check that recieving user exists
            if (!_dbContext.Users.Any(x => x.UserId == user.Id))
            {
                await AddUser(user);
            }

            var givingDbUser = _dbContext.Users.FirstOrDefault(x => x.UserId == Context.User.Id);

            // check that one day has passed, rep isn't being given to a bot, and that its for another user.
            if ((DateTimeOffset.Now - givingDbUser.KarmaTime).TotalDays < 1 || user.IsBot || user.Id == Context.User.Id)
            {
                await Context.Message.AddReactionAsync(new Emoji(DeniedEmoji)); // Denied emoji

                return;
            }

            var recievingDbUser = _dbContext.Users.FirstOrDefault(x => x.UserId == user.Id);

            // add, save and let users know it worked.
            if (recievingDbUser.Karma + 1 >= 30 && !user.Roles.Any(x => x.Id == 364042915619799050))
            {
                var newrole = Context.Guild.Roles.FirstOrDefault(x => x.Id == 364042915619799050);
                if (newrole != null)
                {
                    await user.AddRoleAsync(newrole);
                }
                else
                {
                    Console.WriteLine("No such role \"abyss\"");
                }
            }

            recievingDbUser.Karma += 1;
            givingDbUser.KarmaTime = DateTimeOffset.Now;
            _dbContext.SaveChanges();
            await Context.Message.AddReactionAsync(new Emoji("\u2611")); // Accepted emoji
        }
Exemplo n.º 3
0
 protected override void AfterExecute(CommandInfo command)
 {
     _dbContext?.SaveChanges();
 }
Exemplo n.º 4
0
        public async Task Gamble(double stakes)
        {
            var userMoney = _dctx.Users.SingleOrDefault(x => x.UserId == Context.User.Id);

            if (userMoney.Tokens < stakes)
            {
                await ReplyAsync($"(GambleDragon) :dragon_face:: {Context.User.Mention}, you're missing {stakes - userMoney.Tokens} tokens to do that!\n" +
                                 $"(Your current tokens: {userMoney.Tokens})!");

                return;
            }

            if (stakes < 1 || stakes > 50)
            {
                await ReplyAsync($"(GambleDragon) :dragon_face:: I'm sorry, we only take wagers between 1-50.");

                return;
            }

            Random rnd = new Random();

            double dice1Roll   = rnd.Next(1, 7);
            double dice2Roll   = rnd.Next(1, 7);
            double pointResult = 0;

            string rollResultText = $"(GambleDragon) :dragon_face:: {Context.User.Mention}, Your roll consisting of a __{dice1Roll}__ and a __{dice2Roll}__, earned points for: \n";

            if (dice1Roll == dice2Roll)
            {
                pointResult    += (int)Math.Ceiling(stakes * 0.5);
                rollResultText += $":diamonds: rolling a double ({dice1Roll}). *+{(int)Math.Ceiling(stakes * 0.5)} points!*\n";
            }
            if (dice1Roll == 6 || dice2Roll == 6)
            {
                if (dice1Roll == 6 && dice2Roll == 6)
                {
                    pointResult    += (int)Math.Ceiling(stakes * 2.4);
                    rollResultText += $":hearts: rolling two 6's. *+{(int)Math.Ceiling(stakes * 2.4)} points!*\n";
                }
                else
                {
                    pointResult    += (int)Math.Ceiling(stakes * 1.2);
                    rollResultText += $":hearts: rolling a 6. *+{(int)Math.Ceiling(stakes * 1.2)} points!*\n";
                }
            }
            if ((dice1Roll + dice2Roll) % 4 == 0)
            {
                pointResult    += (int)Math.Ceiling(stakes * ((3 * ((dice1Roll + dice2Roll) / 4)) / 10));
                rollResultText += $":spades: the sum of your roll was a multiple of 4. *+{(int)Math.Ceiling(stakes * (3 * ((dice1Roll + dice2Roll) / 4) / 10))} point(s)!*\n";
            }
            if ((dice1Roll + dice2Roll) % 3 == 0)
            {
                pointResult    += (int)Math.Ceiling(stakes * ((3 * ((dice1Roll + dice2Roll) / 3)) / 10));
                rollResultText += $":clubs: the sum of your roll was a multiple of 3. *+{(int)Math.Ceiling(stakes * (3 * ((dice1Roll + dice2Roll) / 3) / 10))} point(s)!*\n";
            }

            stakes = -stakes;

            if (pointResult == 0)
            {
                rollResultText = $"(GambleDragon) :dragon_face:: {Context.User.Mention}, Your roll consisting of a __{dice1Roll}__ and a __{dice2Roll}__, earned you no points.\n" +
                                 $"*as such, I'll be taking your money.* ***({stakes} tokens)***";
            }
            else
            {
                if ((stakes + pointResult) >= 0)
                {
                    rollResultText += $":game_die: this comes down to a total of {pointResult} points!\n\n" +
                                      $"***Stakes: {stakes}, Points: {pointResult}, Actual profit: {stakes + pointResult} :moneybag:***\n";
                }
                else
                {
                    rollResultText += $":game_die: this comes down to a total of {pointResult} points!\n\n" +
                                      $"***Stakes: {stakes}, Points: {pointResult}, Actual loss: {stakes + pointResult} :money_with_wings:***\n";
                }
            }

            int profitResult = Convert.ToInt32(stakes + pointResult);

            userMoney.Tokens -= Convert.ToUInt32(profitResult);

            _dctx.SaveChanges();
            await ReplyAsync(rollResultText);
        }