File: filter.py

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