Esempio n. 1
0
 def read(self, msg, cmd, user, arg):
     response = Response()
     try:
         result = requests.post(self.qdb_api_read % self.qdb_secret, data={'permaid': arg[0]})
     except:
         return self.send_message("Tu puta madre.")
     try:
         result = json.loads(result.content)
     
         if result['results'].has_key('success'):
             if result['results']['success'] == 1:
                 if result['results']['data']['status'] == "deleted":
                     return self.send_message("Quote is deleted.")
                 else:
                     quote = result['results']['data']['text'].split("\n")
                     response.add_action(self.send_message('Enviado por ' + result['results']['data']['nick'] + ' (' + result['results']['data']['date'] + '):'))
                     
                     for line in quote:
                         if "\r" in line or "\n" in line:    
                             for subline in line.split("\r\n"):
                                 response.add_action(self.send_message(subline))
                         else:
                             response.add_action(self.send_message(line))
                             
                     if result['results']['data']['comment']:
                         comment = result['results']['data']['comment']
                         dashes_length = int((40 - len(comment)) / 2) # little decorator
                         response.add_action(self.send_message(("-" * dashes_length) + comment + ("-" * dashes_length)))
             else:
                 problem = {'hidden_quote': 'The quote is hidden.', 'no_such_quote': 'No such quote exists.'}[result['results']['error']]
                 response.add_action(self.send_message("Error: " + problem))
     except:
         return self.send_message('wodim, arregla el qdb.')
         
     return self.multiple_response(response.generate_response())
Esempio n. 2
0
 def search(self, msg, cmd, user, arg): 
     response = Response()
     try:
         result = requests.post(self.qdb_api_search % self.qdb_secret, data={'criteria': ' '.join(arg), 'page_size': 10})
     except:
         return self.send_message("Tu puta madre.")
     
     try:
         result = json.loads(result.content)
         
         if result['results'].has_key('success'):
             if result['results']['success'] == 1:
                 if result['results']['count'] == 0:
                     return self.send_message("No quotes matching that criteria found.")
                 else:
                     for quote in result['results']['data']:
                         firstline = quote['excerpt']
                         response.add_action(self.send_message(quote['permaid'] + " - " + quote['nick'] + ": '" + firstline + "'"))
                     
                     response.add_action(self.send_message("Escribe .read <id> para leer el quote completo."))
                         
             else:
                 return self.send_message("Algo se ha roto. (dunno lol)")
     except:
         raise
         return self.send_message("wodim, arregla el qdb.")
         
     return self.multiple_response(response.generate_response())
Esempio n. 3
0
File: help.py Progetto: hien/IRC-bot
	def handle_modules(self, modules):
		response = Response()
		
		response.add_action(self.send_message("Módulos disponibles: " + ', '.join(modules)))
		response.add_action(self.send_message("Escribe .help <module> para ver los comandos de un módulo."))
		
		return self.multiple_response(response.generate_response())
		
Esempio n. 4
0
 def text(self, msg, cmd, user, arg):
     try:
         if "." in arg[0]:
             return self.send_message("A hackear a tu casa.")
     except:
         return self.send_message("Tu puta madre.")
     
     try:
         file = open(self.path + arg[0]).readlines()
     except:
         return self.send_message("Ese texto no existe.")
         
     response = Response()
     
     for line in file:
         response.add_action(self.send_message(line))
         
     return self.multiple_response(response.generate_response())