core-keeper-dedicated icon indicating copy to clipboard operation
core-keeper-dedicated copied to clipboard

Feature: Improved Discord messages

Open Micke90s opened this issue 2 years ago • 6 comments

At the moment the server only sends the game id to the configured discord server. I think it would be a nice feature if we could set up a message text.

Heroic hero the world of ${WORLD_NAME} awaits you. Please join ${GAME_ID}

I think the an environment variable DISCORD_STARTUP should work. I am not sure if the placeholders can be replaced automatically, but this should not be a problem to get a good solution.

Also it would be great to get notified if the server goes down by using the handler kill_corekeeperserver

I think it would be a good solution to create a function for the discord call which handles curl call. (A function would be great for further enhancements e.g. “Player joined”, “Player left” if this could be determined by the logs of the server)

What’s your opinion?

Micke90s avatar Jul 16 '23 18:07 Micke90s

I developed the Discord implementation with simplicity in mind. However, I believe that expanding it as per your description would be a good ide.

mattiasghodsian avatar Aug 06 '23 18:08 mattiasghodsian

@mattiasghodsian Thank you for your feedback

I worked on the prototype. Messages for server start, player join and player leave seems to work fine. The message for server shutdown does not work so far.

There are still a few things I have to check. The resolve of the placeholder vars works but it uses eval
(and "eval is evil". So I am looking for a better solution) Also I want to check additional regex for boss down, player down or other key events which could be useful to send to Discord.

I'll keep you updated.

Example core.env file:

WORLD_INDEX=0
WORLD_NAME=CoreKeeperWorld
DISCORD=1
DISCORD_HOOK=https://discord.com/api/webhooks/###########################
DISCORD_MESSAGE_WELCOME=Welcome hero $$user
DISCORD_MESSAGE_BYE=Bye $$user
DISCORD_MESSAGE_STOP=$$WORLD_NAME is shutting down
DISCORD_MESSAGE_START=Brave hero, the world of $$WORLD_NAME awaits you. Feel free to join $$GAME_ID

Micke90s avatar Sep 11 '23 21:09 Micke90s

@Micke90s I also think we should check if any of the DISCORD_MESSAGE_* are empty. we shouldn't send anything (a way to disable any of them). What you think @arguser ?

mattiasghodsian avatar Sep 12 '23 14:09 mattiasghodsian

@mattiasghodsian I think this already should work. All calls of discord_send are within an if which checks the variable.

if [ ! -z "${DISCORD_MESSAGE_BYE}" ]; then discord_send ${DISCORD_MESSAGE_BYE}; fi

I think the message variables should be defined as "opt-in". Only the GameID should always be sent if no welcome message is defined.

Micke90s avatar Sep 15 '23 06:09 Micke90s

@Micke90s i missed that but like you stated a fallback for the GameID should be there.

mattiasghodsian avatar Sep 15 '23 16:09 mattiasghodsian

Short update to the current development.

The pull requests #46 and #47 solved the problem with the missing DISCORD_MESSAGE_BYE. So, start and stop of the server will send messages to discord.

Unfortunately, the latest update of the core keeper server seems to change the login / logout logging so that the current regex is not working anymore.

I will check this and keep you updated.

Micke90s avatar Sep 04 '24 21:09 Micke90s