Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Commit

Permalink
fix #12;废止reboot responder;更新依赖;不再在帮助信息中显示已经禁止的响应器
Browse files Browse the repository at this point in the history
  • Loading branch information
Ray-Eldath committed May 18, 2019
1 parent f607ea3 commit 96f6f34
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 67 deletions.
23 changes: 12 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = 'ray-eldath.avalon'
version = '1.3.0'
version = '1.3.1'

apply plugin: 'java'
apply plugin: 'kotlin'
Expand Down Expand Up @@ -27,34 +27,35 @@ dependencies {
compile group: 'org.jdom', name: 'jdom2', version: '2.0.6'
// https://mvnrepository.com/artifact/jaxen/jaxen
compile group: 'jaxen', name: 'jaxen', version: '1.1.6'
// https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-server
compile group: 'org.eclipse.jetty', name: 'jetty-server', version: '9.4.12.v20180830'
// https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-server
compile group: 'org.eclipse.jetty', name: 'jetty-server', version: '9.4.18.v20190429'
// https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-servlet
compile group: 'org.eclipse.jetty', name: 'jetty-servlet', version: '9.4.12.v20180830'
compile group: 'org.eclipse.jetty', name: 'jetty-servlet', version: '9.4.18.v20190429'
// https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-util
compile group: 'org.eclipse.jetty', name: 'jetty-util', version: '9.4.12.v20180830'
compile group: 'org.eclipse.jetty', name: 'jetty-util', version: '9.4.18.v20190429'
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
// https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
// https://mvnrepository.com/artifact/org.slf4j/slf4j-api
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.26'
// https://mvnrepository.com/artifact/org.json/json
compile group: 'org.json', name: 'json', version: '20180813'
// https://mvnrepository.com/artifact/mysql/mysql-connector-java
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.11'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.16'
// https://mvnrepository.com/artifact/com.h2database/h2
compile group: 'com.h2database', name: 'h2', version: '1.4.197'
compile group: 'com.h2database', name: 'h2', version: '1.4.199'
// https://bintray.com/dv8fromtheworld/maven/JDA/
compile 'net.dv8tion:JDA:3.8.0_424'
compile 'net.dv8tion:JDA:3.8.3_463'

compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

buildscript {
ext.kotlin_version = '1.2.51'
ext.kotlin_version = '1.3.21'

repositories {
jcenter()
mavenCentral()
}

Expand Down
2 changes: 1 addition & 1 deletion config_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"function_config": {
"RSS": {
"enable": false,
"enable": true,
"feed": [
"http://ice1000.org/feed.xml"
]
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/avalon/function/RSSFeeder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.time.format.FormatStyle
import java.util.*

object RSSFeeder : Runnable {
private val urls = toURLList(Configs.getResponderConfigArray("RSS", "feed"))
private val urls = toURLList(Configs.getPluginConfigArray("RSS", "feed"))
private val updated = hashMapOf(*urls.map { it to LocalDateTime.MIN }.toTypedArray())
private val random = Random()

Expand Down
50 changes: 25 additions & 25 deletions src/main/kotlin/avalon/group/GroupMessageHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import kotlin.collections.ArrayList
object GroupMessageHandler {

internal fun getGroupResponderByKeywordRegex(keyword: String): GroupMessageResponder? =
apiTriples.firstOrNull { it.actualPattern.matcher(keyword).matches() }?.instance
apiTriples.firstOrNull { it.actualPattern.matcher(keyword).matches() }?.instance

internal fun isResponderEnable(api: GroupMessageResponder): Boolean {
if (!enableMap.containsKey(api))
Expand All @@ -54,10 +54,10 @@ object GroupMessageHandler {
val senderUid = message.senderUid

val groupConfig =
if (groupUid != DEBUG_MESSAGE_GROUP_UID)
GroupConfigs.instance().getConfig(groupUid)
else
GroupConfig(true, false, DEBUG_MESSAGE_UID, longArrayOf(), longArrayOf(), listOf())
if (groupUid != DEBUG_MESSAGE_GROUP_UID)
GroupConfigs.instance().getConfig(groupUid)
else
GroupConfig(true, false, DEBUG_MESSAGE_UID, longArrayOf(), longArrayOf(), listOf())

if (groupConfig == null) {
LOGGER.warn("listened message from not configured group $groupUid. Ignored this message. Please config this group in `group.json`.")
Expand Down Expand Up @@ -96,7 +96,7 @@ object GroupMessageHandler {
APISurvivePool.getInstance().setNoticed(value)
}
} else if (MessageChecker.check(message) && isResponderEnable(value) &&
permissionCheck(info.permission, groupConfig, message))
permissionCheck(info.permission, groupConfig, message))
value.doPost(message, groupConfig)
return
}
Expand Down Expand Up @@ -138,10 +138,10 @@ object GroupMessageHandler {
// 屏蔽词判断
for (thisBlockString in blockWordList)
if (groupMessage.content
.trim { it <= ' ' }
.toLowerCase()
.replace("[\\pP\\p{Punct}]".toRegex(), "")
.contains(thisBlockString)) {
.trim { it <= ' ' }
.toLowerCase()
.replace("[\\pP\\p{Punct}]".toRegex(), "")
.contains(thisBlockString)) {
var notice = LANG.getString("group.handler.block_word")
if (Constants.Setting.Block_Words_Punishment_Mode_Enabled && !admin) {
notice = String.format(LANG.getString("group.handler.block_word_e"), punishFrequency)
Expand Down Expand Up @@ -195,7 +195,7 @@ object GroupMessageHandler {
*/
// 管理类
registerInner(Shutdown)
registerInner(Reboot)
// registerInner(Reboot) v1.3.1:安全和稳健性问题,废止Reboot API
registerInner(Flush)
registerInner(Heartbeat)
registerInner(Manager)
Expand Down Expand Up @@ -226,14 +226,14 @@ object GroupMessageHandler {
}

for (thisEnable in enable
.map { selectByName(apiTriples, it) }
.filterNot { enableMap.containsKey(it) }) {
.map { selectByName(apiTriples, it) }
.filterNot { enableMap.containsKey(it) }) {
enableMap[thisEnable ?: continue] = true
}

apiTriples.map { it.instance }
.filterNot { enableMap.containsKey(it) }
.forEach { enableMap[it] = false }
.filterNot { enableMap.containsKey(it) }
.forEach { enableMap[it] = false }

// 校验
for ((key, value) in enableMap) {
Expand Down Expand Up @@ -261,24 +261,24 @@ object GroupMessageHandler {
print("Input here:")
val content = scanner.nextLine()
val message = GroupMessage(++id, System.currentTimeMillis(),
DEBUG_MESSAGE_UID, "Test", DEBUG_MESSAGE_GROUP_UID, "Test Group", content)
DEBUG_MESSAGE_UID, "Test", DEBUG_MESSAGE_GROUP_UID, "Test Group", content)
GroupMessageHandler.handle(message)
println("===")
}
}

fun addGroupMessageResponder(responder: GroupMessageResponder) {
val matchPattern =
if (responder == Mo)
responder.responderInfo().keyWordRegex
else
Pattern.compile("^(" + Constants.Basic.DEFAULT_PREFIX.joinToString(separator = "|") + ")" +
responder.responderInfo().keyWordRegex.pattern())
if (responder == Mo)
responder.responderInfo().keyWordRegex
else
Pattern.compile("^(" + Constants.Basic.DEFAULT_PREFIX.joinToString(separator = "|") + ")" +
responder.responderInfo().keyWordRegex.pattern())
apiTriples.add(GroupMessageResponderTriple(
responder.javaClass.simpleName,
matchPattern,
responder.responderInfo().keyWordRegex,
responder))
responder.javaClass.simpleName,
matchPattern,
responder.responderInfo().keyWordRegex,
responder))
}

fun addCustomGroupResponder(responder: CustomGroupResponder) = customApiList.put(responder.getKeyWordRegex(), responder)
Expand Down
27 changes: 14 additions & 13 deletions src/main/kotlin/avalon/group/Help.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ object Help : GroupMessageResponder() {
for (api in apiTriple.map { it.instance }.sortedBy { it.responderInfo().helpMessage.first }) {
val flags = ArrayList<String>()
if (!GroupMessageHandler.isResponderEnable(api))
flags.add(disabled)
// flags.add(disabled)
continue
val info = api.responderInfo()
val helpMessage = info.helpMessage
if (helpMessage.first.isEmpty() || helpMessage.second.isEmpty())
Expand All @@ -35,19 +36,19 @@ object Help : GroupMessageResponder() {
else if (info.permission == ResponderPermission.OWNER)
flags.add(owner)
messageShow.append("\n$prefixString")
.append(helpMessage.first)
.append("")
.append(if (flags.isEmpty()) "" else flags.joinToString(separator = " ", postfix = " "))
.append(helpMessage.second)
.append(helpMessage.first)
.append("")
.append(if (flags.isEmpty()) "" else flags.joinToString(separator = " ", postfix = " "))
.append(helpMessage.second)
}
for (thisPlugin in AvalonPluginPool.getPluginList()) {
val temp = RegisterResponder.queryAvalonPlugin(thisPlugin)
.forEach { e -> messageShow.append("\n").append(e.getHelpMessage()) }
.forEach { e -> messageShow.append("\n").append(e.getHelpMessage()) }
messageShow.append(LANG.getString("group.help.plugin_command").format(thisPlugin.name(), temp))
}
val displayPrefix = Constants.Basic.DEFAULT_PREFIX
.joinToString(separator = LANG.getString("base.or"))
.replace(" ", "")
.joinToString(separator = LANG.getString("base.or"))
.replace(" ", "")
"""${LANG.getString("group.help.reply").format(displayPrefix)}$messageShow
For Avalon Version v${Constants.Version.AVALON}"""
// "\n(我才不会告诉你我有一些没有写在这里的彩蛋指令呢~哈哈`(*∩_∩*)′)");
Expand All @@ -58,11 +59,11 @@ For Avalon Version v${Constants.Version.AVALON}"""
}

override fun responderInfo(): ResponderInfo =
ResponderInfo(
Pair("(hp|help)", LANG.getString("group.help.help")),
Pattern.compile("(hp|help)"),
manageable = false
)
ResponderInfo(
Pair("(hp|help)", LANG.getString("group.help.help")),
Pattern.compile("(hp|help)"),
manageable = false
)

override fun instance(): GroupMessageResponder? = this
}
26 changes: 13 additions & 13 deletions src/main/kotlin/avalon/tool/Executives.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ object GlotRun : Executive {
val array = arrayT.getJSONArray("array")
val map = HashMap<String, URL>(array.length())
(0 until array.length())
.map(array::getJSONObject)
.forEach { map[it.getString("name")] = URL("${it.getString("url")}/latest") }
.map(array::getJSONObject)
.forEach { map[it.getString("name")] = URL("${it.getString("url")}/latest") }
return map
}

Expand Down Expand Up @@ -55,21 +55,21 @@ object GlotRun : Executive {
obj.put("files", array)


val result = Share.post(lang[language]!!, obj,
hashMapOf(
Pair("Content-type", "application/json"),
Pair("Authorization", "Token $token"))) ?: throw RuntimeException("nonnull `result`")
val result = Share.post(lang.getValue(language), obj,
hashMapOf(
Pair("Content-type", "application/json"),
Pair("Authorization", "Token $token"))) ?: throw RuntimeException("nonnull `result`")

val errorB = result.getBoolean("internal_error")

val error =
if (errorB) {
if (result.has("message") && result.notNull("message"))
result.getString("message")
else
"internal error"
} else
result.getString("error")
if (errorB) {
if (result.has("message") && result.notNull("message"))
result.getString("message")
else
"internal error"
} else
result.getString("error")

val stdout = if (errorB) "" else result.getString("stdout")
val stderr = if (errorB) "" else result.getString("stderr")
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/avalon/tool/pool/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object Constants {
}

object Version {
const val AVALON = "1.3.0"
const val AVALON = "1.3.1"
val SERVLET = Basic.CURRENT_SERVLET.version()
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/lang/Avalon.properties
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ group.show_admin.no_admin=Current group DO NOT has admin (-ロ-)
group.shutdown.help=To exit Avalon

# Version
group.version.reply=Hi, I'm Avalon.\nMy name and avatar are all come from *Implosion*, My backend service served by %s. \nI am developed by Ray Eldath, and I am open source on GitHub, on https://github.com/Ray-Eldath/Avalon
group.version.reply=Hi, I'm Avalon.\nMy name and/or avatar are all come from *Implosion*, My backend service served by %s. \nI am developed by Ray Eldath, and I am open source on GitHub, on https://github.com/Ray-Eldath/Avalon
group.version.plugin=All plugins: %s\tAll loaded plugins: %s
group.version.running_on_pc=I am running on personal computer (not server), so I am not able to serve stable service. Asking my owner `%s - %d` for more info.
group.version.help=Show version and related info.
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/lang/Avalon_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ group.show_admin.no_admin=当前群组未配置管理员(-ロ-)
group.shutdown.help=退出Avalon

# Version
group.version.reply=Hi, I'm Avalon.\n我是阿瓦隆,IM群机器人。\n我的名字和头像均取自《Implosion》,我由%s提供底层服务。\n我由Ray Eldath开发。\n我在GitHub上开源,欢迎访问我的仓库:https://github.com/Ray-Eldath/Avalon
group.version.reply=Hi, I'm Avalon.\n我是阿瓦隆,IM群机器人。\n我的名字和/或头像均取自《Implosion》,我由%s提供底层服务。\n我由Ray Eldath开发。\n我在GitHub上开源,欢迎访问我的仓库:https://github.com/Ray-Eldath/Avalon
group.version.plugin=全部插件有:%s\t已装载的插件有:%s
group.version.running_on_pc=我运行在个人计算机(而不是服务器)上,故无法提供稳定服务。若有其它疑问请联系我的主人`%s - %d`
group.version.help=显示版本及相关信息
Expand Down

0 comments on commit 96f6f34

Please sign in to comment.