当前位置: 首页>>代码示例>>Python>>正文


Python bot.Bot方法代码示例

本文整理汇总了Python中bot.Bot方法的典型用法代码示例。如果您正苦于以下问题:Python bot.Bot方法的具体用法?Python bot.Bot怎么用?Python bot.Bot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bot的用法示例。


在下文中一共展示了bot.Bot方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUpClass

# 需要导入模块: import bot [as 别名]
# 或者: from bot import Bot [as 别名]
def setUpClass(cls):
        DEFAULTS["ADMINS"] = BaseSettings.DEFAULT_ADMINS
        BotSettings.DEFAULT_ADMINS = BaseSettings.DEFAULT_ADMINS

        BotSettings.PLUGINS = (
            StoragePlugin(in_memory=True), CalculatorPlugin(),
            StaffControlPlugin(admins=(2,), set_admins=True), AboutPlugin(),
            TimePlugin(), NoQueuePlugin(), ChatControlPlugin(banned=(100,)),
        )

        cls.bot = Bot(BotSettings)
        cls.user_id = cls.bot.api.get_current_id()

        cls._answer = Message.answer
        cls.messages = []

        async def answer(self, message="", **kwargs):
            cls.messages.append(message)

        Message.answer = answer 
开发者ID:ekonda,项目名称:sketal,代码行数:22,代码来源:tests.py

示例2: make_bot

# 需要导入模块: import bot [as 别名]
# 或者: from bot import Bot [as 别名]
def make_bot(remote=None):
  return bot.Bot(remote, {'dimensions': {
      'id': ['bot1'],
      'pool': ['private']
  }}, 'https://localhost:1', '1234-1a2b3c4-tainted-joe', 'base_dir', None) 
开发者ID:luci,项目名称:luci-py,代码行数:7,代码来源:bot_test.py

示例3: pre_install

# 需要导入模块: import bot [as 别名]
# 或者: from bot import Bot [as 别名]
def pre_install():
    """This route renders the installation page with 'Add to Slack' button."""
    # Since we've set the client ID and scope on our Bot object, we can change
    # them more easily while we're developing our app.
    client_id = pyBot.oauth["client_id"]
    scope = pyBot.oauth["scope"]
    # Our template is using the Jinja templating language to dynamically pass
    # our client id and scope
    return render_template("install.html", client_id=client_id, scope=scope) 
开发者ID:slackapi,项目名称:Slack-Python-Onboarding-Tutorial,代码行数:11,代码来源:app.py

示例4: hears

# 需要导入模块: import bot [as 别名]
# 或者: from bot import Bot [as 别名]
def hears():
    """
    This route listens for incoming events from Slack and uses the event
    handler helper function to route events to our Bot.
    """
    slack_event = request.get_json()

    # ============= Slack URL Verification ============ #
    # In order to verify the url of our endpoint, Slack will send a challenge
    # token in a request and check for this token in the response our endpoint
    # sends back.
    #       For more info: https://api.slack.com/events/url_verification
    if "challenge" in slack_event:
        return make_response(slack_event["challenge"], 200, {"content_type":
                                                             "application/json"
                                                             })

    # ============ Slack Token Verification =========== #
    # We can verify the request is coming from Slack by checking that the
    # verification token in the request matches our app's settings
    if pyBot.verification != slack_event.get("token"):
        message = "Invalid Slack verification token: %s \npyBot has: \
                   %s\n\n" % (slack_event["token"], pyBot.verification)
        # By adding "X-Slack-No-Retry" : 1 to our response headers, we turn off
        # Slack's automatic retries during development.
        make_response(message, 403, {"X-Slack-No-Retry": 1})

    # ====== Process Incoming Events from Slack ======= #
    # If the incoming request is an Event we've subscribed to
    if "event" in slack_event:
        event_type = slack_event["event"]["type"]
        # Then handle the event by event_type and have your bot respond
        return _event_handler(event_type, slack_event)
    # If our bot hears things that are not events we've subscribed to,
    # send a quirky but helpful error response
    return make_response("[NO EVENT IN SLACK REQUEST] These are not the droids\
                         you're looking for.", 404, {"X-Slack-No-Retry": 1}) 
开发者ID:slackapi,项目名称:Slack-Python-Onboarding-Tutorial,代码行数:39,代码来源:app.py

示例5: run

# 需要导入模块: import bot [as 别名]
# 或者: from bot import Bot [as 别名]
def run(self, logger):
        bot = Bot(logger)
        if not bot.error:
            bot.run() 
开发者ID:oliverjrose99,项目名称:Recordurbate,代码行数:6,代码来源:daemon.py

示例6: test_loading

# 需要导入模块: import bot [as 别名]
# 或者: from bot import Bot [as 别名]
def test_loading(self):
        logger = logging.getLogger()

        with self.assertLogs(logger, level='INFO') as cm:
            self.bot = Bot(BotSettings, logger=logger)

        self.assertIn(f'INFO:{self.bot.logger.name}:Initializing bot', cm.output)
        self.assertIn(f'INFO:{self.bot.logger.name}:Initializing vk clients', cm.output)
        self.assertIn(f'INFO:{self.bot.logger.name}:Loading plugins', cm.output) 
开发者ID:ekonda,项目名称:sketal,代码行数:11,代码来源:tests.py

示例7: test_get_pseudo_rand

# 需要导入模块: import bot [as 别名]
# 或者: from bot import Bot [as 别名]
def test_get_pseudo_rand(self):
    # This test assumes little endian.
    # The following confirms the equivalent code in Bot.get_pseudo_rand():
    self.assertEqual(-1., round(struct.unpack('h', b'\x00\x80')[0] / 32768., 4))
    self.assertEqual(1., round(struct.unpack('h', b'\xff\x7f')[0] / 32768., 4))
    b = make_bot()
    self.assertEqual(-0.7782, b.get_pseudo_rand(1.))
    self.assertEqual(-0.0778, b.get_pseudo_rand(.1)) 
开发者ID:luci,项目名称:luci-py,代码行数:10,代码来源:bot_test.py

示例8: startGame

# 需要导入模块: import bot [as 别名]
# 或者: from bot import Bot [as 别名]
def startGame(self):
        logging.info("Starting positions")
        self.bots["black"] = Bot("green", 6, 1, Directions.north)
        self.bots["blue"] = Bot("blue", 1, 1, Directions.north)
        self.bots["white"] = Bot("white", 6, 6, Directions.south)
        self.bots["red"] =  Bot("red", 1, 6, Directions.south)
        for bot in self.bots:
            logging.info(f"{bot} x: {self.bots[bot].position.x}, y: {self.bots[bot].position.y}") 
开发者ID:aws-samples,项目名称:aws-builders-fair-projects,代码行数:10,代码来源:game.py

示例9: _event_handler

# 需要导入模块: import bot [as 别名]
# 或者: from bot import Bot [as 别名]
def _event_handler(event_type, slack_event):
    """
    A helper function that routes events from Slack to our Bot
    by event type and subtype.

    Parameters
    ----------
    event_type : str
        type of event received from Slack
    slack_event : dict
        JSON response from a Slack reaction event

    Returns
    ----------
    obj
        Response object with 200 - ok or 500 - No Event Handler error

    """
    team_id = slack_event["team_id"]
    # ================ Team Join Events =============== #
    # When the user first joins a team, the type of event will be team_join
    if event_type == "team_join":
        user_id = slack_event["event"]["user"]["id"]
        # Send the onboarding message
        pyBot.onboarding_message(team_id, user_id)
        return make_response("Welcome Message Sent", 200,)

    # ============== Share Message Events ============= #
    # If the user has shared the onboarding message, the event type will be
    # message. We'll also need to check that this is a message that has been
    # shared by looking into the attachments for "is_shared".
    elif event_type == "message" and slack_event["event"].get("attachments"):
        user_id = slack_event["event"].get("user")
        if slack_event["event"]["attachments"][0].get("is_share"):
            # Update the onboarding message and check off "Share this Message"
            pyBot.update_share(team_id, user_id)
            return make_response("Welcome message updates with shared message",
                                 200,)

    # ============= Reaction Added Events ============= #
    # If the user has added an emoji reaction to the onboarding message
    elif event_type == "reaction_added":
        user_id = slack_event["event"]["user"]
        # Update the onboarding message
        pyBot.update_emoji(team_id, user_id)
        return make_response("Welcome message updates with reactji", 200,)

    # =============== Pin Added Events ================ #
    # If the user has added an emoji reaction to the onboarding message
    elif event_type == "pin_added":
        user_id = slack_event["event"]["user"]
        # Update the onboarding message
        pyBot.update_pin(team_id, user_id)
        return make_response("Welcome message updates with pin", 200,)

    # ============= Event Type Not Found! ============= #
    # If the event_type does not have a handler
    message = "You have not added an event handler for the %s" % event_type
    # Return a helpful error message
    return make_response(message, 200, {"X-Slack-No-Retry": 1}) 
开发者ID:slackapi,项目名称:Slack-Python-Onboarding-Tutorial,代码行数:62,代码来源:app.py


注:本文中的bot.Bot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。