示例#1
0
 def group(self, arg):
     '''
     群发模式,请指定群发模式: group id1 id2 id3 id... 消息将发送给指定的所有人
     '''
     user_name_list = []
     if len(arg) == 0:
         print(tdtr("请指定群发对象的id,例如: 'group 3 34 36 23 74'"))
         return
     elif arg[0] == '-inverse':  # 反选模式,指定的好友不会收到消息。
         for uid in [x.id for x in self.parent.getUsers()]:
             if str(uid) not in arg[1:]:
                 user_name_list.append(
                     self.parent.getUserByID(uid).userName)
     else:  # 正选模式
         for uid in arg:
             if uid == ' ':  # 过滤掉空格
                 continue
             try:
                 user_id = int(uid)
             except Exception:
                 continue
             user_name_list.append(
                 self.parent.getUserByID(user_id).userName)
     while (True):
         print(tdtr(
             "【群发模式】选定的{}位好友将收到此条信息 \n请输入要发送的内容,输入“cd ..”退出\n>>> ").format(
                 len(user_name_list)),
               end='')
         msg = td_input()
         if msg == 'cd ..' or msg == 'cd ../':
             # 退出聊天,把当前正在沟通的用户置为None
             self.parent.current_user = None
             break
         # 如果输入内容包含疑似cmd字符串,这个len不为0
         if len(
                 list(
                     filter(lambda x: True
                            if x in msg else False, cmd_list))) > 0:
             print(tdtr("您的输入中包含疑似shell终端命令的字符串,确认发送此消息吗?y or n"))
             res = td_input()
             if res == 'y' or res == 'yes':
                 pass
             else:
                 continue
         # 如果能走到这一步就发送数据
         for name in user_name_list:
             self.parent.sendMsg(msg,
                                 name)  # 将信息发送给user  userName是微信用于识别的用户名
示例#2
0
 def ignore(self,arg):
     '''
     忽略掉对应的内容
     '''    
     if arg == 'all':    # 忽略掉所有消息
         print(tdtr("确认忽略所有未读消息吗?y or n"))
         res = td_input()
         if res == 'y' or res == 'yes':
             # 忽略所有
             for user in self.getUsers():
                 user.msgs.clear()
         else:
             return
     else:
         try:
             uid = int(arg)
         except Exception :
             print(tdtr("参数错误,请重试"))
             return 
         if uid not in self.user_dict:
             print(tdtr("参数错误,请重试"))
             return  
         self.getUserByID(uid).msgs.clear()
示例#3
0
    def cd(self, arg):
        '''
        进入聊天室, cd {id}  进入与id进行聊天的界面
        '''
        if len(arg) == 0:
            print(tdtr("cd命令需要参数"))
            return
        elif arg[0] == '..' or arg[0] == '../':
            # 返回主页
            return
        else:
            try:
                user_id = int(arg[0])
            except Exception:
                print(tdtr("cd后请输入一个数字"))
                return
            user = self.parent.getUserByID(user_id)
            if user is None:  # 未找到用户 直接返回
                print(tdtr("用户id不存在,请重试"))
                return
            self.parent.current_user = user
            self.cls(None)
            # 进入与其聊天的死循环
            while True:
                # 进入后先把队列中的消息打印
                while user.hasNewMsg():
                    msg = user.takeMsg()
                    print("【{}】{} ===> :{}".format(msg.createTime,
                                                   msg.getName(), msg.text))
                print(tdtr(" 与 {} 聊天中 >>> ").format(user.getName()), end='')
                msg = td_input()
                if msg.strip() == 'cd ..' or msg.strip() == 'cd ../':
                    # 退出聊天,把当前正在沟通的用户置为None
                    self.parent.current_user = None
                    break
                if msg.strip() == "emoj":
                    print(
                        tdtr(
                            "检测到您的输入为:emoj,如果发送消息内容即为emoj直接回车键发送,如果查看所有emoj表情,请输入1:"
                        ))
                    res = td_input()
                    if res != "1":
                        pass
                    else:
                        print(emoj_list)
                        continue

                # 如果输入内容包含疑似cmd字符串,这个len不为0
                if len(
                        list(
                            filter(lambda x: True
                                   if x in msg else False, cmd_list))) > 0:
                    print(tdtr("您的输入中包含疑似shell终端命令的字符串,确认发送此消息吗?y or n"))
                    res = td_input()
                    if res == 'y' or res == 'yes':
                        pass
                    else:
                        continue
                # 如果能走到这一步就发送数据
                if user.id == 0 or user.id == '0':  # 处理发送给文件助手的消息
                    self.parent.sendMsg(msg, 'filehelper')
                else:
                    self.parent.sendMsg(
                        msg, user.userName)  # 将信息发送给user  userName是微信用于识别的用户名
示例#4
0
#     td_print("按了↑箭头")

# @register_func(CmdType.CMD_DOWN)
# def down():
#     td_print("按了↓箭头")

if __name__ == '__main__':
    td_print(">>> ***********************************")
    td_print(">>> **     TDInput输入模块测试程序   **")
    td_print(">>> **                               **")
    td_print(">>> **         输入exit退出          **")
    td_print(">>> ***********************************")
    try:
        while True:
            td_print(">>> ", end='')
            cmd = td_input().strip()  # 获取字符去除前后空格
            if cmd == '':  # 输入无效内容,直接跳过
                continue
            if cmd == 'exit':
                break
            # print(cmd)

    except Exception as e:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        td_print(exc_type, fname, exc_tb.tb_lineno)
        #rate.sleep()

# import threading

# if __name__ == '__main__':
示例#5
0
def minput():
    msg = td_input()
    history.append(msg)
    return msg