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

Commit

Permalink
0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
CodePwn2021 committed Oct 1, 2022
1 parent 8d96062 commit b65592c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
25 changes: 22 additions & 3 deletions lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ export class OmegaClient extends EventEmitter {
}

/**
* 获取一个玩家对象
* @function getPlayer
* 使用玩家昵称获取一个玩家对象
* @function getPlayerByName
* @param {string} playerName 玩家昵称
* @returns {Player}
*/
async getPlayer(playerName: string): Promise<Player> {
async getPlayerByName(playerName: string): Promise<Player> {
const playerListPacket = await this.sendPacket('get_players_list', {});
let targetIndex: number = 0;
const isPlayerExists: boolean = playerListPacket.data.some((value: any, index: number) => {
Expand All @@ -193,6 +193,25 @@ export class OmegaClient extends EventEmitter {
throw Error('Player NOT exists!!!');
}

/**
* 使用UUID获取一个玩家对象
* @function getPlayerByUUID
* @param {string} UUID 玩家UUID
* @returns {Player}
*/
async getPlayerByUUID(UUID: string): Promise<Player> {
const playerListPacket = await this.sendPacket('get_players_list', {});
let targetIndex: number = 0;
const isPlayerExists: boolean = playerListPacket.data.some((value: any, index: number) => {
targetIndex = index;
return UUID === value.uuid;
});
if (isPlayerExists) {
return new Player(this, playerListPacket.data[targetIndex]);
}
throw Error('Player NOT exists!!!');
}

/**
* 发送QQ信息(会调用群服互通,若未开启群服互通则会导致不可预料的异常)
* @function sendQQMsg
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "light-omega",
"author": "codepwn",
"description": "Omega ws client in FastBuilder.",
"version": "0.2.0",
"publish_time": "2022-8-29",
"version": "0.2.1",
"publish_time": "2022-10-01",
"main": "./lib/index.js",
"typings": "./lib/index.d.ts",
"repository": "https://github.com/CodePwn2021/light-omega",
Expand Down
2 changes: 1 addition & 1 deletion test/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function init() {
// 在这里随便干点什么
const res = await omg.sendPacket('get_players_list', {});
console.log(JSON.stringify(res));
const player = await omg.getPlayer(omg.bot_name);
const player = await omg.getPlayerByUUID(omg.bot_name);
console.log(player);
const echo = await omg.sendPacket('echo', {
message: 'hello, light-omega!'
Expand Down

0 comments on commit b65592c

Please sign in to comment.