Community Bread

This commit is contained in:
lucidiot 2021-04-03 17:33:58 +02:00
parent 57df2b59e7
commit c7130e5f9b
3 changed files with 26 additions and 31 deletions

View File

@ -4,4 +4,13 @@ breadbot
A Python IRC bot built using the `pinhook`_ framework to encourage A Python IRC bot built using the `pinhook`_ framework to encourage
addiction to bread on breadpunk's own irc server. 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 .. _pinhook: https://github.com/archangelic/pinhook

View File

@ -1,20 +0,0 @@
bread
mmhhhh, 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

View File

@ -5,20 +5,26 @@ import re
import random import random
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
data_path = Path(__file__).absolute().parent.parent / 'data'
data_path = Path('/bread/breadbot')
count_file = data_path / 'breadcount.txt' count_file = data_path / 'breadcount.txt'
messages_file = data_path / 'bread_messages.txt' messages_file = data_path / 'bread_messages.txt'
word_regex = re.compile(r'\W') word_regex = re.compile(r'\W')
try:
bread_messages = messages_file.read_text().strip().splitlines() def get_that_bread():
assert bread_messages try:
except (IOError, TypeError, ValueError, AssertionError): bread_messages = messages_file.read_text().strip().splitlines()
if not messages_file.exists(): assert bread_messages
messages_file.write_text('bread\n') except (IOError, TypeError, ValueError, AssertionError):
logger.warning(f'Bread messages file at {messages_file} not found ' if not messages_file.exists():
'or corrupted, using ["bread"]') messages_file.write_text('bread\n')
bread_messages = ['bread'] 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(): def increment_bread():
@ -38,7 +44,7 @@ def bread(ctx):
if 'bread' in words: if 'bread' in words:
increment_bread() increment_bread()
if words == {'bread'}: if words == {'bread'}:
return plugin.message(random.choice(bread_messages)) return plugin.message(get_that_bread())
@plugin.command( @plugin.command(