support pnut api v1
This commit is contained in:
parent
84e96df945
commit
90a831650a
1 changed files with 18 additions and 17 deletions
|
@ -22,7 +22,7 @@ _connected = threading.Event()
|
||||||
_error = threading.Event()
|
_error = threading.Event()
|
||||||
|
|
||||||
def subscribe(connection_id):
|
def subscribe(connection_id):
|
||||||
url = f"https://api.pnut.io/v0/channels/{config['CHANNEL']}/messages"
|
url = f"https://api.pnut.io/v1/channels/{config['CHANNEL']}/messages"
|
||||||
url += "?connection_id=" + connection_id
|
url += "?connection_id=" + connection_id
|
||||||
headers = {'Authorization': "Bearer " + config['ACCESS_TOKEN']}
|
headers = {'Authorization': "Bearer " + config['ACCESS_TOKEN']}
|
||||||
r = requests.get(url, headers=headers)
|
r = requests.get(url, headers=headers)
|
||||||
|
@ -302,28 +302,29 @@ def on_message(ws, message):
|
||||||
|
|
||||||
if "channel_type" in msg['meta'] and msg['meta']['channel_type'] == "io.pnut.core.chat":
|
if "channel_type" in msg['meta'] and msg['meta']['channel_type'] == "io.pnut.core.chat":
|
||||||
|
|
||||||
pmsg = pnutpy.models.Message.from_response_data(msg['data'])
|
for d_item in msg['data']:
|
||||||
|
pmsg = pnutpy.models.Message.from_response_data(d_item)
|
||||||
|
|
||||||
if 'is_deleted' in msg['meta']:
|
if 'is_deleted' in msg['meta']:
|
||||||
return
|
return
|
||||||
|
|
||||||
vpattern = r"([\w]+)\s?(\-\-|\+\+|\U0001F44D|\U0001F44E|\:thumbsup\:|\:\+1\:|\:thumbsdown\:|\:-1\:|\+1|-1)"
|
vpattern = r"([\w]+)\s?(\-\-|\+\+|\U0001F44D|\U0001F44E|\:thumbsup\:|\:\+1\:|\:thumbsdown\:|\:-1\:|\+1|-1)"
|
||||||
votes = re.search(vpattern, pmsg.content.text)
|
votes = re.search(vpattern, pmsg.content.text)
|
||||||
|
|
||||||
if pmsg.user.username == config['USERNAME']:
|
if pmsg.user.username == config['USERNAME']:
|
||||||
return
|
return
|
||||||
|
|
||||||
if pmsg.user.username == config['MNDPUSER']:
|
if pmsg.user.username == config['MNDPUSER']:
|
||||||
on_mndp(pmsg)
|
on_mndp(pmsg)
|
||||||
|
|
||||||
elif config['USERNAME'] in [e.text for e in pmsg.content.entities.mentions]:
|
elif config['USERNAME'] in [e.text for e in pmsg.content.entities.mentions]:
|
||||||
on_mention(pmsg)
|
on_mention(pmsg)
|
||||||
|
|
||||||
elif pmsg.content.text.startswith('!'):
|
elif pmsg.content.text.startswith('!'):
|
||||||
on_command(pmsg)
|
on_command(pmsg)
|
||||||
|
|
||||||
elif votes:
|
elif votes:
|
||||||
on_vote(pmsg, votes)
|
on_vote(pmsg, votes)
|
||||||
|
|
||||||
def on_error(ws, error):
|
def on_error(ws, error):
|
||||||
logger.error("on_error: !!! ERROR !!!")
|
logger.error("on_error: !!! ERROR !!!")
|
||||||
|
@ -380,7 +381,7 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
pnutpy.api.add_authorization_token(config['ACCESS_TOKEN'])
|
pnutpy.api.add_authorization_token(config['ACCESS_TOKEN'])
|
||||||
|
|
||||||
ws_url = "wss://stream.pnut.io/v0/user"
|
ws_url = "wss://stream.pnut.io/v1/user"
|
||||||
ws_url += "?access_token=" + config['ACCESS_TOKEN']
|
ws_url += "?access_token=" + config['ACCESS_TOKEN']
|
||||||
|
|
||||||
# setup the websocket connection
|
# setup the websocket connection
|
||||||
|
|
Loading…
Reference in a new issue