Skip to content

Commit 7bf3d1e

Browse files
committed
complete some TODO
1 parent b85a21a commit 7bf3d1e

File tree

6 files changed

+234
-63
lines changed

6 files changed

+234
-63
lines changed

bukkit/src/main/kotlin/me/regadpole/plumbot/bukkit/BukkitImpl.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class BukkitImpl: PlatformImpl() {
3131
TODO("Not yet implemented")
3232
}
3333

34-
override fun dispatchCommand(cmd: String): StringBuilder {
34+
override fun dispatchCommand(cmd: String): String {
3535
TODO("Not yet implemented")
3636
}
3737
}

common/src/main/kotlin/me/regadpole/plumbot/PlatformImpl.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ abstract class PlatformImpl {
44
abstract fun load()
55
abstract fun getPlayerList() : List<String>
66
abstract fun getTPS(): List<Double>
7-
abstract fun dispatchCommand(cmd: String): StringBuilder
7+
abstract fun dispatchCommand(cmd: String): String
88
}

common/src/main/kotlin/me/regadpole/plumbot/bot/Bot.kt

+25
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,29 @@ interface Bot {
5353
*/
5454
fun sendUserMsg(targetId: String, message: String)
5555

56+
/**
57+
* Send picture to the group/user
58+
* @param isGroup is this message send to group
59+
* @param targetId the target you want to send
60+
* @param message the message
61+
*/
62+
fun sendPictureWithText(isGroup: Boolean, targetId: String, message: String?) {
63+
if (message == null) return
64+
if (isGroup) sendGroupMsg(targetId, message)
65+
else sendUserMsg(targetId, message)
66+
}
67+
68+
/**
69+
* Send a picture to group
70+
* @param targetId ID of the target
71+
* @param message Message to send
72+
*/
73+
fun sendGroupPicWithText(targetId: String, message: String)
74+
75+
/**
76+
* Send a picture to user
77+
* @param targetId ID of the target
78+
* @param message Message to send
79+
*/
80+
fun sendUserPicWithText(targetId: String, message: String)
5681
}

common/src/main/kotlin/me/regadpole/plumbot/bot/KookBot.kt

+42-4
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,44 @@ class KookBot(private val plugin: PlumBot): Bot {
127127
}
128128
}
129129

130+
/**
131+
* Send a picture to group
132+
* @param targetId ID of the target
133+
* @param message Message to send
134+
*/
135+
override fun sendGroupPicWithText(targetId: String, message: String) {
136+
val channel = kookClient.core.httpAPI.getChannel(targetId) as TextChannel
137+
val list: MutableList<ImageElement> = ArrayList()
138+
list.add(ImageElement(createPicWithText(message), "", false))
139+
val card: MultipleCardComponent = CardBuilder()
140+
.setTheme(Theme.PRIMARY)
141+
.setSize(Size.LG)
142+
.addModule(ContainerModule(list))
143+
.build()
144+
submitAsync(now = true) {
145+
channel.sendComponent(card)
146+
}
147+
}
148+
149+
/**
150+
* Send a picture to user
151+
* @param targetId ID of the target
152+
* @param message Message to send
153+
*/
154+
override fun sendUserPicWithText(targetId: String, message: String) {
155+
val user = kookClient.core.httpAPI.getUser(targetId)
156+
val list: MutableList<ImageElement> = ArrayList()
157+
list.add(ImageElement(createPicWithText(message), "", false))
158+
val card: MultipleCardComponent = CardBuilder()
159+
.setTheme(Theme.PRIMARY)
160+
.setSize(Size.LG)
161+
.addModule(ContainerModule(list))
162+
.build()
163+
submitAsync(now = true) {
164+
user.sendPrivateMessage(card)
165+
}
166+
}
167+
130168

131169
/**
132170
* Send message to the group/user
@@ -179,7 +217,7 @@ class KookBot(private val plugin: PlumBot): Bot {
179217
user.sendPrivateMessage(s)
180218
}
181219

182-
private fun createFile(s: String): String? {
220+
private fun createPicWithText(s: String): String? {
183221
try {
184222
val file = File.createTempFile("PlumBot-", ".png")
185223
val fos = FileOutputStream(file)
@@ -192,9 +230,9 @@ class KookBot(private val plugin: PlumBot): Bot {
192230
return null
193231
}
194232

195-
fun sendPrivateFileReply(e: PrivateMessageReceivedEvent, s: String) {
233+
fun sendPrivatePicReplyWithText(e: PrivateMessageReceivedEvent, s: String) {
196234
val list: MutableList<ImageElement> = ArrayList()
197-
list.add(ImageElement(createFile(s), "", false))
235+
list.add(ImageElement(createPicWithText(s), "", false))
198236
val card: MultipleCardComponent = CardBuilder()
199237
.setTheme(Theme.PRIMARY)
200238
.setSize(Size.LG)
@@ -207,7 +245,7 @@ class KookBot(private val plugin: PlumBot): Bot {
207245

208246
fun sendChannelFileReply(e: ChannelMessageEvent, s: String) {
209247
val list: MutableList<ImageElement> = ArrayList()
210-
list.add(ImageElement(createFile(s), "", false))
248+
list.add(ImageElement(createPicWithText(s), "", false))
211249
val card: MultipleCardComponent = CardBuilder()
212250
.setTheme(Theme.PRIMARY)
213251
.setSize(Size.LG)

common/src/main/kotlin/me/regadpole/plumbot/bot/QQBot.kt

+25
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import cn.evole.onebot.client.core.BotConfig
55
import cn.evole.onebot.sdk.util.MsgUtils
66
import me.regadpole.plumbot.PlumBot
77
import me.regadpole.plumbot.listener.qq.QQListener
8+
import me.regadpole.plumbot.tool.TextToImg
89
import taboolib.common.platform.function.info
910
import taboolib.common.platform.function.submitAsync
1011

@@ -94,6 +95,30 @@ class QQBot(private val plugin: PlumBot): Bot {
9495
onebot.bot.sendGroupMsg(target, MsgUtils.builder().text(message).build(), true)
9596
}
9697

98+
/**
99+
* Send a picture to group
100+
* @param targetId ID of the target
101+
* @param message Message to send
102+
*/
103+
override fun sendGroupPicWithText(targetId: String, message: String) {
104+
if (targetId.toLongOrNull() == null) return
105+
val target = targetId.toLong()
106+
val msg = TextToImg.toImgCQCode(message)
107+
onebot.bot.sendGroupMsg(target, msg, false)
108+
}
109+
110+
/**
111+
* Send a picture to user
112+
* @param targetId ID of the target
113+
* @param message Message to send
114+
*/
115+
override fun sendUserPicWithText(targetId: String, message: String) {
116+
if (targetId.toLongOrNull() == null) return
117+
val target = targetId.toLong()
118+
val msg = TextToImg.toImgCQCode(message)
119+
onebot.bot.sendPrivateMsg(target, msg, false)
120+
}
121+
97122
/**
98123
* Send message to the group/user
99124
* @param isGroup is this message send to group

0 commit comments

Comments
 (0)