Example #1
0
class Notificator:
    PREDICTIONS_LENGTH = 6
    NOTIFICATION_DELAY = 60  #seconds

    def __init__(self):
        self.slackBot = SlackBot()
        self.predictions = [
            False for _ in range(Notificator.PREDICTIONS_LENGTH)
        ]
        self.lastNotificationTime = time.time()

    def notify(self, imagePath):
        message = "ApareciĆ³ un gato wachin!"
        channel = "#negra"
        self.slackBot.sendMessage(channel=channel, message=message)
        self.slackBot.sendImage(channel=channel, imagePath=imagePath)

    def manageNotification(self, prediction):
        label, prob = prediction
        labelTruthValue = True if label == 1 else False
        self.predictions.append(labelTruthValue)
        self.predictions.pop(0)
        count = 0
        lastPredIndex = None
        for i, pred in enumerate(self.predictions):
            if pred:
                lastPredIndex = i
                count += 1
        if count > Notificator.PREDICTIONS_LENGTH / 2:
            elapsed = time.time() - self.lastNotificationTime
            print("Elapsed {} seconds since last notification".format(elapsed))
            if elapsed > Notificator.NOTIFICATION_DELAY:
                print("Elapsed > NOTIFICATION_DELAY.. should notify")
                imageName = "temp{}.jpg".format(lastPredIndex + 1)
                self.notify(imageName)
                self.lastNotificationTime = time.time()
Example #2
0
def main():
    timestamp = time.time()
    slack_bot_dns320 = SlackBot(slack_token, channel_id, file_with_list, dir_list_command)
    try:
        slack_bot_dns320.post_message('Ready. Type *help* to get started')

        while True:
            time.sleep(5)
            try:
                msgs = slack_bot_dns320.get_sorted_latest_messages(timestamp)
                if msgs:  # not empty
                    timestamp = msgs[-1]['ts']
                    for msg in msgs:
                        if 'bot_message' not in msg:
                            slack_bot_dns320.parse_command(msg['text'])
            except Exception as e:
                print e
                slack_bot_dns320.post_message(str(e))

    except Exception as e:
        print e
Example #3
0
def minecraft_speakup(bot,msg):
    thread.start_new(minecraft_watch,(bot,msg))
    bot.say(msg.channel, ':tanky: Anyone want to play Minecraft?')

def minecraft_shutup(bot,msg):
    minecraft_stop = True
    bot.say(msg.channel, ':tanky:  Awww come on guys')

def minecraft_player(bot,msg):
    bot.say(msg.channel, 'Getting player info... ')
    player = re.match('^!minecraft_player(.*)$', msg.text, re.I)


load_config()

buch = SlackBot(slack_api_token)
buch.show_typing = True

buch.add_event_listener('open', on_open)
buch.add_event_listener('message', listen_for_keywords)
buch.add_event_listener('presence_change', greet_people)
buch.add_event_listener('message', chatbot)

buch.add_command('reload', reload_command)
buch.add_command('say', say_command)
buch.add_command('yell', yell_command)
#buch.add_command('refrigerators', refrigerators_command)
#buch.add_command('totinos', totinos_command)
#buch.add_command('kris', kris_command)
#buch.add_command('grumble', grumble_command)
#buch.add_command('clickbait', clickbait_command)
Example #4
0
def slackClient():
    from SlackBot import SlackBot
    import creds as config
    return SlackBot(config.slack['token'])
Example #5
0
 def __init__(self):
     self.slackBot = SlackBot()
     self.predictions = [
         False for _ in range(Notificator.PREDICTIONS_LENGTH)
     ]
     self.lastNotificationTime = time.time()
Example #6
0
def runSlackBot():

    slackbot = SlackBot();
    slackbot.run();