From 2511675fad5bf18587ca9dd72207a24e7feb1894 Mon Sep 17 00:00:00 2001 From: sgoudham Date: Sun, 19 Jul 2020 00:20:37 +0100 Subject: [PATCH] storing embeds/fields into dictionaries iterating through dictionary to add fields --- cogs/help/help.py | 69 +++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 45 deletions(-) diff --git a/cogs/help/help.py b/cogs/help/help.py index 7e160200..c6c953e3 100644 --- a/cogs/help/help.py +++ b/cogs/help/help.py @@ -1,4 +1,5 @@ import datetime +from typing import List, Tuple, Any from discord import Embed from discord.ext import commands, menus @@ -7,6 +8,11 @@ from discord.ext.commands import command from settings import enso_embedmod_colours +async def make_embed(embed, seq: List[Tuple[Any, Any, bool]]) -> Embed: + embed.add_field(seq) + return embed + + # Pages of the help embed def help_menu(self, guild_icon): # Setting up the embed for the Fun Commands @@ -165,51 +171,24 @@ def help_menu(self, guild_icon): (f"**{self.ctx.prefix}mmsetup delete modmail**", "Existing modmail system will be deleted", False)] - """ fields = [fun_fields, interactive_fields, interactive_fields_2, - relationship_fields, enso_fields, waifu_and_husbando_fields, - important_fields, modmail_fields] - embeds = [fun, interactive, interactive_2, - relationship, enso, waifu_and_husbando, - important, modmail] - - for embed in embeds: - for field in fields: - # Add fields to the embed - for name, value, inline in field: - embed.add_field(name=name, value=value, inline=inline)""" - - # Add fields to the embed - for name, value, inline in fun_fields: - fun.add_field(name=name, value=value, inline=inline) - - # Add fields to the embed - for name, value, inline in interactive_fields: - interactive.add_field(name=name, value=value, inline=inline) - - # Add fields to the embed - for name, value, inline in interactive_fields_2: - interactive_2.add_field(name=name, value=value, inline=inline) - - # Add fields to the embed - for name, value, inline in relationship_fields: - relationship.add_field(name=name, value=value, inline=inline) - - # Add fields to the embed - for name, value, inline in enso_fields: - enso.add_field(name=name, value=value, inline=inline) - - # Add fields to the embed - for name, value, inline in waifu_and_husbando_fields: - waifu_and_husbando.add_field(name=name, value=value, inline=inline) - - # Add fields to the embed - for name, value, inline in important_fields: - important.add_field(name=name, value=value, inline=inline) - - # Add fields to the embed - for name, value, inline in modmail_fields: - modmail.add_field(name=name, value=value, inline=inline) - + # Defining dictionary of embeds as keys, list of fields as values + help_dict = { + fun: fun_fields, + interactive: interactive_fields, + interactive_2: interactive_fields_2, + relationship: relationship_fields, + enso: enso_fields, + waifu_and_husbando: waifu_and_husbando_fields, + important: important_fields, + modmail: modmail_fields + } + + # Iterating through the dictionary and adding fields to the embeds + for embed, field in help_dict.items(): + for name, value, inline in field: + embed.add_field(name=name, value=value, inline=inline) + + # Return all the embeds return fun, interactive, interactive_2, relationship, \ enso, waifu_and_husbando, important, modmail