]>
jfr.im git - irc/rizon/acid.git/blob - pyva/src/main/python/limitserv/limitserv.py
1 #!/usr/bin/python pseudoserver.py
3 # module for pypseudoserver
4 # written by celestin - martin <martin@rizon.net>
8 from istring
import istring
9 from pseudoclient
import sys_log
, sys_options
, sys_channels
, inviteable
17 import cmd_admin
, sys_auth
, limitmanager
21 inviteable
.InviteablePseudoclient
25 def start_threads(self
):
29 self
.limit_monitor
.start()
31 def bind_function(self
, function
):
32 func
= types
.MethodType(function
, self
, limitserv
)
33 setattr(limitserv
, function
.__name
__, func
)
36 def bind_admin_commands(self
):
37 list = cmd_admin
.get_commands()
38 self
.commands_admin
= []
41 self
.commands_admin
.append((command
, {'permission': 'j', 'callback': self
.bind_function(list[command
][0]),
42 'usage': list[command
][1]}))
45 AcidPlugin
.__init
__(self
)
47 self
.name
= "limitserv"
48 self
.log
= logging
.getLogger(__name__
)
51 self
.nick
= istring(self
.config
.get('limitserv', 'nick'))
52 except Exception, err
:
53 self
.log
.exception("Error reading 'limitserv:nick' configuration option: %s" % err
)
57 self
.chan
= istring(self
.config
.get('limitserv', 'channel'))
58 except Exception, err
:
59 self
.log
.exception("Error reading 'limitserv:channel' configuration option: %s" % err
)
62 self
.bind_admin_commands()
66 self
.dbp
.execute("CREATE TABLE IF NOT EXISTS limitserv_chans (item SMALLINT(5) NOT NULL AUTO_INCREMENT, channel VARCHAR(35), \
67 PRIMARY KEY (item), UNIQUE KEY (channel));")
68 except Exception, err
:
69 self
.log
.exception("Error creating table for limitserv module (%s)" % err
)
73 AcidPlugin
.start(self
)
74 inviteable
.InviteablePseudoclient
.start(self
)
76 self
.options
= sys_options
.OptionManager(self
)
77 self
.elog
= sys_log
.LogManager(self
)
78 self
.auth
= sys_auth
.LimitServAuthManager(self
)
79 self
.channels
= sys_channels
.ChannelManager(self
)
80 self
.limit_monitor
= limitmanager
.LimitManager(self
)
81 except Exception, err
:
82 self
.log
.exception('Error initializing subsystems for limitserv module (%s)' % err
)
85 for channel
in self
.channels
.list_valid():
86 self
.join(channel
.name
)
88 self
.elog
.debug('Joined channels.')
92 except Exception, err
:
93 self
.log
.exception('Error starting threads for limitserv module (%s)' % err
)
96 self
.initialized
= True
97 self
.elog
.debug('Started threads.')
101 for channel
in self
.channels
.list_valid():
102 self
.join(channel
.name
)
104 self
.log
.debug('Joined channels.')
107 if hasattr(self
, 'auth'):
110 if hasattr(self
, 'channels'):
112 self
.channels
.force()
115 self
.channels
.db_close()
117 if hasattr(self
, 'options'):
122 self
.options
.db_close()
124 if hasattr(self
, 'limit_monitor'):
125 self
.limit_monitor
.stop()
127 def join(self
, channel
):
128 me
= self
.inter
.findUser(self
.nick
)
130 self
.msg('ChanServ', 'OP %s' % channel
) # and the channel is not empty. For now, use /cs op
132 def part(self
, channel
):
133 me
= self
.inter
.findUser(self
.nick
)
136 def msg(self
, target
, message
):
138 self
.inter
.privmsg(self
.nick
, target
, format_ascii_irc(message
))
140 def multimsg(self
, target
, count
, intro
, separator
, pieces
, outro
= ''):
143 while cur
< len(pieces
):
144 self
.msg(target
, intro
+ separator
.join(pieces
[cur
:cur
+ count
]) + outro
)
147 def notice(self
, target
, message
):
149 self
.inter
.notice(self
.nick
, target
, format_ascii_irc(message
))
151 def onPrivmsg(self
, source
, target
, message
):
152 if inviteable
.InviteablePseudoclient
.onPrivmsg(self
, source
, target
, message
) and \
154 # if inviteable fell through, we don't have anything else to do
155 self
.msg(source
, 'Invalid message. Say help for a list of valid messages.')
157 def do_accept(self
, nick
, channel
):
158 chan
= self
.inter
.findChannel(channel
)
159 if chan
.size() < self
.options
.get('required_users', int, 20):
160 self
.auth
.reject_not_enough_users(nick
, channel
)
163 inviteable
.InviteablePseudoclient
.do_accept(self
, nick
, channel
)
165 def onChanModes(self
, prefix
, channel
, modes
):
166 if not self
.initialized
:
169 if not modes
== '-z':
172 if channel
in self
.channels
:
173 self
.channels
.remove(channel
)
174 self
.elog
.request('Channel @b%s@b was dropped. Deleting it.' % channel
)
176 def onJoin(self
, user
, channel
):
177 if self
.channels
.is_valid(channel
) and channel
not in self
.limit_monitor
:
178 self
.limit_monitor
.insert(channel
)
180 def onPart(self
, user
, channel
):
181 self
.onJoin(None, channel
)
183 def onKick(self
, kicker
, victim
, channel
, reason
):
184 self
.onJoin(None, channel
)
186 def getCommands(self
):
187 return self
.commands_admin