2012-04-12 01:06:17 +00:00
# coding=utf-8
import time
import re
2012-05-14 15:50:11 +00:00
import threading
2012-04-12 01:06:17 +00:00
from datetime import date
from datetime import datetime
2012-10-14 23:52:32 +00:00
from . import SiteSoutenances
2012-04-12 01:06:17 +00:00
2012-11-04 15:04:39 +00:00
nemubotversion = 3.3
2012-05-14 15:50:11 +00:00
2012-06-29 17:20:29 +00:00
def help_tiny ( ) :
2012-04-12 01:06:17 +00:00
""" Line inserted in the response to the command !help """
2012-04-18 21:35:58 +00:00
return " EPITA ING1 defenses module "
2012-04-12 01:06:17 +00:00
2012-06-29 17:20:29 +00:00
def help_full ( ) :
return " !soutenance: gives information about current defenses state \n !soutenance <who>: gives the date of the next defense of /who/. \n !soutenances <who>: gives all defense dates of /who/ "
2012-04-12 01:06:17 +00:00
2012-10-14 23:52:32 +00:00
def load ( context ) :
global CONF
SiteSoutenances . CONF = CONF
2012-04-12 01:06:17 +00:00
2012-10-14 23:52:32 +00:00
def ask_soutenance ( msg ) :
req = ModuleState ( " request " )
2012-11-04 15:04:39 +00:00
if len ( msg . cmds ) > 1 :
req . setAttribute ( " user " , msg . cmds [ 1 ] )
2012-04-12 01:06:17 +00:00
else :
2012-10-14 23:52:32 +00:00
req . setAttribute ( " user " , " next " )
2012-11-04 15:04:39 +00:00
req . setAttribute ( " server " , msg . server )
2012-10-14 23:52:32 +00:00
req . setAttribute ( " channel " , msg . channel )
req . setAttribute ( " sender " , msg . sender )
2012-06-29 17:20:29 +00:00
2012-10-14 23:52:32 +00:00
#An instance of this module is already running?
if not DATAS . hasAttribute ( " _running " ) or DATAS [ " _running " ] . needUpdate ( ) :
DATAS . addChild ( req )
site = SiteSoutenances . SiteSoutenances ( DATAS )
DATAS . setAttribute ( " _running " , site )
2012-06-29 17:20:29 +00:00
2012-10-14 23:52:32 +00:00
res = site . run ( )
2012-05-03 14:16:38 +00:00
2012-10-14 23:52:32 +00:00
for n in DATAS . getNodes ( " request " ) :
DATAS . delChild ( n )
2012-05-03 14:16:38 +00:00
2012-10-14 23:52:32 +00:00
return res
2012-05-03 14:16:38 +00:00
else :
2012-10-14 23:52:32 +00:00
site = DATAS [ " _running " ]
return site . res_soutenance ( req )