Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
2.9 kB
14
Indexable
Never
import socket
import ssl
from typing_extensions import Self
from PIL import ImageTk, Image
from mttkinter import *
from twitchAPI import CustomRewardRedemptionStatus
from twitchAPI.twitch import Twitch, AuthScope
from twitchAPI.pubsub import PubSub
from uuid import UUID
import coverpy
import time
import config

coverpy = coverpy.CoverPy()
limit = 1

twitch = Twitch(config.CLIENTID,
        config.CLIENTSECRET,
        target_app_auth_scope=[AuthScope.USER_EDIT])

scope = [AuthScope.CHANNEL_READ_REDEMPTIONS]
scope1 = [AuthScope.CHANNEL_MANAGE_REDEMPTIONS]

twitch.set_user_authentication(
    config.PASS,
    scope + scope1,
    'refresh_token')

def callback_whisper(uuid: UUID, data: dict) -> None:

    print('Foi resgatado um reward ' + str(RedempPubsub))
    print(data['data']['redemption']['reward']['id'])
    print(data['data']['redemption']['reward']['title'])
    print(data['data']['redemption']['user_input'])

    redemid = data['data']['redemption']['reward']['id']
    redemprionid = data['data']['redemption']['id']
    redemtitle = data['data']['redemption']['reward']['title']
    redemuserimput = data['data']['redemption']['user_input']

    Bot.send_command(Bot,f'PRIVMSG #gg_tec :teste11')

    twitch.update_redemption_status(
        broadcaster_id="779823875",
        reward_id=redemid,
        redemption_ids=redemprionid,
        status=CustomRewardRedemptionStatus("FULFILLED"),
    )

pubsub = PubSub(twitch)
pubsub.start()
RedempPubsub = pubsub.listen_channel_points('779823875', callback_whisper)

class Bot:
    def __init__(self):
        self.irc = None
        self.state_schema = None
        self.irc_server = 'irc.chat.twitch.tv'
        self.irc_port = 6697
        self.oauth_token = 'oauth:' + config.PASS
        self.username = config.USER
        self.channels = [config.CHAN]
        self.command_prefix = '!'
        self.state = {}

        self.app = mtTkinter.Tk()
        self.app.title('Album Art')
        self.app.geometry("700x255")
        self.app.resizable(True, False)
        self.app.resizable(True, False)

    def init(self):
        self.connect()
        # you can either start listening before or after you started pubsub.
        

    def send_command(self, command):
        if 'PASS' not in command:
            print(f'< {command}')
        self.irc.send((command + '\r\n').encode())
    


    def connect(self):
        self.irc = ssl.wrap_socket(socket.socket())
        self.irc.connect((self.irc_server, self.irc_port))
        self.send_command(f'PASS {self.oauth_token}')
        self.send_command(f'NICK {self.username}')
        for channel in self.channels:
            self.send_command(f'JOIN #{channel}')

        self.app.configure(background="#202020")
        self.app.mainloop()

def main():
    bot = Bot()
    bot.init()


main()