Commits

Marc-Alexandre Chan committed a8df299

Started to add logging messages to events

Comments (0)

Files changed (1)

minibot/events.py

 "DailyPromptBot? It's open-source! Here's [the DailyPromptBot "
 "repository](https://bitbucket.org/Laogeodritt/dailypromptbot).)")
 
+_evlog = logging.getLog('dailyprompt.minibot.events')
+
 
 class CommandError(MinibotError):
     """ Abstract base class for Command errors. """
 
         self.run()
 
-    def run(self): # TODO: handle exceptions from _parse_message, _parse_field, _make_command, and reddit (?)
+    def run(self):
         for msg in self.reddit.user.get_unread(limit=self.msg_chunk):
             msg_command = None
             # if a PM (no subreddit) and directly to the bot (not modmail)
                 msg_data = self._parse_message(msg)
                 msg_command = self._make_command(msg, msg_data)
             else: # bad message, ignore it
+                # if bad PM, log; don't care about replies/comments though
+                if msg.subreddit is None:
+                    _evlog.info(
+                        ("CheckMessageEvent: Ignoring bad PM from "
+                        "{user} ({id_:d})").ormat(user=msg.author, id_=msg.id))
                 msg.mark_as_read()
 
             if msg_command is not None:
         No validation of the data is performed.
 
         """
+        _evlog.debug('CheckMessageEvent:Parsing message {id_:d} from {user}.'.
+            format(id_=msg.id, user=msg.author))
         msg_data = {}
         text_data = []
 
         data. If the command name is invalid, raises a CommandNameError. If the
         command parameters are invalid or incomplete, raises a
         CommandParametersError (from the command constructor). """
+        _evlog.info('CheckMessageEvent: PM {id_:d}: building command: {info}'.
+                    format(id_=msg.id, info='; '.join(data)))
         if data['action'] in self.cmd_actions.keys():
             CommandClass = self.cmd_actions[data.pop('action')]
             cmd_obj = CommandClass(msg, **data)