-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
1 lines (1 loc) · 3.38 KB
/
index.js
1
const axios=require('axios'),WebSocket=require('ws'),fs=require('fs'),config=JSON.parse(fs.readFileSync('config.json','utf8'));function color(m,c){return`\x1b[37m[\x1b[0m\x1b[${c}m${m}\x1b[0m\x1b[37m]\x1b[0m`}function color2(m,c){return`\x1b[37m\x1b[0m\x1b[${c}m${m}\x1b[0m\x1b[37m\x1b[0m`}function d(){return crypto.randomBytes(16).toString('hex')}const headers={'Accept':'application/json','Accept-Encoding':'gzip, deflate, br','Accept-Language':'en-US,en;q=0.9','Authorization':config.token,'Connection':'keep-alive','Host':'discord.com'};async function g(){try{const a=await axios.get(`https://discord.com/api/v9/guilds/${config.server_id}/application-command-index`,{headers});return a.data.application_commands}catch(e){throw new Error(`Error fetching command index: ${e.response?e.response.data:e.message}`)}}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:!1}}}))}async function b(c,o){const data={type:2,application_id:c.application_id,guild_id:config.server_id,channel_id:config.channel_id,session_id:Math.floor(Math.random()*9999999999999),data:{version:c.version,id:c.id,name:c.name,type:c.type,options:o,application_command:{id:c.id,type:c.type,application_id:c.application_id,version:c.version,name:c.name,description:c.description,dm_permission:!0,integration_types:c.integration_types,global_popularity_rank:c.global_popularity_rank,options:c.options,description_localized:c.description,name_localized:c.name},attachments:[]},nonce:Math.floor(Math.random()*9999999999999),analytics_location:"slash_ui"};try{await axios.post(`https://discord.com/api/v9/interactions`,data,{headers});console.log(color('OK','32'),`Command was run`)}catch(e){throw new Error(`Error running command: ${e.response?e.response.data:e.message}`)}}function s(p){if(!p.match(/^\/(\w+)/))throw new Error('invalid command string format. /<commandname>');const command_name=p.match(/^\/(\w+)/)[1],optionMatches=[...p.matchAll(/(\w+):(\w+)/g)],o=optionMatches.length>0?optionMatches.map(m=>{const[name,value]=[m[1],m[2]];return{name,value,type:3}}):[];return{command_name,o}}async function j(){try{const user_info=await axios.get('https://discord.com/api/v9/users/@me',{headers:{'Authorization':config.token}});console.log(color2(`Made by shwp`,'35')),console.log(color2(`You have been logged in as ${user_info.data.username} (${user_info.data.id})`,'37'));try{const token=config.token,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),{op,d}=v;if(op===10){const{heartbeat_interval}=d;setInterval(()=>{ws.send(JSON.stringify({op:1,d:null}))},heartbeat_interval)}})}catch(e){console.error(color('ERROR','31'),e),process.exit(1)}const{command_name,o}=s(config.command),commands=await g();if(Array.isArray(commands)){const command=commands.find(cmd=>cmd.name===command_name&&cmd.application_id===config.botid);command?await b(command,o):console.log(color('ERROR','31'),`command "${command_name}" not found.`)}else console.log(color('ERROR','31'),`Commands is not an array: ${commands}`)}catch(e){console.log(color('ERROR','31'),e.message)}}(async()=>{if(config.loop ==='loop')for(;;)await j(),await new Promise(r=>setTimeout(r,config.wait_time));else await j()})();