docs: def handle_msg(self, c, e):
          """The Heart and Soul of IrcBot."""
  
          if e.type not in ['authenticate', 'error', 'join', 'part', 'quit']:
              nick = e.source.nick
          else:
              nick = e.source
  
          if e.arguments is None:
              msg = ""
          else:
              msg = " ".join(e.arguments).strip()
  
          # Send the response to private messages to the sending nick.
          target = nick if e.type == 'privmsg' else e.target
  
          def send(msg, mtype='privmsg', target=target, ignore_length=False):
              self.send(target, self.connection.real_nickname, msg, mtype, ignore_length)
  
          if e.type in [
                  'account', 'authenticate', 'bannedfromchan', 'cap', 'ctcpreply', 'error', 'featurelist', 'nosuchnick', 'nick', 'nicknameinuse',
                  'privnotice', 'welcome', 'whospcrpl'
          ]:
              self.handle_event(msg, send, c, e)
              return
  
          # ignore empty messages
          if not msg and e.type != 'join':
              return
  
          self.do_log(target, nick, msg, e.type)
  
          if e.type == 'mode':
              self.do_mode(target, msg, nick, send)
              return
  
          if e.type == 'join':
              self.handle_join(c, e, target, send)
              return
  
          if e.type == 'part':
              if nick == c.real_nickname:
                  send("Parted channel %s" % target, target=self.config['core']['ctrlchan'])
              return
  
          if e.type == 'kick':
              self.handle_kick(c, e, target, send)
              return
  
          if e.target == self.config['core']['ctrlchan'] and self.is_admin(None, nick):
              control.handle_ctrlchan(self, msg, nick, send)
  
          if self.is_ignored(nick) and not self.is_admin(None, nick):
              return
  
          self.handle_hooks(send, nick, target, e, msg)
  
          # We only process hooks for notices, not commands.
          if e.type == 'pubnotice':
              return
  
          msg = misc.get_cmdchar(self.config, c, msg, e.type)
          cmd_name, cmdargs = self.get_cmd(msg)
  
          if registry.command_registry.is_registered(cmd_name):
              self.run_cmd(send, nick, target, cmd_name, cmdargs, e)
          # special commands
          elif cmd_name == 'reload':
              with self.db.session_scope() as session:
                  if session.query(orm.Permissions).filter(orm.Permissions.nick == nick).count():
                      send("Aye Aye Capt'n")