Skip to content

Commit

Permalink
add query commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Multivit4min committed Oct 27, 2019
1 parent be5ae80 commit 102ea3e
Show file tree
Hide file tree
Showing 9 changed files with 314 additions and 6 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Changelog

### 2.2.0 - 31.10.2019
+ add clientedit()
+ add clientGetIds()
+ add clientGetDbidFromUid()
+ add clientGetNameFromUid()
+ add clientGetUidFromClid()
+ add clientGetNameFromDbid()
+ add channelClientPermList()
+ add serverGroupsByClientId()
+ add channelFind()
+ add banClient()
+ add createSnapshot()
+ add deploySnapshot()
* rewrote some internal function in order to be parse snapshot commands
Expand Down
111 changes: 109 additions & 2 deletions src/TeamSpeak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ import { Command } from "./transport/Command"

export * from "./types/enum"

/**
* missing Query Commands
* @todo
* channelclientaddperm
* channelclientdelperm
* servergroupautoaddperm
* servergroupautodelperm
* tokenadd
* tokendelete
* tokenlist
* tokenuse
* clientfind
* clientsetserverquerylogin
*/


declare type NodeType = TeamSpeakClient|TeamSpeakChannel|TeamSpeakChannelGroup|TeamSpeakServer|TeamSpeakServerGroup
declare interface NodeConstructable<T> {
new(parent: TeamSpeak, props: QueryResponse): T
Expand Down Expand Up @@ -60,6 +76,9 @@ export interface TeamSpeak {
on(event: "channelcreate", listener: (event: Event.ChannelCreate) => void): this
on(event: "channelmoved", listener: (event: Event.ChannelMove) => void): this
on(event: "channeldelete", listener: (event: Event.ChannelDelete) => void): this

channelClientPermList(cid: number, cldbid: number, permsid: false): Promise<Response.ChannelClientPermListId[]>
channelClientPermList(cid: number, cldbid: number, permsid: true): Promise<Response.ChannelClientPermListSid[]>
}

export class TeamSpeak extends EventEmitter {
Expand Down Expand Up @@ -573,6 +592,15 @@ export class TeamSpeak extends EventEmitter {
}


/**
* displays all server groups the client specified with cldbid is currently residing in
* @param cldbid the client database id to check
*/
serverGroupsByClientId(cldbid: number): Promise<Response.ServerGroupsByClientId[]> {
return this.execute("servergroupsbyclientid", { cldbid }).then(TeamSpeak.toArray)
}


/**
* Adds one or more servergroups to a client.
* Please note that a client cannot be added to default groups or template groups
Expand Down Expand Up @@ -741,6 +769,14 @@ export class TeamSpeak extends EventEmitter {
return this.channelList({ channel_name }).then(([channel]) => channel)
}

/**
* displays a list of channels matching a given name pattern
* @param pattern the channel name pattern to search for
*/
channelFind(pattern: string): Promise<Response.ChannelFind[]> {
return this.execute("channelfind", { pattern })
}


/**
* Displays detailed configuration information about a channel including ID, topic, description, etc.
Expand Down Expand Up @@ -1415,8 +1451,17 @@ export class TeamSpeak extends EventEmitter {
* Adds a new ban rule on the selected virtual server.
* All parameters are optional but at least one of the following must be set: ip, name, uid or mytsid.
*/
ban({ ip, name, uid, mytsid, time, banreason }: Props.BanAdd): Promise<Response.BanAdd> {
return this.execute("banadd", { ip, name, uid, mytsid, time, banreason }).then(TeamSpeak.singleResponse)
ban(properties: Props.BanAdd): Promise<Response.BanAdd> {
return this.execute("banadd", properties).then(TeamSpeak.singleResponse)
}


/**
* Bans the client specified with ID clid from the server.
* Please note that this will create two separate ban rules for the targeted clients IP address and his unique identifier.
*/
banClient(properties: Props.BanClient): Promise<Response.BanAdd> {
return this.execute("banclient", properties).then(TeamSpeak.singleResponse)
}


Expand Down Expand Up @@ -1466,6 +1511,54 @@ export class TeamSpeak extends EventEmitter {
return this.execute("gm", { msg })
}

/**
* displays all client IDs matching the unique identifier specified by cluid
* @param cluid the unique id to search for
*/
clientGetIds(cluid: string): Promise<Response.ClientGetIds[]> {
return this.execute("clientgetids", { cluid }).then(TeamSpeak.toArray)
}

/**
* displays the database ID matching the unique identifier specified by cluid
* @param cluid the unique id to search for
*/
clientGetDbidFromUid(cluid: string): Promise<Response.ClientGetDbidFromUid> {
return this.execute("clientgetdbidfromuid", { cluid }).then(TeamSpeak.singleResponse)
}

/**
* displays the database ID and nickname matching the unique identifier specified by cluid
* @param cluid the unique id to search for
*/
clientGetNameFromUid(cluid: string): Promise<Response.ClientGetNameFromUid> {
return this.execute("clientgetnamefromuid", { cluid }).then(TeamSpeak.singleResponse)
}

/**
* displays the database ID and nickname matching the unique identifier specified by cluid
* @param clid the client id to search from
*/
clientGetUidFromClid(clid: number): Promise<Response.ClientGetUidFromClid> {
return this.execute("clientgetuidfromclid", { clid }).then(TeamSpeak.singleResponse)
}

/**
* displays the unique identifier and nickname matching the database ID specified by cldbid
* @param cldbid client database it to search from
*/
clientGetNameFromDbid(cldbid: number): Promise<Response.ClientGetNameFromDbid> {
return this.execute("clientgetnamefromdbid", { cldbid }).then(TeamSpeak.singleResponse)
}

/**
* edits a specific client
* @param clid the client id to modify
* @param properties the properties to change
*/
clientEdit(clid: number, properties: Props.ClientEdit) {
return this.execute("clientedit", { clid, ...properties })
}

/**
* Displays a list of client database IDs matching a given pattern.
Expand Down Expand Up @@ -1508,6 +1601,16 @@ export class TeamSpeak extends EventEmitter {
.then(servers => servers.map(s => this.servers[s.virtualserver_id!]))
}

/**
* displays a list of permissions defined for a client in a specific channel
* @param cid the channel to search from
* @param cldbid the client database id to get permissions from
* @param permsid wether to retrieve permission names instead of ids
*/
channelClientPermList(cid: number, cldbid: number, permsid: boolean = false) {
return this.execute("channelclientpermlist", { cid, cldbid }, [permsid ? "-permsid" : null])
}


/**
* Displays a list of channel groups available. Depending on your permissions, the output may also contain template groups.
Expand Down Expand Up @@ -1557,6 +1660,10 @@ export class TeamSpeak extends EventEmitter {
.then(clients => clients.map(c => this.clients[String(c.clid)]))
}

ftList(): Promise<Response.FTList[]> {
return this.execute("ftlist")
}


/**
* Displays a list of files and directories stored in the specified channels file repository.
Expand Down
11 changes: 9 additions & 2 deletions src/node/Client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Abstract } from "./Abstract"
import { TeamSpeak } from "../TeamSpeak"
import { ClientList } from "../types/ResponseTypes"
import { ClientDBEdit } from "../types/PropertyTypes"
import { ClientDBEdit, ClientEdit } from "../types/PropertyTypes"
import { ClientType } from "../types/enum"
import { FileTransfer } from "../transport/FileTransfer"

export class TeamSpeakClient extends Abstract {

Expand Down Expand Up @@ -222,6 +221,14 @@ export class TeamSpeakClient extends Abstract {
return super.getParent().clientDelServerGroup(this.databaseId, sgid)
}

/**
* edits the client
* @param properties the properties to change
*/
edit(properties: ClientEdit) {
return this.getParent().clientEdit(this.clid, properties)
}

/**
* Changes a clients settings using given properties.
* @param properties the properties which should be modified
Expand Down
6 changes: 6 additions & 0 deletions src/transport/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,12 @@ export namespace Command {
size: Command.parseNumber,
clientftfid: Command.parseNumber,
serverftfid: Command.parseNumber,
current_speed: Command.parseNumber,
average_speed: Command.parseNumber,
runtime: Command.parseNumber,
sizedone: Command.parseNumber,
sender: Command.parseNumber,
status: Command.parseNumber,
ftkey: Command.parseString,
port: Command.parseNumber,
proto: Command.parseNumber,
Expand Down
18 changes: 16 additions & 2 deletions src/types/PropertyTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ export declare type ClientUpdate = {
}

export declare type ClientDBEdit = {
//cldbid: number
client_description: string
client_description: string
}

export declare type ClientEdit = {
client_description?: string
client_is_talker?: number
}

export declare type ServerEdit = {
Expand Down Expand Up @@ -123,6 +127,16 @@ export declare type BanAdd = {
banreason: string
}

export declare type BanClient = {
clid: number
/** myteamspeak id, use "empty" to ban all clients without connected myteamspeak */
mytsid?: string
/** bantime in seconds, if left empty it will result in a permaban */
time?: number
/** ban reason */
banreason: string
}

export declare type TransferUpload = {
/** arbitary id to identify the transfer */
clientftfid?: number
Expand Down
7 changes: 7 additions & 0 deletions src/types/QueryResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ export declare interface QueryResponseTypes {
size: number,
clientftfid: number,
serverftfid: number,
current_speed: number,
average_speed: number,
runtime: number,
sizedone: number,
sender: number,
status: number
ftkey: string,
port: number,
proto: number,
Expand Down Expand Up @@ -331,4 +337,5 @@ export declare interface QueryResponseTypes {
count: number
salt: string
snapshot: string

}
76 changes: 76 additions & 0 deletions src/types/ResponseTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TeamSpeakServer } from "../node/Server"
import { stringLiteral } from "@babel/types"

export declare interface QueryErrorMessage {
id: number
Expand Down Expand Up @@ -77,6 +78,32 @@ export declare interface ServerGroupList {
n_member_removep: number
}

export declare interface ServerGroupsByClientId {
name: string
sgid: number
cldbid: number
}


export declare interface ChannelClientPermListId {
cid: number
cldbid: number
permid: number
permvalue: number
permnegated: number
permskip: number
}


export declare interface ChannelClientPermListSid {
cid: number
cldbid: number
permsid: string
permvalue: number
permnegated: number
permskip: number
}


export declare interface ChannelGroupList {
cgid: number
Expand Down Expand Up @@ -302,6 +329,11 @@ export declare interface PermList {
permskip: number
}

export declare interface ChannelFind {
cid: number
channel_name: string
}

export declare interface ChannelInfo {
pid: number
channel_name: string
Expand Down Expand Up @@ -334,6 +366,35 @@ export declare interface ChannelInfo {
seconds_empty: number
}

export declare interface ClientGetIds {
cluid: string
clid: number
name: string
}

export declare interface ClientGetDbidFromUid {
cluid: string
cldbid: number
}

export declare interface ClientGetNameFromUid {
cluid: string
cldbid: number
name: string
}

export declare interface ClientGetUidFromClid {
clid: number
cluid: string
nickname: string
}

export declare interface ClientGetNameFromDbid {
cluid: string
cldbid: number
name: string
}

export declare interface ClientInfo {
cid: number
client_idle_time: number
Expand Down Expand Up @@ -552,6 +613,21 @@ export declare interface ClientDBFind {
cldbid: number
}

export declare interface FTList {
clid: number
path: string
name: string
size: number
sizedone: number
clientftfid: number
serverftfid: number
sender: number
status: number
current_speed: number
average_speed: number
runtime: number
}

export declare interface FTGetFileList {
cid: number
path: string
Expand Down
7 changes: 7 additions & 0 deletions tests/Client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ describe("TeamSpeakClient", () => {
expect(mockExecute).toHaveBeenCalledWith("clientinfo", { clid: raw.clid })
})

it("should verify execute parameters of #edit()", async () => {
mockExecute.mockResolvedValue(null)
await client.edit({ client_is_talker: 0 })
expect(mockExecute).toHaveBeenCalledTimes(1)
expect(mockExecute).toHaveBeenCalledWith("clientedit", { clid: raw.clid, client_is_talker: 0 })
})

it("should verify execute parameters of #getDBInfo()", async () => {
mockExecute.mockResolvedValue(null)
await client.getDBInfo()
Expand Down
Loading

0 comments on commit 102ea3e

Please sign in to comment.