diff --git a/src/main/kotlin/com/bot/events/MessageListener.kt b/src/main/kotlin/com/bot/events/MessageListener.kt index 62b33e8..618e7cf 100644 --- a/src/main/kotlin/com/bot/events/MessageListener.kt +++ b/src/main/kotlin/com/bot/events/MessageListener.kt @@ -42,7 +42,7 @@ class MessageListener : ListenerAdapter() { } event.message.delete().queue() } - if (message.attachments.count { it.fileName == "client.log" } == 1) { + if (message.attachments.count { it.fileExtension == "log" } == 1) { val downloadLoc = File("${message.id}.txt") downloadLoc.mkdirs() message.attachments[0].proxy.downloadToFile(downloadLoc).thenAccept { diff --git a/src/main/kotlin/com/bot/utils/Stats.kt b/src/main/kotlin/com/bot/utils/Stats.kt index 8ba3b0d..0aa509c 100644 --- a/src/main/kotlin/com/bot/utils/Stats.kt +++ b/src/main/kotlin/com/bot/utils/Stats.kt @@ -1,28 +1,43 @@ package com.bot.utils +import org.apache.commons.lang.StringUtils import org.jsoup.Jsoup import java.text.NumberFormat object Stats { - fun getRank(): String { + fun getInstalls(): String { + val runeliteVersion = getRuneliteVerison() + if (runeliteVersion == "ERROR") { + return "0" + } return try { - return NumberFormat.getIntegerInstance().format(Jsoup.connect("https://api.phstatistics.com/rank/plugin/117hd") + val doc = Jsoup.connect("https://api.runelite.net/runelite-${runeliteVersion}/pluginhub") .userAgent("Mozilla").timeout(3000).ignoreContentType(true) - .get().body().text().toInt()) + .get().body().text() + + NumberFormat.getIntegerInstance().format(StringUtils.substringBetween(doc, "\"117hd\":", ",").toInt()) } catch (e: Exception) { e.printStackTrace() - "2" + "" } } - fun getInstalls(): String { + fun getRank(): String { + return "2" + } + + private fun getRuneliteVerison(): String { return try { - return NumberFormat.getIntegerInstance().format(Jsoup.connect("https://api.phstatistics.com/installs/plugin/117hd") + val doc = Jsoup.connect("https://static.runelite.net/bootstrap.json") .userAgent("Mozilla").timeout(3000).ignoreContentType(true) - .get().body().text().toInt()) + .get() + + + StringUtils.substringsBetween(doc.body().text(), "\"version\": \"", "\" }").last() } catch (e: Exception) { e.printStackTrace() - "2" + "ERROR" } } + }