~thrrgilag/partybot

90a831650a7f604cd9b3aa74fad7e1cac2eecb67 — Morgan McMillian 3 months ago 84e96df main
support pnut api v1
1 files changed, 18 insertions(+), 17 deletions(-)

M partybot-pnut.py
M partybot-pnut.py => partybot-pnut.py +18 -17
@@ 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