|
@@ -2,11 +2,12 @@ KRS-One Bot for Mastodon
|
2
|
2
|
========================
|
3
|
3
|
|
4
|
4
|
This is a python script using the
|
5
|
|
-https://github.com/halcy/Mastodon.py[Mastodon.py] library for a silly purpose.
|
|
5
|
+[Mastodon.py](https://github.com/halcy/Mastodon.py) library for a silly
|
|
6
|
+purpose.
|
6
|
7
|
|
7
|
8
|
Basically, the script will search the current Federated Timeline and
|
8
|
|
-Notifications Timeline, and will answer //"THAT'S THE SOUND OF DA POLICE!"// to
|
9
|
|
-any toot ending with //"toot toot"// (there's a regexp to account for
|
|
9
|
+Notifications Timeline, and will answer *"THAT'S THE SOUND OF DA POLICE!"* to
|
|
10
|
+any toot ending with *"toot toot"* (there's a regexp to account for
|
10
|
11
|
punctuation).
|
11
|
12
|
|
12
|
13
|
Yeah, it's silly. It's also a pretty simple introduction to basic
|
|
@@ -16,7 +17,7 @@ I want to play with the bot!
|
16
|
17
|
----------------------------
|
17
|
18
|
|
18
|
19
|
You will need a Mastodon account, and you'll find one running at
|
19
|
|
-https://mastodon.lertsenem.com/@KRSOneBot[@KRSOneBot@mastodon.lertsenem.com].
|
|
20
|
+[@KRSOneBot@mastodon.lertsenem.com](https://mastodon.lertsenem.com/@KRSOneBot).
|
20
|
21
|
Enjoy yourself.
|
21
|
22
|
|
22
|
23
|
Dependencies
|
|
@@ -24,68 +25,68 @@ Dependencies
|
24
|
25
|
To run this script, you will of course need python 3.
|
25
|
26
|
The following modules are also required:
|
26
|
27
|
|
27
|
|
- * **Mastodon.py**, for Mastodon API interactions
|
28
|
|
- * **BeautifulSoup4**, for very simple HTML parsing
|
|
28
|
+ - **Mastodon.py**, for Mastodon API interactions
|
|
29
|
+ - **BeautifulSoup4**, for very simple HTML parsing
|
29
|
30
|
|
30
|
31
|
Installation
|
31
|
32
|
------------
|
32
|
33
|
|
33
|
34
|
For a simpler installation, I recommend using a virtualenv.
|
34
|
35
|
|
35
|
|
- $> apt install python3-virtualenv
|
36
|
|
-
|
37
|
|
-(You'll need to adapt that command if your package manager is not //apt//)
|
38
|
|
-
|
39
|
|
- $> mkdir krsonebot
|
40
|
|
- $> cd krsonebot
|
41
|
|
- $> git clone https://git.lertsenem.com/lertsenem/mastodon_krsonebot krsonebot
|
42
|
|
- $> virtualenv -p python3 venv
|
43
|
|
- $> . venv/bin/activate
|
44
|
|
- (venv)$> pip install Mastodon.py beautifulsoup4
|
45
|
|
- (venv)$> python krsonebot/main.py --help
|
46
|
|
-
|
47
|
|
- usage: main.py [-h] [-V] [-v] [-i ID_FILE] [-t TOKEN_FILE] [-d DATA_FILE]
|
48
|
|
- [-l LOGIN] [-p PASSWORD]
|
49
|
|
- [fullhandle]
|
50
|
|
-
|
51
|
|
- positional arguments:
|
52
|
|
- fullhandle full mastodon handle
|
53
|
|
-
|
54
|
|
- optional arguments:
|
55
|
|
- -h, --help show this help message and exit
|
56
|
|
- -V, --version show bot version
|
57
|
|
- -v, --verbose more verbose logs
|
58
|
|
- -i ID_FILE, --id-file ID_FILE
|
59
|
|
- the id file
|
60
|
|
- -t TOKEN_FILE, --token-file TOKEN_FILE
|
61
|
|
- the token file
|
62
|
|
- -d DATA_FILE, --data-file DATA_FILE
|
63
|
|
- the data file
|
64
|
|
- -l LOGIN, --login LOGIN
|
65
|
|
- the login to use, needed the first time
|
66
|
|
- -p PASSWORD, --password PASSWORD
|
67
|
|
- the password to use, needed the first time
|
|
36
|
+ $> apt install python3-virtualenv
|
|
37
|
+
|
|
38
|
+(You'll need to adapt that command if your package manager is not *apt*)
|
|
39
|
+
|
|
40
|
+ $> mkdir krsonebot
|
|
41
|
+ $> cd krsonebot
|
|
42
|
+ $> git clone https://git.lertsenem.com/lertsenem/mastodon_krsonebot krsonebot
|
|
43
|
+ $> virtualenv -p python3 venv
|
|
44
|
+ $> . venv/bin/activate
|
|
45
|
+ (venv)$> pip install Mastodon.py beautifulsoup4
|
|
46
|
+ (venv)$> python krsonebot/main.py --help
|
|
47
|
+
|
|
48
|
+ usage: main.py [-h] [-V] [-v] [-i ID_FILE] [-t TOKEN_FILE] [-d DATA_FILE]
|
|
49
|
+ [-l LOGIN] [-p PASSWORD]
|
|
50
|
+ [fullhandle]
|
|
51
|
+
|
|
52
|
+ positional arguments:
|
|
53
|
+ fullhandle full mastodon handle
|
|
54
|
+
|
|
55
|
+ optional arguments:
|
|
56
|
+ -h, --help show this help message and exit
|
|
57
|
+ -V, --version show bot version
|
|
58
|
+ -v, --verbose more verbose logs
|
|
59
|
+ -i ID_FILE, --id-file ID_FILE
|
|
60
|
+ the id file
|
|
61
|
+ -t TOKEN_FILE, --token-file TOKEN_FILE
|
|
62
|
+ the token file
|
|
63
|
+ -d DATA_FILE, --data-file DATA_FILE
|
|
64
|
+ the data file
|
|
65
|
+ -l LOGIN, --login LOGIN
|
|
66
|
+ the login to use, needed the first time
|
|
67
|
+ -p PASSWORD, --password PASSWORD
|
|
68
|
+ the password to use, needed the first time
|
68
|
69
|
|
69
|
70
|
Usage
|
70
|
71
|
-----
|
71
|
72
|
|
72
|
73
|
First, you'll need a mastodon account, on the instance of your choice.
|
73
|
74
|
|
74
|
|
-Next, you can run the //krsonebot// with your handle ('user@instance') as an
|
|
75
|
+Next, you can run the *krsonebot* with your handle ('user@instance') as an
|
75
|
76
|
argument.
|
76
|
77
|
|
77
|
|
- (venv)$> python krsonebot/main.py user@instance
|
|
78
|
+ (venv)$> python krsonebot/main.py user@instance
|
78
|
79
|
|
79
|
80
|
The first time you will be prompted for your credentials, which will then be
|
80
|
|
-saved in 'mstdn_krsonebot.*' files. **Those files holds secrets for a full
|
|
81
|
+saved in `mstdn_krsonebot.*` files. **Those files holds secrets for a full
|
81
|
82
|
access to your account, keep them secret**. You can also revoke the bot access
|
82
|
83
|
to your account any time you want by going into your account settings and
|
83
|
84
|
reviewing the applications permissions.
|
84
|
85
|
|
85
|
86
|
For a repeated usage, on a dedicated account for example, I recommend setting a
|
86
|
|
-cron task to run every minutes:
|
|
87
|
+cron task to run every minutes or so:
|
87
|
88
|
|
88
|
|
- cd path/to/krsonebot/krsonebot && ./venv/bin/python krsonebot/main.py
|
|
89
|
+ */1 * * * * myuser cd path/to/krsonebot/ && ./venv/bin/python krsonebot/main.py
|
89
|
90
|
|
90
|
91
|
Note that after the first time the handle to use is saved in one of the
|
91
|
|
-'mstdn_krsonebot.*' files, so you don't need to precise it in the command line.
|
|
92
|
+`mstdn_krsonebot.*` files, so you don't need to precise it in the command line.
|