Exemple #1
0
    def configure(self):
        p = self.absPath('plugins')
        if not os.path.exists(p):
            try:
                os.mkdir(p)
            except:
                pass

        if os.path.isdir(p):
            if p not in sys.path:
                sys.path.insert(0, p)
            self.pluginPath1 = SYSTEMSTR2STR(p)
        else:
            self.pluginPath1 = None

        if self.pluginPath:
            p = os.path.abspath(STR2SYSTEMSTR(self.pluginPath))
            if p not in sys.path:
                sys.path.insert(0, p)
            self.pluginPath = SYSTEMSTR2STR(p)

        try:
            import qqbotdefault as q
        except ImportError:
            pass
        else:
            for x, name, y in pkgutil.iter_modules(q.__path__,
                                                   q.__name__ + '.'):
                self.plugins.append(name)

        SetLogLevel(self.debug and 'DEBUG' or 'INFO')
Exemple #2
0
    def configure(self):
        if self.pluginPath:
            p = os.path.abspath(STR2SYSTEMSTR(self.pluginPath))
            if p not in sys.path:
                sys.path.insert(0, p)

        SetLogLevel(self.debug and 'DEBUG' or 'INFO')
Exemple #3
0
    def configure(self):
        p = self.absPath('plugins')
        if not os.path.exists(p):
            try:
                os.mkdir(p)
            except:
                pass

        if os.path.isdir(p):
            if p not in sys.path:
                sys.path.insert(0, p)
            self.pluginPath1 = SYSTEMSTR2STR(p)
        else:
            self.pluginPath1 = None

        if self.pluginPath:
            p = os.path.abspath(STR2SYSTEMSTR(self.pluginPath))
            if p not in sys.path:
                sys.path.insert(0, p)
            self.pluginPath = STR2SYSTEMSTR(p)

        SetLogLevel(self.debug and 'DEBUG' or 'INFO')
Exemple #4
0
    def readConfFile(self):
        confPath = self.ConfPath()
        strConfPath = SYSTEMSTR2STR(confPath)
        conf = rootConf.copy()

        if os.path.exists(confPath):
            try:
                with open(confPath, 'rb') as f:
                    cusConf = ast.literal_eval(BYTES2STR(f.read()))

                if type(cusConf) is not dict:
                    raise ConfError('文件内容必须是一个 dict')

                if type(cusConf.get('默认配置', {})) is not dict:
                    raise ConfError('默认配置必须是一个 dict')

                if self.user is not None:
                    if self.user not in cusConf:
                        raise ConfError('用户 %s 不存在' % self.user)
                    elif type(cusConf[self.user]) is not dict:
                        raise ConfError('用户 %s 的配置必须是一个 dict' % self.user)
                    else:
                        names = ['默认配置', self.user]
                else:
                    names = ['默认配置']

                for name in names:
                    for k, v in list(cusConf.get(name, {}).items()):
                        if k in deprecatedConfKeys:
                            PRINT('被废弃的配置选项 %s ,将忽略此选项' % k)
                        elif k not in conf:
                            raise ConfError('不存在的配置选项 %s.%s ' % (name, k))
                        elif type(v) is not type(conf[k]):
                            t = type(conf[k]).__name__
                            raise ConfError('%s.%s 必须是一个 %s' % (name, k, t))
                        else:
                            conf[k] = v

            except (IOError, SyntaxError, ValueError, ConfError) as e:
                PRINT('配置文件 %s 错误: %s\n' % (strConfPath, e), end='')
                sys.exit(1)

        else:
            PRINT('未找到配置文件“%s”,将使用默认配置' % strConfPath)
            try:
                with open(confPath, 'wb') as f:
                    f.write(STR2BYTES(sampleConfStr))
            except IOError:
                pass
            else:
                PRINT('已创建一个默认配置文件“%s”' % strConfPath)

            if self.user is not None:
                PRINT('用户 %s 不存在\n' % self.user, end='')
                sys.exit(1)

        for k, v in list(conf.items()):
            if getattr(self, k, None) is None:
                setattr(self, k, v)

        if self.pluginPath and not os.path.isdir(STR2SYSTEMSTR(
                self.pluginPath)):
            PRINT('配置文件 %s 错误: 插件目录 “%s” 不存在\n' % \
                  (strConfPath, self.pluginPath), end='')
            sys.exit(1)

        if self.mailAccount and not self.mailAuthCode:
            msg = '请输入 %s 的 IMAP/SMTP 服务授权码: ' % self.mailAccount
            self.mailAuthCode = RAWINPUT(msg)

        if self.cmdQrcode:
            try:
                import PIL
                import wcwidth
            except ImportError:
                PRINT('您已选择以文本模式显示二维码,请先安装 pillow, wcwidth 库')
                sys.exit(1)
Exemple #5
0
    def readCmdLine(self):
        parser = argparse.ArgumentParser()

        parser.add_argument('-u',
                            '--user',
                            help=STR2SYSTEMSTR('指定一个配置文件项目以导入设定。USER指的是配置文\n'
                                               '件项目的名称。注意:所有从命令行中指定的参数设定的\n'
                                               '优先级都会高于从配置文件中获取的设定。\n'))

        parser.add_argument('-q',
                            '--qq',
                            help=STR2SYSTEMSTR('指定本次启动时使用的QQ号。如果指定的QQ号的自动登\n'
                                               '陆信息存在,那么将会使用自动登陆信息进行快速登陆。'))

        parser.add_argument('-p',
                            '--termServerPort',
                            type=int,
                            help=STR2SYSTEMSTR(
                                '更改QTerm控制台的监听端口到 TERMSERVERPORT 。\n'
                                '默认的监听端口是 8189 (TCP)。'))

        parser.add_argument('-ip',
                            '--httpServerIP',
                            help=STR2SYSTEMSTR('指定HTTP服务要监听在哪个IP地址上。如需在所有网络\n'
                                               '接口上监听,请指定 "0.0.0.0" 。'))

        parser.add_argument('-hp',
                            '--httpServerPort',
                            type=int,
                            help=STR2SYSTEMSTR('指定HTTP服务要监听在哪个端口上。'))

        parser.add_argument('-m',
                            '--mailAccount',
                            help=STR2SYSTEMSTR('指定用于接收二维码的收件邮箱地址。'))

        parser.add_argument('-mc',
                            '--mailAuthCode',
                            help=STR2SYSTEMSTR('设置接收账户的授权码(如果需要的话)。如果命令行和\n'
                                               '配置文件中都没有指定授权码,但收件邮箱地址已指定,\n'
                                               '则QQbot将会在启动时要求输入授权码。'))

        parser.add_argument('-d',
                            '--debug',
                            action='store_true',
                            default=None,
                            help=STR2SYSTEMSTR('启用调试模式。'))

        parser.add_argument('-nd',
                            '--nodebug',
                            action='store_true',
                            help=STR2SYSTEMSTR('停用调试模式'))

        parser.add_argument('-r',
                            '--restartOnOffline',
                            action='store_true',
                            default=None,
                            help=STR2SYSTEMSTR('在掉线时自动重新启动。'))

        parser.add_argument('-nr',
                            '--norestart',
                            action='store_true',
                            help=STR2SYSTEMSTR('在掉线时不要重新启动。'))

        parser.add_argument('-fi',
                            '--fetchInterval',
                            type=int,
                            help=STR2SYSTEMSTR('每轮联系人列表刷新之间的间歇时间(秒)'))

        opts = parser.parse_args()

        if opts.nodebug:
            opts.debug = False

        if opts.norestart:
            opts.restartOnOffline = False

        delattr(opts, 'nodebug')
        delattr(opts, 'norestart')

        for k, v in list(opts.__dict__.items()):
            if getattr(self, k, None) is None:
                setattr(self, k, v)