@imaentity/selfjs 4.0.0 → 4.1.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.
Files changed (4) hide show
  1. package/README.md +12 -10
  2. package/docs.md +1142 -848
  3. package/package.json +1 -1
  4. package/self.js +151 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imaentity/selfjs",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "Breaking Discord's TOS to bot user accounts.",
5
5
  "main": "self.js",
6
6
  "repository": {
package/self.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * @name SelfJS
3
3
  * @description Breaking Discord's TOS to bot user accounts.
4
4
  * @author Entity
5
- * @version 4.0
5
+ * @version 4.1
6
6
  */
7
7
 
8
8
  const EventEmitter = require("events");
@@ -74,7 +74,7 @@ const OPCODES = {
74
74
  // Formats JSON in a way that makes the Discord API
75
75
  // able to accept random unicode characters
76
76
  function unison(jsonData) {
77
- return JSON.Stringify(jsonData)?.replace(
77
+ return JSON.stringify(jsonData)?.replace(
78
78
  /[\u007F-\uFFFF]/g,
79
79
  c => `\\u${c.charCodeAt(0).toString(16).padStart(4, '0')}`
80
80
  );
@@ -576,7 +576,9 @@ class Client extends EventEmitter {
576
576
  * Gets the channels active in the DM list of the user, channels can be both DMs and group chats
577
577
  * @returns {Promise<Object>} The list of channels open in the user's DM list
578
578
  */
579
- getOpenChannels() { return this.#GET({path: "/users/@me/channels"}); }
579
+ getOpenChannels() {
580
+ return this.#GET({path: "/users/@me/channels"});
581
+ }
580
582
 
581
583
  /**
582
584
  * Closes the current session and disconnects from discord
@@ -720,6 +722,152 @@ class Client extends EventEmitter {
720
722
  query: {limit: options.limit, before: options.before}
721
723
  });
722
724
  }
725
+
726
+ /**
727
+ * Creates a group DM with certain members
728
+ * @param {Array<String>} recipients A list of user ids to add to the created group
729
+ * @returns {Promise<Object>} The new channel object after creation
730
+ */
731
+ createGroupDM(recipients) {
732
+ return this.#POST({path: `/users/@me/channels`, body: {recipients}});
733
+ }
734
+
735
+ /**
736
+ * Removes a user from a group dm if the logged in account owns the group
737
+ * @param {Object} options Options specifying which user to remove and from what group
738
+ * @param {String} options.channel_id The id of the group to remove the user from
739
+ * @param {String} options.user_id The id of the user to be removed from the group
740
+ * @returns {Promise<void>} No content returned on success
741
+ */
742
+ removeFromGroup(options) {
743
+ return this.#DELETE({path: `/channels/${options.channel_id}/recipients/${options.user_id}`});
744
+ }
745
+
746
+ /**
747
+ * Adds a user to a group dm if the logged in account is friends with the user
748
+ * @param {Object} options Options specifying which user to add and to what group
749
+ * @param {String} options.channel_id The id of the group to add the user to
750
+ * @param {String} options.user_id The id of the user to be added to the group
751
+ * @returns {Promise<void>} No content returned on success
752
+ */
753
+ addToGroup(options) {
754
+ return this.#PUT({path: `/channels/${options.channel_id}/recipients/${options.user_id}`});
755
+ }
756
+
757
+ /**
758
+ * Transfers ownership of a group to another user if that user is in the group
759
+ * @param {Object} options Options specifying which user to give owner and in what group
760
+ * @param {String} options.channel_id The id of the group to be transfered
761
+ * @param {String} options.user_id The id of the user to given ownership of the group
762
+ * @returns {Promise<Object>} The new channel object after the transfer
763
+ */
764
+ transferGroup(options) {
765
+ return this.#PATCH({
766
+ path: `/channels/${options.channel_id}`,
767
+ body: {owner: options.user_id}
768
+ });
769
+ }
770
+
771
+ /**
772
+ * Leaves a group while optionally not notifying members of that group
773
+ * @param {Object} options Options specifying what group to leave and if the leave should notify
774
+ * @param {String} options.channel_id The id of the group to leave
775
+ * @param {Boolean} [options.silent] If true, the group will not receive a leave notification
776
+ * @returns {Promise<Object>} The new channel object after the group has been left
777
+ */
778
+ leaveGroup(options) {
779
+ return this.#DELETE({
780
+ path: `/channels/${options.channel_id}`,
781
+ query: {silent: options.silent}
782
+ });
783
+ }
784
+
785
+ /**
786
+ * Shows the typing indicator for other users in a certain channel for 10 seconds
787
+ * Calling this again before the indicator expires resets the timer, while sending a message clears the indicator
788
+ * @param {String} channel_id The id of the channel to start typing in
789
+ * @returns {Promise<void>} No content returned on success
790
+ */
791
+ startTyping(channel_id) {
792
+ return this.#POST({path: `/channels/${channel_id}/typing`});
793
+ }
794
+
795
+ /**
796
+ * Pins a message to a certain channel
797
+ * @param {Object} options Specifies the message and channel to pin it in
798
+ * @param {String} options.channel_id The id of the channel to pin the message in
799
+ * @param {String} options.message_id The id of the message to pin in the channel
800
+ * @returns {Promise<void>} No content returned on success
801
+ */
802
+ pinMessage(options) {
803
+ return this.#PUT({path: `/api/v10/channels/${options.channel_id}/pins/${options.message_id}`});
804
+ }
805
+
806
+ /**
807
+ * Unpins a message from a certain channel
808
+ * @param {Object} options Specifies the message and channel to unpin it from
809
+ * @param {String} options.channel_id The id of the channel to unpin the message from
810
+ * @param {String} options.message_id The id of the message to unpin from the channel
811
+ * @returns {Promise<void>} No content returned on success
812
+ */
813
+ unpinMessage(options) {
814
+ return this.#DELETE({path: `/api/v10/channels/${options.channel_id}/pins/${options.message_id}`});
815
+ }
816
+
817
+ /**
818
+ * Gets the current representation of a channel via its id
819
+ * Channels can be DMs, group DMs, server text, or server voice channels
820
+ * @param {String} channel_id
821
+ * @returns {Promise<Object>} The current channel object
822
+ */
823
+ getChannelObject(channel_id) {
824
+ return this.#GET({path: `/channels/${channel_id}`});
825
+ }
826
+
827
+ /**
828
+ * Gets the channel object for DMs with a certain user
829
+ * Getting the channel object also opens the channel in the active DM list
830
+ * @param {String} user_id The id of the user to get the DM channel of
831
+ * @returns {Promise<Object>} The DM channel object
832
+ */
833
+ getDMChannel(user_id) {
834
+ return this.#POST({path: "/users/@me/channels", body: {recipients: [user_id]}});
835
+ }
836
+
837
+ /**
838
+ * Closes and hides the DM channel for a certain user from the active list
839
+ * @param {String} user_id The id of the user to close the DM channel of
840
+ * @returns {Promise<Object>} Returns the channel after closing on success
841
+ */
842
+ async closeDMChannel(user_id) {
843
+ const channel = await this.getDMChannel(user_id);
844
+ if(!("id" in channel)) return null;
845
+ return this.#DELETE({path: `/channels/${channel.id}`});
846
+ }
847
+
848
+ /**
849
+ * Get a user's profile if one of the following is true:
850
+ * The client shares a server with the user, is friends with the user
851
+ * The user sent a friend request to the client, or the user is a bot
852
+ * @param {Object} options The options specifying what the response should contain
853
+ * @param {String} options.user_id The id of the user to request the profile of
854
+ * @param {Boolean} [options.with_mutual_servers] If true or absent, include mutual servers in the response
855
+ * @param {Boolean} [options.with_mutual_friends] If true, include mutual friends in the response
856
+ * @param {Boolean} [options.with_mutual_friends_count] If true, include the number of mutual friends in the response
857
+ * @param {String} [options.guild_id] If present respond with the server profile for this guild
858
+ * @returns {Promise<Object>} The user's profile on success, 404 error if no conditions were met
859
+ */
860
+ getUserProfile(options) {
861
+ return this.#GET({
862
+ path: `/users/${options.user_id}/profile`,
863
+ query: {
864
+ guild_id: options.guild_id,
865
+ with_mutual_guilds: options.with_mutual_servers,
866
+ with_mutual_friends: options.with_mutual_friends,
867
+ with_mutual_friends_count: options.with_mutual_friends_count
868
+ }
869
+ });
870
+ }
723
871
  }
724
872
 
725
873
  module.exports = {