2022-06-14 21:51:44 +02:00
|
|
|
from apimock import *
|
|
|
|
|
2022-06-08 12:09:36 +02:00
|
|
|
gramar_slots = {
|
|
|
|
'pullrequest': (('action', 'optional'),
|
|
|
|
('repo', 'required')
|
|
|
|
),
|
|
|
|
'brefing': (('action', 'optional'),
|
|
|
|
('repo', 'required')
|
|
|
|
),
|
|
|
|
'notifications': (('liczba', 'optional'),
|
2022-06-14 21:51:44 +02:00
|
|
|
('repo', 'required')
|
2022-06-08 12:09:36 +02:00
|
|
|
),
|
|
|
|
'tests': (('test', 'optional'),
|
2022-06-14 21:51:44 +02:00
|
|
|
('repo', 'required')
|
2022-06-08 12:09:36 +02:00
|
|
|
),
|
|
|
|
'time': (('time_when', 'required'),
|
2022-06-14 21:51:44 +02:00
|
|
|
('timeunit', 'required'),
|
|
|
|
('liczba','optional')
|
|
|
|
),
|
|
|
|
'issues': (('time_when','optional'),
|
|
|
|
('liczba','optional'),
|
|
|
|
('timeunit','optional'),
|
|
|
|
('repozytoria', 'required')
|
|
|
|
),
|
|
|
|
'number': (('liczba', 'required')
|
|
|
|
),
|
|
|
|
'help': (('functions', 'optional'),
|
|
|
|
('help', 'optional')
|
2022-06-08 12:09:36 +02:00
|
|
|
),
|
2022-06-14 21:51:44 +02:00
|
|
|
'repo': (('repozytoria', 'required')
|
2022-06-08 12:09:36 +02:00
|
|
|
),
|
2022-06-14 21:51:44 +02:00
|
|
|
'hello': (),
|
|
|
|
'bye': (),
|
2022-06-08 12:09:36 +02:00
|
|
|
}
|
|
|
|
|
2022-04-19 23:22:44 +02:00
|
|
|
|
2022-06-08 10:23:01 +02:00
|
|
|
def taktyka_dialogu(state, frame):
|
2022-06-08 12:09:36 +02:00
|
|
|
if frame['act'] == 'null':
|
|
|
|
return 'null'
|
2022-06-15 08:48:04 +02:00
|
|
|
# if state['current_context'] in ['hello', 'pomoc', 'bye']:
|
|
|
|
# return short_thread(state)
|
|
|
|
# else:
|
|
|
|
return long_thread(state)
|
2022-04-19 23:22:44 +02:00
|
|
|
|
2022-06-15 08:48:04 +02:00
|
|
|
# def short_thread(state):
|
|
|
|
# if state['current_context'] == 'pomoc':
|
|
|
|
# return state['current_context']
|
|
|
|
# else:
|
|
|
|
# return state['current_context']
|
2022-04-19 23:22:44 +02:00
|
|
|
|
2022-06-14 21:51:44 +02:00
|
|
|
def validate_repo(repo):
|
|
|
|
if repo not in listRepositories():
|
2022-06-15 00:02:44 +02:00
|
|
|
return 'repo not in listRepositories'
|
2022-06-14 21:51:44 +02:00
|
|
|
if repo not in listPublicRepositories():
|
2022-06-15 00:02:44 +02:00
|
|
|
return 'repo not in listPublicRepositories'
|
2022-06-14 21:51:44 +02:00
|
|
|
|
2022-06-08 10:23:01 +02:00
|
|
|
def long_thread(state):
|
2022-06-08 12:09:36 +02:00
|
|
|
act = state['current_context']
|
2022-06-15 08:47:39 +02:00
|
|
|
if act == None:
|
|
|
|
return 'null'
|
2022-06-08 12:09:36 +02:00
|
|
|
for topic in state['topics']:
|
|
|
|
if act == topic['act']:
|
|
|
|
slots = topic['slots']
|
|
|
|
required = gramar_slots[act]
|
2022-06-14 21:51:44 +02:00
|
|
|
req_args, opt_args = agregate(required, slots)
|
2022-06-15 08:48:04 +02:00
|
|
|
facts = state['facts']
|
2022-06-14 21:51:44 +02:00
|
|
|
req_args = add_facts(req_args, facts)
|
|
|
|
opt_args = add_facts(opt_args, facts)
|
|
|
|
required_empty = check_req(req_args)
|
|
|
|
if required_empty:
|
2022-06-15 08:48:04 +02:00
|
|
|
return False, required_empty[0] #slot do uzupełnienia
|
|
|
|
return True, act, req_args, opt_args #wyświetl użytkownikowi
|
2022-06-08 12:09:36 +02:00
|
|
|
|
2022-06-14 21:51:44 +02:00
|
|
|
def check_req(req_args):
|
|
|
|
req = []
|
|
|
|
for item in req_args:
|
|
|
|
if item[1] == None:
|
|
|
|
req.append(item)
|
|
|
|
return req
|
2022-06-08 12:09:36 +02:00
|
|
|
|
2022-06-14 21:51:44 +02:00
|
|
|
def add_facts(args, facts):
|
|
|
|
for key, value in facts.items():
|
|
|
|
for idx, item in enumerate(args):
|
|
|
|
if key == item[0] and value != None and item[1] == None:
|
|
|
|
args[idx] = value
|
|
|
|
if key == 'repo':
|
|
|
|
validate_repo(value)
|
2022-04-19 23:22:44 +02:00
|
|
|
|
|
|
|
|
2022-06-14 21:51:44 +02:00
|
|
|
return args
|
|
|
|
|
|
|
|
def agregate(grammar, slots):
|
|
|
|
req_args, opt_args = [], []
|
|
|
|
for item in grammar:
|
|
|
|
value = None
|
|
|
|
for slot in slots:
|
|
|
|
if slot[0] == item[0]:
|
|
|
|
value = None if slot[1] == '' else slot[1]
|
|
|
|
if item[1] == 'required':
|
|
|
|
req_args.append([item[0], value])
|
|
|
|
elif item[1] == 'optional':
|
|
|
|
opt_args.append([item[0], value])
|
|
|
|
return req_args, opt_args
|