コード例 #1
0
ファイル: bot.py プロジェクト: kenkov/kovot
    def __init__(self,
                 mods,
                 speaker=None,
                 preprocessor=None,
                 response_selector=None,
                 postprocessor=None):

        self.module_manager = ModManager(mods=mods)

        if not speaker:
            from kovot.speaker import Speaker
            speaker = Speaker(name="bot")

        if not preprocessor:
            from kovot.message import MessageTransformer
            preprocessor = MessageTransformer()

        if not response_selector:
            from kovot.response import ResponseSelector
            response_selector = ResponseSelector()

        if not postprocessor:
            from kovot.response import ResponseTransformer
            postprocessor = ResponseTransformer()

        self.speaker = speaker
        self.response_selector = response_selector
        self.preprocessor = preprocessor
        self.postprocessor = postprocessor

        # debug
        self.module_manager.show_mods()
コード例 #2
0
    def from_dict(cls, dic):
        # convert to Speaker and Message object from dictionary
        if dic.get("speaker"):
            speaker = Speaker.from_dict(dic["speaker"])
        else:
            speaker = None
        if dic.get("message"):
            message = Speaker.from_dict(dic["message"])
        else:
            message = None

        return cls(text=dic["text"],
                   score=dic["score"],
                   id_=dic.get("id_"),
                   speaker=speaker,
                   message=message,
                   source=dic.get("source"))
コード例 #3
0
    def from_dict(cls, dic):
        speaker = dic.get("speaker")
        if speaker:
            speaker = Speaker.from_dict(speaker)

        m = Message(text=dic["text"],   
                    id_=dic.get("id_"),
                    speaker=speaker)
        return m
コード例 #4
0
ファイル: slack.py プロジェクト: kenkov/kovot
    def __next__(self):
        while True:
            try:
                reses = self.sc.rtm_read()
            except:
                traceback.print_exc()
                self.sc.rtm_connect()

            if reses:
                for item in reses:
                    name = self.id2name.get(item.get("user", None), None)
                    if (item["type"] == "message" and
                            name != self.name):
                        self.messages.append(item)
            if self.messages:
                break
            time.sleep(1)
        mess = self.messages.popleft()
        return Message(text=self._get_text(mess),
                       speaker=Speaker(name=""))
コード例 #5
0
ファイル: test_user.py プロジェクト: kenkov/kovot
 def test_user(self):
     name = "hoge"
     message = Speaker(name=name)
     self.assertEqual(message.name, name)
コード例 #6
0
 def test_from_dict_arg_speaker(self):
     d = {"text": "テスト", "speaker": {"name": "bot"}}
     self.assertEqual(Message.from_dict(d),
                      Message(text="テスト", speaker=Speaker(name="bot")))
コード例 #7
0
 def test_dict(self):
     speaker = Speaker(name="太郎")
     self.assertEqual(speaker.dict(), {"name": "太郎"})
コード例 #8
0
    def test_from_dict(self):
        dic = {"name": "太郎"}

        self.assertEqual(Speaker.from_dict(dic), Speaker(name="太郎"))
コード例 #9
0
 def __next__(self):
     ipt = sys.stdin.readline().strip("\n")
     return Message(text=ipt, speaker=Speaker(name="You"))