Beispiel #1
0
 def __init__(self, groupName):
     self.m_groupName = groupName
     self.refreshGroup()
     self.refreshBot()
     self.getAdmins()
     self.m_thisTwitch = twitch.emotes()
     self.m_thisAlarm = timer.alarm()
     self.m_thisMarkov = markov.markov(self.m_thisGroup, self.m_groupName, self.m_thisBot)
     utils.showOutput('Bot initialized successfully...listening...', verbosity=utils.INFO_LEVEL_Useful)
Beispiel #2
0
 def refreshBot(self):
     bots = Bot.list()
     for bot in bots:
         if self.m_thisGroup.id == bot.gorup_id:
             self.m_thisBot = bot
             break
     if self.m_thisBot is None:
         utils.showOutput("Cannot find bot for group {0}".format(groupName), verbosity=utils.INFO_LEVEL_Important)
         sys.exit(0)
Beispiel #3
0
 def refreshGroup(self):
     groups = groupy.Group.list()
     for group in groups:
         if group.name == self.m_groupName:
             self.m_thisGroup = group
             break
     if self.m_thisGroup is None:
         utils.showOutput("Cannot find group {0}".format(groupName), verbosity=utils.INFO_LEVEL_Important)
         sys.exit(0)
Beispiel #4
0
def getAllText(groupObj, groupName, botName):
    output_text = ''
    all_text = ''
    if os.path.exists("..{1}cache{1}messages-{0}.txt".format(groupName, os.path.sep)):
        utils.showOutput("found existing messages cached, continuing lexicon generation...", end='')
        return
    utils.showOutput("Compiling all messages to ..{1}cache{1}messages-{0}.txt...".format(groupName, os.path.sep))
    num_messages, initial_count = groupObj.message_count, groupObj.message_count

    start = time.time()
    cur = groupObj.messages()
    while num_messages > 0:
        for message in cur:
            if message.text is None or message.name.lower() == botName.lower():
                continue
            all_text = all_text + message.text + ' '          
        try:
            cur = cur.older()
        except: 
            pass
        num_messages = num_messages - 100
        utils.showOutput ('{0} messages remain'.format(num_messages))
    
    f = open('..{1}cache{1}messages-{0}.txt'.format(groupName, os.path.sep), 'w+', encoding='utf-8')
    f.write(all_text)
    f.close()
    utils.showOutput("completed.")
Beispiel #5
0
    def getAdmins(self):
        adminFile = '..{0}assets{0}admins-{1}.txt'.format(os.path.sep, self.m_groupName)

        if not os.path.exists(adminFile):
            utils.showOutput("WARNING: No admin file found at {0}, please make a csv of admins using full names, this bot will not be able to use admin commands".format(adminFile), 
                             verbosity=utils.INFO_LEVEL_Important)
        else:
            utils.showOutput('Found admin file {0}, reading...'.format(adminFile), verbosity=utils.INFO_LEVEL_Important, end='')
            f = open(adminFile, 'r')
            text = f.read()
            f.close()
            self.m_admins = text.split(',')
            utils.showOutput('finished.')
Beispiel #6
0
 def train(self, groupObj, groupName):
     stats.getAllText(groupObj, groupName, self.m_botName)
     self.buildMapping(self.wordlist('..{1}cache{1}messages-{0}.txt'.format(groupName, os.path.sep)), MARKOV_LENGTH)
     utils.showOutput("bot successfully trained.")
Beispiel #7
0
 def runBot(self):
     cur = self.m_thisGroup.messages()
     start_messages = self.m_thisGroup.message_count
     messageAlreadyParsed = True
 
     while True:                   
         anyAlarms = self.m_thisAlarm.checkAlarms()
         if anyAlarms:
             self.m_thisBot.post(anyAlarms)          
         if messageAlreadyParsed == False:
             for message in cur:
                 if not message.text:
                     utils.showOutput('recived image ({0}) from {1}'.format(message.created_at, message.name))
                     continue
                 else:
                     utils.showOutput('recieved message {0} ({1}) from {2}'.format(message.text.encode('utf-8'), message.created_at, message.name), verbosity=utils.INFO_LEVEL_Useful)
                  
                 if message.text[0] == '!' and message.name != self.m_thisBot.name:
                     self.checkAndEvaluateCommand(message, message.name)             #getting a little unwieldy, we'll hook in through this method now
                 elif message.name != self.m_thisBot.name:    
                     self.checkAndEvaluateMessage(message, message.name)            #same thing but for misc. events happening only from test
         
         messageAlreadyParsed = True
         utils.showOutput('sleeping for {0}s '.format(SLEEP_INTERVAL), verbosity=utils.INFO_LEVEL_RarelyUseful, end='')
         time.sleep(SLEEP_INTERVAL)
         try:
             self.refreshGroup()
             new_messages = self.m_thisGroup.message_count
             utils.showOutput('started with {0} messages, now see {1}'.format(start_messages, new_messages), verbosity=utils.INFO_LEVEL_RarelyUseful)
             if (new_messages - start_messages) > 0:
                 cur = cur.newer()
                 start_messages = new_messages
                 utils.showOutput('retrieved {0} new messages'.format(len(cur)), verbosity=utils.INFO_LEVEL_RarelyUseful)
                 messageAlreadyParsed = False
         except Exception as e:
             utils.showOutput(e)