diff --git a/README.rst b/README.rst index 6573b60..79362c6 100644 --- a/README.rst +++ b/README.rst @@ -4,4 +4,13 @@ breadbot A Python IRC bot built using the `pinhook`_ framework to encourage addiction to bread on breadpunk's own irc server. +Data files +---------- + +This bot expects a ``/bread/breadbot`` folder to exist, and will +use it to store the breadcount in ``breadcount.txt``. It will also +use the ``/bread/bread_messages.txt`` file if it is available to give +interesting replies instead of just saying ``bread`` when you say +``bread``. + .. _pinhook: https://github.com/archangelic/pinhook diff --git a/breadbot/data/bread_messages.txt b/breadbot/data/bread_messages.txt deleted file mode 100644 index d349822..0000000 --- a/breadbot/data/bread_messages.txt +++ /dev/null @@ -1,20 +0,0 @@ -bread -mmhhhh, bread -bread!!! -bread -🅱️ r e a d -baguette -bagel -waffle -le pain -brode -Adrian Bready -Breadley Cooper -toast -Sometimes you get the crumb, sometimes the crust. -muffin -pita -bread pudding -ciabatta -Jared Breado -roll \ No newline at end of file diff --git a/breadbot/plugins/bread.py b/breadbot/plugins/bread.py index 773fc20..8468d01 100644 --- a/breadbot/plugins/bread.py +++ b/breadbot/plugins/bread.py @@ -5,20 +5,26 @@ import re import random logger = logging.getLogger(__name__) -data_path = Path(__file__).absolute().parent.parent / 'data' + +data_path = Path('/bread/breadbot') count_file = data_path / 'breadcount.txt' messages_file = data_path / 'bread_messages.txt' + word_regex = re.compile(r'\W') -try: - bread_messages = messages_file.read_text().strip().splitlines() - assert bread_messages -except (IOError, TypeError, ValueError, AssertionError): - if not messages_file.exists(): - messages_file.write_text('bread\n') - logger.warning(f'Bread messages file at {messages_file} not found ' - 'or corrupted, using ["bread"]') - bread_messages = ['bread'] + +def get_that_bread(): + try: + bread_messages = messages_file.read_text().strip().splitlines() + assert bread_messages + except (IOError, TypeError, ValueError, AssertionError): + if not messages_file.exists(): + messages_file.write_text('bread\n') + logger.warning(f'Bread messages file at {messages_file} not found ' + 'or corrupted, using ["bread"]') + bread_messages = ['bread'] + + return random.choice(bread_messages) def increment_bread(): @@ -38,7 +44,7 @@ def bread(ctx): if 'bread' in words: increment_bread() if words == {'bread'}: - return plugin.message(random.choice(bread_messages)) + return plugin.message(get_that_bread()) @plugin.command(