Skip to content

Commit

Permalink
增加日志显示选项;修复未配置代理报错的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
TigerBeanst committed Nov 8, 2022
1 parent 157f4be commit d1b016b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ luoxu-bot 是依赖于 [luoxu](https://github.com/lilydjwg/luoxu) 后端的 Tele
```yaml
my-id: 19260817
bot-token: 1111122222:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
show-log: false
local-proxy:

base-url: http://localhost:9008
base-url-prefix: luoxu
```
1. `my-id` 为你的 Telegram 账号 ID,向 [@getidsbot](https://t.me/getidsbot) 发送 `/start` 可以获取
2. `bot-token` 为你的 Bot Token,向 [@BotFather](https://t.me/botfather) 申请 Bot,获取 `bot-token`(由`数字:数字字母`构成,如`1111122222:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA`),获取完毕后记得向 Bot 本身发送 `/start` 之类的消息以让其获悉你的 id
3. `local-proxy` 为你的代理,如 `socks5://127.0.0.1:7890`,留空则不使用代理
4. `base-url` 为你的 luoxu 后端地址,如 `http://localhost:9008`
5. `base-url-prefix` 为你的 luoxu 后端地址前缀,如 `luoxu`
3. `show-log` 为是否显示 Bot 的日志,`true` 为显示,`false` 为不显示
4. `local-proxy` 为你的代理,如 `socks5://127.0.0.1:7890`,留空则不使用代理
5. `base-url` 为你的 luoxu 后端地址,如 `http://localhost:9008`
6. `base-url-prefix` 为你的 luoxu 后端地址前缀,如 `luoxu`

# 使用
- `/list` 获取已索引群组的列表和相关信息
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/BotUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import java.net.Proxy

fun String.containsEnhanced(vararg strs: String) = strs.any { this.contains(it) }

fun getProxy(): Proxy {
if (LOCAL_PROXY == "") return Proxy.NO_PROXY
fun getProxy(): Proxy? {
if (LOCAL_PROXY == "") return null
val proxyType = if (LOCAL_PROXY.contains("http")) Proxy.Type.HTTP else Proxy.Type.SOCKS
val proxyAddress = LOCAL_PROXY.substringAfter("://").substringBefore(":")
val proxyPort = LOCAL_PROXY.substringAfter("://").substringAfter(":").toInt()
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import java.io.File

var MY_ID = 0L
var BOT_TOKEN: String = ""
var SHOW_LOG: Boolean = false
var LOCAL_PROXY = ""
var BASE_URL = "http://localhost:9008"
var BASE_URL_PREFIX = "luoxu"
Expand All @@ -18,6 +19,7 @@ fun configInit() {
when {
startsWith("my-id:") -> MY_ID = value.toLong()
startsWith("bot-token:") -> BOT_TOKEN = value
startsWith("show-log:") -> SHOW_LOG = value.toBoolean()
startsWith("local-proxy:") -> LOCAL_PROXY = value
startsWith("base-url:") -> BASE_URL = value
startsWith("base-url-prefix:") -> BASE_URL_PREFIX = value
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ fun main() {
configInit()
val bot = bot {
token = BOT_TOKEN
proxy = getProxy()
if(getProxy() != null) {
proxy = getProxy()!!
}
dispatch {
command("list") { getGroupList() }
text() { beforeSearch() }
callbackQuery { afterSearch() }
}
// logLevel = LogLevel.All()
logLevel = if (SHOW_LOG) LogLevel.All() else LogLevel.None
}
bot.startPolling()
}
Expand Down

0 comments on commit d1b016b

Please sign in to comment.