Skip to content

Instantly share code, notes, and snippets.

@Bren2010
Created August 2, 2012 01:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Bren2010/3232398 to your computer and use it in GitHub Desktop.
Save Bren2010/3232398 to your computer and use it in GitHub Desktop.
An IRC bot that texts you. God help us.
<?PHP
/*
Version 0.2
License This code is released under the MIT Open Source License. Feel free to do whatever you want with it.
Author lostleon@gmail.com, http://www.lostleon.com/
LastUpdate 05/28/2010
*/
class GoogleVoice
{
public $username;
public $password;
public $status;
private $lastURL;
private $login_auth;
private $inboxURL = 'https://www.google.com/voice/m/';
private $loginURL = 'https://www.google.com/accounts/ClientLogin';
private $smsURL = 'https://www.google.com/voice/m/sendsms';
public function __construct($username, $password)
{
$this->username = $username;
$this->password = $password;
}
public function getLoginAuth()
{
$login_param = "accountType=GOOGLE&Email={$this->username}&Passwd={$this->password}&service=grandcentral&source=com.lostleon.GoogleVoiceTool";
$ch = curl_init($this->loginURL);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_2_1 like Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5H11 Safari/525.20");
curl_setopt($ch, CURLOPT_REFERER, $this->lastURL);
curl_setopt($ch, CURLOPT_POST, "application/x-www-form-urlencoded");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $login_param);
$html = curl_exec($ch);
$this->lastURL = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch);
$this->login_auth = $this->match('/Auth=([A-z0-9_-]+)/', $html, 1);
return $this->login_auth;
}
public function get_rnr_se()
{
$this->getLoginAuth();
$ch = curl_init($this->inboxURL);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$headers = array("Authorization: GoogleLogin auth=".$this->login_auth, 'User-Agent: Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_2_1 like Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5H11 Safari/525.20');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$html = curl_exec($ch);
$this->lastURL = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch);
$_rnr_se = $this->match('!<input.*?name="_rnr_se".*?value="(.*?)"!ms', $html, 1);
return $_rnr_se;
}
public function sms($to_phonenumber, $smstxt)
{
$_rnr_se = $this->get_rnr_se();
$sms_param = "id=&c=&number=".urlencode($to_phonenumber)."&smstext=".urlencode($smstxt)."&_rnr_se=".urlencode($_rnr_se);
$ch = curl_init($this->smsURL);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$headers = array("Authorization: GoogleLogin auth=".$this->login_auth, 'User-Agent: Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_2_1 like Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5H11 Safari/525.20');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_REFERER, $this->lastURL);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $sms_param);
$this->status = curl_exec($ch);
$this->lastURL = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch);
return $this->status;
}
private function match($regex, $str, $out_ary = 0)
{
return preg_match($regex, $str, $match) == 1 ? $match[$out_ary] : false;
}
}
?>
<?php
$username = '';
$password = '';
# Requirements
net = require 'net'
exec = require('child_process').exec
# Configuration
name = 'Bren Bot'
nick = 'BrenBot'
channel = '#muzeko'
numbers = []
text = (num, who, msg) ->
exec 'php ./text.php ' + num +
' "<' + who + '> ' + msg + '"', () ->
# Function to parse 1 line of input and emit an event.
parse = (line) ->
console.log line
cmd =
host: {nick: 'Anon', user: '', host: ''}
command: ''
params: []
# Handle pings
if line.substr(0, 4) is 'PING'
cmd.command = 'ping'
cmd.params[0] = line.substr line.indexOf(' ') + 2
return client.emit('ping', cmd)
# Parse the hostmask
space = line.indexOf(' ')
host = line.substr 1, space - 1
line = line.substr space + 1
excl = host.indexOf('!')
at = host.indexOf('@')
cmd.host.nick = host.substr 0, excl if excl != -1
cmd.host.user = host.substr excl + 1, at - excl - 1
cmd.host.host = host.substr at + 1
# Parse command
cmd.command = line.substr 0, line.indexOf(' ')
line = line.substr line.indexOf(' ') + 1
# Parse parameters
while line isnt ''
if line.charAt(0) is ':'
cmd.params.push line.substr 1
line = ''
else
space = line.indexOf(' ')
if space is -1 then space = line.length
cmd.params.push line.substr 0, space
line = line.substr space + 1
client.emit(cmd.command.toLowerCase() + "_cmd", cmd)
# Connecting to the IRC server and emitting new lines.
client = net.connect {host: 'irc.freenode.net', port: 8001}, ->
console.log 'Starting...'
client.write "USER #{nick} #{nick} #{nick} :#{name}\r\n"
client.write "NICK #{nick}\r\n"
client.write "JOIN #{channel}\r\n"
client.on 'data', (data) ->
data = data.toString().split('\r\n')
data.pop()
parse line for line in data
client.on 'end', ->
console.log 'Disconnected'
# Handle pings
client.on 'ping', (cmd) ->
client.write 'PONG :' + cmd.params[1] + '\r\n'
# Handle user commands.
client.on 'privmsg_cmd', (cmd) ->
text num, cmd.host.nick, cmd.params[1] for num in numbers
<?php
include("config.php"); // Defines variables $username and $password
include("class.googlevoice.php");
$gv = new GoogleVoice($username, $password);
$gv->sms($_SERVER['argv'][1], $_SERVER['argv'][2]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment