mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
Shamrock
: support /set_guild_member_role
This commit is contained in:
parent
c43689822b
commit
7bfb9b7b61
@ -68,5 +68,6 @@ public interface IKernelGuildService {
|
|||||||
|
|
||||||
void deleteRole(long guild, long role, IGProResultCallback cb);
|
void deleteRole(long guild, long role, IGProResultCallback cb);
|
||||||
|
|
||||||
|
void setMemberRoles(long guild, long u1, long u2, long tinyId, ArrayList<Long> addRoles, ArrayList<Long> removeRoles, IGProResultCallback cb);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -305,4 +305,16 @@ internal object GProSvc: BaseSvc() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setMemberRole(guildId: ULong, tinyId: ULong, roleId: ULong, isSet: Boolean) {
|
||||||
|
val kernelGProService = NTServiceFetcher.kernelService.wrapperSession.guildService
|
||||||
|
val addList = arrayListOf<Long>()
|
||||||
|
val rmList = arrayListOf<Long>()
|
||||||
|
(if (isSet) addList else rmList).add(roleId.toLong())
|
||||||
|
kernelGProService.setMemberRoles(guildId.toLong(), 0, 0, tinyId.toLong(), addList, rmList) { code, msg, result ->
|
||||||
|
if (code != 0) {
|
||||||
|
LogCenter.log("setMemberRole failed: $code($msg) => $result", Level.WARN)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package moe.fuqiuluo.shamrock.remote.action.handlers
|
||||||
|
|
||||||
|
import kotlinx.serialization.json.JsonElement
|
||||||
|
import moe.fuqiuluo.qqinterface.servlet.GProSvc
|
||||||
|
import moe.fuqiuluo.shamrock.remote.action.ActionSession
|
||||||
|
import moe.fuqiuluo.shamrock.remote.action.IActionHandler
|
||||||
|
import moe.fuqiuluo.shamrock.tools.EmptyJsonString
|
||||||
|
import moe.fuqiuluo.shamrock.tools.asString
|
||||||
|
import moe.fuqiuluo.symbols.OneBotHandler
|
||||||
|
|
||||||
|
@OneBotHandler("set_guild_member_role")
|
||||||
|
internal object SetGuildMemberRole: IActionHandler() {
|
||||||
|
override suspend fun internalHandle(session: ActionSession): String {
|
||||||
|
val guildId = session.getString("guild_id").toULong()
|
||||||
|
val role = session.getString("role_id").toULong()
|
||||||
|
val set = session.getBooleanOrDefault("set", false)
|
||||||
|
return if (session.has("user_id")) {
|
||||||
|
val userId = session.getString("user_id").toULong()
|
||||||
|
invoke(guildId, userId, role, set, echo = session.echo)
|
||||||
|
} else if (session.isArray("users")) {
|
||||||
|
invoke(guildId, session.getArray("users").map {
|
||||||
|
it.asString.toULong()
|
||||||
|
}, role, set, echo = session.echo)
|
||||||
|
} else {
|
||||||
|
logic("missing user_id or users", echo = session.echo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun invoke(guildId: ULong, users: List<ULong>, roleId: ULong, set: Boolean, echo: JsonElement = EmptyJsonString): String {
|
||||||
|
users.forEach {
|
||||||
|
GProSvc.setMemberRole(guildId, it, roleId, set)
|
||||||
|
}
|
||||||
|
return ok("success", echo = echo)
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun invoke(guildId: ULong, user: ULong, roleId: ULong, set: Boolean, echo: JsonElement = EmptyJsonString): String {
|
||||||
|
GProSvc.setMemberRole(guildId, user, roleId, set)
|
||||||
|
return ok("success", echo = echo)
|
||||||
|
}
|
||||||
|
|
||||||
|
override val requiredParams: Array<String> = arrayOf("guild_id", "role_id")
|
||||||
|
}
|
@ -19,12 +19,14 @@ import moe.fuqiuluo.shamrock.remote.action.handlers.GetGuildRoles
|
|||||||
import moe.fuqiuluo.shamrock.remote.action.handlers.GetGuildServiceProfile
|
import moe.fuqiuluo.shamrock.remote.action.handlers.GetGuildServiceProfile
|
||||||
import moe.fuqiuluo.shamrock.remote.action.handlers.SendGuildMessage
|
import moe.fuqiuluo.shamrock.remote.action.handlers.SendGuildMessage
|
||||||
import moe.fuqiuluo.shamrock.remote.action.handlers.SendMessage
|
import moe.fuqiuluo.shamrock.remote.action.handlers.SendMessage
|
||||||
|
import moe.fuqiuluo.shamrock.remote.action.handlers.SetGuildMemberRole
|
||||||
import moe.fuqiuluo.shamrock.tools.fetchGetOrNull
|
import moe.fuqiuluo.shamrock.tools.fetchGetOrNull
|
||||||
import moe.fuqiuluo.shamrock.tools.fetchGetOrThrow
|
import moe.fuqiuluo.shamrock.tools.fetchGetOrThrow
|
||||||
import moe.fuqiuluo.shamrock.tools.fetchOrNull
|
import moe.fuqiuluo.shamrock.tools.fetchOrNull
|
||||||
import moe.fuqiuluo.shamrock.tools.fetchOrThrow
|
import moe.fuqiuluo.shamrock.tools.fetchOrThrow
|
||||||
import moe.fuqiuluo.shamrock.tools.fetchPostJsonArray
|
import moe.fuqiuluo.shamrock.tools.fetchPostJsonArray
|
||||||
import moe.fuqiuluo.shamrock.tools.fetchPostJsonObject
|
import moe.fuqiuluo.shamrock.tools.fetchPostJsonObject
|
||||||
|
import moe.fuqiuluo.shamrock.tools.fetchPostJsonString
|
||||||
import moe.fuqiuluo.shamrock.tools.fetchPostOrNull
|
import moe.fuqiuluo.shamrock.tools.fetchPostOrNull
|
||||||
import moe.fuqiuluo.shamrock.tools.fetchPostOrThrow
|
import moe.fuqiuluo.shamrock.tools.fetchPostOrThrow
|
||||||
import moe.fuqiuluo.shamrock.tools.getOrPost
|
import moe.fuqiuluo.shamrock.tools.getOrPost
|
||||||
@ -130,4 +132,22 @@ fun Routing.guildAction() {
|
|||||||
val roleId = fetchOrThrow("role_id").toULong()
|
val roleId = fetchOrThrow("role_id").toULong()
|
||||||
call.respondText(DeleteGuildRole(guildId, roleId), ContentType.Application.Json)
|
call.respondText(DeleteGuildRole(guildId, roleId), ContentType.Application.Json)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getOrPost("/set_guild_member_role") {
|
||||||
|
val guildId = fetchOrThrow("guild_id").toULong()
|
||||||
|
val roleId = fetchOrThrow("role_id").toULong()
|
||||||
|
val set = fetchOrNull("set")?.toBoolean() ?: false
|
||||||
|
val userId = fetchOrNull("user_id")?.toULong()
|
||||||
|
val users = fetchOrNull("users")?.split(",")?.map { it.toULong() }
|
||||||
|
call.respondText(
|
||||||
|
if (userId != null) {
|
||||||
|
SetGuildMemberRole(guildId, userId, roleId, set)
|
||||||
|
} else if (users != null) {
|
||||||
|
SetGuildMemberRole(guildId, users, roleId, set)
|
||||||
|
} else {
|
||||||
|
throw IllegalArgumentException("missing user_id or users")
|
||||||
|
},
|
||||||
|
ContentType.Application.Json
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user