Advertisement
cyber01

TGInformer

Sep 14th, 2017
884
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.21 KB | None | 0 0
  1. --[[ Telegram informer for various things. Author: cyber01]]--
  2.  
  3. -- [CONFIG]
  4. local chatid = '123456'
  5.  
  6. local component = require("component")
  7. local fs = require("filesystem")
  8. local shell = require("shell")
  9. local args, options = shell.parse(...)
  10. if not component.isAvailable("internet") then
  11.   print("This program requires an internet card to run.")
  12.   os.exit()
  13. end
  14.  
  15. local internet = require("internet")
  16.  
  17.  
  18. ---  ========= Telegram section (past in  your programm)===================
  19. function urlencode(str)
  20.    if (str) then
  21.       str = string.gsub (str, "\n", "\r\n")
  22.       str = string.gsub (str, "([^%w ])",
  23.          function (c) return string.format ("%%%02X", string.byte(c)) end)
  24.       str = string.gsub (str, " ", "+")
  25.    end
  26.    return str    
  27. end
  28.  
  29.  
  30. function telegramGET(chatid, text)
  31.     local result, reason = internet.request("http://computercraft.ru/telegram.php?chatid="..chatid.."&text="..urlencode(text))
  32.     local info = ""
  33.     if result then
  34.         for chunk in result do
  35.             info = info .. chunk
  36.         end
  37.     end
  38.     return info
  39. end
  40. --===============Telegram section (end)============
  41. answer = telegramGET(chatid, args[1])
  42.     print('Результат отправки сообщения: ', answer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement