Skip to content

Commit

Permalink
synchronize branch nosb code
Browse files Browse the repository at this point in the history
  • Loading branch information
kukume committed Aug 25, 2024
1 parent b5945fc commit d582ba6
Show file tree
Hide file tree
Showing 21 changed files with 287 additions and 127 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM openjdk:21-bullseye
RUN apt update -y && apt install ffmpeg -y
ADD tgbot-1.0-SNAPSHOT.jar /opt/kuku/tgbot-1.0-SNAPSHOT.jar
ADD tgbot.jar /opt/kuku/tgbot.jar
ADD application.yml /opt/kuku/application.yml
ADD docker-entrypoint.sh /opt/kuku/docker-entrypoint.sh
WORKDIR /opt/kuku
Expand Down
19 changes: 9 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
@file:Suppress("VulnerableLibrariesLocal")

plugins {
val kotlinVersion = "2.0.0"
val kotlinVersion = "2.0.20"
kotlin("jvm") version kotlinVersion
kotlin("plugin.spring") version kotlinVersion
id("org.springframework.boot") version "3.3.1"
id("io.spring.dependency-management") version "1.1.5"
application
id("org.springframework.boot") version "3.3.3"
id("io.spring.dependency-management") version "1.1.6"
}

group = "me.kuku"
Expand All @@ -23,11 +22,11 @@ dependencies {
implementation("io.projectreactor.kotlin:reactor-kotlin-extensions")
implementation("org.springframework.boot:spring-boot-starter-data-mongodb-reactive")
implementation("org.springframework.boot:spring-boot-starter-mail")
implementation("com.github.pengrad:java-telegram-bot-api:7.7.0")
implementation("me.kuku:utils:2.3.12.0")
implementation("com.github.pengrad:java-telegram-bot-api:7.9.0")
implementation("me.kuku:utils:2.3.12.1")
implementation("me.kuku:ktor-spring-boot-starter:2.3.12.0")
implementation("org.jsoup:jsoup:1.17.2")
val ociVersion = "3.44.1"
val ociVersion = "3.44.4"
implementation("com.oracle.oci.sdk:oci-java-sdk-core:$ociVersion")
implementation("com.oracle.oci.sdk:oci-java-sdk-identity:$ociVersion")
implementation("com.oracle.oci.sdk:oci-java-sdk-common-httpclient-jersey3:$ociVersion") {
Expand Down Expand Up @@ -62,6 +61,6 @@ tasks.test {
useJUnitPlatform()
}

application {
mainClass = "me.kuku.telegram.TelegramApplicationKt"
}
tasks.bootJar {
archiveFileName.set("tgbot.jar")
}
4 changes: 2 additions & 2 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

jar_name=tgbot-1.0-SNAPSHOT.jar
jar_new_name=tgbot-1.0-SNAPSHOT-new.jar
jar_name=tgbot.jar
jar_new_name=tgbot-new.jar
rm -f update.pid

java -Dspring.profiles.active=prod -Duser.timezone=Asia/Shanghai -jar $jar_name &
Expand Down
4 changes: 2 additions & 2 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
JAVA_HOME=~/jdk/jdk-21+35
java=$JAVA_HOME/bin/java

jar_name=tgbot-1.0-SNAPSHOT.jar
jar_new_name=tgbot-1.0-SNAPSHOT-new.jar
jar_name=tgbot.jar
jar_new_name=tgbot-new.jar
rm -f update.pid

"${java}" -Dspring.profiles.active=prod -jar $jar_name &
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/me/kuku/telegram/entity/MiHoYoEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class MiHoYoEntity: BaseEntity() {
var mysSign: Status = Status.OFF

fun hubCookie(): String {
if (sToken.isEmpty()) error("未设置sToken,请使用账号密码重新登录")
return "stuid=$aid; stoken=$sToken; "
if (token.isEmpty()) error("未设置token,请使用app账号密码重新登录")
return "stuid=$aid; stoken=$token; mid=$mid; "
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/kotlin/me/kuku/telegram/entity/NetEaseEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class NetEaseEntity: BaseEntity() {
var sign: Status = Status.OFF
var musicianSign: Status = Status.OFF
var vipSign: Status = Status.OFF
var listen: Status = Status.OFF

fun cookie() = "channel=netease; __remember_me=true; MUSIC_U=$musicU; __csrf=$csrf; "

Expand All @@ -36,6 +37,8 @@ interface NetEaseRepository: CoroutineCrudRepository<NetEaseEntity, String> {

suspend fun findByVipSign(status: Status): List<NetEaseEntity>

suspend fun findByListen(listen: Status): List<NetEaseEntity>

}

@Service
Expand All @@ -58,4 +61,6 @@ class NetEaseService(

suspend fun findByVipSign(status: Status) = netEaseRepository.findByVipSign(status)

suspend fun findByListen(listen: Status) = netEaseRepository.findByListen(listen)

}
36 changes: 36 additions & 0 deletions src/main/kotlin/me/kuku/telegram/entity/NetEaseSmallEntity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package me.kuku.telegram.entity

import kotlinx.coroutines.flow.toList
import org.springframework.data.annotation.Id
import org.springframework.data.mongodb.core.mapping.Document
import org.springframework.data.repository.kotlin.CoroutineCrudRepository
import org.springframework.stereotype.Service

@Document("net_ease_small")
class NetEaseSmallEntity {
@Id
var id: String? = null
var username: String = ""
var password: String = ""
var musicU: String = ""
var csrf: String = ""

fun cookie() = "channel=netease; __remember_me=true; MUSIC_U=$musicU; __csrf=$csrf; "
}

interface NetEaseSmallRepository: CoroutineCrudRepository<NetEaseSmallEntity, String> {
suspend fun findByUsername(username: String): NetEaseSmallEntity?
}

@Service
class NetEaseSmallService(
private val netEaseSmallRepository: NetEaseSmallRepository
) {
suspend fun save(netEaseSmallEntity: NetEaseSmallEntity): NetEaseSmallEntity = netEaseSmallRepository.save(netEaseSmallEntity)

suspend fun findByUsername(username: String): NetEaseSmallEntity? = netEaseSmallRepository.findByUsername(username)

suspend fun findAll(): List<NetEaseSmallEntity> = netEaseSmallRepository.findAll().toList()

suspend fun delete(entity: NetEaseSmallEntity) = netEaseSmallRepository.delete(entity)
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class ExecExtension(
val markup = InlineKeyboardMarkup(arrayOf(genShinSignButton), arrayOf(mysSign))
editMessageText("""
米哈游
注意:签到大概率需要在/config配置rrcor的key
注意:签到大概率需要在/config配置2captcha的key
""".trimIndent(), markup)
}
callback("genShinSign") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ class LoginExtension(
arrayOf(appQrcodeButton),
arrayOf(cookieButton)
)
editMessageText("请选择什么值得买登录方式\n注意:因为什么值得买部分有极验验证码,所以你可能需要在/config中设配置rrocr密钥", markup)
editMessageText("请选择什么值得买登录方式\n注意:因为什么值得买部分有极验验证码,所以你可能需要在/config中设配置2captcha密钥", markup)
}
callback("smZdmLoginByPhoneCode") {
editMessageText("请发送什么值得买的手机号码")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class ManagerExtension(
)
editMessageText("""
米哈游签到管理
注意:签到大概率需要在/config配置rrcor的key
注意:签到大概率需要在/config配置2captcha的key
""".trimIndent(), inlineKeyboardMarkup, top = true)
}
}
Expand All @@ -238,18 +238,21 @@ class ManagerExtension(
callback("netEaseSignSwitch") { firstArg<NetEaseEntity>().also { it.sign = !it.sign } }
callback("netEaseMusicianSignSwitch") { firstArg<NetEaseEntity>().also { it.musicianSign = !it.musicianSign } }
callback("netEaseVipSignSwitch") { firstArg<NetEaseEntity>().also { it.vipSign = !it.vipSign } }
callback("netEaseListenSwitch") { firstArg<NetEaseEntity>().also { it.listen = !it.listen } }
after {
val netEaseEntity = firstArg<NetEaseEntity>()
netEaseService.save(netEaseEntity)
val signButton = InlineKeyboardButton("${netEaseEntity.sign}自动签到")
.callbackData("netEaseSignSwitch")
val musicianSignButton = InlineKeyboardButton("${netEaseEntity.musicianSign}音乐人自动签到")
.callbackData("netEaseMusicianSignSwitch")
val vipSign = inlineKeyboardButton("vip自动签到", "netEaseVipSignSwitch")
val vipSign = inlineKeyboardButton("${netEaseEntity.vipSign}vip自动签到", "netEaseVipSignSwitch")
val listen = inlineKeyboardButton("${netEaseEntity.listen}刷歌曲播放", "netEaseListenSwitch")
val inlineKeyboardMarkup = InlineKeyboardMarkup(
arrayOf(signButton),
arrayOf(musicianSignButton),
arrayOf(vipSign)
arrayOf(vipSign),
arrayOf(listen)
)
editMessageText("""
网易云签到管理
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package me.kuku.telegram.extension

import me.kuku.telegram.context.AbilitySubscriber
import me.kuku.telegram.context.nextMessage
import me.kuku.telegram.entity.NetEaseSmallEntity
import me.kuku.telegram.entity.NetEaseSmallService
import org.springframework.stereotype.Service

@Service
class NetEaseSmallExtension(
private val netEaseSmallService: NetEaseSmallService
) {

fun AbilitySubscriber.netEaseSmall() {
sub(name = "netEaseSmall") {
sendMessage("""
请发送网易云小号,格式为:用户名----密码,一行一个
""".trimIndent())
val text = nextMessage().text()
val firstArr = text.split("\n")
for (line in firstArr) {
val lineSplit = line.split("----")
val username = lineSplit[0]
var password = lineSplit[1]
password.indexOf('-').takeIf { it > 0 }?.let {
password = password.substring(0, it)
}
val netEaseSmallEntity = netEaseSmallService.findByUsername(username) ?: NetEaseSmallEntity()
netEaseSmallEntity.username = username
netEaseSmallEntity.password = password
netEaseSmallService.save(netEaseSmallEntity)
}
sendMessage("保存网易云小号成功")
}
}

}
6 changes: 3 additions & 3 deletions src/main/kotlin/me/kuku/telegram/extension/UpdateExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ class UpdateExtension {
mutex.withLock {
editMessageText("下载指定jar中")
val suffix = query.data().split("|")[1]
val find = listFile("/tgbot/$suffix").find { it.name == "tgbot-1.0-SNAPSHOT.jar" } ?: error("未找到该目录下的文件")
val url = "https://pan.kuku.me/d/tgbot/$suffix/tgbot-1.0-SNAPSHOT.jar?sign=${find.sign}"
val find = listFile("/tgbot/$suffix").find { it.name == "tgbot.jar" } ?: error("未找到该目录下的文件")
val url = "https://pan.kuku.me/d/tgbot/$suffix/tgbot.jar?sign=${find.sign}"
val str = client.get(url).bodyAsText()
val newUrl = Jsoup.parse(str).getElementsByTag("a").first()?.attr("href") ?: error("未获取到文件链接")
val iis = client.get(newUrl).body<InputStream>()
iis.transferTo(FileOutputStream("tmp${java.io.File.separator}tgbot-1.0-SNAPSHOT-new.jar"))
iis.transferTo(FileOutputStream("tmp${java.io.File.separator}tgbot-new.jar"))
"kuku".toByteArray().inputStream().transferTo(FileOutputStream("update.pid"))
editMessageText("""
下载完成,更新中...
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/me/kuku/telegram/logic/AliDriveLogic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ class AliDriveLogic(
val fileList = fileList(aliDriveEntity, backupDriveId, fileId)
val bodies = fileList.items.map { AliDriveBatch.DeleteFileBody(it.driveId.toString(), it.fileId) }
batchDeleteFile(aliDriveEntity, bodies)
val bytes = this::class.java.classLoader.getResourceAsStream("video" + File.separator + "BV14s4y1Z7ZAoutput.mp4")!!.readAllBytes()
val bytes = client.get("https://minio.kuku.me/kuku/BV14s4y1Z7ZAoutput.mp4").body<ByteArray>()
val uploadComplete = uploadFileToBackupDrive(
aliDriveEntity, backupDriveId,
"BV14s4y1Z7ZAoutput.mp4", bytes, fileId
Expand Down
57 changes: 37 additions & 20 deletions src/main/kotlin/me/kuku/telegram/logic/CaptchaLogic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.JsonNode
import io.ktor.client.call.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import kotlinx.coroutines.delay
import me.kuku.telegram.config.TelegramConfig
import me.kuku.telegram.entity.BotConfigService
import me.kuku.telegram.entity.ConfigService
import me.kuku.utils.Jackson
import me.kuku.utils.client
import me.kuku.utils.convertValue
import me.kuku.utils.setJsonBody
import org.springframework.stereotype.Service

@Service
Expand All @@ -20,44 +20,61 @@ class TwoCaptchaLogic(
private val configService: ConfigService
) {

private suspend inline fun <reified T> captcha(tgId: Long? = null, map: Map<String, String>): T {
private suspend inline fun <reified T> captcha(tgId: Long? = null, task: Map<String, Any>): T {
val newKey = run {
tgId?.let {
val configEntity = configService.findByTgId(tgId)
configEntity?.twoCaptchaKey()
}
} ?: botConfigService.findByToken(telegramConfig.token)?.twoCaptchaKey() ?: error("未设置2captcha的key")
val text = client.get("http://2captcha.com/in.php") {
url {
parameters.append("key", newKey)
map.forEach { (k, v) -> parameters.append(k, v) }
}
}.bodyAsText()
val arr = text.split("|")
if (arr[0] != "OK") error("无法识别验证码")
val code = arr[1]
val paramNode = Jackson.createObjectNode()
paramNode.put("clientKey", newKey)
paramNode.putPOJO("task", task)
val jsonNode = client.post("https://api.2captcha.com/createTask") {
setJsonBody(paramNode)
}.body<JsonNode>()
if (jsonNode["errorId"].asInt() != 0) error("识别验证码失败:" + jsonNode["errorDescription"].asText())
val code = jsonNode["taskId"].asLong()
var i = 0
while (true) {
if (i++ > 35) error("无法识别验证码")
delay(2000)
val jsonNode = client.get("http://2captcha.com/res.php?key=$newKey&action=get&json=1&id=$code").body<JsonNode>()
if (jsonNode["status"].asInt() == 1) return jsonNode["request"].convertValue()
val resultJsonNode = client.post("https://api.2captcha.com/getTaskResult") {
setJsonBody("""
{
"clientKey": "$newKey",
"taskId": $code
}
""".trimIndent())
}.body<JsonNode>()
val resultCode = resultJsonNode["errorId"].asInt()
if (resultCode == 0) {
val status = resultJsonNode["status"].asText()
if (status == "processing") continue
else return Jackson.convertValue(resultJsonNode["solution"])
} else {
error("识别验证码失败:" + resultJsonNode["errorDescription"].asText())
}
}
}

suspend fun geeTest(gt: String, challenge: String, pageUrl: String, tgId: Long? = null): GeeTest {
return captcha<GeeTest>(tgId, mapOf("method" to "geetest", "gt" to gt, "challenge" to challenge, "pageurl" to pageUrl))
return captcha<GeeTest>(tgId,
mapOf("type" to "GeeTestTaskProxyless", "gt" to gt, "challenge" to challenge, "websiteURL" to pageUrl))
}

suspend fun geeTestV4(captchaId: String, pageUrl: String, tgId: Long? = null): GeeTestV4 {
return captcha(tgId, mapOf("method" to "geetest_v4", "id" to captchaId, "pageurl" to pageUrl))
suspend fun geeTestV4(captchaId: String, pageUrl: String, extraParams: Map<String, String> = mapOf(), tgId: Long? = null): GeeTestV4 {
return captcha(tgId,
mapOf("type" to "GeeTestTaskProxyless", "captcha_id" to captchaId, "websiteURL" to pageUrl, "version" to 4,
"initParameters" to mutableMapOf("captcha_id" to captchaId).also { it.putAll(extraParams) }
))
}

}

data class GeeTest(@JsonProperty("geetest_challenge") val challenge: String,
@JsonProperty("geetest_validate") val validate: String,
@JsonProperty("geetest_seccode") val secCode: String)
data class GeeTest(@JsonProperty("challenge") val challenge: String,
@JsonProperty("validate") val validate: String,
@JsonProperty("seccode") val secCode: String)


data class GeeTestV4(@JsonProperty("lot_number") val lotNumber: String,
Expand Down
Loading

0 comments on commit d582ba6

Please sign in to comment.