Пример #1
0
        public static EventResponse CreateUser(string ID, IDType IDVariant)
        {
            EventResponse Response   = new EventResponse();
            bool          UserExists = false;

            if (UserData.UserExists(ID, IDVariant))
            {
                UserExists = true;
            }

            if (UserExists)
            {
                Response.Message = "User already exists"; return(Response);
            }

            if (IDVariant == IDType.Discord)
            {
                foreach (Newtonsoft.Json.Linq.JObject Connection in GetConnections(ID)["connected_accounts"])
                {
                    if (Connection["type"].ToString() == "twitch")
                    {
                        if (UserData.UserExists(Connection["id"].ToString(), IDType.Twitch))
                        {
                            Newtonsoft.Json.Linq.JToken R = UserData.GetUser(Connection["id"].ToString(), IDType.Twitch);
                            if (R["Status"].ToString() != "200")
                            {
                                Response.Message = Shared.ConfigHandler.Config["CommandResponses"]["Errors"]["WhoKnows"].ToString(); return(Response);
                            }
                            Newtonsoft.Json.Linq.JToken User = R["Data"];
                            if (User["DiscordId"].ToString() == "")
                            {
                                User["DiscordId"] = ID.ToString();
                                WebRequests.POST("/update/user", null, User.ToString());
                                return(Response);
                            }
                        }
                        else
                        {
                            Dictionary <string, string> Headers1 = new Dictionary <string, string> {
                            };
                            Headers1.Add("DiscordId", ID.ToString()); Headers1.Add("TwitchId", Connection["id"].ToString());
                            WebRequests.POST("/create/user", Headers1);
                            Response.Success = true;
                            Response.Message = "Created User Account and added Twitch";
                            return(Response);
                        }
                    }
                }
            }
            Dictionary <string, string> Headers2 = new Dictionary <string, string> {
            };

            Headers2.Add(IDVariant.ToString() + "Id", ID.ToString());
            WebRequests.POST("/create/user", Headers2);
            Response.Success = true;
            Response.Message = "Created User Account";

            return(Response);
        }
Пример #2
0
        public static Newtonsoft.Json.Linq.JToken GetUser(string ID, IDType IDVariant)
        {
            Dictionary <string, string> Headers = new Dictionary <string, string> {
            };

            Headers.Add(IDVariant.ToString() + "Id", ID);
            Newtonsoft.Json.Linq.JToken Response = WebRequests.POST("/user", Headers, "", false, false);
            return(Response);
        }
Пример #3
0
        public static EventResponse MergeAccounts(string DiscordID)
        {
            EventResponse Response = new EventResponse();

            Newtonsoft.Json.Linq.JToken R = UserData.GetUser(DiscordID, Shared.IDType.Twitch);
            if (R["Status"].ToString() != "200")
            {
                Response.Message = Shared.ConfigHandler.Config["CommandResponses"]["Errors"]["WhoKnows"].ToString(); return(Response);
            }
            Newtonsoft.Json.Linq.JToken User = R["Data"];
            if (User["TwitchId"].ToString() == "")
            {
                foreach (Newtonsoft.Json.Linq.JObject Connection in GetConnections(DiscordID)["connected_accounts"])
                {
                    if (Connection["type"].ToString() == "twitch")
                    {
                        if (UserData.UserExists(Connection["id"].ToString(), IDType.Twitch))
                        {
                            R = UserData.GetUser(Connection["id"].ToString(), IDType.Twitch);
                            if (R["Status"].ToString() != "200")
                            {
                                Response.Message = Shared.ConfigHandler.Config["CommandResponses"]["Errors"]["WhoKnows"].ToString(); return(Response);
                            }
                            User = R["Data"];
                            if (User["DiscordId"].ToString() == "")
                            {
                                Accounts.GiveUser(Connection["id"].ToString(), IDType.Twitch, Accounts.GetBalance(DiscordID, IDType.Discord));
                                R = UserData.GetUser(DiscordID, Shared.IDType.Discord);
                                if (R["Status"].ToString() != "200")
                                {
                                    Response.Message = Shared.ConfigHandler.Config["CommandResponses"]["Errors"]["WhoKnows"].ToString(); return(Response);
                                }
                                User = R["Data"];
                                WebRequests.POST("/delete/user/" + User["UserId"].ToString());
                                R = UserData.GetUser(Connection["id"].ToString(), IDType.Twitch);
                                if (R["Status"].ToString() != "200")
                                {
                                    Response.Message = Shared.ConfigHandler.Config["CommandResponses"]["Errors"]["WhoKnows"].ToString(); return(Response);
                                }
                                User = R["Data"];
                                User["DiscordId"] = DiscordID.ToString();
                                WebRequests.POST("/update/user", null, User.ToString());
                            }
                        }
                        break;
                    }
                }
            }
            return(Response);
        }
Пример #4
0
        public static EventResponse PayUser(string MyID, IDType MyIDType, string TheirID, IDType TheirIDType, int Amount)
        {
            Amount = Math.Abs(Amount);
            EventResponse Response = new EventResponse();

            UserData.CreateUser(TheirID, TheirIDType);

            if (UserData.UserExists(MyID, MyIDType) && UserData.UserExists(TheirID, TheirIDType))
            {
                Newtonsoft.Json.Linq.JToken MyUser    = UserData.GetUser(MyID, MyIDType),
                                            TheirUser = UserData.GetUser(TheirID, TheirIDType);
                if (MyUser["Status"].ToString() != "200" || TheirUser["Status"].ToString() != "200")
                {
                    Response.Message = Shared.ConfigHandler.Config["CommandResponses"]["Errors"]["WhoKnows"].ToString(); return(Response);
                }
                MyUser = MyUser["Data"]; TheirUser = TheirUser["Data"];
                if (MyUser["UserId"].ToString() == TheirUser["UserId"].ToString())
                {
                    Response.Message = Shared.ConfigHandler.Config["CommandResponses"]["Errors"]["Self"].ToString(); return(Response);
                }
                int MyBal    = int.Parse(MyUser["Account"]["Balance"].ToString()),
                    TheirBal = int.Parse(TheirUser["Account"]["Balance"].ToString());
                if (MyBal >= Amount)
                {
                    Dictionary <string, string> Headers = new Dictionary <string, string> {
                    };
                    Headers.Add("Value", Amount.ToString());
                    WebRequests.POST("/account/take/" + MyUser["UserId"], Headers);
                    WebRequests.POST("/account/give/" + TheirUser["UserId"], Headers);
                    Response.Message = " Payment of " + Amount + " Owlcoin Complete, New Balance: " + MyBal + " Owlcoin!";
                    Response.Success = true;
                }
                else
                {
                    Response.Message = Shared.ConfigHandler.Config["CommandResponses"]["Errors"]["NotEnough"].ToString();
                }
            }
            else
            {
                Response.Message = Shared.ConfigHandler.Config["CommandResponses"]["Errors"]["NoUser"].ToString();
            }

            return(Response);
        }
Пример #5
0
        public static bool SetUser(string ID, IDType IDVariant, int Amount)
        {
            UserData.CreateUser(ID, IDVariant);
            Amount = Math.Abs(Amount);
            bool Response = false;

            Newtonsoft.Json.Linq.JToken R = UserData.GetUser(ID, IDVariant);
            if (R["Status"].ToString() != "200")
            {
                return(false);
            }
            Newtonsoft.Json.Linq.JToken User    = R["Data"];
            Dictionary <string, string> Headers = new Dictionary <string, string> {
            };

            Headers.Add("Value", Amount.ToString());
            Newtonsoft.Json.Linq.JToken Resp = WebRequests.POST("/account/set/" + User["UserId"].ToString(), Headers);
            Response = Resp["Status"].ToString() == "200";
            return(Response);
        }
Пример #6
0
        public static EventResponse AddID(string CurrentID, IDType CurrentIDVariant, string NewID, IDType NewIDVariant)
        {
            EventResponse Response = new EventResponse();

            bool UserExists = false;

            if (UserData.UserExists(CurrentID, CurrentIDVariant))
            {
                UserExists = true;
            }

            if (!UserExists)
            {
                Response.Message = "User doesnt exist"; return(Response);
            }

            Newtonsoft.Json.Linq.JToken R = UserData.GetUser(CurrentID, CurrentIDVariant);
            if (R["Status"].ToString() != "200")
            {
                Response.Message = Shared.ConfigHandler.Config["CommandResponses"]["Errors"]["WhoKnows"].ToString(); return(Response);
            }
            Newtonsoft.Json.Linq.JToken User = R["Data"];
            User[NewIDVariant.ToString() + "Id"] = NewID;
            Newtonsoft.Json.Linq.JToken D = WebRequests.POST("/update/user", null, User.ToString());

            if (D["Status"].ToString() == "200")
            {
                Response.Success = true;
                Response.Message = "Set " + NewIDVariant.ToString() + "ID";
            }
            else
            {
                Response.Message = "Error occured while setting " + NewIDVariant.ToString() + "ID";
            }

            return(Response);
        }