Dateien nach "servers" hochladen
parent
2163482149
commit
c38d785dc3
|
@ -13,7 +13,6 @@ if not os.path.exists("PM server/acc's"):
|
|||
file = open("PM server/conversations", 'w')
|
||||
file.write(str({}))
|
||||
file.close()
|
||||
else:
|
||||
file = open("PM server/acc's", 'r')
|
||||
accounts = file.read()
|
||||
accounts = ast.literal_eval(accounts)
|
||||
|
@ -22,6 +21,10 @@ else:
|
|||
conversations = file.read()
|
||||
conversations = ast.literal_eval(conversations)
|
||||
file.close()
|
||||
file = open("PM server/bots", 'r')
|
||||
bots = file.read()
|
||||
bots = ast.literal_eval(bots)
|
||||
file.close()
|
||||
|
||||
currentsessionids = {}
|
||||
sessiontime = {}
|
||||
|
@ -29,6 +32,7 @@ sessiontime = {}
|
|||
def updatefiles():
|
||||
global accounts
|
||||
global conversations
|
||||
global bots
|
||||
while True:
|
||||
try:
|
||||
file = open("PM server/acc's", 'r')
|
||||
|
@ -39,10 +43,16 @@ def updatefiles():
|
|||
conversations = file.read()
|
||||
conversations = ast.literal_eval(conversations)
|
||||
file.close()
|
||||
file = open("PM server/bots", 'r')
|
||||
bots = file.read()
|
||||
bots = ast.literal_eval(bots)
|
||||
file.close()
|
||||
break
|
||||
except:
|
||||
pass
|
||||
|
||||
updatefiles()
|
||||
|
||||
def saveaccounts(target):
|
||||
file = open("PM server/acc's", 'w')
|
||||
file.write(str(target))
|
||||
|
@ -53,7 +63,17 @@ def saveconversations(target):
|
|||
file.write(str(target))
|
||||
file.close()
|
||||
|
||||
def savebots(target):
|
||||
file = open("PM server/bots", 'w')
|
||||
file.write(str(target))
|
||||
file.close()
|
||||
|
||||
def GET(args, ressources=None):
|
||||
global accounts
|
||||
global conversations
|
||||
global bots
|
||||
global currentsessionids
|
||||
global sessiontime
|
||||
function = args["targetfunction"]
|
||||
if function == "getsessionid":
|
||||
name = args["name"]
|
||||
|
@ -106,8 +126,54 @@ def GET(args, ressources=None):
|
|||
currentsessionids.pop(sessionid)
|
||||
sessiontime.pop(sessionid)
|
||||
return "sessionid ran out"
|
||||
elif args["targetfunction"] == "botgetconversations":
|
||||
updatefiles()
|
||||
if args["botname"] in bots:
|
||||
if bots[args["botname"]]["pass"] == args["pass"]:
|
||||
for i in bots[args["botname"]]["conversations"]:
|
||||
bots[args["botname"]]["conversations"][i] = conversations[i]
|
||||
savebots(bots)
|
||||
print(bots[args["botname"]]["conversations"])
|
||||
return bots[args["botname"]]["conversations"]
|
||||
else:
|
||||
return "wrong password"
|
||||
else:
|
||||
return "bot not found"
|
||||
elif args["targetfunction"] == "botsend":
|
||||
updatefiles
|
||||
if args["botname"] in bots:
|
||||
if bots[args["botname"]]["pass"] == args["pass"]:
|
||||
message = args["message"]
|
||||
conversation = args["conversation"]
|
||||
if conversation in conversations:
|
||||
if conversation in bots[args["botname"]]["conversations"]:
|
||||
conversations[conversation] = conversations[conversation] + "message from bot " + message + "\n"
|
||||
saveconversations(conversations)
|
||||
return "sucess"
|
||||
else:
|
||||
return "no permission to send in this conversation"
|
||||
else:
|
||||
return "conversation not found"
|
||||
else:
|
||||
return "wrong password"
|
||||
else:
|
||||
return "bot not found"
|
||||
elif args["targetfunction"] == "createbot":
|
||||
updatefiles()
|
||||
if not args["botname"] in bots:
|
||||
bots[args["botname"]] = {}
|
||||
bots[args["botname"]]["pass"] = args["pass"]
|
||||
bots[args["botname"]]["conversations"] = {}
|
||||
savebots(bots)
|
||||
return "sucess"
|
||||
else:
|
||||
return "bot already exists"
|
||||
|
||||
def PATCH(args, ressources=None):
|
||||
global accounts
|
||||
global conversations
|
||||
global currentsessionids
|
||||
global sessiontime
|
||||
if args["targetfunction"] == "send":
|
||||
updatefiles()
|
||||
sessionid = args["sessionid"]
|
||||
|
@ -116,7 +182,16 @@ def PATCH(args, ressources=None):
|
|||
conversation = args["conversation"]
|
||||
if conversation in conversations:
|
||||
if name in conversation:
|
||||
conversations[conversation] = conversations[conversation] + name + ":" + message + "\n"
|
||||
if message.split(" ")[0] != "!addbot":
|
||||
conversations[conversation] = conversations[conversation] + name + ":" + message + "\n"
|
||||
else:
|
||||
message = message.split(" ")
|
||||
if message[1] in bots:
|
||||
bots[message[1]]["conversations"][conversation] = conversations[conversation]
|
||||
conversations[conversation] = conversations[conversation] + "bot '{}' added!".format(message[1]) + "\n"
|
||||
savebots(bots)
|
||||
else:
|
||||
conversations[conversation] = conversations[conversation] + "bot not found" + "\n"
|
||||
saveconversations(conversations)
|
||||
elif args["targetfunction"] == "newconv":
|
||||
sessionid = args["sessionid"]
|
||||
|
|
Loading…
Reference in New Issue