Skip to content

Instantly share code, notes, and snippets.

@yiheng0 yiheng0/BaseBot.kt Secret
Created Aug 4, 2018

Embed
What would you like to do?
package moe.yiheng
import com.sobte.cqp.jcq.entity.ICQVer
import com.sobte.cqp.jcq.entity.IMsg
import com.sobte.cqp.jcq.entity.IRequest
import com.sobte.cqp.jcq.event.JcqAppAbstract
import java.util.*
abstract class BaseBot : JcqAppAbstract(), ICQVer, IMsg, IRequest {
override fun startup(): Int {
log("bot开始运行")
return 0
}
override fun exit(): Int {
log("bot停止运行")
return 0
}
override fun enable(): Int {
log("应用被启用")
return 0
}
override fun disable(): Int {
log("应用被停用")
return 0
}
override fun privateMsg(subType: Int, msgId: Int, fromQQ: Long, msg: String, font: Int): Int {
log("""
收到了一条私聊消息:
类型 -> ${
when (subType) {
// 11/来自好友 1/来自在线状态 2/来自群 3/来自讨论组
11 -> "来自好友"
1 -> "来自在线状态"
2 -> "来自群"
3 -> "来自讨论组"
else -> "未知"
}
}
消息ID -> $msgId
来自QQ -> $fromQQ
消息内容 -> $msg
字体 -> $font
""".trimIndent()
)
return 0
}
override fun groupMsg(subType: Int, msgId: Int, fromGroup: Long, fromQQ: Long, fromAnonymous: String, msg: String, font: Int): Int {
log("""
收到了一条群组消息
消息ID -> $msgId
来自群组 -> $fromGroup
来自QQ -> $fromQQ
来源匿名者 -> $fromAnonymous
消息 -> $msg
字体 -> $font
""".trimIndent())
return 0
}
override fun discussMsg(subtype: Int, msgId: Int, fromDiscuss: Long, fromQQ: Long, msg: String, font: Int): Int {
log("""
收到了一条讨论组消息
消息ID -> $msgId
来自讨论组 -> $fromDiscuss
来自QQ -> $fromQQ
消息 -> $msg
字体 -> $font
""".trimIndent())
return 0
}
override fun groupUpload(subType: Int, sendTime: Int, fromGroup: Long, fromQQ: Long, file: String): Int {
log("""
群文件上传
发送时间 -> ${Date(sendTime.toLong())}
来自群组 -> $fromGroup
来自QQ -> $fromQQ
文件 -> $file
""".trimIndent())
return 0
}
override fun groupAdmin(subtype: Int, sendTime: Int, fromGroup: Long, beingOperateQQ: Long): Int {
log("""
群组管理员变动
类型 -> ${
when (subtype) {
1 -> "被取消管理员"
2 -> "被设置管理员"
else -> "未知"
}
}
发送时间 -> ${Date(sendTime.toLong())}
来自群组 -> $fromGroup
被操作QQ -> $beingOperateQQ
""".trimIndent())
return 0
}
override fun groupMemberDecrease(subtype: Int, sendTime: Int, fromGroup: Long, fromQQ: Long, beingOperateQQ: Long): Int {
log("""
群组成员减少
类型 -> ${
when (subtype) {
1 -> "群员离开"
2 -> "群员被踢"
else -> "未知"
}
}
发送时间 -> ${Date(sendTime.toLong())}
来自群组 -> $fromGroup
操作者QQ -> $fromQQ
被操作QQ -> $beingOperateQQ
""".trimIndent())
return 0
}
override fun groupMemberIncrease(subtype: Int, sendTime: Int, fromGroup: Long, fromQQ: Long, beingOperateQQ: Long): Int {
log("""
群组成员增加
类型 -> ${
when (subtype) {
1 -> "管理员已同意"
2 -> "管理员邀请"
else -> "未知"
}
}
发送时间 -> ${Date(sendTime.toLong())}
来自群组 -> $fromGroup
操作者QQ -> $fromQQ
被操作QQ -> $beingOperateQQ
""".trimIndent())
return 0
}
override fun friendAdd(subtype: Int, sendTime: Int, fromQQ: Long): Int {
log("""
好友已添加
发送时间 -> ${Date(sendTime.toLong())}
添加QQ -> $fromQQ
""".trimIndent())
return 0
}
override fun requestAddFriend(subtype: Int, sendTime: Int, fromQQ: Long, msg: String, responseFlag: String): Int {
log("""
添加好友请求
发送时间 -> ${Date(sendTime.toLong())}
请求者QQ -> $fromQQ
留言 -> $msg
反馈标识 -> $responseFlag
""".trimIndent())
return 0
}
override fun requestAddGroup(subtype: Int, sendTime: Int, fromGroup: Long, fromQQ: Long, msg: String, responseFlag: String): Int {
log("""
加群请求
类型 -> ${
when (subtype) {
1 -> "他人申请入群"
2 -> "自己受邀入群"
else -> "未知"
}
}
来源群号 -> $fromGroup
来源者QQ -> $fromQQ
留言 -> $msg
反馈标识 -> $responseFlag
""".trimIndent())
return 0
}
override fun appInfo(): String? {
val AppID = "moe.yiheng.test"// 记住编译后的文件和json也要使用appid做文件名
/**
* 本函数【禁止】处理其他任何代码,以免发生异常情况。
* 如需执行初始化代码请在 startup 事件中执行(Type=1001)。
*/
return ICQVer.CQAPIVER.toString() + "," + AppID
}
private fun log(content: String) {
CQ.logInfo("testbot", content)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.