async def convert(self, ctx, argument): # Check if the fiat is valid valid = exchange_rates_api.valid_fiat(argument) if not valid: raise errors.InvalidArgument("Invalid fiat symbol") return argument
async def add_starboard_emoji( bot: commands.Bot, starboard_id: int, guild: discord.Guild, emoji: Union[discord.Emoji, str] ) -> None: check_sbemoji = \ """SELECT * FROM sbemojis WHERE name=$1 AND starboard_id=$2""" get_all_sbemojis = \ """SELECT * FROM sbemojis WHERE starboard_id=$1""" check_starboard = \ """SELECT * FROM starboards WHERE id=$1""" if not isinstance(emoji, discord.Emoji): if not functions.is_emoji(emoji): raise errors.InvalidArgument( "I don't recognize that emoji. If it is a custom " "emoji, it has to be in this server." ) emoji_name = str(emoji.id) if isinstance( emoji, discord.Emoji) else str(emoji) emoji_id = emoji.id if isinstance( emoji, discord.Emoji) else None limit = await functions.get_limit(bot, 'emojis', guild.id) conn = bot.db.conn async with bot.db.lock: async with conn.transaction(): sql_starboard = await conn.fetchrow( check_starboard, starboard_id ) if sql_starboard is None: raise errors.DoesNotExist("That is not a starboard!") all_sbemojis = await conn.fetch( get_all_sbemojis, starboard_id ) if len(all_sbemojis) + 1 > limit: raise errors.NoPremiumError( "You have reached your limit for emojis " "on this starboard.\nSee the last page of " "`sb!tutorial` for more info." ) sbemoji = await conn.fetchrow( check_sbemoji, emoji_name, starboard_id ) if sbemoji is not None: raise errors.AlreadyExists( "That is already a starboard emoji!" ) await bot.db.q.create_sbemoji.fetch( emoji_id, starboard_id, emoji_name, False )
async def convert(self, ctx, argument): # Check if argument is a valid location valid = weather_api.valid_location(argument) if not valid: raise errors.InvalidArgument("Invalid location name") # Retrieve the current weather data of the location data = weather_api.get_current_weather_data(argument) if data is None: raise errors.RequestError( "There was an error while fetching the weather data") return {"location_name": argument.capitalize(), "data": data}
async def convert(self, ctx, argument): # Check if the coin is valid valid = coingecko_api.valid_coin(argument) if not valid: raise errors.InvalidArgument("Invalid coin symbol") # Retrieve the price data of the coin data = coingecko_api.get_price_data(argument) if data is None: raise errors.RequestError( "There was an error while fetching the coin data") return {"symbol": argument.upper(), "data": data}