DMcP89 / harambot

A Yahoo Fantasy Sports bot for Discord
MIT License
29 stars 18 forks source link

Refactor set_yahoo_from_interaction to decorator in Yahoo Cog #87

Closed DMcP89 closed 1 year ago

DMcP89 commented 1 year ago

We call this function to set the correct yahoo credentials before each command in the Yahoo cog:

    async def set_yahoo_from_interaction(
        self, interaction: discord.Interaction
    ):
        guild = Guild.get(Guild.guild_id == str(interaction.guild_id))
        self.yahoo_api = Yahoo(
            OAuth2(
                self.KEY, self.SECRET, store_file=False, **model_to_dict(guild)
            ),
            guild.league_id,
            guild.league_type,
        )
        return

This should be refactored to a decorator that is attached to each command.

DMcP89 commented 1 year ago

https://github.com/Rapptz/discord.py/discussions/8372 has an example of how to implement decorators for app commands.