summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAda Isopods <me@bathynomus.xyz>2024-05-20 16:28:48 -0600
committerAda Isopods <me@bathynomus.xyz>2026-10-21 23:26:17 -0600
commit3a7c55a6e5e02edfe48d38c861a760fdb5aabb4a (patch)
tree4e5b1d6c3297f1524ab42c166c7d5c30c7451c68
parent2618b264f3b32b67c479833f4ece9c6dcf6d0d92 (diff)
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
-rw-r--r--.gitignore1
-rw-r--r--config__.default.py15
-rw-r--r--generate.py34
-rw-r--r--readme.md25
-rw-r--r--readme.txt5
5 files changed, 65 insertions, 15 deletions
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