Skip to content

Commit

Permalink
Merge pull request #12 from iArxic/production
Browse files Browse the repository at this point in the history
"Currently testing" + icons
  • Loading branch information
iArxic authored Dec 22, 2022
2 parents 31f9a7f + 9345fbf commit 5aa9192
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 57 deletions.
87 changes: 42 additions & 45 deletions src/client/src/generators/activityCreator.luau
Original file line number Diff line number Diff line change
@@ -1,63 +1,60 @@
local activityCreator = {}
local activityCreator = {};

local StudioPresence = script:FindFirstAncestor("StudioPresence")
local StudioPresence = script:FindFirstAncestor("StudioPresence");

local Activity = require(StudioPresence.src.activity).new()
local FormatString = require(StudioPresence.src.generators.formatString)
local Data = require(StudioPresence.src.dataHandler)
local StudioService = game:GetService("StudioService")
local Activity = require(StudioPresence.src.activity).new();
local FormatString = require(StudioPresence.src.generators.formatString);
local Data = require(StudioPresence.src.dataHandler);
local StudioService = game:GetService("StudioService");

function eval(item)
if item == "" then
return false
end
if item == nil then
return false
end
if item == false then
return false
end
if item == 0 then
return false
end
if pcall(function()
return #item
end) and #item == 0 then
return false
end
return true
end
if item == "" then return false end;
if item == nil then return false end;
if item == false then return false end;
if item == 0 then return false end;
if pcall(function() return #item end) and #item == 0 then return false end;
return true;
end;

function activityCreator:Get()
local savedDescription = Data:Get("Description")
local savedState = Data:Get("State")

local savedDescription = Data:Get("Description");
local savedState = Data:Get("State");
local active = StudioService.ActiveScript
local editing = "StudioPresence by iArxic"
local description = "Developing"
if active ~= nil then
description = "Editing " .. active.Name .. " (" .. #string.split(active.source, "\n") .. " lines)"
local smallImageKey, smallImageDesc = "",""
if active~=nil then
description = "Editing "..active.Name.." ("..#string.split(active.source,"\n").." lines)"
end
if active == nil then
if active==nil then
active = "studio"
elseif active:IsA("ModuleScript") then
editing = "Editing a MODULE Script"
active = "modulescript"
active="modulescript"
elseif active:IsA("LocalScript") then
editing = "Editing a CLIENT Script"
active = "clientscript"
editing="Editing a CLIENT Script"
active="clientscript"
elseif active:IsA("Script") then
editing = "Editing a SERVER Script"
active = "serverscript"
editing="Editing a SERVER Script"
active="serverscript"
end

Activity:clear()
if game:GetService("RunService"):IsRunning() then
editing="StudioPresence by iArxic"
active="studio"
description="Currently play-testing"
smallImageKey="playtesticon"
smallImageDesc = "Currently play-testing"
end
Activity
:clear()
:setDescription(description)
:setState(FormatString:process("Workspace: $WORKSPACE"))
:setImage(active, editing)
:setTimer()

return Activity
end

return activityCreator
:setThumbnail(smallImageKey,smallImageDesc)
:setImage(active,editing)
:setTimer();

return Activity;
end;

return activityCreator;
30 changes: 18 additions & 12 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ async function login(drpcClient: drpc.Client) {
} finally {
if (!user) {
console.log(chalk.red("DRPC failed to start (Is Discord open?)"));

process.exit(1);
} else {
console.log(chalk.green("DRPC started"));
}
Expand All @@ -27,8 +25,7 @@ async function login(drpcClient: drpc.Client) {

async function main() {
const drpcClient = new drpc.Client({ transport: "ipc" });
let lastStudioEdit = Date.now();

let lastTesting = 0
login(drpcClient);

http
Expand All @@ -40,29 +37,38 @@ async function main() {
});

req.on("end", () => {
lastStudioEdit = Date.now();

try {
let passThrough = true
data = JSON.parse(data).activity;
if (!data) {drpcClient.clearActivity()}else{
if (data.details=="Currently testing"){
lastTesting=Date.now()
}else if((Date.now()-lastTesting)<3000) {
// i wish i could just use a return here
passThrough=false
}
if (passThrough==true){
drpcClient.setActivity({
details: data.details,
startTimestamp: data.timestamps.start,
state: data.state,
largeImageText: data.assets.large_text,
largeImageKey: data.assets.large_image,
smallImageText: data.assets.small_text,
smallImageKey: data.assets.small_image
});

if (data.updateType === "CLOSE") {
drpcClient.destroy()
main()
drpcClient.clearActivity()
}


}}
res.writeHead(200, { "Content-Type": "text/plain" });
res.end("SET Activity");
} catch (err: any) {
console.log(err)
drpcClient.clearActivity()
try {
drpcClient.destroy();
main()
} catch (err: any) {
console.log("Failed to clear activity: " + err.message);
}
Expand All @@ -72,4 +78,4 @@ async function main() {
.listen(SERVER_PORT);
}

main();
main();

0 comments on commit 5aa9192

Please sign in to comment.