def retrieve_top_tokens(arg_guild): session = Session() guild = session.query(Guild).filter(Guild.guild_id == arg_guild.id).first() header = ":moneybag: tokens" top_list = [] # Fetch top tokens temp_list = sorted(guild.users, key=lambda x: x.tokens, reverse=True) for index, user in enumerate(temp_list): guild_user = arg_guild.get_member(int(user.user_id)) # If user currently no longer in guild, skip said person. if guild_user is None: continue # Create dict object to store user data in. dbuser = services.AttrDict() dbuser.update({"user": str(guild_user.mention), "value": user.tokens}) top_list.append(dbuser) # maximum of 10 entries tyvm if len(top_list) is 10: break session.commit() session.close() return header, top_list
def retrieve_top_activity(arg_guild): session = Session() guild = session.query(Guild).filter(Guild.guild_id == arg_guild.id).first() header = ":speaking_head: activity" top_list = [] i = 0 # Fetch top messages_sent temp_list = sorted(guild.users, key=lambda x: x.activity_points, reverse=True) for index, user in enumerate(temp_list): guild_user = arg_guild.get_member(int(user.user_id)) # If user currently no longer in guild, skip said person. if guild_user is None: continue # Create dict object to store user data in. dbuser = services.AttrDict() dbuser.update({ "user": str(guild_user.display_name), "value": user.activity_points }) top_list.append(dbuser) # maximum of 10 entries tyvm if len(top_list) is 10: break session.commit() session.close() return header, top_list
def retrieve_guild(arg_guild): session = Session() guild = session.query(Guild).filter(Guild.guild_id == arg_guild.id).first() dbguild = services.AttrDict() dbguild.update({ "name": guild.name, "id": guild.guild_id, "join_date": guild.join_date, "prefix": guild.prefix, "attached": guild.attached, "karma_emoji": guild.karma_emoji, "log_channel_id": guild.log_channel_id }) session.commit() session.close() return dbguild
def get_user(arg_user): session = Session() guild = session.query(Guild).filter( Guild.guild_id == arg_user.guild.id).first() user = next((x for x in guild.users if int(x.user_id) == int(arg_user.id)), None) dbuser = services.AttrDict() dbuser.update({ "name": user.name, "user_id": user.user_id, "messages_sent": user.messages_sent, "activity_points": user.activity_points, "tokens": user.tokens, "karma": user.karma, "last_message": user.last_message }) session.commit() session.close() return dbuser