Commit 28c05302 authored by Him188's avatar Him188

Add more builders for Bot

parent 6a324d4a
...@@ -24,4 +24,15 @@ actual object QQAndroid : BotFactory { ...@@ -24,4 +24,15 @@ actual object QQAndroid : BotFactory {
actual override fun Bot(context: Context, qq: Long, password: String, configuration: BotConfiguration): Bot { actual override fun Bot(context: Context, qq: Long, password: String, configuration: BotConfiguration): Bot {
return QQAndroidBot(context, BotAccount(qq, password), configuration) return QQAndroidBot(context, BotAccount(qq, password), configuration)
} }
/**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
@UseExperimental(MiraiInternalAPI::class)
actual override fun Bot(
context: Context,
qq: Long,
passwordMd5: ByteArray,
configuration: BotConfiguration
): Bot = QQAndroidBot(context, BotAccount(qq, passwordMd5), configuration)
} }
\ No newline at end of file
...@@ -11,6 +11,7 @@ package net.mamoe.mirai.qqandroid ...@@ -11,6 +11,7 @@ package net.mamoe.mirai.qqandroid
import net.mamoe.mirai.Bot import net.mamoe.mirai.Bot
import net.mamoe.mirai.BotFactory import net.mamoe.mirai.BotFactory
import net.mamoe.mirai.qqandroid.QQAndroid.Bot
import net.mamoe.mirai.utils.BotConfiguration import net.mamoe.mirai.utils.BotConfiguration
import net.mamoe.mirai.utils.Context import net.mamoe.mirai.utils.Context
...@@ -23,4 +24,14 @@ expect object QQAndroid : BotFactory { ...@@ -23,4 +24,14 @@ expect object QQAndroid : BotFactory {
* 使用指定的 [配置][configuration] 构造 [Bot] 实例 * 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/ */
override fun Bot(context: Context, qq: Long, password: String, configuration: BotConfiguration): Bot override fun Bot(context: Context, qq: Long, password: String, configuration: BotConfiguration): Bot
/**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
override fun Bot(
context: Context,
qq: Long,
passwordMd5: ByteArray,
configuration: BotConfiguration
): Bot
} }
\ No newline at end of file
...@@ -14,6 +14,7 @@ package net.mamoe.mirai.qqandroid ...@@ -14,6 +14,7 @@ package net.mamoe.mirai.qqandroid
import net.mamoe.mirai.Bot import net.mamoe.mirai.Bot
import net.mamoe.mirai.BotAccount import net.mamoe.mirai.BotAccount
import net.mamoe.mirai.BotFactory import net.mamoe.mirai.BotFactory
import net.mamoe.mirai.qqandroid.QQAndroid.Bot
import net.mamoe.mirai.utils.BotConfiguration import net.mamoe.mirai.utils.BotConfiguration
import net.mamoe.mirai.utils.Context import net.mamoe.mirai.utils.Context
import net.mamoe.mirai.utils.MiraiInternalAPI import net.mamoe.mirai.utils.MiraiInternalAPI
...@@ -24,12 +25,37 @@ import net.mamoe.mirai.utils.MiraiInternalAPI ...@@ -24,12 +25,37 @@ import net.mamoe.mirai.utils.MiraiInternalAPI
@UseExperimental(MiraiInternalAPI::class) @UseExperimental(MiraiInternalAPI::class)
actual object QQAndroid : BotFactory { actual object QQAndroid : BotFactory {
/**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
actual override fun Bot(context: Context, qq: Long, password: String, configuration: BotConfiguration): Bot { actual override fun Bot(context: Context, qq: Long, password: String, configuration: BotConfiguration): Bot {
return QQAndroidBot(context, BotAccount(qq, password), configuration) return QQAndroidBot(context, BotAccount(qq, password), configuration)
} }
/**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
fun Bot(qq: Long, password: String, configuration: BotConfiguration = BotConfiguration.Default): Bot = fun Bot(qq: Long, password: String, configuration: BotConfiguration = BotConfiguration.Default): Bot =
QQAndroidBot(BotAccount(qq, password), configuration) QQAndroidBot(BotAccount(qq, password), configuration)
/**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
actual override fun Bot(
context: Context,
qq: Long,
passwordMd5: ByteArray,
configuration: BotConfiguration
): Bot = QQAndroidBot(context, BotAccount(qq, passwordMd5), configuration)
/**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
fun Bot(
qq: Long,
passwordMd5: ByteArray,
configuration: BotConfiguration
): Bot = QQAndroidBot(BotAccount(qq, passwordMd5), configuration)
} }
/** /**
......
...@@ -13,8 +13,6 @@ package net.mamoe.mirai ...@@ -13,8 +13,6 @@ package net.mamoe.mirai
import net.mamoe.mirai.utils.BotConfiguration import net.mamoe.mirai.utils.BotConfiguration
import net.mamoe.mirai.utils.Context import net.mamoe.mirai.utils.Context
import kotlin.jvm.JvmName
import kotlin.jvm.JvmOverloads
/** /**
* 构造 [Bot] 的工厂. * 构造 [Bot] 的工厂.
...@@ -27,11 +25,42 @@ interface BotFactory { ...@@ -27,11 +25,42 @@ interface BotFactory {
/** /**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例 * 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/ */
fun Bot(context: Context, qq: Long, password: String, configuration: BotConfiguration = BotConfiguration.Default): Bot fun Bot(
context: Context,
qq: Long,
password: String,
configuration: BotConfiguration = BotConfiguration.Default
): Bot
/**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
fun Bot(
context: Context,
qq: Long,
passwordMd5: ByteArray,
configuration: BotConfiguration = BotConfiguration.Default
): Bot
} }
/** /**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例 * 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/ */
inline fun BotFactory.Bot(context: Context, qq: Long, password: String, configuration: (BotConfiguration.() -> Unit)): Bot = inline fun BotFactory.Bot(
this.Bot(context, qq, password, BotConfiguration().apply(configuration)) context: Context,
\ No newline at end of file qq: Long,
password: String,
configuration: (BotConfiguration.() -> Unit)
): Bot =
this.Bot(context, qq, password, BotConfiguration().apply(configuration))
/**
* 使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
inline fun BotFactory.Bot(
context: Context,
qq: Long,
passwordMd5: ByteArray,
configuration: (BotConfiguration.() -> Unit)
): Bot =
this.Bot(context, qq, passwordMd5, BotConfiguration().apply(configuration))
\ No newline at end of file
...@@ -71,4 +71,41 @@ fun Bot(qq: Long, password: String, configuration: BotConfiguration = BotConfigu ...@@ -71,4 +71,41 @@ fun Bot(qq: Long, password: String, configuration: BotConfiguration = BotConfigu
*/ */
@JvmSynthetic @JvmSynthetic
inline fun Bot(qq: Long, password: String, configuration: (BotConfiguration.() -> Unit)): Bot = inline fun Bot(qq: Long, password: String, configuration: (BotConfiguration.() -> Unit)): Bot =
factory.Bot(ContextImpl(), qq, password, configuration) factory.Bot(ContextImpl(), qq, password, configuration)
\ No newline at end of file
/**
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
@JvmName("newBot")
@JvmOverloads
fun Bot(
context: Context,
qq: Long,
passwordMd5: ByteArray,
configuration: BotConfiguration = BotConfiguration.Default
): Bot =
factory.Bot(context, qq, passwordMd5, configuration)
/**
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
@JvmSynthetic
inline fun Bot(context: Context, qq: Long, passwordMd5: ByteArray, configuration: (BotConfiguration.() -> Unit)): Bot =
factory.Bot(context, qq, passwordMd5, BotConfiguration().apply(configuration))
/**
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
@JvmName("newBot")
@JvmOverloads
fun Bot(qq: Long, passwordMd5: ByteArray, configuration: BotConfiguration = BotConfiguration.Default): Bot =
factory.Bot(ContextImpl(), qq, passwordMd5, configuration)
/**
* 加载现有协议的 [BotFactory], 并使用指定的 [配置][configuration] 构造 [Bot] 实例
*/
@JvmSynthetic
inline fun Bot(qq: Long, passwordMd5: ByteArray, configuration: (BotConfiguration.() -> Unit)): Bot =
factory.Bot(ContextImpl(), qq, passwordMd5, BotConfiguration().apply(configuration))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment