12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- # -*- coding: utf-8 -*-
- import subprocess as sp
- import httplib
- import numpy as np
- from insults import insults
- from speak import produce_sentence
- def start(update, context):
- """Says hi to new users"""
- #context.bot.send_message(chat_id=update.effective_chat.id, text="I'm a bot, please talk to me!")
- update.message.reply_text(text='Bot ufficiale di LCM')
- def ping(update, context):
- """Check LCM ping response"""
- try:
- sp.check_output(['ping', '-c', '1', 'lcm.mi.infn.it'])
- except CalledProcessError, e:
- update.message.reply_text(text='LCM is unreachable')
- update.message.reply_text(text='LCM is reachable')
- def is_web_up(update, context):
- """Check LCM http response"""
- try:
- conn = httplib.HTTPSConnection('lcm.mi.infn.it:443')
- conn.request('HEAD', '/')
- s = conn.getresponse().status
- if s == 200:
- update.message.reply_text(text='Website is OK')
- update.message.reply_text(text='Web server replied with code %s ' % s)
- except StandardError:
- update.message.reply_text(text='An error occurred while connecting')
- def vietnam(update, context):
- """Spout wise words"""
- update.message.reply_text(text='Ricordate, ragazzi, LCM è come il Vietnam. '
- 'Una volta entrati, è impossibile uscirne!',
- quote=False)
- def sell_your_mother(update, context):
- """Remind people not to disclose passwords"""
- pic_id = 'AgADBAADz7AxG0u34VPYhr3TqmbSck56qBsABAEAAwIAA3gAA_ZiBQABFgQ'
- update.message.reply_photo(photo=pic_id, caption='cit. Mandelli',
- quote=False)
- def print_msg_info(update, context):
- """Print all message info to console - useful for debugging purposes"""
- print update.message
- def error(update, context, error):
- """Log errors"""
- # create a logger with function scope ("static" object)
- error.logger = logging.getLogger(__name__)
- error.logger.warn('Update "%s" caused error "%s"' % (update, error))
- def abuse_150(update, context):
- """Verbally abuse incompetent LCM collaborators"""
- insult = np.random.choice(insults)
- update.message.reply_text(text=insult, quote=False)
- def moarpuddu(update,context):
- """More broken pipes for Puddu"""
- update.message.reply_text(text="più broken pipe per Puddu", quote=False)
- def speak(update, context, *args):
- """Produce pseudo-random wise words"""
- word = args[0] if len(args) > 0 else None
- update.message.reply_text(text=produce_sentence(word), quote=False)
|