X-Git-Url: https://apps.delaporte.us/gitweb/matrix-fridge-bot.git/blobdiff_plain/98abdc941c39a6dea3d3b5afb7cd3e13bcec5167..2f917aaa798317cb369c0226ff059bf83d01fbe6:/matrix_fridge_bot/bot.py?ds=sidebyside diff --git a/matrix_fridge_bot/bot.py b/matrix_fridge_bot/bot.py index 2484c46..ff6a5e6 100644 --- a/matrix_fridge_bot/bot.py +++ b/matrix_fridge_bot/bot.py @@ -1,17 +1,15 @@ ''' -Prefix: !chore +Prefix: .fridge Synax: -!chore COMMAND ARGS +.fridge COMMAND ARGS Commands: -help - show this help -add - add a chore -check - check status of a chore -done - mark a chore as done -list - print the chore list -filter TERM - list all chores that include TERM -undo - mark a chore as undone +add - add an item +list - print the list of fresh items +remove - remove an item +to.toss - print the list of items to toss +filter TERM - list all items that include TERM ''' from datetime import datetime as dt @@ -20,25 +18,27 @@ import os import simplematrixbotlib as botlib -from .db import Data as ChoreData +from .db import Data logger = logging.getLogger(__name__) logging.getLogger('nio').setLevel(logging.WARNING) -class ChoreBot(): +MODULE='fridge' + +class FridgeBot(): def __init__(self, matrix_server, bot_name, bot_pwd, db_file=None, - bot_prefix='!chore'): + bot_prefix='.fridge'): - logging.basicConfig(filename='matrix-chore-bot.log', encoding='utf-8', level=logging.DEBUG) + logging.basicConfig(filename=f'matrix-{MODULE}-bot.log', encoding='utf-8', level=logging.DEBUG) creds = botlib.Creds(matrix_server, bot_name, bot_pwd) self.bot = botlib.Bot(creds) self.prefix = bot_prefix - self.data = ChoreData(db_file=db_file) + self.data = Data(db_file=db_file) def run(self): self.bot.run() @@ -52,9 +52,16 @@ class ChoreBot(): if match.prefix(): try: result_lines = await self._handle_match(match) + + message_lines = [] for line in result_lines: - await self.bot.api.send_text_message( - room.room_id, str(line)) + message_lines.append(str(line)) + + message = '\n'.join(message_lines) + + await self.bot.api.send_text_message( + room.room_id, message) + except Exception as ex: line = f'Ye flask must be load bearing, or something... {str(ex)}' await self.bot.api.send_text_message( @@ -64,12 +71,21 @@ class ChoreBot(): async def _handle_match(self, match): if match.command('list'): - results = ['## Listing all...'] + results = ['## Listing fresh items...'] for item in self.data.list(): results.append(item) results.append('-- End of List --') return results + + if match.command('toss'): + results = ['## Listing items to toss...'] + for item in self.data.to_toss(): + results.append(item) + results.append('-- End of List --') + return results + + if match.command('filter'): term = ' '.join(match.args()[1:]) results = [f'## List matching {term}'] @@ -80,37 +96,20 @@ class ChoreBot(): if match.command('setup'): results = [] - results.append('Doing chore setup...') + results.append('Doing fridge setup...') result = self.data.setup() results.append(str(result)) return results if match.command('add'): - new_chore = ' '.join(match.args()[1:]) - result = self.data.add(new_chore) - return [result] - - if match.command('check'): - chore_id = match.args()[1] - result = self.data.check(chore_id) + new_fridge = ' '.join(match.args()[1:]) + result = self.data.add(new_fridge) return [result] - if match.command('done'): - ids = match.args()[1:] - results = [] - for chore_id in ids: - result = self.data.done(chore_id) - results.append(result) - return results - - if match.command('undo'): - chore_id = match.args()[1] - result = self.data.undo(chore_id) - return [result] if match.command('remove'): - chore_id = match.args()[1] - result = self.data.remove(chore_id) + fridge_id = match.args()[1] + result = self.data.remove(fridge_id) return [result] return [__doc__]