2022-02-06 01:54:17 +01:00
|
|
|
import pickle
|
2022-02-05 00:46:57 +01:00
|
|
|
|
|
|
|
# Isengard commands
|
|
|
|
|
2022-02-06 01:29:59 +01:00
|
|
|
def cmdping(owners, nick, text, sbuf):
|
2022-02-05 00:46:57 +01:00
|
|
|
"""
|
|
|
|
Ping command.
|
|
|
|
"""
|
|
|
|
|
|
|
|
return "pong !"
|
|
|
|
|
|
|
|
|
2022-02-06 01:29:59 +01:00
|
|
|
def cmdmainteneur(owners, nick, text, sbuf):
|
|
|
|
"""
|
|
|
|
Change maintainer for an host
|
|
|
|
"""
|
|
|
|
|
|
|
|
if not nick in owners:
|
|
|
|
return "désolé mais vous n'êtes pas autorisé à utiliser cette commande."
|
|
|
|
|
|
|
|
try:
|
|
|
|
splittedtext = text.split(" ")
|
|
|
|
|
|
|
|
# print maintainer
|
|
|
|
if len(splittedtext) == 2:
|
|
|
|
host = splittedtext[1]
|
|
|
|
|
|
|
|
return "le responsable de cette machine est " \
|
|
|
|
+ sbuf.buf[host]["maintainer"]
|
|
|
|
|
|
|
|
if len(splittedtext) == 3:
|
|
|
|
host = splittedtext[1]
|
|
|
|
maintainer = splittedtext[2]
|
|
|
|
|
2022-02-06 01:54:17 +01:00
|
|
|
sbuf.buf[host] = {}
|
|
|
|
sbuf.buf[host]["destmuc"] = None
|
|
|
|
sbuf.buf[host]["status_state"] = None
|
|
|
|
sbuf.buf[host]["status_type"] = None
|
|
|
|
sbuf.buf[host]["text"] = None
|
|
|
|
sbuf.buf[host]["raw"] = None
|
|
|
|
sbuf.buf[host]["needUpdate"] = False
|
2022-02-06 01:29:59 +01:00
|
|
|
sbuf.buf[host]["maintainer"] = maintainer
|
|
|
|
|
|
|
|
return "le responsable est à présent " \
|
|
|
|
+ sbuf.buf[host]["maintainer"]
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
print(repr(e))
|
|
|
|
return "Erreur à l'exécution"
|
|
|
|
|
|
|
|
return "Syntaxe invalide"
|
2022-02-05 00:46:57 +01:00
|
|
|
|
2022-02-06 01:54:17 +01:00
|
|
|
def cmdsave(owners, nick, text, sbuf):
|
|
|
|
"""
|
|
|
|
Save
|
|
|
|
"""
|
|
|
|
|
|
|
|
if not nick in owners:
|
|
|
|
return "désolé mais vous n'êtes pas autorisé à utiliser cette commande."
|
|
|
|
|
|
|
|
try:
|
|
|
|
with open('current_buffer', 'wb') as current_buffer_file:
|
|
|
|
pickle.dump(sbuf.buf, current_buffer_file)
|
|
|
|
return "OK"
|
2022-02-05 00:46:57 +01:00
|
|
|
|
2022-02-06 01:54:17 +01:00
|
|
|
except Exception as e:
|
|
|
|
print(repr(e))
|
|
|
|
return "Erreur à l'exécution"
|
2022-02-05 00:46:57 +01:00
|
|
|
|
2022-02-06 01:54:17 +01:00
|
|
|
def cmdload(owners, nick, text, sbuf):
|
|
|
|
"""
|
|
|
|
Save
|
|
|
|
"""
|
|
|
|
|
|
|
|
if not nick in owners:
|
|
|
|
return "désolé mais vous n'êtes pas autorisé à utiliser cette commande."
|
|
|
|
|
|
|
|
try:
|
|
|
|
with open('current_buffer', 'rb') as current_buffer_file:
|
|
|
|
sbuf.buf = pickle.load(current_buffer_file)
|
|
|
|
return "OK"
|
2022-02-05 00:46:57 +01:00
|
|
|
|
2022-02-06 01:54:17 +01:00
|
|
|
except Exception as e:
|
|
|
|
print(repr(e))
|
|
|
|
return "Erreur à l'exécution"
|
2022-02-05 00:46:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Commands
|
|
|
|
|
|
|
|
commandtable = {
|
|
|
|
|
|
|
|
"ping" : cmdping,
|
2022-02-06 01:29:59 +01:00
|
|
|
"mainteneur" : cmdmainteneur,
|
2022-02-06 01:54:17 +01:00
|
|
|
"save" : cmdsave,
|
|
|
|
"load" : cmdload,
|
2022-02-05 00:46:57 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|