def format_weather(self, res: WeatherResponse, /) -> BetterEmbed: """Returns a formatted embed from the data received by the api""" embed = BetterEmbed(title=f"Weather in {res.name} ({res.sys.country})", description=f"Overall description : {res.weather[0].description}") embed.set_thumbnail(url=f"http://openweathermap.org/img/wn/{res.weather[0].icon}@2x.png") main = res.main sys = res.sys wind = res.wind nf = lambda obj, attr: getattr(obj, attr, '[NF]') # -> Any from_timestamp = lambda ts: naturaltime(dt.now(tz.utc) - dt.fromtimestamp(ts, tz=tz.utc)) # -> str from_kelvin = lambda kt: f"{kt - 273.15:.1f}°C | {(kt * 9/5 - 459.67):.1f}°F" # -> str fields = ( ('Min temperature', from_kelvin(main.temp_min)), ('Max temperature', from_kelvin(main.temp_max)), ('Feels like', from_kelvin(main.feels_like)), ('Pressure', f"{main.pressure} hPA"), ('Humidity', f"{main.humidity}%"), ('Visibility', f"{((res.visibility or 0) / 1000):.1f} kilometers"), ('Wind speed', f"{wind.speed} km/h"), ('Wind direction', f"{wind.deg} degrees"), ('Cloudiness', f"{res.clouds.all}%"), ('Data refreshed', from_timestamp(res.dt)), ('Sunrise', from_timestamp(sys.sunrise)), ('Sunset', from_timestamp(sys.sunset)) ) return embed.add_fields(fields)
def format_page(self, menu, page: Rule34Post): embed = BetterEmbed(title=f'Results for : {self.query}', url=page.file_url) fields = ( ('Size', f'{page.width}x{page.height}'), ('Creator id', page.creator_ID), ('Created at', to_human_datetime(page.created_at, "%a %b %d %H:%M:%S %z %Y")), ) embed.set_image(url=page.file_url) return embed.add_fields(fields)
def format_page(self, menu, page: Rule34Post): embed = BetterEmbed(title=f"Results for : {self.query}", url=page.file_url) fields = ( ("Size", f"{page.width}x{page.height}"), ("Creator id", page.creator_ID), ( "Created at", to_human_datetime(page.created_at, "%a %b %d %H:%M:%S %z %Y"), ), ) embed.set_image(url=page.file_url) return embed.add_fields(fields)
def format_page(self, menu, page: Rule34Post): embed = BetterEmbed(title=f'Results for : {self.query}', url=page.file_url) created_at = datetime.strptime( page.created_at, "%a %b %d %H:%M:%S %z %Y") # there must be a format for that fields = ( ('Size', f'{page.width}x{page.height}'), ('Creator id', page.creator_ID), ('Created at', naturaldate(created_at)), ) embed.set_image(url=page.file_url) return embed.add_fields(fields)
async def suggest(self, ctx: NewCtx, *, suggestion: str): if len(suggestion) >= 1000: raise commands.BadArgument( message="Cannot forward suggestions longer than 1000 characters" ) embed = BetterEmbed(title='Suggestion', description=suggestion) fields = (('Guild', f"{ctx.guild.name} ({ctx.guild.id})"), ('Channel', f"{ctx.channel.name} ({ctx.channel.id})"), ('User', f"{ctx.author} ({ctx.author.id})")) channel = self.bot.get_channel(config.SUGGESTION) await channel.send(embed=embed.add_fields(fields)) await ctx.send('Thank you for your suggestion')
def format_resp(self, *, resp: Translated, text: str) -> BetterEmbed: """Formats the response into an embed""" src = LANGUAGES.get(resp.src) or resp.src dest = LANGUAGES.get(resp.dest) or resp.dest conf = round(resp.confidence * 100, 1) f_confidence = str(conf) + '%' if conf < 50.0: f_confidence += ' (might be innacurate)' embed = BetterEmbed(title="Translated something !") fields = (('original', text, False), ('Translation', resp.text, False), ('Confidence', f_confidence, True), ('Languages', f'{src} -> {dest}', True)) return embed.add_fields(fields)
def format_resp(self, *, resp: Translated, text: str) -> BetterEmbed: """Formats the response into an embed""" src = LANGUAGES.get(resp.src) or resp.src dest = LANGUAGES.get(resp.dest) or resp.dest conf = round(resp.confidence * 100, 1) f_confidence = str(conf) + "%" if conf < 50.0: f_confidence += " (might be innacurate)" embed = BetterEmbed(title="Translated something !") fields = ( ("original", text, False), ("Translation", resp.text, False), ("Confidence", f_confidence, True), ("Languages", f"{src} -> {dest}", True), ) return embed.add_fields(fields)