2016-08-17 14:41:05 +00:00
|
|
|
import json
|
2016-10-02 20:48:14 +00:00
|
|
|
|
2016-12-28 11:41:24 +00:00
|
|
|
import tornado.web
|
|
|
|
import tornado.gen
|
|
|
|
|
|
|
|
from common.sentry import sentry
|
2016-10-02 20:48:14 +00:00
|
|
|
from common.web import requestsManager
|
|
|
|
from constants import exceptions
|
2016-08-17 14:41:05 +00:00
|
|
|
from helpers import chatHelper
|
2016-10-02 20:48:14 +00:00
|
|
|
from objects import glob
|
|
|
|
|
2016-08-17 14:41:05 +00:00
|
|
|
|
2016-10-02 20:48:14 +00:00
|
|
|
class handler(requestsManager.asyncRequestHandler):
|
2016-12-28 11:41:24 +00:00
|
|
|
@tornado.web.asynchronous
|
|
|
|
@tornado.gen.engine
|
|
|
|
@sentry.captureTornado
|
2016-08-23 18:35:47 +00:00
|
|
|
def asyncGet(self):
|
|
|
|
statusCode = 400
|
|
|
|
data = {"message": "unknown error"}
|
|
|
|
try:
|
|
|
|
# Check arguments
|
2016-10-02 20:48:14 +00:00
|
|
|
if not requestsManager.checkArguments(self.request.arguments, ["k", "to", "msg"]):
|
2016-08-23 18:35:47 +00:00
|
|
|
raise exceptions.invalidArgumentsException()
|
2016-08-17 14:41:05 +00:00
|
|
|
|
2016-08-23 18:35:47 +00:00
|
|
|
# Check ci key
|
|
|
|
key = self.get_argument("k")
|
|
|
|
if key is None or key != glob.conf.config["server"]["cikey"]:
|
|
|
|
raise exceptions.invalidArgumentsException()
|
2016-08-17 14:41:05 +00:00
|
|
|
|
2017-10-31 12:11:01 +00:00
|
|
|
chatHelper.sendMessage(
|
|
|
|
"FokaBot",
|
|
|
|
self.get_argument("to").encode().decode("ASCII", "ignore"),
|
|
|
|
self.get_argument("msg").encode().decode("ASCII", "ignore")
|
|
|
|
)
|
2016-08-17 14:41:05 +00:00
|
|
|
|
2016-08-23 18:35:47 +00:00
|
|
|
# Status code and message
|
|
|
|
statusCode = 200
|
|
|
|
data["message"] = "ok"
|
|
|
|
except exceptions.invalidArgumentsException:
|
|
|
|
statusCode = 400
|
|
|
|
data["message"] = "invalid parameters"
|
|
|
|
finally:
|
|
|
|
# Add status code to data
|
|
|
|
data["status"] = statusCode
|
2016-08-17 14:41:05 +00:00
|
|
|
|
2016-08-23 18:35:47 +00:00
|
|
|
# Send response
|
|
|
|
self.write(json.dumps(data))
|
2016-11-17 18:13:06 +00:00
|
|
|
self.set_status(statusCode)
|