static public async Task registerUser(SocketMessage message)
        {
            //Expected input:
            //%register - Register the user with nil weight
            //%register 250 - Register the user with weight 250
            //%register 250 200 - Register the user with weight 250 and goal of 200
            string[] messageContext = message.Content.Split(" ");
            float    userWeight     = 0;
            float    userGoal       = 0;

            switch (messageContext.Length)
            {
            case 3:
                userGoal = float.Parse(messageContext[2]);
                goto case 2;

            case 2:
                userWeight = float.Parse(messageContext[1]);
                break;

            default:
                break;
            }
            //ok if we made it past this point our little kitten should be good and ready to be petted and placed into the database nyaaaa~
            using (var db = new Models.fitotron_devContext())
            {
                var user = new Models.Users
                {
                    discordID     = message.Author.Id,
                    CurrentWeight = userWeight,
                    Goal          = userGoal
                };
                await db.Users.AddAsync(user);

                var weight = new Models.Weights
                {
                    User       = user,
                    UserWeight = userWeight,
                    TimeStamp  = DateTime.Now
                };
                await db.Weights.AddAsync(weight);

                await db.SaveChangesAsync();
            }
            await message.Channel.SendMessageAsync("Successuflly added user!");
        }
        static public async Task updateGoal(SocketMessage message)
        {
            string[] messageContent = message.Content.Split(" ");
            double   newGoal;

            if (double.TryParse(messageContent[1], out newGoal))
            {
                using (var db = new Models.fitotron_devContext())
                {
                    var user = db.Users.Where(e => e.discordID == message.Author.Id);
                    if (user.Any())
                    {
                        Models.Users foundUser = user.First();
                        double?      oldGoal   = foundUser.Goal;
                        foundUser.Goal = newGoal;
                        db.Users.Update(foundUser);
                        await db.SaveChangesAsync();

                        if (oldGoal != null)
                        {
                            await message.Channel.SendMessageAsync($"Ok Updated user goal from {oldGoal} Lbs to {newGoal} Lbs");
                        }
                        else
                        {
                            await message.Channel.SendMessageAsync($"Ok Updated user goal to {newGoal}");
                        }
                    }
                    else
                    {
                        await message.Channel.SendMessageAsync($"Error: User not Found! Make sure to register first with `{Program.commandPrefix + Program.registerCommand}` !");
                    }
                }
            }
            else
            {
                await message.Channel.SendMessageAsync($"Error: Sorry but {messageContent[1]} is not a valid number.");
            }
        }
        public static async Task addWeight(SocketMessage message)
        {
            string[] args = message.Content.Split(" ");
            //Ok, we are expecting the format of `%addweight 888` where 888 is the weight
            using (var db = new Models.fitotron_devContext())
            {
                var user = db.Users.Where(e => e.discordID == message.Author.Id);
                if (user.Any())
                {
                    Models.Users foundUser = user.First();
                    double       newWeight;
                    if (double.TryParse(args[1], out newWeight))
                    {
                        Models.Weights weight = new Models.Weights
                        {
                            User       = foundUser,
                            UserWeight = newWeight,
                            TimeStamp  = DateTime.Now
                        };
                        await db.Weights.AddAsync(weight);

                        foundUser.CurrentWeight = newWeight;
                        db.Users.Update(foundUser);
                        await db.SaveChangesAsync();

                        await message.Channel.SendMessageAsync("Added New Weight!");
                    }
                    else
                    {
                        await message.Channel.SendMessageAsync($"Error!: Was expecting a numeric number. instead got {args[1]}");
                    }
                }
                else
                {
                    await message.Channel.SendMessageAsync($"Error!: You need to register first with {Program.commandPrefix+Program.registerCommand}");
                }
            }
        }
        static public async Task getUser(SocketMessage message)
        {
            string[] messageContext = message.Content.Split(" ");
            ulong    userID;

            if (message.MentionedUsers.Any())
            {
                userID = message.MentionedUsers.First().Id;
            }
            else
            {
                userID = message.Author.Id;
            }
            using (var db = new Models.fitotron_devContext())
            {
                var user = db.Users.Where(e => e.discordID == userID);
                if (user.Any())
                {
                    Models.Users foundUser    = user.First();
                    string       returnString = "User Found!";
                    if (foundUser.CurrentWeight != null)
                    {
                        returnString += $"\n\tCurrent Weight: {Math.Round((double)foundUser.CurrentWeight, 1)} Lbs";
                    }
                    if (foundUser.Goal != null)
                    {
                        returnString += $"\n\tWeight Goal: {Math.Round((double)foundUser.Goal, 1)} Lbs";
                    }
                    await message.Channel.SendMessageAsync(returnString);
                }
                else
                {
                    await message.Channel.SendMessageAsync("Could not find user!");
                }
            }
        }
Exemple #5
0
        public static async Task generateChart(SocketMessage message)
        {
            string[] messageContext = message.Content.Split(" ");
            ulong    userId;

            if (message.MentionedUsers.Any())
            {
                userId = message.MentionedUsers.First().Id;
            }
            else
            {
                userId = message.Author.Id;
            }
            using (var db = new Models.fitotron_devContext())
            {
                var user = db.Users.Where(e => e.discordID == userId);
                if (user.Any())
                {
                    Models.Users foundUser = user.First();
                    //Ordering our data points by when they were generated
                    var userWeights = db.Weights.Where(e => e.User == foundUser);
                    //Ok setting up our series in OxyPlot
                    OxyPlot.Series.LineSeries weightData = new OxyPlot.Series.LineSeries();
                    //And adding all of our datapoints in order
                    foreach (Models.Weights weight in userWeights)
                    {
                        weightData.Points.Add(new OxyPlot.DataPoint(((DateTime)weight.TimeStamp).ToOADate(), (double)weight.UserWeight));
                    }
                    //Ok and setting up our graph
                    OxyPlot.PlotModel weightGraph = new OxyPlot.PlotModel()
                    {
                        PlotType   = OxyPlot.PlotType.XY,
                        Background = OxyPlot.OxyColor.FromArgb(0x80, 0x2c, 0x2f, 0x33),
                        TextColor  = OxyPlot.OxyColor.FromRgb(0x99, 0xaa, 0xb5),
                    };
                    //And adding our series to our graph
                    weightGraph.Series.Add(weightData);
                    if (foundUser.Goal != null)
                    {
                        OxyPlot.Series.LineSeries goalLine = new OxyPlot.Series.LineSeries();
                        DateTime firstTime = (DateTime)userWeights.First().TimeStamp;
                        DateTime lastTime  = (DateTime)userWeights.Last().TimeStamp;
                        goalLine.Points.Add(new OxyPlot.DataPoint(firstTime.ToOADate(), (double)foundUser.Goal));
                        goalLine.Points.Add(new OxyPlot.DataPoint(lastTime.ToOADate(), (double)foundUser.Goal));
                        weightGraph.Series.Add(goalLine);
                    }
                    //And exporting our PNG
                    using (var stream = new MemoryStream())
                    {
                        var pngExport = new OxyPlot.CommonGraphics.PngExporter()
                        {
                            Width  = 1024,
                            Height = 768
                        };
                        pngExport.Export(weightGraph, stream);
                        stream.Position = 0;
                        await message.Channel.SendFileAsync(stream, $"Graph for {message.Author.Username}#{message.Author.Discriminator} created on {DateTime.Now} SHUT UP MOM I DO WHAT I WANT OF COURSE I'M MAKING IT LONGER.jpg.png");
                    }
                }
            }
        }