Ejemplo n.º 1
0
        public void Test()
        {
            using (var context = new mashDbContext())
            {
                // Add user.
                context.Users.Add(new Users
                {
                    Name      = "pmash2",
                    EntryDate = DateTime.Now
                });
                context.Users.Add(new Users
                {
                    Name      = "hunter2140",
                    EntryDate = DateTime.Now
                });
                context.SaveChanges();

                // Fetch Reminders
                var users = context.Users.ToArray();
                foreach (var user in users)
                {
                    Console.WriteLine($"We found user {user.Name}!");
                }
            }
        }
Ejemplo n.º 2
0
        public UserPoints GetPointsRecord(string user)
        {
            UserPoints pointsRecord;

            using (var context = new mashDbContext())
            {
                pointsRecord = context.UserPoints
                               .Where(x => x.Viewer == user.ToLower())
                               .FirstOrDefault();

                if (pointsRecord == null)
                {
                    UserPoints newRecord = new()
                    {
                        Viewer = user.ToLower(),
                        Points = 0
                    };

                    context.UserPoints.Add(newRecord);
                    pointsRecord = newRecord;
                    context.SaveChanges();
                }
            }

            return(pointsRecord);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var envReader = new EnvReader();

            DotEnv.Config(true, "mySecrets");
            var channel  = envReader.GetStringValue("CHANNEL");
            var token    = envReader.GetStringValue("BOT_PASSWORD");
            var endpoint = envReader.GetStringValue("API_ENDPOINT");

#if DEBUG
            using (var context = new mashDbContext())
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
            }
#endif

            BotSettings settings = new(endpoint);
            var         bot      = new Bot(channel, token, settings);

            while (true)
            {
                bot.settings.RefreshSettings();
                System.Threading.Thread.Sleep(1000);
            }

            Console.WriteLine("We made it here without error!");
        }
Ejemplo n.º 4
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _logger.LogInformation($"{Directory.GetCurrentDirectory()}");
            Console.WriteLine("Hello World!");
            var envReader = new EnvReader();

            DotEnv.Config(true, "mySecrets");
            var channel  = envReader.GetStringValue("CHANNEL");
            var token    = envReader.GetStringValue("BOT_PASSWORD");
            var endpoint = envReader.GetStringValue("API_ENDPOINT");

#if DEBUG
            using (var context = new mashDbContext())
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
            }
#endif

            BotSettings settings = new(endpoint);
            var         bot      = new Bot(channel, token, settings);

            while (!stoppingToken.IsCancellationRequested)
            {
                //_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
                bot.settings.RefreshSettings(_logger);
                await Task.Delay(1000, stoppingToken);
            }
        }
Ejemplo n.º 5
0
        public string Execute(string username, string[] args, BotSettings settings)
        {
            var    records = new List <TodaysMessage>();
            string message;

            using (var context = new mashDbContext())
            {
                records = context.TodaysMessage
                          .Where(x => x.Date >= DateTime.Now.Date)
                          .Where(x => x.Date <= DateTime.Now.AddDays(1).Date)
                          .OrderBy(x => x.Date)
                          .ToList();
            }

            if (records.Count == 1)
            {
                message = records.First().Message;
            }
            else if (records.Count > 1)
            {
                message = records.Last().Message;
            }
            else
            {
                message = "I don't know what we're doing today!";
            }

            return(message);
        }
Ejemplo n.º 6
0
        public GlobalConfigs GetConfig(string key)
        {
            using var context = new mashDbContext();

            return(context.GlobalConfigs
                   .SingleOrDefault(x => x.Key == key));
        }
Ejemplo n.º 7
0
 public void UpdateDescription(string key, string description)
 {
     using (var context = new mashDbContext())
     {
         var record = GetConfig(key);
         record.Description = description;
         context.GlobalConfigs.Update(record);
     }
 }
Ejemplo n.º 8
0
 public void UpdateValue(string key, string value)
 {
     using (var context = new mashDbContext())
     {
         var record = GetConfig(key);
         record.Value = value;
         context.GlobalConfigs.Update(record);
     }
 }
Ejemplo n.º 9
0
        public Users GetUser(string username)
        {
            Users user;

            using (var context = new mashDbContext())
            {
                user = context.Users.Where(x => x.Name == username).FirstOrDefault();
            }

            return(user);
        }
Ejemplo n.º 10
0
        public void AddUser(string username)
        {
            var user = new Users
            {
                Name      = username,
                EntryDate = DateTime.Now
            };

            using (var context = new mashDbContext())
            {
                context.Users.Add(user);
                context.SaveChanges();
            }
        }
Ejemplo n.º 11
0
        public static StaticCommands GetCommand(string keyword)
        {
            StaticCommands cmd = new();

            keyword = CheckForBang(keyword);

            using (var context = new mashDbContext())
            {
                cmd = context.StaticCommands
                      .Where(x => x.Keyword == keyword)
                      .FirstOrDefault();
            }

            return(cmd);
        }
Ejemplo n.º 12
0
        public static void DeleteCommand(StaticCommands cmd)
        {
            if (string.IsNullOrEmpty(cmd.Keyword))
            {
                throw new System.ArgumentException();
            }

            cmd.Keyword = CheckForBang(cmd.Keyword);

            using (var context = new mashDbContext())
            {
                context.Remove(GetCommand(cmd.Keyword));
                context.SaveChanges();
            }
        }
Ejemplo n.º 13
0
        public static string GetRecord(string userName)
        {
            var message = "";
            var records = new List <WinLoss>();

            using (var context = new mashDbContext())
            {
                records = context.WinLoss.Where(x => x.UserName == userName).ToList();
            }

            var wins   = records.Where(x => x.DidWin == true).Count();
            var losses = records.Count - wins;

            message = $"{userName}'s current win loss record is : {wins} - {losses}";
            return(message);
        }
Ejemplo n.º 14
0
        public static DateTime GetLastCheckIn(string username)
        {
            DateTime lastCheckIn;

            using (var context = new mashDbContext())
            {
                lastCheckIn = context.TransactionLog
                              .Where(x => x.Notes == "Checked in!")
                              .Where(x => x.Receiver == username)
                              .OrderByDescending(x => x.Date)
                              .Select(x => x.Date)
                              .FirstOrDefault();
            }

            return(lastCheckIn);
        }
Ejemplo n.º 15
0
        public static void UpdateCommand(StaticCommands cmd)
        {
            if (string.IsNullOrEmpty(cmd.Keyword) || string.IsNullOrEmpty(cmd.Text))
            {
                throw new System.ArgumentException();
            }

            cmd.Keyword = CheckForBang(cmd.Keyword);

            using (var context = new mashDbContext())
            {
                var existing = GetCommand(cmd.Keyword);
                existing.Text = cmd.Text;

                context.Update(existing);
                context.SaveChanges();
            }
        }
Ejemplo n.º 16
0
        public static string PlayGame(bool betEven, string userName, int wager, UserPointsRepo mgr)
        {
            var rand   = new Random();
            var number = rand.Next(0, 1000);
            var didWin = false;

            Console.WriteLine($"The random number for this round is {number}");

            var isEven = number % 2 == 0 ? true : false;

            string result = $"The number was {number}. ";

            if (betEven && isEven || !betEven && !isEven)
            {
                result += "YOU WIN!!!!";
                didWin  = true;
                mgr.ChangePoints(userName, "", wager, "Won OddOrEven");
            }
            else
            {
                result += "Oh no, you lose! :(";
                didWin  = false;
                mgr.ChangePoints(userName, "", wager * -1, "Lost OddOrEven");
            }

            using (var context = new mashDbContext())
            {
                context.WinLoss.Add(new WinLoss
                {
                    UserName = userName,
                    DidWin   = didWin,
                    Date     = DateTime.Now,
                    Game     = "OddOrEven"
                });
                context.SaveChanges();
            }

            return(result);
        }
Ejemplo n.º 17
0
        public string Execute(string username, string[] args, BotSettings settings)
        {
            // !addconfig PTS multiplier 2

            if (args.Length < 4)
            {
                return($"@{username}, try !addcommand PTS multiplier 2");
            }

            string key         = args[1];
            string description = args[2];
            string value       = args[3];

            GlobalConfigsManager cfgMgr = new();

            if (cfgMgr.GetConfig(key) != null)
            {
                return($"@{username}, that configuration already exists : {key}");
            }

            using (var context = new mashDbContext())
            {
                GlobalConfigs cfg = new()
                {
                    Key         = key,
                    Description = description,
                    Value       = value,
                    DateUpdated = DateTime.Now
                };

                context.GlobalConfigs.Add(cfg);
                context.SaveChanges();
            }

            return($"@{username}, configuration saved");
        }
    }
Ejemplo n.º 18
0
        public string Execute(string username, string[] args, BotSettings settings)
        {
            string result;

            if (username == "pmash2")
            {
                var message = new TodaysMessage
                {
                    Message = String.Join(' ', args, 1, args.Length - 1),
                    Date    = DateTime.Now
                };

                using (var context = new mashDbContext())
                {
                    context.TodaysMessage.Add(message);
                    context.SaveChanges();
                }

                try
                {
                    PostMessage(settings.Endpoint, message.Message);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error posting today's message: {ex.Message}");
                }

                result = "Today's message has been updated";
            }
            else
            {
                result = "Sorry, you're not allowed to do that";
            }

            return(result);
        }
Ejemplo n.º 19
0
        public List <GlobalConfigs> GetAllConfigs()
        {
            using var context = new mashDbContext();

            return(context.GlobalConfigs.ToList());
        }