Beispiel #1
0
    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()
Beispiel #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"))
Beispiel #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
Beispiel #4
0
    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=""))
Beispiel #5
0
 def test_user(self):
     name = "hoge"
     message = Speaker(name=name)
     self.assertEqual(message.name, name)
Beispiel #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")))
Beispiel #7
0
 def test_dict(self):
     speaker = Speaker(name="太郎")
     self.assertEqual(speaker.dict(), {"name": "太郎"})
Beispiel #8
0
    def test_from_dict(self):
        dic = {"name": "太郎"}

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