Skip to content

Commit

Permalink
add custom-alert command
Browse files Browse the repository at this point in the history
  • Loading branch information
MicLieg committed Apr 24, 2024
1 parent ad2f815 commit 0f709af
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lgsm/modules/alert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions lgsm/modules/command_custom_alert.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion lgsm/modules/core_getopt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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[@]}")
Expand Down
5 changes: 5 additions & 0 deletions lgsm/modules/core_modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions linuxgsm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0f709af

Please sign in to comment.