BotFactory.kt 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2019-2020 Mamoe Technologies and contributors.
  3. *
  4. * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  5. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  6. *
  7. * https://github.com/mamoe/mirai/blob/master/LICENSE
  8. */
  9. @file:Suppress("FunctionName", "INAPPLICABLE_JVM_NAME", "DEPRECATION_ERROR", "DeprecatedCallableAddReplaceWith")
  10. package net.mamoe.mirai
  11. import net.mamoe.mirai.utils.BotConfiguration
  12. import net.mamoe.mirai.utils.Context
  13. import net.mamoe.mirai.utils.SinceMirai
  14. import kotlin.jvm.JvmName
  15. import kotlin.jvm.JvmSynthetic
  16. /**
  17. * 构造 [Bot] 的工厂. 这是 [Bot] 唯一的构造方式.
  18. *
  19. * `mirai-core-qqandroid`: `QQAndroid`
  20. *
  21. * 在 JVM, 请查看 `BotFactoryJvm`
  22. */
  23. public expect interface BotFactory {
  24. /**
  25. * 使用指定的 [配置][configuration] 构造 [Bot] 实例
  26. */
  27. @JvmName("newBot")
  28. public fun Bot(
  29. context: Context,
  30. qq: Long,
  31. password: String,
  32. configuration: BotConfiguration = BotConfiguration.Default
  33. ): Bot
  34. /**
  35. * 使用指定的 [配置][configuration] 构造 [Bot] 实例
  36. */
  37. @JvmName("newBot")
  38. public fun Bot(
  39. context: Context,
  40. qq: Long,
  41. passwordMd5: ByteArray,
  42. configuration: BotConfiguration = BotConfiguration.Default
  43. ): Bot
  44. @SinceMirai("1.3.0")
  45. public companion object INSTANCE : BotFactory
  46. }
  47. /**
  48. * 使用指定的 [配置][configuration] 构造 [Bot] 实例
  49. */
  50. @JvmSynthetic
  51. public inline fun BotFactory.Bot(
  52. context: Context,
  53. qq: Long,
  54. password: String,
  55. configuration: (BotConfiguration.() -> Unit)
  56. ): Bot = this.Bot(context, qq, password, BotConfiguration().apply(configuration))
  57. /**
  58. * 使用指定的 [配置][configuration] 构造 [Bot] 实例
  59. */
  60. @JvmSynthetic
  61. public inline fun BotFactory.Bot(
  62. context: Context,
  63. qq: Long,
  64. password: ByteArray,
  65. configuration: (BotConfiguration.() -> Unit)
  66. ): Bot = this.Bot(context, qq, password, BotConfiguration().apply(configuration))