This commit is contained in:
idranme 2024-09-24 14:18:44 +08:00
parent a95ae44614
commit 1e35ffd7e6
No known key found for this signature in database
GPG Key ID: 926F7B5B668E495F
10 changed files with 23 additions and 16 deletions

View File

@ -38,3 +38,10 @@ export function mergeNewProperties(newObj: Dict, oldObj: Dict) {
export function filterNullable<T>(array: T[]) { export function filterNullable<T>(array: T[]) {
return array.filter(e => !isNullable(e)) as NonNullable<T>[] return array.filter(e => !isNullable(e)) as NonNullable<T>[]
} }
export function parseBool(value: string) {
if (['', 'true', '1'].includes(value)) {
return true
}
return false
}

View File

@ -30,7 +30,7 @@ export default class Store extends Service {
constructor(protected ctx: Context) { constructor(protected ctx: Context) {
super(ctx, 'store', true) super(ctx, 'store', true)
this.cache = new LimitedHashTable<string, number>(1000) this.cache = new LimitedHashTable(1000)
this.initDatabase() this.initDatabase()
} }

View File

@ -156,12 +156,7 @@ export class NTQQGroupApi extends Service {
} }
} }
async kickMember( async kickMember(groupCode: string, kickUids: string[], refuseForever = false, kickReason = '') {
groupCode: string,
kickUids: string[],
refuseForever = false,
kickReason = '',
) {
const session = getSession() const session = getSession()
if (session) { if (session) {
return session.getGroupService().kickMember(groupCode, kickUids, refuseForever, kickReason) return session.getGroupService().kickMember(groupCode, kickUids, refuseForever, kickReason)

View File

@ -4,7 +4,7 @@ import { ActionName } from '../types'
import { ChatType } from '@/ntqqapi/types' import { ChatType } from '@/ntqqapi/types'
import { OB11Entities } from '../../entities' import { OB11Entities } from '../../entities'
import { RawMessage } from '@/ntqqapi/types' import { RawMessage } from '@/ntqqapi/types'
import { filterNullable } from '@/common/utils/misc' import { filterNullable, parseBool } from '@/common/utils/misc'
interface Payload { interface Payload {
group_id: number | string group_id: number | string
@ -23,7 +23,7 @@ export class GetGroupMsgHistory extends BaseAction<Payload, Response> {
group_id: Schema.union([Number, String]).required(), group_id: Schema.union([Number, String]).required(),
message_seq: Schema.union([Number, String]), message_seq: Schema.union([Number, String]),
count: Schema.union([Number, String]).default(20), count: Schema.union([Number, String]).default(20),
reverseOrder: Schema.boolean().default(false), reverseOrder: Schema.union([Boolean, Schema.transform(String, parseBool)]).default(false)
}) })
protected async _handle(payload: Payload): Promise<Response> { protected async _handle(payload: Payload): Promise<Response> {

View File

@ -1,6 +1,7 @@
import { BaseAction, Schema } from '../BaseAction' import { BaseAction, Schema } from '../BaseAction'
import { GroupRequestOperateTypes } from '@/ntqqapi/types' import { GroupRequestOperateTypes } from '@/ntqqapi/types'
import { ActionName } from '../types' import { ActionName } from '../types'
import { parseBool } from '@/common/utils/misc'
interface Payload { interface Payload {
flag: string flag: string
@ -12,7 +13,7 @@ export default class SetGroupAddRequest extends BaseAction<Payload, null> {
actionName = ActionName.SetGroupAddRequest actionName = ActionName.SetGroupAddRequest
payloadSchema = Schema.object({ payloadSchema = Schema.object({
flag: Schema.string().required(), flag: Schema.string().required(),
approve: Schema.boolean().default(true), approve: Schema.union([Boolean, Schema.transform(String, parseBool)]).default(true),
reason: Schema.string() reason: Schema.string()
}) })

View File

@ -1,6 +1,7 @@
import { BaseAction, Schema } from '../BaseAction' import { BaseAction, Schema } from '../BaseAction'
import { GroupMemberRole } from '@/ntqqapi/types' import { GroupMemberRole } from '@/ntqqapi/types'
import { ActionName } from '../types' import { ActionName } from '../types'
import { parseBool } from '@/common/utils/misc'
interface Payload { interface Payload {
group_id: number | string group_id: number | string
@ -13,7 +14,7 @@ export default class SetGroupAdmin extends BaseAction<Payload, null> {
payloadSchema = Schema.object({ payloadSchema = Schema.object({
group_id: Schema.union([Number, String]).required(), group_id: Schema.union([Number, String]).required(),
user_id: Schema.union([Number, String]).required(), user_id: Schema.union([Number, String]).required(),
enable: Schema.boolean().default(true) enable: Schema.union([Boolean, Schema.transform(String, parseBool)]).default(true)
}) })
protected async _handle(payload: Payload): Promise<null> { protected async _handle(payload: Payload): Promise<null> {

View File

@ -1,5 +1,6 @@
import { BaseAction, Schema } from '../BaseAction' import { BaseAction, Schema } from '../BaseAction'
import { ActionName } from '../types' import { ActionName } from '../types'
import { parseBool } from '@/common/utils/misc'
interface Payload { interface Payload {
group_id: number | string group_id: number | string
@ -12,7 +13,7 @@ export default class SetGroupKick extends BaseAction<Payload, null> {
payloadSchema = Schema.object({ payloadSchema = Schema.object({
group_id: Schema.union([Number, String]).required(), group_id: Schema.union([Number, String]).required(),
user_id: Schema.union([Number, String]).required(), user_id: Schema.union([Number, String]).required(),
reject_add_request: Schema.boolean().default(false) reject_add_request: Schema.union([Boolean, Schema.transform(String, parseBool)]).default(false)
}) })
protected async _handle(payload: Payload): Promise<null> { protected async _handle(payload: Payload): Promise<null> {

View File

@ -1,5 +1,6 @@
import { BaseAction, Schema } from '../BaseAction' import { BaseAction, Schema } from '../BaseAction'
import { ActionName } from '../types' import { ActionName } from '../types'
import { parseBool } from '@/common/utils/misc'
interface Payload { interface Payload {
group_id: number | string group_id: number | string
@ -10,7 +11,7 @@ export default class SetGroupWholeBan extends BaseAction<Payload, null> {
actionName = ActionName.SetGroupWholeBan actionName = ActionName.SetGroupWholeBan
payloadSchema = Schema.object({ payloadSchema = Schema.object({
group_id: Schema.union([Number, String]).required(), group_id: Schema.union([Number, String]).required(),
enable: Schema.boolean().default(true) enable: Schema.union([Boolean, Schema.transform(String, parseBool)]).default(true)
}) })
protected async _handle(payload: Payload): Promise<null> { protected async _handle(payload: Payload): Promise<null> {

View File

@ -3,7 +3,7 @@ import { OB11Message } from '@/onebot11/types'
import { ActionName } from '../types' import { ActionName } from '../types'
import { ChatType, RawMessage } from '@/ntqqapi/types' import { ChatType, RawMessage } from '@/ntqqapi/types'
import { OB11Entities } from '@/onebot11/entities' import { OB11Entities } from '@/onebot11/entities'
import { filterNullable } from '@/common/utils/misc' import { filterNullable, parseBool } from '@/common/utils/misc'
interface Payload { interface Payload {
user_id: number | string user_id: number | string
@ -24,7 +24,7 @@ export class GetFriendMsgHistory extends BaseAction<Payload, Response> {
message_seq: Schema.union([Number, String]), message_seq: Schema.union([Number, String]),
message_id: Schema.union([Number, String]), message_id: Schema.union([Number, String]),
count: Schema.union([Number, String]).default(20), count: Schema.union([Number, String]).default(20),
reverseOrder: Schema.boolean().default(false) reverseOrder: Schema.union([Boolean, Schema.transform(String, parseBool)]).default(false)
}) })
async _handle(payload: Payload): Promise<Response> { async _handle(payload: Payload): Promise<Response> {

View File

@ -3,6 +3,7 @@ import { OB11User } from '../../types'
import { OB11Entities } from '../../entities' import { OB11Entities } from '../../entities'
import { ActionName } from '../types' import { ActionName } from '../types'
import { getBuildVersion } from '@/common/utils' import { getBuildVersion } from '@/common/utils'
import { parseBool } from '@/common/utils/misc'
interface Payload { interface Payload {
no_cache: boolean no_cache: boolean
@ -11,7 +12,7 @@ interface Payload {
export class GetFriendList extends BaseAction<Payload, OB11User[]> { export class GetFriendList extends BaseAction<Payload, OB11User[]> {
actionName = ActionName.GetFriendList actionName = ActionName.GetFriendList
payloadSchema = Schema.object({ payloadSchema = Schema.object({
no_cache: Schema.boolean().default(false) no_cache: Schema.union([Boolean, Schema.transform(String, parseBool)]).default(false)
}) })
protected async _handle(payload: Payload) { protected async _handle(payload: Payload) {