Skip to content

Commit

Permalink
add LLOnebot, NapCat, go-cqhttp poke support
Browse files Browse the repository at this point in the history
drop OpenShamrock poke support
  • Loading branch information
MrXiaoM committed Jan 11, 2025
1 parent e1351e9 commit c521744
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
34 changes: 34 additions & 0 deletions onebot/src/main/kotlin/client/core/Bot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1494,4 +1494,38 @@ class Bot(
val result = actionHandler.action(this, action, params)
return result.withToken()
}

/**
* 好友戳一戳
*
* LLOnebot、NapCat
* @param userId 好友QQ号
* @return [ActionRaw]
*/
suspend fun extFriendPoke(userId: Long): ActionRaw {
val action = ActionPathEnum.EXT_FRIEND_POKE
val params = JsonObject().apply {
addProperty("user_id", userId)
}
val result = actionHandler.action(this, action, params)
return result.withClass()
}

/**
* 群聊戳一戳
*
* LLOnebot、NapCat
* @param groupId 群号
* @param userId 好友QQ号
* @return [ActionRaw]
*/
suspend fun extGroupPoke(groupId: Long, userId: Long): ActionRaw {
val action = ActionPathEnum.EXT_GROUP_POKE
val params = JsonObject().apply {
addProperty("group_id", groupId)
addProperty("user_id", userId)
}
val result = actionHandler.action(this, action, params)
return result.withClass()
}
}
14 changes: 14 additions & 0 deletions onebot/src/main/kotlin/sdk/enums/ActionPathEnum.kt
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,20 @@ enum class ActionPathEnum(
*/
EXT_GET_AVATAR("get_avatar"),

/**
* 好友戳一戳
*
* 属于 LLOnebot, NapCat 扩展 API
*/
EXT_FRIEND_POKE("friend_poke"),

/**
* 群聊戳一戳
*
* 属于 LLOnebot, NapCat 扩展 API
*/
EXT_GROUP_POKE("group_poke"),

/**
* 创建群文件夹
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,23 @@ class Overflow : IMirai, CoroutineScope, LowLevelApiAccessor, OverflowAPI {
}

override suspend fun sendNudge(bot: Bot, nudge: Nudge, receiver: Contact): Boolean {
val msg = "[{\"type\":\"touch\",\"data\":{\"id\":${nudge.target.id}}}]"
val onebot = bot.asOnebot
when (onebot.appName.lowercase()) {
"llonebot", "napcat" -> {
if (receiver is Group) {
onebot.impl.extGroupPoke(receiver.id, nudge.target.id)
} else {
onebot.impl.extFriendPoke(receiver.id)
}
return true
}
}
// go-cqhttp
val msg = "[{\"type\":\"poke\",\"data\":{\"id\":${nudge.target.id}}}]"
if (receiver is Group) {
bot.asOnebot.impl.sendGroupMsg(receiver.id, msg, false)
onebot.impl.sendGroupMsg(receiver.id, msg, false)
} else {
bot.asOnebot.impl.sendPrivateMsg(receiver.id, msg, false)
onebot.impl.sendPrivateMsg(receiver.id, msg, false)
}
return true
}
Expand Down

0 comments on commit c521744

Please sign in to comment.