This commit is contained in:
Andreas Stephanides
2017-01-14 16:02:28 +01:00
parent 64a915ee17
commit 491fd2d25b
4 changed files with 21 additions and 13 deletions

View File

@@ -40,7 +40,7 @@ def query_test_url(url):
print(json.dumps(url))
return {"text": url.url, "callback_data":"/urls/"+str(url.id)+"/test"}
def handle_urls(handler, cmd):
def handle_urls(handler, cmd,args=[]):
curls=CrawlUrl.query.all()
#sent=handler.sender.sendMessage(json.dumps(curls))
kb_que= IKM2(map(query_que_url,curls))
@@ -62,6 +62,8 @@ def handle_urls(handler, cmd):
sent=handler.sender.sendMessage("Which url shoud I test?", reply_markup=kb_test)
handler._edit_msg_ident = telepot.message_identifier(sent)
handler._editor = telepot.helper.Editor(handler.bot, sent)
elif len(cmd) >= 3 and cmd[2] == "add":
sent=handler.sender.sendMessage("I added tested url: "+ json.dumps(compiler_controller.url_add(args[0],args[1]))[0:399], reply_markup=None)
else:
sent=handler.sender.sendMessage("What do you want to do?", reply_markup=kb_url)
handler._edit_msg_ident = telepot.message_identifier(sent)
@@ -70,12 +72,13 @@ def handle_urls(handler, cmd):
def execute_command(handler,cmd,msg=None, args=[]):
if cmd[1]=='urls':
if is_admin(msg["from"]["id"]):
handle_urls(handler,cmd)
handle_urls(handler,cmd,args)
else:
handler.sender.sendMessage("Not allowed for "+json.dumps(msg["from"]))
elif cmd[1] =='articles':
handler.sender.sendMessage(json.dumps({"args": args, "cmd": cmd}))
handler.sender.sendMessage(json.dumps(articles_controller.search(args[0])))
for a in articles_controller.search(args[0]):
handler.sender.sendMessage(json.dumps(a))
elif cmd[1] =='startworkers':
if is_admin(msg["from"]["id"]):
handler.sender.sendMessage(compiler_controller.start_workers())
@@ -87,9 +90,9 @@ def handle(handler,msg):
content_type,chat_type,chat_id = telepot.glance(msg)
if msg.has_key('text'):
if msg['text'][0]=='/':
cmd = msg['text'].split("/")
args=cmd[-1].split(" ")[1:]
cmd[-1]=cmd[-1].split(" ")[0]
args=msg['text'].split(" ")
cmd = args[0].split("/")
args=args[1:]
execute_command(handler, cmd, msg,args)
if msg.has_key('data'):
lg.debug(msg['data'])