From 07460ac1f06bc062d4cf13dace2ff2750a316e2f Mon Sep 17 00:00:00 2001 From: yagop Date: Tue, 1 Jul 2014 22:06:40 +0200 Subject: [PATCH] launch --- bot/bot.lua | 23 +++++++++++++++++++++-- launch.sh | 12 +++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/bot/bot.lua b/bot/bot.lua index 6af98a3..a1d33dc 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -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) @@ -46,13 +57,14 @@ function do_action(msg) send_msg(receiver, text) end if string.starts(msg.text, 'help') then - text = [[ !help : print this help + text = [[!help : print this help !ping : bot sends pong !echo : echoes the 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 = "" diff --git a/launch.sh b/launch.sh index 3deb6c0..3e70132 100755 --- a/launch.sh +++ b/launch.sh @@ -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