From 2c6858e306976a731b03eae8dc7a0fe6fbc5cee8 Mon Sep 17 00:00:00 2001 From: will Date: Mon, 20 May 2024 16:28:48 -0600 Subject: [PATCH] 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 --- .gitignore | 1 + config__.default.py | 15 +++++++++++++++ generate.py | 34 ++++++++++++++++++++++++---------- readme.md | 25 +++++++++++++++++++++++++ readme.txt | 5 ----- 5 files changed, 65 insertions(+), 15 deletions(-) create mode 100644 config__.default.py create mode 100644 readme.md delete mode 100644 readme.txt diff --git a/.gitignore b/.gitignore index 21d30b6..0195375 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.json *.py[oc] +/config__.py /secrets__.py /venv /cron.log diff --git a/config__.default.py b/config__.default.py new file mode 100644 index 0000000..0ed45fa --- /dev/null +++ b/config__.default.py @@ -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 \ No newline at end of file diff --git a/generate.py b/generate.py index a90c43e..fd4803d 100644 --- a/generate.py +++ b/generate.py @@ -3,27 +3,41 @@ import sys import requests import secrets__ +import config__ -model_f = open("model.json") +model_f = open(config__.model_file) model = chain.Text.from_json(model_f.read()) generated = False text = None 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 text = text.replace('@','@​').replace('#','#​') print(text) -requests.post("https://brain.d.on-t.work/api/notes/create", json={ - 'i': secrets__.TOKEN, +apicreate = "https://" + config__.instance_url + "/api/notes/create"\ - 'visibility': 'home', - 'noExtractMentions': True, - 'noExtractHashtags': True, +if(config__.cw == ""): + requests.post(apicreate, json={ + 'i': secrets__.TOKEN, - 'text': text, - 'cw': 'markov chain generated post' -}) + 'visibility': 'home', + 'noExtractMentions': True, + 'noExtractHashtags': True, + + 'text': text, + }) +else: + requests.post(apicreate, json={ + 'i': secrets__.TOKEN, + + 'visibility': 'home', + 'noExtractMentions': True, + 'noExtractHashtags': True, + + 'text': text, + 'cw': config__.cw + }) \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..707a096 --- /dev/null +++ b/readme.md @@ -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 diff --git a/readme.txt b/readme.txt deleted file mode 100644 index 34112f6..0000000 --- a/readme.txt +++ /dev/null @@ -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