niho #2
					 3 changed files with 18 additions and 27 deletions
				
			
		
							
								
								
									
										34
									
								
								bot.py
									
										
									
									
									
								
							
							
						
						
									
										34
									
								
								bot.py
									
										
									
									
									
								
							|  | @ -12,8 +12,10 @@ def json_read(file): | ||||||
|         config = json.load(f) |         config = json.load(f) | ||||||
|     return config |     return config | ||||||
| 
 | 
 | ||||||
|  | # Temp | ||||||
| config = json_read('config.json') | config = json_read('config.json') | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| #try: | #try: | ||||||
| #    config = json_read('config.json') | #    config = json_read('config.json') | ||||||
| #except FileNotFoundError: | #except FileNotFoundError: | ||||||
|  | @ -26,38 +28,36 @@ if config['verbosity'].upper() == 'DEBUG': | ||||||
| 
 | 
 | ||||||
| msk = msk.Misskey(i=config['token'], url=config['url']) | 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(): | async def main(): | ||||||
|  |     log.info("Connecting to {}".format(msk.url)) | ||||||
|     async with websockets.connect(msk.ws_url) as ws: |     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 = { |         p = { | ||||||
|             'type': 'connect', |             'type': 'connect', | ||||||
|             'body': { |             'body': { | ||||||
|                 'channel': 'homeTimeline', |                 'channel': 'main' | ||||||
|                 'id': 'Nya1' |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         await ws.send(json.dumps(p)) |  | ||||||
|         p = { |  | ||||||
|             'type': 'connect', |  | ||||||
|             'body': { |  | ||||||
|                 'channel': 'main', |  | ||||||
|                 'id': 'Nya2' |  | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         await ws.send(json.dumps(p)) |         await ws.send(json.dumps(p)) | ||||||
|          |          | ||||||
|         print('Listening') |         log.info('Listening to timeline') | ||||||
|         while True: |         while True: | ||||||
|             data = await ws.recv() |             data = await ws.recv() | ||||||
|             j = json.loads(data) |             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) |             print(j) | ||||||
| 
 |  | ||||||
| while True: | while True: | ||||||
|     try: |     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: |     except KeyboardInterrupt: | ||||||
|         break |         break | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								msk.py
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								msk.py
									
										
									
									
									
								
							|  | @ -10,7 +10,7 @@ class Misskey: | ||||||
|     def __init__(self, url: str, i: str): |     def __init__(self, url: str, i: str): | ||||||
|         self.url = f"https://{url}" |         self.url = f"https://{url}" | ||||||
|         self.i = i |         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): |     def notes_create(self, text=None, visibility = "public", cw = None, fileIds = list(), replyId = None, renoteId = None): | ||||||
|         req_url = self.url + "/api/notes/create" |         req_url = self.url + "/api/notes/create" | ||||||
|  |  | ||||||
|  | @ -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 |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue