2019-10-13 20:19:54 +08:00
|
|
|
@file:Suppress("unused", "EXPERIMENTAL_API_USAGE")
|
|
|
|
|
|
|
|
package net.mamoe.mirai
|
|
|
|
|
|
|
|
import kotlinx.io.core.readBytes
|
|
|
|
import net.mamoe.mirai.contact.Group
|
|
|
|
import net.mamoe.mirai.contact.QQ
|
|
|
|
import net.mamoe.mirai.network.protocol.tim.packet.ClientPacket
|
|
|
|
import net.mamoe.mirai.network.protocol.tim.packet.ServerPacket
|
|
|
|
import net.mamoe.mirai.network.protocol.tim.packet.login.LoginResult
|
2019-10-19 11:59:08 +08:00
|
|
|
import net.mamoe.mirai.utils.BotNetworkConfiguration
|
2019-10-13 20:19:54 +08:00
|
|
|
import net.mamoe.mirai.utils.ContactList
|
|
|
|
import net.mamoe.mirai.utils.toUHexString
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The mirror of functions in inner classes of [Bot]
|
|
|
|
*/
|
|
|
|
|
|
|
|
//Contacts
|
|
|
|
fun Bot.getQQ(number: Long): QQ = this.contacts.getQQ(number)
|
|
|
|
|
|
|
|
fun Bot.getQQ(number: UInt): QQ = getQQ(number.toLong())
|
|
|
|
|
|
|
|
fun Bot.getGroupByNumber(number: Long): Group = this.contacts.getGroupByNumber(number)
|
|
|
|
fun Bot.getGroupByNumber(number: UInt): Group = getGroupByNumber(number.toLong())
|
|
|
|
|
|
|
|
fun Bot.getGroupById(number: Long): Group = this.contacts.getGroupById(number)
|
|
|
|
|
|
|
|
val Bot.groups: ContactList<Group> get() = this.contacts.groups
|
|
|
|
|
|
|
|
val Bot.qqs: ContactList<QQ> get() = this.contacts.qqs
|
|
|
|
|
|
|
|
|
|
|
|
//NetworkHandler
|
|
|
|
suspend fun Bot.sendPacket(packet: ClientPacket) = this.network.sendPacket(packet)
|
|
|
|
|
2019-10-19 11:59:08 +08:00
|
|
|
suspend fun Bot.login(configuration: BotNetworkConfiguration.() -> Unit): LoginResult = this.network.login(BotNetworkConfiguration().apply(configuration))
|
2019-10-13 20:19:54 +08:00
|
|
|
|
2019-10-19 11:59:08 +08:00
|
|
|
suspend fun Bot.login(): LoginResult = this.network.login(BotNetworkConfiguration.Default)
|
2019-10-13 20:19:54 +08:00
|
|
|
|
|
|
|
//BotAccount
|
2019-10-17 10:01:20 +08:00
|
|
|
val Bot.qqAccount: Long get() = this.account.account
|
2019-10-13 20:19:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
//logging
|
2019-10-19 11:59:08 +08:00
|
|
|
fun Bot.log(o: Any?) = logInfo(o)
|
2019-10-13 20:19:54 +08:00
|
|
|
|
2019-10-19 11:59:08 +08:00
|
|
|
fun Bot.println(o: Any?) = logInfo(o)
|
|
|
|
fun Bot.logInfo(o: Any?) = this.logger.logInfo(o)
|
2019-10-13 20:19:54 +08:00
|
|
|
|
2019-10-19 11:59:08 +08:00
|
|
|
fun Bot.logError(o: Any?) = this.logger.logError(o)
|
2019-10-13 20:19:54 +08:00
|
|
|
|
2019-10-19 11:59:08 +08:00
|
|
|
fun Bot.logPurple(o: Any?) = this.logger.logPurple(o)
|
2019-10-13 20:19:54 +08:00
|
|
|
|
2019-10-19 11:59:08 +08:00
|
|
|
fun Bot.logCyan(o: Any?) = this.logger.logCyan(o)
|
|
|
|
fun Bot.logGreen(o: Any?) = this.logger.logGreen(o)
|
2019-10-13 20:19:54 +08:00
|
|
|
|
2019-10-19 11:59:08 +08:00
|
|
|
fun Bot.logDebug(o: Any?) = this.logger.logDebug(o)
|
2019-10-13 20:19:54 +08:00
|
|
|
|
|
|
|
fun Bot.printPacketDebugging(packet: ServerPacket) {
|
2019-10-19 11:59:08 +08:00
|
|
|
logDebug("Packet=$packet")
|
|
|
|
logDebug("Packet size=" + packet.input.readBytes().size)
|
|
|
|
logDebug("Packet data=" + packet.input.readBytes().toUHexString())
|
2019-10-13 20:19:54 +08:00
|
|
|
}
|