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,11 +5,15 @@ 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')
def get_that_bread():
try: try:
bread_messages = messages_file.read_text().strip().splitlines() bread_messages = messages_file.read_text().strip().splitlines()
assert bread_messages assert bread_messages
@ -20,6 +24,8 @@ except (IOError, TypeError, ValueError, AssertionError):
'or corrupted, using ["bread"]') 'or corrupted, using ["bread"]')
bread_messages = ['bread'] bread_messages = ['bread']
return random.choice(bread_messages)
def increment_bread(): def increment_bread():
try: try:
@ -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(