Created
October 23, 2021 13:35
-
-
Save kraftwerk28/4a4d908fd1df7ace3f382266e8fc759d to your computer and use it in GitHub Desktop.
not-LUA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local http = require"ssl.https" | |
local url = require"socket.url" | |
local json = require"cjson" | |
local token = os.getenv("TOKEN") | |
local tguri = "https://api.telegram.org/bot"..token | |
local last_update_id = 0 | |
local function process_update(update) | |
if not update.message then return end | |
local text = update.message.text or "" | |
local chat_id = (update.message.chat or {}).id | |
local reply_text = [[<a href="https://www.lua.org/about.html#name">Lua*</a>]] | |
if chat_id and text:match("LU[AА]") then | |
local query = ("chat_id=%d&text=%s&reply_to_message_id=%d&parse_mode=HTML") | |
:format(chat_id, url.escape(reply_text), update.message.message_id) | |
http.request(tguri.."/sendMessage?"..query) | |
end | |
end | |
while true do | |
local raw_body = http.request( | |
("%s/getUpdates?offset=%d&timeout=30"):format(tguri, last_update_id+1) | |
) | |
local ok, body = pcall(json.decode, raw_body) | |
if not ok or not body.ok then goto cont end | |
for _, update in ipairs(body.result) do | |
process_update(update) | |
last_update_id = update.update_id | |
end | |
::cont:: | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment