It's a fork now

Most notably, I've moved a bunch of options to a
separate config file and added the ability to not
use a CW by leaving that field blank. Plus updated
the README
This commit is contained in:
will 2024-05-20 16:28:48 -06:00
parent 2618b264f3
commit 2c6858e306
5 changed files with 65 additions and 15 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
*.json *.json
*.py[oc] *.py[oc]
/config__.py
/secrets__.py /secrets__.py
/venv /venv
/cron.log /cron.log

15
config__.default.py Normal file
View file

@ -0,0 +1,15 @@
model_file = "model.json"
# Path to the model generated by import_misskey.py
# I had to use absolute paths to get the cronjob to work (ie. /path/to/file.json instead of just file.json)
instance_url = "example.com"
# Domain of the instance the bot is on, eg. botsin.space
cw = "markov bot generated post"
# Content warning to put on the bot's posts
character_limit = 80
# Maximum length of the posts
log_length = 96
# Currently unused

View file

@ -3,21 +3,25 @@ import sys
import requests import requests
import secrets__ import secrets__
import config__
model_f = open("model.json") model_f = open(config__.model_file)
model = chain.Text.from_json(model_f.read()) model = chain.Text.from_json(model_f.read())
generated = False generated = False
text = None text = None
while not generated: while not generated:
text = model.make_short_sentence(80, tries=900, min_words=3) text = model.make_short_sentence(config__.character_limit, tries=900, min_words=3)
generated = text is not None generated = text is not None
text = text.replace('@','@').replace('#','#') text = text.replace('@','@').replace('#','#')
print(text) print(text)
requests.post("https://brain.d.on-t.work/api/notes/create", json={ apicreate = "https://" + config__.instance_url + "/api/notes/create"\
if(config__.cw == ""):
requests.post(apicreate, json={
'i': secrets__.TOKEN, 'i': secrets__.TOKEN,
'visibility': 'home', 'visibility': 'home',
@ -25,5 +29,15 @@ requests.post("https://brain.d.on-t.work/api/notes/create", json={
'noExtractHashtags': True, 'noExtractHashtags': True,
'text': text, 'text': text,
'cw': 'markov chain generated post' })
else:
requests.post(apicreate, json={
'i': secrets__.TOKEN,
'visibility': 'home',
'noExtractMentions': True,
'noExtractHashtags': True,
'text': text,
'cw': config__.cw
}) })

25
readme.md Normal file
View file

@ -0,0 +1,25 @@
Basic Markov bot for Misskey. Fork of https://activitypub.software/kopper/markov
## Setup
- Install dependencies:
```
pip install -r requirements.txt
python -m spacy download en_core_web_sm
```
- Export your notes from Misskey and generate a model:
```
python import-misskey.py notes-XXXX-XX-XX-XX-XX-XX.json
```
- Generate an API token for the bot account and use it here:
```
echo "TOKEN='yourtoken'" > secrets__.py
```
- Copy `config__.default.py` to `config__.py` and edit as needed
## Usage
```
python generate.py
```
Point a cronjob to this file to post automatically

View file

@ -1,5 +0,0 @@
pip install -r requirements.txt
python -m spacy download en_core_web_sm
python import-misskey.py notes-XXXX-XX-XX-XX-XX-XX.json
echo "TOKEN=''" > secrets__.py
python generate.py