Пример #1
0
 def do_nickname(self,nick):
     if '#' in nick:
         nick = nick.strip()
         i = nick.index('#')
         trip = util.tripcode(nick[:i],nick[i+1:])
         nick = util.filter_unicode(nick[:i])
         for c in nick:
             if c in self._bad_chars:
                 return self._rand_nick(6)
         nick += '|' 
         return nick + trip[:len(trip)/2]        
     return self._rand_nick(6)
Пример #2
0
def wxlogin():
    window.geometry('400x500+400+100')
    login_frame = LoginFrame(window)
    login_frame.pack()
    wxbot = wx.Bot(qr_callback=login_frame.qr_callback,
                   login_callback=login_frame.login_callback,
                   logout_callback=logout_callback)
    wxbot.enable_puid('wxpy_puid.pkl')
    wxbot.core.send_video()
    init_user(wxbot)
    logger.info('%s login', util.filter_unicode(wxbot.self.name))
    login_frame.destroy()
    return wxbot
Пример #3
0
 def __init__(self,
              bdz,
              zxl,
              fzxl,
              tq,
              name,
              wxgroup=None,
              row=None,
              valid=True):
     """
     :param bdz:     变电站
     :param zxl:     主线路
     :param fzxl:    分支线路
     :param tq:      台区
     :param name:    群名称
     """
     self.bdz = filter_unicode(bdz)
     self.zxl = filter_unicode(zxl)
     self.fzxl = filter_unicode(fzxl)
     self.tq = filter_unicode(tq)
     self.name = filter_unicode(name)
     self.wxgroup = wxgroup
     self.row = row
     self.valid = valid
Пример #4
0
def parse_group(wxbot, encoding):
    """
    从文件中解析微信群
    """

    name = util.filter_unicode(wxbot.self.name)
    filepath = util.GROUP_PATH + path.sep + name + '.csv'
    wxgroups = wxbot.groups()
    groups = []
    logger.info(encoding)

    try:
        if not os.path.exists(filepath):
            with open(filepath, 'w', encoding=encoding) as f:
                f.write('变电站,主线路,分支线路,台区,群名称\n')
                for g in wxgroups:
                    if not has_not_unicode(g.name):
                        f.write(',,,,' + g.name + '\n')
                        groups.append(Group('', '', '', '', g.name, wxgroup=g))
        else:
            wxgroup_dict = {g.name: g for g in wxgroups}
            with open(filepath, encoding=encoding) as f:
                f.readline()  # skip title
                for line in f:
                    if len(line.strip()) == 0:
                        continue
                    bdz, zxl, fzxl, tq, name = line.strip().split(',', 4)
                    if name in wxgroup_dict:
                        groups.append(
                            Group(bdz,
                                  zxl,
                                  fzxl,
                                  tq,
                                  name,
                                  wxgroup=wxgroup_dict[name]))
                    else:
                        groups.insert(
                            0, Group(bdz, zxl, fzxl, tq, name, valid=False))
    except Exception as e:
        raise Exception('解析微信群信息时异常,请检查:' + filepath, e)
    return groups
Пример #5
0
    def got_line(self,inbuffer):
        p = inbuffer.split(' ')
        l = len(p)
        data = inbuffer.lower()
        
        if data.startswith('quit'):
            self.close_when_done()
            return
        if data.startswith('ping'):
            if len(p) != 2:
                return
            self.on_ping(p[1])
            return
        if data.startswith('pong'):
            if len(p) != 2:
                return
            self.on_pong(p[1])
            return
        
        #if data.startswith('user') and l > 1:
        #    self.usr = p[1]

        if data.startswith('nick') and l > 1:
            self.dbg('got nick: %s'%p[1])
            nick = self.do_nickname(p[1])
            if not self.welcomed and len(self.nick) == 0:
                self.nick = p[1]
                self.server.add_user(self)
            self.server.change_nick(self,nick)
        if not self.welcomed:
            return

        if data.startswith('mode'):
            if len(p) > 1 and p[1][0] in ['&','#']: #channel mode
                #the spec doesn't actually say when we're supposed to send this
                #TODO: find out wtf to do in edge cases like 404, etc.
                self.send_num(324,'%s +'%(p[1]))
            elif len(p) == 3: #user mode
                if p[1] == self.nick:
                    self.set_mode(p[2])
                else:
                    self.send_num(502, ':Cannot change mode for other users')
            elif len(p) == 2: #user get mode
                if p[1] == self.nick:
                    self.send_num(221, '+'+''.join(self.modes))

        # try uncommmenting for now
        #if data.startswith('who'):
        #    if len(p) > 1:
        #        if p[1][0] in ['#','&']:
        #            chan = p[1]
        #            if chan in self.chans:
        #                if chan in self.server.chans:
        #                    self.server.chans[chan].send_who(self)
        if data.startswith('part'):
            chans = p[1].split(',')
            for chan in chans:
                if chan in self.chans:
                    self.part_chan(chan)
        if data.startswith('privmsg'):
            c = inbuffer.split(':')
            msg = ':'.join(c[1:])
            target = p[1]
            self.server.privmsg(self,target,msg)
        if data.startswith('topic'):
            c = inbuffer.split(':')
            msg = ':'.join(c[1:])
            msg = util.filter_unicode(msg)
            chan = p[1]
            self.topic(chan,msg)
        if data.startswith('motd'):
            self.server.send_motd(self)
        if data.startswith('join'):
            if l == 1:
                self.send_raw(461, '%s :Not enough parameters'%p[0])
                return
            chans = p[1].split(',')
            for chan in chans:
                chan = util.filter_unicode(chan.strip())
                if len(chan) > 1:
                    self.join_chan(chan)
        if data.startswith('names'):
            for chan in p[1].split(','):
                if chan in self.chans:
                    self.server.chans[chan].send_who(self)
        if data.startswith('list'):
            self.server.send_list(self)
Пример #6
0
    def __init__(self,
                 master,
                 wxbot,
                 templates,
                 send_method,
                 stop_send_method,
                 width=300,
                 height=500):
        tk.Frame.__init__(self, master)
        self.wxbot = wxbot
        self.send_method = send_method
        self.stop_send_method = stop_send_method
        tk.Label(self,
                 text='您好, %s' % (util.filter_unicode(wxbot.self.name)),
                 pady=5).grid(row=0,
                              column=0,
                              columnspan=2,
                              sticky=tk.E + tk.W + tk.N + tk.S)
        logout = tk.Label(self, text='退出', cursor='hand2', padx=5)
        logout.grid(row=0, column=2, sticky=tk.E)
        logout.bind('<Button-1>', lambda e: wxbot.logout())

        # 消息输入框
        book = ttk.Notebook(self, width=width, height=height)
        texts = [tk.Text(book) for _ in templates]
        for text, template in zip(texts, templates):
            text.insert(tk.END, template.content)
            book.add(text,
                     text=template.name,
                     sticky=tk.N + tk.E + tk.S + tk.W)
        book.grid(row=1,
                  column=0,
                  columnspan=3,
                  sticky=tk.E + tk.W + tk.N + tk.S)
        self.texts = texts
        self.book = book

        # 文件选择
        self.file_path = tk.StringVar()
        self.file_entry = tk.Entry(self, textvariable=self.file_path, width=25)
        self.file_entry.grid(row=2, column=0, sticky=tk.W)
        tk.Button(master=self, text='选择',
                  command=self.select_file).grid(row=2, column=1, sticky=tk.W)

        # 发送按扭
        self.send_btn_text = tk.StringVar(value='发送')
        self.send_btn = tk.Button(self,
                                  textvariable=self.send_btn_text,
                                  command=self.send_massage,
                                  width=8,
                                  bg='#DDD')
        self.send_btn.grid(row=2, column=2, sticky=tk.E,
                           pady=10)  #.pack(side=tk.RIGHT, pady=10)

        # 消息提示
        self._infomation = '消息提示'
        self.infomation = tk.StringVar(master=self,
                                       value=self._infomation[:21])
        self.info_label = tk.Label(master=self,
                                   textvariable=self.infomation,
                                   width=32,
                                   height=2,
                                   cursor='hand2',
                                   fg='#555',
                                   font=font.Font(size=12))
        self.info_label.bind('<Button-1>', lambda e: self.show_info_detail())
        self.info_label.grid(row=3,
                             column=0,
                             columnspan=3,
                             sticky=tk.W,
                             padx=5)  # .pack(side=tk.LEFT, padx=5)
Пример #7
0
    def got_line(self,inbuffer):
        p = inbuffer.split(' ')
        l = len(p)
        data = inbuffer.lower()
        
        if data.startswith('quit'):
            self.close_when_done()
            return
        if data.startswith('ping'):
            if len(p) != 2:
                return
            self.on_ping(p[1])
            return
        if data.startswith('pong'):
            if len(p) != 2:
                return
            self.on_pong(p[1])
            return
        
        #if data.startswith('user') and l > 1:
        #    self.usr = p[1]

        if data.startswith('nick') and l > 1:
            self.dbg('got nick: %s'%p[1])
            nick = self.do_nickname(p[1])
            if not self.welcomed and len(self.nick) == 0:
                self.nick = p[1]
                self.server.add_user(self)
            self.server.change_nick(self,nick)
        if not self.welcomed:
            return

        if data.startswith('mode'):
            if len(p) > 1:
                if p[1][0] in ['&','#']:
                    self.send_num(324,'%s +'%(p[1]))

        # try uncommmenting for now
        #if data.startswith('who'):
        #    if len(p) > 1:
        #        if p[1][0] in ['#','&']:
        #            chan = p[1]
        #            if chan in self.chans:
        #                if chan in self.server.chans:
        #                    self.server.chans[chan].send_who(self)
        if data.startswith('part'):
            chans = p[1].split(',')
            for chan in chans:
                if chan in self.chans:
                    self.part_chan(chan)
        if data.startswith('privmsg'):
            c = inbuffer.split(':')
            msg+= ':'.join(c[1:])
            target = p[1]
            self.server.privmsg(self,target,msg)
        if data.startswith('topic'):
            c = inbuffer.split(':')
            msg = ':'.join(c[1:])
            msg = util.filter_unicode(msg)
            chan = p[1]
            self.topic(chan,msg)
        if data.startswith('motd'):
            self.server.send_motd(self)
        if data.startswith('join'):
            if l == 1:
                self.send_raw(461, '%s :Not enough parameters'%p[0])
                return
            chans = p[1].split(',')
            for chan in chans:
                chan = util.filter_unicode(chan.strip())
                if len(chan) > 1:
                    self.join_chan(chan)
        if data.startswith('names'):
            for chan in p[1].split(','):
                if chan in self.chans:
                    self.server.chans[chan].send_who(self)
        if data.startswith('list'):
            self.server.send_list(self)