mirror of
https://github.com/miaowware/qrm2.git
synced 2024-09-27 14:26:35 -04:00
updates based on PR review, and new code in quickbot
This commit is contained in:
parent
7bf5071bb9
commit
0418ae16a6
12
Dockerfile
12
Dockerfile
@ -3,7 +3,7 @@ FROM python:3-alpine
|
||||
COPY . /app
|
||||
WORKDIR /app
|
||||
|
||||
VOLUME /app/data
|
||||
ENV PYTHON_BIN python3
|
||||
|
||||
RUN \
|
||||
echo "**** install build packages ****" && \
|
||||
@ -13,11 +13,11 @@ RUN \
|
||||
gcc \
|
||||
libxml2-dev \
|
||||
libxslt-dev \
|
||||
openssl-dev \
|
||||
libressl-dev \
|
||||
python3-dev && \
|
||||
echo "**** install runtime packages ****" && \
|
||||
apk add --no-cache \
|
||||
openssl \
|
||||
libressl \
|
||||
py3-lxml \
|
||||
py3-pip \
|
||||
python3 && \
|
||||
@ -30,8 +30,6 @@ RUN \
|
||||
rm -rf \
|
||||
/root/.cache \
|
||||
/tmp/* \
|
||||
/var/cache/apk/* && \
|
||||
echo "**** prepare scripts ****" && \
|
||||
chmod +x docker-run.sh
|
||||
/var/cache/apk/*
|
||||
|
||||
CMD ["sh", "docker-run.sh", "--pass-errors"]
|
||||
CMD ["/bin/sh", "run.sh", "--pass-errors", "--no-botenv"]
|
||||
|
11
README-DOCKER.md
Normal file
11
README-DOCKER.md
Normal file
@ -0,0 +1,11 @@
|
||||
A sample `docker-compose.yml` file:
|
||||
|
||||
```yaml
|
||||
version: '3'
|
||||
services:
|
||||
bot:
|
||||
image: "classabbyamp/discord-qrm-bot:latest"
|
||||
container_name: "qrmbot"
|
||||
volumes:
|
||||
- "./data:/app/data:rw"
|
||||
```
|
20
README.md
20
README.md
@ -4,6 +4,26 @@ A discord bot with ham radio functionalities.
|
||||
|
||||
An independent rewrite of qrmbot-discord.
|
||||
|
||||
## Running
|
||||
|
||||
### Docker
|
||||
|
||||
See [README-DOCKER.md](./README-DOCKER.md)
|
||||
|
||||
### Without Docker
|
||||
|
||||
Prep the environment. For more information on extra options, see the [quick-bot-no-pain Makefile documentation](https://github.com/0x5c/quick-bot-no-pain/blob/master/docs/makefile.md).
|
||||
|
||||
```
|
||||
$ make install
|
||||
```
|
||||
|
||||
Run. For more information on options, see the [quick-bot-no-pain run.sh documentation](https://github.com/0x5c/quick-bot-no-pain/blob/master/docs/run.sh.md).
|
||||
|
||||
```
|
||||
$ run.sh
|
||||
```
|
||||
|
||||
## Copyright
|
||||
|
||||
Copyright (C) 2019 Abigail Gold, 0x5c
|
||||
|
@ -1,7 +1,7 @@
|
||||
version: '3'
|
||||
services:
|
||||
bot:
|
||||
image: "classabbyamp/discord-qrm-bot:latest"
|
||||
build: .
|
||||
container_name: "qrmbot"
|
||||
volumes:
|
||||
- "./data:/app/data:rw"
|
||||
|
@ -1,49 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# A wrapper script for painless discord bots.
|
||||
# v1.0.0
|
||||
# Copyright (c) 2019 0x5c
|
||||
# Released under the terms of the MIT license.
|
||||
# Part of:
|
||||
# https://github.com/0x5c/quick-bot-no-pain
|
||||
|
||||
|
||||
# Argument handling # ? TODO: Argument passing ?
|
||||
if [[ $1 == '--pass-errors' ]]; then
|
||||
_PASS_ERRORS=1
|
||||
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
|
||||
python3 main.py
|
||||
err=$?
|
||||
_message="$0: The bot exited with [$err]"
|
||||
code_handling
|
||||
done
|
39
run.sh
39
run.sh
@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
#!/bin/sh
|
||||
|
||||
# A wrapper script for painless discord bots.
|
||||
# v1.0.0
|
||||
# v1.2.0
|
||||
# Copyright (c) 2019 0x5c
|
||||
# Released under the terms of the MIT license.
|
||||
# Part of:
|
||||
@ -9,13 +9,34 @@
|
||||
|
||||
|
||||
# If $BOTENV is not defined, default to 'botenv'
|
||||
if [[ -z ${BOTENV+x} ]]; then
|
||||
if [ -z "$BOTENV" ]; then
|
||||
BOTENV='botenv'
|
||||
fi
|
||||
|
||||
# Argument handling # ? TODO: Argument passing ?
|
||||
if [[ $1 == '--pass-errors' ]]; then
|
||||
|
||||
# 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.7'
|
||||
if [ $_NO_BOTENV -eq 1 -a -z "$PYTHON_BIN" ]; then
|
||||
PYTHON_BIN='python3.7'
|
||||
fi
|
||||
|
||||
|
||||
@ -31,7 +52,7 @@ code_handling() {
|
||||
return # The bot whishes to be restarted (returns to the loop).
|
||||
;;
|
||||
*)
|
||||
if [[ $_PASS_ERRORS -eq 0 ]]; then # The bot crashed and:
|
||||
if [ $_PASS_ERRORS -eq 0 ]; then # The bot crashed and:
|
||||
echo "$_message: restarting"
|
||||
return # ...we should return to the loop to restart it.
|
||||
else
|
||||
@ -47,7 +68,11 @@ echo "$0: Starting bot..."
|
||||
|
||||
# The loop
|
||||
while true; do
|
||||
./$BOTENV/bin/python3 main.py
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user