2
0
Эх сурвалжийг харах

Add more builders for Bot

Him188 6 жил өмнө
parent
commit
28c0530268

+ 11 - 0
mirai-core-qqandroid/src/androidMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroid.kt

@@ -24,4 +24,15 @@ actual object QQAndroid : BotFactory {
     actual override fun Bot(context: Context, qq: Long, password: String, configuration: BotConfiguration): Bot {
         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)
 }

+ 11 - 0
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/BotFactory.kt

@@ -11,6 +11,7 @@ package net.mamoe.mirai.qqandroid
 
 import net.mamoe.mirai.Bot
 import net.mamoe.mirai.BotFactory
+import net.mamoe.mirai.qqandroid.QQAndroid.Bot
 import net.mamoe.mirai.utils.BotConfiguration
 import net.mamoe.mirai.utils.Context
 
@@ -23,4 +24,14 @@ expect object QQAndroid : BotFactory {
      * 使用指定的 [配置][configuration] 构造 [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
 }

+ 26 - 0
mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroid.kt

@@ -14,6 +14,7 @@ package net.mamoe.mirai.qqandroid
 import net.mamoe.mirai.Bot
 import net.mamoe.mirai.BotAccount
 import net.mamoe.mirai.BotFactory
+import net.mamoe.mirai.qqandroid.QQAndroid.Bot
 import net.mamoe.mirai.utils.BotConfiguration
 import net.mamoe.mirai.utils.Context
 import net.mamoe.mirai.utils.MiraiInternalAPI
@@ -24,12 +25,37 @@ import net.mamoe.mirai.utils.MiraiInternalAPI
 @UseExperimental(MiraiInternalAPI::class)
 actual object QQAndroid : BotFactory {
 
+    /**
+     * 使用指定的 [配置][configuration] 构造 [Bot] 实例
+     */
     actual override fun Bot(context: Context, qq: Long, password: String, configuration: BotConfiguration): Bot {
         return QQAndroidBot(context, BotAccount(qq, password), configuration)
     }
 
+    /**
+     * 使用指定的 [配置][configuration] 构造 [Bot] 实例
+     */
     fun Bot(qq: Long, password: String, configuration: BotConfiguration = BotConfiguration.Default): Bot =
         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)
 }
 
 /**

+ 34 - 5
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotFactory.kt

@@ -13,8 +13,6 @@ package net.mamoe.mirai
 
 import net.mamoe.mirai.utils.BotConfiguration
 import net.mamoe.mirai.utils.Context
-import kotlin.jvm.JvmName
-import kotlin.jvm.JvmOverloads
 
 /**
  * 构造 [Bot] 的工厂.
@@ -27,11 +25,42 @@ interface BotFactory {
     /**
      * 使用指定的 [配置][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] 实例
  */
-inline fun BotFactory.Bot(context: Context, qq: Long, password: String, configuration: (BotConfiguration.() -> Unit)): Bot =
-    this.Bot(context, qq, password, BotConfiguration().apply(configuration))
+inline fun BotFactory.Bot(
+    context: Context,
+    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))

+ 38 - 1
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/BotFactoryJvm.kt

@@ -71,4 +71,41 @@ fun Bot(qq: Long, password: String, configuration: BotConfiguration = BotConfigu
  */
 @JvmSynthetic
 inline fun Bot(qq: Long, password: String, configuration: (BotConfiguration.() -> Unit)): Bot =
-    factory.Bot(ContextImpl(), qq, password, configuration)
+    factory.Bot(ContextImpl(), qq, password, configuration)
+
+
+/**
+ * 加载现有协议的 [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))