Merge lp:~marco-gallotta/ibid/channel-key into lp:~ibid-core/ibid/old-trunk-1.6

Proposed by marcog
Status: Merged
Approved by: Stefano Rivera
Approved revision: 968
Merged at revision: 997
Proposed branch: lp:~marco-gallotta/ibid/channel-key
Merge into: lp:~ibid-core/ibid/old-trunk-1.6
Diff against target: 93 lines (+23/-12)
2 files modified
ibid/plugins/sources.py (+13/-6)
ibid/source/irc.py (+10/-6)
To merge this branch: bzr merge lp:~marco-gallotta/ibid/channel-key
Reviewer Review Type Date Requested Status
Max Rabkin Approve
Stefano Rivera Approve
Keegan Carruthers-Smith Needs Fixing
Review via email: mp+30867@code.launchpad.net

Commit message

Provide the possibility to join a channel with a key. Only supported in IRC so far.

Description of the change

Provides the possibility to join a channel with a key. It only works online as I have not yet thought of a nice way to add a key to the config file.

To post a comment you must log in.
Revision history for this message
Stefano Rivera (stefanor) wrote :

please update the help string

review: Needs Fixing
Revision history for this message
Keegan Carruthers-Smith (keegan-csmith) wrote :

You removed logging for source.irc.Ircbot.join. You also unneccessarily added the key=None argument to join, rather just leave join as before.

review: Needs Fixing
Revision history for this message
Max Rabkin (max-rabkin) wrote :

u'%s cannot join key-protected channels' should be u'I cannot join key-protected channels on %s'

review: Needs Fixing
Revision history for this message
marcog (marco-gallotta) wrote :

> u'%s cannot join key-protected channels' should be u'I cannot join key-protected channels on %s'

r960

>You removed logging for source.irc.Ircbot.join. You also unneccessarily added the key=None argument to join, rather just leave join as before.

r961

> please update the help string

r962

lp:~marco-gallotta/ibid/channel-key updated
960. By marcog

source cannot -> i cannot on source

961. By marcog

Put join()'s logging back and remove useless arg

962. By marcog

Update help string and allow option using/with in syntax

Revision history for this message
Stefano Rivera (stefanor) wrote :

"\s+(?:(?:using|with)?\s+" That requires two spaces without the using or with, right?

> def join_with_key(self, channel, key=None):

Why is key optional? In fact why do we need this method, can we not just add an optional argument to join?

Revision history for this message
Stefano Rivera (stefanor) :
review: Needs Fixing
lp:~marco-gallotta/ibid/channel-key updated
963. By marcog

Remove useless group from channel join regex

Revision history for this message
marcog (marco-gallotta) wrote :

> "\s+(?:(?:using|with)?\s+" That requires two spaces without the using or with,
> right?
>
> > def join_with_key(self, channel, key=None):
>
> Why is key optional? In fact why do we need this method, can we not just add
> an optional argument to join?

join is an inherited method, so you can't change its arguments (afaik). I've made key non-optional here though (r964).

lp:~marco-gallotta/ibid/channel-key updated
964. By marcog

Make key required in join_with_key

Revision history for this message
marcog (marco-gallotta) wrote :

> "\s+(?:(?:using|with)?\s+" That requires two spaces without the using or with, right?

r965

lp:~marco-gallotta/ibid/channel-key updated
965. By marcog

Fix potential double-spaces in channel regex

Revision history for this message
marcog (marco-gallotta) wrote :

> why do we need this method, can we not just add an optional argument to join?

Now using single join_with_key and no join method (r966).

lp:~marco-gallotta/ibid/channel-key updated
966. By marcog

Change to single join_with_key method

Revision history for this message
Stefano Rivera (stefanor) wrote :

Why not use the same "join" name in the protocol, after all it's a pretty direct override of it.

lp:~marco-gallotta/ibid/channel-key updated
967. By marcog

Rather override join

Revision history for this message
marcog (marco-gallotta) wrote :

> Why not use the same "join" name in the protocol, after all it's a pretty
> direct override of it.

Sorry, I was being daft. I totally missed the join_with_key I added in SourceFactory many months ago which was causing issues doing this. It's done and works now (r967).

Revision history for this message
Stefano Rivera (stefanor) wrote :

One more: Can we use $factory.supports instead of catching TypeError?

review: Needs Fixing
Revision history for this message
marcog (marco-gallotta) wrote :

> One more: Can we use $factory.supports instead of catching TypeError?

r968

lp:~marco-gallotta/ibid/channel-key updated
968. By marcog

Use $factory.supports instead of catching TypeError

Revision history for this message
Stefano Rivera (stefanor) :
review: Approve
Revision history for this message
Stefano Rivera (stefanor) wrote :

What about keys for autojoined channels?

Revision history for this message
Stefano Rivera (stefanor) wrote :

> What about keys for autojoined channels?

Marco says this will be handled in a future branch. That's ok with me.

Revision history for this message
Max Rabkin (max-rabkin) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/plugins/sources.py'
2--- ibid/plugins/sources.py 2010-09-30 21:25:01 +0000
3+++ ibid/plugins/sources.py 2011-01-20 10:54:11 +0000
4@@ -20,15 +20,15 @@
5 }
6
7 class Actions(Processor):
8- usage = u"""(join|part|leave) [<channel> [on <source>]]
9+ usage = u"""(join|part|leave) [<channel> [on <source>] [using key <key>]]
10 change nick to <nick> [on <source>]"""
11 features = ('actions',)
12
13 permission = 'sources'
14
15- @match(r'^(join|part|leave)(?:\s+(\S*))?(?:\s+on\s+(\S+))?$')
16+ @match(r'^(join|part|leave)(?:\s+(\S*))?(?:\s+on\s+(\S+))?(?:(?:\s+(?:using|with))?\s+(?:key\s+)?(\S+))?$')
17 @authorise()
18- def channel(self, event, action, channel, source):
19+ def channel(self, event, action, channel, source, key):
20 action = action.lower()
21
22 if not source:
23@@ -45,11 +45,18 @@
24 source = ibid.sources[source]
25
26 if not hasattr(source, 'join'):
27- event.addresponse(u'%s cannot join/part channels', source.name)
28+ event.addresponse(u'I cannot join/part channels on %s', source.name)
29 return
30
31 if action == 'join':
32- source.join(channel)
33+ if key:
34+ if 'channel key' in source.supports:
35+ source.join(channel, key)
36+ else:
37+ event.addresponse(u'I cannot use keys on %s', source.name)
38+ return
39+ else:
40+ source.join(channel)
41 event.addresponse(u'Joining %s', channel)
42 else:
43 source.leave(channel)
44@@ -69,7 +76,7 @@
45 source = ibid.sources[source]
46
47 if not hasattr(source, 'change_nick'):
48- event.addresponse(u'%s cannot change nicks', source)
49+ event.addresponse(u'I cannot change nicks on %s', source)
50 else:
51 source.change_nick(nick)
52 event.addresponse(u'Changing nick to %s', nick)
53
54=== modified file 'ibid/source/irc.py'
55--- ibid/source/irc.py 2010-12-24 16:40:41 +0000
56+++ ibid/source/irc.py 2011-01-20 10:54:11 +0000
57@@ -208,9 +208,13 @@
58 self.msg(raw_target, raw_message)
59 self.factory.log.debug(u"Sent privmsg to %s: %s", target, message)
60
61- def join(self, channel):
62- self.factory.log.info(u"Joining %s", channel)
63- irc.IRCClient.join(self, channel.encode('utf-8'))
64+ def join(self, channel, key=None):
65+ if key:
66+ self.factory.log.info(u"Joining %s with key %s", channel, key)
67+ key = key.encode('utf-8')
68+ else:
69+ self.factory.log.info(u"Joining %s", channel)
70+ irc.IRCClient.join(self, channel.encode('utf-8'), key)
71
72 def joined(self, channel):
73 event = Event(self.factory.name, u'source')
74@@ -300,7 +304,7 @@
75 protocol = Ircbot
76
77 auth = ('hostmask', 'nickserv')
78- supports = ('action', 'notice', 'topic')
79+ supports = ('action', 'notice', 'topic', 'channel key')
80
81 port = IntOption('port', 'Server port number', 6667)
82 ssl = BoolOption('ssl', 'Use SSL', False)
83@@ -345,8 +349,8 @@
84 self.proto.transport.loseConnection()
85 return True
86
87- def join(self, channel):
88- return self.proto.join(channel)
89+ def join(self, channel, key=None):
90+ return self.proto.join(channel, key)
91
92 def leave(self, channel):
93 return self.proto.leave(channel)

Subscribers

People subscribed via source and target branches