diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6a7d6d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,130 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp +.cache + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..89d9cb6 --- /dev/null +++ b/index.js @@ -0,0 +1,122 @@ +require('dotenv').config(); +const discordToken = process.env.token; +const myRL = require("serverline"); +const axios = require("axios"); + +if(!discordToken) { + console.error("No discord token provided in environment variables"); + process.exit(1); +} + +process.title = `DiscordMobilePlayingCLI - Idle`; + +myRL.init(); +myRL.setCompletion(['start', 'stop', 'set', 'update', 'exit']); +myRL.setPrompt('> '); + +let isStarted = false; +let currentPackageName; +let refreshInterval; + +myRL.on('line', async (line) => { + const args = line.split(' '); + + switch (args[0]) { + case 'start': + if(isStarted) { + console.log("Already started"); + return; + } + if(!currentPackageName) { + console.error('No package name set'); + return; + } + console.log('Starting...'); + await setStatus(currentPackageName, "START"); + isStarted = true; + createRefreshInterval(); + break; + case 'stop': + if(!isStarted) { + console.error('Not started'); + return; + } + if(!currentPackageName) { + console.error('No package name set'); + return; + } + console.log('Stopping...'); + await setStatus(currentPackageName, "STOP"); + isStarted = false; + clearInterval(refreshInterval); + process.title = `DiscordMobilePlayingCLI - Idle`; + break; + case 'set': + if(!args[1]) { + console.error("No package name provided"); + return; + } + console.log(`Setting... ${args[1]}`); + currentPackageName = args[1]; + break; + case 'update': + if(!isStarted) { + console.error('Not started'); + return; + } + if(!currentPackageName) { + console.error('No package name set'); + return; + } + console.log('Updating...'); + process.title = `DiscordMobilePlayingCLI - Running - ${currentPackageName}`; + await setStatus(currentPackageName, "UPDATE"); + break; + case 'exit': + if(isStarted) { + console.log("Stoping..."); + await setStatus(currentPackageName, "STOP"); + } + process.exit(0); + break; + default: + console.log('Unknown command'); + break; + } +}); + + +function createRefreshInterval() { + if(refreshInterval) + clearInterval(refreshInterval); + + process.title = `DiscordMobilePlayingCLI - Running - ${currentPackageName}`; + + refreshInterval = setInterval(async () => { + if(!isStarted) return; + console.log('Updating...'); + await setStatus(currentPackageName, "UPDATE"); + }, 5 * 60 * 1000); +} + +async function setStatus(packageName, update) { + if(!currentPackageName) { + console.error('No package name set'); + return; + } + try { + await axios.post(`https://discord.com/api/v6/presences`, { + 'package_name': packageName, + 'update': update + }, { + headers: { + 'Authorization': discordToken, + 'User-Agent': 'Mozilla/5.0 (Linux; Android 11) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/100.0.4896.127 Mobile OceanHero/6 Safari/537.36', + 'Content-Type': 'application/json', + 'Cache-Control': 'max-age=121', + } + }); + } catch (err) { + console.error(err.message); + } +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..8121120 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "discordmobileplayingcli", + "version": "1.0.0", + "main": "index.js", + "author": "Yuzu ", + "license": "GPL-3.0", + "dependencies": { + "axios": "^0.27.2", + "dotenv": "^16.0.0", + "serverline": "^1.6.0" + } +} diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..779933d --- /dev/null +++ b/yarn.lock @@ -0,0 +1,71 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@types/node@^16.11.12": + version "16.11.33" + resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.33.tgz#566713b1b626f781c5c58fe3531307283e00720c" + integrity sha512-0PJ0vg+JyU0MIan58IOIFRtSvsb7Ri+7Wltx2qAg94eMOrpg4+uuP3aUHCpxXc1i0jCXiC+zIamSZh3l9AbcQA== + +asynckit@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" + integrity sha1-x57Zf380y48robyXkLzDZkdLS3k= + +axios@^0.27.2: + version "0.27.2" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972" + integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ== + dependencies: + follow-redirects "^1.14.9" + form-data "^4.0.0" + +combined-stream@^1.0.8: + version "1.0.8" + resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" + integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== + dependencies: + delayed-stream "~1.0.0" + +delayed-stream@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" + integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk= + +dotenv@^16.0.0: + version "16.0.0" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.0.tgz#c619001253be89ebb638d027b609c75c26e47411" + integrity sha512-qD9WU0MPM4SWLPJy/r2Be+2WgQj8plChsyrCNQzW/0WjvcJQiKQJ9mH3ZgB3fxbUUxgc/11ZJ0Fi5KiimWGz2Q== + +follow-redirects@^1.14.9: + version "1.15.0" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.0.tgz#06441868281c86d0dda4ad8bdaead2d02dca89d4" + integrity sha512-aExlJShTV4qOUOL7yF1U5tvLCB0xQuudbf6toyYA0E/acBNw71mvjFTnLaRp50aQaYocMR0a/RMMBIHeZnGyjQ== + +form-data@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" + integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.8" + mime-types "^2.1.12" + +mime-db@1.52.0: + version "1.52.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70" + integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg== + +mime-types@^2.1.12: + version "2.1.35" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a" + integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw== + dependencies: + mime-db "1.52.0" + +serverline@^1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/serverline/-/serverline-1.6.0.tgz#e88e8aa3474b4971bc5940d56dd2bb07fe50a485" + integrity sha512-Y6c+EhD3d1WR+h1ORnb15zyskC5WoDHEkOJ1CCqyTl20+K4byKs8GP2Rn7kyDh4kQaNUOtSYBjSkLVY0q+KjrQ== + dependencies: + "@types/node" "^16.11.12"