Skip to content

Instantly share code, notes, and snippets.

@acelan
Last active July 3, 2016 13:28
Show Gist options
  • Save acelan/f7908088b5fb671877b62941630178b2 to your computer and use it in GitHub Desktop.
Save acelan/f7908088b5fb671877b62941630178b2 to your computer and use it in GitHub Desktop.
--telegram-cli -v -s village_game.lua
function ok_cb(extra, success, result)
end
function sleep(n)
os.execute("sleep " .. tonumber(n))
end
function vardump(value, depth, key)
local line_prefix = ""
local spaces = ""
if key ~= nil then
line_prefix = "["..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 ..line_prefix.."(table) ")
else
print(spaces .."(metatable) ")
value = mTable
end
for table_key, table_value in pairs(value) do
vardump(table_value, depth, table_key)
end
elseif type(value) == 'function' or
type(value) == 'thread' or
type(value) == 'userdata' or
value == nil
then
print(spaces..tostring(value))
else
print(spaces..line_prefix.."("..type(value)..") "..tostring(value))
end
end
local stop_flag = 0
function on_msg_receive (msg)
if msg.unread == 0 then
return
end
if msg.to.username == "villagegamebot" then
if string.match(msg.text, "為我評分") then
stop_flag = 1 - stop_flag
if stop_flag == 0 then
send_msg (msg.to.print_name, "任務", ok_cb, false)
end
end
end
if stop_flag == 1 then
return
end
if msg.from.username == "villagegamebot" then
-- we got image sometimes, so no text
if msg.text == nil then
if msg.media ~= nil and string.match(msg.media.caption,"山賊們襲擊了一條村落") then
send_msg (msg.from.print_name, "進行任務🗡", ok_cb, false)
end
elseif string.match(msg.text, "您可以選擇一項任務") then
sleep(5)
send_msg (msg.from.print_name, "⭐️⭐️⭐️拯救村落", ok_cb, false)
elseif string.match(msg.text, "為了反制他們") then
send_msg (msg.from.print_name, "增派援軍!🗡", ok_cb, false)
-- 出售麵包💰
-- 🍞工作!
elseif string.match(msg.text, "工作完成") then
send_msg (msg.from.print_name, "🍞工作!", ok_cb, false)
send_msg (msg.from.print_name, "🍞工作!", ok_cb, false)
send_msg (msg.from.print_name, "🍞工作!", ok_cb, false)
elseif string.match(msg.text, "農場堆滿了麵包") then
send_msg (msg.from.print_name, "出售麵包💰", ok_cb, false)
send_msg (msg.from.print_name, "出售麵包💰", ok_cb, false)
send_msg (msg.from.print_name, "出售麵包💰", ok_cb, false)
end
end
--print("msg = ")
--vardump(msg)
end
function on_our_id (id)
end
function on_user_update (user)
--vardump (user)
end
function on_chat_update (user)
--vardump (user)
end
function on_get_difference_end ()
end
function on_binlog_replay_end ()
end
function on_secret_chat_created (peer)
--vardump (peer)
end
function on_secret_chat_update (schat, what)
--vardump (schat)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment