Skip to content

Commit

Permalink
Add donut functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
nfaltermeier committed Oct 15, 2021
1 parent ee6e2be commit beb8143
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ COPY checkpoint checkpoint

RUN pip3 --no-cache-dir install -U tensorflow==1.15.5 gpt-2-simple discord.py python-dotenv

COPY .env src/ secret-scholars-bot-config.json ./

RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

COPY .env src/ secret-scholars-bot-config.json ./

CMD [ "python", "./bot.py" ]
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# About
A discord bot to produce gpt-2 messages on command. The bot can be prompted by including a text after the command name in the discord message.

Designed to be ran in a Docker container.
Designed to be ran in a Docker container. I would recomend removing the `.env` file from the image before pushing the image anywhere.

## Config
`.env`
Expand All @@ -16,7 +16,11 @@ DISCORD_TOKEN=<discord bot token>
],
"checkpoints": {
"<command name>": "<checkpoint model name>"
}
},
"donut-ids": [
<integer discord id 1>
],
"strict-donuts": false
}
```
Command names must be prefixed with a `$` when used in discord for the bot to recognize the command.
Expand Down
3 changes: 3 additions & 0 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
from datetime import datetime, timezone
import gptlib
import donut
import config
import asyncio

Expand All @@ -29,6 +30,8 @@ async def on_message(message):
if message.author == client.user:
return

await donut.on_message(message, conf)

if message.content.startswith('$hello'):
bot_response = await message.channel.send('Hello!')
await asyncio.sleep(300)
Expand Down
10 changes: 10 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,22 @@ def read_or_create_config():
conf['allowed-channels'] = []
elif not type(conf['allowed-channels']) is list:
raise Exception('config file key \'allowed-channels\' should be an array with channel name values')
if not 'donut-ids' in conf:
conf['donut-ids'] = []
elif not type(conf['donut-ids']) is list:
raise Exception('config file key \'donut-ids\' should be an array with discord user IDs to donut')
if not 'strict-donuts' in conf:
conf['strict-donuts'] = false
elif not type(conf['strict-donuts']) is bool:
raise Exception('config file key \'strict-donuts\' should be an bool to delete messages from donut users that block the bot')
return conf
else:
with open(filename, 'w') as f:
conf = {
'checkpoints': {},
'allowed-channels': [],
'donut-ids': [],
'strict-donuts': False
}
json.dump(conf, f)
logging.info(f'{datetime.now(timezone.utc)} Created default config file at \'{filename}\'')
Expand Down
19 changes: 19 additions & 0 deletions src/donut.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import discord
import asyncio

async def on_message(message, conf):
if message.author.id in conf['donut-ids']:
try:
await message.add_reaction("🍩")
await message.add_reaction("🇩")
await message.add_reaction("🇴")
await message.add_reaction("🇳")
await message.add_reaction("🇺")
await message.add_reaction("🇹")
await message.add_reaction("🇸")
except discord.HTTPException as result:
if result.status == 403 and conf['strict-donuts']:
await message.delete()
bot_response = await message.channel.send("Donut be naughty...")
await asyncio.sleep(10)
await bot_response.delete()

0 comments on commit beb8143

Please sign in to comment.