From ad22866d0c4da07c6b048a7bf2d2837fe066de03 Mon Sep 17 00:00:00 2001 From: Denny Dai Date: Thu, 4 Jun 2015 16:15:34 +0800 Subject: [PATCH] Change lua to python. easiler to use --- init.php | 16 +++++++++++++++- readmes/Telegram/Telegram.md | 7 ++++++- readmes/Telegram/Telegram.py | 10 +++++----- readmes/Telegram/onmessage.lua | 10 ---------- 4 files changed, 26 insertions(+), 17 deletions(-) delete mode 100644 readmes/Telegram/onmessage.lua diff --git a/init.php b/init.php index 67b8147..b3d7619 100644 --- a/init.php +++ b/init.php @@ -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'); diff --git a/readmes/Telegram/Telegram.md b/readmes/Telegram/Telegram.md index d87d23c..f8176cf 100644 --- a/readmes/Telegram/Telegram.md +++ b/readmes/Telegram/Telegram.md @@ -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, diff --git a/readmes/Telegram/Telegram.py b/readmes/Telegram/Telegram.py index f0530b0..77d7727 100644 --- a/readmes/Telegram/Telegram.py +++ b/readmes/Telegram/Telegram.py @@ -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 \ No newline at end of file + 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) \ No newline at end of file diff --git a/readmes/Telegram/onmessage.lua b/readmes/Telegram/onmessage.lua deleted file mode 100644 index dfe0366..0000000 --- a/readmes/Telegram/onmessage.lua +++ /dev/null @@ -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 \ No newline at end of file