From: CMDR furrycat Date: Wed, 10 Oct 2018 08:33:01 +0000 (+0100) Subject: Tidy loading facts and haikus. X-Git-Url: http://git.furryclan.net/?a=commitdiff_plain;h=46231333922eab62701cd1af98f4781c8e6b5eb9;p=furrycat%2Fcatbot.git Tidy loading facts and haikus. --- diff --git a/plugin/facts/facts.py b/plugin/facts/facts.py index 3a3528d..00da32b 100644 --- a/plugin/facts/facts.py +++ b/plugin/facts/facts.py @@ -1,25 +1,24 @@ import asyncio +import os import random from plugins import PluginCommand import bot - class Facts(object): def __init__(self): - fFacts = open("catfacts.txt", "r") - self.catFacts = fFacts.readlines() - fFacts.close() - fHaiku = open("cat_haiku.txt", "r") - self.haikus = [] - haiku = [] - for line in fHaiku.readlines(): - if line != "\n": - haiku.append(line) - else: - self.haikus.append(haiku) - haiku = [] - fHaiku.close() + self.path = os.path.dirname(__file__)[(len(os.getcwd()) + 1):] + with open(os.sep.join([self.path, 'catfacts.txt']), 'r') as fd: + self.catFacts = fd.readlines() + with open(os.sep.join([self.path, 'cat_haiku.txt']), 'r') as fd: + self.haikus = [] + haiku = [] + for line in fd.readlines(): + if line != "\n": + haiku.append(line.strip()) + else: + self.haikus.append(haiku) + haiku = [] def description(self): return 'Generates Cat Facts and Haikus'