Change lua to python.

easiler to use
This commit is contained in:
Denny Dai 2015-06-04 16:15:34 +08:00
parent 5c511bbe58
commit ad22866d0c
4 changed files with 26 additions and 17 deletions

View File

@ -4,7 +4,21 @@ require_once('config.inc.php');
require_once('functions.php');
$plugins = [];
$from = $_GET['from']
if($_GET['from'] != escapePeer(BOT_NAME)){
//is group?
if ($_GET['to'] == escapePeer(BOT_NAME)) {
$isgroup = false;
}else{
$isgroup = true;
}
//reply to...
if ($isgroup) {
$from = $_GET['to'];
}else{
$from = $_GET['from'];
$BOT->exec("msg ".escapePeer(OWNER_NAME)." ".json_encode($_GET));
}
//load plugins
$load_plugins = glob(dirname(__FILE__).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'*.php');

View File

@ -6,6 +6,7 @@ Requirements
------------
- A running [telegram-cli](https://github.com/vysheng/tg/) listening on a unix-socket (`-S`) or a port (`-P`). Needs to be configured (phone-number, etc.) before this progarm runs.
- php >= 5.3.0
- python = 2.7.9
Usage
-----
@ -13,9 +14,13 @@ Usage
###Setup telegram-cli
[telegram-cli](https://github.com/vysheng/tg/) needs to be installed.
And
Change Url to your BOT.php address in [Telegram.py](https://github.com/dennydai/D-bot/blob/master/readmes/Telegram/Telegram.py)
Then
./bin/telegram-cli -s [onmessage.lua Path Here] -dWS /tmp/tg.sck &
./bin/telegram-cli -s [Telegram.py Path Here] -dWS /tmp/tg.sck &
Finally,

View File

@ -4,8 +4,8 @@ import urllib
import urllib2
def on_msg_receive(msg):
get="from="+urllib.quote(msg.dest.name)+"&text="+urllib.quote(msg.text)
url="http://1.vps.dennx.com/onmessage.php?"
req=urllib2.Request(url+get)
res=urllib2.urlopen(req).read()
print res
params = urllib.urlencode({'from': msg.src.name.encode("UTF-8"), 'text': msg.text.encode("UTF-8"), 'to': msg.dest.name.encode("UTF-8")})
f = urllib.urlopen("[your BOT.php Url Here]?%s" % params)
print f.read()
tgl.set_on_msg_receive(on_msg_receive)

View File

@ -1,10 +0,0 @@
function encodeURI(s)
s = string.gsub(s, "([^%w%.%- ])", function(c) return string.format("%%%02X", string.byte(c)) end)
return string.gsub(s, " ", "+")
end
function on_msg_receive (msg)
local handle = io.popen( "wget [your BOT.php url here]?to="..encodeURI(msg.to.print_name).."&from="..encodeURI(msg.from.print_name).."&text="..encodeURI(msg.text) )
local result = handle:read("*a")
handle:close()
end