mirror of
https://github.com/miaowware/qrm2.git
synced 2025-02-03 09:44:07 -05:00
commit
4d86c2d9be
1
.dockerignore
Normal file
1
.dockerignore
Normal file
@ -0,0 +1 @@
|
||||
data/
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,6 +7,7 @@ cty.json
|
||||
cty.zip
|
||||
|
||||
botenv/
|
||||
data/
|
||||
|
||||
|
||||
#########################################################
|
||||
|
35
Dockerfile
Normal file
35
Dockerfile
Normal file
@ -0,0 +1,35 @@
|
||||
FROM python:3-alpine
|
||||
|
||||
COPY . /app
|
||||
WORKDIR /app
|
||||
|
||||
ENV PYTHON_BIN python3
|
||||
|
||||
RUN \
|
||||
echo "**** install build packages ****" && \
|
||||
apk add --no-cache --virtual=build-dependencies \
|
||||
g++ \
|
||||
git \
|
||||
gcc \
|
||||
libxml2-dev \
|
||||
libxslt-dev \
|
||||
libressl-dev \
|
||||
python3-dev && \
|
||||
echo "**** install runtime packages ****" && \
|
||||
apk add --no-cache \
|
||||
libressl \
|
||||
py3-lxml \
|
||||
py3-pip \
|
||||
python3 && \
|
||||
echo "**** install pip packages ****" && \
|
||||
pip3 install -U pip setuptools wheel && \
|
||||
pip3 install -r requirements.txt && \
|
||||
echo "**** clean up ****" && \
|
||||
apk del --purge \
|
||||
build-dependencies && \
|
||||
rm -rf \
|
||||
/root/.cache \
|
||||
/tmp/* \
|
||||
/var/cache/apk/*
|
||||
|
||||
CMD ["/bin/sh", "run.sh", "--pass-errors", "--no-botenv"]
|
49
Makefile
49
Makefile
@ -1,31 +1,24 @@
|
||||
# A quick installation script for discord bots.
|
||||
#
|
||||
# A quick installation script for painless discord bots.
|
||||
# v1.1.0
|
||||
# Copyright (c) 2019 0x5c
|
||||
# Released under the terms of the MIT license.
|
||||
#
|
||||
# https://github.com/0x5c/discord.py-quickinstall
|
||||
# Part of:
|
||||
# https://github.com/0x5c/quick-bot-no-pain
|
||||
|
||||
|
||||
#### Setup ####
|
||||
.DEFAULT_GOAL := help
|
||||
|
||||
## Variables ##
|
||||
### Variables ###
|
||||
# Those are the defaults; they can be over-ridden if specified
|
||||
# at en environment level or as 'make' arguments.
|
||||
BOTENV ?= botenv
|
||||
PY3DOT ?= 7
|
||||
PIP_OUTPUT ?= q
|
||||
PYTHON_BIN ?= python3.7
|
||||
PIP_OUTPUT ?= -q
|
||||
|
||||
|
||||
# Define some rules as phony
|
||||
.PHONY: help install clean onlyenv
|
||||
|
||||
|
||||
|
||||
#### Targets ####
|
||||
|
||||
## Support targets ##
|
||||
### Support targets ###
|
||||
|
||||
.PHONY: help
|
||||
help:
|
||||
@echo ""
|
||||
@echo "\033[97m>>>>>> Default dummy target <<<<<<"
|
||||
@ -35,16 +28,17 @@ help:
|
||||
@echo "\033[0m"
|
||||
|
||||
|
||||
## Actual install/setup targets ##
|
||||
### Actual install/setup targets ###
|
||||
|
||||
# Main install target
|
||||
.PHONY: install
|
||||
install: $(BOTENV)/req_done options.py keys.py
|
||||
|
||||
# Virual environment setup
|
||||
$(BOTENV)/success:
|
||||
ifneq ("$(wildcard ./$(BOTENV).)",)
|
||||
@echo "\033[94m--> Creating the virtual environment...\033[0m"
|
||||
@python3.$(PY3DOT) -m venv $(BOTENV)
|
||||
@$(PYTHON_BIN) -m venv $(BOTENV)
|
||||
@touch $(BOTENV)/success
|
||||
endif
|
||||
|
||||
@ -52,17 +46,21 @@ endif
|
||||
$(BOTENV)/req_done: requirements.txt $(BOTENV)/success
|
||||
@echo "\033[34;1m--> Installing the dependencies...\033[0m"
|
||||
@. $(BOTENV)/bin/activate; \
|
||||
pip install -${PIP_OUTPUT} -U pip setuptools wheel; \
|
||||
pip install -${PIP_OUTPUT} -U -r requirements.txt
|
||||
pip install ${PIP_OUTPUT} -U pip setuptools wheel; \
|
||||
pip install ${PIP_OUTPUT} -U -r requirements.txt
|
||||
@touch $(BOTENV)/req_done
|
||||
|
||||
data:
|
||||
mkdir data
|
||||
|
||||
# Copying templates
|
||||
options.py keys.py:
|
||||
options.py keys.py: | data
|
||||
@echo "\033[34;1m--> Copying template files...\033[0m"
|
||||
@cp -nv ./templates/template_$@ ./$@
|
||||
@touch ./$@
|
||||
@cp -nv ./templates/template_$@ ./data/$@
|
||||
@touch ./data/$@
|
||||
|
||||
# Deletes the python cache and the virtual environment
|
||||
.PHONY: clean
|
||||
clean:
|
||||
@echo "\033[34;1m--> Removing python cache files...\033[0m"
|
||||
rm -rf __pycache__
|
||||
@ -70,8 +68,9 @@ clean:
|
||||
rm -rf $(BOTENV)
|
||||
|
||||
|
||||
## Dev targets ##
|
||||
### Dev targets ###
|
||||
|
||||
|
||||
## Weird dev targets ##
|
||||
### Special targets ###
|
||||
.PHONY: onlyenv
|
||||
onlyenv: $(BOTENV)/success
|
||||
|
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
|
||||
|
7
docker-compose.yml
Normal file
7
docker-compose.yml
Normal file
@ -0,0 +1,7 @@
|
||||
version: '3'
|
||||
services:
|
||||
bot:
|
||||
build: .
|
||||
container_name: "qrmbot"
|
||||
volumes:
|
||||
- "./data:/app/data:rw"
|
4
main.py
4
main.py
@ -15,8 +15,8 @@ from discord.ext import commands, tasks
|
||||
|
||||
import info
|
||||
|
||||
import options as opt
|
||||
import keys
|
||||
from data import options as opt
|
||||
from data import keys
|
||||
|
||||
|
||||
# --- Settings ---
|
||||
|
41
run.sh
41
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
|
||||
_PASS_ERRORS=1
|
||||
|
||||
# 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