示例#1
0
 public async Task DeleteBet()
 {
     using (var db = new NeoContext()) {
         if (db.NeoBet.Any(x => x.ChannelId == Context.Channel.Id))
         {
             var obj = db.NeoBet.FirstOrDefault(x => x.ChannelId == Context.Channel.Id);
             foreach (var loser in obj.userBets)   //TODO: Actually refund people lmao
             {
                 if (loser.User.Cash < 500)
                 {
                     loser.User.Cash = 500;
                 }
                 db.Users.Update(loser.User);
             }
             foreach (var i in obj.userBets)
             {
                 db.Remove(i);
             }
             foreach (var i in obj.Bets)
             {
                 db.Remove(i);
             }
             db.NeoBet.Attach(obj);
             db.NeoBet.Remove(obj);
             db.SaveChanges();
             var embed = NeoEmbeds.Success("Bet removed.", Context.User);
             await ReplyAsync("", false, embed.Build());
         }
         else
         {
             var embed = NeoEmbeds.Error("There is no active bets.", Context.User);
             await ReplyAsync("", false, embed.Build());
         }
     }
 }
示例#2
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());
         }
     }
 }
示例#3
0
 public async Task PostInformation()
 {
     using (var db = new NeoContext()) {
         var chan = Context.Channel.Id;
         if (!db.NeoHubSettings.Any(x => x.ChannelId == chan))
         {
             var set = new NeoHub {
                 ChannelId = chan,
                 MsgId     = await PostInformationAsync(Context)
             };
             db.NeoHubSettings.Add(set);
             db.SaveChanges();
             await Context.Message.DeleteAsync();
         }
     }
 }
示例#4
0
        private Task _client_Ready()
        {
            Task.Run(() => {
                foreach (var guild in _client.Guilds)
                {
                    using (var db = new NeoContext()) {
                        if (db.Guilds.Any(x => x.Id == guild.Id))
                        {
                            continue;
                        }
                        var newobj = new Guild {
                            Id     = guild.Id,
                            Prefix = null
                        };
                        db.Guilds.Add(newobj);
                        db.SaveChanges();
                        Console.WriteLine($"Guild Added : {guild.Name}");
                    }
                }
            });

            Task.Run(async() => {
                using (var db = new NeoContext()) {
                    foreach (var hub in db.NeoHubSettings)
                    {
                        var m = await(_client.GetChannel(hub.ChannelId) as ITextChannel)
                                .GetMessageAsync(hub.MsgId);
                        await(m as IUserMessage).ModifyAsync(x => x.Embed = NeoEmbeds.Information(_client));
                    }
                }
            });

            _autoEvent    = new AutoResetEvent(false);
            _playingTimer = new Timer(ChangePlayingAsync, _autoEvent, 0, 1000 * 60 * 5);
            Task.Run(async() => {
                using (var db = new NeoContext()) {
                    if (!db.Playings.Any())
                    {
                        return;
                    }
                    var game = await db.Playings.AsAsyncEnumerable().OrderBy(o => Guid.NewGuid())
                               .FirstOrDefaultAsync();
                    await _client.SetGameAsync(game.Name);
                }
            });
            return(Task.CompletedTask);
        }
示例#5
0
            public async Task FinishBet([Summary("Winning Bet Index")] int winning_index)
            {
                using (var db = new NeoContext()) {
                    if (db.NeoBet.Any(x => x.ChannelId == Context.Channel.Id))   //if bet
                    {
                        var           bet     = db.NeoBet.FirstOrDefault(x => x.ChannelId == Context.Channel.Id);
                        var           realbet = bet.Bets.ToArray()[winning_index - 1];
                        StringBuilder sb      = new StringBuilder();
                        StringBuilder sbloser = new StringBuilder();
                        foreach (var userBet in bet.userBets.Where(b => b.BetLoc == winning_index))
                        {
                            var newcash = (int)(userBet.BetAmount * realbet.BetRate);
                            userBet.User.Cash += newcash;
                            db.Users.Update(userBet.User);
                            sb.Append($"{Context.Guild.GetUser(userBet.User.Id).Username} : {newcash}₺\n");
                        } // give everybody their winnings

                        foreach (var loser in bet.userBets.Where(b => b.BetLoc != winning_index))
                        {
                            sbloser.Append($"{Context.Guild.GetUser(loser.User.Id).Username} : {loser.BetAmount}₺\n");
                            if (loser.User.Cash < 500)
                            {
                                loser.User.Cash = 500;
                            }
                            db.Users.Update(loser.User);
                        }
                        //lets remove the bet and update users

                        foreach (var i in bet.userBets)
                        {
                            db.Remove(i);
                        }
                        foreach (var i in bet.Bets)
                        {
                            db.Remove(i);
                        }
                        db.Attach(bet);
                        db.Remove(bet);
                        db.SaveChanges();
                        var winners = sb.ToString();
                        var losers  = sbloser.ToString();
                        var embed   = NeoEmbeds.Minimal($"**Winners**:\n {(!string.IsNullOrEmpty(winners) ? winners : "No one wins")}\n **Losers**:\n {(!string.IsNullOrEmpty(losers) ? losers : "No losers")}");
                        await ReplyAsync("", false, embed.Build());
                    }
                }
            }
示例#6
0
        public async Task PostInformation(ulong mid)
        {
            using (var db = new NeoContext()) {
                var chan = Context.Channel.Id;
                if (db.NeoHubSettings.Any(x => x.MsgId == mid))
                {
                    var set = db.NeoHubSettings.FirstOrDefault(f => f.MsgId == mid);
                    db.NeoHubSettings.Remove(set);
                    db.SaveChanges();
                    await Context.Message.DeleteAsync();

                    var m = await(Context.Client.GetChannel(set.ChannelId) as ITextChannel)
                            .GetMessageAsync(set.MsgId);
                    await m.DeleteAsync();
                }
            }
        }
示例#7
0
 public async Task RemGame([Summary("Game Name")][Remainder] string game)
 {
     using (var db = new NeoContext()) {
         if (!db.Playings.Any(x => x.Name == game))
         {
             var embedFail = NeoEmbeds.Minimal("Game do not exist in current queue.").Build();
             await ReplyAsync("", false, embedFail);
         }
         else
         {
             var obj = db.Playings.FirstOrDefault(x => x.Name == game);
             db.Playings.Remove(obj);
             db.SaveChanges();
             var embedSucc = NeoEmbeds.Minimal($"Successfully removed {game} from the queue.").Build();
             await ReplyAsync("", false, embedSucc);
         }
     }
 }
示例#8
0
            public async Task DelBlacklist([Summary("User ID")] ulong userid)
            {
                using (var db = new NeoContext()) {
                    if (!db.Blacklist.Any(bl => bl.User == db.Users.FirstOrDefault(u => u.Id == userid)))
                    {
                        var builder = NeoEmbeds.Error("User is not blacklisted.", Context.User);
                        await ReplyAsync("", false, builder.Build());

                        return;
                    }

                    var obj = db.Blacklist.FirstOrDefault(bl => bl.User == db.Users.FirstOrDefault(u => u.Id == userid));
                    db.Blacklist.Remove(obj);
                    db.SaveChanges();
                    var builder2 = NeoEmbeds.Success("User removed from blacklist.", Context.User);
                    await ReplyAsync("", false, builder2.Build());
                }
            }
示例#9
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());
         }
     }
 }
示例#10
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());
         }
     }
 }
示例#11
0
 public async Task AddGame([Summary("Game Name")][Remainder] string game)
 {
     using (var db = new NeoContext()) {
         if (db.Playings.Any(x => x.Name == game))
         {
             var embedFail = NeoEmbeds.Minimal("Game exists in current queue.").Build();
             await ReplyAsync("", false, embedFail);
         }
         else
         {
             var obj = new Playing {
                 Name = game
             };
             db.Playings.Add(obj);
             db.SaveChanges();
             var embedSucc = NeoEmbeds.Minimal($"Successfully added {game} to the queue.").Build();
             await ReplyAsync("", false, embedSucc);
         }
     }
 }
示例#12
0
            public async Task AddBlacklist([Summary("User ID")] ulong userid, [Summary("Reason")][Remainder] string reason = null)
            {
                using (var db = new NeoContext()) {
                    if (db.Blacklist.Any(bl => bl.User == db.Users.FirstOrDefault(u => u.Id == userid)))
                    {
                        var builder = NeoEmbeds.Error("User is already blacklisted.", Context.User);
                        await ReplyAsync("", false, builder.Build());

                        return;
                    }

                    var obj = new Blacklist {
                        User     = db.Users.FirstOrDefault(u => u.Id == userid),
                        Creation = DateTime.Now,
                        reason   = reason
                    };
                    db.Blacklist.Add(obj);
                    db.SaveChanges();
                    var builder2 = NeoEmbeds.Success("User is now blacklisted.", Context.User);
                    await ReplyAsync("", false, builder2.Build());
                }
            }
示例#13
0
        private async Task HandleTag(SocketUserMessage e)
        {
            using (var db = new NeoContext()) {
                if (!db.Tags.Any(t =>
                                 t.Trigger == e.Content))
                {
                    return;
                }
                var obj = db.Tags.FirstOrDefault(t => t.Trigger == e.Content);
                if (obj.IfAttachment)
                {
                    await NeoConsole.Log(LogSeverity.Critical, "TAG", obj.Value);

                    //await e.Channel.SendFileAsync(obj.Value,"henlo");
                    await e.Channel.SendMessageAsync("", false, NeoEmbeds.Picture(obj.Value, e.Author));
                }
                else
                {
                    await e.Channel.SendMessageAsync(obj.Value);
                }
                db.SaveChanges();
            }
        }
示例#14
0
            public async Task Away([Summary("Time and/or Reason")][Remainder] string reason = null)
            {
                using (var db = new NeoContext()) {
                    if (db.Afks.Any(afk => afk.User == db.Users.FirstOrDefault(u => u.Id == Context.User.Id))) //user is afk so he is back now
                    {
                        var obj = db.Afks.FirstOrDefault(afk => afk.User == db.Users.FirstOrDefault(u => u.Id == Context.User.Id));
                        if (string.IsNullOrEmpty(obj?.Reason))
                        {
                            var embed = NeoEmbeds.Afk($"{Context.User} is back!", Context.User);
                            await ReplyAsync("", false, embed.Build());
                        }
                        else
                        {
                            var embed = NeoEmbeds.Afk($"{Context.User} is back from {obj.Reason.TrimStart()}!", Context.User);
                            await ReplyAsync("", false, embed.Build());
                        }
                        db.Afks.Attach(obj ?? throw new InvalidOperationException());
                        db.Afks.Remove(obj);
                        db.SaveChanges();
                    }
                    else
                    {
                        var obj = new Afk();
                        if (reason != null)                                                                                  // there is time and or reason
                        {
                            var time = reason.Substring(0, reason.IndexOf(' ') <= -1 ? reason.Length : reason.IndexOf(' ')); // get first block
                            if (CheckTimeString(time))                                                                       //check if first block is time string
                            {
                                var timestr = HandleTime(time);                                                              //get timespan from that block
                                reason = reason.Replace(time, "");                                                           //get time out of reason
                                if (reason.Length == 0)
                                {
                                    var embed = NeoEmbeds.Afk($"{Context.User} is now afk!", Context.User, null, Thing(timestr));
                                    await ReplyAsync("", false, embed.Build());

                                    obj.Reason = null;
                                    obj.Time   = (DateTime.Now + timestr);
                                    obj.User   = db.Users.FirstOrDefault(u => u.Id == Context.User.Id);
                                }
                                else
                                {
                                    var embed = NeoEmbeds.Afk($"{Context.User} is now afk!", Context.User, reason, Thing(timestr));
                                    await ReplyAsync("", false, embed.Build());

                                    obj.Reason = reason;
                                    obj.Time   = (DateTime.Now + timestr);
                                    obj.User   = db.Users.FirstOrDefault(u => u.Id == Context.User.Id);
                                }
                            }
                            else  //no time just reason
                            {
                                var embed = NeoEmbeds.Afk($"{Context.User} is now afk!", Context.User, reason);
                                await ReplyAsync("", false, embed.Build());

                                obj.Reason = reason;
                                obj.Time   = default(DateTime);
                                obj.User   = db.Users.FirstOrDefault(u => u.Id == Context.User.Id);
                            }
                        }
                        else  //no reason and time
                        {
                            var embed = NeoEmbeds.Afk($"{Context.User} is now afk!", Context.User);
                            await ReplyAsync("", false, embed.Build());

                            obj.Reason = null;
                            obj.Time   = default(DateTime);
                            obj.User   = db.Users.FirstOrDefault(u => u.Id == Context.User.Id);
                        }
                        db.Afks.Add(obj);
                        db.SaveChanges();
                    }
                }
            }
示例#15
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());
                                }
                            }
                        }
                    }
                }
            }
示例#16
0
        private async Task HandleCommand(SocketMessage s)
        {
            var msg = s as SocketUserMessage;

            if (msg == null)
            {
                return;                                           // Check if the received message is from a user.
            }
            var context = new SocketCommandContext(_client, msg); // Create a new command context.

            if (context.User.IsBot)
            {
                return;
            }
            var prefix = Configuration.Load().Prefix;

            using (var db = new NeoContext()) {
                if (!db.Users.Any(x => x.Id == msg.Author.Id)) //if user does net exist in database create it
                {
                    var newobj = new DbUser {
                        Id   = msg.Author.Id,
                        Cash = 500
                    };
                    db.Users.Add(newobj);
                    db.SaveChanges();
                }
                if (!(msg.Channel is ISocketPrivateChannel) && db.Guilds.Any(x => x.Id == (msg.Channel as IGuildChannel).GuildId))
                {
                    prefix = db.Guilds.FirstOrDefault(x => x.Id == (msg.Channel as IGuildChannel).GuildId).Prefix ?? Configuration.Load().Prefix;
                }
                if (db.Blacklist.Any(bl => bl.User == db.Users.FirstOrDefault(u => u.Id == context.User.Id)))
                {
                    return;
                }
            }

            await CheckAfk(msg);
            await HandleTag(msg);

            await NeoConsole.Log(msg);

            var argPos = 0;                                     // Check if the message has either a string or mention prefix.

            if (msg.HasStringPrefix(prefix, ref argPos) ||
                msg.HasStringPrefix(Configuration.Load().Prefix, ref argPos) ||
                msg.HasMentionPrefix(_client.CurrentUser, ref argPos))
            {
                IResult result; // Try and execute a command with the given context.
                try {
                    result = await _cmds.ExecuteAsync(context, argPos, _services);

                    if (!result.IsSuccess && result.Error != CommandError.UnknownCommand)
                    {
                        var embed = NeoEmbeds.Error(result.ErrorReason, context.User, result.Error != null ? result.Error.ToString() : "Error").Build();
                        await context.Channel.SendMessageAsync("", false, embed);
                    }
                } catch (Exception ex) {
                    var embed = NeoEmbeds.Minimal(ex.Message).AddField("inner", ex.InnerException?.Message ?? "nope");
                    await NeoConsole.NewLine(ex.StackTrace);

                    await context.Channel.SendMessageAsync("", false, embed.Build());
                }
            }
        }
示例#17
0
            public async Task CreateBet([Summary("The bet"), Remainder] string betname)
            {
                using (var db = new NeoContext()) {
                    if (db.NeoBet.Any(x => x.ChannelId == Context.Channel.Id))   //there is a bet
                    {
                        var embed = NeoEmbeds.Error("There is already a bet going.", Context.User);
                        await ReplyAsync("", false, embed.Build());
                    }
                    else     //Create bet
                    {
                        var    tuples  = new List <Tuple <string, double> >();
                        var    count   = 0;
                        double answer2 = 0.0;

                        var msg = await ReplyAsync("How many rates?");

                        var response = await NextMessageAsync(true, true, TimeSpan.FromSeconds(30));

                        if (response != null)
                        {
                            if (int.TryParse(response.Content, out count))
                            {
                                if (count <= 0 || count >= 5)
                                {
                                    await ReplyAndDeleteAsync("Please give a number either bigger than 0 or lower than 5.", false, null, TimeSpan.FromSeconds(5));
                                }
                                else     // we gucci lets get the nay nays
                                {
                                    for (int index = 0; index < count; index++)
                                    {
                                        var old1 = await ReplyAsync($"Bet {index + 1}:");

                                        var response1 = await NextMessageAsync(true, true, TimeSpan.FromSeconds(30));

                                        if (response1 != null)
                                        {
                                            var old2 = await ReplyAsync($"Bet rate {index + 1}:");

                                            var response2 = await NextMessageAsync(true, true, TimeSpan.FromSeconds(30));

                                            if (response2 != null)
                                            {
                                                if (double.TryParse(response2.Content, out answer2))
                                                {
                                                    tuples.Add(new Tuple <string, double>(response1.Content, answer2));
                                                    var messages = await Context.Channel.GetMessagesAsync(20).FlattenAsync();

                                                    messages = messages.Where(x => x.Id == msg.Id || x.Id == old1.Id || x.Id == old2.Id || x.Id == response.Id || x.Id == response1.Id || x.Id == response2.Id);
                                                    await(Context.Channel as ITextChannel).DeleteMessagesAsync(messages);
                                                }
                                                else
                                                {
                                                    await ReplyAndDeleteAsync("Please give a corrent number.", false, null, TimeSpan.FromSeconds(5));

                                                    await Task.CompletedTask;
                                                }
                                            }
                                            else
                                            {
                                                await ReplyAndDeleteAsync("You did not reply before the timeout.", false, null, TimeSpan.FromSeconds(5));

                                                await Task.CompletedTask;
                                            }
                                        }
                                        else
                                        {
                                            await ReplyAndDeleteAsync("You did not reply before the timeout.", false, null, TimeSpan.FromSeconds(5));

                                            await Task.CompletedTask;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                await ReplyAndDeleteAsync("Please give a number.", false, null, new TimeSpan(0, 0, 5));

                                await Task.CompletedTask;
                            }
                        }
                        else
                        {
                            await ReplyAndDeleteAsync("You did not reply before the timeout.", false, null, new TimeSpan(0, 0, 5));

                            await Task.CompletedTask;
                        }



                        var msgobj = await ReplyAsync("Creating new bet...");

                        var betobj = new NeoBet {
                            BetName   = betname,
                            ChannelId = Context.Channel.Id,
                            open      = true,
                            msgID     = msgobj.Id
                        };
                        foreach (var tple in tuples)
                        {
                            betobj.Bets.Add(new Bet {
                                BetName = tple.Item1,
                                BetRate = tple.Item2
                            });
                        }

                        db.NeoBet.Attach(betobj);
                        db.SaveChanges();

                        var embed = NeoEmbeds.Bet(
                            betobj.BetName,
                            betobj.Bets,
                            0,
                            ""
                            );
                        await msgobj.ModifyAsync(x => { x.Embed = embed.Build(); x.Content = ""; });
                    }
                }
            }
示例#18
0
 public bool Commit()
 {
     return(_context.SaveChanges() > 0);
 }
示例#19
0
 public int Salvar()
 {
     return(Db.SaveChanges());
 }