Skip to content

Commit f3282dc

Browse files
committed
6.2.0
- ReWrote parameter handler to lower memory usage Added Endpoints - UserStats.GetUserFollowingAsync(string username, int? page = 1, int? max = 20) - UserStats.GetUserFollowersAsync(string username, int? page = 1, int? max = 20) - UserStats.GetUserInfoAsync(string username, int? page = 1, int? max = 20) - Comments.GetScriptCommentsAsync(string scriptId, int? page = 1, int? max = 20) - Executors.GetRobloxVersions() - Scripts.FetchScriptsFromUser(string username, int? page = 1, int? max = 20)
1 parent 2ca55c6 commit f3282dc

File tree

11 files changed

+230
-32
lines changed

11 files changed

+230
-32
lines changed

Client.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ internal class Client
2222

2323
internal static HttpClient HttpClient => LazyClient.Value;
2424

25-
internal static async Task<T> Get<T>(string endpoint, Dictionary<string, string> queryParams)
25+
internal static async Task<T> Get<T>(string endpoint, (string Key, string Value)[]? queryParams)
2626
{
27-
string queryString = string.Join("&", queryParams.Select(kvp => $"{kvp.Key}={kvp.Value}"));
27+
string queryString = string.Join("&", queryParams?.Select(kvp => $"{kvp.Key}={kvp.Value}") ?? []);
2828

2929
if (!string.IsNullOrEmpty(queryString))
3030
queryString = "?" + queryString;

Executors/Executors.cs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
6+
namespace ScriptBloxApi.Executors
7+
{
8+
public static class Executors
9+
{
10+
public static async Task<IReadOnlyList<Version>> GetRobloxVersions()
11+
{
12+
IReadOnlyList<Version> result = await Client.Get<IReadOnlyList<Version>>("roblox/versions", []);
13+
return result;
14+
}
15+
16+
public static async Task<string> GetExecutorList()
17+
{
18+
//await Client.Get<IReadOnlyList<Version>>("executor/list", []); They haven't finished it on their end
19+
return "";
20+
}
21+
}
22+
}

LanguageFeatures/StringModification.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ namespace ScriptBloxApi.LanguageFeatures
33
{
44
internal static class StringModification
55
{
6-
internal static string GetBoolInt(this bool value) => value ? "1" : "0";
6+
internal static string GetBoolInt(this bool? value) => value.HasValue ? (value.Value ? "1" : "0") : "";
77
}
88
}

Objects/Comment.cs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Collections.Generic;
2+
using System.Text.Json.Serialization;
3+
using System;
4+
5+
namespace ScriptBloxApi.Objects;
6+
public record Comment(
7+
[property: JsonPropertyName("_id")] string Id,
8+
[property: JsonPropertyName("commentBy")] CommentBy CommentBy,
9+
[property: JsonPropertyName("text")] string Text,
10+
[property: JsonPropertyName("createdAt")] DateTime? CreatedAt,
11+
[property: JsonPropertyName("__v")] int? V,
12+
[property: JsonPropertyName("edited")] bool? Edited,
13+
[property: JsonPropertyName("likeCount")] int? LikeCount,
14+
[property: JsonPropertyName("dislikeCount")] int? DislikeCount,
15+
[property: JsonPropertyName("liked")] bool? Liked,
16+
[property: JsonPropertyName("disliked")] bool? Disliked
17+
);
18+
19+
public record CommentBy(
20+
[property: JsonPropertyName("_id")] string _Id,
21+
[property: JsonPropertyName("username")] string Username,
22+
[property: JsonPropertyName("verified")] bool? Verified,
23+
[property: JsonPropertyName("role")] string Role,
24+
[property: JsonPropertyName("profilePicture")] string ProfilePicture,
25+
[property: JsonPropertyName("status")] string Status,
26+
[property: JsonPropertyName("id")] string Id
27+
);
28+
29+
public record CommentResult(
30+
[property: JsonPropertyName("totalPages")] int? TotalPages,
31+
[property: JsonPropertyName("comments")] IReadOnlyList<Comment> Comments
32+
);
33+
34+
public record CommentRoot(
35+
[property: JsonPropertyName("result")] CommentResult Result
36+
);
37+

Objects/UserFollowing.cs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Text.Json.Serialization;
5+
6+
namespace ScriptBloxApi.Objects;
7+
8+
public record FollowRoot(
9+
[property: JsonPropertyName("users")] IReadOnlyList<FollowUser> Users,
10+
[property: JsonPropertyName("totalPages")] int? TotalPages
11+
);
12+
13+
public record FollowUser(
14+
[property: JsonPropertyName("_id")] string Id,
15+
[property: JsonPropertyName("username")] string Username,
16+
[property: JsonPropertyName("profilePicture")] string ProfilePicture
17+
);

Objects/UserInfo.cs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Text.Json.Serialization;
3+
4+
namespace ScriptBloxApi.Objects;
5+
6+
public record Discord(
7+
[property: JsonPropertyName("id")] string Id,
8+
[property: JsonPropertyName("username")] string Username,
9+
[property: JsonPropertyName("discriminator")] string Discriminator
10+
);
11+
12+
public record UserInfo(
13+
[property: JsonPropertyName("user")] User User
14+
);
15+
16+
public record User(
17+
[property: JsonPropertyName("_id")] string _Id,
18+
[property: JsonPropertyName("username")] string Username,
19+
[property: JsonPropertyName("verified")] bool? Verified,
20+
[property: JsonPropertyName("role")] string Role,
21+
[property: JsonPropertyName("profilePicture")] string ProfilePicture,
22+
[property: JsonPropertyName("bio")] string Bio,
23+
[property: JsonPropertyName("createdAt")] DateTime? CreatedAt,
24+
[property: JsonPropertyName("lastActive")] DateTime? LastActive,
25+
[property: JsonPropertyName("discord")] Discord Discord,
26+
[property: JsonPropertyName("status")] string Status,
27+
[property: JsonPropertyName("id")] string Id,
28+
[property: JsonPropertyName("followingCount")] int? FollowingCount,
29+
[property: JsonPropertyName("followersCount")] int? FollowersCount
30+
);

Objects/Versions.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Text.Json.Serialization;
3+
4+
namespace ScriptBloxApi.Objects;
5+
public record Versions(
6+
[property: JsonPropertyName("_id")] string Id,
7+
[property: JsonPropertyName("version")] string Version,
8+
[property: JsonPropertyName("platform")] string Platform,
9+
[property: JsonPropertyName("versionDate")] DateTime? VersionDate,
10+
[property: JsonPropertyName("updatedAt")] DateTime? UpdatedAt,
11+
[property: JsonPropertyName("__v")] int? V
12+
);

ScriptBloxAPI.csproj

+14-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,22 @@
1313
<RepositoryUrl>https://github.com/RiisDev/ScriptBloxAPI</RepositoryUrl>
1414
<RepositoryType>git</RepositoryType>
1515
<PackageTags>scriptblox, scripts, roblox, scripting, lua</PackageTags>
16-
<PackageReleaseNotes>Updated, ported to net standard to allow every application</PackageReleaseNotes>
16+
<PackageReleaseNotes>- ReWrote parameter handler to lower memory usage
17+
18+
Added Endpoints
19+
20+
- UserStats.GetUserFollowingAsync(string username, int? page = 1, int? max = 20)
21+
- UserStats.GetUserFollowersAsync(string username, int? page = 1, int? max = 20)
22+
- UserStats.GetUserInfoAsync(string username, int? page = 1, int? max = 20)
23+
24+
- Comments.GetScriptCommentsAsync(string scriptId, int? page = 1, int? max = 20)
25+
26+
- Executors.GetRobloxVersions()
27+
28+
- Scripts.FetchScriptsFromUser(string username, int? page = 1, int? max = 20)</PackageReleaseNotes>
1729
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1830
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
19-
<Version>6.0.0</Version>
31+
<Version>6.2.0</Version>
2032
<PackageId> ScriptBloxAPI</PackageId>
2133
</PropertyGroup>
2234

Scripts/Comments.cs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Collections.Generic;
2+
using System.Text;
3+
using System.Threading.Tasks;
4+
using System.Xml.Linq;
5+
using ScriptBloxApi.LanguageFeatures;
6+
using ScriptBloxApi.Objects;
7+
using static System.Int32;
8+
9+
namespace ScriptBloxApi.Scripts
10+
{
11+
public static class Comments
12+
{
13+
public static async Task<IReadOnlyList<Comment>> GetScriptCommentsAsync(string scriptId, int? page = 1, int? max = 20)
14+
{
15+
CommentRoot result = await Client.Get<CommentRoot>($"comment/{scriptId}", [
16+
("page", page.InternalClamp(1, MaxValue).ToString()),
17+
("max", max.InternalClamp(1, 20).ToString())
18+
]);
19+
20+
return result.Result.Comments;
21+
}
22+
}
23+
}

Scripts/Scripts.cs

+36-27
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Threading.Tasks;
44
using ScriptBloxApi.LanguageFeatures;
55
using ScriptBloxApi.Objects;
6+
using static System.Int32;
67

78
namespace ScriptBloxApi.Scripts
89
{
@@ -42,17 +43,18 @@ public static async Task<Results> FetchScriptsAsync(
4243
Order? order = null
4344
)
4445
{
45-
Dictionary<string, string> queryParams = new ();
46-
47-
if (page.HasValue) queryParams.Add("page", page.Value.ToString());
48-
if (max.HasValue) queryParams.Add("max", max.InternalClamp(1, 20).ToString());
49-
if (mode.HasValue) queryParams.Add("mode", mode.ToString());
50-
if (patched.HasValue) queryParams.Add("patched", patched.Value.GetBoolInt());
51-
if (key.HasValue) queryParams.Add("key", key.Value.GetBoolInt());
52-
if (universal.HasValue) queryParams.Add("universal", universal.Value.GetBoolInt());
53-
if (verified.HasValue) queryParams.Add("verified", verified.Value.GetBoolInt());
54-
if (sortBy.HasValue) queryParams.Add("sortBy", sortBy.ToString());
55-
if (order.HasValue) queryParams.Add("order", order.ToString());
46+
(string Key, string Value)[] queryParams =
47+
[
48+
("page", page?.ToString()),
49+
("max", max.InternalClamp(1, 20).ToString()),
50+
("mode", mode?.ToString()),
51+
("patched", patched.GetBoolInt()),
52+
("key", key.GetBoolInt()),
53+
("universal", universal.GetBoolInt()),
54+
("verified", verified.GetBoolInt()),
55+
("sortBy", sortBy?.ToString()),
56+
("order", order?.ToString())
57+
];
5658

5759
FetchResult fetchResult = await Client.Get<FetchResult>("script/fetch", queryParams);
5860

@@ -65,10 +67,16 @@ public static async Task<Results> FetchScriptsAsync(
6567

6668
public static async Task<IReadOnlyList<Script>> FetchTrendingScriptsAsync(int? max = 20)
6769
{
68-
FetchResult fetchResult = await Client.Get<FetchResult>("script/trending", new Dictionary<string, string>
69-
{
70-
{"max", max.InternalClamp(1, 20).ToString()}
71-
});
70+
FetchResult fetchResult = await Client.Get<FetchResult>("script/trending", [("max", max.InternalClamp(1, 20).ToString())]);
71+
return fetchResult.Result.Scripts;
72+
}
73+
74+
public static async Task<IReadOnlyList<Script>> FetchScriptsFromUser(string username, int? page = 1, int? max = 20)
75+
{
76+
FetchResult fetchResult = await Client.Get<FetchResult>($"user/scripts/{username}", [
77+
("page", page.InternalClamp(1, MaxValue).ToString()),
78+
("max", max.InternalClamp(1, 20).ToString())
79+
]);
7280
return fetchResult.Result.Scripts;
7381
}
7482

@@ -86,19 +94,20 @@ public static async Task<Results> SearchScriptsAsync(
8694
bool? strict = null
8795
)
8896
{
89-
Dictionary<string, string> queryParams = new (){ { "q", query } };
97+
(string Key, string Value)[] queryParams =
98+
[
99+
("page", page.InternalClamp(1, MaxValue).ToString()),
100+
("max", max.InternalClamp(1, 20).ToString()),
101+
("mode", mode.ToString()),
102+
("patched", patched.GetBoolInt()),
103+
("key", key.GetBoolInt()),
104+
("universal", universal.GetBoolInt()),
105+
("verified", verified.GetBoolInt()),
106+
("sortBy", sortBy.ToString()),
107+
("order", order.ToString()),
108+
("strict", strict.ToString().ToLower())
109+
];
90110

91-
if (page.HasValue) queryParams.Add("page", page.Value.ToString());
92-
if (max.HasValue) queryParams.Add("max", max.InternalClamp(1, 20).ToString());
93-
if (mode.HasValue) queryParams.Add("mode", mode.ToString());
94-
if (patched.HasValue) queryParams.Add("patched", patched.Value.GetBoolInt());
95-
if (key.HasValue) queryParams.Add("key", key.Value.GetBoolInt());
96-
if (universal.HasValue) queryParams.Add("universal", universal.Value.GetBoolInt());
97-
if (verified.HasValue) queryParams.Add("verified", verified.Value.GetBoolInt());
98-
if (sortBy.HasValue) queryParams.Add("sortBy", sortBy.ToString());
99-
if (order.HasValue) queryParams.Add("order", order.ToString());
100-
if (strict.HasValue) queryParams.Add("strict", strict.ToString().ToLower());
101-
102111
FetchResult fetchResult = await Client.Get<FetchResult>("script/search", queryParams);
103112

104113
return fetchResult.Result;

User/UserStats.cs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Threading.Tasks;
2+
using ScriptBloxApi.Objects;
3+
4+
namespace ScriptBloxApi.User
5+
{
6+
public static class UserStats
7+
{
8+
public static async Task<FollowRoot> GetUserFollowingAsync(string username, int? page = 1, int? max = 20)
9+
{
10+
(string Key, string Value)[] queryParams =
11+
[
12+
("page", page?.ToString()),
13+
("max", max?.ToString())
14+
];
15+
FollowRoot result = await Client.Get<FollowRoot>($"user/{username}/following", queryParams);
16+
return result;
17+
}
18+
19+
public static async Task<FollowRoot> GetUserFollowersAsync(string username, int? page = 1, int? max = 20)
20+
{
21+
(string Key, string Value)[] queryParams =
22+
[
23+
("page", page?.ToString()),
24+
("max", max?.ToString())
25+
];
26+
FollowRoot result = await Client.Get<FollowRoot>($"user/{username}/followers", queryParams);
27+
return result;
28+
}
29+
30+
public static async Task<UserInfo> GetUserInfoAsync(string username, int? page = 1, int? max = 20)
31+
{
32+
UserInfo result = await Client.Get<UserInfo>($"user/info/{username}", []);
33+
return result;
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)