sadfroger

Telegram Modul

Sep 5th, 2016
1,013
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.85 KB | None | 0 0
  1. #Version 1.1:
  2. @name Telegram Modul
  3. @inputs
  4. @outputs
  5. @trigger
  6. @persist TokenTel:string UrlTel:string ModeTel:string MsgTel:string ChatidTel:string MChatidTel:string OffsetTel ContactsTel:table WhitelistTel:table KeyboardTel:table SoundindicatorTel TickTel USTel TextTel:string
  7. interval(10)
  8. runOnHTTP(1)
  9. runOnLast(1)
  10. runOnChat(1)
  11. #Telegram Modul
  12. ############################################################
  13. #Settings
  14. if(first()) {
  15.   TokenTel="" #The Token from you Telegram Bot.
  16.   UrlTel="https://api.telegram.org/bot"+TokenTel
  17.   MChatidTel="" #Your main Chat Id
  18.   #WhitelistTel["",number]=1 #Whitelist for the commands. If no one is in the whitelist its deactivated. Whitelist["<Chat Id>,number"]=1
  19.   ModeTel="check"
  20.   #SoundindicatorTel=1 #If active its indicates commands with a button sound.
  21.   #Pre installed Telegram commands
  22.   #"/start" To get your Chat Id
  23.   #"/chatid" To get your Chat Id
  24.   #"/ping" Pong!
  25.   #"/420"
  26. }
  27. #/Settings/
  28.  
  29. #Description
  30. #Setup
  31. #1.Go to Telegram
  32. #2.Click on BotFather
  33. #3.Type in /newbot
  34. #4.Find an avaible name for your bot. Hint: Keep it secret, this E2 doesnt have an Spam protection.
  35. #5.Grab the API Key and paste it in the Token Variable above.
  36. #6.Send your Bot a "/start"
  37. #Optional if you want to listen every Messages not just the ones who start with /
  38. #7.Type in /setprivacy
  39. #8.Select your Bot.
  40. #9.Type in Disable
  41.  
  42. #E2 Functions
  43. #Send an message: sendmsg(Chatid:string,Message:string)
  44. #Send an message with a costum Keyboard layout:
  45. #Before you send an message via. sendmsg() you need to change the follow Table
  46. #Example: KeyboardTel["keyboard",table]=table(table("1","2","3"),table("4","5","6"),table("7","8","9")) #This displays a 3x3 Field.
  47. #TickTel is true for one tick long if a message was recieved
  48. #The ContactsTel Table saves all Chatids under the first names Example: sendmsg(ContactsTel["Moritz",string],"Its just a test!")
  49. #/Description
  50. ############################################################
  51. #Automate Update
  52.  
  53. if(!USTel&httpCanRequest()) {
  54. print("Begin with searching for updates.")
  55. print("----------------")
  56. USTel=1  
  57. httpRequest("http://pastebin.com/raw/yw8i4F1b")
  58. }
  59. if(httpClk()&USTel==3) {
  60.  
  61. DatasTel=httpData()
  62. print("Update!")
  63. print("-----------")
  64. #print("Version "+Datas[2,string])
  65. print("Changes:")  
  66. print(DatasTel)
  67. print("The e2 is saved in you e2shared folder!")
  68. print("-----------")
  69.  
  70. USTel=420
  71. }
  72. if(httpClk()&USTel==1) {
  73. Data=httpData():explode(":")[1,string]:explode(" ")  
  74. if(Data[2,string]:toNumber()>1.1) {
  75. hint("Update was found!",4)  
  76. fileWrite(">e2shared/Telegram Modul.txt",httpData())
  77. USTel=2
  78. } else {
  79. USTel=420
  80. print("No updates was found.")
  81. }
  82. }
  83. if(USTel==2&httpCanRequest()) {httpRequest("http://pastebin.com/raw/GXvvMB1n") USTel=3}
  84. TickTel=0
  85. function sendmsg(IdTel:string,MessTel:string) {
  86.   ModeTel="send"
  87.   MsgTel=httpUrlEncode(MessTel)
  88.   ChatidTel=IdTel
  89.   #print("send "+httpUrlDecode(Msg)+" to "+Id)
  90. }
  91. #/Automate Update/
  92.  
  93.  
  94. #[if(last()) {
  95.   if(MChatid:length()>2) {
  96.     httpRequest(Url+"/sendmessage?chat_id="+MChatid+"&text="+entity():getName()+" is shutingdown now.")
  97.   }
  98.   print(httpRequestUrl())
  99. }]#
  100.  
  101.  
  102. if(httpCanRequest()&USTel==420) {
  103.   if(ModeTel=="recieve") {
  104.     httpRequest(UrlTel+"/getUpdates?offset="+OffsetTel)
  105.     ModeTel="recieve"
  106.     #print(httpRequestUrl())
  107.   }
  108.   if(ModeTel=="send") {
  109.     if(KeyboardTel["keyboard",table]:count()) {
  110.       KYTel=KeyboardTel["one_time_keyboard",normal]=666
  111.       ArgTel=jsonEncode(KeyboardTel):replace("666","true"):replace(toChar(34),"%22")
  112.       KFTel="&reply_markup="+ArgTel
  113.       # print(KF)
  114.     }
  115.     httpRequest(UrlTel+"/sendmessage?chat_id="+ChatidTel+"&text="+MsgTel+KFTel)
  116.     KFTel=""
  117.     KeyboardTel["keyboard",table]=table()
  118.  
  119.     #print(httpRequestUrl())
  120.     ModeTel="recieve"
  121.   }
  122.   if(ModeTel=="check") {
  123.     httpRequest(UrlTel+"/getme")
  124.   }
  125. }
  126. if(httpClk()&httpRequestUrl():find(UrlTel)) {
  127.   if(ModeTel=="check") {
  128.     DataTel=httpData()
  129.     TeTel=jsonDecode(DataTel)
  130.     if(TeTel["ok",number]) {
  131.  
  132.       hint("Your now connected with "+TeTel["result",table]["username",string],4)
  133.       ModeTel="recieve"
  134.       if(MChatidTel:length()>2) {
  135.         sendmsg(MChatidTel,"Your E2 "+toChar(34)+entity():getName()+toChar(34)+" is running now.")
  136.       }
  137.     } else {
  138.     ModeTel="error"
  139.     hint("Your Bot Token seem to be wrong, pls retry.",4)
  140.   }
  141. }
  142. if(ModeTel=="recieve") {
  143.   DataTel=httpData()
  144.   TeTel=jsonDecode(DataTel)
  145.   MTTel=TeTel["result",table]
  146.   NachrichtenCTel=MTTel:count() #Anzahl der Nachrichten
  147.   if(MTTel[1,table]["update_id",number]) {
  148.     OffsetTel=MTTel[1,table]["update_id",number]+1 #Loeschen der ersten Nachricht
  149.   }
  150.   #print(NachrichtenC)
  151.   #print(MT:toString())
  152.   if(NachrichtenCTel) {
  153.     TickTel=1
  154.     if(SoundindicatorTel) {
  155.       owner():soundPlay(1,1,"buttons/button14.wav")
  156.     }
  157.   }
  158.   for(X=1,NachrichtenCTel) {
  159.     DetailsTel=MTTel[X,table]["message",table]
  160.     TextTel=DetailsTel["text",string]:lower()
  161.     AbsenderTel=DetailsTel["chat",table]["first_name",string]:lower()
  162.     ChatidTel=DetailsTel["chat",table]["id",number]:toString()
  163.     ContactsTel[AbsenderTel,string]=ChatidTel
  164.     #print(Text)
  165.     if((WhitelistTel:count()&WhitelistTel[ChatidTel,number])|!WhitelistTel:count()) {
  166.       ##############################################################
  167.       #Commands
  168.       if(TextTel:find("/ping")) {
  169.         sendmsg(ChatidTel,"pong!")
  170.         hint("pong!",2000)
  171.         #print("pong!")
  172.       }
  173.       if(TextTel:find("/chatid")|TextTel:find("/start")) {
  174.         sendmsg(ChatidTel,"Hey buddy! Your Chatid is "+ChatidTel)
  175.       }
  176.       if(TextTel:find("/420")) {
  177.         KeyboardTel["keyboard",table]=table(table("4","2","0"),table("4","2","0"),table("4","2","0"))
  178.         sendmsg(ChatidTel," blaze it.")  
  179.       }
  180.       #/Commands/
  181.       ##############################################################
  182.     }
  183.   }
  184. }
  185. }
  186.  
  187. #/Telegram Modul/
Advertisement
Add Comment
Please, Sign In to add comment