コード例 #1
0
ファイル: sync.py プロジェクト: Terrance/IMMP
 async def _rename_user(self, user, channel):
     config = self._plug_config(channel)
     # Use name-format or identities to render a suitable author real name.
     base = (user.real_name or user.username) if user else None
     name = None
     identity = None
     force = False
     if user and self._identities:
         try:
             identity = await self._identities.identity_from_user(user)
         except Exception:
             log.warning("Failed to retrieve identity information for %r",
                         user,
                         exc_info=True)
     if config["name-format"]:
         if not Template:
             raise immp.PlugError("'jinja2' module not installed")
         title = await channel.title() if channel else None
         context = {"user": user, "identity": identity, "channel": title}
         try:
             name = Template(config["name-format"]).render(**context)
         except TemplateError:
             log.warning("Bad name format template", exc_info=True)
         else:
             # Remove the user's username, so that this name is always used.
             force = True
     elif identity:
         name = "{} ({})".format(base, identity.name)
     if config["strip-name-emoji"]:
         if not EMOJI_REGEX:
             raise immp.PlugError("'emoji' module not installed")
         current = name or base
         if current:
             name = EMOJI_REGEX.sub(_emoji_replace, current).strip()
     if not name:
         return user
     elif config["reset-author"] or not user:
         log.debug("Creating unlinked user with real name: %r", name)
         return immp.User(real_name=name,
                          suggested=(user.suggested if user else False))
     else:
         log.debug("Copying user with new real name: %r -> %r", user, name)
         return immp.User(id_=user.id,
                          plug=user.plug,
                          real_name=name,
                          username=(None if force else user.username),
                          avatar=user.avatar,
                          link=user.link,
                          suggested=user.suggested)
コード例 #2
0
ファイル: sync.py プロジェクト: Terrance/IMMP
 async def put(self, channel, msg):
     if channel.source in self._hook.config["channels"]:
         ref = await self._hook.send(channel.source, msg)
         return [immp.Receipt(ref.key, channel)]
     else:
         raise immp.PlugError("Send to unknown sync channel: {}".format(
             repr(channel)))
コード例 #3
0
 def write_config(self):
     """
     Write the live config out to the target config file, if writing is enabled.
     """
     if not self.writeable:
         raise immp.PlugError("Writing not enabled")
     log.info("Writing config file")
     anyconfig.dump(self.config_full, self._path)
コード例 #4
0
 def __init__(self, name, config, host):
     super().__init__(name, config, host)
     if self.config["console"] == "ptpython":
         if ptpython:
             log.debug("Using ptpython console")
             self.console = self._ptpython
         else:
             raise immp.PlugError("'ptpython' module not installed")
     else:
         log.debug("Using native console")
         self.console = self._code
コード例 #5
0
ファイル: sync.py プロジェクト: raveinid/IMMP
 async def _rename_user(self, user, channel):
     # Use name-format or identities to render a suitable author real name.
     renamed = name = identity = None
     if not self.config["reset-author"]:
         renamed = user
     if self._identities:
         try:
             identity = await self._identities.identity_from_user(user)
         except Exception as e:
             log.warning("Failed to retrieve identity information for %r", user,
                         exc_info=e)
     if self.config["name-format"]:
         if not Template:
             raise immp.PlugError("'jinja2' module not installed")
         title = await channel.title() if channel else None
         context = {"user": user, "identity": identity, "channel": title}
         name = Template(self.config["name-format"]).render(**context)
         if not name and self.config["reset-author"]:
             user = None
     elif self.config["reset-author"]:
         user = None
     elif identity:
         name = "{} ({})".format(user.real_name or user.username, identity.name)
     elif self.config["strip-name-emoji"] and user:
         name = user.real_name or user.username
     if not name:
         return user
     if self.config["strip-name-emoji"]:
         if not EMOJI_REGEX:
             raise immp.PlugError("'emoji' module not installed")
         name = EMOJI_REGEX.sub(_emoji_replace, name).strip()
     if renamed:
         log.debug("Replacing real name: %r -> %r", renamed.real_name, name)
         renamed = copy(renamed)
         renamed.real_name = name
     else:
         log.debug("Adding real name: %r", name)
         renamed = immp.User(real_name=name)
     return renamed
コード例 #6
0
 def __init__(self, name, config, host):
     super().__init__(name, config, host)
     warn("ShellHook is deprecated, migrate to AsyncShellHook",
          DeprecationWarning)
     if self.config["console"] == "ptpython":
         if ptpython:
             log.debug("Using ptpython console")
             self.console = self._ptpython
         else:
             raise immp.PlugError("'ptpython' module not installed")
     else:
         log.debug("Using native console")
         self.console = self._code
コード例 #7
0
ファイル: database.py プロジェクト: Terrance/IMMP
 def __init__(self, name, config, host):
     super().__init__(name, config, host)
     warn("DatabaseHook is deprecated, migrate to AsyncDatabaseHook", DeprecationWarning)
     if not Model:
         raise immp.PlugError("'peewee' module not installed")
     self.db = None
コード例 #8
0
ファイル: database.py プロジェクト: Terrance/IMMP
 def __init__(self, name, config, host):
     super().__init__(name, config, host)
     if not Tortoise:
         raise immp.PlugError("'tortoise' module not installed")
コード例 #9
0
 def __init__(self, name, config, host):
     super().__init__(name, config, host)
     if not aioconsole:
         raise immp.PlugError("'aioconsole' module not installed")
     self.buffer = None
     self._server = None