aboutsummaryrefslogtreecommitdiff
path: root/bot.py
diff options
context:
space:
mode:
Diffstat (limited to 'bot.py')
-rw-r--r--bot.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/bot.py b/bot.py
index a9d661f..54cc31c 100644
--- a/bot.py
+++ b/bot.py
@@ -5,7 +5,7 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
parser = ArgumentParser()
-parser.add_argument('-b', '--backend', choices=['mastodon', 'misskey'], default='mastodon',
+parser.add_argument('-b', '--backend', choices=['mastodon', 'misskey', 'matrix'], default='mastodon',
help='fediverse server type')
parser.add_argument('-i', '--instance', help='Mastodon instance hosting the bot')
parser.add_argument('-t', '--token', help='Mastodon application access token')
@@ -81,6 +81,7 @@ print(output)
post = output.split('\n')[0]
if len(post) < 200:
post = output.split('\n')[0] + '\n' + output.split('\n')[1]
+post = post[:500]
# Post it!
@@ -91,9 +92,22 @@ if args.backend == 'mastodon':
access_token=args.token,
api_base_url=args.instance
)
- mastodon.status_post(post[:500])
+ mastodon.status_post(post)
+
elif args.backend == 'misskey':
from Misskey import Misskey
misskey = Misskey(args.instance, i=args.token)
- misskey.notes_create(post[:500])
+ misskey.notes_create(post)
+
+elif args.backend == 'matrix':
+ import simplematrixbotlib as botlib
+
+ creds = botlib.Creds(args.instance, 'ebooks', args.token)
+ bot = botlib.Bot(creds)
+
+ @bot.listener.on_startup
+ async def room_joined(room_id):
+ await bot.api.send_text_message(room_id=room_id, message=post)
+
+ bot.run()