Skip to content

Commit

Permalink
完成 Github #7
Browse files Browse the repository at this point in the history
  • Loading branch information
IceCream-QAQ committed Jul 7, 2020
1 parent d74c47a commit c098568
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/main/kotlin/com/icecreamqaq/yuq/controller/util.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.icecreamqaq.yuq.controller

import com.IceCreamQAQ.Yu.annotation.Before
import com.icecreamqaq.yuq.YuQ
import com.icecreamqaq.yuq.message.Message
import com.icecreamqaq.yuq.message.MessageFactory
import com.icecreamqaq.yuq.message.MessageItem
import com.icecreamqaq.yuq.message.MessageItemFactory
import com.icecreamqaq.yuq.send
import javax.inject.Inject
import javax.inject.Named

abstract class QQController {

@Inject
lateinit var yuq: YuQ

@Inject
lateinit var mf: MessageFactory

@Inject
lateinit var mif: MessageItemFactory


private val qqControllerUtilActionContextLocal: ThreadLocal<BotActionContext> = ThreadLocal()

@Before
fun qqControllerUtilBefore(@Named("actionContext") actionContext: BotActionContext) {
qqControllerUtilActionContextLocal.set(actionContext)
}

fun reply(msg: String) = ((qqControllerUtilActionContextLocal.get()?.message?.newMessage()
?: error("当前线程没有 Action 上下文。")) + msg).send()

fun reply(msg: MessageItem) = ((qqControllerUtilActionContextLocal.get()?.message?.newMessage()
?: error("当前线程没有 Action 上下文。")) + msg).send()

fun reply(msg: Message) = ((qqControllerUtilActionContextLocal.get()?.message?.newMessage()
?: error("当前线程没有 Action 上下文。")) + msg).send()

}

0 comments on commit c098568

Please sign in to comment.