Bot
unknown
python
2 years ago
3.0 kB
18
Indexable
Never
from asyncio import tasks import socket import ssl from tabnanny import check from PIL import ImageTk, Image from mttkinter import * from twitchAPI import CustomRewardRedemptionStatus from twitchAPI.twitch import Twitch, AuthScope import coverpy import time import config coverpy = coverpy.CoverPy() limit = 1 app = mtTkinter.Tk() app.title('Album Art') app.geometry("700x255") app.resizable(True, False) 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 = {} def init(self): self.connect() 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}') def check(): try: time.sleep(4) 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') redem = twitch.get_custom_reward_redemption( broadcaster_id="779823875", reward_id="1b6df349-d3b5-42c6-a767-6014de518474", status="UNFULFILLED", sort="NEWEST", first=1) redemid = redem['data'][0]['id'] redemtitle = redem['data'][0]['reward']['title'] redemuserimput = redem['data'][0]['user_input'] print(redemid) print(redemtitle) print(redemuserimput) self.send_command(f'JOIN #{channel}') self.send_command(f'PRIVMSG #gg_tec :!sr ' + redemuserimput) twitch.update_redemption_status( broadcaster_id="779823875", reward_id="1b6df349-d3b5-42c6-a767-6014de518474", redemption_ids=redemid, status=CustomRewardRedemptionStatus("FULFILLED"), ) except: print('Nada') def main(): bot = Bot() bot.init() main() def task(): check() app.after(3000, task) app.resizable(True, False) app.configure(background="#202020") app.mainloop()