示例#1
0
 def initialize(self, bot_handler: BotHandler) -> None:
     self.config_info = bot_handler.get_config_info('twitter')
     auth = tweepy.OAuthHandler(self.config_info['consumer_key'],
                                self.config_info['consumer_secret'])
     auth.set_access_token(self.config_info['access_token'],
                           self.config_info['access_token_secret'])
     self.api = tweepy.API(auth, parser=tweepy.parsers.JSONParser())
示例#2
0
    def initialize(self, bot_handler: BotHandler) -> None:
        self.config_info = bot_handler.get_config_info("baremetrics")
        self.api_key = self.config_info["api_key"]

        self.auth_header = {"Authorization": "Bearer " + self.api_key}

        self.commands = [
            "help",
            "list-commands",
            "account-info",
            "list-sources",
            "list-plans <source_id>",
            "list-customers <source_id>",
            "list-subscriptions <source_id>",
            "create-plan <source_id> <oid> <name> <currency> <amount> <interval> <interval_count>",
        ]

        self.descriptions = [
            "Display bot info",
            "Display the list of available commands",
            "Display the account info",
            "List the sources",
            "List the plans for the source",
            "List the customers in the source",
            "List the subscriptions in the source",
            "Create a plan in the given source",
        ]

        self.check_api_key(bot_handler)
示例#3
0
    def initialize(self, bot_handler: BotHandler) -> None:
        config = bot_handler.get_config_info('front')
        api_key = config.get('api_key')
        if not api_key:
            raise KeyError("No API key specified.")

        self.auth = "Bearer " + api_key
示例#4
0
    def initialize(self, bot_handler: BotHandler) -> None:
        config = bot_handler.get_config_info("jira")

        username = config.get("username")
        password = config.get("password")
        domain = config.get("domain")
        if not username:
            raise KeyError("No `username` was specified")
        if not password:
            raise KeyError("No `password` was specified")
        if not domain:
            raise KeyError("No `domain` was specified")

        self.auth = make_jira_auth(username, password)

        # Allow users to override the HTTP scheme
        if re.match(r"^https?://", domain, re.IGNORECASE):
            self.domain_with_protocol = domain
        else:
            self.domain_with_protocol = "https://" + domain

        # Use the front facing URL in output
        self.display_url = config.get("display_url")
        if not self.display_url:
            self.display_url = self.domain_with_protocol
示例#5
0
    def initialize(self, bot_handler: BotHandler) -> None:
        global api_key, default_team
        self.config_info = bot_handler.get_config_info("idonethis")
        if "api_key" in self.config_info:
            api_key = self.config_info["api_key"]
        else:
            logging.error("An API key must be specified for this bot to run.")
            logging.error(
                "Have a look at the Setup section of my documenation for more information."
            )
            bot_handler.quit()

        if "default_team" in self.config_info:
            default_team = self.config_info["default_team"]
        else:
            logging.error(
                "Cannot find default team. Users will need to manually specify a team each time an entry is created."
            )

        try:
            api_noop()
        except AuthenticationException:
            logging.error(
                "Authentication exception with idonethis. Can you check that your API keys are correct? "
            )
            bot_handler.quit()
        except UnspecifiedProblemException:
            logging.error(
                "Problem connecting to idonethis. Please check connection")
            bot_handler.quit()
示例#6
0
    def initialize(self, bot_handler: BotHandler) -> None:
        config = bot_handler.get_config_info('jira')

        username = config.get('username')
        password = config.get('password')
        domain = config.get('domain')
        if not username:
            raise KeyError('No `username` was specified')
        if not password:
            raise KeyError('No `password` was specified')
        if not domain:
            raise KeyError('No `domain` was specified')

        self.auth = make_jira_auth(username, password)

        # Allow users to override the HTTP scheme
        if re.match(r'^https?://', domain, re.IGNORECASE):
            self.domain_with_protocol = domain
        else:
            self.domain_with_protocol = 'https://' + domain

        # Use the front facing URL in output
        self.display_url = config.get('display_url')
        if not self.display_url:
            self.display_url = self.domain_with_protocol
示例#7
0
    def initialize(self, bot_handler: BotHandler) -> None:
        self.config_info = bot_handler.get_config_info('trello')
        self.api_key = self.config_info['api_key']
        self.access_token = self.config_info['access_token']
        self.user_name = self.config_info['user_name']

        self.auth_params = {'key': self.api_key, 'token': self.access_token}

        self.check_access_token(bot_handler)
示例#8
0
    def initialize(self, bot_handler: BotHandler) -> None:
        self.config_info = bot_handler.get_config_info("trello")
        self.api_key = self.config_info["api_key"]
        self.access_token = self.config_info["access_token"]
        self.user_name = self.config_info["user_name"]

        self.auth_params = {"key": self.api_key, "token": self.access_token}

        self.check_access_token(bot_handler)
示例#9
0
    def initialize(self, bot_handler: BotHandler) -> None:
        self.config_info = bot_handler.get_config_info("chess")

        try:
            self.engine = chess.engine.SimpleEngine.popen_uci(
                self.config_info["stockfish_location"])
        except FileNotFoundError:
            # It is helpful to allow for fake Stockfish locations if the bot
            # runner is testing or knows they won't be using an engine.
            print("That Stockfish doesn't exist. Continuing.")
示例#10
0
    def initialize(self, bot_handler: BotHandler) -> None:
        self.config_info = bot_handler.get_config_info('chess')

        try:
            self.engine = chess.uci.popen_engine(
                self.config_info['stockfish_location'])
            self.engine.uci()
        except FileNotFoundError:
            # It is helpful to allow for fake Stockfish locations if the bot
            # runner is testing or knows they won't be using an engine.
            print('That Stockfish doesn\'t exist. Continuing.')
示例#11
0
 def initialize(self, bot_handler: BotHandler) -> None:
     self.config_info = bot_handler.get_config_info("salesforce")
     try:
         self.sf = simple_salesforce.Salesforce(
             username=self.config_info["username"],
             password=self.config_info["password"],
             security_token=self.config_info["security_token"],
         )
     except simple_salesforce.exceptions.SalesforceAuthenticationFailed as err:
         bot_handler.quit(
             f"Failed to log in to Salesforce. {err.code} {err.message}")
示例#12
0
 def initialize(self, bot_handler: BotHandler) -> None:
     self.config_info = bot_handler.get_config_info('beeminder')
     # Check for valid auth_token
     auth_token = self.config_info['auth_token']
     try:
         r = requests.get("https://www.beeminder.com/api/v1/users/me.json",
                          params={'auth_token': auth_token})
         if r.status_code == 401:
             bot_handler.quit('Invalid key!')
     except ConnectionError as e:
         logging.exception(str(e))
示例#13
0
 def initialize(self, bot_handler: BotHandler) -> None:
     self.config_info = bot_handler.get_config_info("youtube")
     # Check if API key is valid. If it is not valid, don't run the bot.
     try:
         search_youtube("test", self.config_info["key"], self.config_info["video_region"])
     except HTTPError as e:
         if e.response.json()["error"]["errors"][0]["reason"] == "keyInvalid":
             bot_handler.quit(
                 "Invalid key." "Follow the instructions in doc.md for setting API key."
             )
         else:
             raise
     except ConnectionError:
         logging.warning("Bad connection")
示例#14
0
 def initialize(self, bot_handler: BotHandler) -> None:
     self.config_info = bot_handler.get_config_info('youtube')
     # Check if API key is valid. If it is not valid, don't run the bot.
     try:
         search_youtube('test', self.config_info['key'],
                        self.config_info['video_region'])
     except HTTPError as e:
         if (e.response.json()['error']['errors'][0]['reason'] ==
                 'keyInvalid'):
             bot_handler.quit(
                 'Invalid key.'
                 'Follow the instructions in doc.md for setting API key.')
         else:
             raise
     except ConnectionError:
         logging.warning('Bad connection')
示例#15
0
    def initialize(self, bot_handler: BotHandler) -> None:
        self.config_info = bot_handler.get_config_info('baremetrics')
        self.api_key = self.config_info['api_key']

        self.auth_header = {'Authorization': 'Bearer ' + self.api_key}

        self.commands = [
            'help', 'list-commands', 'account-info', 'list-sources',
            'list-plans <source_id>', 'list-customers <source_id>',
            'list-subscriptions <source_id>',
            'create-plan <source_id> <oid> <name> <currency> <amount> <interval> <interval_count>'
        ]

        self.descriptions = [
            'Display bot info', 'Display the list of available commands',
            'Display the account info', 'List the sources',
            'List the plans for the source',
            'List the customers in the source',
            'List the subscriptions in the source',
            'Create a plan in the given source'
        ]

        self.check_api_key(bot_handler)
示例#16
0
    def initialize(self, bot_handler: BotHandler) -> None:
        config = bot_handler.get_config_info("witai")

        token = config.get("token")
        if not token:
            raise KeyError("No `token` was specified")

        # `handler_location` should be the location of a module which contains
        # the function `handle`. See `doc.md` for more details.
        handler_location = config.get("handler_location")
        if not handler_location:
            raise KeyError("No `handler_location` was specified")
        handle = get_handle(handler_location)
        if handle is None:
            raise Exception("Could not get handler from handler_location.")
        else:
            self.handle = handle

        help_message = config.get("help_message")
        if not help_message:
            raise KeyError("No `help_message` was specified")
        self.help_message = help_message

        self.client = wit.Wit(token)
示例#17
0
    def initialize(self, bot_handler: BotHandler) -> None:
        try:
            self.config = bot_handler.get_config_info("monkeytestit")
        except NoBotConfigException:
            bot_handler.quit("Quitting because there's no config file "
                             "supplied. See doc.md for a guide on setting up "
                             "one. If you already know the drill, just create "
                             'a .conf file with "monkeytestit" as the '
                             "section header and api_key = <your key> for "
                             "the api key.")

        self.api_key = self.config.get("api_key")

        if not self.api_key:
            bot_handler.quit("Config file exists, but can't find api_key key "
                             "or value. Perhaps it is misconfigured. Check "
                             "doc.md for details on how to setup the config.")

        logging.info("Checking validity of API key. This will take a while.")

        if "wrong secret" in parse.execute("check https://website",
                                           self.api_key).lower():
            bot_handler.quit("API key exists, but it is not valid. Reconfigure"
                             " your api_key value and try again.")
示例#18
0
 def initialize(self, bot_handler: BotHandler) -> None:
     self.config_info = bot_handler.get_config_info('dropbox_share')
     self.ACCESS_TOKEN = self.config_info.get('access_token')
     self.client = Dropbox(self.ACCESS_TOKEN)
示例#19
0
 def initialize(self, bot_handler: BotHandler) -> None:
     self.config_info = bot_handler.get_config_info("link_shortener")
     self.check_api_key(bot_handler)
示例#20
0
 def initialize(self, bot_handler: BotHandler) -> None:
     self.config_info = bot_handler.get_config_info("followup", optional=False)
     self.stream = self.config_info.get("stream", "followup")
示例#21
0
 def initialize(self, bot_handler: BotHandler) -> None:
     self.api_key = bot_handler.get_config_info('weather')['key']
     self.response_pattern = 'Weather in {}, {}:\n{:.2f} F / {:.2f} C\n{}'
     self.check_api_key(bot_handler)
示例#22
0
 def initialize(self, bot_handler: BotHandler) -> None:
     self.api_key = bot_handler.get_config_info("yoda")["api_key"]
示例#23
0
    def initialize(self, bot_handler: BotHandler) -> None:
        self.config_info = bot_handler.get_config_info('mention')
        self.access_token = self.config_info['access_token']
        self.account_id = ''

        self.check_access_token(bot_handler)
示例#24
0
 def initialize(self, bot_handler: BotHandler) -> None:
     self.config_info = bot_handler.get_config_info('github_detail',
                                                    optional=True)
     self.owner = self.config_info.get("owner", False)
     self.repo = self.config_info.get("repo", False)
示例#25
0
 def initialize(self, bot_handler: BotHandler) -> None:
     self.api_key = bot_handler.get_config_info('yoda')['api_key']
示例#26
0
 def initialize(self, bot_handler: BotHandler) -> None:
     self.config_info = bot_handler.get_config_info('giphy')
示例#27
0
 def initialize(self, bot_handler: BotHandler) -> None:
     self.config_info = bot_handler.get_config_info("dialogflow")
示例#28
0
    def initialize(self, bot_handler: BotHandler) -> None:
        self.config_info = bot_handler.get_config_info("mention")
        self.access_token = self.config_info["access_token"]
        self.account_id = ""

        self.check_access_token(bot_handler)
示例#29
0
 def initialize(self, bot_handler: BotHandler) -> None:
     self.api_key = bot_handler.get_config_info("weather")["key"]
     self.response_pattern = "Weather in {}, {}:\n{:.2f} F / {:.2f} C\n{}"
     self.check_api_key(bot_handler)