squacker.js 1.0.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.

Potentially problematic release.


This version of squacker.js might be problematic. Click here for more details.

Files changed (3) hide show
  1. package/index.js +30 -0
  2. package/package.js +257 -0
  3. package/package.json +16 -0
package/index.js ADDED
@@ -0,0 +1,30 @@
1
+ const pkg = require('./package.js'); // or require('squacker.js')
2
+
3
+
4
+ pkg.READY = ()=>{
5
+ console.log('Bot is online!')
6
+ }
7
+
8
+ pkg.INTERACTION_CREATE = (interaction)=>{
9
+ // console.log('Interaction!^2')
10
+ if(interaction.data.name == 'help'){
11
+ new pkg.INTERACTION(interaction).repy('Help Message!', [], [])
12
+ }else if(interaction.data.name == 't'){
13
+ new pkg.INTERACTION(interaction).repy('oohh yeah! you said.. ' + interaction.data.options[0].value, [], [])
14
+ }
15
+ }
16
+
17
+ pkg.MESSAGE_CREATE = (msg)=>{
18
+ if(msg.content == 'ping'){
19
+ let ping = new pkg.MESSAGE(msg)
20
+ ping.reply('pong')
21
+ ping.channel.send('pong')
22
+ console.log('pong')
23
+ }
24
+ }
25
+
26
+
27
+ pkg.login('TOKEN', 513, {
28
+ name: "Froggy",
29
+ type: 3
30
+ });
package/package.js ADDED
@@ -0,0 +1,257 @@
1
+ // require('dotenv').config()
2
+ const WebSocket = require('ws');
3
+ const ws = new WebSocket('wss://gateway.discord.gg/?v=9&encoding=json')
4
+ // const fetch = require('node-fetch')
5
+ const fetchPromise = import('node-fetch').then(mod => mod.default)
6
+ const fetch = (...args) => fetchPromise.then(fetch => fetch(...args))
7
+ let interval = 0;
8
+
9
+
10
+
11
+ ws.addEventListener('message', function(event) {
12
+ const payload = event.data
13
+ // console.log(JSON.parse(payload.toString()))
14
+ })
15
+
16
+ ws.on('message', function incoming(data) {
17
+ let payload = JSON.parse(data)
18
+ const { t, event, op, d } = payload;
19
+
20
+ switch (op) {
21
+ case 10:
22
+ const { heartbeat_interval } = d;
23
+ interval = heartbeat(heartbeat_interval)
24
+ break;
25
+ }
26
+ // console.log(t)
27
+
28
+ if(t == "ready"){
29
+ pkg.READY()
30
+ }else if(t == "MESSAGE_CREATE"){
31
+ pkg.MESSAGE_CREATE(d)
32
+ }else if( t == "INTERACTION_CREATE"){
33
+ // https://discord.com/api/v9/interactions/${d.id}/${d.token}/callback
34
+ let URL = `https://discord.com/api/v9/interactions/${d.id}/${d.token}/callback`;
35
+ pkg["INTERACTION_CREATE"](d)
36
+ }else if(typeof(t) == "string"){
37
+ pkg[t](d)
38
+ }
39
+
40
+
41
+
42
+ })
43
+
44
+ const heartbeat = (ms) => {
45
+ return setInterval(() => {
46
+ ws.send(JSON.stringify({op: 2, d: null}))
47
+ }, ms)
48
+ }
49
+
50
+ let pkg = {
51
+ login: (token, intents, activity)=>{ ws.on('open', function open(data) {
52
+ pkg.token = token
53
+ ws.send(JSON.stringify({
54
+ op: 2,
55
+ d: {
56
+ token: token,
57
+ intents: intents,
58
+ properties: {
59
+ $os: 'win',
60
+ $browser: 'squacker',
61
+ $device: 'squacker'
62
+ },
63
+ presence: {
64
+ activities: [activity],
65
+ status: "online",
66
+ since: 0,
67
+ afk: false
68
+ },
69
+ }
70
+ }))
71
+ })
72
+ },
73
+ ["INTERACTION_CREATE"]: (d)=>{
74
+ console.log('INTERACTION_CREATE')
75
+ },
76
+ ["MESSAGE_CREATE"]: (d)=>{
77
+ console.log('MESSAGE_CREATE')
78
+ },
79
+ ["READY"]: (d)=>{
80
+ console.log('READY')
81
+ },
82
+ ['CHANNEL_CREATE']: (d)=>{
83
+ console.log('CHANNEL_CREATE')
84
+ },
85
+ ['CHANNEL_UPDATE']: (d)=>{
86
+ console.log('CHANNEL_UPDATE')
87
+ },
88
+ ['CHANNEL_DELETE']: (d)=>{
89
+ console.log('CHANNEL_DELETE')
90
+ },
91
+ ['CHANNEL_PINS_UPDATE']: (d)=>{
92
+ console.log('CHANNEL_PINS_UPDATE')
93
+ },
94
+ ["GUILD_CREATE"]: (d)=>{
95
+ console.log('GUILD_CREATE')
96
+ },
97
+ ["GUILD_MEMBER_ADD"]: (d)=>{
98
+ console.log('GUILD_MEMBER_ADD')
99
+ },
100
+ ["GUILD_MEMBER_REMOVE"]: (d)=>{
101
+ console.log('GUILD_MEMBER_REMOVE')
102
+ },
103
+ ["GUILD_MEMBER_UPDATE"]: (d)=>{
104
+ console.log('GUILD_MEMBER_UPDATE')
105
+ },
106
+ ["GUILD_MEMBERS_CHUNK"]: (d)=>{
107
+ console.log('GUILD_MEMBERS_CHUNK')
108
+ },
109
+ ["GUILD_UPDATE"]: (d)=>{
110
+ console.log('GUILD_UPDATE')
111
+ },
112
+ ["GUILD_DELETE"]: (d)=>{
113
+ console.log('GUILD_DELETE')
114
+ },
115
+ ["GUILD_BAN_ADD"]: (d)=>{
116
+ console.log('GUILD_BAN_ADD')
117
+ },
118
+ ["GUILD_BAN_REMOVE"]: (d)=>{
119
+ console.log('GUILD_BAN_REMOVE')
120
+ },
121
+ ["GUILD_EMOJIS_UPDATE"]: (d)=>{
122
+ console.log('GUILD_EMOJIS_UPDATE')
123
+ },
124
+ ["GUILD_INTEGRATIONS_UPDATE"]: (d)=>{
125
+ console.log('GUILD_INTEGRATIONS_UPDATE')
126
+ },
127
+ ["GUILD_ROLE_CREATE"]: (d)=>{
128
+ console.log('GUILD_ROLE_CREATE')
129
+ },
130
+ ["GUILD_ROLE_UPDATE"]: (d)=>{
131
+ console.log('GUILD_ROLE_UPDATE')
132
+ },
133
+ ["GUILD_ROLE_DELETE"]: (d)=>{
134
+ console.log('GUILD_ROLE_DELETE')
135
+ },
136
+ ["GUILD_SYNC"]: (d)=>{
137
+ console.log('GUILD_SYNC')
138
+ },
139
+ ["GUILD_MEMBERS_CHUNK"]: (d)=>{
140
+ console.log('GUILD_MEMBERS_CHUNK')
141
+ },
142
+ ["GUILD_MESSAGE_DELETE"]: (d)=>{
143
+ console.log('GUILD_MESSAGE_DELETE')
144
+ },
145
+ ["GUILD_MESSAGE_BULK_DELETE"]: (d)=>{
146
+ console.log('GUILD_MESSAGE_BULK_DELETE')
147
+ },
148
+ ["GUILD_MESSAGE_UPDATE"]: (d)=>{
149
+ console.log('GUILD_MESSAGE_UPDATE')
150
+ },
151
+ ["GUILD_MESSAGE_DELETE_BULK"]: (d)=>{
152
+ console.log('GUILD_MESSAGE_DELETE_BULK')
153
+ },
154
+ ["GUILD_MESSAGE_REACTION_ADD"]: (d)=>{
155
+ console.log('GUILD_MESSAGE_REACTION_ADD')
156
+ },
157
+ ["GUILD_MESSAGE_REACTION_REMOVE"]: (d)=>{
158
+ console.log('GUILD_MESSAGE_REACTION_REMOVE')
159
+ },
160
+ ["GUILD_MESSAGE_REACTION_REMOVE_ALL"]: (d)=>{
161
+ console.log('GUILD_MESSAGE_REACTION_REMOVE_ALL')
162
+ },
163
+ ["GUILD_MESSAGE_REACTION_REMOVE_EMOJI"]: (d)=>{
164
+ console.log('GUILD_MESSAGE_REACTION_REMOVE_EMOJI')
165
+ },
166
+ ["GUILD_INTEGRATIONS_UPDATE"]: (d)=>{
167
+ console.log('GUILD_INTEGRATIONS_UPDATE')
168
+ },
169
+ ["GUILD_WEBHOOKS_UPDATE"]: (d)=>{
170
+ console.log('GUILD_WEBHOOKS_UPDATE')
171
+ },
172
+ ["GUILD_INVITE_CREATE"]: (d)=>{
173
+ console.log('GUILD_INVITE_CREATE')
174
+ },
175
+ ["GUILD_INVITE_DELETE"]: (d)=>{
176
+ console.log('GUILD_INVITE_DELETE')
177
+ },
178
+ ["GUILD_BAN_ADD"]: (d)=>{
179
+ console.log('GUILD_BAN_ADD')
180
+ },
181
+ ["GUILD_BAN_REMOVE"]: (d)=>{
182
+ console.log('GUILD_BAN_REMOVE')
183
+ },
184
+ ["GUILD_EMOJIS_UPDATE"]: (d)=>{
185
+ console.log('GUILD_EMOJIS_UPDATE')
186
+ },
187
+ INTERACTION: class {
188
+ constructor(d) {
189
+ this.data = d
190
+ }
191
+ repy(reply, embeds, components) {
192
+ // https://discord.com/api/v9/interactions/${this.data.id}/${this.data.token}/callback
193
+ const fetch_arguments = {
194
+ method: "POST",
195
+ headers: {
196
+ "Content-Type": "application/json",
197
+ "Authorization": `Bot ${pkg.token}`,
198
+ },
199
+ body: JSON.stringify({
200
+ type: 4,
201
+ data: {
202
+ "content": reply,
203
+ "embeds": embeds,
204
+ "components": components,
205
+ }
206
+ })
207
+ }
208
+ // console.log(this)
209
+ fetch(`https://discord.com/api/v9/interactions/${this.data.id}/${this.data.token}/callback`, fetch_arguments).catch(err => console.log(err))
210
+ }},
211
+ token: null,
212
+ MESSAGE: class {
213
+ constructor(d) {
214
+ this.data = d
215
+ this.channel = {
216
+ id: d.channel_id,
217
+ send: (reply, embeds, components)=>{
218
+ // https://discord.com/api/v10/channels/${channel.id}/messages
219
+ const fetch_arguments = {
220
+ method: "POST",
221
+ headers: {
222
+ "Content-Type": "application/json",
223
+ "Authorization": `Bot ${pkg.token}`,
224
+ },
225
+ body: JSON.stringify({
226
+ "content": reply,
227
+ "embeds": embeds,
228
+ "components": components,
229
+ })
230
+ }
231
+ fetch(`https://discord.com/api/v10/channels/${this.data.channel_id}/messages`, fetch_arguments).catch(err => console.log(err))
232
+ }
233
+ }
234
+ }
235
+ reply(reply, embeds, components) {
236
+ // POST https://discord.com/api/v10/channels/${channel.id}/messages
237
+ const fetch_arguments = {
238
+ method: "POST",
239
+ headers: {
240
+ "Content-Type": "application/json",
241
+ "Authorization": `Bot ${pkg.token}`,
242
+ },
243
+ body: JSON.stringify({
244
+ "content": `<@${this.data.author.id}>, ${reply}`,
245
+ "embeds": embeds,
246
+ "components": components,
247
+ })
248
+ }
249
+ // console.log(this.data)
250
+ fetch(`https://discord.com/api/v10/channels/${this.data.channel_id}/messages`, fetch_arguments).catch(err => console.log(err))
251
+ }
252
+
253
+
254
+ }
255
+ }
256
+
257
+ module.exports = pkg
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "squacker.js",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "author": "amukh1",
10
+ "license": "ISC",
11
+ "dependencies": {
12
+ "node-fetch": "^3.2.9",
13
+ "request": "^2.88.2",
14
+ "ws": "^8.8.1"
15
+ }
16
+ }