Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@commands.command()
async def forecast(self, ctx, *, location = ""):
# TODO: Detailed forecast option?
if not location or location.lower() == ctx.channel.name:
location = await self.bot.db.fetchval("SELECT location FROM twitch.locations WHERE channel = $1", ctx.channel.name)
if not location:
return await ctx.send(f"Error: Location not specified")
try:
forecaster = self.bot.owm_client.daily_forecast(location)
except (pyowm.exceptions.api_response_error.NotFoundError,
pyowm.exceptions.api_call_error.BadGatewayError) as e:
# TODO: Catch base exceptions?
return await ctx.send(f"Error: {e}")
forecast = forecaster.get_forecast()
location = forecast.get_location()
output = f"{location.get_name()}, {location.get_country()}"
for weather in forecast:
@commands.command()
async def averagefps(self, ctx):
users = await self.bot.get_users(ctx.channel.name)
url = "https://api.twitch.tv/kraken/streams/" + users[0].id
params = {"client_id": self.bot.http.client_id}
headers = {"Accept": "application/vnd.twitchtv.v5+json"}
async with self.bot.aiohttp_session.get(url, params = params, headers = headers) as resp:
data = await resp.json()
stream = data.get("stream")
if not stream:
return await ctx.send("Average FPS not found.")
await ctx.send(f"Average FPS: {stream['average_fps']}")
@commands.command()
async def time(self, ctx, *, location = ""):
if not location or location.lower() == ctx.channel.name:
location = await self.bot.db.fetchval("SELECT location FROM twitch.locations WHERE channel = $1", ctx.channel.name)
if not location:
return await ctx.send(f"Error: Location not specified")
try:
geocode_data = await get_geocode_data(location, aiohttp_session = self.bot.aiohttp_session)
latitude = geocode_data["geometry"]["location"]["lat"]
longitude = geocode_data["geometry"]["location"]["lng"]
timezone_data = await get_timezone_data(latitude = latitude, longitude = longitude,
aiohttp_session = self.bot.aiohttp_session)
except UnitOutputError as e:
return await ctx.send(f"Error: {e}")
location_time = datetime.datetime.now(datetime.timezone(datetime.timedelta(
seconds = timezone_data["dstOffset"] + timezone_data["rawOffset"])))
# TODO: Use method for Discord time command
@commands.command(aliases = ("goodbye",))
async def bye(self, ctx, *, user = None):
if not user or user.lower() == "harmonbot":
await ctx.send(f"Bye, {ctx.author.name.capitalize()}!")
else:
await ctx.send(f"{user.title().lstrip('/')}, {ctx.author.name.capitalize()} says goodbye!")
@commands.command(aliases = ("audiodefine", "pronounce"))
async def pronunciation(self, ctx, word):
# TODO: Add phonetic/text pronunciation
url = f"http://api.wordnik.com:80/v4/word.json/{word}/audio"
params = {"useCanonical": "false", "limit": 1, "api_key": self.bot.WORDNIK_API_KEY}
async with self.bot.aiohttp_session.get(url, params = params) as resp:
if resp.status == 404:
return await ctx.send("Error: Not found")
data = await resp.json()
if resp.status == 429:
return await ctx.send(f"Error: {data['message']}")
if data:
await ctx.send(f"{data[0]['word'].capitalize()}: {data[0]['fileUrl']}")
else:
await ctx.send("Word or audio not found.")
@commands.command()
async def cache(self, ctx):
seconds = int(10800 - time.time() % 10800)
# 10800 = seconds in 3 hours
await ctx.send(f"{duration_to_string(datetime.timedelta(seconds = seconds))} until Guthixian Cache.")
@commands.command()
async def zybez(self, ctx):
return await ctx.send("See https://forums.zybez.net/topic/1783583-exit-post-the-end/")