X-Git-Url: https://apps.delaporte.us/gitweb/matrix-goal-bot.git/blobdiff_plain/390a4cf60a66718bed359b3a4141a51d0f9571b0..421f514aa0533cdcead40f2c689548b96a29885e:/matrix_goal_bot/bot.py diff --git a/matrix_goal_bot/bot.py b/matrix_goal_bot/bot.py index dce0f73..4bfce67 100644 --- a/matrix_goal_bot/bot.py +++ b/matrix_goal_bot/bot.py @@ -24,6 +24,7 @@ More commands: set.vision GOAL_ID VISION_ID- associate GOAL_ID with VISION_ID visions - list incomplete visions list.done - list completed goals + remove ID - remove a task by ID visionless - list goals with no set vision ''' @@ -42,8 +43,6 @@ def today(): return dt.now().strftime(DATE_FORMAT) logger = logging.getLogger(__name__) -logging.basicConfig(filename='matrix-goal-bot.log', encoding='utf-8', level=logging.DEBUG) -logging.getLogger('nio').setLevel(logging.WARNING) snark = [ 'Ye cannot get ye flask.', @@ -69,14 +68,20 @@ class GoalBot(): self.data = Data(db_file) def run(self): + logger.debug('Running goal bot...') self.bot.run() async def handle_message(self, room, message): match = botlib.MessageMatch(room, message, self.bot, self.prefix) - if not match.is_not_from_this_bot() and match.prefix(): + if not match.is_not_from_this_bot(): + # Let's not talk to our-self return + logger.debug(f'Message: {message}') + if not match.prefix(): + logger.debug(f'{message} - did not match {self.prefix}') + if match.prefix(): try: result_lines = await self._handle_match(match) @@ -84,11 +89,18 @@ class GoalBot(): await self.bot.api.send_text_message( room.room_id, str(line)) except Exception as ex: + logger.warn(f'Caught exception: {str(ex)}') + dumb_msg_idx = len(str(ex)) % len(snark) + dumb_msg = snark[dumb_msg_idx] + await self.bot.api.send_text_message( + room.room_id, dumb_msg) + await self.bot.api.send_text_message( room.room_id, str(ex)) async def _handle_match(self, match): + logger.debug(f'Try to match {str(match)}') if match.command('setup'): result = self.data.setup() @@ -96,10 +108,18 @@ class GoalBot(): if match.command('add'): new = ' '.join(match.args()[1:]) - result = self.data.add_goal(new) - return [f'Goal added with id {result}'] + goal_id = self.data.add_goal(new) + results = [f'Goal added with id {goal_id}'] + + goals = self.data.get_all_goals() + results.append('# Goals list...') + for goal in goals: + results.append(str(goal)) + + return results if match.command('list'): + logger.debug('Asked to list goals...') goals = self.data.get_all_goals() results = ['# Goals list...'] for goal in goals: