Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge collapsible with statements #283

Merged
merged 2 commits into from
Oct 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions minato_namikaze/bot_files/cogs/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ async def get_weather(
params["q"] = str(location)
url = "https://api.openweathermap.org/data/2.5/weather?{0}".format(
urlencode(params))
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
data = await resp.json()
async with aiohttp.ClientSession() as session, session.get(
url) as resp:
data = await resp.json()
try:
if data["message"] == "city not found":
await ctx.send("City not found.")
Expand Down
47 changes: 23 additions & 24 deletions minato_namikaze/bot_files/lib/classes/games/typeracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,18 +286,17 @@ def _tr_img(text: str, font: str):
buffer.seek(0)
return buffer

async def wait_for_tr_response(
self, ctx: commands.Context, text: str, *, timeout: int, start
):
async def wait_for_tr_response(self, ctx: commands.Context, text: str, *,
timeout: int, start):

text = text.lower().replace("\n", " ").strip(".")

try:
message = await ctx.bot.wait_for(
"message",
timeout=timeout,
check=lambda m: m.channel == ctx.channel
and m.content.lower().replace("\n", " ").strip(".") == text,
check=lambda m: m.channel == ctx.channel and m.content.lower().
replace("\n", " ").strip(".") == text,
)
except asyncio.TimeoutError:
return await ctx.reply(
Expand All @@ -315,9 +314,8 @@ async def wait_for_tr_response(
)

await message.add_reaction("\U00002705")
await message.reply(
embed=embed, allowed_mentions=discord.AllowedMentions.none()
)
await message.reply(embed=embed,
allowed_mentions=discord.AllowedMentions.none())
return True

async def start(
Expand All @@ -332,34 +330,35 @@ async def start(
):

if mode == "sentence":
async with aiohttp.ClientSession() as session:
async with session.get(self.SENTENCE_URL) as r:
if r.status in range(200, 299):
text = await r.json()
text = text["content"]
else:
return await ctx.send("Oops an error occured")
async with aiohttp.ClientSession() as session, session.get(
self.SENTENCE_URL) as r:
if r.status in range(200, 299):
text = await r.json()
text = text["content"]
else:
return await ctx.send("Oops an error occured")
elif mode == "random":
text = " ".join(
[random.choice(self.GRAMMAR_WORDS).lower() for _ in range(15)]
)
[random.choice(self.GRAMMAR_WORDS).lower() for _ in range(15)])
else:
raise TypeError(
"Invalid game mode , must be either 'random' or 'sentence'")

buffer = await ctx.bot.loop.run_in_executor(
None, self._tr_img, text, path_to_text_font
)
buffer = await ctx.bot.loop.run_in_executor(None, self._tr_img, text,
path_to_text_font)

embed = discord.Embed(
title=embed_title, color=embed_color, timestamp=dt.utcnow()
)
embed = discord.Embed(title=embed_title,
color=embed_color,
timestamp=dt.utcnow())
embed.set_image(url="attachment://tr.png")
embed.set_author(name=ctx.author.name, icon_url=ctx.author.avatar_url)

await ctx.send(embed=embed, file=discord.File(buffer, "tr.png"))

start = time.perf_counter()
await self.wait_for_tr_response(ctx, text, start=start, timeout=timeout)
await self.wait_for_tr_response(ctx,
text,
start=start,
timeout=timeout)

return True