PDA

View Full Version : SRL-6 Messaging System



Clarity
05-02-2015, 04:27 PM
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:

http://i.gyazo.com/f7a98ceaa7de5e06a1f327f0c234cf0c.png
http://i.gyazo.com/205d65bb1678ed51db5a593082de3c68.png

Supported Commands:
!reply [Username] Message
!reply [Public] Message
!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:

http://i.gyazo.com/a0731f448daf38dd3c414d37633e1198.png

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

# Based on a script by Sha1Sum, modified by Clarity

class 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
$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
$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.";
}
}
?>





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



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.


Include Download: 25771

Enjoy! Please help me make this better by reporting any bugs or issues :)

Credits:
Justin for helping me test PMing on him all night.

rj
05-02-2015, 04:37 PM
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;

Hitac
05-02-2015, 06:27 PM
Wow. You sir are epic.

Incurable
05-02-2015, 07:51 PM
This is amazing, very well done.

Lipcot
05-02-2015, 07:56 PM
http://puu.sh/hz1nD/c993c5251b.jpg

this guy is on fire

J_R
05-02-2015, 08:17 PM
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

Clarity
05-02-2015, 11:53 PM
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!


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 :)

acow
05-03-2015, 02:29 AM
seems like a lot of work when you could just...
http://i.imgur.com/ZRGBqvy.png

Clarity
05-03-2015, 04:04 AM
seems like a lot of work when you could just...
http://i.imgur.com/ZRGBqvy.png

I will consider this advice but it may not be implemented.

The Mayor
05-03-2015, 07:40 AM
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.

http://puu.sh/hzC4m/a46a2f51f7.png