-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
103 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ plugins { | |
} | ||
|
||
group = "layou233.mcbot" | ||
version = "0.1.0" | ||
version = "0.2.0" | ||
|
||
repositories { | ||
mavenLocal() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package layou233.mcbot.httpClient | ||
|
||
import okhttp3.OkHttpClient | ||
import java.util.concurrent.TimeUnit | ||
|
||
val client = OkHttpClient.Builder() | ||
.connectTimeout(10000, TimeUnit.MILLISECONDS) | ||
.readTimeout(3000, TimeUnit.MILLISECONDS) | ||
.addInterceptor { | ||
return@addInterceptor it.proceed( | ||
it.request().newBuilder() | ||
.addHeader( | ||
"User-Agent", | ||
"" | ||
) | ||
.build() | ||
) | ||
} | ||
.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,29 @@ | ||
package layou233.mcbot.hypixel.apiRequester | ||
|
||
import okhttp3.OkHttpClient | ||
import layou233.mcbot.httpClient.client | ||
import okhttp3.Request | ||
import okhttp3.Response | ||
import java.lang.Exception | ||
import java.util.concurrent.TimeUnit | ||
import java.net.SocketTimeoutException | ||
|
||
val client = OkHttpClient.Builder() | ||
.connectTimeout(10000, TimeUnit.MILLISECONDS) | ||
.readTimeout(3000, TimeUnit.MILLISECONDS) | ||
.addInterceptor { | ||
return@addInterceptor it.proceed( | ||
it.request().newBuilder() | ||
.addHeader( | ||
"User-Agent", | ||
"" | ||
) | ||
.build() | ||
) | ||
} | ||
.build() | ||
|
||
fun sb_money(id: String): Int { | ||
val response: Response = | ||
client.newCall(Request.Builder().url("http://sky.shiiyu.moe/api/v2/coins/$id").build()).execute() | ||
var money: Int = 0 | ||
val back: String = response.body!!.string() | ||
val finding: List<String> = listOf("purse", "bank") | ||
val indexes: List<Int> = listOf(7, 6) | ||
for (ind in finding.indices) { | ||
val found = Regex("""${finding.elementAt(ind)}\":.*?(?=[,.}])""").findAll(back) | ||
for (i in found) money += i.value.substring(indexes.elementAt(ind)).toInt() | ||
try { | ||
val response = | ||
client.newCall(Request.Builder().url("http://sky.shiiyu.moe/api/v2/coins/$id").build()).execute() | ||
var money: Int = 0 | ||
val back: String = response.body!!.string() | ||
if (back == "{\"error\":\"Player has no SkyBlock profiles.\"}") return -1 | ||
else if (back == "{\"error\":\"Failed resolving username.\"}") return -2 | ||
else { | ||
/* val finding: List<String> = listOf("purse", "bank") | ||
val indexes: List<Int> = listOf(7, 6)*/ | ||
for (ind in listOf("purse", "bank").indices) { | ||
val found = Regex("""${listOf("purse", "bank").elementAt(ind)}\":.*?(?=[,.}])""").findAll(back) | ||
for (i in found) money += i.value.substring(listOf(7, 6).elementAt(ind)).toInt() | ||
} | ||
response.close() | ||
return money | ||
} | ||
} catch (e: SocketTimeoutException) { | ||
return -3 | ||
} | ||
response.close() | ||
return money | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,37 @@ | ||
package layou233.mcbot.mojang.apiRequester | ||
|
||
import okhttp3.OkHttpClient | ||
import layou233.mcbot.httpClient.client | ||
import okhttp3.Request | ||
import java.lang.Exception | ||
import java.util.concurrent.TimeUnit | ||
import java.net.SocketTimeoutException | ||
import java.util.Base64.getDecoder | ||
|
||
val client = OkHttpClient.Builder() | ||
.connectTimeout(10000, TimeUnit.MILLISECONDS) | ||
.readTimeout(3000, TimeUnit.MILLISECONDS) | ||
.addInterceptor { | ||
return@addInterceptor it.proceed( | ||
it.request().newBuilder() | ||
.addHeader( | ||
"User-Agent", | ||
"" | ||
) | ||
.build() | ||
) | ||
} | ||
.build() | ||
/* | ||
fun uuid(id: String): String? { | ||
TODO("Have not start yet") | ||
return try | ||
try { | ||
val response = | ||
client.newCall(Request.Builder().url("https://api.mojang.com/users/profiles/minecraft/$id").build()) | ||
.execute() | ||
val found: String = Regex("\\\":.*?(?=[,.}])").find(response.toString()).toString() | ||
val back: String = response.body!!.string() | ||
response.close() | ||
found | ||
} catch (e: Exception) { | ||
return null | ||
return back.substring(17 + id.length, back.length - 2) | ||
} catch (e: SocketTimeoutException) { | ||
return null | ||
} | ||
} | ||
}*/ | ||
|
||
fun resource(uuid: String?): String? { | ||
if (uuid==null) return null | ||
else{ | ||
try { | ||
val response = | ||
client.newCall(Request.Builder().url("https://sessionserver.mojang.com/session/minecraft/profile/$uuid") | ||
.build()) | ||
.execute() | ||
val back: String = response.body!!.string().replace("\\s".toRegex(), "") | ||
response.close() | ||
val res: String = Regex("""value\":\".*=+""").find(back)!!.value.substring(8) | ||
return String(getDecoder().decode(res)).replace("\\s".toRegex(), "") | ||
} catch (e: SocketTimeoutException) { | ||
return null | ||
}} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package layou233.mcbot.mojang.getSkin | ||
|
||
import layou233.mcbot.mojang.apiRequester.resource | ||
import layou233.mcbot.mojang.apiRequester.uuid | ||
|
||
fun skin(id: String): String? { | ||
val res: String? = resource(uuid(id)) | ||
return if (res == null) null | ||
else { | ||
Regex("""http.*[0-z]""").find(res)!!.value | ||
//Example for Regex: {"url":"http://textures.minecraft.net/texture/a1b2c3d4e5"}}} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name: "MCBot" | ||
author: "layou233" | ||
version: "0.1.0" | ||
version: "0.2.0" | ||
main: "layou233.mcbot" | ||
info: "" | ||
info: "https://github.com/layou233/mirai-MCBot/" | ||
depends: [] |