<commit_before>import re
import sqlite3
from hubbot.moduleinterface import ModuleInterface
from pushbullet import PushBullet, InvalidKeyError


class Notify(ModuleInterface):
    pb = None
    APIKey = None
    regexPattern = "Hubbe.*"

    def getAPIkey(self):
        """
        Get the API key for pushbullet from the sqlite database.
        """
        apiKey = None
        with sqlite3.connect(self.bot.databaseFile) as conn:
            c = conn.cursor()
            for row in c.execute("SELECT apikey FROM keys WHERE name=\"pushbullet\""):
                apiKey = row[0]
        return apiKey

    def onEnable(self):
        """
        When the module is enabled, try to get the API key for Pushbullet and authenticate with it.
        """
        try:
            self.APIKey = self.getAPIkey()
            self.pb = None
            if self.APIKey is not None:
                try:
                    self.pb = PushBullet(self.APIKey)
                except InvalidKeyError:
                    self.bot.logger.exception("Pushbullet API key invalid!")
                    raise
                self.bot.logger.info("Successfully authenticated with Pushbullet API key.")
            else:
                self.bot.logger.error("Could not find Pushbullet API key!")
        except:
            self.bot.logger.error("Error when fetching Pushbullet API key!")
            raise

    def shouldTrigger(self, message):
        """
        @type message: hubbot.message.IRCMessage
        """
        if message.Type in self.acceptedTypes:
            match = re.search(self.regexPattern, message.MessageString, re.IGNORECASE)
            if match:
                return True
            else:
                return False

    def onTrigger(self, message):
        """
        @type message: hubbot.message.IRCMessage
        """
        try:
            self.pb.refresh()
            phone = self.getDeviceByName("phone")
            push = phone.push_note("Highlight in {}".format(message.Channel.Name), "<{}> {}".format(message.User.Name, message.MessageString))
        except:
            self.bot.logger.exception("Highlighting pushbullet push failed.")
        else:
            if "error" in push:
                self.bot.logger.error("Pushbullet returned error '{}'".format(push["error"]["type"]))

    def getDeviceByName(self, deviceName):<commit_msg>[Notify] Only Notify if intended target is in channel<commit_after>import re
import sqlite3
from hubbot.moduleinterface import ModuleInterface
from pushbullet import PushBullet, InvalidKeyError


class Notify(ModuleInterface):
    pb = None
    APIKey = None
    regexPattern = "Hubbe.*"

    def getAPIkey(self):
        """
        Get the API key for pushbullet from the sqlite database.
        """
        apiKey = None
        with sqlite3.connect(self.bot.databaseFile) as conn:
            c = conn.cursor()
            for row in c.execute("SELECT apikey FROM keys WHERE name=\"pushbullet\""):
                apiKey = row[0]
        return apiKey

    def onEnable(self):
        """
        When the module is enabled, try to get the API key for Pushbullet and authenticate with it.
        """
        try:
            self.APIKey = self.getAPIkey()
            self.pb = None
            if self.APIKey is not None:
                try:
                    self.pb = PushBullet(self.APIKey)
                except InvalidKeyError:
                    self.bot.logger.exception("Pushbullet API key invalid!")
                    raise
                self.bot.logger.info("Successfully authenticated with Pushbullet API key.")
            else:
                self.bot.logger.error("Could not find Pushbullet API key!")
        except:
            self.bot.logger.error("Error when fetching Pushbullet API key!")
            raise

    def shouldTrigger(self, message):
        """
        @type message: hubbot.message.IRCMessage
        """
        if message.Type in self.acceptedTypes:
            for IRCUser in message.Channel.Users:
                userMatch = re.search(self.regexPattern, IRCUser.Name, re.IGNORECASE)
                if userMatch:
                    match = re.search(self.regexPattern, message.MessageString, re.IGNORECASE)
                    if match:
                        return True
                    else:
                        return False
                else:
                    continue
            return False

    def onTrigger(self, message):
        """
        @type message: hubbot.message.IRCMessage
        """
        try:
            self.pb.refresh()
            phone = self.getDeviceByName("phone")
            push = phone.push_note("Highlight in {}".format(message.Channel.Name), "<{}> {}".format(message.User.Name, message.MessageString))
        except:
            self.bot.logger.exception("Highlighting pushbullet push failed.")
        else:
            if "error" in push:
                self.bot.logger.error("Pushbullet returned error '{}'".format(push["error"]["type"]))

    def getDeviceByName(self, deviceName):
{'fraction_non_alphanumeric': 0.09499408750492708, 'fraction_numerical': 0.0011824990145841545, 'mean_word_length': 1.773224043715847, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1844332', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1279, 'n_words': 357}