nemubot/modules/nextstop/__init__.py

56 lines
2.2 KiB
Python
Raw Normal View History

# coding=utf-8
2014-08-27 23:39:31 +00:00
"""Informe les usagers des prochains passages des transports en communs de la RATP"""
from nemubot.exception import IRCException
from nemubot.hooks import hook
2014-12-28 16:24:56 +00:00
from more import Response
2014-08-13 13:53:55 +00:00
nemubotversion = 3.4
2014-09-18 23:42:37 +00:00
from .external.src import ratp
def help_full ():
2012-11-04 14:33:04 +00:00
return "!ratp transport line [station]: Donne des informations sur les prochains passages du transport en commun séléctionné à l'arrêt désiré. Si aucune station n'est précisée, les liste toutes."
2014-09-18 23:42:37 +00:00
@hook("cmd_hook", "ratp")
def ask_ratp(msg):
"""Hook entry from !ratp"""
2015-07-10 21:09:54 +00:00
if len(msg.args) >= 3:
transport = msg.args[0]
line = msg.args[1]
station = msg.args[2]
if len(msg.args) == 4:
times = ratp.getNextStopsAtStation(transport, line, station, msg.args[3])
else:
times = ratp.getNextStopsAtStation(transport, line, station)
2014-09-18 23:42:37 +00:00
if len(times) == 0:
raise IRCException("la station %s n'existe pas sur le %s ligne %s." % (station, transport, line))
(time, direction, stationname) = times[0]
return Response(message=["\x03\x02%s\x03\x02 direction %s" % (time, direction) for time, direction, stationname in times],
title="Prochains passages du %s ligne %s à l'arrêt %s" % (transport, line, stationname),
channel=msg.channel)
2015-07-10 21:09:54 +00:00
elif len(msg.args) == 2:
stations = ratp.getAllStations(msg.args[0], msg.args[1])
2014-09-18 23:42:37 +00:00
if len(stations) == 0:
raise IRCException("aucune station trouvée.")
return Response([s for s in stations], title="Stations", channel=msg.channel)
else:
raise IRCException("Mauvais usage, merci de spécifier un type de transport et une ligne, ou de consulter l'aide du module.")
2015-06-09 22:59:57 +00:00
@hook("cmd_hook", "ratp_alert")
def ratp_alert(msg):
2015-07-10 21:09:54 +00:00
if len(msg.args) == 2:
transport = msg.args[0]
cause = msg.args[1]
2015-06-09 22:59:57 +00:00
incidents = ratp.getDisturbance(cause, transport)
return Response(incidents, channel=msg.channel, nomore="No more incidents", count=" (%d more incidents)")
else:
raise IRCException("Mauvais usage, merci de spécifier un type de transport et un type d'alerte (alerte, manif, travaux), ou de consulter l'aide du module.")