This commit is contained in:
yagop 2014-07-01 22:06:40 +02:00
parent 7dd62c8115
commit 07460ac1f0
2 changed files with 30 additions and 5 deletions

View File

@ -1,10 +1,15 @@
our_id = 0
started = 0
now = os.time()
function on_msg_receive (msg)
-- vardump(msg)
if msg.out then
return
end
if msg.date < now then
return
end
if msg.text == nil then
return
end
@ -18,8 +23,14 @@ function on_msg_receive (msg)
end
end
-- Where magic happens
function do_action(msg)
receiver = get_receiver(msg)
-- sudo apt-get install fortunes-es-off
if string.starts(msg.text, 'fortune') then
text = run_bash('fortune')
send_msg(receiver, text)
end
if string.starts(msg.text, 'forni') then
text = msg.text:sub(7,-1)
send_msg('Fornicio_2.0', text)
@ -52,7 +63,8 @@ function do_action(msg)
!version : version info
!cpu : Status (uname + top)
!fwd : Forward msg
!forni : Send text to group Fornicio]]
!forni : Send text to group Fornicio
!fortune : Print a random adage]]
send_msg(receiver, text)
end
end
@ -97,6 +109,13 @@ function run_bash(str)
return result
end
function readAll(file)
local f = io.open(file, "rb")
local content = f:read("*all")
f:close()
return content
end
function vardump(value, depth, key)
local linePrefix = ""
local spaces = ""

View File

@ -1,11 +1,17 @@
#!/bin/sh
cd tg
cd "$(dirname "$0")"
if [ ! -f ./telegram ]; then
if [ ! -f ./tg/telegram.h ]; then
echo "Download tg first:"
echo "git submodule update --init --recursive"
exit
fi
if [ ! -f ./tg/telegram ]; then
echo "Compile telegram first:"
echo "cd tg && ./configure && make"
exit
fi
./telegram -s ../bot/bot.lua
./tg/telegram -k tg/tg-server.pub -s ./bot/bot.lua