def prepare_notify_events(self, no_trumpet = False): pn = PullNotify() if not no_trumpet and hruntime.user.seen_board != True: txt = lib.trumpet.Board().text if len(txt) > 0: pn.trumpet = hlib.format.tagize(txt) # Do I have unread posts on global chat? cnt = lib.chat.ChatPagerGlobal().unread if cnt > 0: pn.chat = cnt # Are there any free games? cnt = sum([1 for g in games.f_active(hruntime.user) if g.is_free and not g.is_personal_free(hruntime.user)]) cnt += sum([1 for t in tournaments.f_active(hruntime.user) if t.is_active and not t.has_player(hruntime.user)]) if cnt > 0: pn.free_games = cnt # Am I on turn in any game? cnt = 0 for k in games.GAME_KINDS: cnt += len(games.game_module(k, submodule = 'handler').GameOnTurnChecker.check()) for g in games.f_active(hruntime.user): if g.has_player(hruntime.user): # Am I invited to this game? if not g.has_confirmed_player(hruntime.user): cnt += 1 continue # Do I have undread posts? if g.my_player.chat.unread > 0: cnt += 1 continue # Do I have unread posts in inactive games? cnt += sum([1 for g in games.f_inactive(hruntime.user) if g.my_player.chat.unread > 0]) # Do I have unread posts in tournaments' chat? cnt += sum([1 for t in tournaments.f_active(hruntime.user) if t.has_player(hruntime.user) and t.my_player.chat.unread > 0]) # Do I have unread posts in inactive tournaments? cnt += sum([1 for t in tournaments.f_inactive(hruntime.user) if t.my_player.chat.unread > 0]) if cnt > 0: pn.on_turn = cnt return pn
def __recent_events(): import games import tournaments re = RecentEvents() re.finished_chat = 0 # Active games for g in games.f_active(hruntime.user): ga = g.to_api() if ( g.has_player(hruntime.user) and g.my_player.is_on_turn or g.has_player(hruntime.user) and not g.has_confirmed_player(hruntime.user) or g.has_player(hruntime.user) ): re.playable.append(ga) else: re.free.append(ga) # Inactive games for g in games.f_inactive(hruntime.user): re.finished.append(g.to_api()) if g.my_player.chat.unread > 0: re.finished_chat += 1 # Active tournaments for t in tournaments.f_active(hruntime.user): ta = t.to_api() if t.has_player(hruntime.user): re.playable.append(ta) else: re.free.append(ta) # Inactive tournaments for t in tournaments.f_inactive(hruntime.user): re.finished.append(t.to_api()) if t.my_player.chat.unread > 0: re.finished_chat += 1 return hlib.api.Reply(200, events=re)