WIP on Epita Cristal module
This commit is contained in:
parent
073f34af26
commit
3f2ae59b9f
64
modules/cristal.py
Normal file
64
modules/cristal.py
Normal 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
5
modules/cristal.xml
Normal 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>
|
Loading…
x
Reference in New Issue
Block a user