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


Python Bot.add_sentence方法代码示例

本文整理汇总了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
开发者ID:PythonHamilton,项目名称:august-bot,代码行数:12,代码来源:test_bot.py

示例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"):
开发者ID:PythonHamilton,项目名称:august-bot,代码行数:33,代码来源:server.py

示例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
开发者ID:PythonHamilton,项目名称:august-bot,代码行数:7,代码来源:test_bot.py

示例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?")
开发者ID:PythonHamilton,项目名称:python-hamilton,代码行数:29,代码来源:server.py


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