Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
aurel1on | 2cbc570f3e | 3 years ago |
Nihonium | 11825e4825 | 3 years ago |
aurel1on | 0fbdfab1dd | 3 years ago |
aurel1on_sol | b5a71d5dce | 3 years ago |
Nihonium | 5e47ecc9b4 | 3 years ago |
@ -1,61 +0,0 @@
|
|||||||
#!/usr/bin/python3
|
|
||||||
import logging as log
|
|
||||||
import requests
|
|
||||||
import json
|
|
||||||
import msk
|
|
||||||
import websockets
|
|
||||||
import asyncio, aiohttp
|
|
||||||
|
|
||||||
def json_read(file):
|
|
||||||
print("Reading config file: {}".format(file))
|
|
||||||
with open(file) as f:
|
|
||||||
config = json.load(f)
|
|
||||||
return config
|
|
||||||
|
|
||||||
# Temp
|
|
||||||
config = json_read('config.json')
|
|
||||||
|
|
||||||
|
|
||||||
#try:
|
|
||||||
# config = json_read('config.json')
|
|
||||||
#except FileNotFoundError:
|
|
||||||
# print("Config file not found. Maybe we should launch setup.py?")
|
|
||||||
|
|
||||||
|
|
||||||
if config['verbosity'].upper() == 'DEBUG':
|
|
||||||
log.basicConfig(format="%(levelname)s: %(message)s", level=log.DEBUG)
|
|
||||||
log.info("Verbose output")
|
|
||||||
|
|
||||||
msk = msk.Misskey(i=config['token'], url=config['url'])
|
|
||||||
|
|
||||||
async def main():
|
|
||||||
log.info("Connecting to {}".format(msk.url))
|
|
||||||
async with websockets.connect(msk.ws_url) as ws:
|
|
||||||
log.info('Sucessfully connected to {}'.format(msk.url))
|
|
||||||
log.info('Attemping to watch timeline')
|
|
||||||
p = {
|
|
||||||
'type': 'connect',
|
|
||||||
'body': {
|
|
||||||
'channel': 'main'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await ws.send(json.dumps(p))
|
|
||||||
|
|
||||||
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.run(main())
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
break
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "[Shitpost] PoridgeClub",
|
||||||
|
"url" : "https://shitpost.poridge.club",
|
||||||
|
"token": "ur_token",
|
||||||
|
"visibility": "public"
|
||||||
|
}
|
@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "nyan.nekoea.red",
|
|
||||||
"url" : "nyan.nekoea.red",
|
|
||||||
"token": "*****",
|
|
||||||
"verbosity": "debug"
|
|
||||||
}
|
|
||||||
|
|
@ -1,73 +0,0 @@
|
|||||||
import requests
|
|
||||||
import logging as log
|
|
||||||
|
|
||||||
class Misskey:
|
|
||||||
'''
|
|
||||||
Class for interaction with Misskey instance
|
|
||||||
Currently, this class ignores most of the Misskey specific shit like channels =3
|
|
||||||
'''
|
|
||||||
|
|
||||||
def __init__(self, url: str, i: str):
|
|
||||||
self.url = f"https://{url}"
|
|
||||||
self.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"
|
|
||||||
|
|
||||||
if renoteId:
|
|
||||||
body = {
|
|
||||||
"renoteId": renoteId,
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
body = {
|
|
||||||
"text": text,
|
|
||||||
"visibility": visibility,
|
|
||||||
}
|
|
||||||
for item in [(cw, "cw"), (fileIds,"fileIds"), (replyId,"replyId")]:
|
|
||||||
if item[0]:
|
|
||||||
body[item[1]] = item[0]
|
|
||||||
|
|
||||||
body['i'] = self.i
|
|
||||||
|
|
||||||
log.info("Trying to post note to {}".format(self.url))
|
|
||||||
r = requests.post(req_url, json=body)
|
|
||||||
print(body)
|
|
||||||
if r.status_code == 200:
|
|
||||||
log.info("Successfully posted")
|
|
||||||
else:
|
|
||||||
log.error("Posting failed with {} error!".format(r.status_code))
|
|
||||||
|
|
||||||
return r.json()
|
|
||||||
|
|
||||||
def following_create(self, userId: str):
|
|
||||||
req_url = self.url + "/api/following/create"
|
|
||||||
r = requests.post(req_url, json={"i":self.i, "userId": userId})
|
|
||||||
if r.status_code == 200:
|
|
||||||
res = r.json()
|
|
||||||
log.info("Successfully followed user {}@{}[{}]".format(res['username'],res['host'] ,userId))
|
|
||||||
else:
|
|
||||||
log.error("Failed to follow user [{}] with {} error!".format(userId, r.status_code))
|
|
||||||
|
|
||||||
return r.json()
|
|
||||||
|
|
||||||
def drive_files_create(self, file, isSensitive=False):
|
|
||||||
req_url = self.url + "/api/drive/files/create"
|
|
||||||
|
|
||||||
with open(file, "rb") as f:
|
|
||||||
files = {"file": (file, f)}
|
|
||||||
body = {
|
|
||||||
"isSensitive": isSensitive,
|
|
||||||
"i":self.i
|
|
||||||
}
|
|
||||||
payload = {'json_payload': body, 'i': self.i }
|
|
||||||
|
|
||||||
r = requests.post(req_url, data=payload, files=files)
|
|
||||||
|
|
||||||
if r.status_code == 200:
|
|
||||||
res = r.json()
|
|
||||||
log.info("Successfully uploaded file {}[{}]".format(res['name'], res['id']))
|
|
||||||
else:
|
|
||||||
log.error("Failed to upload file {} with {} error!".format(file, r.status_code))
|
|
||||||
|
|
||||||
return r.json()
|
|
@ -0,0 +1,12 @@
|
|||||||
|
## API
|
||||||
|
https://misskey.io/api-doc
|
||||||
|
|
||||||
|
## Примеры ботов
|
||||||
|
https://github.com/yupix/Mi.py
|
||||||
|
|
||||||
|
https://github.com/TennousuAthena/RSSToMisskey
|
||||||
|
|
||||||
|
https://github.com/theskanthunt42/misskeyInstanceCheckBot
|
||||||
|
|
||||||
|
## Twitter API
|
||||||
|
https://www.earthdatascience.org/courses/use-data-open-source-python/intro-to-apis/twitter-data-in-python/
|
Loading…
Reference in New Issue