def last_game(client, arguments, message): if arguments and len(arguments) == 1: name = arguments[0] member = list(map(lambda server: find(lambda m: m.name == name, server.members), client.servers)) if len(member) > 0 and member[0] is not None: player = member[0] elif len(message.mentions) > 0: player = message.mentions[0] else: client.send_message(message.channel, "Could not find %s" % (name)) else: player = message.author if player.id not in Bot().dota_accounts.keys(): client.send_message(message.channel, "%s not registered" % (player.name)) return account_id = Bot().dota_accounts[player.id].id64() matches = Match.list(account_id) if not isinstance(matches,list): client.send_message(message.channel, matches) return last_match = matches[0] if last_match.match_id not in Bot().match_cache.keys(): client.send_typing(message.channel) result = BotResult.find(last_match.match_id) Bot().match_cache[last_match.match_id] = BotResult.schema().dump(result).data Bot().save_metadata() client.send_message(message.channel, Bot().renderer.render_name("match_result_short", {'result':Bot().match_cache[last_match.match_id]}))
def run(self): while True: for k,v in iter(Bot().dota_accounts.items()): try: match = Match.list(v.id32(), matches_requested=1, date_min=int((datetime.datetime.now() - datetime.timedelta(minutes=1)).strftime("%s"))) if len(match) > 0: match = match[0] if isinstance(match,Match): if match.match_id not in Bot().match_cache.keys(): #if (datetime.now() - match.end_time) =< 60*5: if callable(self.callback): self.callback(match) except Exception as e: pass time.sleep(10)