diff --git a/bot.py b/bot.py index 6e017a0..1228976 100755 --- a/bot.py +++ b/bot.py @@ -12,8 +12,10 @@ def json_read(file): config = json.load(f) return config +# Temp config = json_read('config.json') + #try: # config = json_read('config.json') #except FileNotFoundError: @@ -26,38 +28,36 @@ if config['verbosity'].upper() == 'DEBUG': msk = msk.Misskey(i=config['token'], url=config['url']) - -#fid = msk.drive_files_create("yaoshi-jun-Toosaka-Rin-Fate-(series)-Anime-3306019.jpeg", isSensitive=True)['id'] -#msk.notes_create(text="Wannya see my picture?", cw="Nya?", fileIds=[fid]) async def main(): + log.info("Connecting to {}".format(msk.url)) async with websockets.connect(msk.ws_url) as ws: - print('Connecting') + log.info('Sucessfully connected to {}'.format(msk.url)) + log.info('Attemping to watch timeline') p = { 'type': 'connect', 'body': { - 'channel': 'homeTimeline', - 'id': 'Nya1' - } - } - await ws.send(json.dumps(p)) - p = { - 'type': 'connect', - 'body': { - 'channel': 'main', - 'id': 'Nya2' + 'channel': 'main' } } await ws.send(json.dumps(p)) - print('Listening') + log.info('Listening to timeline') while True: data = await ws.recv() j = json.loads(data) + if j['type'] == 'channel': + if j['body']['type'] == 'followed': + print("Follow!") + msk.following_create(j['body']['body']['id']) + if j['body']['type'] == 'mention': + if not j['body']['body']['replyId']: + msk.notes_create(renoteId=j['body']['body']['id']) print(j) - while True: try: - asyncio.get_event_loop().run_until_complete(main()) + loop = asyncio.new_event_loop() + #asyncio.set_event_loop(loop) + loop.run_until_complete(main()) except KeyboardInterrupt: break diff --git a/msk.py b/msk.py index d7de9f7..02aef4e 100644 --- a/msk.py +++ b/msk.py @@ -10,7 +10,7 @@ class Misskey: def __init__(self, url: str, i: str): self.url = f"https://{url}" self.i = i - self.ws_url=f"wss://{url}/streaming&i={i}" + self.ws_url=f"wss://{url}/streaming?i={i}" def notes_create(self, text=None, visibility = "public", cw = None, fileIds = list(), replyId = None, renoteId = None): req_url = self.url + "/api/notes/create" diff --git a/sources.md b/sources.md deleted file mode 100644 index f648ea6..0000000 --- a/sources.md +++ /dev/null @@ -1,9 +0,0 @@ -## API -https://misskey.io/api-doc - -## Примеры ботов -https://github.com/yupix/Mi.py - -https://github.com/TennousuAthena/RSSToMisskey - -https://github.com/theskanthunt42/misskeyInstanceCheckBot