magmastream 2.10.2-dev.3 → 2.10.2-dev.4

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.
@@ -169,7 +169,6 @@ export declare class Manager extends EventEmitter {
169
169
  * @param string - The string to escape.
170
170
  * @returns The escaped string.
171
171
  */
172
- private escapeRegExp;
173
172
  /**
174
173
  * Checks if the given data is a voice update.
175
174
  * @param data The data to check.
@@ -16,6 +16,11 @@ const Enums_1 = require("./Enums");
16
16
  const package_json_1 = require("../../package.json");
17
17
  const MagmastreamError_1 = require("./MagmastreamError");
18
18
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
19
+ function escapeRegExp(value) {
20
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
21
+ }
22
+ const YOUTUBE_URL_PATTERN = /(youtube\.com|youtu\.be)/;
23
+ const BLOCKED_WORDS_PATTERN = new RegExp(`\\b(${blockedWords_1.blockedWords.map(escapeRegExp).join("|")})\\b`, "gi");
19
24
  /**
20
25
  * The main hub for interacting with Lavalink and using Magmastream.
21
26
  */
@@ -258,7 +263,7 @@ class Manager extends events_1.EventEmitter {
258
263
  }
259
264
  if (this.options.normalizeYouTubeTitles && "tracks" in result) {
260
265
  const processTrack = (track) => {
261
- if (!/(youtube\.com|youtu\.be)/.test(track.uri))
266
+ if (!YOUTUBE_URL_PATTERN.test(track.uri))
262
267
  return track;
263
268
  const { cleanTitle, cleanAuthor } = this.parseYouTubeTitle(track.title, track.author);
264
269
  track.title = cleanTitle;
@@ -267,7 +272,7 @@ class Manager extends events_1.EventEmitter {
267
272
  };
268
273
  result.tracks = result.tracks.map(processTrack);
269
274
  if ("playlist" in result && result.playlist) {
270
- result.playlist.tracks = result.playlist.tracks.map(processTrack);
275
+ result.playlist.tracks = result.tracks;
271
276
  }
272
277
  }
273
278
  const summary = "tracks" in result ? result.tracks.map((t) => Object.fromEntries(Object.entries(t).filter(([key]) => key !== "requester"))) : [];
@@ -780,9 +785,7 @@ class Manager extends events_1.EventEmitter {
780
785
  const cleanAuthor = originalAuthor.replace("- Topic", "").trim();
781
786
  title = title.replace("Topic -", "").trim();
782
787
  // Remove blocked words and phrases
783
- const escapedBlockedWords = blockedWords_1.blockedWords.map((word) => this.escapeRegExp(word));
784
- const blockedWordsPattern = new RegExp(`\\b(${escapedBlockedWords.join("|")})\\b`, "gi");
785
- title = title.replace(blockedWordsPattern, "").trim();
788
+ title = title.replace(BLOCKED_WORDS_PATTERN, "").trim();
786
789
  // Remove empty brackets and balance remaining brackets
787
790
  title = title
788
791
  .replace(/[([{]\s*[)\]}]/g, "") // Empty brackets
@@ -847,10 +850,6 @@ class Manager extends events_1.EventEmitter {
847
850
  * @param string - The string to escape.
848
851
  * @returns The escaped string.
849
852
  */
850
- escapeRegExp(string) {
851
- // Replace special regex characters with their escaped counterparts
852
- return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
853
- }
854
853
  /**
855
854
  * Checks if the given data is a voice update.
856
855
  * @param data The data to check.
@@ -1125,7 +1125,7 @@ class Node {
1125
1125
  });
1126
1126
  }
1127
1127
  try {
1128
- await this.rest.put(`/v4/sessions/${this.sessionId}/players/${player.guildId}/sponsorblock/categories`, Utils_1.JSONUtils.safe(segments.map((v) => v.toLowerCase()), 2));
1128
+ await this.rest.put(`/v4/sessions/${this.sessionId}/players/${player.guildId}/sponsorblock/categories`, segments.map((v) => v.toLowerCase()));
1129
1129
  }
1130
1130
  catch (err) {
1131
1131
  throw err instanceof MagmastreamError_1.MagmaStreamError
@@ -104,8 +104,6 @@ class Rest {
104
104
  */
105
105
  async request(method, endpoint, body) {
106
106
  this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[REST] ${method} request to ${endpoint} with body: ${Utils_1.JSONUtils.safe(body, 2)}`);
107
- const controller = new AbortController();
108
- const timeoutHandle = setTimeout(() => controller.abort(), this.node.options.apiRequestTimeoutMs);
109
107
  let response = null;
110
108
  try {
111
109
  response = await (0, undici_1.fetch)(this.url + endpoint, {
@@ -115,11 +113,11 @@ class Rest {
115
113
  Authorization: this.password,
116
114
  },
117
115
  body: body !== undefined ? JSON.stringify(body) : undefined,
118
- signal: controller.signal,
116
+ signal: AbortSignal.timeout(this.node.options.apiRequestTimeoutMs),
119
117
  });
120
118
  }
121
119
  catch (e) {
122
- const isTimeout = e instanceof Error && e.name === "AbortError";
120
+ const isTimeout = e instanceof Error && (e.name === "AbortError" || e.name === "TimeoutError");
123
121
  const message = e instanceof Error ? e.message : "Unknown error";
124
122
  const error = new MagmastreamError_1.MagmaStreamError({
125
123
  code: Enums_1.MagmaStreamErrorCode.REST_REQUEST_FAILED,
@@ -128,9 +126,6 @@ class Rest {
128
126
  this.manager.emit(Enums_1.ManagerEventTypes.NodeError, this.node, error);
129
127
  return null;
130
128
  }
131
- finally {
132
- clearTimeout(timeoutHandle);
133
- }
134
129
  const { status } = response;
135
130
  const data = status !== 204 ? await response.json() : null;
136
131
  if (status >= 200 && status < 300) {
@@ -15,7 +15,7 @@ class DiscordJSManager extends Manager_1.Manager {
15
15
  constructor(client, options) {
16
16
  super(options, true);
17
17
  this.client = client;
18
- const { version: djsVersion } = moduleRequire("discord.js/package.json");
18
+ const { version: djsVersion } = moduleRequire("discord.js");
19
19
  const [major, minor] = djsVersion.split(".").map(Number);
20
20
  if (!this.client.options.intents.has(GUILD_VOICE_STATES_INTENT)) {
21
21
  throw new MagmastreamError_1.MagmaStreamError({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "magmastream",
3
- "version": "2.10.2-dev.3",
3
+ "version": "2.10.2-dev.4",
4
4
  "description": "A user-friendly Lavalink client designed for NodeJS.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -16,8 +16,10 @@
16
16
  "lint": "eslint \"src/**/*.{ts,js}\"",
17
17
  "lint:fix": "eslint --fix \"src/**/*.{ts,js}\"",
18
18
  "ci": "run-s format:check lint build types",
19
- "release:alpha": "npm run format && npm run lint:fix && npm run ci && npm version prerelease --preid=alpha && npm publish --tag alpha && git push && git push --follow-tags",
20
- "release:dev": "npm run format && npm run lint:fix && npm run ci && npm version prerelease --preid=dev && npm publish --tag dev && git push && git push --follow-tags"
19
+ "version:alpha": "node scripts/prerelease-version.cjs alpha",
20
+ "version:dev": "node scripts/prerelease-version.cjs dev",
21
+ "release:alpha": "npm run format && npm run lint:fix && npm run ci && npm run version:alpha && npm publish --tag alpha && git push && git push --follow-tags",
22
+ "release:dev": "npm run format && npm run lint:fix && npm run ci && npm run version:dev && npm publish --tag dev && git push && git push --follow-tags"
21
23
  },
22
24
  "devDependencies": {
23
25
  "@favware/rollup-type-bundler": "^4.0.0",