DJWoodZ / Satisfactory-Discord-Bot

A Discord bot that posts Satisfactory Dedicated Server status information such as online players.
MIT License
12 stars 2 forks source link

Request feature: purge messages on request /purge lines(0-100) #5

Closed LucaPierino closed 1 year ago

LucaPierino commented 1 year ago

Hello, I think it would be interesting if the bot could execute the /purge command upon request. Sometimes the bot can write more than 100 messages in a day, and the chat fills up very quickly. Do you think it's something in line with your project?

DJWoodZ commented 1 year ago

Thank you for your request @LucaPierino.

I've attempted to implement this in a way that is in keeping with the existing, fully automatic nature of the bot. This will save you from having to remember to run any commands manually.

I've added a new environment variable which hopefully achieves what you are after: SATISFACTORY_BOT_PURGE_DISCORD_CHANNEL_AFTER_LINES. You can use this in addition to or instead of the existing SATISFACTORY_BOT_PURGE_DISCORD_CHANNEL_AFTER_DAYS environment variable.

For example, if you would like the bot to only purge its messages after a number of messages have been created in the channel (say 50), but you'd otherwise like to keep messages no matter when they were created, you can use a blank value for SATISFACTORY_BOT_PURGE_DISCORD_CHANNEL_AFTER_DAYS, like this:

SATISFACTORY_BOT_PURGE_DISCORD_CHANNEL_AFTER_DAYS=
SATISFACTORY_BOT_PURGE_DISCORD_CHANNEL_AFTER_LINES=50

If you would like the bot to delete its messages when either condition is met, for example you'd like it to delete messages that were created 7 or more days ago or if number of messages is greater than 50, you can do so like this:

SATISFACTORY_BOT_PURGE_DISCORD_CHANNEL_AFTER_DAYS=7
SATISFACTORY_BOT_PURGE_DISCORD_CHANNEL_AFTER_LINES=50

Hopefully this achieves what you had in mind. I will leave this on the 5-request-feature-purge-messages-on-request-purge-lines0-100 branch until I've tested it more thoroughly. If you get the opportunity to test it, please let me know how you get on.

LucaPierino commented 1 year ago

Hi @DJWoodZ thank you dedication to the satisfactory community providing this usefull bot.

I have restarted the bot with these .env.local settings

SATISFACTORY_BOT_PURGE_DISCORD_CHANNEL_AFTER_DAYS=2
SATISFACTORY_BOT_PURGE_DISCORD_CHANNEL_AFTER_LINES=10

This is the output on pm2 logs... On discord i have a lot of messages. first messages starts 4 days ago.

PM2                         | Stopping app:satisfactory-discord-bot id:1
1|satisfactory-discord-bot  | 2023-05-13T12:02:43: Logging out
PM2                         | App [satisfactory-discord-bot:1] exited with code [0] via signal [SIGINT]
PM2                         | pid=355909 msg=process killed
PM2                         | App [satisfactory-discord-bot:1] starting in -fork mode-
PM2                         | App [satisfactory-discord-bot:1] online
1|satisfactory-discord-bot  | 2023-05-13T12:02:44: Poll interval: 120000 milliseconds
1|satisfactory-discord-bot  | 2023-05-13T12:02:44: Found: ./db.json
1|satisfactory-discord-bot  | 2023-05-13T12:02:45: First purge will be Sun May 14 2023 03:00:00 GMT+0200 (Central European Summer Time)
1|satisfactory-discord-bot  | 2023-05-13T12:02:45: Updating...
1|satisfactory-discord-bot  | 2023-05-13T12:02:45: Log file open 05/12/23 22:05:11

Can I help you in any way to provide you with more information to understand if it works?

DJWoodZ commented 1 year ago

Thank you. The purge is performed once every 24 hours. The specific hour is controlled by the SATISFACTORY_BOT_PURGE_DISCORD_CHANNEL_HOUR environment variable which is expressed as UTC. The bot will only delete messages if it is running at that time. I.e. the bot will not purge messages when it first starts up.

Your log output shows that the first purge will take place at Sun May 14 2023 03:00:00 GMT+0200 (Central European Summer Time), so after that time you should see if and how it is working. Message deletion isn't always immediate. It can take a few moments for the messages to actually disappear. No messages should be deleted before that time though.

If you are keen to test it sooner, you can try changing the SATISFACTORY_BOT_PURGE_DISCORD_CHANNEL_HOUR and restarting the bot, but there is no rush. I plan to run the bot from this branch for a few days to check it works as expected. 🙂

LucaPierino commented 1 year ago

Hello @DJWoodZ .. I tried the release and didn't encounter any issues. It deleted the messages correctly.

have a question to ask you: if I invite the bot to another Discord server, will the bot be able to delete messages?

Ciao Luca

DJWoodZ commented 1 year ago

That's great. Thank you.

The bot can post to multiple servers and channels, but it will only delete messages from a single channel on a single server. Maybe you could disable the purging option of this bot and use an auto-deletion bot to keep each Discord server tidy instead?