Skip to content

Commit

Permalink
support delete group files
Browse files Browse the repository at this point in the history
  • Loading branch information
MrXiaoM committed Dec 11, 2023
1 parent bad4daa commit 3028c30
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ public enum ActionPathEnum implements ActionPath {
* 获取用户资料卡
*/
GET_USER_INFO("get_user_info"),
/**
* 删除群文件
*/
DELETE_GROUP_FILE("delete_group_file"),
/**
* 删除群文件夹
*/
DELETE_GROUP_FOLDER("delete_group_folder"),

;

Expand Down
36 changes: 36 additions & 0 deletions onebot/src/main/kotlin/cn/evolvefield/onebot/client/core/Bot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,42 @@ class Bot(
object : TypeToken<ActionData<UserInfoResp>>() {}.type
)
}

/**
* 删除群文件
*
* @param groupId 群号
* @param fileId 文件ID
* @param busid 此参数可在群文件相关接口中获取
* @return [ActionRaw]
*/
@JvmBlockingBridge
suspend fun deleteGroupFile(groupId: Long, fileId: String, busid: Int): ActionRaw {
val action = ActionPathEnum.DELETE_GROUP_FILE
val params = JsonObject()
params.addProperty("group_id", groupId)
params.addProperty("file_id", fileId)
params.addProperty("busid", busid)
val result = actionHandler.action(channel, action, params)
return GsonUtil.strToJavaBean(result.toString(), ActionRaw::class.java)
}

/**
* 删除群文件夹
*
* @param groupId 群号
* @param folderId 文件夹ID
* @return [ActionRaw]
*/
@JvmBlockingBridge
suspend fun deleteGroupFolder(groupId: Long, folderId: String): ActionRaw {
val action = ActionPathEnum.DELETE_GROUP_FOLDER
val params = JsonObject()
params.addProperty("group_id", groupId)
params.addProperty("folder_id", folderId)
val result = actionHandler.action(channel, action, params)
return GsonUtil.strToJavaBean(result.toString(), ActionRaw::class.java)
}
}

fun <T> List<T>.toJsonArray(): JsonArray {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class FolderWrapper(
}

override suspend fun delete(): Boolean {
TODO("Not yet implemented")
return contact.botWrapper.impl.deleteGroupFolder(contact.id, id).status != "failed"
}

override suspend fun exists(): Boolean {
Expand Down Expand Up @@ -179,7 +179,8 @@ class FileWrapper(
override val expiryTime: Long,
override val lastModifiedTime: Long,
override val uploadTime: Long,
override val uploaderId: Long
override val uploaderId: Long,
val busid: Int,
) : AbsoluteFile {
override val isFile: Boolean = true
override val isFolder: Boolean = false
Expand All @@ -194,7 +195,7 @@ class FileWrapper(
}

override suspend fun delete(): Boolean {
TODO("Not yet implemented")
return contact.botWrapper.impl.deleteGroupFile(contact.id, id, busid).status != "failed"
}

override suspend fun exists(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fun List<GroupFilesResp.Files>.toMiraiFiles(group: GroupWrapper, parent: FolderW
val md5 = it.md5?.hexToBytes() ?: ByteArray(16)
val sha1 = it.sha1?.hexToBytes() ?: ByteArray(16)
FileWrapper(group, parent,
it.fileId, it.fileName, md5, sha1, it.fileSize, it.deadTime, it.modifyTime, it.uploadTime, it.uploader
it.fileId, it.fileName, md5, sha1, it.fileSize, it.deadTime, it.modifyTime, it.uploadTime, it.uploader, it.busid
)
}
}
Expand Down

0 comments on commit 3028c30

Please sign in to comment.