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
19 import pyva_net_rizon_acid_core_Acidictive
as Acidictive
20 import pyva_net_rizon_acid_core_AcidCore
as AcidCore
21 import pyva_net_rizon_acid_core_User
as User
22 import pyva_net_rizon_acid_core_Channel
as Channel
26 inviteable
.InviteablePseudoclient
30 def start_threads(self
):
34 self
.limit_monitor
.start()
36 def bind_function(self
, function
):
37 func
= types
.MethodType(function
, self
, limitserv
)
38 setattr(limitserv
, function
.__name
__, func
)
41 def bind_admin_commands(self
):
42 list = cmd_admin
.get_commands()
43 self
.commands_admin
= []
46 self
.commands_admin
.append((command
, {'permission': 'j', 'callback': self
.bind_function(list[command
][0]),
47 'usage': list[command
][1]}))
50 AcidPlugin
.__init
__(self
)
52 self
.name
= "limitserv"
53 self
.log
= logging
.getLogger(__name__
)
56 self
.nick
= istring(self
.config
.get('limitserv').get('nick'))
57 except Exception, err
:
58 self
.log
.exception("Error reading 'limitserv:nick' configuration option: %s" % err
)
62 self
.chan
= istring(self
.config
.get('limitserv').get('channel'))
63 except Exception, err
:
64 self
.log
.exception("Error reading 'limitserv:channel' configuration option: %s" % err
)
67 self
.bind_admin_commands()
71 self
.dbp
.execute("CREATE TABLE IF NOT EXISTS limitserv_chans (item SMALLINT(5) NOT NULL AUTO_INCREMENT, channel VARCHAR(35), \
72 PRIMARY KEY (item), UNIQUE KEY (channel));")
73 except Exception, err
:
74 self
.log
.exception("Error creating table for limitserv module (%s)" % err
)
78 AcidPlugin
.start(self
)
79 inviteable
.InviteablePseudoclient
.start(self
)
81 self
.options
= sys_options
.OptionManager(self
)
82 self
.elog
= sys_log
.LogManager(self
)
83 self
.auth
= sys_auth
.LimitServAuthManager(self
)
84 self
.channels
= sys_channels
.ChannelManager(self
)
85 self
.limit_monitor
= limitmanager
.LimitManager(self
)
86 except Exception, err
:
87 self
.log
.exception('Error initializing subsystems for limitserv module (%s)' % err
)
90 for channel
in self
.channels
.list_valid():
91 self
.join(channel
.name
)
93 self
.elog
.debug('Joined channels.')
97 except Exception, err
:
98 self
.log
.exception('Error starting threads for limitserv module (%s)' % err
)
101 self
.initialized
= True
102 self
.elog
.debug('Started threads.')
106 for channel
in self
.channels
.list_valid():
107 self
.msg('ChanServ', 'OP %s' % channel
.name
)
110 if hasattr(self
, 'auth'):
113 if hasattr(self
, 'channels'):
115 self
.channels
.force()
118 self
.channels
.db_close()
120 if hasattr(self
, 'options'):
125 self
.options
.db_close()
127 if hasattr(self
, 'limit_monitor'):
128 self
.limit_monitor
.stop()
130 def join(self
, channel
):
131 super(limitserv
, self
).join(channel
)
132 if Acidictive
.me
and not Acidictive
.me
.isBursting():
133 self
.msg('ChanServ', 'OP %s' % channel
) # and the channel is not empty. For now, use /cs op
135 def msg(self
, target
, message
):
137 Acidictive
.privmsg(self
.nick
, target
, format_ascii_irc(message
))
139 def multimsg(self
, target
, count
, intro
, separator
, pieces
, outro
= ''):
142 while cur
< len(pieces
):
143 self
.msg(target
, intro
+ separator
.join(pieces
[cur
:cur
+ count
]) + outro
)
146 def notice(self
, target
, message
):
148 Acidictive
.notice(self
.nick
, target
, format_ascii_irc(message
))
150 def onPrivmsg(self
, source
, target
, message
):
151 if inviteable
.InviteablePseudoclient
.onPrivmsg(self
, source
, target
, message
) and \
153 # if inviteable fell through, we don't have anything else to do
154 self
.msg(source
, 'Invalid message. Say help for a list of valid messages.')
156 def do_accept(self
, nick
, channel
):
157 chan
= Channel
.findChannel(channel
)
158 if chan
.size() < self
.options
.get('required_users', int, 20):
159 self
.auth
.reject_not_enough_users(nick
, channel
)
162 inviteable
.InviteablePseudoclient
.do_accept(self
, nick
, channel
)
164 def onChanModes(self
, prefix
, channel
, modes
):
165 if not self
.initialized
:
168 if not modes
== '-z':
171 if channel
in self
.channels
:
172 self
.channels
.remove(channel
)
173 self
.elog
.request('Channel @b%s@b was dropped. Deleting it.' % channel
)
175 def onJoin(self
, user
, channel
):
176 if self
.channels
.is_valid(channel
) and channel
not in self
.limit_monitor
:
177 self
.limit_monitor
.insert(channel
)
179 def onPart(self
, user
, channel
):
180 self
.onJoin(None, channel
)
182 def onKick(self
, kicker
, victim
, channel
, reason
):
183 self
.onJoin(None, channel
)
185 def getCommands(self
):
186 return self
.commands_admin