From 973d9ee7cfaf9b826dfdf7c3d9e5df50995c07bd Mon Sep 17 00:00:00 2001 From: askiiart Date: Mon, 28 Aug 2023 21:00:35 -0500 Subject: [PATCH] Containerize it --- .env.example | 16 ++++++++++++++ Dockerfile | 9 ++++++++ README.md | 56 ++++++++++++++++++++++++++++++++++++++--------- build-and-push.sh | 9 ++++++++ generate.py | 2 +- main.py | 30 +++++++++++++------------ 6 files changed, 97 insertions(+), 25 deletions(-) create mode 100644 .env.example create mode 100644 Dockerfile create mode 100644 build-and-push.sh diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..309f1bf --- /dev/null +++ b/.env.example @@ -0,0 +1,16 @@ +BOT_TOKEN=9198675309 +NEURAL=Bearer v3498347598347523983497 +POE_TOKEN=023423840823 +OPENAI_EMAIL=email@example.com +OPENAI_PASS=password1234 +GUILD_ID=1234567890 +BOT_ID=1234567890 +MAGIC_ITEM_FORUM=1234567890 +RACE_FORUM=1234567890 +SUBCLASS_FORUM=1234567890 +LOCATION_FORUM=1234567890 +MONSTER_FORUM=1234567890 +NPC_FORUM=1234567890 +OTHER_FORUM=1234567890 +LOG_CHANNEL=1234567890 +AUTOGEN=true \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6d2d47b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM python:alpine +WORKDIR /data +COPY ./requirements.txt /data/ +RUN pip3 install -r requirements.txt +COPY ./neural.py /data/ +COPY ./generate.py /data/ +COPY ./itemname.py /data/ +COPY ./main.py /data/ +CMD python3 main.py \ No newline at end of file diff --git a/README.md b/README.md index 22c9345..28caa51 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,27 @@ - # AlwaysDungeons + 24-hour AI DND generation. ## Environment Variables -|KEY|DESCRIPTION| -|--|--| -|DISCORDBOT|The discord bot's token.| -|NEURAL|Your NeuralLove api key. Should look like "Bearer v...."| -|PB|Your Quora api key. You'll sign into Quora on your browser, go into your Inspect Element -> Storage -> Quora.com cookies, and copy the m-b cookie. Used to access poe.com's ChatGPT bot.| -|EMAIL|The email used with your ChatGPT account. Used as a fallback to poe.com, and not required to fill in.| -|PASS|The password used with your ChatGPT account. Used as a fallback to poe.com, and not required to fill in. -| - +| KEY | DESCRIPTION | +| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| BOT_TOKEN | The discord bot's token. | +| NEURAL | Your NeuralLove api key. Should look like "Bearer v...." | +| POE_TOKEN | Your Quora api key. You'll sign into Quora on your browser, go into your Inspect Element -> Storage -> Quora.com cookies, and copy the m-b cookie. Used to access poe.com's ChatGPT bot. | +| OPENAI_EMAIL | OPTIONAL, currently not implemented. The email used with your ChatGPT account. Used as a fallback to poe.com, and not required to fill in. | +| OPENAI_PASS | OPTIONAL, currently not implemented. The password used with your ChatGPT account. Used as a fallback to poe.com, and not required to fill in. | +| GUILD_ID | The ID of the server the bot is in. | +| BOT_ID | The ID of the bot itself. | +| MAGIC_ITEM_FORUM | The channel ID of the magic item forum | +| RACE_FORUM | The channel ID of the race forum | +| SUBCLASS_FORUM | The channel ID of the subclass forum | +| LOCATION_FORUM | The channel ID of the location forum | +| MONSTER_FORUM | The channel ID of the monster forum | +| NPC_FORUM | The channel ID of the NPC forum | +| OTHER_FORUM | The channel ID of the other forum | +| LOG_CHANNEL | The channel ID of the log channel | +| AUTOGEN | Whether or not the bot should automatically generate content. (true/false) | ## Functionality @@ -33,3 +42,30 @@ magicForum, raceForum, subclassForum, locationForum, monsterForum, npcForum, and logChannel is the channel that error messages and other announcements from the bot are posted in. Be sure to put this channel in a publicly visible place; it announces when a user's request is being fulfilled. autogen enables or disables the bot's automatic production of homebrew content. If this is not desired, change autogen to False. + +## Running the bot + +### Docker + +Example `docker run`: + +```bash +docker run -d -v /path/to/.env:/data/.env docker.askiiart.net/askiiart/createrepo_c +``` + +Example `docker-compose.yml`: + +```yaml +version: '3.7' +services: + hugo: + image: docker.askiiart.net/askiiart/discord-always-dungeons + volumes: + - /path/to/.env:/data/.env +``` + +## Build the Docker image + +Just run `docker build .` + +Alternatively, you can just run `./build-and-push.sh`, which will build the image and push it to the registry. Just make sure to fix the variables before running it. diff --git a/build-and-push.sh b/build-and-push.sh new file mode 100644 index 0000000..fc600e3 --- /dev/null +++ b/build-and-push.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -e +ORG="askiiart" +NAME="discord-always-dungeons" +ID=$(docker build . -q) + +# Could just do -t on the build, but this makes it easier to expand if needed. +docker tag ${ID} ${ORG}/${NAME}:latest +docker push ${ORG}/${NAME}:latest diff --git a/generate.py b/generate.py index 4cfe3cb..5746646 100644 --- a/generate.py +++ b/generate.py @@ -1,6 +1,6 @@ from poe_api_wrapper import PoeApi import os -client = PoeApi(os.environ['PB']) +client = PoeApi(os.environ['POE_TOKEN']) import asyncio #from revChatGPT.V1 import AsyncChatbot diff --git a/main.py b/main.py index 9971b82..4cc533f 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ import os - +from dotenv import load_dotenv import discord import generate import neural @@ -11,22 +11,24 @@ from discord.ext import tasks import keep_alive from keep_alive import keep_alive +load_dotenv() + client = discord.Client(intents=discord.Intents.all()) tree = app_commands.CommandTree(client) queue = [] -guildID = 1081397933276155977 -botID = 1144041248303366314 -magicForum = 1144040531240964256 -raceForum = 1144075835217825868 -subclassForum = 1144075898870579290 -locationForum = 1144075950749925457 -monsterForum = 1144081512724176947 -npcForum = 1144425240018034878 -otherForum = 1144426051720724602 -logChannel = 1144064721922834582 -autogen = True +guildID = os.environ['GUILD_ID'] +botID = os.environ['BOT_ID'] +magicForum = os.environ['MAGIC_ITEM_FORUM'] +raceForum = os.environ['RACE_FORUM'] +subclassForum = os.environ['SUBCLASS_FORUM'] +locationForum = os.environ['LOCATION_FORUM'] +monsterForum = os.environ['MONSTER_FORUM'] +npcForum = os.environ['NPC_FORUM'] +otherForum = os.environ['OTHER_FORUM'] +logChannel = os.environ['LOG_CHANNEL'] +autogen = True if os.environ('AUTOGEN') == 'true' else False @client.event async def on_message(message): @@ -177,5 +179,5 @@ async def on_ready(): keep_alive() -my_secret = os.environ['DISCORDBOT'] -client.run(my_secret) +bot_token = os.environ['BOT_TOKEN'] +client.run(bot_token)