1 # Copyright (C) 2013 W. Trevor King <wking@tremily.us>
3 # This file is part of ipython-irc.
5 # ipython-irc is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free Software
7 # Foundation, either version 3 of the License, or (at your option) any later
10 # ipython-irc is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 # You should have received a copy of the GNU General Public License along with
16 # ipython-irc. If not, see <http://www.gnu.org/licenses/>.
18 """An IRC iframe using webchat.freenode.net
21 import urllib.parse as _urllib_parse
23 import IPython.display as _IPython_display
32 """An IRC iframe using webchat clients
34 Currently only supports freenode (via webchat.freenode.net).
38 IRC(nick='you', channels=('#ipython', ...)).show()
40 def __init__(self, server='chat.freenode.net', nick=None,
41 channels=('#ipython','#rogue'), width=647, height=400):
44 self.channels = channels
47 if self.server not in [
50 raise NotImplementedError(self.server)
54 for attr in ['nick', 'channels']:
55 value = getattr(self, attr)
57 if attr in ['channels']:
58 value = ','.join(chan.lstrip('#') for chan in value)
63 'http://webchat.freenode.net',
64 _urllib_parse.urlencode(data)
66 return '<iframe src="{}" width="{}" height="{}"></iframe>'.format(
67 url, self.width, self.height)
70 _IPython_display.display(_IPython_display.HTML(self._html()))