1
0
Fork 0

WIP on Epita Cristal module

This commit is contained in:
nemunaire 2014-04-08 15:26:42 +02:00
parent 073f34af26
commit 3f2ae59b9f
2 changed files with 69 additions and 0 deletions

64
modules/cristal.py Normal file
View File

@ -0,0 +1,64 @@
# coding=utf-8
from tools import web
nemubotversion = 3.3
def help_tiny ():
"""Line inserted in the response to the command !help"""
return "Gets information about Cristal missions"
def help_full ():
return "!cristal [id|name] : gives information about id Cristal mission."
def get_all_missions():
print (web.getContent(CONF.getNode("server")["url"]))
response = web.getXML(CONF.getNode("server")["url"])
print (CONF.getNode("server")["url"])
if response is not None:
return response.getNodes("mission")
else:
return None
def get_mission(id=None, name=None, people=None):
missions = get_all_missions()
if missions is not None:
for m in missions.childs:
if id is not None and m.getFirstNode("id").getContent() == id:
return m
elif (name is not None or name in m.getFirstNode("title").getContent()) and (people is not None or people in m.getFirstNode("contact").getContent()):
return m
return None
def cmd_cristal(msg):
if len(msg.cmds) > 1:
srch = msg.cmds[1]
else:
srch = ""
res = Response(msg.sender, channel=msg.channel, nomore="Je n'ai pas d'autre mission à afficher")
try:
id=int(srch)
name=""
except:
id=None
name=srch
missions = get_all_missions()
if missions is not None:
print (missions)
for m in missions:
print (m)
idm = m.getFirstNode("id").getContent()
crs = m.getFirstNode("title").getContent()
contact = m.getFirstNode("contact").getDate()
updated = m.getFirstNode("updated").getDate()
content = m.getFirstNode("content").getContent()
res.append_message(msg, crs + " ; contacter : " + contact + " : " + content)
else:
res.append_message("Aucune mission n'a été trouvée")
return res

5
modules/cristal.xml Normal file
View File

@ -0,0 +1,5 @@
<?xml version="1.0" ?>
<nemubotmodule name="cristal">
<server url="http://p0m.fr/cristal.php?f=xml" />
<message type="cmd" name="cristal" call="cmd_cristal" />
</nemubotmodule>