Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralsin committed Jun 12, 2022
2 parents 890ee03 + e07daf6 commit c652287
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 31 deletions.
52 changes: 34 additions & 18 deletions src/js/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,43 @@ const { Client } = require('discord-rpc')
const { readFileSync, existsSync } = require('fs');
const { app } = require('electron');
const fetch = require('node-fetch')
const { execSync } = require('child_process');
let avatarUrl, userNames;
let latestId;
let latestId = 'none';
let data = new Date();
let connected = false;
async function getFromUrl(url) {
const result = await fetch(url)
const data = result.json();
return data;
}
async function updateProfile() {
const id = readFileSync(app.getPath('appData') + '\\rblxcord\\robloxId').toString();
const userFetch = await fetch('https://users.roblox.com/v1/users/' + id);
const user = await userFetch.json();
const user = await getFromUrl('https://users.roblox.com/v1/users/' + id);
userNames = { nick: user.displayName, name: user.name };
const avatarFetch = await fetch(`https://thumbnails.roblox.com/v1/users/avatar-headshot?userIds=${id}&size=60x60&format=Png`);
const avatar = await avatarFetch.json();
const avatar = await getFromUrl(`https://thumbnails.roblox.com/v1/users/avatar-headshot?userIds=${id}&size=60x60&format=Png`);
avatarUrl = avatar.data[0].imageUrl;
}
if (existsSync(app.getPath('appData') + '\\rblxcord\\robloxId')) updateProfile();

let Rblxcord;
class RblxcordCon {
clientId;
client;
isReady = false;
constructor(clientId) {
this.clientId = clientId;
this.client = new Client({ transport: 'ipc' });
this.client.once('ready', () => {
console.log('[DRP] Connected! Meow!');
this.isReady = true;
});
this.client.connect(this.clientId).catch(console.log);
this.client.login({ clientId: this.clientId }).catch(() => { this.destroy(); setTimeout(() => { Rblxcord = new RblxcordCon('983406322924023860'); }, 10e3) });
this.client.login({ clientId }).catch(() => { this.destroy(); setTimeout(() => { Rblxcord = new RblxcordCon('983406322924023860'); }, 10e3) });
}
setActivity(activity) {
if (!this.isReady) return false;
this.client.setActivity(activity);
return true;
}
clearActivity() {
if (!this.isReady) return;
this.client.clearActivity()
}
destroy() {
Expand All @@ -54,17 +54,19 @@ class RblxcordCon {
Rblxcord = new RblxcordCon('983406322924023860');

exports.refreshDiscord = async (placeJson) => {
if (placeJson == 'none' && connected) {
if (connected && placeJson == 'none') {
Rblxcord.clearActivity();
latestId = placeJson.id;
latestId = 'none';
console.log('[DRP] No activity... Meow!');
connected = false;
return false;
} else if (!connected && Rblxcord?.isReady || (latestId != placeJson.id && latestId != undefined && placeJson != 'none')) {
if (Rblxcord?.isReady) {
return Rblxcord.isReady
} else return false;
} else if (Rblxcord?.isReady && latestId != placeJson.id) {
console.log('[DRP] Setting activity... Meow!');
data = new Date();
let activity;
if (userNames) {
if (userNames && placeJson.name) {
activity = {
details: placeJson.name,
state: 'by ' + (placeJson.owner?.split('@')[1] || placeJson.owner),
Expand All @@ -74,19 +76,33 @@ exports.refreshDiscord = async (placeJson) => {
smallImageText: `${userNames?.nick} (@${userNames?.name})`,
startTimestamp: data
}
} else {
} else if (placeJson.name) {
activity = {
details: placeJson.name,
state: 'by ' + (placeJson.owner.split('@')[1] || placeJson.owner),
largeImageKey: placeJson.iconUrl,
largeImageText: placeJson.id,
startTimestamp: data
}
} else {
Rblxcord.clearActivity();
latestId = 'none';
console.log('[DRP] No activity... Meow!');
connected = false;
if (Rblxcord?.isReady) {
return Rblxcord.isReady
} else return false;
}
const activitySet = Rblxcord.setActivity(activity);
console.log(`${latestId} != ${placeJson.id}`);
connected = activitySet;
if (connected) latestId = placeJson.id;
return connected;
if (Rblxcord?.isReady) latestId = placeJson.id;
return Rblxcord?.isReady;
} else return false;
}

exports.isConnected = () => {
if (Rblxcord) {
return Rblxcord.isReady;
} else return false;
}
18 changes: 7 additions & 11 deletions src/js/getGame.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { execSync } = require('child_process')
const fetch = require('node-fetch')
const { refreshDiscord } = require('./discord.js')
const { refreshDiscord, isConnected } = require('./discord.js')

function getPlaceId() {
const cmd = execSync("C:\\Windows\\System32\\wbem\\wmic.exe process where \"Name='RobloxPlayerBeta.exe'\" get CommandLine /format:csv").toString();
Expand All @@ -9,27 +9,23 @@ function getPlaceId() {
}
async function getGameInfo(id, prevId) {
if (id == prevId) return { "meow": true }
if (id == 'none') return { id: 'none', connected: isConnected() }
const gaem = await fetch(`https://www.roblox.com/places/api-get-details?assetId=${id}`);
const info = await gaem.json();
const iconGaem = await fetch(`https://thumbnails.roblox.com/v1/assets?assetIds=${id}&size=250x250&format=Png&isCircular=false`);
const iconGaem = await fetch(`https://thumbnails.roblox.com/v1/assets?assetIds=${id}&size=250x250&format=Png`);
const icon = await iconGaem.json();
const json = {
id,
name: info.Name,
owner: info.Builder || "error",
owner: info.Builder,
iconUrl: icon.data[0].imageUrl,
connected: null
connected: isConnected()
}
return json;
}

module.exports.refreshGame = async (prevId) => {
const placeId = getPlaceId();
if (placeId == 'none') {
refreshDiscord(placeId);
return { connected: false };
}
const placeJson = await getGameInfo(placeId, prevId);
placeJson.connected = await refreshDiscord(placeJson);
const placeJson = await getGameInfo(getPlaceId(), prevId);
await refreshDiscord(placeJson);
return placeJson;
}
4 changes: 2 additions & 2 deletions src/meow.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ window.addEventListener('DOMContentLoaded', () => {
clearInterval(setTimer);
text2.innerText = 'Updating...';
const place = await window.api.refresh(true, latestId);
console.log(place);
if (place.meow) return console.log('Meow! Id\'s were the same so no changes was made!');
text0.innerText = 'Connected: ' + place.connected;
if (!place.id || !place.name || !place.owner) {
if (!place.id || place.id == 'none' || !place.name || !place.owner) {
text1.innerText = "Game: none";
icon.setAttribute('style', 'display:none');
latestId = 'disconnected';
} else {
Expand Down

0 comments on commit c652287

Please sign in to comment.