本文整理汇总了Python中bot.Bot.add_sentence方法的典型用法代码示例。如果您正苦于以下问题:Python Bot.add_sentence方法的具体用法?Python Bot.add_sentence怎么用?Python Bot.add_sentence使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bot.Bot
的用法示例。
在下文中一共展示了Bot.add_sentence方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_sentence
# 需要导入模块: from bot import Bot [as 别名]
# 或者: from bot.Bot import add_sentence [as 别名]
def test_add_sentence():
bot = Bot()
sentence = "The cat in the hat"
bot.add_sentence(sentence)
expected_monte_carlo = {
'The cat': ['in'],
'cat in': ['the'],
'in the': ['hat']
}
assert bot.monte_carlo == expected_monte_carlo
示例2: Bot
# 需要导入模块: from bot import Bot [as 别名]
# 或者: from bot.Bot import add_sentence [as 别名]
import time
from slackclient import SlackClient
from bot import Bot
bot = Bot()
with open('history.txt', 'r') as fh:
for line in fh:
bot.add_sentence(line.strip())
token = "GET YOUR OWN TOKEN" # found at https://api.slack.com/web#authentication
sc = SlackClient(token)
fh = open('history.txt', 'a')
if sc.rtm_connect():
while True:
evts = sc.rtm_read()
for evt in evts:
if evt["type"] == "message" and "text" in evt:
if evt["text"].lower().startswith("hey bot"):
sc.api_call("chat.postMessage",
channel="#general",
text=bot.get_sentence(),
username="august_bot",
icon_emoji=":robot_face:")
else:
if "subtype" not in evt or ("subtype" in evt and evt["subtype"] != "bot_message"):
示例3: test_create_sentence
# 需要导入模块: from bot import Bot [as 别名]
# 或者: from bot.Bot import add_sentence [as 别名]
def test_create_sentence():
bot = Bot()
sentence = "The cat in the hat"
bot.add_sentence(sentence)
assert bot.create_sentence(20) is not None
示例4: Bot
# 需要导入模块: from bot import Bot [as 别名]
# 或者: from bot.Bot import add_sentence [as 别名]
import time
from slackclient import SlackClient
from bot import Bot
bot = Bot()
token = "GET YOUR OWN TOKEN" # found at https://api.slack.com/web#authentication
sc = SlackClient(token)
if sc.rtm_connect():
while True:
evts = sc.rtm_read()
for evt in evts:
if evt['type'] == 'message' and 'text' in evt:
if evt['text'].lower().startswith('hey bot'):
sc.api_call("chat.postMessage", channel="#general", text=bot.get_sentence(), username='august_bot', icon_emoji=':robot_face:')
else:
if 'subtype' not in evt or ('subtype' in evt and evt['subtype'] != 'bot_message'):
bot.add_sentence(evt['text'])
time.sleep(1)
else:
print("Connection Failed, invalid token?")