Skip to content

Commit

Permalink
Add markov chain text generation for arm32
Browse files Browse the repository at this point in the history
It isn't very good
x86/64 builds are broken now since the Dockerfile needs updates
  • Loading branch information
nfaltermeier committed Sep 25, 2022
1 parent ed34da2 commit e217bf0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ disabled_checkpoint
secret-scholars-bot-config.json
src/config.py
secret-scholars-bot-arm32v6.tar.gz
markov.txt

# Created by https://www.toptal.com/developers/gitignore/api/windows,python
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,python
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile-arm32v6
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Based off of https://github.com/minimaxir/gpt-2-cloud-run/blob/master/Dockerfile
FROM arm32v6/python:3.8-alpine
FROM arm32v6/python:3.10-alpine

RUN apk update && apk add gcc musl-dev

WORKDIR /code

RUN pip3 --no-cache-dir install -U py-cord==2.0.0b5 python-dotenv
RUN pip3 --no-cache-dir install -U py-cord python-dotenv markovchain

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

RUN printf "build_time=%s" "'`date -Iseconds`'" > autogen_buildtime.py

Expand Down
2 changes: 2 additions & 0 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import asyncio
import minecraft
import excuse
import markov
import autogen_buildtime

logging.basicConfig(level=logging.INFO)
Expand Down Expand Up @@ -47,6 +48,7 @@ async def on_message(message):
await donut.on_message(message, config, client)
await soup.on_message(message, client, config)
await excuse.on_message(message)
await markov.on_message(message)
if await roll.on_message(message):
return

Expand Down
16 changes: 16 additions & 0 deletions src/markov.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from markovchain.text import MarkovText, ReplyMode

markov = MarkovText()

with open('markov.txt') as fp:
markov.data(fp.read())

def reply(input=''):
return markov(reply_to=input, reply_mode=ReplyMode.END)

cmd = '$mk '

async def on_message(message):
if message.content.startswith(cmd):
prefix = message.content[len(cmd):]
await message.channel.send(reply(prefix))

0 comments on commit e217bf0

Please sign in to comment.