mirai/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotHelper.kt

39 lines
1.4 KiB
Kotlin
Raw Normal View History

2019-10-13 20:19:54 +08:00
@file:Suppress("unused", "EXPERIMENTAL_API_USAGE")
package net.mamoe.mirai
2019-10-24 15:01:56 +08:00
import net.mamoe.mirai.contact.*
2019-10-26 15:54:02 +08:00
import net.mamoe.mirai.network.BotSession
2019-10-22 20:08:08 +08:00
import net.mamoe.mirai.network.protocol.tim.packet.OutgoingPacket
2019-10-13 20:19:54 +08:00
import net.mamoe.mirai.network.protocol.tim.packet.login.LoginResult
2019-10-26 15:54:02 +08:00
import net.mamoe.mirai.network.session
2019-10-19 11:59:08 +08:00
import net.mamoe.mirai.utils.BotNetworkConfiguration
2019-10-13 20:19:54 +08:00
2019-10-24 15:01:56 +08:00
/*
2019-10-13 20:19:54 +08:00
* The mirror of functions in inner classes of [Bot]
*/
//Contacts
2019-10-24 15:01:56 +08:00
suspend fun Bot.getQQ(number: Long): QQ = this.contacts.getQQ(number.toUInt())
2019-10-13 20:19:54 +08:00
2019-10-24 15:01:56 +08:00
suspend fun Bot.getQQ(number: UInt): QQ = this.contacts.getQQ(number)
2019-10-13 20:19:54 +08:00
2019-10-24 15:01:56 +08:00
suspend fun Bot.getGroup(id: GroupId): Group = this.contacts.getGroup(id)
suspend fun Bot.getGroup(internalId: GroupInternalId): Group = this.contacts.getGroup(internalId)
2019-10-13 20:19:54 +08:00
val Bot.groups: ContactList<Group> get() = this.contacts.groups
val Bot.qqs: ContactList<QQ> get() = this.contacts.qqs
2019-10-26 15:54:02 +08:00
inline fun <T> Bot.withSession(block: BotSession.() -> T): T = with(this.network.session) { block() }
2019-10-13 20:19:54 +08:00
//NetworkHandler
2019-10-22 20:08:08 +08:00
suspend fun Bot.sendPacket(packet: OutgoingPacket) = this.network.sendPacket(packet)
2019-10-13 20:19:54 +08:00
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-24 15:01:56 +08:00
val Bot.qqAccount: UInt get() = this.account.id