Skip to content
This repository has been archived by the owner on Apr 19, 2021. It is now read-only.

Check if valorant is dropped #56

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ const cheerio = require('cheerio');
var fs = require('fs');
const inquirer = require('./input');
const treekill = require('tree-kill');
const axios = require('axios')

var run = true;
var firstRun = true;
var cookie = null;
var streamers = null;
var cookie;
var streamers;
var isDropped = false;
// ========================================== CONFIG SECTION =================================================================
const configPath = './config.json'
const screenshotFolder = './screenshots/';
Expand Down Expand Up @@ -57,15 +59,28 @@ const streamPauseQuery = 'button[data-a-target="player-play-pause-button"]';
const streamSettingsQuery = '[data-a-target="player-settings-button"]';
const streamQualitySettingQuery = '[data-a-target="player-settings-menu-item-quality"]';
const streamQualityQuery = 'input[data-a-target="tw-radio"]';
const listNotificationRaw = '{"operationName":"OnsiteNotifications_ListNotifications","variables":{"limit":3,"cursor":"","language":"en"},"extensions":{"persistedQuery":{"version":1,"sha256Hash":"b317b93ed481bf07c35defbcf01848f09744805ebb640734763298f9a7dfd64f"}}}'
// ========================================== CONFIG SECTION =================================================================


async function checkDrop(){
await axios.post('https://gql.twitch.tv/gql', listNotificationRaw, {headers: { Authorization: "OAuth " + cookie[0].value }}).then(
response=>{
isDropped = JSON.stringify(response.data.data.currentUser.notifications.edges).includes('You just received the **VALORANT**')
}
)
}

async function viewRandomPage(browser, page) {
var streamer_last_refresh = dayjs().add(streamerListRefresh, streamerListRefreshUnit);
var browser_last_refresh = dayjs().add(browserClean, browserCleanUnit);
while (run) {
try {
await checkDrop()
if (isDropped){
console.log('Valorant has been dropped')
await shutDown()
}

if (dayjs(browser_last_refresh).isBefore(dayjs())) {
var newSpawn = await cleanup(browser, page);
browser = newSpawn.browser;
Expand All @@ -74,6 +89,8 @@ async function viewRandomPage(browser, page) {
browser_last_refresh = dayjs().add(browserClean, browserCleanUnit);
}



if (dayjs(streamer_last_refresh).isBefore(dayjs())) {
await getAllStreamer(page); //Call getAllStreamer function and refresh the list
streamer_last_refresh = dayjs().add(streamerListRefresh, streamerListRefreshUnit); //https://github.com/D3vl0per/Valorant-watcher/issues/25
Expand Down Expand Up @@ -245,14 +262,11 @@ async function getAllStreamer(page) {
console.log('📡 Checking active streamers...');
await scroll(page, scrollTimes);
const jquery = await queryOnWebsite(page, channelsQuery);
streamers = null;
streamers = new Array();

streamers = []
console.log('🧹 Filtering out html codes...');
for (var i = 0; i < jquery.length; i++) {
streamers[i] = jquery[i].attribs.href.split("/")[1];
}
return;
}


Expand Down Expand Up @@ -366,4 +380,4 @@ async function main() {
main();

process.on("SIGINT", shutDown);
process.on("SIGTERM", shutDown);
process.on("SIGTERM", shutDown);
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"url": "https://github.com/D3vl0per/Valorant-watcher"
},
"dependencies": {
"axios": "^0.19.2",
"cheerio": "^1.0.0-rc.3",
"dayjs": "^1.8.24",
"dotenv": "^8.2.0",
Expand Down