mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-27 08:50:15 +08:00
Updated message
This commit is contained in:
parent
fa6a9b66b2
commit
f2986d91db
BIN
.github/event hook.png
vendored
Normal file
BIN
.github/event hook.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
@ -24,8 +24,12 @@ Network部分使用 Kotlin 完成(因为kt有对 unsigned byte 的支持).
|
||||
1. Clone
|
||||
2. Import as Maven project
|
||||
3. Run [MiraiMain](mirai-core/src/main/java/net/mamoe/mirai/MiraiMain.java#L7)
|
||||
|
||||
简略阅读源码便可测试接收和发送消息
|
||||
|
||||
Hook 一个事件(Kotlin):
|
||||
![event hook.png](.github/event%20hook.png)
|
||||
|
||||
### TODO
|
||||
- [x] 事件(Event)模块
|
||||
- [ ] 插件(Plugin)模块 **(Working on)**
|
||||
|
@ -178,7 +178,13 @@ public class MiraiServer {
|
||||
|
||||
getLogger().info("Initializing [Robot]s");
|
||||
|
||||
try {
|
||||
getAvailableRobot();
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
/*
|
||||
this.qqs.keySet().stream().map(key -> this.qqs.getSection(key)).forEach(section -> {
|
||||
getLogger().info("Initializing [Robot] " + section.getString("account"));
|
||||
try {
|
||||
@ -199,7 +205,7 @@ public class MiraiServer {
|
||||
getLogger().error("Could not load QQ robots config!");
|
||||
System.exit(1);
|
||||
}
|
||||
});
|
||||
});*/
|
||||
}
|
||||
|
||||
|
||||
@ -209,20 +215,9 @@ public class MiraiServer {
|
||||
"3145561616----987654321\n" +
|
||||
"2374150554----12345678910\n" +
|
||||
"2375307394----12345678910\n" +
|
||||
"1531848970----1234567890\n" +
|
||||
"1947293188----a123456789\n" +
|
||||
"1771231721----123456789a\n" +
|
||||
"2401645747----12345678910\n" +
|
||||
"3338427598----987654321\n" +
|
||||
"3055657369----1234567890\n" +
|
||||
"3502771486----987654321\n" +
|
||||
"1515419818----1234567890\n" +
|
||||
"2402273360----12345678910\n" +
|
||||
"3107367848----987654321\n" +
|
||||
"3487109947----123456789a\n" +
|
||||
"3489288352----123456789a\n" +
|
||||
"2385617018----12345678910\n" +
|
||||
"1251003390----123456789a\n";
|
||||
"3107367848----987654321\n";
|
||||
|
||||
private Robot getAvailableRobot() throws ExecutionException, InterruptedException {
|
||||
for (String it : qqList.split("\n")) {
|
||||
|
@ -15,7 +15,17 @@ import java.util.*
|
||||
* 可发送的或从服务器接收的消息.
|
||||
* 采用这样的消息模式是因为 QQ 的消息多元化, 一条消息中可包含 [纯文本][PlainText], [图片][Image] 等.
|
||||
*
|
||||
* 在 Kotlin, 使用 [Message] 与使用 [String] 几乎没有什么用法上的区别, 除了
|
||||
* #### 在 Kotlin 使用 [Message]
|
||||
* 这与使用 [String] 的使用非常类似.
|
||||
*
|
||||
* 比较 [Message] 与 [String] (使用 infix [Message.valueEquals]):
|
||||
* `if(message valueEquals "你好") qq.sendMessage(message)`
|
||||
*
|
||||
* 连接 [Message] 与 [Message], [String], [BufferedImage] (使用 operator [Message.plus]):
|
||||
* ```
|
||||
* message = PlainText("Hello ")
|
||||
* qq.sendMessage(message + "world")
|
||||
* ```
|
||||
*
|
||||
* @author Him188moe
|
||||
* @see Contact.sendMessage
|
||||
|
@ -3,6 +3,7 @@ package net.mamoe.mirai.message.defaults
|
||||
import net.mamoe.mirai.message.Message
|
||||
import net.mamoe.mirai.message.MessageId
|
||||
import net.mamoe.mirai.utils.lazyEncode
|
||||
import org.intellij.lang.annotations.MagicConstant
|
||||
import java.util.*
|
||||
import java.util.stream.Collectors
|
||||
import java.util.stream.Stream
|
||||
@ -31,6 +32,20 @@ class MessageChain : Message {
|
||||
return list.toList()
|
||||
}
|
||||
|
||||
fun size(): Int {
|
||||
return list.size
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun containsType(@MagicConstant(valuesFromClass = MessageId::class) type: Int): Boolean {
|
||||
for (message in list) {
|
||||
if (message.type == type) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun stream(): Stream<Message> {
|
||||
return ArrayList(list).stream()
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import net.mamoe.mirai.event.events.network.PacketSentEvent
|
||||
import net.mamoe.mirai.event.events.network.ServerPacketReceivedEvent
|
||||
import net.mamoe.mirai.event.events.qq.FriendMessageEvent
|
||||
import net.mamoe.mirai.event.events.robot.RobotLoginSucceedEvent
|
||||
import net.mamoe.mirai.event.hookAlways
|
||||
import net.mamoe.mirai.event.hookWhile
|
||||
import net.mamoe.mirai.message.Message
|
||||
import net.mamoe.mirai.message.defaults.MessageChain
|
||||
@ -483,6 +484,16 @@ class RobotNetworkHandler(private val robot: Robot) : Closeable {
|
||||
inner class MessageHandler : PacketHandler() {
|
||||
internal var ignoreMessage: Boolean = false
|
||||
|
||||
init {
|
||||
FriendMessageEvent::class.hookAlways {
|
||||
if (it.message() valueEquals "你好") {
|
||||
it.qq.sendMessage("你好!")
|
||||
} else if (it.message().toString().startsWith("复读")) {
|
||||
it.qq.sendMessage(it.message())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPacketReceived(packet: ServerPacket) {
|
||||
when (packet) {
|
||||
is ServerGroupUploadFileEventPacket -> {
|
||||
@ -494,12 +505,7 @@ class RobotNetworkHandler(private val robot: Robot) : Closeable {
|
||||
return
|
||||
}
|
||||
|
||||
val friendMessageEvent = FriendMessageEvent(robot, robot.contacts.getQQ(packet.qq), packet.message)
|
||||
friendMessageEvent.broadcast()
|
||||
|
||||
if (friendMessageEvent.message() valueEquals "你好") {
|
||||
friendMessageEvent.qq.sendMessage("你好")
|
||||
}
|
||||
FriendMessageEvent(robot, robot.contacts.getQQ(packet.qq), packet.message).broadcast()
|
||||
}
|
||||
|
||||
is ServerGroupMessageEventPacket -> {
|
||||
|
@ -70,7 +70,7 @@ abstract class ClientPacket : ByteArrayDataOutputStream(), Packet {
|
||||
|
||||
|
||||
override fun toString(): String {
|
||||
return adjustName(this.javaClass.simpleName + "(${this.getFixedId()})") + this.getAllDeclaredFields().filterNot { it.name == "idHex" || it.name == "encoded" }.joinToString(", ", "{", "}") {
|
||||
return adjustName(this.javaClass.simpleName + "(${this.getFixedId()})") + this.getAllDeclaredFields().filterNot { it.name == "idHex" || it.name == "idByteArray" || it.name == "encoded" }.joinToString(", ", "{", "}") {
|
||||
it.trySetAccessible(); it.name + "=" + it.get(this).let { value ->
|
||||
when (value) {
|
||||
null -> null
|
||||
|
@ -16,7 +16,7 @@ import java.io.IOException
|
||||
*
|
||||
* @author Him188moe
|
||||
*/
|
||||
@PacketId("08 25 31 0?")
|
||||
@PacketId("08 25 31 01")
|
||||
class ServerTouchResponsePacket(inputStream: DataInputStream) : ServerPacket(inputStream) {
|
||||
var serverIP: String? = null
|
||||
|
||||
|
@ -101,7 +101,7 @@ private fun DataOutputStream.writePart1(qq: Long, password: String, loginTime: I
|
||||
this.writeHex("00 38")//length
|
||||
this.write(token0825)//length
|
||||
this.writeHex("03 0F")//tag
|
||||
this.writeDeviceName(false)
|
||||
this.writeDeviceName(true)
|
||||
|
||||
this.writeHex("00 05 00 06 00 02")
|
||||
this.writeQQ(qq)
|
||||
|
@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>mirai</artifactId>
|
||||
<groupId>net.mamoe</groupId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>mirai-native</artifactId>
|
||||
<version>1.0</version>
|
||||
</project>
|
@ -1,9 +0,0 @@
|
||||
package net.mamoe.mirai.util;
|
||||
|
||||
/**
|
||||
* @author Him188moe
|
||||
*/
|
||||
public final class TeaEncryption {
|
||||
|
||||
public static native int Decrypt();
|
||||
}
|
Loading…
Reference in New Issue
Block a user