Skip to content

Commit 211c1ad

Browse files
authored
Merge pull request #3 from StopWuyu/update
javadoc: add more descriptions for codes
2 parents ed34d4a + c245561 commit 211c1ad

17 files changed

+156
-24
lines changed

.gitignore

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# 项目排除路径
22
/.gradle/
33
/build/
4-
/build/classes/kotlin/main/
4+
/build/classes/kotlin/main/
5+
/config.json
6+
/LinkBot-1.0.0.jar
7+
/data/
8+
/device.json
9+
/plugins/
10+
/cache/
11+
/logs/

gradle/libs.versions.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
[versions]
22
kotlin = "1.8.10"
3-
ktor = "2.1.2"
43
exposed = "0.41.1"
54

65
[plugins]
76
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
8-
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "11.2.0" }
7+
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "11.4.0" }
98
abi-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.12.1" }
109
spotless = { id = "com.diffplug.spotless", version = "6.15.0" }
1110
licensee = { id = "app.cash.licensee", version = "1.6.0" }

settings.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ rootProject.name = "LinkBot"
22

33
pluginManagement {
44
repositories {
5-
maven("https://maven.aliyun.com/repository/public/")
6-
maven("https://maven.aliyun.com/repository/gradle-plugin/")
75
maven(url = "https://plugins.gradle.org/m2/")
6+
maven("https://maven.aliyun.com/repository/gradle-plugin/")
7+
maven("https://maven.aliyun.com/repository/public/")
88
mavenCentral()
99
}
1010
}

src/main/kotlin/tech/egglink/projects/linkbot/bot/Bot.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ class Bot {
1212

1313
/**
1414
* 机器人登录
15-
* */
15+
*
16+
* @param account QQ 号
17+
* @param password 密码
18+
*/
1619
fun login(account: Long, password: String) {
1720
bot = Mirai.BotFactory.newBot(
1821
account,

src/main/kotlin/tech/egglink/projects/linkbot/command/BotCommandSender.kt

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package tech.egglink.projects.linkbot.command
33
import net.mamoe.mirai.contact.Contact
44
import net.mamoe.mirai.contact.Group
55

6+
/**
7+
* 用于 Bot 的 CommandSender
8+
* */
69
interface BotCommandSender : CommandSender {
710
val sender: Contact
811
val group: Group

src/main/kotlin/tech/egglink/projects/linkbot/command/CommandHandler.kt

+21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
package tech.egglink.projects.linkbot.command
22

3+
/**
4+
* 命令实例
5+
*
6+
* 所有的命令都应该继承这个类
7+
* @param entry 命令信息
8+
* */
39
abstract class CommandHandler(val entry: Entry) {
10+
/**
11+
* 命令信息
12+
*
13+
* @property name 命令名
14+
* @property description 命令描述
15+
* @property usage 命令用法
16+
* @property aliases 命令别名
17+
* @property type 命令类型
18+
* @property argsType 参数类型
19+
* @property defaultArgs 默认参数
20+
* @property permission 权限
21+
* */
422
open class Entry {
523
var name: String = ""
624
var description: String = ""
@@ -20,5 +38,8 @@ abstract class CommandHandler(val entry: Entry) {
2038
var permission: String = "true"
2139
}
2240

41+
/**
42+
* 命令执行
43+
* */
2344
abstract suspend fun execute(sender: CommandSender, args: Array<String>): CommandResult
2445
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
package tech.egglink.projects.linkbot.command
22

3+
/**
4+
* 命令结果
5+
*
6+
* @property SUCCESS 成功
7+
* @property FAILURE 失败
8+
* @property ERROR 错误
9+
* @property NOT_FOUND 未找到
10+
* @property NO_PERMISSION 无权限
11+
* @property INVALID_USAGE 无效用法
12+
* */
313
enum class CommandResult {
4-
SUCCESS,
5-
FAILURE,
6-
ERROR,
7-
NOT_FOUND,
8-
NO_PERMISSION,
9-
INVALID_USAGE
14+
SUCCESS, // 成功
15+
FAILURE, // 失败
16+
ERROR, // 错误
17+
NOT_FOUND, // 未找到
18+
NO_PERMISSION, // 无权限
19+
INVALID_USAGE // 无效用法
1020
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
package tech.egglink.projects.linkbot.command
22

3+
/**
4+
* 命令发送者实例
5+
* */
36
interface CommandSender {
7+
/**
8+
* 发送消息
9+
*
10+
* @param message 消息
11+
* */
412
suspend fun sendMessage(message: String)
513

14+
/**
15+
* 检查是否有权限
16+
*
17+
* @param permission 权限
18+
* */
619
fun hasPermission(permission: String): Boolean
720
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
package tech.egglink.projects.linkbot.command
22

3+
/**
4+
* 命令类型
5+
*
6+
* @property Bot 机器人
7+
* @property Console 控制台
8+
* */
39
enum class CommandType {
4-
Bot,
5-
Console
10+
Bot, // 机器人
11+
Console // 控制台
612
}

src/main/kotlin/tech/egglink/projects/linkbot/command/Commands.kt

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class Commands {
2828
registerCommand(CommandLogout())
2929
}
3030

31+
/**
32+
* 注册所有机器人命令
33+
* */
3134
fun registerBotCommands() {
3235
registerCommand(tech.egglink.projects.linkbot.command.cmd.bot.CommandHelp())
3336
}

src/main/kotlin/tech/egglink/projects/linkbot/command/ConsoleCommandSender.kt

+14-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@ package tech.egglink.projects.linkbot.command
22

33
import tech.egglink.projects.linkbot.utils.Utils
44

5+
/**
6+
* 用于控制台的 CommandSender
7+
* */
58
class ConsoleCommandSender : CommandSender {
9+
/**
10+
* 发送消息
11+
*
12+
* @param message 消息
13+
* */
614
override suspend fun sendMessage(message: String) {
715
Utils.logger.info(message)
816
}
917

10-
override fun hasPermission(permission: String): Boolean {
11-
return true
12-
}
18+
/**
19+
* 检查是否有权限
20+
*
21+
* @param permission 权限
22+
* */
23+
override fun hasPermission(permission: String): Boolean = true
1324
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
package tech.egglink.projects.linkbot.dataprovider
22

3+
/**
4+
* 数据提供器
5+
* */
36
class DataProvider {
7+
/**
8+
* 通过 QQ 号新建用户数据
9+
*
10+
* @param qq QQ 号
11+
* */
412
fun createUserData(qq: Long) {
13+
UserData(qq)
514
}
615
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
11
package tech.egglink.projects.linkbot.dataprovider
22

3-
class UserData {
3+
data class UserData(
44
/**
55
* QQ 号 用于核对
66
* */
7-
var qqId: Long = 0L
7+
var qqId: Long = 0L,
88

99
/**
1010
* 被授予 True 权限的权限
1111
* */
12-
val permissionTrue: Array<String> = arrayOf()
12+
val permissionTrue: Array<String> = arrayOf(),
1313

1414
/**
1515
* 被授予 False 权限的权限
1616
* */
1717
val permissionFalse: Array<String> = arrayOf()
18+
) {
19+
override fun equals(other: Any?): Boolean {
20+
if (this === other) return true
21+
if (javaClass != other?.javaClass) return false
22+
23+
other as UserData
24+
25+
if (qqId != other.qqId) return false
26+
if (!permissionTrue.contentEquals(other.permissionTrue)) return false
27+
return permissionFalse.contentEquals(other.permissionFalse)
28+
}
29+
30+
override fun hashCode(): Int {
31+
var result = qqId.hashCode()
32+
result = 31 * result + permissionTrue.contentHashCode()
33+
result = 31 * result + permissionFalse.contentHashCode()
34+
return result
35+
}
1836
}

src/main/kotlin/tech/egglink/projects/linkbot/event/CommandEvent.kt

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package tech.egglink.projects.linkbot.event
22

3+
/**
4+
* 不清楚干什么的了
5+
*/
36
class CommandEvent : net.mamoe.mirai.event.Event {
47
override val isIntercepted: Boolean = false
58

src/main/kotlin/tech/egglink/projects/linkbot/event/EventListener.kt

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import net.mamoe.mirai.event.events.GroupNameChangeEvent
1212
import net.mamoe.mirai.event.events.MemberJoinRequestEvent
1313
import tech.egglink.projects.linkbot.utils.Utils
1414

15+
/**
16+
* 事件监听器
17+
* */
1518
object EventListener {
1619
fun beginListen() {
1720
Utils.bot.getBot().eventChannel.subscribeAlways<BotEvent> {

src/main/kotlin/tech/egglink/projects/linkbot/event/EventManager.kt

+27-1
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,50 @@ package tech.egglink.projects.linkbot.event
22

33
import tech.egglink.projects.linkbot.utils.Utils
44

5+
/**
6+
* 事件管理器
7+
* */
58
class EventManager {
69

7-
private val events = mutableListOf<Event>()
10+
private val events = mutableListOf<Event>() // 事件列表
11+
12+
/**
13+
* 注册事件
14+
*
15+
* @param events 事件列表
16+
* */
817
fun registerEvents(vararg events: Event) {
918
events.forEach { event ->
1019
registerEvent(event)
1120
}
1221
}
22+
23+
/**
24+
* 注册事件
25+
*
26+
* @param events 事件列表
27+
* */
1328
fun registerEvents(events: List<Event>) {
1429
events.forEach { event ->
1530
registerEvent(event)
1631
}
1732
}
1833

34+
/**
35+
* 注册单个事件
36+
*
37+
* @param event 事件
38+
* */
1939
fun registerEvent(event: Event) {
2040
events.add(event)
2141
}
2242

43+
/**
44+
* 广播事件
45+
*
46+
* @param eventType 事件类型
47+
* @param evt 事件
48+
* */
2349
fun broadcastEvent(eventType: EventType, evt: net.mamoe.mirai.event.Event = CommandEvent()) {
2450
eventType.let {
2551
Utils.logger.debug("事件广播: ${it.javaClass.simpleName}(${it.hashCode()})")

src/main/kotlin/tech/egglink/projects/linkbot/utils/configurations/Message.kt

-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ class Message {
2121
val loginDescription = "登录机器人."
2222
val logoutUsage = "logout"
2323
val logoutDescription = "登出机器人."
24-
val databaseUsage = "database find <qq>"
25-
val databaseDescription = "查看数据库."
2624
}
2725
val command = Command()
2826

@@ -34,7 +32,6 @@ class Message {
3432
val unknownCommand = "未知命令!"
3533
val noPermission = "没有权限!"
3634
val invalidArgs = "参数错误!"
37-
val databaseNotFound = "数据库中未找到!"
3835
}
3936
val error = Error()
4037

0 commit comments

Comments
 (0)