1. ## SRL-6 Messaging System

SRL-6 RS Messaging System

Version 1.0

This utility include file, when set up properly, will allow you to receive and respond to in-game PMs while your scripts are running via smartphone. You can also speak in public chat, remotely shut down your script, or log out. I am also working on screenshots of SMART being sent to your phone.

Example in action:

Supported Commands:
!logout
!terminate

More commands will be added soon

Setup Instructions:
You will need to have a web server with mySQL and PHP support. If you do not have this, I am happy to provide a mySQL table for you from my own!

These scripts assume a mySQL table (titled "Communicator") layout like so:

Here are the PHP scripts I used. I'm a PHP novice, so I'm sure there are better/more optimal ways of doing this, but it worked for me so I was satisfied. I welcome any feedback.

PHP Script - GroupMe Handler

PHP Code:
 <?php# Based on a script by Sha1Sum, modified by Clarityclass GroupMeBot {    public $group,$id, $user_id,$group_id;        public function __construct($id) {$this->id = $id; } public function post($message) {        $post_text = utf8_encode($message);                $ch = curl_init();$post_contents = array(            'bot_id' => $this->id, 'text' =>$post_text,        );                $post = json_encode($post_contents);                $arr = array(); array_push($arr, 'Content-Type: application/json; charset=utf-8');        curl_setopt($ch, CURLOPT_HTTPHEADER,$arr);        curl_setopt($ch, CURLOPT_URL, 'https://api.groupme.com/v3/bots/post'); curl_setopt($ch, CURLOPT_POST, true);        curl_setopt($ch, CURLOPT_POSTFIELDS,$post);        curl_exec($ch); curl_close($ch);    }}$bot = new GroupMeBot('Your GroupMe Bot ID Here');$msg_json = file_get_contents('php://input');$msg = json_decode($msg_json);$user_id =$msg->user_id;$group_id =$msg->group_id;$inquirer_name =$msg->name;$from =$msg->name;$text =$msg->text;if (!substr($text, 0, 1) == '!') exit();$available_keywords = array(    'reply',    'logout',    'terminate');$no_trigger = strtolower(substr($text, 1));$unstripped_keywords = explode(' ',$no_trigger);$keywords = array();foreach ($unstripped_keywords as $keyword) {$keywords[] = trim($keyword, ' ,');}if (in_array('reply',$keywords) || in_array('logout', $keywords) || in_array('terminate',$keywords)) {        $username = "mySQL username";$password = "mySQL password";      $database = "mySQL database";$server = "mySQL server address";          $db_handle = mysql_connect($server, $username,$password);     $db_found = mysql_select_db($database, $db_handle); if ($db_found) {         $SQL = "SELECT * FROM Communicator WHERE ID = 1";$result = mysql_query($SQL); if($result){                 $SQL = "UPDATE Communicator SET Reply = '".$text."' WHERE ID = 1";                $result = mysql_query($SQL);                 if($result) print "Success - command added."; else print "Failure - command was not added."; } } }?>  PHP Script - Reply PHP Code:  <?php$username = "mySQL username";      $password = "mySQL password";$database = "mySQL database";    $server = "mySQL server address";$db_handle = mysql_connect($server,$username, $password);$db_found = mysql_select_db($database,$db_handle);      if ($db_found) {$SQL = "SELECT * FROM Communicator WHERE ID = 1";        $result = mysql_query($SQL);            if($result){ while ($db_field = mysql_fetch_assoc($result)){$reply = $db_field['Reply']; } if($result)                             print "$reply"; else print "Failure."; } } ?>  PHP Script - Clear PHP Code:  <?php$username = "mySQL username";      $password = "mySQL password";$database = "mySQL database";    $server = "mySQL server address";$db_handle = mysql_connect($server,$username, $password);$db_found = mysql_select_db($database,$db_handle);       if ($db_found) {$SQL = "SELECT * FROM Communicator WHERE ID = 1";        $result = mysql_query($SQL);            if($result){$SQL = "UPDATE Communicator SET Reply = '".$command."' WHERE ID = 1";$result = mysql_query($SQL); if($result)                             print "Success - commands cleared.";                         else                             print "Failure - commands were not cleared.";            }                  }?> 

1. Download the free app GroupMe (https://groupme.com/) for your smartphone. This can also be used on a computer via https://app.groupme.com/signin.
2. Create a new group chat titled "SRL Communicator" or something similar.
3. Navigate to https://dev.groupme.com/bots and follow the steps to create a bot, selecting your new group chat as the bot's residency.
4. Place the three PHP scripts somewhere where Simba and GroupMe will be able to access them.
5. Set the Callback URL as your PHP GroupMe handler script location on your server.
6. Remember your Bot ID, and place it inside the first script (GroupMe Handler) as indicated.
8. Use the test script below to try it out! Have a conversation with an alternate account of yours

Simba Code:
program communicatorTest;{$DEFINE SMART}{$i srl-6/srl.simba}{\$i srl-6/lib/misc/communicator.simba}begin  smartEnableDrawing := True;  setupSRL();  communicator.setup(10,                                 //No. of lines to scan    '<Your GroupMe Bot ID Here>',                        //BotID    'http://www.srlclarity.com/communicator/reply.php',  //ReplyPHPScriptURL    'http://www.srlclarity.com/communicator/clear.php'); //ClearPHPScriptURL  repeat    communicator.updateGroupMe();    communicator.processCommands();    wait(random(5000, 10000));  until false;end.

Credits:
@Justin for helping me test PMing on him all night.
Last edited by Clarity; 05-02-2015 at 04:43 PM.

2. This looks pretty neat + rep

BTW instead of making a record for TCommunicator you can make it a custom type (does the same thing but you don't have the access the field or whatever)

Type
TCommunicator = boolean;

3. SRL Junior Member
Join Date
Dec 2014
Posts
188
Mentioned
3 Post(s)
Quoted
100 Post(s)
Wow. You sir are epic.

4. This is amazing, very well done.

5. this guy is on fire

6. J_R
SRL Member
Join Date
May 2014
Posts
633
Mentioned
8 Post(s)
Quoted
322 Post(s)
Epic, maybe I will turn pm on now

Also a further extension of this would be to have it be able to respond when you are mentioned in clan chat

7. Indeed, I am working on many more commands and features for more than private messaging!
Thanks for the feedback everyone, I hope you find this useful!

Originally Posted by rj
BTW instead of making a record for TCommunicator you can make it a custom type (does the same thing but you don't have the access the field or whatever)

Type
TCommunicator = boolean;
Thanks, I didn't know that. Will update
Last edited by Clarity; 05-03-2015 at 01:49 AM.

8. seems like a lot of work when you could just...

9. Originally Posted by No Lifer
seems like a lot of work when you could just...
I will consider this advice but it may not be implemented.

10. Very nice idea! You know what would be cool, rather than just having reply/login/logout, the user could create their own 'response' and assign a procedure to the response. E.g., if you get a screenshot of a stuck bot you can tell it to reset itself, or you can tell it to bank when you want it to, etc.