Browse Source

Community Bread

pull/2/head
lucidiot 4 months ago
parent
commit
c7130e5f9b
  1. 9
      README.rst
  2. 20
      breadbot/data/bread_messages.txt
  3. 28
      breadbot/plugins/bread.py

9
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

20
breadbot/data/bread_messages.txt

@ -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

28
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(

Loading…
Cancel
Save