Advertisement
MolSno

quote.py

Dec 26th, 2014
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.78 KB | None | 0 0
  1. import random
  2. import codecs
  3.  
  4. cache = []
  5.  
  6. def cachequotes(phenny, input):
  7.     file = codecs.open('/root/phenny/oldlogs.txt', 'r', encoding='utf-8')
  8.     for line in file:
  9.         cache.append(line)
  10.     phenny.say(str(len(cache)) + " quotes have been successfully cached.")
  11.  
  12. cachequotes.commands = ['cachequotes']
  13. cachequotes.priority = 'high'
  14. cachequotes.thread = False
  15.  
  16. def oldquote(phenny, input):
  17.     if input.group(2) == None:
  18.         quote = random.choice(cache)
  19.         while not quote.startswith('<'):
  20.             quote = random.choice(cache)
  21.         phenny.say(quote)
  22.         return
  23.     results = []
  24.     for line in cache:
  25.         if input.group(2).lower() in line.lower() and line.startswith('<'):
  26.             results.append(line)
  27.     if not results:
  28.         phenny.say("No quotes found.")
  29.         return
  30.     phenny.say(random.choice(results))
  31.    
  32. oldquote.commands = ['oldquote']
  33. oldquote.priority = 'high'
  34. oldquote.thread = False
  35.  
  36. def searchquote(phenny, input):
  37.     quotes = codecs.open('/root/phenny/madlibs/quote.txt','r',encoding='utf-8').read().splitlines()
  38.     if input.group(2) == None:
  39.         quote = random.choice(quotes)
  40.         phenny.say(quote)
  41.         return
  42.     results = []
  43.     for line in quotes:
  44.         if input.group(2).lower() in line.lower():
  45.             results.append(line)
  46.     if not results:
  47.         phenny.say("No quotes found.")
  48.         return
  49.     phenny.say(random.choice(results))
  50.  
  51. searchquote.commands = ['quote']
  52. searchquote.priority = 'high'
  53. searchquote.thread = False
  54.  
  55. def addquote(phenny, input):
  56.     quotes = codecs.open('/root/phenny/madlibs/quote.txt','a',encoding='utf-8').write('\r\n'+input.group(2))
  57.     phenny.say('Quote added.')
  58. addquote.commands = ['addquote']
  59. addquote.priority = 'high'
  60. addquote.thread = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement