implement /api/v1/fokabotMessage
This commit is contained in:
parent
677abae257
commit
d76fecb442
45
handlers/fokabotMessageHandler.py
Normal file
45
handlers/fokabotMessageHandler.py
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
from helpers import requestHelper
|
||||||
|
from constants import exceptions
|
||||||
|
import json
|
||||||
|
from objects import glob
|
||||||
|
from helpers import chatHelper
|
||||||
|
from helpers import logHelper as log
|
||||||
|
|
||||||
|
class handler(requestHelper.asyncRequestHandler):
|
||||||
|
def asyncGet(self):
|
||||||
|
statusCode = 400
|
||||||
|
data = {"message": "unknown error"}
|
||||||
|
try:
|
||||||
|
# Check arguments
|
||||||
|
if requestHelper.checkArguments(self.request.arguments, ["k"]) == False:
|
||||||
|
raise exceptions.invalidArgumentsException()
|
||||||
|
|
||||||
|
if requestHelper.checkArguments(self.request.arguments, ["to"]) == False:
|
||||||
|
raise exceptions.invalidArgumentsException()
|
||||||
|
|
||||||
|
if requestHelper.checkArguments(self.request.arguments, ["msg"]) == False:
|
||||||
|
raise exceptions.invalidArgumentsException()
|
||||||
|
|
||||||
|
# Check ci key
|
||||||
|
key = self.get_argument("k")
|
||||||
|
if key is None or key != glob.conf.config["server"]["cikey"]:
|
||||||
|
raise exceptions.invalidArgumentsException()
|
||||||
|
|
||||||
|
log.info("API REQUEST FOR FOKABOT MESSAGE AAAAAAA")
|
||||||
|
chatHelper.sendMessage("FokaBot", self.get_argument("to"), self.get_argument("msg"))
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# Send response
|
||||||
|
#self.clear()
|
||||||
|
self.write(json.dumps(data))
|
||||||
|
self.set_status(statusCode)
|
||||||
|
#self.finish(json.dumps(data))
|
2
pep.py
2
pep.py
|
@ -31,6 +31,7 @@ from handlers import apiOnlineUsersHandler
|
||||||
from handlers import apiServerStatusHandler
|
from handlers import apiServerStatusHandler
|
||||||
from handlers import ciTriggerHandler
|
from handlers import ciTriggerHandler
|
||||||
from handlers import apiVerifiedStatusHandler
|
from handlers import apiVerifiedStatusHandler
|
||||||
|
from handlers import fokabotMessageHandler
|
||||||
|
|
||||||
from irc import ircserver
|
from irc import ircserver
|
||||||
|
|
||||||
|
@ -42,6 +43,7 @@ def make_app():
|
||||||
(r"/api/v1/serverStatus", apiServerStatusHandler.handler),
|
(r"/api/v1/serverStatus", apiServerStatusHandler.handler),
|
||||||
(r"/api/v1/ciTrigger", ciTriggerHandler.handler),
|
(r"/api/v1/ciTrigger", ciTriggerHandler.handler),
|
||||||
(r"/api/v1/verifiedStatus", apiVerifiedStatusHandler.handler),
|
(r"/api/v1/verifiedStatus", apiVerifiedStatusHandler.handler),
|
||||||
|
(r"/api/v1/fokabotMessage", fokabotMessageHandler.handler)
|
||||||
])
|
])
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue
Block a user