-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
1 lines (1 loc) · 3.04 KB
/
index.js
1
const axios = require('axios'); const fs = require('fs'); const WebSocket = require('ws'); let login = false; let config; config = JSON.parse(fs.readFileSync('config.json', 'utf8')); function color(message, color) { return `\x1b[37m[\x1b[0m\x1b[${color}m${message}\x1b[0m\x1b[37m]\x1b[0m`; } function color2(message, color) { return `\x1b[37m\x1b[0m\x1b[${color}m${message}\x1b[0m\x1b[37m\x1b[0m`; } async function m(id, token) { try { const r = await axios.get(`https://discord.com/api/v9/channels/${id}/messages?limit=${config.log_message}`, { headers: { 'Authorization': `${token}` } }); return r.data; } catch (error) { console.error(color('ERROR', '31'), error); return []; } } async function status(ws, token, config) { const l = config.device_spoof === 'pc' ? 'linux' : 'Discord Android'; ws.send(JSON.stringify({ op: 2, d: { token: token, properties: { $os: l, $browser: l, $device: l }, presence: { status: config.status || 'online', since: 0, activities: [], afk: false } } })); } function number(content) { return /^\d+$/.test(content); } async function count() { try { config = JSON.parse(fs.readFileSync('config.json', 'utf8')); } catch (error) { console.error(color('ERROR', '31'), error); return; } const token = config.token; const id = config.channel_id; const messages = await m(id, token); let e = 0; let bot = false; for (let i = 0; i < messages.length; i++) { const w = messages[i]; if (number(w.content)) { e = parseInt(w.content); break; } } if (messages[0].author.bot) { bot = true; } else { bot = false; } if (bot && config.reset_on_bot_message) { e = 0; } if (config.counting5250) { const user_info = await axios.get('https://discord.com/api/v9/users/@me', { headers: { 'Authorization': `${token}` } }); let z = false; for (let i = 0; i < messages.length; i++) { const w = messages[i]; if (number(w.content)) { if (w.author.id === user_info.data.id) { z = true; break; } else { z = false; break; } } } if (z) { console.log(color('WAITING', '33'), 'Waiting for someone else to send the next number.'); return; } } try { const i = await axios.post(`https://discord.com/api/v9/channels/${id}/messages`, { content: e + 1, tts: false }, { headers: { 'Authorization': `${token}`, 'Content-Type': 'application/json' } }); if (!login) { console.log(color2(`Made by shwp`, '35')); console.log(color2(`You have been logged in as ${i.data.author.username} (${i.data.author.id})`, '37')); } login = true; console.log(color('OK', '32'), `The count is now at ${i.data.content}`); } catch (error) { console.error(color('ERROR', '31'), error); } } (async () => { try { const token = config.token; const ws = new WebSocket('wss://gateway.discord.gg/?v=9&encoding=json'); ws.on('open', () => status(ws, token, config)); ws.on('message', async (data) => { const v = JSON.parse(data); const { op, d } = v; if (op === 10) { const { heartbeat_interval } = d; setInterval(() => { ws.send(JSON.stringify({ op: 1, d: null })); }, heartbeat_interval); } }); } catch (error) { console.error(color('ERROR', '31'), error); process.exit(1); } const speed = config.interval_speed; setInterval(count, speed); })();