Skip to content

Commit

Permalink
Add fortune module
Browse files Browse the repository at this point in the history
  • Loading branch information
aluminiumgeek committed Dec 14, 2015
1 parent 918ad05 commit 0bad854
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions modules/user_fortune.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os
import random


def main(bot, *args):
"""
fortune
Print a random, hopefully interesting, adage
"""

fortunes_path = '/usr/share/games/fortunes/'

try:
types = filter(lambda x: not x.endswith('.dat'), os.listdir(fortunes_path))
except OSError:
return 'Package `fortunes` is not installed in your system. Run `aptitude install fortunes`'

fortune_file = random.choice(list(types))
with open(os.path.join(fortunes_path, fortune_file)) as fortune_file:
data = fortune_file.read()
quotes = data.split('%\n')
return random.choice(quotes)

0 comments on commit 0bad854

Please sign in to comment.