mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
optimize
This commit is contained in:
parent
a95ae44614
commit
1e35ffd7e6
@ -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
|
||||||
|
}
|
||||||
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
@ -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> {
|
||||||
|
@ -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()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -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> {
|
||||||
|
@ -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> {
|
||||||
|
@ -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> {
|
||||||
|
@ -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> {
|
||||||
|
@ -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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user