44
55namespace ScriptBloxAPI . Methods
66{
7- public class Scripts
7+ public class ScriptsMethods
88 {
9- private static Script _invalidScript = new Script ( new GameObject ( 0 , "" , "" ) , "N/A" , "N/A" , "N/A" , "N/A" , "2023-05-22T10:36:23.273Z" , "2023-05-22T10:36:23.273Z" , - 1 , - 1 , - 1 , false , false , false , false , new List < string > ( ) ) ;
10-
119 /// <summary>
1210 /// Retrieves a script from Scriptblox based on the provided Scriptblox ID.
1311 /// </summary>
1412 /// <param name="bloxId">The Scriptblox ID of the script to retrieve.</param>
1513 /// <returns>The script retrieved from the API, or a default script if the retrieval fails or the data is invalid.</returns>
16- public static Script GetScriptFromScriptbloxId ( string bloxId )
14+ public static ScriptObject GetScriptFromScriptbloxId ( string bloxId )
1715 {
18- dynamic jsonReturn = MiscFunctions . HttpClient . GetStringAsync ( $ "https://scriptblox.com/api/script/{ bloxId } ") . Result ;
16+ JToken jsonReturn = JToken . Parse ( MiscFunctions . HttpClient . GetStringAsync ( $ "https://scriptblox.com/api/script/{ bloxId } ") . Result ) ;
1917
2018 if ( jsonReturn == null )
2119 throw new ScriptBloxException ( "An error has occured while fetching the json, please submit a bug report." ) ;
2220 if ( jsonReturn [ "message" ] != null )
23- throw new ScriptBloxException ( jsonReturn [ "message" ] ) ;
21+ throw new ScriptBloxException ( jsonReturn . Value < string > ( "message" ) ) ;
2422 if ( jsonReturn [ "script" ] == null )
2523 throw new ScriptBloxException ( "Backend error occured." ) ;
2624
@@ -37,18 +35,18 @@ public static Script GetScriptFromScriptbloxId(string bloxId)
3735 /// </summary>
3836 /// <param name="pageNumber">The page number of the front page scripts (default is 1).</param>
3937 /// <returns>A list of Script objects representing the scripts from the front page.</returns>
40- public static List < Script > GetFrontPageScripts ( int pageNumber = 1 )
38+ public static List < ScriptObject > GetFrontPageScripts ( int pageNumber = 1 )
4139 {
4240 if ( pageNumber < 1 ) pageNumber = 1 ;
4341
44- List < Script > scriptsToReturn = new List < Script > ( ) ;
42+ List < ScriptObject > scriptsToReturn = new List < ScriptObject > ( ) ;
4543
46- dynamic jsonReturn = MiscFunctions . HttpClient . GetStringAsync ( $ "https://scriptblox.com/api/script/fetch?page={ pageNumber } ") . Result ;
44+ JToken jsonReturn = JToken . Parse ( MiscFunctions . HttpClient . GetStringAsync ( $ "https://scriptblox.com/api/script/fetch?page={ pageNumber } ") . Result ) ;
4745
4846 if ( jsonReturn == null )
4947 throw new ScriptBloxException ( "An error has occured while fetching the json, please submit a bug report." ) ;
5048 if ( jsonReturn [ "message" ] != null )
51- throw new ScriptBloxException ( jsonReturn [ "message" ] ) ;
49+ throw new ScriptBloxException ( jsonReturn . Value < string > ( "message" ) ) ;
5250 if ( jsonReturn [ "script" ] == null )
5351 throw new ScriptBloxException ( "Backend error occured." ) ;
5452
@@ -64,26 +62,26 @@ public static List<Script> GetFrontPageScripts(int pageNumber = 1)
6462 /// </summary>
6563 /// <param name="pageNumber">The page number of the front page scripts (default is 1).</param>
6664 /// <returns>A list of Script objects representing the scripts from the front page.</returns>
67- public static List < Script > GetScriptsFromPageNumber ( int pageNumber = 1 ) => GetFrontPageScripts ( pageNumber ) ;
65+ public static List < ScriptObject > GetScriptsFromPageNumber ( int pageNumber = 1 ) => GetFrontPageScripts ( pageNumber ) ;
6866
6967 /// <summary>
7068 /// Retrieves a list of scripts from Scriptblox based on the provided search query and maximum results.
7169 /// </summary>
7270 /// <param name="searchQuery">The search query to filter the scripts.</param>
7371 /// <param name="maxResults">The maximum number of results to retrieve (default is 20).</param>
7472 /// <returns>A list of Script objects representing the scripts matching the search query.</returns>
75- public static List < Script > GetScriptsFromQuery ( string searchQuery , int maxResults = 20 )
73+ public static List < ScriptObject > GetScriptsFromQuery ( string searchQuery , int maxResults = 20 )
7674 {
7775 if ( maxResults < 1 ) maxResults = 1 ;
7876
79- List < Script > scriptsToReturn = new List < Script > ( ) ;
77+ List < ScriptObject > scriptsToReturn = new List < ScriptObject > ( ) ;
8078
81- dynamic jsonReturn = MiscFunctions . HttpClient . GetStringAsync ( $ "https://scriptblox.com/api/script/search?q={ searchQuery } &page=1&max={ maxResults } ") . Result ;
79+ JToken jsonReturn = JToken . Parse ( MiscFunctions . HttpClient . GetStringAsync ( $ "https://scriptblox.com/api/script/search?q={ searchQuery } &page=1&max={ maxResults } ") . Result ) ;
8280
8381 if ( jsonReturn == null )
8482 throw new ScriptBloxException ( "An error has occured while fetching the json, please submit a bug report." ) ;
8583 if ( jsonReturn [ "message" ] != null )
86- throw new ScriptBloxException ( jsonReturn [ "message" ] ) ;
84+ throw new ScriptBloxException ( jsonReturn . Value < string > ( "message" ) ) ;
8785 if ( jsonReturn [ "script" ] == null )
8886 throw new ScriptBloxException ( "Backend error occured." ) ;
8987
@@ -100,20 +98,20 @@ public static List<Script> GetScriptsFromQuery(string searchQuery, int maxResult
10098 /// </summary>
10199 /// <param name="username">The username of the user whose scripts to retrieve.</param>
102100 /// <returns>A list of Script objects representing the scripts owned by the user.</returns>
103- public static List < Script > GetScriptsFromUser ( string username )
101+ public static List < ScriptObject > GetScriptsFromUser ( string username )
104102 {
105- List < Script > scriptsToReturn = new List < Script > ( ) ;
103+ List < ScriptObject > scriptsToReturn = new List < ScriptObject > ( ) ;
106104
107- dynamic jsonReturn = MiscFunctions . HttpClient . GetStringAsync ( $ "https://scriptblox.com/u/{ username } ") . Result ;
105+ JToken jsonReturn = JToken . Parse ( MiscFunctions . HttpClient . GetStringAsync ( $ "https://scriptblox.com/u/{ username } ") . Result ) ;
108106
109107 if ( jsonReturn == null )
110108 throw new ScriptBloxException ( "An error has occured while fetching the json, please submit a bug report." ) ;
111109 if ( jsonReturn [ "message" ] != null )
112- throw new ScriptBloxException ( jsonReturn [ "message" ] ) ;
110+ throw new ScriptBloxException ( jsonReturn . Value < string > ( "message" ) ) ;
113111 if ( jsonReturn [ "script" ] == null )
114112 throw new ScriptBloxException ( "Backend error occured." ) ;
115113
116- List < string > slugsToCheck = GetSlugsFromResults ( jsonReturn ) ;
114+ List < string > slugsToCheck = GetSlugsFromResults ( jsonReturn . ToString ( ) ) ;
117115
118116 foreach ( string slug in slugsToCheck ) scriptsToReturn . Add ( GetScriptFromScriptbloxId ( slug ) ) ;
119117
@@ -139,13 +137,11 @@ private static bool IsScriptDataInvalid(JToken scriptData)
139137 scriptData [ "id" ] == null ;
140138 }
141139
142- private static List < string > GetSlugsFromResults ( string json )
140+ private static List < string > GetSlugsFromResults ( JToken json )
143141 {
144142 List < string > slugs = new List < string > ( ) ;
145143
146- JObject data = JObject . Parse ( json ) ;
147-
148- JArray scripts = ( JArray ) data [ "result" ] [ "scripts" ] ;
144+ JArray scripts = ( JArray ) json [ "result" ] [ "scripts" ] ;
149145
150146 foreach ( JToken script in scripts )
151147 {
@@ -156,22 +152,22 @@ private static List<string> GetSlugsFromResults(string json)
156152 return slugs ;
157153 }
158154
159- private static Script CreateScriptFromData ( JToken scriptData )
155+ private static ScriptObject CreateScriptFromData ( JToken scriptData )
160156 {
161- GameObject game = new GameObject ( scriptData [ "game" ] . Value < int > ( "gameId" ) ,
157+ GameObject game = new GameObject ( scriptData [ "game" ] . Value < long > ( "gameId" ) ,
162158 scriptData [ "game" ] . Value < string > ( "name" ) ,
163159 scriptData [ "game" ] . Value < string > ( "imageUrl" ) ) ;
164160
165- return new Script ( game ,
161+ return new ScriptObject ( game ,
166162 scriptData . Value < string > ( "title" ) ,
167163 scriptData . Value < string > ( "_id" ) ,
168164 scriptData . Value < string > ( "slug" ) ,
169165 scriptData . Value < string > ( "script" ) ,
170166 scriptData . Value < string > ( "createdAt" ) ,
171167 scriptData . Value < string > ( "updatedAt" ) ,
172- scriptData . Value < int > ( "views" ) ,
173- scriptData . Value < int > ( "likeCount" ) ,
174- scriptData . Value < int > ( "dislikeCount" ) ,
168+ scriptData . Value < long > ( "views" ) ,
169+ scriptData . Value < long > ( "likeCount" ) ,
170+ scriptData . Value < long > ( "dislikeCount" ) ,
175171 scriptData . Value < bool > ( "isUniversal" ) ,
176172 scriptData . Value < bool > ( "isPatched" ) ,
177173 scriptData . Value < bool > ( "key" ) ,
0 commit comments