Skip to content

Commit

Permalink
attempt fix for ratelimiting error in reactx
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomGuyJCI committed Oct 9, 2024
1 parent 99faea0 commit ba66e73
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions orchard/bot/lib/comm/interactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from orchard.bot.lib.constants import APPLICATION_ID, BOT_TOKEN
from orchard.utils.constants import DISCORD_API_URL

from orchard.utils.client import Client

from orchard.bot.lib.comm import pager
from typing import Callable, List, Awaitable

Expand All @@ -17,19 +19,6 @@
logger = logging.getLogger(__name__)


def could_raise(func: Callable[[], Awaitable[httpx.Response]]):
"""
Decorator. Apply to an async function that returns a Response, and it will call raise_for_status first.
"""

async def inner(*args, **kwargs):
resp = await func(*args, **kwargs)
resp.raise_for_status()
return resp

return inner


class Interactor:
"""
A class that contains methods for handling a slash command interaction.
Expand All @@ -41,7 +30,7 @@ class Interactor:

def __init__(self, token):
self._token = token
self.client = httpx.AsyncClient()
self.client = Client()
# list of crosscode uuids which this interactor owns
self.crosscode_uuids = []

Expand All @@ -67,14 +56,12 @@ async def __aexit__(self, exc_type, exc_value, traceback):
await self.client.aclose()
return True # don't propogate any error

@could_raise
async def get(self, id):
"""
Wrapper around discord API get message (from this webhook)
"""
return await self.client.get(f"{base_url}/{self._token}/messages/{id}")

@could_raise
async def edit(self, mb: MessageBuilder, id):
"""
Wrapper around discord API edit message.
Expand All @@ -85,7 +72,6 @@ async def edit(self, mb: MessageBuilder, id):
f"{base_url}/{self._token}/messages/{id}", json=mb.payload()
)

@could_raise
async def post(self, mb: MessageBuilder):
"""
Wrapper around discord API post message.
Expand All @@ -94,21 +80,18 @@ async def post(self, mb: MessageBuilder):
"""
return await self.client.post(f"{base_url}/{self._token}", json=mb.payload())

@could_raise
async def delete(self, id):
"""
Wrapper around discord API delete message.
"""
return await self.client.delete(f"{base_url}/{self._token}/messages/{id}")

@could_raise
async def react(self, channel_id, message_id, emoji):
return await self.client.put(
f"{DISCORD_API_URL}/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me",
headers={"Authorization": f"Bot {BOT_TOKEN}"},
)

@could_raise
async def get_reactions(self, channel_id, message_id, emoji):
return await self.client.get(
f"{DISCORD_API_URL}/channels/{channel_id}/messages/{message_id}/reactions/{urllib.parse.quote(emoji)}",
Expand Down

0 comments on commit ba66e73

Please sign in to comment.