Example #1
0
def listLiveBroadcasts():
    global pageToken #pulls in the page token
    global liveChatId #pulls in the liveChatID
    global botUserID #pulls in the bots channel ID
    global youtube       
    x = youtube.liveBroadcasts().list(
    broadcastStatus="all",
    part="id,snippet",
    maxResults=50
  ).execute()
    fileIO.fileSave("youtubeliveBroadcastsJson.json", x)    
Example #2
0
def listLiveStreams():
    global pageToken #pulls in the page token
    global liveChatId #pulls in the liveChatID
    global botUserID #pulls in the bots channel ID
    global youtube           
    x = list_streams_request = youtube.liveStreams().list(
        part="id,snippet",
        mine=True,
        maxResults=50
    ).execute()
    fileIO.fileSave("youtubeliveStreamsJson.json", x)
Example #3
0
    def main(self):
        print("bot loaded")
        cycle = 0
        while True:
            self.checkConsole()
            self.checkMSG()
            self.authorMuteTimeCheck()
            if cycle == 120:
                fileIO.fileSave("variables.config-test.json", variables.config)

                cycle = 0
            cycle = cycle + 1
            time.sleep(0.2)
Example #4
0
def listChat():
    global pageToken #pulls in the page token
    global liveChatId #pulls in the liveChatID
    global botUserID #pulls in the bots channel ID
    global youtube
    try:
        continuation = True
        try:
            list_chatmessages = youtube.liveChatMessages().list( #lists the chat messages
                part="id,snippet,authorDetails", #gets the author details needed and the snippet all of which giving me the message and username
                liveChatId=liveChatId,
                maxResults=500,
                pageToken=variables.config["Bot"]["Youtube"]["pageToken"] #gives the previous token so it loads a new section of the chat
            ).execute() #executes it so its not just some object
            variables.config["Bot"]["Youtube"]["pageToken"] = list_chatmessages["nextPageToken"] #page token for next use
        except googleapiclient.errors.HttpError:
            continuation = False 
            
        msgCheckRegex = re.compile(r'(:)') #setup for if we happen to need this it should never change either way
        if continuation == True:
            for temp in list_chatmessages["items"]: #goes through all the stuff in the list messages list
                message = temp["snippet"]["displayMessage"] #gets the display message
                username = temp["authorDetails"]["displayName"] #gets the users name
                userID = temp["authorDetails"]["channelId"]
                if message != "" and username != "": #this makes sure that the message and username slot arent empty before putting this to the discord chat        
                    print(temp)
                    fileIO.fileSave("youtubeMsgJson.json", temp)
                    print(userID)
                    print(botUserID)
                    if userID != botUserID:
                        print("{0} {1}".format(username,message))
                        msgStats = {"sentFrom":"Youtube","msgData": None,"Bot":"Youtube","Server": "None","Channel": variables.config["Bot"]["Youtube"]["ChannelName"], "author": username,"authorData":None,"authorsRole": youtubeRoles(temp["authorDetails"]),"msg":message,"sent":False}
                        variables.mainMsg.append(msgStats)
                    elif userID == botUserID: #if the userId is the bots then check the message to see if the bot sent it.
                        try:
                            msgCheckComplete = msgCheckRegex.search(message) #checks the message against the previously created regex for ":"
                            if msgCheckComplete.group(1) != ":": #if its this then go and send the message as normal
                                print("{0} {1}".format(username,message))
                                msgStats = {"sentFrom":"Youtube","msgData": None,"Bot":"Youtube","Server": "None","Channel": variables.config["Bot"]["Youtube"]["ChannelName"], "author": username,"authorData":None,"authorRole": youtubeRoles(temp["authorDetails"]),"msg":message,"sent":False}
                                variables.mainMsg.append(msgStats)
                        except AttributeError as error:
                            print("{0} {1}".format(username,message))
                            msgStats = {"sentFrom":"Youtube","msgData": None,"Bot":"Youtube","Server": "None","Channel": variables.config["Bot"]["Youtube"]["ChannelName"], "author": username,"authorData":None,"authorsRole": youtubeRoles(temp["authorDetails"]),"msg":message,"sent":False}
                            variables.mainMsg.append(msgStats)    
    except ConnectionResetError:
        x = 1
        mainBot.mainBot().addToConsole('Connection Error reconnecting',"Youtube","Info")
        youtube = Login()
Example #5
0
    def checkConsole(self):  #console sending to another service
        j = 0
        for msg in variables.mainMsg:
            try:
                if msg["Channel"] == "Console" and msg["sent"] == False:

                    for key, val in variables.config["Bot Console"].items():
                        if val["Site"] == "Terminal" and self.consoleDebugCheck(
                                val["Debug"],
                                msg["Info"]["errorLevel"]) == True:
                            x = 1
                        elif self.consoleDebugCheck(
                                val["Debug"],
                                msg["Info"]["errorLevel"]) == True:
                            print(val)
                            fileIO.fileSave("Val", val)
                            msgStats = {
                                "sentFrom": msg["sentFrom"],
                                "Bot": msg["Bot"],
                                "Server": msg["Server"],
                                "sendTo": {
                                    "Bot": "Discord",
                                    "Server": "Popicraft Network",
                                    "Channel": "console"
                                },
                                "Channel": msg["Channel"],
                                "author": msg["author"],
                                "msg": msg["msg"],
                                "msgFormated": self.consoleFormat(msg, val),
                                "sent": False
                            }
                            variables.processedMSG.append(msgStats)
                            print(msgStats)
                            fileIO.fileSave("console", str(msgStats))

                    variables.mainMsg[j]["sent"] = True
                    return True

                j = j + 1
            except KeyError as error:
                #print("not deleted")
                #print('Error on line {}'.format(sys.exc_info()[-1].tb_lineno), type(error).__name__, error)
                errorMsg = 'Error on line {}'.format(
                    sys.exc_info()[-1].tb_lineno,
                    type(error).__name__, error)
                #mainBot().addToConsole(errorMsg,"Discord"," Extra Debug")
                return False