async def update(self, ctx, allycode: int): """Updated the list of guild members in DB """ from operator import itemgetter database = "guild.db" conn = db_create_connection(database) guild_members = await fetch_guilds(CONFIG, [allycode]) guild_members_list = [[ x['allyCode'], x['name'], x['gpShip'] + x['gpChar'], x['gpChar'], x['gpShip'] ] for x in guild_members[0]['roster']] guild_members_list.sort(key=itemgetter(3), reverse=True) with conn: for player in guild_members_list: db_update_player(conn, (guild_members[0]['updated'], player[4], player[3], player[1], player[0])) #print(id) longest_name = max(map(len, [x[1] for x in guild_members_list])) await ctx.send(longest_name) reply = """```\n""" for pl in guild_members_list: #reply=reply+pl[0]+"\n" reply = reply + f"""{pl[1]} {(longest_name-len(pl[1]))*" "} {pl[2]/1000000:.2f}M \n""" reply = reply + "\n```" await ctx.send(len(reply)) #print(reply) await ctx.send(reply)
async def remove_warn(ctx, id: int): database = "guild" conn = db_create_connection(database) print(type(id)) with conn: db_dell_warn(conn, id) await ctx.send("Remove warning")
async def _search(self, ctx, name): '''Prints all guild members from DB. Provide an allycode of a guild member. Optional: if you want it to display an allycode for each player after the name follow with "with"''' from operator import itemgetter database = "guild.db" #if with_codes == "with": w conn = db_create_connection(database) with conn: guild_members_list = db_search_all_players(conn, name) #print("WTF") #await ctx.send( guild_members_list) #print(guild_members_list) # guild_members_list=[ list(player).append(player[4]+player[5]) for player in guild_members_list] for idx, player in enumerate(guild_members_list): guild_members_list[idx] = list(player) guild_members_list[idx].append(player[4] + player[5]) #print(guild_members_list) guild_members_list.sort(key=itemgetter(6), reverse=True) longest_name = max(map(len, [x[2] for x in guild_members_list])) reply = """```\n""" allycodes = "" for pl in guild_members_list: #reply=reply+pl[0]+"\n" allycodes = f" ({pl[1]})" reply_line = f"""{pl[2]}{allycodes} {(longest_name-len(pl[2]))*" "} {pl[6]/1000000:.2f}M \n""" if len(reply + reply_line) > 2000: reply = reply + "\n```" await ctx.send(reply) reply = """```\n""" + reply_line else: reply = reply + reply_line reply = reply + "\n```" # await ctx.send(len(reply)) await ctx.send(reply)
async def sm(self, ctx, phase: int): database = "guild.db" #if with_codes == "with": w conn = db_create_connection(database) with conn: guild_members_list = db_query_all_players(conn) for player in guild_members_list: asyncio.create_task(self.tb_message(ctx, player, phase))
async def average(self, ctx, gp_type="Total", allycode: int = None): """Plots the average guild GP over time. As parameters accepts: Total, GP_Ships, GP_Chars""" database = "guild.db" register_matplotlib_converters() conn = db_create_connection(database) with conn: guild_list = db_query_all_players(conn) allyC = [p[1] for p in guild_list] guild_list = db_query_gp_history(conn, allyC) df = pd.DataFrame( guild_list, columns=["id", "allycode", "Date", "GP_Ships", "GP_Chars"]).set_index("id") df.rename_axis(None, inplace=True) df['Date'] = df['Date'].astype("datetime64[ms]") df["GP_Ships"] = df["GP_Ships"] / 10**6 df["GP_Chars"] = df["GP_Chars"] / 10**6 df["Total"] = df["GP_Ships"] + df["GP_Chars"] x_min = df['Date'].min() x_max = df['Date'].max() delt = (x_max - x_min) / 10 fig, ax = plt.subplots(figsize=(10, 10)) date_form = DateFormatter("%d.%m") ax.xaxis.set_major_formatter(date_form) plt.xlim((x_min - delt, x_max + delt)) sns.set(style="ticks", context="talk") plt.style.use("dark_background") ax.set_title("Average Guild GP:" + gp_type) if allycode: sns.lineplot(data=df[df['allycode'] == allycode], x="Date", y=gp_type, marker="o", ax=ax, markersize=1, linewidth=1) # plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.,ncol=2) sns.lineplot(data=df, x="Date", y=gp_type, marker="o", ax=ax, markersize=15, linewidth=10) plt.savefig("avg_gp.png") plt.close(fig) file = discord.File("avg_gp.png", filename="avg_gp.png") await ctx.send(file=file)
async def add_warn(ctx, allycode: int, *args): await ctx.send(allycode) await ctx.send(" ".join(args)) await ctx.send("New warning") database = "guild" conn = db_create_connection(database) with conn: if db_player_in_guild(conn, allycode): date = datetime.now().strftime("%d/%m/%Y") db_add_warn(conn, [allycode, date, " ".join(args)]) await ctx.send("A strike has been added") else: await ctx.send( "Error: player with this allycode is not in the guild. Did you boot him already?" )
async def list_warn(ctx): database = "guild" conn = db_create_connection(database) with conn: warnings = db_list_warn(conn) warn_formated = defaultdict(list) print(warnings) for w in warnings: warn_formated[tuple(w[:2])].append(w[2:]) reply = """```md\n **LIST OF WARNINGS**\n""" for key, values in warn_formated.items(): name_code = f"{key[0]} {key[1]}:\n" reply += name_code for w in values: reply += f"""\t{w[0]}, {w[1]}\t id: {w[2]}\n""" print(reply) reply = reply + "\n```" await ctx.send(reply)
async def _list(ctx, allycode: int): '''Prints all guild members from DB''' from operator import itemgetter database = "guild" conn = db_create_connection(database) with conn: guild_members_list = db_query_all_players(conn) print("WTF") #await ctx.send( guild_members_list) print(guild_members_list) # guild_members_list=[ list(player).append(player[4]+player[5]) for player in guild_members_list] for idx, player in enumerate(guild_members_list): guild_members_list[idx] = list(player) guild_members_list[idx].append(player[4] + player[5]) #print(guild_members_list) guild_members_list.sort(key=itemgetter(6), reverse=True) longest_name = max(map(len, [x[2] for x in guild_members_list])) reply = """```\n""" for pl in guild_members_list: #reply=reply+pl[0]+"\n" reply = reply + f"""{pl[2]} {(longest_name-len(pl[2]))*" "} {pl[6]/1000000:.2f}M \n""" reply = reply + "\n```" # await ctx.send(len(reply)) await ctx.send(reply)