-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimer.py
44 lines (28 loc) · 1.25 KB
/
timer.py
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
# timer.py
# a module to invoke IRC commands in a timed manner
import znc
class delay_cmd_timer(znc.Timer):
def RunJob(self):
self.GetModule().PutIRC(self.command)
class timer(znc.Module):
description = "TIMER command, usage: TIMER <seconds> <command>"
module_types = [ znc.CModInfo.NetworkModule ]
timer_generation = 0
def OnModCommand(self, sCommand): # const CString & sCommand
self.OnSendToIRC("timer " + str(sCommand))
def OnSendToIRC(self, sLine): # CString & sLine
parts = str(sLine).partition(" ") # split at first whitespace
if not parts[0].lower() == "timer":
return znc.CONTINUE # command does not match
parts = parts[2].lstrip().partition(" ") # remove whitespace and continue
argdelay = parts[0]
argcmd = parts[2].lstrip()
if not argdelay.isdigit() or len(argcmd) == 0:
self.PutModule(self.description)
return znc.HALTCORE # do not forward
sNetwork = str(self.GetNetwork().GetName())
sUser = str(self.GetUser().GetUserName())
t = self.CreateTimer(delay_cmd_timer, interval=int(argdelay), label="delay_cmd_timer-" + sUser + "-" + sNetwork + "-" + str(self.timer_generation))
t.command = argcmd
self.timer_generation += 1
return znc.HALT # do neither forward nor process anywhere else