本文整理汇总了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
示例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)
示例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)
示例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})
示例5: run
# 需要导入模块: import bot [as 别名]
# 或者: from bot import Bot [as 别名]
def run(self, logger):
bot = Bot(logger)
if not bot.error:
bot.run()
示例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)
示例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))
示例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}")
示例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})