forked from cswimr/SeaCogs
misc(pterodactyl): renamed tellraw to chat_command
This commit is contained in:
parent
37cdca09ec
commit
417f297193
1 changed files with 15 additions and 17 deletions
|
@ -28,7 +28,7 @@ class Pterodactyl(commands.Cog):
|
|||
startup_arguments=None,
|
||||
power_action_in_progress=False,
|
||||
chat_regex=r"\[(\d{2}:\d{2}:\d{2})\sINFO\]:\s<(\w+)>\s(.*)",
|
||||
tellraw_json='tellraw @a ["",{"text":".$U ","color":".$C"},{"text":" (DISCORD): ","color":"blue"},{"text":".$M","color":"white"}]',
|
||||
chat_command='tellraw @a ["",{"text":".$U ","color":".$C"},{"text":" (DISCORD): ","color":"blue"},{"text":".$M","color":"white"}]',
|
||||
api_endpoint="minecraft",
|
||||
chat_channel=None
|
||||
)
|
||||
|
@ -147,12 +147,10 @@ class Pterodactyl(commands.Cog):
|
|||
else:
|
||||
self.logger.debug("Chat channel not set. Skipping sending chat message to Discord")
|
||||
|
||||
async def get_tellraw_string(self, username: str, message: str, color: discord.Color):
|
||||
tellraw = await self.config.tellraw_json()
|
||||
self.logger.debug("Generating tellraw string:\n%s", tellraw)
|
||||
tellraw = tellraw.replace(".$U", username).replace(".$M", message).replace(".$C", str(color))
|
||||
self.logger.debug("Tellraw string generated:\n%s", tellraw)
|
||||
return tellraw
|
||||
async def get_chat_command(self, username: str, message: str, color: discord.Color):
|
||||
command = await self.config.chat_command()
|
||||
command = command.replace(".$U", username).replace(".$M", message).replace(".$C", str(color))
|
||||
return command
|
||||
|
||||
def get_task(self):
|
||||
task = self.bot.loop.create_task(self.establish_websocket_connection(), name="Pterodactyl Websocket Connection")
|
||||
|
@ -192,7 +190,7 @@ class Pterodactyl(commands.Cog):
|
|||
channel = self.bot.get_channel(await self.config.console_channel())
|
||||
if channel:
|
||||
await channel.send(f"Received chat message from {message.author.id}: {message.content[:1900]}")
|
||||
msg = json.dumps({"event": "send command", "args": [await self.get_tellraw_string(message.author.display_name, message.content, message.author.color)]})
|
||||
msg = json.dumps({"event": "send command", "args": [await self.get_chat_command(message.author.display_name, message.content, message.author.color)]})
|
||||
self.logger.debug("Sending chat message to server:\n%s", msg)
|
||||
try:
|
||||
await self.websocket.send(msg)
|
||||
|
@ -257,7 +255,7 @@ class Pterodactyl(commands.Cog):
|
|||
|
||||
@pterodactyl_config_chat.command(name = "regex")
|
||||
async def pterodactyl_config_chat_regex(self, ctx: commands.Context, *, regex: str = None) -> None:
|
||||
"""Set the regex pattern to match chat messages.
|
||||
"""Set the regex pattern to match chat messages on the server.
|
||||
|
||||
See [documentation]() for more information."""
|
||||
#TODO - fix this link
|
||||
|
@ -267,15 +265,15 @@ class Pterodactyl(commands.Cog):
|
|||
await self.config.chat_regex.set(regex)
|
||||
await ctx.send(f"Chat regex set to:\n{box(regex, 'regex')}")
|
||||
|
||||
@pterodactyl_config_chat.command(name = "tellraw")
|
||||
async def pterodactyl_config_chat_tellraw(self, ctx: commands.Context, *, tellraw: str = None) -> None:
|
||||
"""Set the tellraw JSON to send chat messages to Discord.
|
||||
@pterodactyl_config_chat.command(name = "command")
|
||||
async def pterodactyl_config_chat_command(self, ctx: commands.Context, *, command: str = None) -> None:
|
||||
"""Set the command that will be used to send messages from Discord.
|
||||
|
||||
Required placeholders: `.$U` (username), `.$M` (message), `.$C` (color)
|
||||
See [documentation]() for more information."""
|
||||
#TODO - fix this link
|
||||
if tellraw is None:
|
||||
tellraw = await self.config.tellraw_json()
|
||||
return await ctx.send(f"Tellraw JSON is currently set to:\n{box(tellraw, 'json')}")
|
||||
await self.config.tellraw_json.set(tellraw)
|
||||
await ctx.send(f"Tellraw JSON set to:\n{box(tellraw, 'json')}")
|
||||
if command is None:
|
||||
command = await self.config.chat_command()
|
||||
return await ctx.send(f"Chat command is currently set to:\n{box(command, 'json')}")
|
||||
await self.config.chat_command.set(command)
|
||||
await ctx.send(f"Chat command set to:\n{box(command, 'json')}")
|
||||
|
|
Loading…
Reference in a new issue