Add Dockerfile

This commit is contained in:
2020-12-27 03:31:53 +01:00
parent 8709038492
commit 827f156e08
5 changed files with 78 additions and 9 deletions

19
Dockerfile Normal file
View File

@ -0,0 +1,19 @@
FROM archlinux
# Update Arch and install gcc, python and pip and remove cache
RUN pacman -Syu --noconfirm && pacman --noconfirm -S gcc python python-pip git && yes | pacman -Scc
# Copy requirements for the bot and install them
COPY requirements.txt /tmp/
RUN pip install --disable-pip-version-check --no-cache-dir --requirement /tmp/requirements.txt
# Create user
RUN useradd --create-home botuser
WORKDIR /home/botuser
USER botuser
RUN mkdir -p ~/data
# Copy bot and run
COPY main.py .
CMD ["python", "./main.py"]

6
Pipfile.lock generated
View File

@ -131,10 +131,10 @@
},
"pytz": {
"hashes": [
"sha256:3e6b7dd2d1e0a59084bcee14a17af60c5c562cdc16d828e8eba2e683d3a7e268",
"sha256:5c55e189b682d420be27c6995ba6edce0c0a77dd67bfbe2ae6607134d5851ffd"
"sha256:16962c5fb8db4a8f63a26646d8886e9d769b6c511543557bc84e9569fb9a9cb4",
"sha256:180befebb1927b16f6b57101720075a984c019ac16b1b7575673bea42c6c3da5"
],
"version": "==2020.4"
"version": "==2020.5"
},
"regex": {
"hashes": [

18
docker-compose.yml Normal file
View File

@ -0,0 +1,18 @@
version: "3"
services:
discord-reminder-bot:
#image: thelovinator/discord-reminder-bot
build: .
env_file:
- .env
container_name: discord-reminder-bot
environment:
- BOT_TOKEN=${BOT_TOKEN}
- TIMEZONE=${TIMEZONE}
- LOG_LEVEL=${LOG_LEVEL}
- SQLITE_LOCATION=/data/jobs.sqlite
# restart: unless-stopped
volumes:
- data_folder:/home/botuser/data/
volumes:
data_folder:

17
main.py
View File

@ -18,7 +18,6 @@ bot = commands.Bot(
description="Reminder bot for Discord by TheLovinator#9276",
intents=intents,
)
logging.basicConfig(level=logging.DEBUG)
@bot.event
@ -70,11 +69,12 @@ async def remind(ctx, message_date: str, message_reason: str):
},
)
logging.debug(f"Job id: '{job.id}', name: '{job.name}' and kwargs: '{job.kwargs}'")
message = f"Hello {ctx.message.author.name}, I will notify you at:\n" \
f"**{remove_timezone_from_date}**\n" \
message = (
f"Hello {ctx.message.author.name}, I will notify you at:\n"
f"**{remove_timezone_from_date}**\n"
f"With message:\n**{message_reason}**. "
logging.debug(f"Message we sent back to user in Discord:\n"
f"{message}")
)
logging.debug(f"Message we sent back to user in Discord:\n" f"{message}")
await ctx.send(message)
@ -91,6 +91,13 @@ if __name__ == "__main__":
bot_token = os.getenv("BOT_TOKEN")
log_level = os.getenv(key="LOG_LEVEL", default="INFO")
logging.basicConfig(level=logging.getLevelName(log_level))
logging.info(
f"\nsqlite_location = {sqlite_location}\nconfig_timezone = {config_timezone}\n"
f"bot_token = {bot_token}\nlog_level = {log_level}"
)
# Advanced Python Scheduler
jobstores = {"default": SQLAlchemyJobStore(url=f"sqlite://{sqlite_location}")}
job_defaults = {"coalesce": True}

25
requirements.txt Normal file
View File

@ -0,0 +1,25 @@
#
# These requirements were autogenerated by pipenv
# To regenerate from the project's Pipfile, run:
#
# pipenv lock --requirements
#
-i https://pypi.org/simple
aiohttp==3.6.3; python_full_version >= '3.5.3'
apscheduler==3.6.3
async-timeout==3.0.1; python_full_version >= '3.5.3'
attrs==20.3.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
chardet==3.0.4
dateparser==1.0.0
discord.py==1.5.1
idna==2.10; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
multidict==4.7.6; python_version >= '3.5'
python-dateutil==2.8.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
python-dotenv==0.15.0
pytz==2020.5
regex==2020.11.13
six==1.15.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
sqlalchemy==1.3.22
tzlocal==2.1
yarl==1.5.1; python_version >= '3.5'