Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # Simple Bot to reply to Telegram messages
- # This program is dedicated to the public domain under the CC0 license.
- import logging
- import telegram
- from telegram.error import NetworkError, Unauthorized
- from time import sleep
- from telegram import InlineQueryResultArticle
- def main():
- # Telegram Bot Authorization Token
- bot = telegram.Bot('219783361:AAH8N9DqEfpAvBX4s3qTLBB2CYZzuiYIjWk')
- # get the first pending update_id, this is so we can skip over it in case
- # we get an "Unauthorized" exception.
- try:
- update_id = bot.getUpdates()[0].update_id
- except IndexError:
- update_id = None
- logging.basicConfig(
- format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
- while True:
- try:
- update_id = echo(bot, update_id)
- except NetworkError:
- sleep(1)
- except Unauthorized:
- # The user has removed or blocked the bot.
- update_id += 1
- def echo(bot, update_id):
- 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'м'}
- v=u'йцкнгшщзхъфвпрлджчсмтьб'
- w=u'уеёаоэяию'
- shit=u'/.,\'\"'
- # Request updates after the last update_id
- for update in bot.getUpdates(offset=update_id, timeout=10):
- # chat_id is required to reply to any message
- update_id = update.update_id + 1
- inline=None
- message=None
- if update.message is not None and update.message.text:
- message = update.message.text
- chat_id = update.message.chat_id
- if update.inline_query is not None and update.inline_query.query:
- inline=update.inline_query.query
- if message:
- # Reply to the message
- f=False
- t=message.split()
- r=[]
- for k in t:
- n=k
- i=0
- m=''
- f=False
- n=n.lower()
- n+=u'$$'
- while n[0] in shit:
- n=n[1:]
- p=[]
- for c in n:
- p.append(dic.setdefault(c, c))
- m=''.join(p)
- if m[:2]==u'ху' and len(m)>7:
- m=m[2:]
- if m[0] in w and len(m)>5:
- m=m[1:]
- while m[i] in v:
- i+=1
- while m[i+1] in w:
- i+=1
- if m[i] in u'ая' and f==False:
- m=u'хуя'+m[i+1:-2]
- f=True
- elif m[i] in u'еэ':
- m=u'хуе'+m[i+1:-2]
- f=True
- elif m[i] in u'ёо':
- m=u'хуё'+m[i+1:-2]
- f=True
- elif m[i] in u'ую':
- m=u'хую'+m[i+1:-2]
- f=True
- elif m[i] in u'иы':
- m=u'хуи'+m[i+1:-2]
- f=True
- if f==False:
- m=k
- r.append(m)
- x=u' '.join(r)
- bot.sendMessage(chat_id=chat_id,text=x)
- if inline:
- # Reply to the messag
- f=False
- t=inline.split()
- r=[]
- for k in t:
- n=k
- i=0
- m=''
- f=False
- n=n.lower()
- n+=u'$$'
- while n[0] in shit:
- n=n[1:]
- p=[]
- for c in n:
- p.append(dic.setdefault(c, c))
- m=''.join(p)
- if m[:2]==u'ху' and len(m)>7:
- m=m[2:]
- if m[0] in w and len(m)>5:
- m=m[1:]
- while m[i] in v:
- i+=1
- while m[i+1] in w:
- i+=1
- if m[i] in u'ая' and f==False:
- m=u'хуя'+m[i+1:-2]
- f=True
- elif m[i] in u'еэ':
- m=u'хуе'+m[i+1:-2]
- f=True
- elif m[i] in u'ёо':
- m=u'хуё'+m[i+1:-2]
- f=True
- elif m[i] in u'ую':
- m=u'хую'+m[i+1:-2]
- f=True
- elif m[i] in u'иы':
- m=u'хуи'+m[i+1:-2]
- f=True
- if f==False:
- m=k
- r.append(m)
- x=u' '.join(r)
- results=list()
- results.append(InlineQueryResultArticle(
- id='1',
- title=x,
- message_text=x))
- bot.answerInlineQuery(update.inline_query.id, results)
- return update_id
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment