Change lua to python.
easiler to use
This commit is contained in:
parent
5c511bbe58
commit
ad22866d0c
16
init.php
16
init.php
@ -4,7 +4,21 @@ require_once('config.inc.php');
|
|||||||
require_once('functions.php');
|
require_once('functions.php');
|
||||||
$plugins = [];
|
$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
|
||||||
$load_plugins = glob(dirname(__FILE__).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'*.php');
|
$load_plugins = glob(dirname(__FILE__).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'*.php');
|
||||||
|
@ -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.
|
- 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
|
- php >= 5.3.0
|
||||||
|
- python = 2.7.9
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
-----
|
-----
|
||||||
@ -13,9 +14,13 @@ Usage
|
|||||||
###Setup telegram-cli
|
###Setup telegram-cli
|
||||||
[telegram-cli](https://github.com/vysheng/tg/) needs to be installed.
|
[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
|
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,
|
Finally,
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@ import urllib
|
|||||||
import urllib2
|
import urllib2
|
||||||
|
|
||||||
def on_msg_receive(msg):
|
def on_msg_receive(msg):
|
||||||
get="from="+urllib.quote(msg.dest.name)+"&text="+urllib.quote(msg.text)
|
params = urllib.urlencode({'from': msg.src.name.encode("UTF-8"), 'text': msg.text.encode("UTF-8"), 'to': msg.dest.name.encode("UTF-8")})
|
||||||
url="http://1.vps.dennx.com/onmessage.php?"
|
f = urllib.urlopen("[your BOT.php Url Here]?%s" % params)
|
||||||
req=urllib2.Request(url+get)
|
print f.read()
|
||||||
res=urllib2.urlopen(req).read()
|
|
||||||
print res
|
tgl.set_on_msg_receive(on_msg_receive)
|
@ -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
|
|
Loading…
Reference in New Issue
Block a user