bancho.js 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,7 +1,23 @@
1
1
  # Pre-release
2
2
 
3
+ ## Version 0.11
4
+
5
+ ### Version 0.11.0
6
+
7
+ - **Add ability to set default gamemode for fetching users from API**
8
+ In order to optimize API calls in your application, you can rely on bancho.js' existing API data.
9
+ The new `gamemode` parameter in the bancho.js config object allows you to specify which gamemode data to receive when fetching an user to save more API calls in certain scenarios.
10
+
11
+ - **BanchoLobby: When updating from an FFA to a team-based mode, reset teams**
12
+ Whenn enabling teams, all players in the lobby are assigned a default team. They're assigned predictably based on their slots.
13
+ bancho.js now applies the same algorithm when changing team mode.
14
+
3
15
  ## Version 0.10
4
16
 
17
+ ### Version 0.10.1
18
+
19
+ - **BanchoLobby: Fix beatmap never being refreshed from API**
20
+
5
21
  ### Version 0.10.0
6
22
 
7
23
  #### Highlights
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![NPM](https://nodei.co/npm/bancho.js.png?compact=true)](https://nodei.co/npm/bancho.js/)
4
4
  [![pipeline status](https://git.cartooncraft.fr/ThePooN/bancho.js/badges/master/pipeline.svg)](https://git.cartooncraft.fr/ThePooN/bancho.js/commits/master)
5
5
 
6
- ## Current release: 0.10.0
6
+ ## Current release: 0.11.0
7
7
 
8
8
  # Introduction
9
9
 
package/index.d.ts CHANGED
@@ -794,7 +794,11 @@ declare module "bancho.js" {
794
794
  /**
795
795
  * osu! API key for API requests (see https://osu.ppy.sh/p/api). WARNING: Multiplayer lobbies won't work without an API key!
796
796
  */
797
- apiKey?: string
797
+ apiKey?: string,
798
+ /**
799
+ * Gamemode id to fetch users with. Defaults to null
800
+ */
801
+ gamemode?: number
798
802
  }
799
803
 
800
804
  interface BanchoClientOptionsWithoutRateLimiter extends BanchoClientBaseOptions {
@@ -58,6 +58,7 @@ class BanchoClient extends EventEmitter {
58
58
  * @prop {string} [apiKey] osu! API key for API requests (see https://osu.ppy.sh/p/api). WARNING: Multiplayer lobbies won't work without an API key!
59
59
  * @prop {RateLimiter} [rateLimiter] Instance of RateLimiter from the `limiter` npm module for outgoing Bancho messages. Default is safe for normal users in private messages (PM and #multiplayer channels), bots are not supposed to send public messages. Can be disabled by setting to `null`.
60
60
  * @prop {boolean} [botAccount=false] Apply bot account rate-limits to the default RateLimiter instance if true (see https://osu.ppy.sh/wiki/en/Bot_account).
61
+ * @prop {number} [gamemode=null] Gamemode id to fetch users with. Defaults to null
61
62
  */
62
63
  const options = {
63
64
  host: "irc.ppy.sh",
@@ -66,6 +67,7 @@ class BanchoClient extends EventEmitter {
66
67
  limiterPrivate: 9,
67
68
  limiterPublic: undefined,
68
69
  botAccount: false,
70
+ gamemode: null,
69
71
  };
70
72
  Object.assign(options, optionsOrUsername);
71
73
  if(options.rateLimiter && options.botAccount)
@@ -90,10 +92,12 @@ class BanchoClient extends EventEmitter {
90
92
  this.password = options.password;
91
93
  this.host = options.host;
92
94
  this.port = options.port;
93
- if(options.apiKey)
95
+ if(options.apiKey) {
94
96
  this.osuApi = new Nodesu.Client(options.apiKey, {
95
97
  parseData: true
96
98
  });
99
+ this.gamemode = options.gamemode;
100
+ }
97
101
  this.rateLimiter = options.rateLimiter;
98
102
  }
99
103
  this.setMaxListeners(50);
@@ -341,7 +345,7 @@ class BanchoClient extends EventEmitter {
341
345
  if(user)
342
346
  resolve(user);
343
347
  else
344
- this.osuApi.user.get(userid, Nodesu.LookupType.id).then((apiUser) => {
348
+ this.osuApi.user.get(userid, this.gamemode, null, Nodesu.LookupType.id).then((apiUser) => {
345
349
  user = this.getUser(apiUser.username);
346
350
  user.updateFromAPI(apiUser);
347
351
  resolve(user);
@@ -27,7 +27,7 @@ class BanchoMessage {
27
27
 
28
28
  /**
29
29
  * The content of this message
30
- * @type {string}
30
+ * @returns {string}
31
31
  */
32
32
  get content() {
33
33
  return this.message;
@@ -35,7 +35,7 @@ class BanchoMessage {
35
35
 
36
36
  /**
37
37
  * Tries to parse this message as an ACTION (/me message).
38
- * @returns {[string]}
38
+ * @returns {string}
39
39
  */
40
40
  getAction() {
41
41
  const action = actionRegex.exec(this.message);
package/lib/BanchoUser.js CHANGED
@@ -78,7 +78,7 @@ class BanchoUser extends EventEmitter {
78
78
  fetchFromAPI() {
79
79
  if(this.banchojs.osuApi) {
80
80
  return new Promise((resolve, reject) => {
81
- this.banchojs.osuApi.user.get(this.ircUsername, null, null, Nodesu.LookupType.string).then((user) => {
81
+ this.banchojs.osuApi.user.get(this.ircUsername, this.banchojs.gamemode, null, Nodesu.LookupType.string).then((user) => {
82
82
  this.updateFromAPI(user);
83
83
  resolve(user);
84
84
  }, reject);
@@ -7,6 +7,7 @@ const BanchoLobbyPlayerStates = require("./Enums/BanchoLobbyPlayerStates");
7
7
  const BanchoLobbyTeams = require("./Enums/BanchoLobbyTeams");
8
8
  const Regexes = require("./BanchoLobbyRegexes");
9
9
  const Teams = require("./Enums/BanchoLobbyTeams");
10
+ const BanchoLobbyTeamModes = require("./Enums/BanchoLobbyTeamModes");
10
11
 
11
12
  /**
12
13
  * Represents a Bancho multiplayer lobby
@@ -138,8 +139,8 @@ class BanchoLobby extends EventEmitter {
138
139
  case "playerChangedBeatmap":
139
140
  case "refereeChangedBeatmap":
140
141
  case "beatmapFromSettings":
141
- this.beatmapId = ret.id;
142
142
  if(ret.id != this.beatmapId) {
143
+ this.beatmapId = ret.id;
143
144
  this.beatmap = null;
144
145
  for(const player of this.slots)
145
146
  if(player != null)
@@ -1081,6 +1082,15 @@ class BanchoLobby extends EventEmitter {
1081
1082
  * @see BanchoLobbyTeamModes
1082
1083
  */
1083
1084
  set teamMode(val) {
1085
+ const teamModes = [BanchoLobbyTeamModes.TeamVs, BanchoLobbyTeamModes.TagTeamVs];
1086
+ if(!teamModes.includes(this.teamMode) && teamModes.includes(val)) {
1087
+ for(let i = 0; i < this.slots.length; i++) {
1088
+ const slot = this.slots[i];
1089
+ if (slot !== null) {
1090
+ slot.team = i % 2 === 0 ? BanchoLobbyTeams.Blue : BanchoLobbyTeams.Red;
1091
+ }
1092
+ }
1093
+ }
1084
1094
  this._setter("teamMode", val);
1085
1095
  }
1086
1096
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bancho.js",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "Interface with Bancho over IRC, made easy and reliable",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",