Add Pterodactyl cog #19
3 changed files with 16 additions and 10 deletions
|
@ -129,11 +129,14 @@ The cog uses a tellraw command to send messages to Minecraft from Discord. To ch
|
||||||
|
|
||||||
Available placeholders:
|
Available placeholders:
|
||||||
|
|
||||||
- `.$U` - replaced with display name
|
- `.$C` - replaced with hex color of user's top colored role
|
||||||
- `.$M` - replaced with message contents
|
- `.$D` - replaced with user's discriminator (will usually be 0, you shouldn't use this)
|
||||||
- `.$C` - replaced with top role color (hex)
|
- `.$M` - replaced with message content
|
||||||
|
- `.$N` - replaced with author's display name (or guild nickname, if set)
|
||||||
|
- `.$I` - replaced with the author's ID
|
||||||
|
- `.$U` - replaced with the author's username (NOT display name, you should usually use `.$N`)
|
||||||
|
|
||||||
Default:
|
Default:
|
||||||
```json
|
```json
|
||||||
tellraw @a ["",{"text":".$U ","color":".$C"},{"text":" (DISCORD): ","color":"blue"},{"text":".$M","color":"white"}]
|
tellraw @a ["",{"text":".$D ","color":".$C"},{"text":" (DISCORD): ","color":"blue"},{"text":".$M","color":"white"}]
|
||||||
```
|
```
|
||||||
|
|
|
@ -15,7 +15,7 @@ def register_config(config_obj: Config) -> None:
|
||||||
join_regex=r"^\[\d{2}:\d{2}:\d{2} INFO\]: ([^<\n]+) joined the game$",
|
join_regex=r"^\[\d{2}:\d{2}:\d{2} INFO\]: ([^<\n]+) joined the game$",
|
||||||
leave_regex=r"^\[\d{2}:\d{2}:\d{2} INFO\]: ([^<\n]+) left the game$",
|
leave_regex=r"^\[\d{2}:\d{2}:\d{2} INFO\]: ([^<\n]+) left the game$",
|
||||||
achievement_regex=r"^\[\d{2}:\d{2}:\d{2} INFO\]: (.*) has (made the advancement|completed the challenge) \[(.*)\]$",
|
achievement_regex=r"^\[\d{2}:\d{2}:\d{2} INFO\]: (.*) has (made the advancement|completed the challenge) \[(.*)\]$",
|
||||||
chat_command='tellraw @a ["",{"text":".$U ","color":".$C"},{"text":" (DISCORD): ","color":"blue"},{"text":".$M","color":"white"}]',
|
chat_command='tellraw @a ["",{"text":".$D ","color":".$C"},{"text":" (DISCORD): ","color":"blue"},{"text":".$M","color":"white"}]',
|
||||||
api_endpoint="minecraft",
|
api_endpoint="minecraft",
|
||||||
chat_channel=None,
|
chat_channel=None,
|
||||||
startup_msg='Server started!',
|
startup_msg='Server started!',
|
||||||
|
|
|
@ -71,7 +71,7 @@ class Pterodactyl(commands.Cog):
|
||||||
channel = self.bot.get_channel(await config.console_channel())
|
channel = self.bot.get_channel(await config.console_channel())
|
||||||
if channel:
|
if channel:
|
||||||
await channel.send(f"Received chat message from {message.author.id}: {message.content[:1900]}")
|
await channel.send(f"Received chat message from {message.author.id}: {message.content[:1900]}")
|
||||||
msg = json.dumps({"event": "send command", "args": [await self.get_chat_command(message.author.display_name, message.content, message.author.color)]})
|
msg = json.dumps({"event": "send command", "args": [await self.get_chat_command(message)]})
|
||||||
logger.debug("Sending chat message to server:\n%s", msg)
|
logger.debug("Sending chat message to server:\n%s", msg)
|
||||||
try:
|
try:
|
||||||
await self.websocket.send(msg)
|
await self.websocket.send(msg)
|
||||||
|
@ -81,12 +81,15 @@ class Pterodactyl(commands.Cog):
|
||||||
self.retry_counter = 0
|
self.retry_counter = 0
|
||||||
self.task = self.get_task()
|
self.task = self.get_task()
|
||||||
|
|
||||||
async def get_chat_command(self, username: str, message: str, color: discord.Color) -> str:
|
async def get_chat_command(self, message: discord.Message) -> str:
|
||||||
command: str = await config.chat_command()
|
command: str = await config.chat_command()
|
||||||
placeholders = {
|
placeholders = {
|
||||||
"U": username,
|
"C": str(message.author.color),
|
||||||
"M": message,
|
"D": message.author.discriminator,
|
||||||
"C": str(color)
|
"M": message.content,
|
||||||
|
"N": message.author.display_name,
|
||||||
|
"I": str(message.author.id),
|
||||||
|
"U": message.author.name,
|
||||||
}
|
}
|
||||||
for key, value in placeholders.items():
|
for key, value in placeholders.items():
|
||||||
command = command.replace('$.' + key, value)
|
command = command.replace('$.' + key, value)
|
||||||
|
|
Loading…
Reference in a new issue