Pulling player all players' points info from the database into a text file manually, maybe?

PhantomBot Version:
OS Version: Windows 10 64bit
Java Version:
Browser and Version (for Panel Support): Chrome Latest
Stock PhantomBot: Yes

I guess this is a bit of a feature request, I don’t know. I realize the Data Render Service exists, however I need something more on-demand and DRS is a tad too slow for what I need (and I 100% undestand why).

What I’m trying to do is to add an on-stream leaderboard of the people on the channel with the most points. I realize there is a command for that but it’s a bit cluttered for Twitch chat IMO which is why I would prefer it that way. I’m expecting a large amount of points usage from viewers, so it would need to be updated every 5 minutes or so. Since it’s for OBS to read, it could be parsed to a simple text file; I believe that would be the easier route. I also know there’s a high CPU usage in this; I personally think it won’t be a problem.

What do you guys think, is this possible? I don’t mind trying my hand on scripting it, I just need a pointer to the right direction I think.

What I personally did was I created a php script on my website and used JavaScript to make ajax requests to the script.

With use of the HTTP API for the database, you can basically pull any info from your database file.

But if you’d like it to be in a text file, it’s possible. You’d just need to create a custom script or modify the pointSystem (or top command system) to include a timer to write to the file every X.

Do you believe writing a custom script would be simpler? I’ll have a look at how pointSystem works

It’d probably be easier to modify the top command because it does all the legwork for you, all you’d have to do is make it write to the file.

I tried setting up a PrintWriter but it gives me this error:

[02-21-2019 @ 15:20:11.245 GMT] [ERROR] [loadScript()@ScriptManager.java:46] Failed to load module: .\scripts\.\commands\topCommand.js: JavaScript Error: missing ; before statement (topCommand.js#8)
[02-21-2019 @ 15:20:11.246 GMT] [ERROR] [loadScript()@ScriptManager.java:49] Terminating PhantomBot due to Bad JavaScript File

Am I not allowed to use Java functions? I don’t think there’s a JS function to write to a file…

That error specifically means you have a bad JavaScript file, due to a missing ‘;’ in the topcommand.js. Once you correct that you can verify if your script is functional or not.

Weird address

I have just added this single line of code for testing:
PrintWriter writer = new PrintWriter(“test.txt”);
No other edits to topcommand.js. The semicolon is right there. I don’t see where the issue is…

I don’t know why cmd is displaying the address like that. I also haven’t touched the script directories.

Download this topCommand.js (5.7 KB)

PS: It will follow the rules of !topamount [number]

You can edit listfile.push(keys[i] + ': ' + $.inidb.get(iniName, keys[i])); for the format you want

1 Like

Rhino does allow for Java to be intermingled, just not using straight Java. You have to use something like the following:

    var printWriter = new Packages.java.io.PrintWriter("addons/printwriter.txt");
        printWriter.print("This is some text");

First, you instantiate a JavaScript object. Then you can use methods from that JavaScript object. Note the full namespace is required as well as “Packages.”

Then the output file:

[morpheus] /opt/iobot
illusion% cat addons/printwriter.txt
This is some text

That said, use what Dakoda specifies, it works and uses the APIs that PhantomBot provides. I just wanted to point out the root cause of the original issue.

1 Like

Worked like a charm man, thank you so much! And thanks @IllusionaryOne for the tips as well. I should’ve read up a lot more on this :stuck_out_tongue:

1 Like

Hey guys. I just noticed setInterval might not be working. It runs the function the first time and also whenever someone does !top, so the function itself works fine. Tried setting the time to miliseconds but no luck. Any ideas on what I can try?

change it to setInterval(function() { getTop5('points')}, 5e5);

1 Like

Funny enough I just figured that out when you posted that answer! You need to use an anonymous function because of the parameter :stuck_out_tongue:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.