async def ranks_hs(self,ctx, skill, *name): try: name = ("_").join(name).lower() players = get_players_in_hs(self.cur) if name in players: all_stats = get_all_from_hs(self.cur) if skill == "skills": ranks = {} for i,skill in enumerate(SKILLS): all_stats = sorted(all_stats,key=lambda tup: (tup[i*2+1],tup[i*2+2]),reverse=True) index = [x for x, y in enumerate(all_stats) if y[0] == name][0] + 1 ranks[skill] = index else: ranks = {} for i,stat in enumerate(CLUES+BOSSES,start=49): all_stats = sorted(all_stats,key=lambda tup: tup[i],reverse=True) index = [x for x, y in enumerate(all_stats) if y[0] == name][0] if all_stats[index][i] != -1: ranks[stat] = index + 1 response = f"{name}\n" for skill in ranks: response += f"{skill}: {ranks[skill]}\n" else: response = f"{name} is not on the clan hs." except Exception as e: response = str(e) finally: await ctx.send(response)
async def add_hs(self,ctx, *members): try: first_msg = 'Adding ' for member in members: first_msg += f'{member} ' first_msg += "to the clan's hs." await ctx.send(first_msg) not_found_osrs = [] in_cc = [] all_names = get_players_in_hs(self.cur) for name in members: name = name.lower() stats = getStats(playerURL(name,'iron')) if stats == 404: not_found_osrs.append(name) elif name in all_names: in_cc.append(name) else: try: sql_add_player_hs(self.cur,name,stats) except Exception as e: in_cc.append(name) #self.conn.commit() found = [x for x in members if (x not in in_cc and x not in not_found_osrs)] response = f"{found} were added!\n" if not_found_osrs: response+= f"{not_found_osrs} were not found in the osrs' hiscores.\n" if in_cc: response+= f"{in_cc} these players are already in the clan's hiscores.\n" except Exception as e: response = str(e) finally: await ctx.send(response)
async def update_hs(self,ctx, *members): try: players = get_players_in_hs(self.cur) first_msg = 'Updating ' for member in members: first_msg += f'{member} ' await ctx.send(first_msg) not_found_osrs = [] not_in_cc = [] for name in members: name = name.lower() stats = getStats(playerURL(name,'iron')) if stats == 404: not_found_osrs.append(name) elif name in players: try: sql_update_player_hs(self.cur,name,stats,stats_col_names) except Exception as e: print(e) else: not_in_cc.append(name) found = [x for x in members if (x not in not_in_cc and x not in not_found_osrs)] response = f"{found} were updated!\n" if not_found_osrs: response+= f"{not_found_osrs} were not found in the osrs' ironman hiscores.\n" if not_in_cc: response+= f"{not_in_cc} were not found on the clan's hiscores.\n" except Exception as e: response = str(e) finally: await ctx.send(response)
async def check_hs(self,ctx, name): name = name.lower() players = get_players_in_hs(self.cur) if name in players: response = f"{name} is in the clan's hiscores." else: response = f"{name} is not in the clan's hiscores." await ctx.send(response)
async def rm(self,ctx, *members): try: await ctx.send("Removing players from the hs.") players_in_hs = get_players_in_hs(self.cur) removed = [] for name in members: name = name.lower() if name in players_in_hs: rm_from_hs(self.cur,name) removed.append(name) response = f"Players removed: {removed}" except Exception as e: response = str(e) finally: await ctx.send(response)
async def rmoutdated(self,ctx): try: await ctx.send("Checking for outdated names in the hs.") players_in_hs = get_players_in_hs(self.cur) outdated = [] for name in players_in_hs: stats = getStats(playerURL(name,'iron')) if stats == 404: outdated.append(name) rm_from_hs(self.cur,name) #self.conn.commit() response = f"Players outdated and removed: {outdated}" except Exception as e: response = str(e) finally: await ctx.send(response)
async def change2(self,ctx,old_name,*new_name): try: players = get_players_in_hs(self.cur) new_name = ("_").join(new_name).lower() old_name = old_name.lower() if old_name in players and new_name not in players: change_player_name(self.cur,old_name,new_name) change_player_name_clantracker(self.cur,old_name,new_name) change_player_name_mytracker(self.cur,old_name,new_name) #self.conn.commit() response = f"{old_name} changed to {new_name} in the clan's hiscores." else: response = f"{old_name} not found in the clan's hiscores." except Exception as e: response = str(e) finally: await ctx.send(response)
async def ranks(self,ctx,stat,name): try: name = name.lower() stat_pretty = get_stat(stat.lower()) stat = coded_string(stat_pretty) names = get_players_in_hs(self.cur) if name in names: skill = is_skill(stat) rank = get_player_rank(self.cur,name,stat,skill) response = f"{name} is rank {rank} in {stat_pretty}" else: response = f"{name} is not on the clan's hiscores." except Exception as e: response = str(e) finally: await ctx.send(response)
async def fullupdate(self,ctx): await ctx.send("Updating all players...") members = get_players_in_hs(self.cur) not_found_osrs = [] for name in members: stats = getStats(playerURL(name,'iron')) if stats == 404: not_found_osrs.append(name) else: try: sql_update_player_hs(self.cur,name,stats_col_names,stats) except Exception as e: print(str(e)) response = "Finished updating." if not_found_osrs: response+= f"{not_found_osrs} were not found in the osrs' hiscores.\n" await ctx.send(response) await ctx.send(response)
async def start_clan_tracker(self, ctx, *members): try: await ctx.send("Adding players to the tracker.") players = get_players_in_tracker(self.cur) players_in_hs = get_players_in_hs(self.cur) already_being_tracked = [] not_found_osrs = [] for name in members: name = name.lower() if name in players: already_being_tracked.append(name) else: stats = getStats(playerURL(name, 'iron')) if stats == 404: not_found_osrs.append(name) else: if name not in players_in_hs: sql_add_player_hs(self.cur, name, stats) else: sql_update_player_hs(self.cur, name, stats, stats_col_names) add_clan_tracker(self.cur, name, stats) #self.conn.commit() response = '' if already_being_tracked: response += f'{already_being_tracked} are already being tracked.\n' if not_found_osrs: response += f'{not_found_osrs} were not found in the osrs hiscores.\n' found = [ x for x in members if (x not in already_being_tracked and x not in not_found_osrs) ] response += f'{found} were added to the clan tracker.' except Exception as e: response = str(e) finally: await ctx.send(response)
async def start_my_tracker(self, ctx): try: name = coded_string(ctx.message.author.display_name) personal_tracker_names = get_players_in_personal_tracker(self.cur) players_in_hs = get_players_in_hs(self.cur) if name not in personal_tracker_names: stats = getStats(playerURL(name, 'iron')) if stats == 404: response = f"{name} is not on the osrs hiscores." else: if name not in players_in_hs: sql_add_player_hs(self.cur, name, stats) else: sql_update_player_hs(self.cur, name, stats, stats_col_names) add_personal_tracker(self.cur, name, stats) #self.conn.commit() response = f"You are now being tracked. use !hs update 'your_name' to update your stats and !hs mytracker 'skill' to check your progress." else: response = "You are already being tracked. do: !hs resetmytracker, to restart your tracker. " except Exception as e: response = str(e) finally: await ctx.send(response)