discord-user-bots
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -55,2 +55,13 @@ const Discord = require("discord-user-bots"); | ||
stickers: [], // Stickers to go with your message (Not optional, must be an array, can be unset for default) (Default empty array) | ||
attachments: [ | ||
// Message attachments (optional, must be an array) | ||
"path/to/file", // Attachment item can be string (absolute path to the file) | ||
// Or can be an object for attachment detail | ||
{ | ||
path: "path/to/file", // File location (Not optional, must be string) | ||
name: "custom-file-name.jpg", // File name (optional, must be string) (Default is base name of file) | ||
description: "File description", // Attachment description (optional, must be string) (Default is empty) | ||
}, | ||
], | ||
} | ||
@@ -136,2 +147,9 @@ ); | ||
// Remove a reaction to a message | ||
client.remove_reaction( | ||
"914533528245506068", // The message to remove a reaction to | ||
"753267478943105028", // The channel the message is in | ||
"🤖" // Emoji to react with (Cannot be ":robot:" has to be an actual emoji like "🤖") | ||
); | ||
// Changes your visibility | ||
@@ -149,2 +167,15 @@ client.change_status( | ||
client.create_invite( | ||
"753267478943105028", // Channel you want to make the invite on | ||
{ | ||
// Invite options (Default seen here) | ||
validate: null, // Validate an already active invite | ||
max_age: 0, // Max age in seconds (0 means never ending) | ||
max_uses: 0, // Make uses (0 means no limit) | ||
target_user_id: null, // Target user ID | ||
target_type: null, // Target type | ||
temporary: false, // Kick the person invited once they log off if they don't have a role | ||
} | ||
); | ||
// Parses a discord invite link wether it be a https link or straight code | ||
@@ -151,0 +182,0 @@ client.parse_invite_link( |
{ | ||
"name": "discord-user-bots", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "I library that allows you to use the full potential of Discords api to create good user bots.", | ||
@@ -30,5 +30,6 @@ "main": "src/exports.js", | ||
"dependencies": { | ||
"node-fetch": "^2.6.6", | ||
"form-data": "^4.0.0", | ||
"node-fetch": "^2.6.7", | ||
"ws": "^8.3.0" | ||
} | ||
} | ||
} |
@@ -0,4 +1,6 @@ | ||
![Logo](https://raw.githubusercontent.com/Sopur/Discord-user-bots/main/logo.png) | ||
# Sopur's user bot library | ||
Hello! This is a user bot library the allows | ||
Hello! This is a user bot library that allows | ||
for a lot more things than Discord.js. | ||
@@ -8,5 +10,5 @@ For example, this library allows you to access | ||
like user notes, friend counts, | ||
the defualt Discord tutorial, | ||
the default Discord tutorial, | ||
and everything else. | ||
This library is in a early state | ||
This library is in an early state | ||
and needs more work. | ||
@@ -36,2 +38,14 @@ More functions will be added soon. | ||
# Practical examples | ||
## Mailing list | ||
Pings other users when a victim on your choice sends a message <br> | ||
**https://github.com/Sopur/Discord-user-bots/blob/main/examples/mailinglist.js** | ||
## Un-sendable channel | ||
Deletes every message that is sent on channels of your choice while avoiding message delete rate limits <br> | ||
**https://github.com/Sopur/Discord-user-bots/blob/main/examples/unsendable-channel.js** | ||
# Functions | ||
@@ -91,2 +105,13 @@ | ||
stickers: [], // Stickers to go with your message (Not optional, must be an array, can be unset for default) (Default empty array) | ||
attachments: [ | ||
// Message attachments (optional, must be an array) | ||
"path/to/file", // Attachment item can be string (absolute path to the file) | ||
// Or can be an object for attachment detail | ||
{ | ||
path: "path/to/file", // File location (Not optional, must be string) | ||
name: "custom-file-name.jpg", // File name (optional, must be string) (Default is base name of file) | ||
description: "File description", // Attachment description (optional, must be string) (Default is empty) | ||
}, | ||
], | ||
} | ||
@@ -172,2 +197,9 @@ ); | ||
// Remove a reaction to a message | ||
client.remove_reaction( | ||
"914533528245506068", // The message to remove a reaction to | ||
"753267478943105028", // The channel the message is in | ||
"🤖" // Emoji to react with (Cannot be ":robot:" has to be an actual emoji like "🤖") | ||
); | ||
// Changes your visibility | ||
@@ -185,2 +217,15 @@ client.change_status( | ||
client.create_invite( | ||
"753267478943105028", // Channel you want to make the invite on | ||
{ | ||
// Invite options (Default seen here) | ||
validate: null, // Validate an already active invite | ||
max_age: 0, // Max age in seconds (0 means never ending) | ||
max_uses: 0, // Make uses (0 means no limit) | ||
target_user_id: null, // Target user ID | ||
target_type: null, // Target type | ||
temporary: false, // Kick the person invited once they log off if they don't have a role | ||
} | ||
); | ||
// Parses a discord invite link wether it be a https link or straight code | ||
@@ -389,18 +434,18 @@ client.parse_invite_link( | ||
- Made the library throw errors instead of returning them | ||
- Added whole new object to the exports, constructs | ||
- Massive code refactoring | ||
- Fixed documentation mistakes | ||
- Added parse_invite_link to the client to get the invite code from a url | ||
- Changed all function names to snake case | ||
- Added add_reaction, change_status, and set_custom_status | ||
- Added a lot more functionality to the send function | ||
- Added a lot more functionality to the edit function | ||
- Changed create_group to group and changed its description | ||
- Fixed bug where if discord rejected your connection attempt it throws an error | ||
- Changed, fixed, and added more documentation | ||
- Updated packages node-fetch and node-ws | ||
- Added special thanks section | ||
- Added logo | ||
- Practical examples in the /examples folder | ||
- Added create_invite function | ||
- Updated send function to include attachments | ||
- Added remove_reaction function | ||
# Special Thanks To | ||
## Github user Luthfi GearIntellix | ||
- Added attachments to the send function | ||
- Added the remove_reaction function | ||
# WARN | ||
WHATEVER HAPPENS TO YOUR ACCOUNT AS A RESULT OF THIS LIBRARY IS WITHIN YOUR OWN LIABILITY. THIS LIBRARY IS MADE PURELY FOR TESTS AND FUN. USE AT YOUR OWN RISK. |
@@ -0,4 +1,5 @@ | ||
const WebSocket = require("ws"); | ||
const fetch = require("node-fetch"); | ||
const WebSocket = require("ws"); | ||
const { fetchRequestOpts, SendMessageOpts, CustomStatusOpts } = require("./constructs.js"); | ||
const { fetchRequestOpts, SendMessageOpts, CustomStatusOpts, createInviteOpts } = require("./constructs.js"); | ||
const DiscordEvents = require("./events.js"); | ||
const constructs = require("./constructs.js"); | ||
@@ -11,3 +12,3 @@ const packets = require("./packet.js"); | ||
* @author Sopur, Discord: Sopur#3550 | ||
* @license GNU | ||
* @license MIT | ||
* @warn WHATEVER HAPPENS TO YOUR ACCOUNT AS A RESULT OF THIS LIBRARY IS WITHIN YOUR OWN LIABILITY. THIS LIBRARY IS MADE PURELY FOR TESTS AND FUN. USE AT YOUR OWN RISK. | ||
@@ -24,3 +25,2 @@ * @param {string} token Auth token for the user account you want to login to | ||
language: "en-US", | ||
intents: "all", | ||
typinginterval: 1000, | ||
@@ -32,57 +32,5 @@ }; | ||
this.typingLoop = function () {}; | ||
this.on = { | ||
discord_disconnect: function () {}, | ||
gateway: function () {}, | ||
heartbeat_sent: function () {}, | ||
heartbeat_received: function () {}, | ||
ready: function () {}, | ||
voice_server_update: function (message) {}, | ||
user_update: function (message) {}, | ||
application_command_create: function (message) {}, | ||
application_command_update: function (message) {}, | ||
application_command_delete: function (message) {}, | ||
interaction_create: function (message) {}, | ||
guild_create: function (message) {}, | ||
guild_delete: function (message) {}, | ||
guild_role_create: function (message) {}, | ||
guild_role_update: function (message) {}, | ||
guild_role_delete: function (message) {}, | ||
thread_create: function (message) {}, | ||
thread_update: function (message) {}, | ||
thread_delete: function (message) {}, | ||
thread_list_sync: function (message) {}, | ||
thread_member_update: function (message) {}, | ||
thread_members_update: function (message) {}, | ||
channel_create: function (message) {}, | ||
channel_update: function (message) {}, | ||
channel_delete: function (message) {}, | ||
channel_pins_update: function (message) {}, | ||
guild_member_add: function (message) {}, | ||
guild_member_update: function (message) {}, | ||
guild_member_remove: function (message) {}, | ||
guild_ban_add: function (message) {}, | ||
guild_ban_remove: function (message) {}, | ||
guild_emojis_update: function (message) {}, | ||
guild_stickers_update: function (message) {}, | ||
guild_integrations_update: function (message) {}, | ||
guild_webhooks_update: function (message) {}, | ||
invite_create: function (message) {}, | ||
invite_delete: function (message) {}, | ||
voice_state_update: function (message) {}, | ||
presence_update: function (message) {}, | ||
message_create: function (message) {}, | ||
message_update: function (message) {}, | ||
message_delete: function (message) {}, | ||
message_delete_bulk: function (message) {}, | ||
message_reaction_add: function (message) {}, | ||
message_reaction_remove: function (message) {}, | ||
message_reaction_remove_all: function (message) {}, | ||
message_reaction_remove_emoji: function (message) {}, | ||
typing_start: function (message) {}, | ||
this.on = new DiscordEvents(); | ||
this.requester = fetch; | ||
// Custom made ones | ||
embed_sent: function (message) {}, | ||
message_edit: function (message) {}, | ||
}; | ||
this.check_token().then((res) => { | ||
@@ -431,2 +379,3 @@ if (res === true) this.setEvents(); | ||
"x-discord-locale": this.config.language, | ||
...(options.isMultipartFormData ? options.body.getHeaders() : {}), | ||
}, | ||
@@ -537,5 +486,5 @@ referrer: `https://discord.com/channels/@me`, | ||
async delete_guild(guild_id) { | ||
return await this.fetch_request(`guilds/${guild_id}/delete`, { | ||
method: "POST", | ||
body: "{}", | ||
return await this.fetch_request(`guilds/${guild_id}`, { | ||
method: "DELETE", | ||
body: null, | ||
parse: false, | ||
@@ -555,2 +504,3 @@ }); | ||
return await this.fetch_request(`channels/${channel_id}/messages`, { | ||
isMultipartFormData: data.isMultipartFormData, | ||
body: data.content, | ||
@@ -693,12 +643,13 @@ method: "POST", | ||
* @param {string} guild_template_code The template of the server (Optional) (Default "2TffvPucqHkN") | ||
* @param {string} icon The icon in base64 (Optional) | ||
*/ | ||
async create_server(name, guild_template_code = "2TffvPucqHkN") { | ||
async create_server(name, guild_template_code = "2TffvPucqHkN", icon = null) { | ||
this.call_check(arguments); | ||
return await this.fetch_request(`guilds`, { | ||
return await this.fetch_request(`guilds/templates/${guild_template_code}`, { | ||
body: JSON.stringify({ | ||
name: name, | ||
icon: null, | ||
channels: [], | ||
system_channel_id: null, | ||
guild_template_code: guild_template_code, | ||
icon: icon, | ||
// channels: [], | ||
// system_channel_id: null, | ||
// guild_template_code: guild_template_code, | ||
}), | ||
@@ -784,2 +735,18 @@ method: "POST", | ||
/** | ||
* Remove a reaction to a message | ||
* @param {string} message_id The message to remove a reaction to | ||
* @param {string} channel_id The channel the message is in | ||
* @param {string} emoji Emoji to react with (Cannot be ":robot:" has to be an actual emoji like "🤖") | ||
* @returns {Promise<Object>} The response from Discord | ||
*/ | ||
async remove_reaction(message_id, channel_id, emoji) { | ||
this.call_check(arguments); | ||
return await this.fetch_request(`channels/${channel_id}/messages/${message_id}/reactions/${encodeURI(emoji)}/%40me`, { | ||
body: null, | ||
method: "DELETE", | ||
parse: false, | ||
}); | ||
} | ||
/** | ||
* Changes your visibility | ||
@@ -817,4 +784,22 @@ * @param {"online" | "idle" | "dnd" | "invisible"} status Status to change to (Must be "online", "idle", "dnd", or "invisible") | ||
} | ||
/** | ||
* Creates an invite | ||
* @param {string} channel_id The channel | ||
* @param {createInviteOpts} inviteOpts Invite options | ||
* @returns {Promise<Object>} The response from Discord (invite code is under .code) | ||
*/ | ||
async create_invite(channel_id, inviteOpts = createInviteOpts) { | ||
const opts = { | ||
createInviteOpts, | ||
...inviteOpts, | ||
}; | ||
return await this.fetch_request(`/channels/${channel_id}/invites`, { | ||
method: "POST", | ||
body: JSON.stringify(opts), | ||
parse: true, | ||
}); | ||
} | ||
} | ||
module.exports = Client; |
@@ -0,1 +1,5 @@ | ||
const FS = require("node:fs"); | ||
const Path = require("node:path"); | ||
const FormData = require("form-data"); | ||
const MentionsLimiterOpts = { | ||
@@ -64,2 +68,3 @@ allowUsers: true, | ||
stickers: [], | ||
attachments: [], | ||
}; | ||
@@ -76,2 +81,37 @@ class SendMessage { | ||
}; | ||
const formData = new FormData(); | ||
const attachments = []; | ||
if (Array.isArray(options.attachments) && options.attachments.length > 0) { | ||
this.isMultipartFormData = true; | ||
options.attachments.forEach((item, index) => { | ||
if (!item) return; | ||
switch (typeof item) { | ||
case "string": { | ||
item = { | ||
path: item, | ||
}; | ||
} | ||
case "object": { | ||
if (!item.path) return; | ||
const filename = item.name || Path.basename(item.path) || `file-${index}`; | ||
formData.append(`files[${index}]`, FS.createReadStream(item.path), filename); | ||
attachments.push({ | ||
id: index, | ||
filename, | ||
description: item.description || filename, | ||
}); | ||
break; | ||
} | ||
} | ||
}); | ||
options.attachments = attachments; | ||
} | ||
this.content = JSON.stringify({ | ||
@@ -90,3 +130,9 @@ content: options.content, | ||
sticker_ids: options.stickers, | ||
...(attachments.length > 0 ? { attachments } : {}), | ||
}); | ||
if (this.isMultipartFormData) { | ||
formData.append("payload_json", this.content); | ||
this.content = formData; | ||
} | ||
} | ||
@@ -101,2 +147,10 @@ } | ||
}, | ||
createInviteOpts: { | ||
validate: null, | ||
max_age: 0, | ||
max_uses: 0, | ||
target_user_id: null, | ||
target_type: null, | ||
temporary: false, | ||
}, | ||
MentionsLimiterOpts, | ||
@@ -103,0 +157,0 @@ CustomStatusOpts, |
module.exports = { | ||
Client: require("./client.js"), | ||
DiscordEvents: require("./events.js"), | ||
packets: require("./packet.js"), | ||
constructs: require("./constructs.js"), | ||
}; |
class GateWayOpen { | ||
constructor(token, config) { | ||
let intent = 0; | ||
switch (config.intents) { | ||
case "all": { | ||
intent = 32767; | ||
break; | ||
} | ||
case "minimum": { | ||
intent = 1; | ||
break; | ||
} | ||
case "unset": { | ||
intent = null; | ||
break; | ||
} | ||
} | ||
return { | ||
op: 2, | ||
d: { | ||
token: token, | ||
capabilities: 125, | ||
properties: { | ||
os: config.os, | ||
browser: "Chrome", | ||
device: "", | ||
system_locale: config.language, | ||
browser_user_agent: `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36`, | ||
browser_version: "93.0.4577.63", | ||
os_version: "", | ||
referrer: "", | ||
referring_domain: "", | ||
referrer_current: "", | ||
referring_domain_current: "", | ||
release_channel: "stable", | ||
client_build_number: 97662, | ||
client_event_source: null, | ||
}, | ||
presence: { status: "online", since: 0, activities: [], afk: false }, | ||
compress: false, | ||
client_state: { guild_hashes: {}, highest_last_message_id: "0", read_state_version: 0, user_guild_settings_version: -1 }, | ||
this.op = 2; | ||
this.d = { | ||
token: token, | ||
capabilities: 125, | ||
properties: { | ||
os: config.os, | ||
browser: "Chrome", | ||
device: "", | ||
system_locale: config.language, | ||
browser_user_agent: `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36`, | ||
browser_version: "93.0.4577.63", | ||
os_version: "", | ||
referrer: "", | ||
referring_domain: "", | ||
referrer_current: "", | ||
referring_domain_current: "", | ||
release_channel: "stable", | ||
client_build_number: 97662, | ||
client_event_source: null, | ||
}, | ||
presence: { status: "online", since: 0, activities: [], afk: false }, | ||
compress: false, | ||
client_state: { guild_hashes: {}, highest_last_message_id: "0", read_state_version: 0, user_guild_settings_version: -1 }, | ||
}; | ||
@@ -49,6 +32,4 @@ } | ||
constructor(lastpacket) { | ||
return { | ||
op: 1, | ||
d: lastpacket === undefined ? null : Number(lastpacket), | ||
}; | ||
this.op = 1; | ||
this.d = lastpacket === undefined ? null : Number(lastpacket); | ||
} | ||
@@ -59,9 +40,7 @@ } | ||
constructor(guildid, limit) { | ||
return { | ||
op: 8, | ||
d: { | ||
guild_id: String(guildid), | ||
query: "", | ||
limit: Number(limit), | ||
}, | ||
this.op = 8; | ||
this.d = { | ||
guild_id: String(guildid), | ||
query: "", | ||
limit: Number(limit), | ||
}; | ||
@@ -73,19 +52,17 @@ } | ||
constructor(token) { | ||
return { | ||
headers: { | ||
accept: "*/*", | ||
"accept-language": "en-US", | ||
authorization: token, | ||
"sec-ch-ua": '" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"', | ||
"sec-ch-ua-mobile": "?0", | ||
"sec-fetch-dest": "empty", | ||
"sec-fetch-mode": "cors", | ||
"sec-fetch-site": "same-origin", | ||
}, | ||
referrer: "https://discord.com/login?redirect_to=%2Fchannels%2F%40me", | ||
referrerPolicy: "strict-origin-when-cross-origin", | ||
body: null, | ||
method: "GET", | ||
mode: "cors", | ||
this.headers = { | ||
accept: "*/*", | ||
"accept-language": "en-US", | ||
authorization: token, | ||
"sec-ch-ua": '" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"', | ||
"sec-ch-ua-mobile": "?0", | ||
"sec-fetch-dest": "empty", | ||
"sec-fetch-mode": "cors", | ||
"sec-fetch-site": "same-origin", | ||
}; | ||
this.referrer = "https://discord.com/login?redirect_to=%2Fchannels%2F%40me"; | ||
this.referrerPolicy = "strict-origin-when-cross-origin"; | ||
this.body = null; | ||
this.method = "GET"; | ||
this.mode = "cors"; | ||
} | ||
@@ -92,0 +69,0 @@ } |
Sorry, the diff of this file is not supported yet
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
87179
15
0
100
1465
446
3
3
+ Addedform-data@^4.0.0
+ Addedasynckit@0.4.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedform-data@4.0.1(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
Updatednode-fetch@^2.6.7