예제 #1
0
파일: main.py 프로젝트: alexwyler/LCS247
def main():
    init()
    while True:
        log('Waiting for a suitable game...')
        # reduce search delay while we search for new games
        active_games.SEARCH_DELAY = 10
        while True:
            SharedGameDetails.selected_game = get_best_suitable_game()
            if not SharedGameDetails.selected_game:
                time.sleep(1)
            else:
                break

        # increase search delay while we have a game
        active_games.SEARCH_DELAY = 120
        personality_name, account, _, game = SharedGameDetails.selected_game
        log("Choosing {0} game, playing on {1}...".format(personality_name, account))
        players.hype_personality(personality_name, 10)
        
        team, position = util.get_player_position(account[0], game)
        team_str = str(team).join(str(team).split()).lower()
        
        if not config.CONTEXT_UTIL.get("skip_launch"):
            log("Launching game...")   
            league_runner.open_game(game, team_str, position)
        
        update_twitch_channel(personality_name, account, game)
        obs.update_now_playing(personality_name, account, game)
        log("Waiting for game to end...")
        while True:
            try:
                if not api.get_active_game(account[0]) or not SharedGameDetails.selected_game:
                    break
            except Exception as e:
                log(str(e))
                traceback.print_exc()
                pass
            time.sleep(IN_GAME_PING_FREQUENCY)
        
        if SharedGameDetails.selected_game:
            log("Game complete. Waiting for spectator delay...")
            time.sleep(util.SPECTATOR_DELAY)
         
        log("Killing game...")
        league_runner.kill_game()
        
        log("Decaying hype...")
예제 #2
0
파일: irc_bot.py 프로젝트: alexwyler/LCS247
 def process():
     readbuffer = ""
     irc = socket.socket()
     irc.connect((server, 6667))  # connects to the server
     
     def send_message(msg):
         irc.send(bytes('PRIVMSG #lcs247 :{0}\r\n'.format(msg), 'UTF-8'))
     
     # sends variables for connection to twitch chat
     irc.send(b'PASS ' + password + b'\r\n')
     irc.send(b'USER ' + nick + b' 0 * :' + bot_owner + b'\r\n')
     irc.send(b'NICK ' + nick + b'\r\n')
     irc.send(bytes("JOIN #lcs247\r\n", "UTF-8"));
     log('Listening for commands...')
     while True:
         try:
             readbuffer = readbuffer + irc.recv(1024).decode("UTF-8")
             temp = str.split(readbuffer, "\n")
             readbuffer = temp.pop()
             
             for line in temp:
                                     
                 m = MESSAGE_PATTERN.match(line)
                 if m:
                     user, message = m.group(1, 4)
                     hype_m = HYPE_COMMAND.search(message)
                     if hype_m:
                         player = hype_m.group(1).strip()
                         region = (hype_m.group(3) or 'NA').strip()
                         players.hype_personality((player, region), 1) 
                         personality = players.get_personality(player)
                         message = "{0} hypes {1} to {2}!".format(user, personality['name'], personality['hype'])
                         log(message)
                         send_message(message)
                     
                     show_m = SHOW_PLAYERS.search(message)
                     if show_m:
                         potential_games = active_games.get_potential_games_in_order()
                         if potential_games:
                             send_message("--- Players in Game ---")
                             for suitable_game in potential_games:
                                 personality_name, account, score, game = suitable_game
                                 if game.is_within_spectator_delay():
                                     waiting = ', waiting to begin'
                                 else:
                                     waiting = ''
                                 message = "({0}{3}) {1} on {2} {4}".format(score, personality_name, game.get_champion(account[0]), waiting, game.get_timestamp_since_start())
                                 send_message(message)
                         else:
                             send_message("No potential games!")
                     
                     if user == 'lcs247' and HYPE_STANDARDS.search(message):
                         log('Hyping standard players...')
                         players.hype_standards()
                     
                     if user == 'lcs247' and NEXT_SONG_COMMAND.search(message):
                         log('SKipping song...')
                         send_message('Skipping song...')
                         subprocess.call([config.CONTEXT_UTIL['ahk_path'],
                                          config.CONTEXT_UTIL['ahk_next_song_path']])
                         
                     if (SKIP_COMMAND.search(message)):
                         selected_game_details = SharedGameDetails.selected_game
                         if selected_game_details:
                             personality_name, account, _, game = selected_game_details
                             players.hype_personality(personality_name, -1)
                             personality = players.get_personality(personality_name)
                             if personality['hype'] <= 0:
                                 send_message('Skipping current game!')
                                 SharedGameDetails.selected_game = None
                             else:
                                 send_message("De-hyping {0} to {1}. Get him to 0 to skip".format(personality_name, personality['hype']))
                         else:
                             send_message("No active game...")
                 else:
                     if line.find ('PING') != -1:
                         irc.send (bytes('PONG ' + line.split() [ 1 ] + '\r\n', 'UTF-8'))
                     else:
                         log(line)
 
             time.sleep(1)
         except Exception as e:
             log(str(e))
             traceback.print_exc()
         
     log('Exiting loop!')