excid3 / logbot

A minimal IRC bot for logging channels
http://excid3.com/blog/projects/logbot
GNU General Public License v2.0
59 stars 29 forks source link

Channel key support #25

Open timypcr opened 6 years ago

timypcr commented 6 years ago

I'd like to use logbot for an internal IRC server at work but the channels we have setup require a key, is there quick modification that can be made so logbot can support this?

Thanks, Tim

FiXato commented 6 years ago

the c.join command at https://github.com/excid3/logbot/blob/db892646b7b814a2ad6b5eca29ea51a1eb5a6bf0/logbot.py#L359-L360 theoretically supports a second parameter for a channel key: https://github.com/excid3/logbot/blob/db892646b7b814a2ad6b5eca29ea51a1eb5a6bf0/irclib.py#L689-L691

Channels are set at https://github.com/excid3/logbot/blob/db892646b7b814a2ad6b5eca29ea51a1eb5a6bf0/logbot.py#L219

So, it doesn't look like there is a clean way to quickly do it without rewriting things.

Since channel names should not contain spaces, you could add a space + channel key to your channels defined at https://github.com/excid3/logbot/blob/db892646b7b814a2ad6b5eca29ea51a1eb5a6bf0/logbot.py#L72 Then extract the channel keys with a split before they are lowercased and assigned to self.chan, and then use that as a second parameter at the join command.

I don't really use this library myself anymore, so to be fair, I don't really have the motivation to submit a pull request with working code for this feature request, but hopefully this helps you (or @excid3) add a workaround yourself. :)

FiXato commented 6 years ago

If someone does end up rewriting it, I would suggest you make use of the IRC protocol's format of the JOIN command: https://tools.ietf.org/html/rfc2812#page-16 And just have the user define the channels and keys in the argument format the server expects; the actual channel names could then be extracted (and downcased if you want) from the actual join replies from the server. That way you don't have to match up the channel keys with each channel, and just rely on the server to do the matching (as long as the keys are entered in the right order as the channels; AFAIK it doesn't matter though if there are channels without keys in between those that require one; the server should be smart enough). Basically use comma delimiters for the channel names, followed by a space, followed by comma-separated channel keys.

excid3 commented 6 years ago

Since keys is just a second parameter, you can create a KEYS array next to channels and then just pass those in during this loop: https://github.com/excid3/logbot/blob/db892646b7b814a2ad6b5eca29ea51a1eb5a6bf0/logbot.py#L359-L360

Should be really simple to fix.