Skip to content

Commit

Permalink
Unstable Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kukume committed Dec 3, 2024
1 parent 5af90f7 commit 7710f49
Show file tree
Hide file tree
Showing 53 changed files with 1,308 additions and 1,091 deletions.
31 changes: 24 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
@file:Suppress("VulnerableLibrariesLocal")

plugins {
val kotlinVersion = "2.0.20"
val kotlinVersion = "2.1.0"
val ktorVersion = "3.0.1"
kotlin("jvm") version kotlinVersion
kotlin("plugin.spring") version kotlinVersion
id("org.springframework.boot") version "3.3.3"
id("org.springframework.boot") version "3.4.0"
id("io.spring.dependency-management") version "1.1.6"
id("io.ktor.plugin") version ktorVersion
}

group = "me.kuku"
Expand All @@ -17,13 +19,25 @@ repositories {
mavenCentral()
}

fun DependencyHandlerScope.ktor() {
implementation("io.ktor:ktor-server-core")
implementation("io.ktor:ktor-server-status-pages")
implementation("io.ktor:ktor-server-call-logging")
implementation("io.ktor:ktor-server-content-negotiation")
implementation("io.ktor:ktor-server-netty")

implementation("io.ktor:ktor-serialization-jackson")

implementation("io.ktor:ktor-client-core")
implementation("io.ktor:ktor-client-okhttp")
implementation("io.ktor:ktor-client-content-negotiation")
implementation("io.ktor:ktor-client-logging")
}

dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
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.9.1")
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.48.0"
implementation("com.oracle.oci.sdk:oci-java-sdk-core:$ociVersion")
Expand All @@ -33,9 +47,8 @@ dependencies {
}
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
implementation("com.google.zxing:javase:3.5.3")
implementation("net.consensys.cava:cava-bytes:0.5.0")
implementation("net.consensys.cava:cava-crypto:0.5.0")
implementation("com.aallam.openai:openai-client:3.8.2")
ktor()
testImplementation("org.springframework.boot:spring-boot-starter-test")
}

Expand Down Expand Up @@ -64,3 +77,7 @@ tasks.test {
tasks.bootJar {
archiveFileName.set("tgbot.jar")
}

application {
mainClass.set("me.kuku.tgbot.TelegramApplicationKt")
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
38 changes: 12 additions & 26 deletions src/main/kotlin/me/kuku/telegram/config/KtorConfig.kt
Original file line number Diff line number Diff line change
@@ -1,41 +1,27 @@
package me.kuku.telegram.config

import com.fasterxml.jackson.databind.ObjectMapper
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.plugins.*
import io.ktor.server.plugins.statuspages.*
import io.ktor.server.response.*
import me.kuku.pojo.CommonResult
import me.kuku.utils.Jackson
import org.springframework.context.annotation.Bean
import org.springframework.stereotype.Component

@Component
class KtorConfig {

fun Application.statusPages() {
fun Application.statusPages() {

install(StatusPages) {
install(StatusPages) {

exception<MissingRequestParameterException> { call, cause ->
call.respond(
HttpStatusCode.BadRequest,
CommonResult.failure(code = 400, message = cause.message ?: "参数丢失", data = null)
)
}

exception<Throwable> { call, cause ->
call.respond(HttpStatusCode.InternalServerError, CommonResult.failure<Unit>(cause.toString()))
throw cause
}
exception<MissingRequestParameterException> { call, cause ->
call.respond(
HttpStatusCode.BadRequest,
mapOf("code" to 400, "message" to cause.message)
)
}

exception<Throwable> { call, cause ->
call.respond(HttpStatusCode.InternalServerError, mapOf("code" to 500, "message" to cause.message))
throw cause
}
}

@Bean
fun objectMapper(): ObjectMapper {
return Jackson.objectMapper
}

}
}
11 changes: 7 additions & 4 deletions src/main/kotlin/me/kuku/telegram/config/TelegramConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package me.kuku.telegram.config

import com.pengrad.telegrambot.TelegramBot
import com.pengrad.telegrambot.UpdatesListener
import io.ktor.client.request.*
import io.ktor.http.*
import jakarta.annotation.PostConstruct
import kotlinx.coroutines.runBlocking
import me.kuku.telegram.context.*
import me.kuku.telegram.utils.SpringUtils
import me.kuku.utils.OkHttpUtils
import me.kuku.telegram.utils.client
import okhttp3.OkHttpClient
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.ApplicationListener
Expand Down Expand Up @@ -198,9 +200,10 @@ val api: String
tempApi = configApi.ifEmpty { "https://api.jpa.cc" }
}
try {
val response = OkHttpUtils.get(tempApi!!)
response.close()
if (response.code == 200) return tempApi!!
val response = runBlocking {
client.get(tempApi!!)
}
if (response.status == HttpStatusCode.OK) return tempApi!!
else error(apiErrorMsg)
} catch (e: Exception) {
error(apiErrorMsg)
Expand Down
9 changes: 6 additions & 3 deletions src/main/kotlin/me/kuku/telegram/context/Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import com.pengrad.telegrambot.model.Update
import com.pengrad.telegrambot.model.request.*
import com.pengrad.telegrambot.request.*
import com.pengrad.telegrambot.response.SendResponse
import kotlinx.coroutines.runBlocking
import me.kuku.telegram.utils.CacheManager
import me.kuku.utils.JobManager
import org.springframework.stereotype.Component
import java.io.Serializable
import java.time.Duration
Expand Down Expand Up @@ -50,8 +50,11 @@ abstract class MessageContext: Context() {

suspend fun Message.delete(timeout: Long = 0) {
if (timeout > 0) {
JobManager.delay(timeout) {
bot.asyncExecute(DeleteMessage(chatId, this@delete.messageId()))
Thread.startVirtualThread {
runBlocking {
delete(timeout)
bot.asyncExecute(DeleteMessage(chatId, this@delete.messageId()))
}
}
} else {
bot.asyncExecute(DeleteMessage(chatId, this.messageId()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import io.ktor.client.call.*
import io.ktor.client.request.*
import me.kuku.telegram.config.TelegramConfig
import me.kuku.telegram.utils.SpringUtils
import me.kuku.utils.client
import me.kuku.telegram.utils.client

fun inlineKeyboardButton(text: String, callbackData: String): InlineKeyboardButton = InlineKeyboardButton(text).callbackData(callbackData)

Expand Down
5 changes: 2 additions & 3 deletions src/main/kotlin/me/kuku/telegram/entity/BaiduEntity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.kuku.telegram.entity

import kotlinx.coroutines.flow.toList
import me.kuku.utils.OkUtils
import org.springframework.data.annotation.Id
import org.springframework.data.mongodb.core.mapping.Document
import org.springframework.data.repository.kotlin.CoroutineCrudRepository
Expand All @@ -16,8 +15,8 @@ class BaiduEntity: BaseEntity() {
var tieBaSToken: String = ""
var sign: Status = Status.OFF

fun otherCookie(sToken: String): String {
return OkUtils.cookieStr(cookie, "BDUSS") + "STOKEN=$sToken; "
private fun otherCookie(sToken: String): String {
return "BDUSS=.*?;".toRegex().find(sToken)!!.value + "STOKEN=$sToken; "
}

fun teiBaCookie(): String {
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/me/kuku/telegram/entity/DouYuEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class DouYuEntity: BaseEntity() {
@Id
var id: String? = null
var cookie: String = ""
var appCookie: String = ""
var live: Status = Status.OFF
var fishGroup: Status = Status.OFF
var push: Status = Status.OFF
Expand Down
32 changes: 0 additions & 32 deletions src/main/kotlin/me/kuku/telegram/extension/CommentExtension.kt

This file was deleted.

19 changes: 8 additions & 11 deletions src/main/kotlin/me/kuku/telegram/extension/ExecExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,9 @@ class ExecExtension(
}
callback("hostLocSign") {
val hostLocEntity = firstArg<HostLocEntity>()
for (i in 0 until 12) {
editMessageText("正在进行第${i}次访问HostLoc用户主页")
HostLocLogic.singleSign(hostLocEntity.cookie)
}
editMessageText("HostLoc签到成功")
editMessageText("后台进行访问HostLoc用户主页,结果稍后发送")
HostLocLogic.sign(hostLocEntity.cookie)
sendMessage("#手动执行结果\nHostLoc签到成功")
}
}

Expand Down Expand Up @@ -185,14 +183,14 @@ class ExecExtension(
callback("leXinStepExec") {
editMessageText("请发送乐心运动下需要刷的步数")
val step = nextMessage().text().toIntOrNull() ?: error("步数不为数字")
val res = LeXinStepLogic.modifyStepCount(firstArg(), step)
editMessageText(res.message)
LeXinStepLogic.modifyStepCount(firstArg(), step)
editMessageText("修改步数成功")
}
callback("xiaomiStepExec") {
editMessageText("请发送小米运动下需要刷的步数")
val step = nextMessage().text().toIntOrNull() ?: error("步数不为数字")
val res = XiaomiStepLogic.modifyStepCount(firstArg(), step)
editMessageText(res.message)
XiaomiStepLogic.modifyStepCount(firstArg(), step)
editMessageText("修改步数成功")
}
}

Expand All @@ -204,8 +202,7 @@ class ExecExtension(
editMessageText("微博", markup)
}
callback("superTalkSign") {
val result = WeiboLogic.superTalkSign(firstArg())
editMessageText(result.message)
WeiboLogic.superTalkSign(firstArg())
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/me/kuku/telegram/extension/LogExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import me.kuku.telegram.context.AbilitySubscriber
import me.kuku.telegram.context.TelegramSubscribe
import me.kuku.telegram.context.inlineKeyboardButton
import me.kuku.telegram.entity.LogService
import me.kuku.utils.DateTimeFormatterUtils
import org.springframework.stereotype.Component
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

@Component
class LogExtension(
Expand All @@ -29,9 +29,9 @@ class LogExtension(
if (list.isEmpty())
list.add(arrayOf(InlineKeyboardButton("").callbackData("logNone")))
val up = before.minusDays(1).toLocalDate()
val upStr = DateTimeFormatterUtils.format(up, "yyyy-MM-dd")
val upStr = up.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))
val down = before.plusDays(1).toLocalDate()
val downStr = DateTimeFormatterUtils.format(down, "yyyy-MM-dd")
val downStr = down.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))
val deepButton = arrayOf(inlineKeyboardButton("上一天", "log-$upStr"), inlineKeyboardButton("下一天", "log-$downStr"))
list.add(deepButton)
return InlineKeyboardMarkup(*list.toTypedArray())
Expand All @@ -41,15 +41,15 @@ class LogExtension(
fun AbilitySubscriber.logShow() {
sub("log") {
val before = LocalDate.now().atTime(0, 0)
sendMessage("${DateTimeFormatterUtils.format(before, "yyyy-MM-dd")}的自动签到日志,点击可查看详情",
sendMessage("${before.format(DateTimeFormatter.ofPattern( "yyyy-MM-dd"))}的自动签到日志,点击可查看详情",
replyMarkup(before, before.plusDays(1), tgId))
}
}

fun TelegramSubscribe.logSwitch() {
callbackStartsWith("log-") {
val data = query.data().substring(4)
val before = DateTimeFormatterUtils.parseToLocalDate(data, "yyyy-MM-dd")
val before = LocalDate.parse(data, DateTimeFormatter.ofPattern("yyyy-MM-dd"))
val beforeTime = before.atTime(0, 0)
editMessageText("${before}的自动签到日志", replyMarkup(beforeTime, beforeTime.plusDays(1), tgId),
returnButton = false)
Expand Down
Loading

0 comments on commit 7710f49

Please sign in to comment.