Esempio n. 1
0
def QTerm():
    port = getPort()
    req = 'help'
    while req != 'quit':
        if req:
            resp = query(port, req)
            if not resp:
                RAWINPUT('与 QQBot term 服务器的连接已断开,按回车键退出')
                break
            if resp == 'QQBot已停止':
                RAWINPUT('QQBot已停止,按回车键退出')
                break
            resp = resp.strip()
            while True:
                front, resp = Utf8Partition(resp, 800)
                if resp:
                    RAWINPUT(front)
                else:
                    resp = front
                    break
        else:
            resp = ''

        if resp:
            req = RAWINPUT(resp + '\nqterm>> ').strip()
        else:
            req = RAWINPUT('qterm>> ').strip()
Esempio n. 2
0
def qterm(port):
    req = 'help'
    while req != 'quit':
        if req:
            resp = query(port, req)
            if not resp:
                RAWINPUT('与 QQBot term 服务器的连接已断开,按回车键退出')
                break
            if resp == 'QQBot已停止':
                RAWINPUT('QQBot已停止,按回车键退出')
                break
            resp = resp.strip()
            while True:
                front, resp = partition(resp)
                if resp:
                    RAWINPUT(front + '--More--')
                else:
                    resp = front
                    break
        else:
            resp = ''

        if resp:
            req = RAWINPUT(resp + '\nqterm>> ').strip()
        else:
            req = RAWINPUT('qterm>> ').strip()
Esempio n. 3
0
 def readConfFile(self):
     conf = ast.literal_eval(sampleConfStr)['默认配置']
     
     confPath = self.ConfPath()
     
     if os.path.exists(confPath):
         try:
             with open(confPath) as f:
                 cusConf = ast.literal_eval(f.read())
 
             if type(cusConf) is not dict:
                 raise ConfError('文件内容必须是一个dict')
                 
             elif self.user is None:
                 pass
             
             elif 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:        
                 for k, v in cusConf[self.user].items():
                     if k not in conf:
                         raise ConfError(
                             '不存在的配置选项 %s.%s ' % (self.user, k)
                         )
                            
                     elif type(v) is not type(conf[k]):
                         raise ConfError(
                             '%s.%s 必须是一个 %s' % 
                             (self.user, k, type(conf[k]).__name__)
                         )
 
                     else:
                         conf[k] = v
                         
         except (IOError, SyntaxError, ValueError, ConfError) as e:
             utf8Stdout.write('配置文件 %s 错误: %s\n' % (confPath, e))
             sys.exit(1)
     
     else:
         try:
             with open(confPath, 'w') as f:
                 f.write(sampleConfStr)
         except IOError:
             pass
         
         if self.user is not None:
             utf8Stdout.write('用户 %s 不存在\n' % self.user)
             sys.exit(1)
     
     for k, v in conf.items():
         if getattr(self, k) is None:
             setattr(self, k, v)
     
     if self.mailAccount and not self.mailAuthCode:
         msg = '请输入 %s 的 IMAP/SMTP 服务授权码: ' % self.mailAccount
         self.mailAuthCode = RAWINPUT(msg)
Esempio n. 4
0
    def getUserInfo(self, userName, version):
        self.version = version
        userName = str(userName) if userName else QQBotConf.defaultUser
        userInfo = QQBotConf.userInfo.get(userName, QQBotConf.userDefInfo)

        for k in QQBotConf.userDefInfo:
            self.__dict__[k] = str(userInfo.get(k, ''))

        if (not self.QQ) and userName.isdigit():
            self.QQ = userName

        argv = sys.argv[1:]
        if '-ac' in argv or '--mail-auth-code' in argv:
            if '-ac' in argv:
                i = argv.index('-ac')
            else:
                i = argv.index('--mail-auth-code')

            if i < len(argv) - 1 and argv[i + 1] and argv[i + 1][0] != '-':
                self.mailAuthCode = argv[i + 1]

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

        self.userName = userName
Esempio n. 5
0
    def getUserInfo(self, userName, version):
        self.version = version
        userName = str(userName) if userName else QQBotConf.defaultUser
        userInfo = QQBotConf.userInfo.get(userName, QQBotConf.userDefInfo)

        for k in QQBotConf.userDefInfo:
            self.__dict__[k] = str(userInfo.get(k, ''))

        if (not self.QQ) and userName.isdigit():
            self.QQ = userName

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

        self.userName = userName