Beispiel #1
0
    async def youtubeChatControl(self):
        self.l.logger.info("Started")
        counter = 0
        while True:  
            if self.serviceStarted == True:  
                #try:
                await self.listChat()
                #await self.listLiveStreams()
                #await self.listLiveBroadcasts()
                await self.clearMsgList()
                if counter == 5:
                    filePath = "config{0}auth{0}youtube.json".format(os.sep)
                    data = {"Enabled": self.enabled, "pageToken": self.pageToken, "selfMsgFilter": self.msgCheckList}
                    fileIO.fileSave(filePath,data)
                    counter=0
                    self.l.logger.debug("Saving")

                    
                counter+=1
                #except googleapiclient.errors.HttpError:
                    #youtube = self.Login()
                    #self.l.logger.info('Connection Error reconnecting')
            if self.messageFrequency == 0: #this should prevent overuse of the google api quota slowing down the bot during times of low use and speeding it up during times of high use
                await asyncio.sleep(8)
            elif self.messageFrequency == 1:
                await asyncio.sleep(5)
            elif self.messageFrequency > 1:
                await asyncio.sleep(1)
Beispiel #2
0
    async def listChat(self):
        try:
            continuation = True
            try:
                list_chatmessages = self.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=self.liveChatId,
                    maxResults=200,
                    pageToken=self.pageToken #gives the previous token so it loads a new section of the chat
                ).execute() #executes it so its not just some object
                self.pageToken = list_chatmessages["nextPageToken"] #page token for next use
            except googleapiclient.errors.HttpError:
                self.l.logger.info("Some Google API Error Occured")
                await self.Login()
                continuation = False 
            
            amount = 0
            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"]
                    profilePic = temp["authorDetails"]["profileImageUrl"]
                    if message != "" and username != "": #this makes sure that the message and username slot arent empty before putting this to the discord chat        
                        self.l.logger.debug(temp)
                        fileIO.fileSave("youtubeMsgJson.json", temp)
                        self.l.logger.debug(userID)
                        self.l.logger.debug(self.botUserID)
                        if (userID != self.botUserID):#await self.weedMsg(userId,message)):
                            self.l.logger.info("{0} {1}".format(username,message))
                            await self.processMsg(username=username,message=message,roleList=await self.youtubeRoles(temp["authorDetails"]),profilePicture=profilePic)
                            amount = amount + 1
                        else: #check if the message was sent by the bot or not
                            msgFound = False
                            for oldMsg in self.oldMessageList:
                                if oldMsg["Message"].strip() == message.strip():
                                    msgFound = True
                            if not msgFound: #if message not sent by bot then send it
                                self.l.logger.info("{0} {1}".format(username,message))
                                await self.processMsg(username=username,message=message,roleList=await self.youtubeRoles(temp["authorDetails"]),profilePicture=profilePic)
                                amount = amount + 1
                            
                        # if userID != self.botUserID:
                        #     self.l.logger.info("{0} {1}".format(username,message))
                        #     await self.processMsg(username=username,message=message,roleList=await self.youtubeRoles(temp["authorDetails"]))
                        # elif userID == self.botUserID: #if the userId is the bots then check the message to see if the bot sent it.
                        #     try:
                        #         if (message.find("[B]")==-1): #Checks the message against this to see if it was sent by the bot or a user
                        #             self.l.logger.info("{0} {1}".format(username,message))
                        #             await self.processMsg(username=username,message=message,roleList=await self.youtubeRoles(temp["authorDetails"]))

                        #     except AttributeError as error:
                        #         self.l.logger.info("{0} {1}".format(username,message))
                        #         await self.processMsg(username=username,message=message,roleList=await self.youtubeRoles(temp["authorDetails"]))
            self.messageFrequency = amount
        except ConnectionResetError:
            x = 1
            await self.Login()
            self.l.logger.info('Connection Error reconnecting')
Beispiel #3
0
 async def listLiveBroadcasts(self):
     try:
         x = self.youtube.liveBroadcasts().list(
         broadcastStatus="all",
         part="id,snippet",
         maxResults=50
       ).execute()
         fileIO.fileSave("youtubeliveBroadcastsJson.json", x)
     except:
         await self.Login()
         self.l.logger.info('Connection Error reconnecting')
Beispiel #4
0
 async def listLiveStreams(self):       
     try:
         x = list_streams_request = self.youtube.liveStreams().list(
             part="id,snippet",
             mine=True,
             maxResults=50
         ).execute()
         fileIO.fileSave("youtubeliveStreamsJson.json", x)
     except:
         await self.Login()
         self.l.logger.info('Connection Error reconnecting')
Beispiel #5
0
 def legacyConverts(
     self
 ):  #converts tags from legacy portions of the code or removes them if unnessisary
     try:
         self.chatbotIdentifier = fileIO.loadConf(
             "config{0}chatbot{0}chatbotIdentifier.json")
         self.chatbot["Identifier"] = self.chatbotIdentifier.pop("Format")
         filename = "config{0}chatbot{0}chatbotIdentifier.json".format(
             os.sep)
         fileIO.fileSave(filename, self.chatbotIdentifier)
     except:
         pass
Beispiel #6
0
    async def sendMessage(self, message, objDeliveryDetails,
                          formattingSettings):  #sends the message
        formatType = "MutedOther"
        FormattingOptions = {"%message%": "message"}

        objSendMsg = Object.ObjectLayout.sendMsgDeliveryDetails(
            Message=message,
            DeliveryDetails=objDeliveryDetails,
            FormattingOptions=FormattingOptions,
            formattingSettings=formattingSettings,
            formatType=formatType,
            messageUnchanged=message
        )  #prepares the delivery object and sends the message send event
        config.events.onMessageSend(sndMessage=objSendMsg)


l = logger.logs("Console")
fileIO.checkFolder("config{0}console{0}".format(os.sep), "console", l)
fileIO.checkFile("config-example{0}console{0}console.json".format(os.sep),
                 "config{0}console{0}console.json".format(os.sep),
                 "console.json", l)
file = fileIO.loadConf("config{0}console{0}console.json")

if (not 'Enabled' in file):
    file.update({"Enabled": False})
    fileIO.fileSave("config{0}console{0}console.json".format(os.sep), file)

if file["Enabled"] == True:
    logger.loggerHandlers.add_Logging_Handler(console())
    print("Attaching console")