Skip to content
Draft
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
9 changes: 3 additions & 6 deletions extensions/addons/cogs/otheraddons.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json # to read API json responses
import requests # to read api calls

import aiohttp
import discord
import discord.app_commands as app_commands
import discord.ext.commands as commands
Expand Down Expand Up @@ -297,11 +297,8 @@ async def convert_unit(
"appid": itx.client.api_tokens['Open Exchange Rates'],
"show_alternative": "true",
}
response_api = requests.get(
"https://openexchangerates.org/api/latest.json",
params=params
).text
data = json.loads(response_api)
async with aiohttp.ClientSession() as client, client.get("https://openexchangerates.org/api/latest.json", params=params) as response:
data = await response.json()
if data.get("error", 0):
await itx.response.send_message(
"I'm sorry, something went wrong while trying to get "
Expand Down
18 changes: 7 additions & 11 deletions extensions/addons/cogs/searchaddons.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json # to read API json responses

import requests # to read api calls
import aiohttp # to read api calls
import aiohttp.client_exceptions

import discord
import discord.app_commands as app_commands
Expand Down Expand Up @@ -375,11 +376,8 @@ async def equaldex(self, itx: discord.Interaction[Bot], country_id: str):
"apiKey": equaldex_key,
# "formatted": "true",
}
response = requests.get(
"https://www.equaldex.com/api/region",
params=querystring
)
response_api = response.text
async with aiohttp.ClientSession() as client, client.get("https://www.equaldex.com/api/region", params=querystring) as response:
response_api = await response.text()
# returns -> <pre>{"regions":{...}}</pre> <- so you need to
# remove the <pre> and </pre> parts. It also has some
# <br \/>\r\n strings in there for some reason...? so uh
Expand Down Expand Up @@ -505,11 +503,9 @@ async def math(self, itx: discord.Interaction[Bot], query: str):
"output": "json",
}
try:
api_response: WolframResult = requests.get(
"https://api.wolframalpha.com/v2/query",
params=params
).json()
except requests.exceptions.JSONDecodeError:
async with aiohttp.ClientSession() as client, client.get("https://api.wolframalpha.com/v2/query", params=params) as response:
api_response: WolframResult = await response.json()
except (aiohttp.client_exceptions.ContentTypeError, json.JSONDecodeError):
await itx.followup.send(
"Your input gave a malformed result! Perhaps it took "
"too long to calculate...",
Expand Down
8 changes: 3 additions & 5 deletions extensions/staffaddons/cogs/staffaddons.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from datetime import datetime, timedelta
# ^ for /delete_week_selfies (within 7 days), and /version startup
# time parsing to discord unix <t:1234:F>
import requests
# to fetch from GitHub and see Rina is running the latest version
import aiohttp # to fetch from GitHub and see Rina is running the latest version

import discord
import discord.app_commands as app_commands
Expand Down Expand Up @@ -171,9 +170,8 @@ async def delete_week_selfies(self, itx: discord.Interaction[Bot]):
async def get_bot_version(self, itx: discord.Interaction[Bot]):
# get most recently pushed bot version
# noinspection LongLine
latest_rina = requests.get(
"https://raw.githubusercontent.com/TransPlace-Devs/uncute-rina/main/main.py" # noqa
).text
async with aiohttp.ClientSession() as client, client.get("https://raw.githubusercontent.com/TransPlace-Devs/uncute-rina/main/main.py") as response:
latest_rina = await response.text()
latest_version = (latest_rina
.split("BOT_VERSION = \"", 1)[1]
.split("\"", 1)[0])
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ pymongo>=4.14.0
pandas>=2.3.1
apscheduler>=3.11.0
matplotlib>=3.10.5
requests>=2.32.3
pytest>=8.4.1
aiohttp>=3.12.15