support pnut api v1

This commit is contained in:
Morgan McMillian 2021-02-27 10:52:56 -08:00
parent 84e96df945
commit 90a831650a

View file

@ -22,7 +22,7 @@ _connected = threading.Event()
_error = threading.Event()
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
headers = {'Authorization': "Bearer " + config['ACCESS_TOKEN']}
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":
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']:
return
if 'is_deleted' in msg['meta']:
return
vpattern = r"([\w]+)\s?(\-\-|\+\+|\U0001F44D|\U0001F44E|\:thumbsup\:|\:\+1\:|\:thumbsdown\:|\:-1\:|\+1|-1)"
votes = re.search(vpattern, pmsg.content.text)
vpattern = r"([\w]+)\s?(\-\-|\+\+|\U0001F44D|\U0001F44E|\:thumbsup\:|\:\+1\:|\:thumbsdown\:|\:-1\:|\+1|-1)"
votes = re.search(vpattern, pmsg.content.text)
if pmsg.user.username == config['USERNAME']:
return
if pmsg.user.username == config['USERNAME']:
return
if pmsg.user.username == config['MNDPUSER']:
on_mndp(pmsg)
if pmsg.user.username == config['MNDPUSER']:
on_mndp(pmsg)
elif config['USERNAME'] in [e.text for e in pmsg.content.entities.mentions]:
on_mention(pmsg)
elif config['USERNAME'] in [e.text for e in pmsg.content.entities.mentions]:
on_mention(pmsg)
elif pmsg.content.text.startswith('!'):
on_command(pmsg)
elif pmsg.content.text.startswith('!'):
on_command(pmsg)
elif votes:
on_vote(pmsg, votes)
elif votes:
on_vote(pmsg, votes)
def on_error(ws, error):
logger.error("on_error: !!! ERROR !!!")
@ -380,7 +381,7 @@ if __name__ == "__main__":
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']
# setup the websocket connection