add custom-alert command

This commit is contained in:
MicLieg 2024-02-03 20:05:52 +01:00 committed by MicLieg
parent ad2f81599a
commit 0f709af84e
5 changed files with 56 additions and 1 deletions

View File

@ -27,6 +27,17 @@ fn_alert_log() {
} | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | tee -a "${alertlog}" > /dev/null 2>&1
}
fn_alert_custom() {
fn_script_log_info "Sending custom alert: Custom alert from ${selfname}."
alertaction="${customalerttitle}"
alertemoji="📢"
alertsound="1"
alertmessage="${customalertmessage}"
# Green
alertcolourhex="#6600CC"
alertcolourdec="6684876"
}
fn_alert_test() {
fn_script_log_info "Sending alert: Testing LinuxGSM Alert. No action to be taken"
alertaction="Tested"
@ -206,6 +217,8 @@ elif [ "${alert}" == "monitor-session" ]; then
fn_alert_monitor_session
elif [ "${alert}" == "monitor-query" ]; then
fn_alert_monitor_query
elif [ "${alert}" == "custom" ]; then
fn_alert_custom
elif [ "${alert}" == "test" ]; then
fn_alert_test
elif [ "${alert}" == "update" ]; then

View File

@ -0,0 +1,35 @@
#!/bin/bash
# LinuxGSM command_custom_alert.sh module
# Author: Daniel Gibbs
# Contributors: http://linuxgsm.com/contrib
# Website: https://linuxgsm.com
# Description: Sends a custom alert.
commandname="CUSTOM-ALERT"
commandaction="Custom Alert"
moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
fn_firstcommand_set
check.sh
if [ -n "${userinput2}" ]; then
customalertmessage="${userinput2}"
else
fn_print_header
fn_print_information_nl "Send a custom alert."
echo ""
customalertmessage=$(fn_prompt_message "alert message: ")
fi
# optional: custom alert title
if [ -n "${userinput3}" ]; then
customalerttitle="${userinput3}"
else
customalerttitle="Custom Alert"
fi
info_game.sh
alert="custom"
alert.sh
core_exit.sh

View File

@ -19,6 +19,7 @@ cmd_details=("dt;details" "command_details.sh" "Display server information.")
cmd_postdetails=("pd;postdetails" "command_postdetails.sh" "Post details to termbin.com (removing passwords).")
cmd_backup=("b;backup" "command_backup.sh" "Create backup archives of the server.")
cmd_update_linuxgsm=("ul;update-lgsm;uf;update-modules" "command_update_linuxgsm.sh" "Check and apply any LinuxGSM updates.")
cmd_custom_alert=("ca;custom-alert" "command_custom_alert.sh" "Send a customizable alert.")
cmd_test_alert=("ta;test-alert" "command_test_alert.sh" "Send a test alert.")
cmd_monitor=("m;monitor" "command_monitor.sh" "Check server status and restart if crashed.")
cmd_skeleton=("sk;skeleton" "command_skeleton.sh" "Create a skeleton directory.")
@ -60,7 +61,7 @@ cmd_dev_clear_modules=("cm;clear-modules" "command_dev_clear_modules.sh" "Delete
### Set specific opt here.
currentopt=("${cmd_start[@]}" "${cmd_stop[@]}" "${cmd_restart[@]}" "${cmd_monitor[@]}" "${cmd_test_alert[@]}" "${cmd_details[@]}" "${cmd_postdetails[@]}" "${cmd_skeleton[@]}")
currentopt=("${cmd_start[@]}" "${cmd_stop[@]}" "${cmd_restart[@]}" "${cmd_monitor[@]}" "${cmd_custom_alert[@]}" "${cmd_test_alert[@]}" "${cmd_details[@]}" "${cmd_postdetails[@]}" "${cmd_skeleton[@]}")
# Update LinuxGSM.
currentopt+=("${cmd_update_linuxgsm[@]}")

View File

@ -96,6 +96,11 @@ command_postdetails.sh() {
fn_fetch_module
}
command_custom_alert.sh() {
modulefile="${FUNCNAME[0]}"
fn_fetch_module
}
command_test_alert.sh() {
modulefile="${FUNCNAME[0]}"
fn_fetch_module

View File

@ -48,6 +48,7 @@ configdirserver="${configdir}/${gameservername}"
configdirdefault="${lgsmdir}/config-default"
userinput="${1}"
userinput2="${2}"
userinput3="${3}"
## GitHub Branch Select
# Allows for the use of different function files