]> us-delaporte.pagekite.me Git - matrix-goal-bot.git/blobdiff - matrix_goal_bot/bot.py
Add snark
[matrix-goal-bot.git] / matrix_goal_bot / bot.py
index dce0f73c895130c99a3aad6c82310557cefee205..1a2bd2faf6f61b981907d8426d1b434e77fee9e8 100644 (file)
@@ -42,8 +42,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 +67,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):
+        logger.debug(f'Message: {message}')
         match = botlib.MessageMatch(room, message, self.bot, self.prefix)
 
         if not match.is_not_from_this_bot() and match.prefix():
+            logger.debug(f'Message: {message} was not for this bot.')
             return
 
+        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 +88,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()
@@ -100,6 +111,7 @@ class GoalBot():
             return [f'Goal added with id {result}']
 
         if match.command('list'):
+            logger.debug('Asked to list goals...')
             goals = self.data.get_all_goals()
             results = ['# Goals list...']
             for goal in goals: