Merge lp://staging/~verterok/lalita/misc-fixes into lp://staging/lalita

Proposed by Guillermo Gonzalez
Status: Superseded
Proposed branch: lp://staging/~verterok/lalita/misc-fixes
Merge into: lp://staging/lalita
Diff against target: None lines
To merge this branch: bzr merge lp://staging/~verterok/lalita/misc-fixes
Reviewer Review Type Date Requested Status
laliputienses Pending
Review via email: mp+11629@code.staging.launchpad.net

This proposal has been superseded by a proposal from 2009-09-22.

To post a comment you must log in.
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

Various fixes:
pass encoding to Plugin.__init__ so the plugins know the encoding
Seen plugin it's now persistent, using shelve.Shelf and other minor fixes
add meta commands support via privmsg
translate the messages in dispatcher.py (we need some internationalion support...gettext?)
allow configure msg length

89. By Guillermo Gonzalez

merge with trunk

90. By Guillermo Gonzalez

revert translations and fix bad merges

91. By Guillermo Gonzalez

update persistent Seen plugin to the new code (and tests for it)
remove privmsg metacommands support
fixed bad merge

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.py.example'
2--- config.py.example 2009-03-27 14:56:55 +0000
3+++ config.py.example 2009-05-19 00:14:26 +0000
4@@ -8,9 +8,10 @@
5 channels= {
6 '#humites': dict (plugins={
7 'url.Url': { },
8+ 'seen.Seen': { },
9 }),
10 '#perrites': dict (plugins={
11- 'seen.Seen': { },
12+ 'seen.Seen': {'base_dir':'<path/to/shelves_dir>'}, # two shelf's are going to be created (iolog and saylog)
13 }),
14 },
15 plugins= {
16
17=== modified file 'core/__init__.py'
18--- core/__init__.py 2009-04-18 17:31:52 +0000
19+++ core/__init__.py 2009-09-11 20:45:22 +0000
20@@ -36,4 +36,5 @@
21
22 def __init__(self, params, log_level):
23 self.nickname = params["nickname"]
24+ self.encoding = params['encoding']
25 self.logger = _PluginLogger(self, log_level)
26
27=== modified file 'core/dispatcher.py'
28--- core/dispatcher.py 2009-08-09 20:59:23 +0000
29+++ core/dispatcher.py 2009-09-11 20:45:22 +0000
30@@ -58,6 +58,9 @@
31 self._plugins = {}
32 self._channel_filter = {}
33
34+ def init(self, config):
35+ self.length_msg = int(config.get('length_msg', LENGTH_MSG))
36+
37 def new_plugin(self, plugin, channel):
38 plugin.register = self.register
39 plugin.say = functools.partial(self._msg_from_plugin, plugin)
40@@ -96,7 +99,7 @@
41 self.msg(to_where, message)
42
43 def msg(self, to_where, message):
44- self.bot.msg(to_where, message.encode("utf8"), LENGTH_MSG)
45+ self.bot.msg(to_where, message.encode("utf8"), self.length_msg)
46
47 def _error(self, error, instance):
48 logger.debug("ERROR in instance %s: %s", instance, error)
49@@ -124,7 +127,16 @@
50 # all of them)
51 cmds = [x[2] for x in self._callbacks[events.COMMAND]]
52 if cmds != [None] and command not in itertools.chain(*cmds):
53- self.msg(channel, u"%s: No existe esa órden!" % user)
54+ self.msg(channel, u"%s: %s: command not found!" % (user, command))
55+ return
56+ elif event == events.PRIVATE_MESSAGE:
57+ user, msg = args
58+ cmd_args = msg.split(' ')
59+ command = cmd_args[0].strip()
60+ if command in META_COMMANDS:
61+ meth = getattr(self, "handle_" + META_COMMANDS[command[0].strip()])
62+ args = [user, user, command] + cmd_args[1:]
63+ meth(*args)
64 return
65
66 all_registered = self._callbacks.get(event)
67@@ -179,7 +191,7 @@
68 def handle_meta_help(self, user, channel, command, *args):
69 '''Handles the HELP meta command.'''
70 if not args:
71- txt = u'"list" para ver las órdenes; "help cmd" para cada uno'
72+ txt = u'"list" To see the available commands ; "help cmd" for specific command help'
73 self.msg(channel, txt)
74 return
75
76@@ -187,7 +199,7 @@
77 try:
78 registered = self._callbacks[events.COMMAND]
79 except KeyError:
80- self.msg(channel, u"No hay ninguna órden registrada...")
81+ self.msg(channel, u"PANIC! I have no commands!!!")
82 return
83
84 # get the docstrings... to get uniques we don't use a dictionary just
85@@ -203,7 +215,7 @@
86
87 # no docs!
88 if not docs:
89- self.msg(channel, u"Esa órden no existe...")
90+ self.msg(channel, u"No such command...")
91 return
92
93 # only one method for that command
94@@ -213,10 +225,10 @@
95 return
96
97 # several methods for the same command
98- self.msg(channel, u"Hay varios métodos para esa órden:")
99+ self.msg(channel, u"Several handlers for the same command:")
100 for doc in docs:
101 t = doc if doc else u"No tiene documentación, y yo no soy adivina..."
102- self.msg(channel, u" - " + t)
103+ self.msg(channel, u" - " + doc)
104
105 def handle_meta_list(self, user, channel, command, *args):
106 '''Handles the LIST meta command.'''
107@@ -226,5 +238,5 @@
108 txt = u"Decí alpiste, no hay órdenes todavía..."
109 else:
110 onlys = set(itertools.chain(*cmds))
111- txt = u"Las órdenes son: %s" % list(sorted(onlys))
112+ txt = u"The available commands are: %s" % list(sorted(onlys))
113 self.msg(channel, txt)
114
115=== modified file 'ircbot.py'
116--- ircbot.py 2009-08-07 04:14:54 +0000
117+++ ircbot.py 2009-09-11 20:45:22 +0000
118@@ -86,6 +86,7 @@
119
120 def load_server_plugins(self):
121 params = {'nickname': self.nickname,
122+ 'encoding': self.encoding_server
123 }
124
125 plugins= self.config.get ('plugins', {})
126@@ -95,6 +96,8 @@
127
128 def load_channel_plugins(self, channel):
129 params = {'nickname': self.nickname,
130+ 'encoding': self.encoding_channels.get('channel',
131+ self.encoding_server)
132 }
133
134 plugins= self.config['channels'][channel].get ('plugins', {})
135@@ -113,6 +116,8 @@
136 logger.info("connected to %s:%d" %
137 (self.config['host'], self.config['port']))
138 self.load_server_plugins()
139+ # configure the dispatcher
140+ self.dispatcher.init(self.config)
141 self.dispatcher.push(events.CONNECTION_MADE)
142
143 def connectionLost (self, reason):
144
145=== modified file 'plugins/seen.py'
146--- plugins/seen.py 2009-04-10 00:09:58 +0000
147+++ plugins/seen.py 2009-09-11 20:45:22 +0000
148@@ -3,14 +3,23 @@
149 # (c) 2009 Marcos Dione <mdione@grulic.org.ar>
150
151 import datetime
152+import os
153+import shelve
154
155 from lalita import Plugin
156
157 class Seen(Plugin):
158 def init(self, config):
159- self.iolog= {}
160- self.saidlog= {}
161- self.config= dict (clever=True)
162+ base = config.get('base_dir', None)
163+ if base is not None:
164+ if not os.path.exists(base):
165+ os.makedirs(base)
166+ self.iolog = shelve.open(os.path.join(base, 'iolog'))
167+ self.saidlog = shelve.open(os.path.join(base, 'saidlog'))
168+ else:
169+ self.iolog = {}
170+ self.saidlog = {}
171+ self.config = dict (clever=True)
172 self.config.update (config)
173
174 self.register(self.events.JOIN, self.joined)
175@@ -33,17 +42,20 @@
176
177 def log(self, channel, nick, what):
178 # server messages are from ''; ignore those and myself
179- if nick not in (self.nickname, ''):
180+ if nick.strip() not in (self.nickname, ''):
181 if what in ('joined', 'parted'):
182- self.iolog[nick] = (what, datetime.datetime.now())
183+ self.iolog[nick.encode(self.encoding)] = (what, datetime.datetime.now())
184 else:
185- self.saidlog[nick] = (what, datetime.datetime.now())
186+ self.saidlog[nick.encode(self.encoding)] = (what, datetime.datetime.now())
187 self.logger.debug("logged %s: %s", nick, what)
188
189- def seen (self, user, channel, command, nick):
190- if not self.config['clever'] or nick not in (self.nickname, user):
191- what1, when1 = self.iolog.get (nick, (None, None))
192- what2, when2 = self.saidlog.get (nick, (None, None))
193+ def seen (self, user, channel, command, nick=None):
194+ """ the last thing a <user> said in the channel (or when he joined/parted)"""
195+ if nick is None:
196+ what = 'no <user> specified'
197+ elif nick and nick.strip() not in (self.nickname, user):
198+ what1, when1 = self.iolog.get(nick.encode(self.encoding), (None, None))
199+ what2, when2 = self.saidlog.get(nick.encode(self.encoding), (None, None))
200 self.logger.debug (str ((what1, when1, what2, when2)))
201 # didn't se him at all or he has just been silent
202 # NOTE: I know this can be reduced a little,
203@@ -60,11 +72,12 @@
204 what= u"%s: [%s] -- parted" % (user, when1.strftime ("%x %X"))
205 else: # command=='last' or when1<when2 or when1 is None
206 what= u"%s: [%s] %s" % (user, when2.strftime ("%x %X"), what2)
207- elif nick==self.nickname:
208+ elif nick==self.nickname and self.config.get('clever', True):
209 what= u"%s: acástoi, papafrita!" % user
210- elif nick==user:
211+ elif nick==user and self.config.get('clever', True):
212 what= u"%s: andá mirate en el espejo del baño" % user
213-
214+ else:
215+ return
216 self.say (channel, what)
217
218 # end

Subscribers

People subscribed via source and target branches