-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuptime.bmod
57 lines (50 loc) · 1.56 KB
/
uptime.bmod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env bash
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2, June 1991.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/gpl-2.0.html>,
# or in pdf format at <http://www.dhampir.no/stuff/private/gpl-2.0.pdf>
# Copyright 2014 - Øyvind 'bolt' Hvidsten <[email protected]>
! ${GHOST:-false} || return 0
if [[ -z "${uptime_death:-}" ]]; then
uptime_death=${UPTIME_LIMIT:-0}
(( uptime_death *= 60 )) || :
if ((uptime_death > 0)) && [[ -n "${UPTIME_RANDOM:-}" ]]; then
(( uptime_death += ( UPTIME_RANDOM * (RANDOM%60) ) )) || :
fi
if (( uptime_death > 0 )); then
sf_stdout "Will die in $uptime_death seconds..."
fi
fi
function uptime_tick
{
(( uptime_death > 0 )) && (( uptime_death < SECONDS )) || return 0
if [[ -n "${UPTIME_MESSAGE:-}" ]]; then
say_all "$UPTIME_MESSAGE"
fi
sf_stdout "Exiting because of \$UPTIME_LIMIT"
clean_exit
}
function uptime_reply
{
local uptime
IFS=" " read -ra uptime <<<"$(uptime)"
reply "${uptime[*]}"
reply "This bot has been running for $(sf_seconds2dayslong $SECONDS)."
}
if [[ -n "$reply" ]]; then
case "$data" in
uptime)
uptime_reply
;;
host)
reply "I am running on $(sf_hostname -f)"
;;
esac
fi