Make sure temp files get cleaned up.

This commit is contained in:
Storm Dragon
2025-10-24 23:11:01 -04:00
parent 8594e011bc
commit f6990bcc81

8
bot.sh
View File

@@ -51,6 +51,11 @@ if [[ ${#missingCore[@]} -gt 0 ]]; then
exit 1 exit 1
fi fi
# Clean up any leftover temporary files from previous runs
cleanup_old_tempfiles() {
find . -maxdepth 1 -type f -name '.[A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9][A-Za-z0-9]' -mmin +5 -delete 2>/dev/null
}
# Function called on exit to remove the temporary input file. # Function called on exit to remove the temporary input file.
rm_input() { rm_input() {
if [[ -f "$input" ]]; then if [[ -f "$input" ]]; then
@@ -86,6 +91,9 @@ trap rm_input EXIT
# Reconnection loop - keeps bot connected even if connection drops # Reconnection loop - keeps bot connected even if connection drops
reconnectDelay=10 reconnectDelay=10
while true; do while true; do
# Clean up old temp files from previous runs
cleanup_old_tempfiles
# Set up the connection. # Set up the connection.
echo -e "Session started $(date "+%I:%M%p%n %A, %B %d, %Y").\n\nTo gracefully exit, make sure you are in the allow list and send the command exit to the bot.\n\n" | tee -a "$log" echo -e "Session started $(date "+%I:%M%p%n %A, %B %d, %Y").\n\nTo gracefully exit, make sure you are in the allow list and send the command exit to the bot.\n\n" | tee -a "$log"
echo "NICK $nick" > "$input" echo "NICK $nick" > "$input"