def random_hero(cls): #@TODO should not hardcode limits of random next_hero = data.get_hero_name(random.randint(1, 107)) if next_hero is not None: return str(next_hero["localized_name"]) else: return ResponseNext.random_hero()
def respond(self): out = "" hero_name = self.msg.text.split(' ', 1) if len(hero_name) < 2: out = "You need a hero name" else: hero_num = AbstractResponse.get_hero_id(hero_name[1]) if hero_num < 0: name = hero_name[1].lower() if name in Best.SPECIFIC_RESPONSES: out = Best.SPECIFIC_RESPONSES[name] else: out = "Hero not found" else: hero_name = data.get_hero_name(hero_num)["localized_name"] record = AbstractResponse.get_record(hero_num) if record is not None: out = "Most Kills with {0} : {1} by {2}\n".format( hero_name, record["max_kills"], AbstractResponse.dotaID_to_name( record["max_kills_player"])) out += "Highest GPM with {0} : {1} by {2}\n".format( hero_name, record["max_GPM"], AbstractResponse.dotaID_to_name( record["max_GPM_player"])) out += "Highest XPM with {0} : {1} by {2}\n".format( hero_name, record["max_XPM"], AbstractResponse.dotaID_to_name( record["max_XPM_player"])) return out
def respond(self): out = "" hero_name = self.msg.text.split(' ', 1) if len(hero_name) < 2: out = "You need a hero name" else: hero_num = AbstractResponse.get_hero_id(hero_name[1]) if hero_num < 0: if hero_name[1].lower() == "person": out = "Jon" elif hero_name[1].lower() == "beer": out = "Mother. F*****g. Pabst." elif hero_name[1].lower() == "game": out = "Hello Kitty Adventure, Pink Edition" elif hero_name[1].lower() == "friend": out = "Porcupines" elif hero_name[1].lower() == "country": out = "Canada (sike prolly some Middle East place)" else: out = "Hero not found" else: hero_name = data.get_hero_name(hero_num)["localized_name"] record = AbstractResponse.get_record(hero_num) if record is not None: out = "Most Deaths with {0} : {1} by {2}\n".format(hero_name, record["max_deaths"], AbstractResponse.dotaID_to_name(record["max_deaths_player"])) out += "Lowest GPM with {0} : {1} by {2}\n".format(hero_name, record["min_GPM"], AbstractResponse.dotaID_to_name(record["min_GPM_player"])) out += "Lowest XPM with {0} : {1} by {2}\n".format(hero_name, record["min_XPM"], AbstractResponse.dotaID_to_name(record["min_XPM_player"])) return out
def respond(self): out = "" hero_name = self.msg.text.split(' ', 1) if len(hero_name) < 2: out = "You need a hero name" else: hero_num = AbstractResponse.get_hero_id(hero_name[1]) if hero_num < 0: if hero_name[1].lower() == "person": out = "Jon" elif hero_name[1].lower() == "beer": out = "Mother. F*****g. Pabst." elif hero_name[1].lower() == "game": out = "Hello Kitty Adventure, Pink Edition" elif hero_name[1].lower() == "friend": out = "Porcupines" elif hero_name[1].lower() == "country": out = "Canada (sike prolly some Middle East place)" else: out = "Hero not found" else: hero_name = data.get_hero_name(hero_num)["localized_name"] record = AbstractResponse.get_record(hero_num) if record is not None: out = "Most Deaths with {0} : {1} by {2}\n".format( hero_name, record["max_deaths"], AbstractResponse.dotaID_to_name( record["max_deaths_player"])) out += "Lowest GPM with {0} : {1} by {2}\n".format( hero_name, record["min_GPM"], AbstractResponse.dotaID_to_name( record["min_GPM_player"])) out += "Lowest XPM with {0} : {1} by {2}\n".format( hero_name, record["min_XPM"], AbstractResponse.dotaID_to_name( record["min_XPM_player"])) return out
def respond(self): out = "" hero_name = self.msg.text.split(' ', 1) if len(hero_name) < 2: out = "You need a hero name" else: hero_num = AbstractResponse.get_hero_id(hero_name[1]) if hero_num < 0: name = hero_name[1].lower() if name in Best.SPECIFIC_RESPONSES: out = Best.SPECIFIC_RESPONSES[name] else: out = "Hero not found" else: hero_name = data.get_hero_name(hero_num)["localized_name"] record = AbstractResponse.get_record(hero_num) if record is not None: out = "Most Kills with {0} : {1} by {2}\n".format(hero_name, record["max_kills"], AbstractResponse.dotaID_to_name(record["max_kills_player"])) out += "Highest GPM with {0} : {1} by {2}\n".format(hero_name, record["max_GPM"], AbstractResponse.dotaID_to_name(record["max_GPM_player"])) out += "Highest XPM with {0} : {1} by {2}\n".format(hero_name, record["max_XPM"], AbstractResponse.dotaID_to_name(record["max_XPM_player"])) return out
def update_dota(self): # Get a list of recent matches for the player total_added = 0 api.set_api_key(AbstractResponse.key) current_time = int(time.time()) last_update_time = AbstractResponse.get_last_update_time() new_records = "" for name, account_id in AbstractResponse.GroupMetoDOTA.items(): print "Starting: {0}".format(name) # Get a list of recent matches for the player matches = api.get_match_history(account_id=account_id)["result"]["matches"] #Go through every match for match in matches: print "\tChecking: " + str(match["match_id"]) if match["start_time"] < last_update_time["last_update"]: print "\tWe've seen these matches" break if (not AbstractResponse.has_dotaMatch(match["match_id"])): single_match = api.get_match_details(match["match_id"])["result"] print "\t\tAdding: " + str(single_match["match_id"]) AbstractResponse.add_dotaMatch(single_match) total_added += 1 #Did this match set any new records# ? for player in single_match["players"]: #Is this a player we are tracking? if AbstractResponse.has_dotaID_num(int(player["account_id"])): #Yes! Check if they broke a record old_record = AbstractResponse.get_record(player["hero_id"]) print player["hero_id"] hero_dict = data.get_hero_name(player["hero_id"]) if not hero_dict: print("For hero id = {}, not in dota2py".format(player["hero_id"])) continue hero_name = data.get_hero_name(player["hero_id"])["localized_name"] player_name = AbstractResponse.dotaID_to_name(int(player["account_id"])) if old_record is None: #this is auto a new record! new_record = {"hero_id": player["hero_id"], "max_kills": player["kills"], "max_kills_player": player["account_id"], "max_deaths": player["deaths"], "max_deaths_player": player["account_id"], "max_GPM": player["gold_per_min"], "max_GPM_player": player["account_id"], "min_GPM": player["gold_per_min"], "min_GPM_player": player["account_id"], "max_XPM": player["xp_per_min"], "max_XPM_player": player["account_id"], "min_XPM": player["xp_per_min"], "min_XPM_player": player["account_id"], } AbstractResponse.set_record(new_record) else: #There is an existing record.. Lets see if this match was a game changer new_record = old_record.copy() if old_record["max_kills"] < player["kills"]: new_records += "{0} just got {1} kills with {2}, a new record!\n".format(player_name, player["kills"], hero_name ) new_record["max_kills"] = player["kills"] new_record["max_kills_player"] = player["account_id"] if old_record["max_deaths"] < player["deaths"]: new_records += "{0} just got {1} deaths with {2}, a new low!\n".format(player_name, player["deaths"], hero_name ) new_record["max_deaths"] = player["deaths"] new_record["max_deaths_player"] = player["account_id"] if old_record["max_GPM"] < player["gold_per_min"]: new_records += "{0} just got {1} GPM with {2}, a new record!\n".format(player_name, player["gold_per_min"], hero_name ) new_record["max_GPM"] = player["gold_per_min"] new_record["max_GPM_player"] = player["account_id"] if old_record["min_GPM"] > player["gold_per_min"]: new_records += "{0} just got {1} GPM with {2}, a new low!\n".format(player_name, player["gold_per_min"], hero_name ) new_record["min_GPM"] = player["gold_per_min"] new_record["min_GPM_player"] = player["account_id"] if old_record["max_XPM"] < player["xp_per_min"]: new_records += "{0} just got {1} XPM with {2}, a new record!\n".format(player_name, player["xp_per_min"], hero_name ) new_record["max_XPM"] = player["xp_per_min"] new_record["max_XPM_player"] = player["account_id"] if old_record["min_XPM"] > player["xp_per_min"]: new_records += "{0} just got {1} XPM with {2}, a new low!\n".format(player_name, player["xp_per_min"], hero_name ) new_record["min_XPM"] = player["xp_per_min"] new_record["min_XPM_player"] = player["account_id"] AbstractResponse.set_record(new_record) else: print "\t Was Duplicate" print "Updated {0} Matches".format(total_added) if last_update_time == None: time_dict = {'last_update' : current_time} else: time_dict = last_update_time.copy() time_dict["last_update"] = current_time AbstractResponse.set_last_update_time(time_dict) return new_records
def respond(self): if random.random() < ResponseLast.SASS_PERCENTAGE: print("#last - sassy override") return "Bitch, you can't last for shit" print "Starting" canonical_name = (key for key,value in AbstractResponse.GroupMeIDs.items() if value==self.msg.sender_id).next() if not AbstractResponse.has_steamID(canonical_name): return "I don't know your SteamID! Set it with '#set ID'" if not AbstractResponse.has_dotaID(canonical_name): return "I don't know your DOTA ID! Set it with '#setDota ID'" print "Setting Key & Account ID" api.set_api_key(AbstractResponse.key) account_id = AbstractResponse.name_to_steamID(canonical_name) print "Got Account ID" # Get a list of recent matches for the player matches = api.get_match_history(account_id=account_id)["result"]["matches"] #Get the full details for a match match = api.get_match_details(matches[0]["match_id"]) match_id = match['result']['match_id'] dotabuff_link = ResponseLast.DOTABUFF_LINK_TEMPLATE.format(id=match_id) print "Got Match Details" player_num = 0 for x in match["result"]["players"]: if int(x["account_id"]) == AbstractResponse.name_to_dotaID(canonical_name): out = "" print "Got self.sender Data" #Stats? print player_num msg = ResponseLast.match_performance_template.format(hero=data.get_hero_name(x["hero_id"])["localized_name"], k=str(x["kills"]), d=str(x["deaths"]), a=str(x["assists"]), GPM=str(x["gold_per_min"]), level=str(x["level"]) ) out += msg + "\n" #Items? finalItems = "Your items: " for itemNum in range(0, 6): if x["item_" + str(itemNum)] != 0 and x["item_" + str(itemNum)] is not None: try: finalItems += str(data.get_item_name(x["item_" + str(itemNum)])["name"]) + ", " except: finalItems += "unknown item, " out += finalItems + "\n" #Win? #@todo fix this to incorporate woody's bugfix if player_num < 5 and match["result"]["radiant_win"]: out += "You Won! " elif player_num > 4 and not match["result"]["radiant_win"]: out += "You Won! " else: out += "You Lost.... Bitch " out += str(match_id) + " " + dotabuff_link return out player_num = player_num + 1
def respond(self): if random.random() < ResponseLast.SASS_PERCENTAGE: print("#last - sassy override") return "Bitch, you can't last for shit" print "Starting" canonical_name = ( key for key, value in AbstractResponse.GroupMeIDs.items() if value == self.msg.sender_id).next() if not AbstractResponse.has_steamID(canonical_name): return "I don't know your SteamID! Set it with '#set ID'" if not AbstractResponse.has_dotaID(canonical_name): return "I don't know your DOTA ID! Set it with '#setDota ID'" print "Setting Key & Account ID" api.set_api_key(AbstractResponse.key) account_id = AbstractResponse.name_to_steamID(canonical_name) print "Got Account ID" # Get a list of recent matches for the player matches = api.get_match_history( account_id=account_id)["result"]["matches"] #Get the full details for a match match = api.get_match_details(matches[0]["match_id"]) match_id = match['result']['match_id'] dotabuff_link = ResponseLast.DOTABUFF_LINK_TEMPLATE.format(id=match_id) print "Got Match Details" player_num = 0 for x in match["result"]["players"]: if int(x["account_id"]) == AbstractResponse.name_to_dotaID( canonical_name): out = "" print "Got self.sender Data" #Stats? print player_num msg = ResponseLast.match_performance_template.format( hero=data.get_hero_name(x["hero_id"])["localized_name"], k=str(x["kills"]), d=str(x["deaths"]), a=str(x["assists"]), GPM=str(x["gold_per_min"]), level=str(x["level"])) out += msg + "\n" #Items? finalItems = "Your items: " for itemNum in range(0, 6): if x["item_" + str(itemNum)] != 0 and x[ "item_" + str(itemNum)] is not None: try: finalItems += str( data.get_item_name( x["item_" + str(itemNum)])["name"]) + ", " except: finalItems += "unknown item ({}), ".format( x["item_" + str(itemNum)]) out += finalItems + "\n" #Win? #@todo fix this to incorporate woody's bugfix if player_num < 5 and match["result"]["radiant_win"]: out += "You Won! " elif player_num > 4 and not match["result"]["radiant_win"]: out += "You Won! " else: out += "You Lost.... Bitch " out += str(match_id) + " " + dotabuff_link return out player_num = player_num + 1
def update_dota(self): # Get a list of recent matches for the player total_added = 0 api.set_api_key(AbstractResponse.key) current_time = int(time.time()) last_update_time = AbstractResponse.get_last_update_time() new_records = "" for name, account_id in AbstractResponse.GroupMetoDOTA.items(): print "Starting: {0}".format(name) # Get a list of recent matches for the player matches = api.get_match_history( account_id=account_id)["result"]["matches"] #Go through every match for match in matches: print "\tChecking: " + str(match["match_id"]) if match["start_time"] < last_update_time["last_update"]: print "\tWe've seen these matches" break if (not AbstractResponse.has_dotaMatch(match["match_id"])): single_match = api.get_match_details( match["match_id"])["result"] print "\t\tAdding: " + str(single_match["match_id"]) AbstractResponse.add_dotaMatch(single_match) total_added += 1 #Did this match set any new records# ? for player in single_match["players"]: #Is this a player we are tracking? if AbstractResponse.has_dotaID_num( int(player["account_id"])): #Yes! Check if they broke a record old_record = AbstractResponse.get_record( player["hero_id"]) print player["hero_id"] hero_dict = data.get_hero_name(player["hero_id"]) if not hero_dict: print( "For hero id = {}, not in dota2py".format( player["hero_id"])) continue hero_name = data.get_hero_name( player["hero_id"])["localized_name"] player_name = AbstractResponse.dotaID_to_name( int(player["account_id"])) if old_record is None: #this is auto a new record! new_record = { "hero_id": player["hero_id"], "max_kills": player["kills"], "max_kills_player": player["account_id"], "max_deaths": player["deaths"], "max_deaths_player": player["account_id"], "max_GPM": player["gold_per_min"], "max_GPM_player": player["account_id"], "min_GPM": player["gold_per_min"], "min_GPM_player": player["account_id"], "max_XPM": player["xp_per_min"], "max_XPM_player": player["account_id"], "min_XPM": player["xp_per_min"], "min_XPM_player": player["account_id"], } AbstractResponse.set_record(new_record) else: #There is an existing record.. Lets see if this match was a game changer new_record = old_record.copy() if old_record["max_kills"] < player["kills"]: new_records += "{0} just got {1} kills with {2}, a new record!\n".format( player_name, player["kills"], hero_name) new_record["max_kills"] = player["kills"] new_record["max_kills_player"] = player[ "account_id"] if old_record["max_deaths"] < player["deaths"]: new_records += "{0} just got {1} deaths with {2}, a new low!\n".format( player_name, player["deaths"], hero_name) new_record["max_deaths"] = player["deaths"] new_record["max_deaths_player"] = player[ "account_id"] if old_record["max_GPM"] < player[ "gold_per_min"]: new_records += "{0} just got {1} GPM with {2}, a new record!\n".format( player_name, player["gold_per_min"], hero_name) new_record["max_GPM"] = player[ "gold_per_min"] new_record["max_GPM_player"] = player[ "account_id"] if old_record["min_GPM"] > player[ "gold_per_min"]: new_records += "{0} just got {1} GPM with {2}, a new low!\n".format( player_name, player["gold_per_min"], hero_name) new_record["min_GPM"] = player[ "gold_per_min"] new_record["min_GPM_player"] = player[ "account_id"] if old_record["max_XPM"] < player["xp_per_min"]: new_records += "{0} just got {1} XPM with {2}, a new record!\n".format( player_name, player["xp_per_min"], hero_name) new_record["max_XPM"] = player[ "xp_per_min"] new_record["max_XPM_player"] = player[ "account_id"] if old_record["min_XPM"] > player["xp_per_min"]: new_records += "{0} just got {1} XPM with {2}, a new low!\n".format( player_name, player["xp_per_min"], hero_name) new_record["min_XPM"] = player[ "xp_per_min"] new_record["min_XPM_player"] = player[ "account_id"] AbstractResponse.set_record(new_record) else: print "\t Was Duplicate" print "Updated {0} Matches".format(total_added) if last_update_time == None: time_dict = {'last_update': current_time} else: time_dict = last_update_time.copy() time_dict["last_update"] = current_time AbstractResponse.set_last_update_time(time_dict) return new_records