This repository has been archived by the owner on Nov 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run-owl.sh
executable file
·79 lines (67 loc) · 1.76 KB
/
run-owl.sh
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh
# A wrapper script for painless discord bots.
# v1.2.0
# Copyright (c) 2019 0x5c
# Released under the terms of the MIT license.
# Part of:
# https://github.com/0x5c/quick-bot-no-pain
# If $BOTENV is not defined, default to 'botenv'
if [ -z "$BOTENV" ]; then
BOTENV='botenv'
fi
# Argument handling
_PASS_ERRORS=0
_NO_BOTENV=0
while [ ! -z "$1" ]; do
case $1 in
--pass-errors)
_PASS_ERRORS=1
;;
--no-botenv)
_NO_BOTENV=1
;;
--)
shift
break
;;
esac
shift
done
# If $PYTHON_BIN is not defined, default to 'python3.9'
if [ $_NO_BOTENV -eq 1 -a -z "$PYTHON_BIN" ]; then
PYTHON_BIN='python3.9'
fi
# A function called when the bot exits to decide what to do
code_handling() {
case $err in
0)
echo "$_message: exiting"
exit 0 # The bot whishes to stay alone.
;;
42)
echo "$_message: restarting"
return # The bot whishes to be restarted (returns to the loop).
;;
*)
if [ $_PASS_ERRORS -eq 0 ]; then # The bot crashed and:
echo "$_message: restarting"
return # ...we should return to the loop to restart it.
else
echo "$_message: exiting (--pass-errors)"
exit $err # ...we should just exit and pass the code to our parent (probably a daemon/service manager).
fi
;;
esac
}
echo "$0: Starting bot..."
# The loop
while true; do
if [ $_NO_BOTENV -eq 1 ]; then
"$PYTHON_BIN" main.py $@
else
./$BOTENV/bin/python3 main.py $@
fi
err=$?
_message="$0: The bot exited with [$err]"
code_handling
done