Crossfire Server, Trunk
filter.py
Go to the documentation of this file.
1 # filter.py
2 #
3 # Copyright 2007 by David Delbecq
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #
19 #
20 # Uses JSON notation for parameters
21 # This script make the event it is attached to (not global!)
22 # works only in specific moment of year/day. Periods are separated
23 # by comas. See wiki doc list of possible values
24 # exemple, to make an "apply" work only during Blizzard, new year and every morning:
25 #
26 # arch event_apply
27 # title Python
28 # slaying /python/tod/filter.py
29 # msg
30 # {
31 # "when":["The Season of New Year","The Season of the Blizzard","Morning"],
32 # "match" : "one",
33 # "inverse": true
34 # }
35 # endmsg
36 # end
37 import Crossfire
38 import string
39 from CFTimeOfDay import TimeOfDay
40 import cjson
41 parameters = cjson.decode(Crossfire.WhatIsEvent().Message)
42 inverse = "inverse" in parameters and parameters["inverse"] == True
43 Crossfire.SetReturnValue(not inverse)
44 if not "match" in parameters:
45  Crossfire.Log(Crossfire.LogError,"Script filter.py didn't get a 'match' parameter. Only got %s" %parameters)
46 elif parameters["match"].lower() == "one":
47  if TimeOfDay().matchAny(parameters["when"]):
48  Crossfire.SetReturnValue(inverse)
49 elif parameters["match"].lower() == "all":
50  if TimeOfDay().matchAll(parameters["when"]):
51  Crossfire.SetReturnValue(inverse)
52 else:
53  Crossfire.Log(Crossfire.LogError,"Script filter.py didn't get a 'match' parameter. Only got %s" %parameters)
CFTimeOfDay.TimeOfDay
Definition: CFTimeOfDay.py:3