Wordpress / PHP Generated Pages

output
lists
quotes
points
commands

#21

You’d need more for that. As it stands, it just pulls information from the database read only. For points, you’d need a way for people to identify themselves to your site and the bot as well. You’d basically be needing to recreate everything Twitch logon already does. Though you might be able to integrate it somehow. Would be a project on it’s own though.


#22

I cut the script down to what I thought would be the ‘bare minimal’ but I’m still not getting results. I don’t really know how to use postman for testing something like this.

This is what I was using:

 <?php
 	ini_set('display_errors', 1);
 	ini_set('display_startup_errors', 1);
 	error_reporting(E_ALL);
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_HTTPHEADER, array(
             'webauth: [auth]'
     ));
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     
     // Get Commands
     curl_setopt($curl, CURLOPT_URL, 'localhost:25000/dbquery?table=command&getKeys');
     $results = curl_exec($curl);
     curl_close($curl);
	echo 'RESULTS: ' . $results;
 ?>

#23

Anytime I run the points/quotes code, the page times out (php execution time is 90 seconds) and causes the bot to hang requiring a reboot.

Ideas/suggestions? The commands code works just fine.


#24

I figured this out, I didn’t notice I copied https :stuck_out_tongue:


#25

Before posting anything make sure you’re using https://github.com/jaredkotoff/phantombot-webpage-scripts
If you have an issue please post it on github rather than this thread.


#26

I can delete the comment later but, would you like this thread locked and noted to please go to the GitHub link that you mention? If you feel that it would help you to better manage your script and support for it, please let me know.

Cheers


#27

I think it’s ok to leave it open for discussion or ideas. Thanks!


#28

Hey @UpDownLeftDie

this Site is awesome i search something like that for me.
Is this at the top the whole Site or just the Quotes? I am a noob in business :smiley:
What i need, that it works?

thx a lot for help :slight_smile:

Sicfragger


#29

I’m not really sure what you mean by that. The first post was just the quotes but please read the edit i added. I updated some of the functions and moved everything to github.
You just need a php server that can run the php script on an interval with cron or you can manually run it and upload the json outputs yourself. Everything you need should be on the github.


#30

ok thx i try it :slight_smile:


#31

UpDownLeftDie wouldnt the post below help so you dont have to save the json and u can just pull live data??? getAllRows instead of getKeys then you wouldnt need to ping the bot twice??? my code may not be clean but it works :slight_smile:

<?php
	//Read the API for the user!
	$url = 'http://[boturl]/dbquery?table=points&getSortedRowsByValue';
	// create curl resource
	$ch = curl_init();
	// set url
	curl_setopt($ch, CURLOPT_URL, $url);
	// set headers
	curl_setopt($ch, CURLOPT_HTTPHEADER, array('webauth: [authkey]'));
	//return the transfer as a string
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	// $output contains the output string
	$output = curl_exec($ch);
	// close curl resource to free up system resources
	curl_close($ch);
	//Output the final result!
	$arr = json_decode($output, true);

	$info = $arr['table']['results'];
?>
	<table style="margin-top: -5px;" class="table reload table-condensed">

<?php
    if($info) {
?>
	<thead>
	    <tr>
	        <th style="border-bottom: 1px solid #ddd; width=10%;">No.</th>
	        <th style="border-bottom: 1px solid #ddd; width=10%;">User</th>
	        <th style="border-bottom: 1px solid #ddd; width=10%;">Points</th>
	    </tr>
	</thead>
<?php } ?>
	<tbody>
<?php
	$number = 1;
	foreach ($info as $k => $results) {
		$key = $results['key'];
		$value = $results['value'];
		echo '<tr>
            <td>'. $number++ .'</td>
            <td>'. $key .'</td>
            <td>'. $value .'</td>
        </tr>';
	}

?>
	</tbody>
	</table>
<?php

	curl_close($curl);
?>

#32

I think when i started writing these those enhancements weren’t in the stable build and I didnt see these changes yet so thanks for bringing it to my attention.
It does look like I can replace the two calls with just one, which is going to be really good for latency. Another user told me it took a very long time to run against a large pool of users.
I’ll try to push changes to the github when i get time, pull requests are also welcome.


#33

Are you wanting to stick with the cron jobs way or live? cus i can work on the conversion on github and do a pull request :slight_smile:


#34

Still probably going to stick with the cron job. This way the user is able to control how often their bot is being hit.
The concern is popular streamers might have large volumes of traffic and I wouldn’t want it to impact the performance of the bot.
If you want to submit it as an alternative though we can, it just seems risky to me. Although it should be easy enough for anyone that wants that to just take the code from the cron script and merge it into the php themselves.


#35

Good idea ill work on it for a bit i may also make a version that will only update if the streamer is offline if that helps :slight_smile:


#36

Finally got around upgrading the API requests.


#37

Is there a way this could be used for users time (not points) but have the outputted time in years/months/days/hours/mins instead of seconds?


#38

you mean like i did here https://www.alixe.pro/leaderboard


#39

yes exactly like that.


#40

Add the following function and change the $value to secondsToHumanReadable($value) and boom you got it :slight_smile:

function secondsToHumanReadable($seconds) {
    $dtF = new \DateTime ( '@0' );
    $dtT = new \DateTime ( "@$seconds" );
    $ret = '';
    if ($seconds == 0) {
        return '0 seconds';
    }
    $diff = $dtF->diff ( $dtT );
    foreach ( array (
            'y' => 'year',
            'm' => 'month',
            'd' => 'day',
            'h' => 'hour',
            'i' => 'minute',
            's' => 'second'
    ) as $time => $timename ) {
        if ($diff->$time !== 0) {
            $ret .= $diff->$time . ' ' . $timename;
            if ($diff->$time !== 1 && $diff->$time !== -1 ) {
                $ret .= 's';
            }
            $ret .= ' ';
        }
    }
    return substr ( $ret, 0, - 1 );
}