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