add an option to avoid creating fake mentions

This commit is contained in:
Lynne 2019-04-29 14:21:46 +10:00
parent 99d1d13fbf
commit 02343668b8
No known key found for this signature in database
GPG key ID: FB7B970303ACE499
3 changed files with 20 additions and 3 deletions

View file

@ -11,6 +11,18 @@ This version makes quite a few changes from [the original](https://github.com/Je
## Install/usage guide ## Install/usage guide
An installation and usage guide is available [here](https://cloud.lynnesbian.space/s/jozbRi69t4TpD95). It's primarily targeted at Linux, but it should be possible on BSD, macOS, etc. I've also put some effort into providing steps for Windows, but I can't make any guarantees as to its effectiveness. An installation and usage guide is available [here](https://cloud.lynnesbian.space/s/jozbRi69t4TpD95). It's primarily targeted at Linux, but it should be possible on BSD, macOS, etc. I've also put some effort into providing steps for Windows, but I can't make any guarantees as to its effectiveness.
## Configuration
Configuring mstdn-ebooks is accomplished by editing `config.json`.
| Setting | Default | Meaning |
|--------------------|------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| site | https://botsin.space | The instance your bot will log in to and post from. |
| cw | null | The content warning (aka subject) mstdn-ebooks will apply to non-error posts. |
| instance_blacklist | ["bofa.lol", "witches.town"] | If your bot is following someone from a blacklisted instance, it will skip over them and not download their posts. This is useful for ensuring that mstdn-ebooks doesn't download posts from dead instances, without you having to unfollow the user(s) from them. |
| learn_from_cw | false | If true, mstdn-ebooks will learn from CW'd posts. |
| mention_handling | 1 | 0: Never use mentions. 1: Only generate fake mentions in the middle of posts, never at the start. 2: Use mentions as normal (old behaviour). |
## Original README ## Original README
hey look it's an ebooks bot hey look it's an ebooks bot

View file

@ -2,5 +2,6 @@
"lang": "en", "lang": "en",
"site": "https://botsin.space", "site": "https://botsin.space",
"cw": null, "cw": null,
"learn_from_cw": false "learn_from_cw": false,
"mention_handling": 1
} }

View file

@ -23,7 +23,7 @@ def make_sentence(output):
else: else:
toots = c.execute("SELECT content FROM `toots` WHERE cw = 0 ORDER BY RANDOM() LIMIT 10000").fetchall() toots = c.execute("SELECT content FROM `toots` WHERE cw = 0 ORDER BY RANDOM() LIMIT 10000").fetchall()
toots_str = "" toots_str = ""
for toot in toots: for toot in toots: # TODO: find a more efficient way to do this
toots_str += "\n{}".format(toot[0]) toots_str += "\n{}".format(toot[0])
model = nlt_fixed(toots_str) model = nlt_fixed(toots_str)
toots_str = None toots_str = None
@ -36,7 +36,11 @@ def make_sentence(output):
sentence = model.make_short_sentence(500, tries=10000) sentence = model.make_short_sentence(500, tries=10000)
tries = tries + 1 tries = tries + 1
sentence = re.sub("^(?:@\u202B[^ ]* )*", "", sentence) #remove leading pings (don't say "@bob blah blah" but still say "blah @bob blah") # optionally remove mentions
if cfg['mention_handling'] == 1:
sentence = re.sub(r"^\S*@\u200B\S*\s?", "")
elif cfg['mention_handling'] == 0:
sentence = re.sub(r"\S*@\u200B\S*\s?", "")
output.send(sentence) output.send(sentence)