Exemple #1
0
 def fetch_hwnd(self):
     """取到模拟器内部屏幕控件的句柄, 并绑定窗口"""
     if self.hwnd is None:
         try:
             logger.debug('trying to fetch the handler...')
             _ = win32gui.FindWindow('Qt5QWindowIcon', '崩坏3 - MuMu模拟器')
             self.hwnd = self.dm.EnumWindow(_, '', '', 4)
         except Exception as e:
             try:
                 logger.error(str(e), 'fail to fetch, attempting another way...')
                 hwnd_list = []
                 win32gui.EnumWindows(lambda h, param: param.append(h), hwnd_list)
                 for h in hwnd_list:
                     if '崩坏3' in win32gui.GetWindowText(h) or 'MuMu模拟器' in win32gui.GetWindowText(h):
                         self.hwnd = self.dm.EnumWindow(h, '', '', 4)
                         break
             except Exception as e:
                 raise HandlerError(str(e), 'catch a exception while reloading handler.')
         logger.debug('succeed finding handler')
     try:
         if not self.bind:
             self.bind = True
             self.dm.BindWindow(self.hwnd, 'dx2', 'dx', 'dx', 0)
             logger.debug('succeed fetching and binding')
     except Exception as e:
         raise HandlerError(str(e), 'can\'t bind the handler, because no handler found')
Exemple #2
0
    def run(self, *args, **kwargs) -> None:
        self.first_execution = time.perf_counter(
        )  # monotonic on both Windows and Linux which is :thumbsup:
        self.first_execution_dt = datetime.datetime.utcnow()
        if not kwargs.get("bot", True):
            log.fatal(
                "tried to login with a non-bot token (this framework is designed to run with a bot account)"
            )
            raise UserBotError("Non-bot accounts are not supported")

        # checks to make sure everything is a coroutine
        if config.debug:

            if any([
                    not asyncio.iscoroutinefunction(x)
                    for x in self._ready_handlers
            ]):
                log.critical("not all ready functions are coroutines")
                raise HandlerError("not all ready functions are coroutines")

            if any([
                    not asyncio.iscoroutinefunction(x)
                    for x in self._shutdown_handlers
            ]):
                log.critical("not all shutdown functions are coroutines")
                raise HandlerError("not all shutdown functions are coroutines")

            if any([
                    not asyncio.iscoroutinefunction(x)
                    for x in self._message_handlers
            ]):
                log.critical("not all message handlers are coroutines")
                raise HandlerError("not all message handlers are coroutines")

            if any([
                    not asyncio.iscoroutinefunction(x)
                    for x in self._member_join_handlers
            ]):
                log.critical("not all member join handlers are coroutines")
                raise HandlerError(
                    "not all member join handlers are coroutines")

            if any([
                    not asyncio.iscoroutinefunction(x)
                    for x in self._member_remove_handlers
            ]):
                log.critical("not all member leave handlers are coroutines")
                raise HandlerError(
                    f"not all member leave handlers are coroutines")

            log.debug("all functions good to run (are coroutines)")

        log.info(
            f"Bot started at {str(self.first_execution_dt)} ({self.first_execution})"
        )
        super().run(*args, **kwargs)
Exemple #3
0
    def extract(self, dir):
        try:
            self._file.extractall(dir)

        except zipfile.BadZipfile:
            raise HandlerError(
                _("Invalid zip file, it's either corrupted or "
                  "not a zip.")
            )
Exemple #4
0
    def namelist(self):
        try:
            return self._file.namelist()

        except zipfile.BadZipfile:
            raise HandlerError(
                _("Invalid zip file, it's either corrupted or "
                  "not a zip.")
            )
Exemple #5
0
    def __init__(self, file):
        try:
            self._file = zipfile.ZipFile(file)

        except zipfile.BadZipfile:
            raise HandlerError(
                _("Invalid zip file, it's either corrupted or "
                  "not a zip.")
            )
Exemple #6
0
 def register_handler(cls, handler_class):
     if not issubclass(handler_class, ShapefileHandler):
         raise HandlerError(_(u"Handler must inherit from ShapefileHandler"))
     cls._handlers.add(handler_class)
     return handler_class