· 5 years ago · Nov 24, 2020, 08:30 PM
1const Discord = require('discord.js');
2const client = new Discord.Client();
3var mysql = require('mysql');
4var fs = require('fs');
5
6var db_config = { host: "ip hidden",
7 user: "discord",
8 password: "discord",
9 database: "mrob"
10}
11
12function writeKeyToFile(k) {
13 fs.appendFile('keys.txt', k + "\n", function (err) {
14 if (err) throw err;
15 console.log('Saved!');
16 });
17}
18function onChatKey(args, msg) {
19 var con = mysql.createConnection(db_config);
20 con.connect(function(err) {
21 if (err) throw err;
22 con.query("UPDATE `DQ_TEST` SET name = '" +msg.author.id+ "' WHERE wlkey = '"+args[1]+"' and name = 0", function (err, result, fields) {
23 if (err) throw err;
24 //console.log(result);
25 if (result.affectedRows>0) {
26 if (result) {
27 console.log("Giving key to: " + msg.author.username)
28 msg.reply("Key has been registered to your discord account")
29 }
30 } else {
31 msg.reply("That key does not exist or is already used")
32 }
33
34 });
35 });
36 con.on('error', function() {});
37}
38
39function onChatIp(args, msg) {
40 var con = mysql.createConnection(db_config);
41 con.connect(function(err) {
42 if (err) throw err;
43 con.query("UPDATE `DQ_TEST` SET ip = '" +args[1]+ "' WHERE name = '"+msg.author.id+"'", function (err, result, fields) {
44 if (err) throw err;
45 //console.log(result);
46 if (result.affectedRows>0) {
47 if (result) {
48 console.log("Updating: " + msg.author.username + " IP")
49 msg.reply('Your IP has been updated to: ' + args[1])
50 } else {
51 msg.reply('error')
52 }
53 } else {
54 msg.reply("Your discord account does not have a registered key")
55 }
56
57 });
58 });
59 con.on('error', function() {});
60}
61
62function onChatId(args, msg) {
63 var con = mysql.createConnection(db_config);
64 con.connect(function(err) {
65 if (err) throw err;
66 con.query("UPDATE `DQ_TEST` SET userid = '" +args[1]+ "' WHERE name = '"+msg.author.id+"'", function (err, result, fields) {
67 if (err) throw err;
68 //console.log(result);
69 if (result.affectedRows>0) {
70 if (result) {
71 console.log("Updating: " + msg.author.username + " ID")
72 msg.reply('Your ID has been updated to: ' + args[1])
73 } else {
74 msg.reply('error')
75 }
76 } else {
77 msg.reply("Your discord account does not have a registered key")
78 }
79
80 });
81 });
82 con.on('error', function() {});
83}
84
85function onChatRank(args, msg) {
86 var con = mysql.createConnection(db_config);
87 con.connect(function(err) {
88 if (err) throw err;
89 con.query("SELECT * from `DQ_TEST` WHERE name = '"+msg.author.id+"'", function (err, result, fields) {
90 if (err) throw err;
91 //console.log(result);
92 if (result.length > 0) {
93 if (result) {
94 console.log("Updating: " + msg.author.username + " Rank")
95 msg.reply('Updating rank...')
96 var role = msg.guild.roles.cache.find(role => role.name === "DQ AI Buyers");
97 msg.member.roles.add(role);
98 var role1 = msg.guild.roles.cache.find(role => role.name === "Non-Buyer");
99 if (role1) {
100 msg.member.roles.remove(role1)
101 }
102
103 } else {
104 msg.reply('error')
105 }
106 } else {
107 msg.reply("Your discord account does not have a registered key")
108 }
109
110 });
111 });
112 con.on('error', function() {});
113}
114
115function onChatGetInfo(args, msg) {
116 var con = mysql.createConnection(db_config);
117 con.connect(function(err) {
118 if (err) throw err;
119 con.query("SELECT * from `DQ_TEST` WHERE name = '"+msg.author.id+"'", function (err, result, fields) {
120 if (err) throw err;
121 //console.log(result);
122 if (result.length > 0) {
123 if (result) {
124 console.log("user: " + msg.author.username + " getting their info")
125 msg.author.send('Key Information for ' + msg.author.username +'\nKey: ' + result[0].wlkey + "\nIP: " + result[0].ip + "\nID: " + result[0].userid)
126
127 } else {
128 msg.reply('error')
129 }
130 } else {
131 msg.reply("Your discord account does not have a registered key")
132 }
133
134 });
135 });
136 con.on('error', function() {});
137}
138
139function onChatAdminGetInfoFromId(args, msg) {
140 var con = mysql.createConnection(db_config);
141 con.connect(function(err) {
142 if (err) throw err;
143 con.query("SELECT * from `DQ_TEST` WHERE name = '"+args[2]+"'", function (err, result, fields) {
144 if (err) throw err;
145 //console.log(result);
146 if (result.length > 0) {
147 if (result) {
148 console.log("admin getting information on: " + args[2])
149 msg.author.send('Key Information for ' + args[2] +'\nKey: ' + result[0].wlkey + "\nIP: " + result[0].ip + "\nID: " + result[0].userid)
150
151 } else {
152 msg.reply('error')
153 }
154 } else {
155 msg.reply("No key on that account")
156 }
157
158 });
159 });
160 con.on('error', function() {});
161}
162
163function onChatAdminGetInfoFromKey(args, msg) {
164 var con = mysql.createConnection(db_config);
165 con.connect(function(err) {
166 if (err) throw err;
167 con.query("SELECT * from `DQ_TEST` WHERE wlkey = '"+args[2]+"'", function (err, result, fields) {
168 if (err) throw err;
169 //console.log(result);
170 if (result.length > 0) {
171 if (result) {
172 console.log("admin getting information on: " + args[2])
173 msg.author.send('Key Information for ' + args[2] +'\nKey: ' + result[0].wlkey + "\nIP: " + result[0].ip + "\nID: " + result[0].userid)
174
175 } else {
176 msg.reply('error')
177 }
178 } else {
179 msg.reply("Nobody claimed that key or key doesn't exist")
180 }
181
182 });
183 });
184 con.on('error', function() {});
185}
186
187function makeKey(k) {
188 var con = mysql.createConnection(db_config);
189 con.connect(function(err) {
190 if (err) throw err;
191 con.query("INSERT INTO DQ_TEST (wlkey) VALUES ('"+k+"');", function (err, result, fields) {
192 if (err) throw err;
193 console.log("Creating Key")
194 writeKeyToFile(k)
195 //console.log(result);
196 });
197 });
198 con.on('error', function() {});
199
200}
201
202function removeKey(args, msg) {
203 var con = mysql.createConnection(db_config);
204 con.connect(function(err) {
205 if (err) throw err;
206 con.query("DELETE FROM DQ_TEST WHERE wlkey = '"+args[1]+"'", function (err, result, fields) {
207 if (err) throw err;
208 console.log("Removing Key")
209 msg.author.send("key removed")
210 });
211 });
212 con.on('error', function() {});
213
214}
215
216function resetFailed(args, msg) {
217 var con = mysql.createConnection(db_config);
218 con.connect(function(err) {
219 if (err) throw err;
220 con.query("DELETE FROM DQ_TEST_FAIL WHERE ip = '"+args[1]+"'", function (err, result, fields) {
221 if (err) throw err;
222 console.log("Reseting failed attempts")
223 msg.author.send("Attempts removed")
224 });
225 });
226 con.on('error', function() {});
227
228}
229
230const Shoppy = require('Shoppy.gg');
231const API = new Shoppy.API("hideen")
232
233function getShoppyFromID(args, msg) {
234API.getSpecificOrder(args[2])
235 .then(data => {})
236 .catch(items => {
237 if (items !== undefined) {
238 if (items.accounts !== undefined) {
239 console.log("Getting shoppy info: "+items.accounts[0].account);
240 if (items.accounts.length == 1) {
241 msg.author.send(items.accounts[0].account)
242 }
243 if (items.accounts.length == 0) {
244 msg.author.send('nothing was sent, shoppy sucks. the key is most likely just taking a while to come')
245 }
246 if (items.accounts.length > 1) {
247 msg.author.send('multiple keys were sent, weird')
248 }
249 } else
250 {
251 msg.author.send("not real order id, or maybe key wasnt sent yet (shoppy being slow)")
252 }
253 } else {
254 msg.author.send("not a real orderid")
255 }
256 });
257}
258
259function generateKey(length) {
260 var result = '';
261 var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
262 var charactersLength = characters.length;
263 for ( var i = 0; i < length; i++ ) {
264 result += characters.charAt(Math.floor(Math.random() * charactersLength));
265 }
266 return result;
267}
268function isValidIpv4Addr(ip) {
269 return /^(?=\d+\.\d+\.\d+\.\d+$)(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\.?){4}$/.test(ip);
270}
271
272client.on('ready', () => {
273 console.log(`Logged in as ${client.user.tag}!`);
274});
275
276client.on('message', msg => {
277 if (msg.author.bot) return;
278 var args = msg.content.split(" ")
279 if (msg.author.id === '6466066759267123201') {
280 msg.reply("shut the fuck up")
281 return
282 }
283 if (msg.author.id === '84342404328456192' && args[0] == "km") {
284 const k = generateKey(25)
285 msg.reply(k);
286 makeKey(k)
287 } else
288 if (msg.author.id === '84342404328456192' && args[0] == "kr") {
289 removeKey(args, msg)
290 } else
291 if (args[0] == "ip") {
292 if (args[1] === undefined) {
293 msg.reply('Missing arguments.\nExample usage: ip 127.0.0.1')
294 } else
295 if (args[1].length > 20) {
296 msg.reply('not valid input')
297 } else
298 {
299 if (isValidIpv4Addr(args[1])) {
300 onChatIp(args, msg)
301 } else
302 {
303 msg.reply("Not a valid IP address!\n Example IP address: 192.168.0.1")
304 }
305 }
306 } else
307 if (args[0] == "id") {
308 if (args[1] === undefined) {
309 msg.reply('Missing arguments.\nExample usage: id 38248394')
310 } else
311 if (args[1].length > 20) {
312 msg.reply('not valid input')
313 } else
314 {
315 onChatId(args, msg)
316 }
317 } else
318 if (args[0] == "key") {
319 if (args[1] === undefined) {
320 msg.reply('Missing arguments.\nExample usage: key jvoawjopsdfj')
321 } else
322 if (args[1].length > 25) {
323 msg.reply('not valid input')
324 } else
325 {
326 onChatKey(args, msg)
327 }
328 } else
329
330 if (args[0] == "getinfo") {
331 onChatGetInfo(args, msg)
332 } else
333 if (args[0] == "agetinfo") {
334 if (msg.member) {
335 if (msg.member.roles.cache.find(r => r.name === "Admin")) {
336 if (args[1] === undefined) {
337 msg.reply('Missing arguments.\nExample usage: agetinfo key jvoawjopsdfj')
338 } else
339 if (args[1] == "id") {
340 onChatAdminGetInfoFromId(args, msg)
341 } else
342 if (args[1] == "key") {
343 onChatAdminGetInfoFromKey(args, msg)
344 }
345 if (args[1] == "shoppy") {
346 getShoppyFromID(args, msg)
347 }
348 }
349 }
350 } else
351 if (args[0] == "rank") {
352 if (msg.guild === null) {} else {onChatRank(args, msg)}
353 }
354});
355
356
357client.login('token hidden');