fix(pterodactyl): fixed join and leave listeners throwing errors
This commit is contained in:
parent
1244d5a941
commit
ad0bb7cf00
2 changed files with 13 additions and 13 deletions
|
@ -22,7 +22,7 @@ class Pterodactyl(commands.Cog):
|
|||
|
||||
__author__ = ["[cswimr](https://www.coastalcommits.com/cswimr)"]
|
||||
__git__ = "https://www.coastalcommits.com/cswimr/SeaCogs"
|
||||
__version__ = "2.0.2"
|
||||
__version__ = "2.0.3"
|
||||
__documentation__ = "https://seacogs.coastalcommits.com/pterodactyl/"
|
||||
|
||||
def __init__(self, bot: Red):
|
||||
|
|
|
@ -80,7 +80,7 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
|
|||
if join_message:
|
||||
if chat_channel is not None:
|
||||
if coginstance.bot.embed_requested(chat_channel):
|
||||
embed, img = await generate_join_leave_embed(coginstance=coginstance, username=chat_message['username'],join=True)
|
||||
embed, img = await generate_join_leave_embed(coginstance=coginstance, username=join_message,join=True)
|
||||
if img:
|
||||
with open(img, 'rb') as file:
|
||||
await chat_channel.send(embed=embed, file=file)
|
||||
|
@ -93,7 +93,7 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
|
|||
if leave_message:
|
||||
if chat_channel is not None:
|
||||
if coginstance.bot.embed_requested(chat_channel):
|
||||
embed, img = await generate_join_leave_embed(coginstance=coginstance, username=chat_message['username'],join=False)
|
||||
embed, img = await generate_join_leave_embed(coginstance=coginstance, username=leave_message,join=False)
|
||||
if img:
|
||||
with open(img, 'rb') as file:
|
||||
await chat_channel.send(embed=embed, file=file)
|
||||
|
@ -165,7 +165,7 @@ async def check_if_server_message(text: str) -> Union[bool, str]:
|
|||
regex = await config.server_regex()
|
||||
match: Optional[re.Match[str]] = re.match(regex, text)
|
||||
if match:
|
||||
logger.debug("Message is a server message")
|
||||
logger.trace("Message is a server message")
|
||||
return match.group(1)
|
||||
return False
|
||||
|
||||
|
@ -174,7 +174,7 @@ async def check_if_chat_message(text: str) -> Union[bool, dict]:
|
|||
match: Optional[re.Match[str]] = re.match(regex, text)
|
||||
if match:
|
||||
groups = {"username": match.group(1), "message": match.group(2)}
|
||||
logger.debug("Message is a chat message\n%s", json.dumps(groups))
|
||||
logger.trace("Message is a chat message\n%s", json.dumps(groups))
|
||||
return groups
|
||||
return False
|
||||
|
||||
|
@ -182,7 +182,7 @@ async def check_if_join_message(text: str) -> Union[bool, str]:
|
|||
regex = await config.join_regex()
|
||||
match: Optional[re.Match[str]] = re.match(regex, text)
|
||||
if match:
|
||||
logger.debug("Message is a join message")
|
||||
logger.trace("Message is a join message")
|
||||
return match.group(1)
|
||||
return False
|
||||
|
||||
|
@ -190,7 +190,7 @@ async def check_if_leave_message(text: str) -> Union[bool, str]:
|
|||
regex = await config.leave_regex()
|
||||
match: Optional[re.Match[str]] = re.match(regex, text)
|
||||
if match:
|
||||
logger.debug("Message is a leave message")
|
||||
logger.trace("Message is a leave message")
|
||||
return match.group(1)
|
||||
return False
|
||||
|
||||
|
@ -203,23 +203,23 @@ async def check_if_achievement_message(text: str) -> Union[bool, dict]:
|
|||
groups["challenge"] = True
|
||||
else:
|
||||
groups["challenge"] = False
|
||||
logger.debug("Message is an achievement message")
|
||||
logger.trace("Message is an achievement message")
|
||||
return groups
|
||||
return False
|
||||
|
||||
async def get_info(username: str) -> Optional[dict]:
|
||||
logger.debug("Retrieving player info for %s", username)
|
||||
logger.verbose("Retrieving player info for %s", username)
|
||||
endpoint = await config.api_endpoint()
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(f"https://playerdb.co/api/player/{endpoint}/{username}") as response:
|
||||
if response.status == 200:
|
||||
logger.debug("Player info retrieved for %s", username)
|
||||
logger.verbose("Player info retrieved for %s", username)
|
||||
return await response.json()
|
||||
logger.error("Failed to retrieve player info for %s: %s", username, response.status)
|
||||
logger.warning("Failed to retrieve player info for %s: %s", username, response.status)
|
||||
return None
|
||||
|
||||
async def send_chat_discord(coginstance: Pterodactyl, username: str, message: str, avatar_url: str) -> None:
|
||||
logger.debug("Sending chat message to Discord")
|
||||
logger.trace("Sending chat message to Discord")
|
||||
channel = coginstance.bot.get_channel(await config.chat_channel())
|
||||
if channel is not None:
|
||||
webhooks = await channel.webhooks()
|
||||
|
@ -227,7 +227,7 @@ async def send_chat_discord(coginstance: Pterodactyl, username: str, message: st
|
|||
if webhook is None:
|
||||
webhook = await channel.create_webhook(name="Pterodactyl Chat")
|
||||
await webhook.send(content=message, username=username, avatar_url=avatar_url, allowed_mentions=discord.AllowedMentions(everyone=False, roles=False, users=True))
|
||||
logger.debug("Chat message sent to Discord")
|
||||
logger.trace("Chat message sent to Discord")
|
||||
else:
|
||||
logger.warning("Chat channel not set. Skipping sending chat message to Discord")
|
||||
|
||||
|
|
Loading…
Reference in a new issue