-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.py
67 lines (52 loc) · 2.12 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from flask import Flask, jsonify, redirect, request
from flask_cors import CORS
from waitress import serve
import message
import os
import json
flaskApp = Flask(__name__)
CORS(flaskApp, resources={r"*": {"origins": "*"}})
@flaskApp.route("/")
def mainPage():
return redirect("https://github.com/yymin1022/Wa_API", code=302)
@flaskApp.route("/getMessage", methods = ["POST"])
def getMessage():
errCode = 0
errMessage = "RESULT OK"
inputData = ""
inputMessage = ""
inputRoom = ""
inputSender = ""
try:
inputData = request.get_json()
inputMessage = inputData["msg"]
inputRoom = inputData["room"]
inputSender = inputData["sender"]
except Exception as errContent:
errCode = 200
errMessage = repr(errContent)
replyData = dict([("RESULT", dict([("RESULT_CODE", errCode), ("RESULT_MSG", errMessage)])), ("DATA", dict([("msg", ""), ("room", ""), ("sender", "")]))])
return jsonify(replyData)
if os.path.isfile("power.json"):
with open('power.json', 'r', encoding='utf-8') as f:
power_dict = json.load(f)
if power_dict.get(inputRoom) == None:
replyMessage = message.getReplyMessage(inputMessage, inputRoom, inputSender)
elif power_dict[inputRoom] == "0":
if "와봇" in inputMessage:
replyMessage = message.getReplyMessage(inputMessage, inputRoom, inputSender)
else:
replyMessage = ""
else:
replyMessage = message.getReplyMessage(inputMessage, inputRoom, inputSender)
else:
replyMessage = message.getReplyMessage(inputMessage, inputRoom, inputSender)
replyRoom = inputRoom
replySender = inputSender
if(replyMessage == ""):
errCode = 100
errMessage = "None WA Bot Message Found"
replyData = dict([("RESULT", dict([("RESULT_CODE", errCode), ("RESULT_MSG", errMessage)])), ("DATA", dict([("msg", replyMessage), ("room", replyRoom), ("sender", replySender)]))])
return jsonify(replyData)
if __name__ == "__main__":
serve(flaskApp, host="0.0.0.0", port=80)