Exemplo n.º 1
0
def get_players_in_game_for_player(dotaid, checktwitch=False, markdown=False):
    herodata = getHeroes()
    # herodict = {h['id']:str(h['localized_name']) for h in herodata['result']['heroes']}
    herodict = getHeroNamedict()
    herodict[0] = "Unknown hero"

    userstatus = node.get_user_status(dotaToSteam(dotaid))
    if userstatus == '#DOTA_RP_PLAYING_AS':
        heroid = node.get_user_playing_as(dotaToSteam(dotaid))
        heroid = getHeroIddict(False)[heroid[0]]
    else: heroid = None

    notable_players = settings.getdata('dota_notable_players')
    game = getSourceTVLiveGameForPlayer(dotaid, heroid)

    teamformat = '%s%s: \n'                  # ('## ' if markdown else '', team)
    playerformat = '%s%s: %s\n'              # ('#### ' if markdown else '  ', hero, name)
    notableformat = '%sNotable player: %s\n' # ('###### ' if markdown else '   - ', name)
    linkformat = '   - %s%s\n'               # (linktype, linkdata)
    
    linktypes = {
        'steam': 'http://steamcommunity.com/profiles/',
        'dotabuff': 'http://www.dotabuff.com/players/',
        'twitch': 'http://twitch.tv/'
    }

    if game:
        data = ''

        for team in ['Radiant', 'Dire']:

            data += teamformat % ('## ' if markdown else '', team)

            for player in game['goodPlayers' if team=='Radiant' else 'badPlayers']:
                data += playerformat % ('#### ' if markdown else '  ', herodict[player['heroId']], player['name'].decode('utf8'))

                if steamToDota(player['steamId']) in notable_players:
                    data += notableformat % ('###### ' if markdown else '   - ', notable_players[steamToDota(player['steamId'])].decode('utf8'))

                mkupsteamlink = linkformat % (linktypes['steam'], player['steamId'])
                
                ressteam = requests.head(linktypes['steam'] + player['steamId']).headers.get('location')

                if ressteam:
                    data += mkupsteamlink.replace('\n', '') + ' (%s)\n' % ressteam.split('.com')[-1][:-1]
                else:
                    data += mkupsteamlink

                data += linkformat % (linktypes['dotabuff'], steamToDota(long(player['steamId'])))
                if checktwitch:
                    tname = twitchapi.get_twitch_from_steam_id(player['steamId'])
                    if tname:
                        data += linkformat % (linktypes['twitch'], tname)
                data += '\n'

        return data
Exemplo n.º 2
0
def notablePlayerBlurb(channel, pages=33):
    playerid = settings.getdata('%s_dota_id' % channel)
    userstatus = node.get_user_status(dotaToSteam(playerid))
    if userstatus:
        # print 'Dota status for %s: %s' % (channel, userstatus)

        if userstatus in ["#DOTA_RP_HERO_SELECTION", "#DOTA_RP_PRE_GAME", "#DOTA_RP_GAME_IN_PROGRESS", "#DOTA_RP_PLAYING_AS"]:
            if getNotableCheckReady(channel):
                if twitchapi.is_streaming(channel):
                    if userstatus == '#DOTA_RP_PLAYING_AS':
                        playerheroid = node.get_user_playing_as(dotaToSteam(playerid))
                        playerheroid = getHeroIddict(False)[playerheroid[0]]
                    else:
                        playerheroid = None

                    print "[Dota-Notable] Doing search for notable players%s" % (' using hero id' if playerheroid else '')
                    players = searchForNotablePlayers(playerid, pages, playerheroid)
                    settings.setdata('%s_notable_message_count' % channel, 0, announce=False)

                    if players:
                        return "Notable players in this game: %s" % ', '.join(['%s (%s)' % (p,h) for p,h in players])
        else:
            notable_check_timeout = settings.trygetset('%s_notable_check_timeout' % channel, 600.0)
            settings.setdata('%s_notable_last_check' % channel, time.time() - notable_check_timeout + 60.0, announce=False)