async def calc_all_stats_after_time(guild: discord.Guild, time: datetime, spamChannelsId: list) -> str: print(guild.name) userDict = {} for channel in guild.channels: if issubclass(type(channel), discord.TextChannel): isSpamChannel = True if channel.id in spamChannelsId else False async for message in channel.history(limit=10000, oldest_first=False, after=time): if message.author.bot: continue if message.author.id not in userDict.keys(): userDict[message.author.id] = User( userId=message.author.id, messagesCount=0, symbolsCount=0) userDict[message.author.id].messagesCount += 1 textLen = messagesProcessing.text_len(stroke=message.content) userDict[message.author.id].symbolsCount += textLen if isSpamChannel: ActivityLogService.logOneSpamMessage( guildId=guild.id, userId=message.author.id, period=message.created_at.date(), symbolsCount=textLen) else: ActivityLogService.logOneMessage( guildId=guild.id, userId=message.author.id, period=message.created_at.date(), symbolsCount=textLen) answerLog = [ '[Поиск сообщений после последней записи на сервере {0}]'.format( guild.name) ] for keyID in userDict: userDict[keyID].exp = (userDict[keyID].symbolsCount + userDict[keyID].messagesCount) / 10 try: UserService.append_stats_on_messages(user=userDict[keyID]) except Exception: answerLog.append(' > новый пользователь:') UserService.add_new_user(userId=keyID) UserService.append_stats_on_messages(user=userDict[keyID]) answerLog.append('\t> {0} > сообщений: {1}, символов: {2}' ''.format(keyID, userDict[keyID].messagesCount, userDict[keyID].symbolsCount)) return '\n'.join(answerLog)
def get_user_on_messages_by_id(userId: int): row: sql.Row = Repos.get_user_on_messages_by_id(userId=userId) if row is None: raise ValueError( 'UserService.get_user_on_messages_by_id(): returned row is null') return User(userId=row[0], exp=row[1], messagesCount=row[2], symbolsCount=row[3])
def get_user_by_id(userId: int): row: sql.Row = Repos.get_user_by_id(userId=userId) if row is None: raise ValueError('UserService.get_user_by_id(): returned row is null') return User(userId=row[0], exp=row[1], level=row[2], messagesCount=row[3], symbolsCount=row[4], voiceChatTime=row[5], voluteCount=row[6], expModifier=row[7])
def get_all_users(): answer = [] for row in Repos.get_all_users(): answer.append( User(userId=row[0], exp=row[1], level=row[2], messagesCount=row[3], symbolsCount=row[4], voiceChatTime=row[5], voluteCount=row[6], expModifier=row[7])) return answer
def get_top10_by_exp(): rows = Repos.get_top10_by_exp() if rows is None: raise ValueError( 'UserService.get_top10_by_exp(): returned rows is null') answer = [] for row in rows: answer.append( User(userId=row[0], exp=row[1], level=row[2], messagesCount=row[3], symbolsCount=row[4], voiceChatTime=row[5], voluteCount=row[6], expModifier=row[7])) return answer
path2 = basePath.split('\\\\')[:-1] + ['transfer'] + ['gif_triggers.db'] path2 = '\\\\'.join(path2) # ========== CONNECTION 1 =========== connection = sql.connect(path1) cursor = connection.cursor() print('connected: ' + path1) cursor.execute(""" SELECT * FROM userstats """) data = cursor.fetchall() UserService.clear_table() for row in data: newUser = User(userId=row[0], exp=row[1], level=row[2], messagesCount=row[3], symbolsCount=row[4], voiceChatTime=row[5]) newUser.voluteCount = 0 newUser.expModifier = 0 UserService.add_new_user(userId=newUser.userId) UserService.update_user(user=newUser) print('data copied') connection.close() print('connection closed') # ========== CONNECTION 2 =========== GifService.clear_table() GifGroupService.clear_table()
def get_user_exp_modifier(userId: int): row: sql.Row = Repos.get_user_exp_modifier(userId=userId) if row is None: raise ValueError( 'UserService.get_user_expModifier(): returned row is null') return User(userId=row[0], exp=row[1], expModifier=row[2])
def get_user_on_voice_chat_by_id(userId: int): row: sql.Row = Repos.get_user_on_voice_chat_by_id(userId=userId) if row is None: raise ValueError( 'UserService.get_user_on_voice_chat_by_id(): returned row is null') return User(userId=row[0], exp=row[1], voiceChatTime=row[2])