fix(pterodactyl): don't depend on a website to host images when i can bundle image files in the cog itself
This commit is contained in:
parent
1c0f12660b
commit
1244d5a941
3 changed files with 26 additions and 10 deletions
BIN
pterodactyl/data/unknown.png
Normal file
BIN
pterodactyl/data/unknown.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 65 KiB |
|
@ -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.1"
|
||||
__version__ = "2.0.2"
|
||||
__documentation__ = "https://seacogs.coastalcommits.com/pterodactyl/"
|
||||
|
||||
def __init__(self, bot: Red):
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
# pylint: disable=cyclic-import
|
||||
import json
|
||||
import re
|
||||
from typing import Optional, Union
|
||||
from pathlib import Path
|
||||
from typing import Optional, Tuple, Union
|
||||
|
||||
import aiohttp
|
||||
import discord
|
||||
import websockets
|
||||
from pydactyl import PterodactylClient
|
||||
from redbot.core.data_manager import bundled_data_path
|
||||
from redbot.core.utils.chat_formatting import bold, pagify
|
||||
|
||||
from pterodactyl.config import config
|
||||
|
@ -78,7 +80,12 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
|
|||
if join_message:
|
||||
if chat_channel is not None:
|
||||
if coginstance.bot.embed_requested(chat_channel):
|
||||
await chat_channel.send(embed=await generate_join_leave_embed(join_message, True))
|
||||
embed, img = await generate_join_leave_embed(coginstance=coginstance, username=chat_message['username'],join=True)
|
||||
if img:
|
||||
with open(img, 'rb') as file:
|
||||
await chat_channel.send(embed=embed, file=file)
|
||||
else:
|
||||
await chat_channel.send(embed=embed)
|
||||
else:
|
||||
await chat_channel.send(f"{join_message} joined the game", allowed_mentions=discord.AllowedMentions.none())
|
||||
|
||||
|
@ -86,7 +93,12 @@ async def establish_websocket_connection(coginstance: Pterodactyl) -> None:
|
|||
if leave_message:
|
||||
if chat_channel is not None:
|
||||
if coginstance.bot.embed_requested(chat_channel):
|
||||
await chat_channel.send(embed=await generate_join_leave_embed(leave_message, False))
|
||||
embed, img = await generate_join_leave_embed(coginstance=coginstance, username=chat_message['username'],join=False)
|
||||
if img:
|
||||
with open(img, 'rb') as file:
|
||||
await chat_channel.send(embed=embed, file=file)
|
||||
else:
|
||||
await chat_channel.send(embed=embed)
|
||||
else:
|
||||
await chat_channel.send(f"{leave_message} left the game", allowed_mentions=discord.AllowedMentions.none())
|
||||
|
||||
|
@ -219,29 +231,33 @@ async def send_chat_discord(coginstance: Pterodactyl, username: str, message: st
|
|||
else:
|
||||
logger.warning("Chat channel not set. Skipping sending chat message to Discord")
|
||||
|
||||
async def generate_join_leave_embed(username: str, join: bool) -> discord.Embed:
|
||||
async def generate_join_leave_embed(coginstance: Pterodactyl, username: str, join: bool) -> Tuple[discord.Embed, Optional[Union[str, Path]]]:
|
||||
embed = discord.Embed()
|
||||
embed.color = discord.Color.green() if join else discord.Color.red()
|
||||
embed.description = await config.join_msg() if join else await config.leave_msg()
|
||||
info = await get_info(username)
|
||||
if info:
|
||||
img = None
|
||||
embed.set_author(name=username, icon_url=info['data']['player']['avatar'])
|
||||
else:
|
||||
embed.set_author(name=username, icon_url='https://seafsh.cc/u/j3AzqQ.png')
|
||||
img = bundled_data_path(coginstance) / "unknown.png"
|
||||
embed.set_author(name=username, icon_url='attachment://unknown.png')
|
||||
embed.timestamp = discord.utils.utcnow()
|
||||
return embed
|
||||
return embed, img
|
||||
|
||||
async def generate_achievement_embed(username: str, achievement: str, challenge: bool) -> discord.Embed:
|
||||
async def generate_achievement_embed(coginstance: Pterodactyl, username: str, achievement: str, challenge: bool) -> Tuple[discord.Embed, Optional[Union[str, Path]]]:
|
||||
embed = discord.Embed()
|
||||
embed.color = discord.Color.from_str('#a800a7') if challenge else discord.Color.from_str('#54fb54')
|
||||
embed.description = f"{bold(username)} has {'completed the challenge' if challenge else 'made the advancement'} {bold(achievement)}"
|
||||
info = await get_info(username)
|
||||
if info:
|
||||
img = None
|
||||
embed.set_author(name=username, icon_url=info['data']['player']['avatar'])
|
||||
else:
|
||||
embed.set_author(name=username, icon_url='https://seafsh.cc/u/j3AzqQ.png')
|
||||
img = bundled_data_path(coginstance) / "unknown.png"
|
||||
embed.set_author(name=username, icon_url='attachment://unknown.png')
|
||||
embed.timestamp = discord.utils.utcnow()
|
||||
return embed
|
||||
return embed, img
|
||||
|
||||
def mask_ip(string: str) -> str:
|
||||
def check(match: re.Match[str]):
|
||||
|
|
Loading…
Reference in a new issue