예제 #1
0
 def __init__(self, pattern, view, pre_process, \
              hook_pattern=None, save_context=True):
     self.pre_process = pre_process
     self.context = ""
     self.conversation = hook_pattern
     self.save_context = save_context
     Pattern.__init__(self, pattern, view)
예제 #2
0
def test_pattern_check_wrong_message():
    '''
    Check if Pattern class returns False when message doesn't
    check with pattern.
    '''
    view = lambda: 'Hello world'
    pattern = Pattern('ping', view)
    message = type('Message', (object, ), {'text': 'pong'})
    assert not pattern.check(message)
예제 #3
0
def test_pattern_check_right_message():
    '''
    Check if Pattern class return the view when message checks with
    pattern.
    '''
    view = lambda: 'Hello world'
    pattern = Pattern('ping', view)
    message = type('Message', (object, ), {'text': 'ping'})
    result = pattern.check(message)
    assert result == view
예제 #4
0
def test_pattern_instance():
    def view():
        return 'Hello world'

    pattern = Pattern('ping', view)
    assert pattern.pattern == 'ping'
    assert pattern.view == view
예제 #5
0
 def __init__(self):
     self._pattern = None
     Pattern.__init__(self, "", None)
예제 #6
0
 def __init__(self, pattern, view, pre_process):
     self.pre_process = pre_process
     Pattern.__init__(self, pattern, view)
예제 #7
0
        if self._pattern is None:
            return False
        return self._pattern.check(message)

    def begin_hook(self, apattern):
        '''Pass the pattern that will begin a conversation'''
        self._pattern = apattern

    def end_hook(self):
        '''Releases pointer to Pattern ending a conversation'''
        self._pattern = None

    def has_hook(self):
        '''Return if hook is active'''
        return self._pattern is None


conversation = HookPattern()
patterns = [
    conversation,
    Pattern('ping', ping),
    Pattern('help', help_text),
    Pattern('log', list_log),
    FuncPattern('cc', consulta_conteiner, two_tokens),
    FuncPattern('ll', consulta_lacre, two_tokens),
    HookableFuncPattern('llhook', consulta_lacre, two_tokens, conversation),
    FuncPattern('report', report_api, two_tokens),
    Pattern('teste', works),
    DefaultPattern(say_help)
]
예제 #8
0
def test_pattern_instance():
    view = lambda: 'Hello world'
    pattern = Pattern('ping', view)
    assert pattern.pattern == 'ping'
    assert pattern.view == view
예제 #9
0
from bottery.conf.patterns import Pattern, DefaultPattern
from bottery.views import pong
from views import hello, greetings, not_found

patterns = [
    Pattern('ping', pong),
    Pattern('hello', hello),
    Pattern('olá', greetings),
    DefaultPattern(not_found),
]
예제 #10
0
from bottery.conf.patterns import Pattern, DefaultPattern
from bottery.views import pong
from views import hello, hello_world, not_found




patterns = [
    Pattern('ping', pong),
    Pattern('hi bot', hello),
    Pattern('hello', hello_world),
    DefaultPattern(not_found),
]
예제 #11
0
    HookableFuncPattern, HookPattern
from bottery.views import pong, access_api_rules
from views import help_text, say_help, END_HOOK_LIST, two_tokens


rules = {'tec': {'rank': 'http://brasilico.pythonanywhere.com/_rank?words=',
                 'filtra':
                  'http://brasilico.pythonanywhere.com/_filter_documents?afilter=',
                 'capitulo':
                  'http://brasilico.pythonanywhere.com/_document_content/',
                 '_message': 'Informe o comando: '
                }
        }

 
rules_cep = {'cep': {'busca': 'http://api.postmon.com.br/v1/cep/',
                     '_message': 'Informe o comando: '
                }
        }


conversation = HookPattern(END_HOOK_LIST)
patterns = [
    conversation,
    Pattern('ping', pong),
    Pattern('help', help_text),
    HookableFuncPattern('tec', access_api_rules, two_tokens, conversation, rules=rules),
    HookableFuncPattern('cep', access_api_rules, two_tokens, conversation, rules=rules_cep),
    DefaultPattern(say_help)
]
 
예제 #12
0
from bottery.conf.patterns import DefaultPattern, Pattern
from bottery.message import render
from bottery.views import ping


def hello(message):
    return render(message, 'hello.md')


def not_found(message):
    return "Sorry, I didn't understand you :/"


patterns = [
    Pattern('ping', ping),
    Pattern('hello', hello),
    DefaultPattern(not_found),
]
예제 #13
0
hang_user_pattern_notebook = HangUserPattern(notebook_view)
hang_user_pattern_note = HangUserPattern(note_view)
hang_user_pattern_input = HangUserPattern(input_example)

ch.set_hang(hang_user_pattern, 'person')
ch.set_hang(hang_user_pattern_tec, 'tec')
ch.set_hang(hang_user_pattern_notebook, 'notebook')
ch.set_hang(hang_user_pattern_note, 'note')
ih.set_hang(hang_user_pattern_input, 'project')


def first_word(pattern, text):
    words = text.split(' ')
    if words:
        return words[0] == pattern
    return False


patterns = [
    hang_user_pattern, hang_user_pattern_tec, hang_user_pattern_notebook,
    hang_user_pattern_note, hang_user_pattern_input,
    Pattern('tec', tec_view),
    Pattern('person', flask_restless_view),
    FunctionPattern('notebook', notebook_view, first_word),
    FunctionPattern('note', note_view, first_word),
    Pattern('project', input_example),
    Pattern('ping', pong),
    Pattern('help', help_text),
    DefaultPattern(say_help)
]