revbot.js 0.0.5 → 0.0.6

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/dist/index.d.mts CHANGED
@@ -1437,10 +1437,17 @@ declare class MessageEmbed {
1437
1437
  /**
1438
1438
  * Sets the media (e.g., image or video) of the embed.
1439
1439
  *
1440
- * @param {string} media - The media URL to set.
1440
+ * @param {Readable | string | File} media - The media URL, File or Stream to set.
1441
1441
  * @returns {this} The updated `MessageEmbed` instance.
1442
1442
  */
1443
- setMedia(media: string): this;
1443
+ setMedia(media: Readable | string | File$1): this;
1444
+ /**
1445
+ *
1446
+ * @param client The client instance used to send the embed.
1447
+ * @returns SendableEmbed
1448
+ * Converts the embed to a JSON object that can be sent to the API, including media handling.
1449
+ */
1450
+ toJSONWithMedia(client: client): Promise<SendableEmbed>;
1444
1451
  /**
1445
1452
  * Converts the embed to a JSON object that can be sent to the API.
1446
1453
  *
package/dist/index.d.ts CHANGED
@@ -1437,10 +1437,17 @@ declare class MessageEmbed {
1437
1437
  /**
1438
1438
  * Sets the media (e.g., image or video) of the embed.
1439
1439
  *
1440
- * @param {string} media - The media URL to set.
1440
+ * @param {Readable | string | File} media - The media URL, File or Stream to set.
1441
1441
  * @returns {this} The updated `MessageEmbed` instance.
1442
1442
  */
1443
- setMedia(media: string): this;
1443
+ setMedia(media: Readable | string | File$1): this;
1444
+ /**
1445
+ *
1446
+ * @param client The client instance used to send the embed.
1447
+ * @returns SendableEmbed
1448
+ * Converts the embed to a JSON object that can be sent to the API, including media handling.
1449
+ */
1450
+ toJSONWithMedia(client: client): Promise<SendableEmbed>;
1444
1451
  /**
1445
1452
  * Converts the embed to a JSON object that can be sent to the API.
1446
1453
  *
package/dist/index.js CHANGED
@@ -1715,6 +1715,10 @@ var Mentions = class {
1715
1715
  };
1716
1716
 
1717
1717
  // src/struct/messageEmbed.ts
1718
+ var import_stream = require("stream");
1719
+ var import_axios = __toESM(require("axios"));
1720
+ var import_form_data = __toESM(require("form-data"));
1721
+ var import_node_buffer = require("buffer");
1718
1722
  var _url, _title, _description, _icon_url, _color, _media;
1719
1723
  var MessageEmbed = class {
1720
1724
  constructor() {
@@ -1778,26 +1782,68 @@ var MessageEmbed = class {
1778
1782
  /**
1779
1783
  * Sets the media (e.g., image or video) of the embed.
1780
1784
  *
1781
- * @param {string} media - The media URL to set.
1785
+ * @param {Readable | string | File} media - The media URL, File or Stream to set.
1782
1786
  * @returns {this} The updated `MessageEmbed` instance.
1783
1787
  */
1784
1788
  setMedia(media) {
1785
1789
  __privateSet(this, _media, media);
1786
1790
  return this;
1787
1791
  }
1792
+ /**
1793
+ *
1794
+ * @param client The client instance used to send the embed.
1795
+ * @returns SendableEmbed
1796
+ * Converts the embed to a JSON object that can be sent to the API, including media handling.
1797
+ */
1798
+ toJSONWithMedia(client3) {
1799
+ return __async(this, null, function* () {
1800
+ const embed = {
1801
+ title: __privateGet(this, _title),
1802
+ icon_url: __privateGet(this, _icon_url),
1803
+ colour: __privateGet(this, _color),
1804
+ description: __privateGet(this, _description),
1805
+ url: __privateGet(this, _url)
1806
+ };
1807
+ if (__privateGet(this, _media)) {
1808
+ let att = __privateGet(this, _media);
1809
+ const data = new import_form_data.default();
1810
+ if (typeof att === "string") {
1811
+ const readableStream = yield import_axios.default.get(att, {
1812
+ responseType: "stream"
1813
+ });
1814
+ data.append("file", readableStream.data, {
1815
+ filename: att.split("/").pop()
1816
+ });
1817
+ }
1818
+ if (att instanceof import_stream.Readable) {
1819
+ data.append("file", att);
1820
+ }
1821
+ if (att instanceof import_node_buffer.File) {
1822
+ const buffer = Buffer.from(yield att.arrayBuffer());
1823
+ data.append("file", buffer, { filename: att.name });
1824
+ }
1825
+ yield client3.cdn.post("/attachments", data).then((attachment) => {
1826
+ const { id } = attachment;
1827
+ embed.media = id;
1828
+ });
1829
+ }
1830
+ return embed;
1831
+ });
1832
+ }
1788
1833
  /**
1789
1834
  * Converts the embed to a JSON object that can be sent to the API.
1790
1835
  *
1791
1836
  * @returns {SendableEmbed} The JSON representation of the embed.
1792
1837
  */
1793
1838
  toJSON() {
1839
+ var _a;
1794
1840
  return {
1795
1841
  title: __privateGet(this, _title),
1796
- description: __privateGet(this, _description),
1797
- url: __privateGet(this, _url),
1798
1842
  icon_url: __privateGet(this, _icon_url),
1799
1843
  colour: __privateGet(this, _color),
1800
- media: __privateGet(this, _media)
1844
+ description: __privateGet(this, _description),
1845
+ url: __privateGet(this, _url),
1846
+ media: (_a = __privateGet(this, _media)) == null ? void 0 : _a.toString()
1801
1847
  };
1802
1848
  }
1803
1849
  };
@@ -2566,10 +2612,10 @@ var UserManager = class extends BaseManager {
2566
2612
  };
2567
2613
 
2568
2614
  // src/managers/messageManager.ts
2569
- var import_node_buffer = require("buffer");
2570
- var import_stream = require("stream");
2571
- var import_form_data = __toESM(require("form-data"));
2572
- var import_axios = __toESM(require("axios"));
2615
+ var import_node_buffer2 = require("buffer");
2616
+ var import_stream2 = require("stream");
2617
+ var import_form_data2 = __toESM(require("form-data"));
2618
+ var import_axios2 = __toESM(require("axios"));
2573
2619
  var MessageManager = class extends BaseManager {
2574
2620
  constructor(channel) {
2575
2621
  super(channel.client);
@@ -2592,19 +2638,19 @@ var MessageManager = class extends BaseManager {
2592
2638
  let embeds = [];
2593
2639
  if (Array.isArray(content.attachments)) {
2594
2640
  const promises = content.attachments.map((att) => __async(this, null, function* () {
2595
- const data = new import_form_data.default();
2641
+ const data = new import_form_data2.default();
2596
2642
  if (typeof att === "string") {
2597
- const readableStream = yield import_axios.default.get(att, {
2643
+ const readableStream = yield import_axios2.default.get(att, {
2598
2644
  responseType: "stream"
2599
2645
  });
2600
2646
  data.append("file", readableStream.data, {
2601
2647
  filename: att.split("/").pop()
2602
2648
  });
2603
2649
  }
2604
- if (att instanceof import_stream.Readable) {
2650
+ if (att instanceof import_stream2.Readable) {
2605
2651
  data.append("file", att);
2606
2652
  }
2607
- if (att instanceof import_node_buffer.File) {
2653
+ if (att instanceof import_node_buffer2.File) {
2608
2654
  const buffer = Buffer.from(yield att.arrayBuffer());
2609
2655
  data.append("file", buffer, { filename: att.name });
2610
2656
  }
@@ -2616,7 +2662,11 @@ var MessageManager = class extends BaseManager {
2616
2662
  yield Promise.all(promises);
2617
2663
  }
2618
2664
  if (Array.isArray(content.embeds)) {
2619
- content.embeds.map((embed) => embeds.push(embed.toJSON()));
2665
+ const promises = content.embeds.map((embed) => __async(this, null, function* () {
2666
+ const json = yield embed.toJSONWithMedia(this.client);
2667
+ embeds.push(json);
2668
+ }));
2669
+ yield Promise.all(promises);
2620
2670
  }
2621
2671
  const resp = yield this.client.api.post(
2622
2672
  `/channels/${this.channel.id}/messages`,
@@ -3038,10 +3088,10 @@ var ServerMemberManager = class extends BaseManager {
3038
3088
  var import_node_events = require("events");
3039
3089
 
3040
3090
  // src/rest/restClient.ts
3041
- var import_axios2 = __toESM(require("axios"));
3091
+ var import_axios3 = __toESM(require("axios"));
3042
3092
 
3043
3093
  // package.json
3044
- var version = "0.0.4";
3094
+ var version = "0.0.6";
3045
3095
 
3046
3096
  // src/rest/restClient.ts
3047
3097
  var RestClient = class {
@@ -3070,7 +3120,7 @@ var RestClient = class {
3070
3120
  "User-Agent": `RevBot.js/${version}`
3071
3121
  }
3072
3122
  };
3073
- const response = yield (0, import_axios2.default)(config);
3123
+ const response = yield (0, import_axios3.default)(config);
3074
3124
  return response.data;
3075
3125
  } catch (error) {
3076
3126
  console.error("API call failed:", error);
@@ -3139,7 +3189,7 @@ var RestClient = class {
3139
3189
  };
3140
3190
 
3141
3191
  // src/rest/CDNClient.ts
3142
- var import_axios3 = __toESM(require("axios"));
3192
+ var import_axios4 = __toESM(require("axios"));
3143
3193
  var CDNClient = class {
3144
3194
  constructor(client3) {
3145
3195
  this.client = client3;
@@ -3168,7 +3218,7 @@ var CDNClient = class {
3168
3218
  "User-Agent": `RevBot.js/${version}`
3169
3219
  }, data.getHeaders())
3170
3220
  };
3171
- const response = yield (0, import_axios3.default)(config);
3221
+ const response = yield (0, import_axios4.default)(config);
3172
3222
  return response.data;
3173
3223
  } catch (error) {
3174
3224
  console.error("API call failed:", error);
package/dist/index.mjs CHANGED
@@ -1642,6 +1642,10 @@ var Mentions = class {
1642
1642
  };
1643
1643
 
1644
1644
  // src/struct/messageEmbed.ts
1645
+ import { Readable } from "stream";
1646
+ import axios from "axios";
1647
+ import FormData from "form-data";
1648
+ import { File } from "node:buffer";
1645
1649
  var _url, _title, _description, _icon_url, _color, _media;
1646
1650
  var MessageEmbed = class {
1647
1651
  constructor() {
@@ -1705,26 +1709,68 @@ var MessageEmbed = class {
1705
1709
  /**
1706
1710
  * Sets the media (e.g., image or video) of the embed.
1707
1711
  *
1708
- * @param {string} media - The media URL to set.
1712
+ * @param {Readable | string | File} media - The media URL, File or Stream to set.
1709
1713
  * @returns {this} The updated `MessageEmbed` instance.
1710
1714
  */
1711
1715
  setMedia(media) {
1712
1716
  __privateSet(this, _media, media);
1713
1717
  return this;
1714
1718
  }
1719
+ /**
1720
+ *
1721
+ * @param client The client instance used to send the embed.
1722
+ * @returns SendableEmbed
1723
+ * Converts the embed to a JSON object that can be sent to the API, including media handling.
1724
+ */
1725
+ toJSONWithMedia(client3) {
1726
+ return __async(this, null, function* () {
1727
+ const embed = {
1728
+ title: __privateGet(this, _title),
1729
+ icon_url: __privateGet(this, _icon_url),
1730
+ colour: __privateGet(this, _color),
1731
+ description: __privateGet(this, _description),
1732
+ url: __privateGet(this, _url)
1733
+ };
1734
+ if (__privateGet(this, _media)) {
1735
+ let att = __privateGet(this, _media);
1736
+ const data = new FormData();
1737
+ if (typeof att === "string") {
1738
+ const readableStream = yield axios.get(att, {
1739
+ responseType: "stream"
1740
+ });
1741
+ data.append("file", readableStream.data, {
1742
+ filename: att.split("/").pop()
1743
+ });
1744
+ }
1745
+ if (att instanceof Readable) {
1746
+ data.append("file", att);
1747
+ }
1748
+ if (att instanceof File) {
1749
+ const buffer = Buffer.from(yield att.arrayBuffer());
1750
+ data.append("file", buffer, { filename: att.name });
1751
+ }
1752
+ yield client3.cdn.post("/attachments", data).then((attachment) => {
1753
+ const { id } = attachment;
1754
+ embed.media = id;
1755
+ });
1756
+ }
1757
+ return embed;
1758
+ });
1759
+ }
1715
1760
  /**
1716
1761
  * Converts the embed to a JSON object that can be sent to the API.
1717
1762
  *
1718
1763
  * @returns {SendableEmbed} The JSON representation of the embed.
1719
1764
  */
1720
1765
  toJSON() {
1766
+ var _a;
1721
1767
  return {
1722
1768
  title: __privateGet(this, _title),
1723
- description: __privateGet(this, _description),
1724
- url: __privateGet(this, _url),
1725
1769
  icon_url: __privateGet(this, _icon_url),
1726
1770
  colour: __privateGet(this, _color),
1727
- media: __privateGet(this, _media)
1771
+ description: __privateGet(this, _description),
1772
+ url: __privateGet(this, _url),
1773
+ media: (_a = __privateGet(this, _media)) == null ? void 0 : _a.toString()
1728
1774
  };
1729
1775
  }
1730
1776
  };
@@ -2493,10 +2539,10 @@ var UserManager = class extends BaseManager {
2493
2539
  };
2494
2540
 
2495
2541
  // src/managers/messageManager.ts
2496
- import { File } from "node:buffer";
2497
- import { Readable } from "stream";
2498
- import FormData from "form-data";
2499
- import axios from "axios";
2542
+ import { File as File2 } from "node:buffer";
2543
+ import { Readable as Readable2 } from "stream";
2544
+ import FormData2 from "form-data";
2545
+ import axios2 from "axios";
2500
2546
  var MessageManager = class extends BaseManager {
2501
2547
  constructor(channel) {
2502
2548
  super(channel.client);
@@ -2519,19 +2565,19 @@ var MessageManager = class extends BaseManager {
2519
2565
  let embeds = [];
2520
2566
  if (Array.isArray(content.attachments)) {
2521
2567
  const promises = content.attachments.map((att) => __async(this, null, function* () {
2522
- const data = new FormData();
2568
+ const data = new FormData2();
2523
2569
  if (typeof att === "string") {
2524
- const readableStream = yield axios.get(att, {
2570
+ const readableStream = yield axios2.get(att, {
2525
2571
  responseType: "stream"
2526
2572
  });
2527
2573
  data.append("file", readableStream.data, {
2528
2574
  filename: att.split("/").pop()
2529
2575
  });
2530
2576
  }
2531
- if (att instanceof Readable) {
2577
+ if (att instanceof Readable2) {
2532
2578
  data.append("file", att);
2533
2579
  }
2534
- if (att instanceof File) {
2580
+ if (att instanceof File2) {
2535
2581
  const buffer = Buffer.from(yield att.arrayBuffer());
2536
2582
  data.append("file", buffer, { filename: att.name });
2537
2583
  }
@@ -2543,7 +2589,11 @@ var MessageManager = class extends BaseManager {
2543
2589
  yield Promise.all(promises);
2544
2590
  }
2545
2591
  if (Array.isArray(content.embeds)) {
2546
- content.embeds.map((embed) => embeds.push(embed.toJSON()));
2592
+ const promises = content.embeds.map((embed) => __async(this, null, function* () {
2593
+ const json = yield embed.toJSONWithMedia(this.client);
2594
+ embeds.push(json);
2595
+ }));
2596
+ yield Promise.all(promises);
2547
2597
  }
2548
2598
  const resp = yield this.client.api.post(
2549
2599
  `/channels/${this.channel.id}/messages`,
@@ -2965,10 +3015,10 @@ var ServerMemberManager = class extends BaseManager {
2965
3015
  import { EventEmitter } from "node:events";
2966
3016
 
2967
3017
  // src/rest/restClient.ts
2968
- import axios2 from "axios";
3018
+ import axios3 from "axios";
2969
3019
 
2970
3020
  // package.json
2971
- var version = "0.0.4";
3021
+ var version = "0.0.6";
2972
3022
 
2973
3023
  // src/rest/restClient.ts
2974
3024
  var RestClient = class {
@@ -2997,7 +3047,7 @@ var RestClient = class {
2997
3047
  "User-Agent": `RevBot.js/${version}`
2998
3048
  }
2999
3049
  };
3000
- const response = yield axios2(config);
3050
+ const response = yield axios3(config);
3001
3051
  return response.data;
3002
3052
  } catch (error) {
3003
3053
  console.error("API call failed:", error);
@@ -3066,7 +3116,7 @@ var RestClient = class {
3066
3116
  };
3067
3117
 
3068
3118
  // src/rest/CDNClient.ts
3069
- import axios3 from "axios";
3119
+ import axios4 from "axios";
3070
3120
  var CDNClient = class {
3071
3121
  constructor(client3) {
3072
3122
  this.client = client3;
@@ -3095,7 +3145,7 @@ var CDNClient = class {
3095
3145
  "User-Agent": `RevBot.js/${version}`
3096
3146
  }, data.getHeaders())
3097
3147
  };
3098
- const response = yield axios3(config);
3148
+ const response = yield axios4(config);
3099
3149
  return response.data;
3100
3150
  } catch (error) {
3101
3151
  console.error("API call failed:", error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revbot.js",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "A Revolt bot client used to interact with the revolt api for Node.js, written in TypeScript.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",