Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
Shamrock: support /delete_guild_role
Browse files Browse the repository at this point in the history
  • Loading branch information
whitechi73 committed Feb 2, 2024
1 parent 7952453 commit c436898
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.tencent.qqnt.kernel.nativeinterface;

public interface IGProResultCallback {
void onResult(int code, String msg, GProSecurityResult result);
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ public interface IKernelGuildService {
String getGuildUserAvatarUrl(long guildId, long tinyId, int seq);

String getGuildUserNickname(long guildId);

void deleteRole(long guild, long role, IGProResultCallback cb);


}
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,13 @@ internal object GProSvc: BaseSvc() {
} ?: return Result.failure(Exception("unable to fetch guild roles"))
return Result.success(roles)
}

fun deleteGuildRole(guildId: ULong, roleId: ULong) {
val kernelGProService = NTServiceFetcher.kernelService.wrapperSession.guildService
kernelGProService.deleteRole(guildId.toLong(), roleId.toLong()) { code, msg, result ->
if (code != 0) {
LogCenter.log("deleteGuildRole failed: $code($msg) => $result", Level.WARN)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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.symbols.OneBotHandler

@OneBotHandler("delete_guild_role")
internal object DeleteGuildRole: IActionHandler() {
override suspend fun internalHandle(session: ActionSession): String {
val guildId = session.getString("guild_id").toULong()
val roleId = session.getString("role_id").toULong()
return invoke(guildId, roleId, session.echo)
}

operator fun invoke(guildId: ULong, roleId: ULong, echo: JsonElement = EmptyJsonString): String {
GProSvc.deleteGuildRole(guildId, roleId)
return ok("success", echo = echo)
}

override val requiredParams: Array<String> = arrayOf("guild_id", "role_id")
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.ktor.server.routing.get
import io.ktor.server.routing.post
import io.ktor.server.routing.route
import moe.fuqiuluo.shamrock.helper.MessageHelper
import moe.fuqiuluo.shamrock.remote.action.handlers.DeleteGuildRole
import moe.fuqiuluo.shamrock.remote.action.handlers.GetGProChannelList
import moe.fuqiuluo.shamrock.remote.action.handlers.GetGuildFeeds
import moe.fuqiuluo.shamrock.remote.action.handlers.GetGuildList
Expand Down Expand Up @@ -123,4 +124,10 @@ fun Routing.guildAction() {
val guildId = fetchOrThrow("guild_id").toULong()
call.respondText(GetGuildRoles(guildId), ContentType.Application.Json)
}

getOrPost("/delete_guild_role") {
val guildId = fetchOrThrow("guild_id").toULong()
val roleId = fetchOrThrow("role_id").toULong()
call.respondText(DeleteGuildRole(guildId, roleId), ContentType.Application.Json)
}
}

0 comments on commit c436898

Please sign in to comment.