Exemple #1
0
 def run(self):
     self.connect()
     self.login()
     time.sleep(1)
     line      = ''
     while not self._terminate:
         for char in self._sock.recv(1024):
             if char not in '\r\n':
                 line += char
                 continue
             if char == '\r': continue
             if char == '\n':
                 if self._irc_debug: print '[-s2c-] %s'%line
                 prefix     = ''
                 command    = ''
                 arguments  = ''
                 if line[0] == ':':
                     line   = line[1:]
                     i      = line.find(' ')
                     prefix = GO.unicod(line[0:i])
                     line   = line[i+1:]
                 i = line.find(' ')
                 command   = 'on_%s'%line[0:i]
                 arguments = GO.unicod(line[i+1:])
                 if command in dir(self): Thread(target=getattr(self, command), args=(prefix, arguments)).start()
                 line = ''
Exemple #2
0
 def history(self, cmd):
     (ok, date) = self._check_for_date(''.join(cmd.arguments()))
     if ok:
         exists = False
         for chan_message in GO.storage.get_channel_log(cmd.channel().name(), date):
             cmd.reply(u'%s [%s] %s: %s'%(cmd.channel().name(), chan_message[0].strftime('%H:%M:%S'), GO.unicod(chan_message[1]), GO.unicod(chan_message[2])))
             exists = True
         if not exists:
             cmd.reply(u'За данную дату сообщения на канале %s отсутствуют'%cmd.channel().name())
     else:
         cmd.reply_error(date)
Exemple #3
0
    def sync_forums_data(self):
        #self.download_part_of_all()
        GO.bot.send_channel_log(u'RSDN. Синхронизация. Запуск.')
        msgcount = { True: 0, False: 0 }
        mdrcount = { True: 0, False: 0 }
        ratcount = { True: 0, False: 0 }
        sync_iteration = 0
        while True:
            msgcnt = 0
            ratcnt = 0
            mdrcnt = 0
            sync_iteration += 1
            GO.bot.send_channel_log(u'RSDN. Синхронизация. Итерация: %d.'%sync_iteration)
            GO.bot.send_channel_log(u'RSDN. Синхронизация. Будет загружено отсутствующих сообщений: %d'%(self.max_broken_per_sync_iteration if len(self._missed_rsdn_messages_mids) > self.max_broken_per_sync_iteration else len(self._missed_rsdn_messages_mids)))
            newData = self.sync_new_data()
            GO.bot.send_channel_log(u'RSDN. Синхронизация. Сообщения загружены. В итерацию не попало %d отсутствующих сообщений'%len(self._missed_rsdn_messages_mids))
            if newData == None:
                break
            if len(newData['newMessages']):
                GO.bot.send_channel_log(u'RSDN. Синхронизация. Обработка сообщений.')
                for message in newData['newMessages'][0]:
                    msgcount[GO.storage.update_rsdn_messages(message)] += 1
                    fid = message['forumId']
                    if fid and self.date_is_today(message['messageDate']):
                        forum_name = self.forums[fid]['sname']
                        text = u'`%s`. Автор: %s'%(
                                                   message['subject'], 
                                                   message['userNick'],
                                                  )
                        urls = u' | '.join([
                                              u'#%s'%forum_name,
                                              self.get_forum_url_by_id(fid),
                                              self.get_message_url_by_id(message['messageId']), 
                                              self.get_member_url_by_id(message['userId'])
                                          ])
                        GO.bot.send_rsdn_notification(u'В форуме `%s` новое сообщение: %s'%(
                                                                                          self.forums[fid]['name'],
                                                                                          text
                                                                                         ))
                        GO.bot.send_rsdn_notification(urls)
                        if message['parentId'] == 0:
                            GO.bot.send_channel_notification(forum_name, u'Новый топик %s'%text)
                            GO.bot.send_channel_notification(forum_name, urls)
                        else:
                            parent_msg = GO.storage.get_rsdn_message(message['parentId'])
                            if parent_msg != None:
                                GO.bot.send_user_notification(parent_msg[2], u'В форуме `%s` ответ на сообщение `%s`: %s'%(
                                                                                          self.forums[fid]['name'],
                                                                                          GO.unicod(parent_msg[4]),
                                                                                          text
                                                                                         ))
                                GO.bot.send_user_notification(parent_msg[2], urls)
                #self.mineMissedInMessages(newData['newMessages'][0])

            if len(newData['newRating']):
                GO.bot.send_channel_log(u'RSDN. Синхронизация. Обработка рейтинга.')
                for rating in newData['newRating'][0]:
                    ratcount[GO.storage.update_rsdn_rating(rating)] += 1
                    if self.date_is_today(rating['rateDate']):
                        target_msg = GO.storage.get_rsdn_message(rating['messageId'])
                        if target_msg == None: 
                            self.get_rsdn_topic(rating['messageId'])
                            target_msg = GO.storage.get_rsdn_message(rating['messageId'])
                        from_user = GO.storage.get_rsdn_member(rating['userId'])
                        if from_user == None:
                            self.get_rsdn_member(rating['userId'])
                            from_user = GO.storage.get_rsdn_member(rating['userId'])
                        rate = rating['rate']
                        r = ''
                        if   rate  >  0: r = u'%d'%(rating['userRating']*rate)
                        elif rate ==  0: r = u'-1'
                        elif rate == -2: r = u':)'
                        elif rate == -4: r = u'+1'
                        text = u'Оценка %s сообщению `%s` от пользователя %s'%(
                                                                                r, 
                                                                                GO.unicod(target_msg[4]) if target_msg != None else u'--нет-в-бд--', 
                                                                                GO.unicod(from_user[1])  if target_msg != None else u'--нет-в-бд--'
                                                                              )
                        urls = u' | '.join([
                                              self.get_message_url_by_id(rating['messageId']), 
                                              self.get_member_url_by_id(rating['userId'])
                                            ])
                        GO.bot.send_rsdn_notification(text)
                        GO.bot.send_rsdn_notification(urls)
                        if target_msg != None:
                            GO.bot.send_user_notification(target_msg[2], u'В форуме `%s` ответ на сообщение `%s`: %s'%(
                                                                                          self.forums[fid]['name'],
                                                                                          GO.unicod(target_msg[4]),
                                                                                          text
                                                                                         ))
                            GO.bot.send_user_notification(target_msg[2], urls)
                #self.mineMissedInMessages(newData['newRating'][0])

            if len(newData['newModerate']):
                GO.bot.send_channel_log(u'RSDN. Синхронизация. Обработка модерирования.')
                for moderate in newData['newModerate'][0]:
                    mdrcount[GO.storage.update_rsdn_moderate(moderate)] += 1
                #self.mineMissedInMessages(newData['newModerate'][0])

            GO.bot.send_channel_log(u'RSDN. Синхронизация. Получение списка отсутствующих сообщений.')
            for mid in GO.storage.get_broken_messages(list(self.forums.keys())):
                if mid not in self._missed_rsdn_messages_mids:
                        self._missed_rsdn_messages_mids.append(mid)
            #print len(newData['newRating']), len(newData['newModerate']), len(newData['newMessages']), len(self._missed_rsdn_messages_mids)
            if len(newData['newRating']) == 0 and len(newData['newModerate']) == 0 and len(newData['newMessages']) == 0 and len(self._missed_rsdn_messages_mids) < self.min_broken_per_sync_iteration:
                break
        GO.bot.send_channel_log(u'RSDN. Синхронизация. Собщения: принято %d, из них новых %d, обновлено %d.'%(msgcount[True]+msgcount[False], msgcount[False], msgcount[True]))
        GO.bot.send_channel_log(u'RSDN. Синхронизация. Оценки: принято %d, из них новых %d, обновлено %d.'%(ratcount[True]+ratcount[False], ratcount[False], ratcount[True]))
        GO.bot.send_channel_log(u'RSDN. Синхронизация. Модерирование: принято %d, из них новых %d, обновлено %d.'%(mdrcount[True]+mdrcount[False], mdrcount[False], mdrcount[True]))
        newUsers = self.sync_new_users()
        if newUsers != None:
            usrcount = { True: 0, False: 0 }
            for newUsersBit in newUsers:
                for user in newUsersBit['users'][0]:
                    usrcount[GO.storage.update_rsdn_members(user)] += 1
                    GO.bot.send_rsdn_notification(u'Новый пользователь `%s`, `%s`, `%s`: %s'%(
                                                                                user['userName'],
                                                                                user['userNick'],
                                                                                user['realName'],
                                                                                self.get_member_url_by_id(user['userId'])
                                                                              ))
            GO.bot.send_channel_log(u'RSDN. Синхронизация. Новые пользователи: принято %d, из них новых %d, обновлено %d.'%(usrcount[True]+usrcount[False], usrcount[False], usrcount[True]))
        if len(self._missed_rsdn_members_uids):
            users = self.load_members_by_ids(self._missed_rsdn_members_uids)
            self._missed_rsdn_members_uids = []
            if users:
                usrcount = { True: 0, False: 0 }
                for user in users['users'][0]:
                    usrcount[GO.storage.update_rsdn_members(user)] += 1
                GO.bot.send_channel_log(u'RSDN. Синхронизация. Пропущенные пользователи: принято %d, из них новых %d, обновлено %d.'%(usrcount[True]+usrcount[False], usrcount[False], usrcount[True]))
        GO.bot.send_channel_log(u'RSDN. Синхронизация. Закончено.')