From 8d30ad796aaf41743f9c4f4ef75c91af7adddda5 Mon Sep 17 00:00:00 2001 From: yagop Date: Mon, 30 Jun 2014 12:42:28 +0200 Subject: [PATCH] creada la estructura --- .gitmodules | 3 ++ bot/bot.lua | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tg | 1 + 3 files changed, 139 insertions(+) create mode 100644 .gitmodules create mode 100644 bot/bot.lua create mode 160000 tg diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..36542cb --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tg"] + path = tg + url = https://github.com/vysheng/tg.git diff --git a/bot/bot.lua b/bot/bot.lua new file mode 100644 index 0000000..6af98a3 --- /dev/null +++ b/bot/bot.lua @@ -0,0 +1,135 @@ +our_id = 0 + +function on_msg_receive (msg) + -- vardump(msg) + if msg.out then + return + end + if msg.text == nil then + return + end + if msg.unread == 0 then + return + end + -- Check if command starts with ! eg !echo + if msg.text:sub(0,1) == '!' then + msg.text = msg.text:sub(2,-1) + do_action(msg) + end +end + +function do_action(msg) + receiver = get_receiver(msg) + if string.starts(msg.text, 'forni') then + text = msg.text:sub(7,-1) + send_msg('Fornicio_2.0', text) + end + if string.starts(msg.text, 'fwd') then + fwd_msg (receiver, msg.id) + end + if string.starts(msg.text, 'cpu') then + text = run_bash('uname -snr') + text = text .. '\n' .. run_bash('top -b |head -2') + send_msg(receiver, text) + end + if string.starts(msg.text, 'ping') then + send_msg(receiver, "pong") + end + if string.starts(msg.text, 'echo') then + -- Removes echo from the string + echo = msg.text:sub(6,-1) + send_msg(receiver, echo) + end + if string.starts(msg.text, 'version') then + text = 'v0.0.2 aka Study\n' + text = text .. 'Host user: ' .. run_bash('whoami') + send_msg(receiver, text) + end + if string.starts(msg.text, 'help') then + 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]] + send_msg(receiver, text) + end +end + +function get_receiver(msg) + if msg.to.type == 'user' then + return msg.from.print_name + end + if msg.to.type == 'chat' then + return msg.to.print_name + end +end + + +function on_our_id (id) + our_id = id +end + +function on_secret_chat_created (peer) +end + +function on_user_update (user) +end + +function on_chat_update (user) +end + +function on_get_difference_end () +end + +function on_binlog_replay_end () +end + +function string.starts(String,Start) + return string.sub(String,1,string.len(Start))==Start +end + +function run_bash(str) + local cmd = io.popen(str) + local result = cmd:read('*all') + cmd:close() + return result +end + +function vardump(value, depth, key) + local linePrefix = "" + local spaces = "" + + if key ~= nil then + linePrefix = "["..key.."] = " + end + + if depth == nil then + depth = 0 + else + depth = depth + 1 + for i=1, depth do spaces = spaces .. " " end + end + + if type(value) == 'table' then + mTable = getmetatable(value) + if mTable == nil then + print(spaces ..linePrefix.."(table) ") + else + print(spaces .."(metatable) ") + value = mTable + end + for tableKey, tableValue in pairs(value) do + vardump(tableValue, depth, tableKey) + end + elseif type(value) == 'function' or + type(value) == 'thread' or + type(value) == 'userdata' or + value == nil + then + print(spaces..tostring(value)) + else + print(spaces..linePrefix.."("..type(value)..") "..tostring(value)) + end +end diff --git a/tg b/tg new file mode 160000 index 0000000..1dad2e8 --- /dev/null +++ b/tg @@ -0,0 +1 @@ +Subproject commit 1dad2e89933085ea1e3d9fb1becb1907ce5de55f