Ejemplo n.º 1
0
 public async Task CloseBet()
 {
     using (var db = new NeoContext()) {
         if (db.NeoBet.Any(x => x.ChannelId == Context.Channel.Id))   //if bet exist
         {
             if (db.NeoBet.FirstOrDefault(x => x.ChannelId == Context.Channel.Id).open)
             {
                 var obj = db.NeoBet.FirstOrDefault(x => x.ChannelId == Context.Channel.Id);
                 obj.open = false;
                 db.Update(obj);
                 db.SaveChanges();
                 var embed = NeoEmbeds.Minimal($"Bet closed. Good luck!").Build();
                 await ReplyAsync("", false, embed);
             }
             else     //already closed.
             {
                 var embed = NeoEmbeds.Error("Bet is already closed.", Context.User);
                 await ReplyAsync("", false, embed.Build());
             }
         }
         else
         {
             var embed = NeoEmbeds.Error("There is no active bets.", Context.User);
             await ReplyAsync("", false, embed.Build());
         }
     }
 }
Ejemplo n.º 2
0
        public async void TestUpdateNode()
        {
            var personGuid = Guid.NewGuid();
            var person     = new Person()
            {
                Age         = 50,
                DateOfBirth = DateTime.Now.AddYears(-50),
                Id          = personGuid,
                Name        = "neo",
                Salary      = 5400.77,
            };
            IDictionary <string, object> parameters = new Dictionary <string, object>()
            {
                { "Id", personGuid }
            };
            var            context         = new NeoContext(Driver);
            IResultSummary resultExecuting = await context.InsertNode <Person>(person);

            person.Age = 55;
            await context.Update <Person>("MATCH (p:Person { Id : $Id} )", parameters, "p", person);

            var resultPerson = await context.QueryDefault <Person>("MATCH (p:Person { Id : $Id} ) return p", parameters);

            Assert.Equal <Person>(person, resultPerson);
            await context.ExecuteQuery("MATCH (p:Person) DETACH DELETE p");
        }
Ejemplo n.º 3
0
 public async Task AwardCash([Summary("User to award cash")] IUser user, int cash)
 {
     using (var db = new NeoContext()) {
         if (db.Users.Any(x => x.Id == user.Id))
         {
             var dbuser = db.Users.FirstOrDefault(uwu => uwu.Id == user.Id);
             dbuser.Cash += cash;
             db.Update(dbuser);
             db.SaveChanges();
             var embed = NeoEmbeds.Minimal($"{user.Username} have been awarded {cash}₺ by {Context.User.Username}.");
             await ReplyAsync("", false, embed.Build());
         }
         else
         {
             var embed = NeoEmbeds.Minimal("User not found.");
             await ReplyAsync("", false, embed.Build());
         }
     }
 }
Ejemplo n.º 4
0
 public async Task Prefix([Summary("Prefix")] string prefix)
 {
     if (prefix.Length < 0 || prefix.Length > 15)
     {
         var embed = NeoEmbeds.Error("Prefix length can't be less than 0 or bigger than 15.", Context.User);
         await ReplyAsync("", false, embed.Build());
     }
     else
     {
         using (var db = new NeoContext()) {
             var obj = db.Guilds.FirstOrDefault(g => g.Id == Context.Guild.Id);
             obj.Prefix = prefix;
             db.Update(obj);
             db.SaveChanges();
             var embed = NeoEmbeds.Success($"Prefix of `{Context.Guild.Name}` has been set to `{prefix}`.", Context.User);
             await ReplyAsync("", false, embed.Build());
         }
     }
 }
Ejemplo n.º 5
0
            public async Task playBet([Summary("bet amount")] int cash, [Summary("bet")] int bet)
            {
                var flag1 = false;

                using (var db = new NeoContext()) {
                    if (!db.NeoBet.Any(x => x.ChannelId == Context.Channel.Id))   //no bet
                    {
                        var embed = NeoEmbeds.Error("There is no active bets.", Context.User);
                        await ReplyAsync("", false, embed.Build());
                    }
                    else if (!db.NeoBet.FirstOrDefault(x => x.ChannelId == Context.Channel.Id).open)    //closed bet
                    {
                        var embed = NeoEmbeds.Error("Bet is closed.", Context.User);
                        await ReplyAsync("", false, embed.Build());
                    }
                    else   //yes bet
                    {
                        var uwu = db.NeoBet.FirstOrDefault(x => x.ChannelId == Context.Channel.Id);
                        if (uwu.userBets?.Count > 0)
                        {
                            foreach (var betto in uwu.userBets)
                            {
                                if (betto.User.Id == Context.User.Id)
                                {
                                    var embed = NeoEmbeds.Error("You have already bet.", Context.User);
                                    await ReplyAsync("", false, embed.Build());

                                    flag1 = true;
                                    break;
                                }
                            }
                        }

                        if (flag1 == false)
                        {
                            var maxbet = db.NeoBet.FirstOrDefault(x => x.ChannelId == Context.Channel.Id);
                            var max    = maxbet.Bets.Count;
                            if (bet <= 0 || bet > max)   //thonk
                            {
                                var embed = NeoEmbeds.Error("Wrong bet location.", Context.User);
                                await ReplyAsync("", false, embed.Build());
                            }
                            else
                            {
                                var user = db.Users.FirstOrDefault(x => x.Id == Context.User.Id);
                                if (user.Cash < cash || cash <= 0) //not enough money
                                {
                                    var embed = NeoEmbeds.Error($"Not enough ₺ to play. (Have {user.Cash}₺)", Context.User);
                                    await ReplyAsync("", false, embed.Build());
                                }
                                else     //oh yes time to play baby

                                {
                                    var betobj = db.NeoBet.FirstOrDefault(x => x.ChannelId == Context.Channel.Id);

                                    var newobj = new NeoBets {
                                        BetAmount = cash,
                                        User      = db.Users.FirstOrDefault(a => a.Id == Context.User.Id),
                                        BetLoc    = bet
                                    };

                                    user.Cash -= cash;

                                    betobj.userBets.Add(newobj);

                                    db.Update(user);
                                    db.Update(betobj);
                                    db.SaveChanges();

                                    var embed = NeoEmbeds.Success($"Bet Accepted.", Context.User);
                                    await ReplyAsync("", false, embed.Build());
                                }
                            }
                        }
                    }
                }
            }