Guest User

Untitled

a guest
Apr 26th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Simple Bot to reply to Telegram messages
  5. # This program is dedicated to the public domain under the CC0 license.
  6.  
  7. import logging
  8. import telegram
  9. from telegram.error import NetworkError, Unauthorized
  10. from time import sleep
  11. from telegram import InlineQueryResultArticle
  12.  
  13. def main():
  14. # Telegram Bot Authorization Token
  15. bot = telegram.Bot('219783361:AAH8N9DqEfpAvBX4s3qTLBB2CYZzuiYIjWk')
  16.  
  17. # get the first pending update_id, this is so we can skip over it in case
  18. # we get an "Unauthorized" exception.
  19. try:
  20. update_id = bot.getUpdates()[0].update_id
  21. except IndexError:
  22. update_id = None
  23.  
  24. logging.basicConfig(
  25. format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
  26.  
  27. while True:
  28. try:
  29. update_id = echo(bot, update_id)
  30. except NetworkError:
  31. sleep(1)
  32. except Unauthorized:
  33. # The user has removed or blocked the bot.
  34. update_id += 1
  35.  
  36.  
  37. def echo(bot, update_id):
  38.  
  39. dic={'q':u'к','w':u'в','e':u'е','r':u'р','t':u'т','y':u'й','u':u'у','i':u'и','o':u'о','p':u'п','a':u'а','s':u'с','d':u'д','f':u'ф','g':u'г','h':u'х','j':u'ж','k':u'к','l':u'л','z':u'з','x':u'х','c':u'ц','v':u'в','b':u'б','n':u'н','m':u'м'}
  40. v=u'йцкнгшщзхъфвпрлджчсмтьб'
  41. w=u'уеёаоэяию'
  42. shit=u'/.,\'\"'
  43.  
  44. # Request updates after the last update_id
  45. for update in bot.getUpdates(offset=update_id, timeout=10):
  46. # chat_id is required to reply to any message
  47. update_id = update.update_id + 1
  48. inline=None
  49. message=None
  50. if update.message is not None and update.message.text:
  51. message = update.message.text
  52. chat_id = update.message.chat_id
  53. if update.inline_query is not None and update.inline_query.query:
  54. inline=update.inline_query.query
  55. if message:
  56. # Reply to the message
  57. f=False
  58. t=message.split()
  59. r=[]
  60. for k in t:
  61. n=k
  62. i=0
  63. m=''
  64. f=False
  65. n=n.lower()
  66. n+=u'$$'
  67. while n[0] in shit:
  68. n=n[1:]
  69. p=[]
  70. for c in n:
  71. p.append(dic.setdefault(c, c))
  72. m=''.join(p)
  73. if m[:2]==u'ху' and len(m)>7:
  74. m=m[2:]
  75. if m[0] in w and len(m)>5:
  76. m=m[1:]
  77. while m[i] in v:
  78. i+=1
  79. while m[i+1] in w:
  80. i+=1
  81. if m[i] in u'ая' and f==False:
  82. m=u'хуя'+m[i+1:-2]
  83. f=True
  84. elif m[i] in u'еэ':
  85. m=u'хуе'+m[i+1:-2]
  86. f=True
  87. elif m[i] in u'ёо':
  88. m=u'хуё'+m[i+1:-2]
  89. f=True
  90. elif m[i] in u'ую':
  91. m=u'хую'+m[i+1:-2]
  92. f=True
  93. elif m[i] in u'иы':
  94. m=u'хуи'+m[i+1:-2]
  95. f=True
  96. if f==False:
  97. m=k
  98. r.append(m)
  99. x=u' '.join(r)
  100. bot.sendMessage(chat_id=chat_id,text=x)
  101. if inline:
  102. # Reply to the messag
  103. f=False
  104. t=inline.split()
  105. r=[]
  106. for k in t:
  107. n=k
  108. i=0
  109. m=''
  110. f=False
  111. n=n.lower()
  112. n+=u'$$'
  113. while n[0] in shit:
  114. n=n[1:]
  115. p=[]
  116. for c in n:
  117. p.append(dic.setdefault(c, c))
  118. m=''.join(p)
  119. if m[:2]==u'ху' and len(m)>7:
  120. m=m[2:]
  121. if m[0] in w and len(m)>5:
  122. m=m[1:]
  123. while m[i] in v:
  124. i+=1
  125. while m[i+1] in w:
  126. i+=1
  127. if m[i] in u'ая' and f==False:
  128. m=u'хуя'+m[i+1:-2]
  129. f=True
  130. elif m[i] in u'еэ':
  131. m=u'хуе'+m[i+1:-2]
  132. f=True
  133. elif m[i] in u'ёо':
  134. m=u'хуё'+m[i+1:-2]
  135. f=True
  136. elif m[i] in u'ую':
  137. m=u'хую'+m[i+1:-2]
  138. f=True
  139. elif m[i] in u'иы':
  140. m=u'хуи'+m[i+1:-2]
  141. f=True
  142. if f==False:
  143. m=k
  144. r.append(m)
  145. x=u' '.join(r)
  146. results=list()
  147. results.append(InlineQueryResultArticle(
  148. id='1',
  149. title=x,
  150. message_text=x))
  151. bot.answerInlineQuery(update.inline_query.id, results)
  152.  
  153. return update_id
  154.  
  155.  
  156. if __name__ == '__main__':
  157. main()
Add Comment
Please, Sign In to add comment