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 = open("PM server/conversations", 'w')
|
||||||
file.write(str({}))
|
file.write(str({}))
|
||||||
file.close()
|
file.close()
|
||||||
else:
|
|
||||||
file = open("PM server/acc's", 'r')
|
file = open("PM server/acc's", 'r')
|
||||||
accounts = file.read()
|
accounts = file.read()
|
||||||
accounts = ast.literal_eval(accounts)
|
accounts = ast.literal_eval(accounts)
|
||||||
|
@ -22,6 +21,10 @@ else:
|
||||||
conversations = file.read()
|
conversations = file.read()
|
||||||
conversations = ast.literal_eval(conversations)
|
conversations = ast.literal_eval(conversations)
|
||||||
file.close()
|
file.close()
|
||||||
|
file = open("PM server/bots", 'r')
|
||||||
|
bots = file.read()
|
||||||
|
bots = ast.literal_eval(bots)
|
||||||
|
file.close()
|
||||||
|
|
||||||
currentsessionids = {}
|
currentsessionids = {}
|
||||||
sessiontime = {}
|
sessiontime = {}
|
||||||
|
@ -29,6 +32,7 @@ sessiontime = {}
|
||||||
def updatefiles():
|
def updatefiles():
|
||||||
global accounts
|
global accounts
|
||||||
global conversations
|
global conversations
|
||||||
|
global bots
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
file = open("PM server/acc's", 'r')
|
file = open("PM server/acc's", 'r')
|
||||||
|
@ -39,10 +43,16 @@ def updatefiles():
|
||||||
conversations = file.read()
|
conversations = file.read()
|
||||||
conversations = ast.literal_eval(conversations)
|
conversations = ast.literal_eval(conversations)
|
||||||
file.close()
|
file.close()
|
||||||
|
file = open("PM server/bots", 'r')
|
||||||
|
bots = file.read()
|
||||||
|
bots = ast.literal_eval(bots)
|
||||||
|
file.close()
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
updatefiles()
|
||||||
|
|
||||||
def saveaccounts(target):
|
def saveaccounts(target):
|
||||||
file = open("PM server/acc's", 'w')
|
file = open("PM server/acc's", 'w')
|
||||||
file.write(str(target))
|
file.write(str(target))
|
||||||
|
@ -53,7 +63,17 @@ def saveconversations(target):
|
||||||
file.write(str(target))
|
file.write(str(target))
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
def savebots(target):
|
||||||
|
file = open("PM server/bots", 'w')
|
||||||
|
file.write(str(target))
|
||||||
|
file.close()
|
||||||
|
|
||||||
def GET(args, ressources=None):
|
def GET(args, ressources=None):
|
||||||
|
global accounts
|
||||||
|
global conversations
|
||||||
|
global bots
|
||||||
|
global currentsessionids
|
||||||
|
global sessiontime
|
||||||
function = args["targetfunction"]
|
function = args["targetfunction"]
|
||||||
if function == "getsessionid":
|
if function == "getsessionid":
|
||||||
name = args["name"]
|
name = args["name"]
|
||||||
|
@ -106,8 +126,54 @@ def GET(args, ressources=None):
|
||||||
currentsessionids.pop(sessionid)
|
currentsessionids.pop(sessionid)
|
||||||
sessiontime.pop(sessionid)
|
sessiontime.pop(sessionid)
|
||||||
return "sessionid ran out"
|
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):
|
def PATCH(args, ressources=None):
|
||||||
|
global accounts
|
||||||
|
global conversations
|
||||||
|
global currentsessionids
|
||||||
|
global sessiontime
|
||||||
if args["targetfunction"] == "send":
|
if args["targetfunction"] == "send":
|
||||||
updatefiles()
|
updatefiles()
|
||||||
sessionid = args["sessionid"]
|
sessionid = args["sessionid"]
|
||||||
|
@ -116,7 +182,16 @@ def PATCH(args, ressources=None):
|
||||||
conversation = args["conversation"]
|
conversation = args["conversation"]
|
||||||
if conversation in conversations:
|
if conversation in conversations:
|
||||||
if name in conversation:
|
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)
|
saveconversations(conversations)
|
||||||
elif args["targetfunction"] == "newconv":
|
elif args["targetfunction"] == "newconv":
|
||||||
sessionid = args["sessionid"]
|
sessionid = args["sessionid"]
|
||||||
|
|
Loading…
Reference in New Issue