Skip to content

Commit

Permalink
remove fork optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
fixator10 committed Oct 12, 2022
1 parent 5715084 commit 31ae943
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 103 deletions.
16 changes: 1 addition & 15 deletions adminutils/adminutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
from redbot.core.utils.mod import get_audit_reason
from redbot.core.utils.predicates import MessagePredicate

try:
from redbot import json # support of Draper's branch
except ImportError:
import json

_ = Translator("AdminUtils", __file__)

EMOJI_RE = re.compile(r"(<(a)?:[a-zA-Z0-9_]+:([0-9]+)>)")
Expand All @@ -30,7 +25,7 @@ class AdminUtils(commands.Cog):
# noinspection PyMissingConstructor
def __init__(self, bot):
self.bot = bot
self.session = aiohttp.ClientSession(json_serialize=json.dumps)
self.session = aiohttp.ClientSession()

def cog_unload(self):
self.bot.loop.create_task(self.session.close())
Expand Down Expand Up @@ -207,8 +202,6 @@ async def emoji_add(self, ctx, name: str, url: str, *roles: discord.Role):
else None,
),
)
except discord.InvalidArgument:
await ctx.send(chat.error(_("This image type is unsupported, or link is incorrect")))
except discord.HTTPException as e:
await ctx.send(chat.error(_("An error occurred on adding an emoji: {}").format(e)))
else:
Expand Down Expand Up @@ -251,13 +244,6 @@ async def emote_steal(
),
)
await ctx.tick()
except discord.InvalidArgument:
await ctx.send(
_(
"This image type is not supported anymore or Discord returned incorrect data. Try again later."
)
)
return
except discord.HTTPException as e:
await ctx.send(chat.error(_("An error occurred on adding an emoji: {}").format(e)))

Expand Down
7 changes: 1 addition & 6 deletions godvilledata/godvilledata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@

from .godvilleuser import GodvilleUser

try:
from redbot import json # support of Draper's branch
except ImportError:
import json

BASE_API = "https://godville.net/gods/api"
BASE_API_GLOBAL = "http://godvillegame.com/gods/api"

Expand Down Expand Up @@ -60,7 +55,7 @@ def __init__(self, bot):
"godvillegame": {"apikey": None, "godname": None},
}
self.config.register_user(**default_user)
self.session = aiohttp.ClientSession(json_serialize=json.dumps)
self.session = aiohttp.ClientSession()

def cog_unload(self):
self.bot.loop.create_task(self.session.close())
Expand Down
12 changes: 3 additions & 9 deletions minecraftdata/minecraftdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@

from .minecraftplayer import MCPlayer

try:
from redbot import json # support of Draper's branch
except ImportError:
import json


_ = Translator("MinecraftData", __file__)


Expand All @@ -31,7 +25,7 @@ class MinecraftData(commands.Cog):
# noinspection PyMissingConstructor
def __init__(self, bot):
self.bot = bot
self.session = aiohttp.ClientSession(json_serialize=json.dumps)
self.session = aiohttp.ClientSession()

def cog_unload(self):
self.bot.loop.create_task(self.session.close())
Expand Down Expand Up @@ -206,7 +200,7 @@ async def fivezig(self, ctx, player: MCPlayer):
async with self.session.get(
f"http://textures.5zig.net/textures/2/{uuid}", raise_for_status=True
) as data:
response_data = await data.json(content_type=None, loads=json.loads)
response_data = await data.json(content_type=None)
cape = response_data["cape"]
except aiohttp.ClientResponseError as e:
if e.status == 404:
Expand All @@ -233,7 +227,7 @@ async def fivezig_animated(self, ctx, player: MCPlayer):
async with self.session.get(
f"http://textures.5zig.net/textures/2/{uuid}", raise_for_status=True
) as data:
response_data = await data.json(content_type=None, loads=json.loads)
response_data = await data.json(content_type=None)
if "animatedCape" not in response_data:
await ctx.send(
chat.error(_("{} doesn't have animated 5zig cape")).format(player.name)
Expand Down
7 changes: 1 addition & 6 deletions minecraftdata/minecraftplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
from redbot.core.commands import BadArgument
from redbot.core.i18n import Translator

try:
from redbot import json # support of Draper's branch
except ImportError:
import json

_ = Translator("MinecraftData", __file__)


Expand All @@ -28,7 +23,7 @@ async def convert(cls, ctx, argument):
f"https://api.mojang.com/users/profiles/minecraft/{argument}",
raise_for_status=True,
) as data:
response_data = await data.json(loads=json.loads)
response_data = await data.json()
except ContentTypeError:
response_data = None
except ClientResponseError as e:
Expand Down
12 changes: 3 additions & 9 deletions moreutils/moreutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
from redbot.core.utils import chat_formatting as chat
from tabulate import tabulate

try:
from redbot import json # support of Draper's branch
except ImportError:
import json


T_ = Translator("MoreUtils", __file__)
_ = lambda s: s

Expand Down Expand Up @@ -99,7 +93,7 @@ class MoreUtils(commands.Cog):
# noinspection PyMissingConstructor
def __init__(self, bot):
self.bot = bot
self.session = aiohttp.ClientSession(json_serialize=json.dumps)
self.session = aiohttp.ClientSession()

def cog_unload(self):
self.bot.loop.create_task(self.session.close())
Expand Down Expand Up @@ -159,7 +153,7 @@ async def color(self, ctx, *, color: discord.Color):
async with self.session.get(
"https://www.thecolorapi.com/id", params={"hex": str(color)[1:]}
) as data:
color_response = await data.json(loads=json.loads)
color_response = await data.json()
em.description = (
_("`Name:` {} ({})\n").format(
color_response.get("name", {}).get("value", "?"),
Expand Down Expand Up @@ -208,7 +202,7 @@ async def discordstatus(self, ctx):
async with self.session.get(
"https://srhpyqt94yxb.statuspage.io/api/v2/summary.json"
) as data:
response = await data.json(loads=json.loads)
response = await data.json()
except Exception as e:
await ctx.send(
chat.error(
Expand Down
11 changes: 1 addition & 10 deletions personalroles/personalroles.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@

from .discord_py_future import edit_role_icon

try:
from redbot import json # support of Draper's branch
except ImportError:
import json

_ = Translator("PersonalRoles", __file__)


Expand All @@ -47,7 +42,7 @@ class PersonalRoles(commands.Cog):
# noinspection PyMissingConstructor
def __init__(self, bot):
self.bot = bot
self.session = aiohttp.ClientSession(json_serialize=json.dumps)
self.session = aiohttp.ClientSession()
self.config = Config.get_conf(self, identifier=0x3D86BBD3E2B744AE8AA8B5D986EB4DD8)
default_member = {"role": None}
default_guild = {"blacklist": [], "role_persistence": True}
Expand Down Expand Up @@ -303,8 +298,6 @@ async def icon_emoji(self, ctx, *, emoji: Union[discord.Emoji, discord.PartialEm
await ctx.send(
chat.error(_("Unable to edit role.\nRole must be lower than my top role"))
)
except discord.InvalidArgument:
await ctx.send(chat.error(_("This image type is unsupported, or link is incorrect")))
except discord.HTTPException as e:
ctx.command.reset_cooldown(ctx)
await ctx.send(chat.error(_("Unable to edit role: {}").format(e)))
Expand Down Expand Up @@ -341,8 +334,6 @@ async def icon_image(self, ctx, *, url: str = None):
await ctx.send(
chat.error(_("Unable to edit role.\nRole must be lower than my top role"))
)
except discord.InvalidArgument:
await ctx.send(chat.error(_("This image type is unsupported, or link is incorrect")))
except discord.HTTPException as e:
ctx.command.reset_cooldown(ctx)
await ctx.send(chat.error(_("Unable to edit role: {}").format(e)))
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fonttools
git+https://github.com/fixator10/F10-Cogs-Utils
mcstatus>=5.1.1
motor>=2.5,<3.0
pillow>=6
pillow==9.2.0
pillow>=6.2.1
pybase64
pymongo>=3.10,<3.12.3
Expand Down
7 changes: 1 addition & 6 deletions reverseimagesearch/reverseimagesearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
from .saucenao import SauceNAO
from .tracemoe import TraceMoe

try:
from redbot import json # support of Draper's branch
except ImportError:
import json

_ = Translator("ReverseImageSearch", __file__)


Expand Down Expand Up @@ -67,7 +62,7 @@ def __init__(self, bot):
"long_remaining": None,
"short_remaining": None,
}
self.session = aiohttp.ClientSession(json_serialize=json.dumps)
self.session = aiohttp.ClientSession()
self.config = Config.get_conf(self, identifier=0x02E801D017C140A9A0C840BA01A25066)
default_global = {"numres": 6}
self.config.register_global(**default_global)
Expand Down
7 changes: 1 addition & 6 deletions reverseimagesearch/saucenao.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
from dateutil.parser import parse
from redbot.core.i18n import Translator

try:
from redbot import json # support of Draper's branch
except ImportError:
import json

_ = Translator("ReverseImageSearch", __file__)

BASE_API_URL = "https://saucenao.com/search.php"
Expand Down Expand Up @@ -88,7 +83,7 @@ async def from_image(cls, ctx, image_url):
async with ctx.cog.session.get(
BASE_API_URL, params=params, raise_for_status=True
) as data:
data = await data.json(loads=json.loads)
data = await data.json()
if data.get("status", 0) != 0:
if data.get("status") > 0:
raise ValueError(
Expand Down
9 changes: 2 additions & 7 deletions reverseimagesearch/tracemoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
from PIL import Image, UnidentifiedImageError
from redbot.core.i18n import Translator

try:
from redbot import json # support of Draper's branch
except ImportError:
import json

_ = Translator("ReverseImageSearch", __file__)

BASE_URL = "https://trace.moe"
Expand Down Expand Up @@ -95,7 +90,7 @@ async def from_image(cls, ctx, image_url):
data=data,
) as data:
# image file closed by aiohttp
resp = await data.json(loads=json.loads)
resp = await data.json()
if data.status != 200 or (error := resp.get("error")):
raise ValueError(
_("An error occurred during search: {}").format(
Expand All @@ -113,7 +108,7 @@ async def from_image(cls, ctx, image_url):
@classmethod
async def me(cls, ctx):
async with ctx.cog.session.get(f"{BASE_API_URL}/me") as data:
data = await data.json(loads=json.loads)
data = await data.json()
me_tuple = namedtuple(
"me",
"user_id,priority,concurrency,quota,quotaUsed",
Expand Down
7 changes: 1 addition & 6 deletions smmdata/smmdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@

from .smmbookmark import SMMB_BASE_URL, Level, Maker

try:
from redbot import json # support of Draper's branch
except ImportError:
import json

_ = Translator("SMMData", __file__)

BOOKMARKS_ICON_URL = f"{SMMB_BASE_URL}/assets/favicon/icon76-08f927f066250b84f628e92e0b94f58d.png"
Expand All @@ -25,7 +20,7 @@ class SMMData(commands.Cog):
# noinspection PyMissingConstructor
def __init__(self, bot):
self.bot = bot
self.session = aiohttp.ClientSession(json_serialize=json.dumps)
self.session = aiohttp.ClientSession()

def cog_unload(self):
self.bot.loop.create_task(self.session.close())
Expand Down
10 changes: 2 additions & 8 deletions steamcommunity/steamcommunity.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@

from .steamuser import SteamUser

try:
from redbot import json # support of Draper's branch
except ImportError:
import json


USERAGENT = (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
Expand Down Expand Up @@ -83,7 +77,7 @@ class SteamCommunity(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.steam = None
self.session = aiohttp.ClientSession(json_serialize=json.dumps)
self.session = aiohttp.ClientSession()
self.status_data = {"last_update": 0.0, "data": {}}

def cog_unload(self):
Expand Down Expand Up @@ -208,7 +202,7 @@ async def steamstatus(self, ctx):
headers={"referer": "https://steamstat.us/", "User-Agent": USERAGENT},
raise_for_status=True,
) as gravity:
data = await gravity.json(loads=json.loads)
data = await gravity.json()
self.status_data["data"] = data
self.status_data["last_update"] = time()
except aiohttp.ClientResponseError as e:
Expand Down
7 changes: 1 addition & 6 deletions translators/translators.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@

from .converters import PySupportedEncoding

try:
from redbot import json # support of Draper's branch
except ImportError:
import json

_ = Translator("Translators", __file__)

USERAGENT = (
Expand Down Expand Up @@ -52,7 +47,7 @@ class Translators(commands.Cog):
# noinspection PyMissingConstructor
def __init__(self, bot):
self.bot = bot
self.session = aiohttp.ClientSession(json_serialize=json.dumps)
self.session = aiohttp.ClientSession()

def cog_unload(self):
self.bot.loop.create_task(self.session.close())
Expand Down
10 changes: 2 additions & 8 deletions weather/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
from requests.exceptions import ConnectionError as RequestsConnectionError
from requests.exceptions import HTTPError, Timeout

try:
from redbot import json # support of Draper's branch
except ImportError:
import json

FORECASTIO_SUPPORTED_LANGS = [
"ar",
"az",
Expand Down Expand Up @@ -146,7 +141,6 @@ def __init__(self, bot):
default_guild = {"units": "si"}
self.config.register_guild(**default_guild)
self.session = aiohttp.ClientSession(
json_serialize=json.dumps,
raise_for_status=True,
)

Expand Down Expand Up @@ -268,7 +262,7 @@ async def weather(self, ctx, *, place: str):
"User-Agent": f"Red-DiscordBot/{redbot_ver} Fixator10-Cogs/Weather/{self.__version__}",
},
) as r:
location = await r.json(loads=json.loads)
location = await r.json()
except aiohttp.ClientResponseError as e:
await ctx.send(
chat.error(
Expand Down Expand Up @@ -393,7 +387,7 @@ async def forecast(self, ctx, *, place: str):
"User-Agent": f"Red-DiscordBot/{redbot_ver} Fixator10-Cogs/Weather/{self.__version__}",
},
) as r:
location = await r.json(loads=json.loads)
location = await r.json()
except aiohttp.ClientResponseError as e:
await ctx.send(
chat.error(
Expand Down

0 comments on commit 31ae943

Please sign in to comment.