-
Notifications
You must be signed in to change notification settings - Fork 607
/
irc.py
774 lines (641 loc) · 26.7 KB
/
irc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
from __future__ import absolute_import
import logging
import sys
import threading
import subprocess
import struct
import re
from markdown import Markdown
from markdown.extensions.extra import ExtraExtension
from errbot.backends.base import Message, Room, RoomError, \
RoomNotJoinedError, Stream, \
RoomOccupant, ONLINE, Person
from errbot.core import ErrBot
from errbot.utils import rate_limited
from errbot.rendering.ansiext import AnsiExtension, enable_format, \
CharacterTable, NSC
# Can't use __name__ because of Yapsy
log = logging.getLogger('errbot.backends.irc')
IRC_CHRS = CharacterTable(fg_black=NSC('\x0301'),
fg_red=NSC('\x0304'),
fg_green=NSC('\x0303'),
fg_yellow=NSC('\x0308'),
fg_blue=NSC('\x0302'),
fg_magenta=NSC('\x0306'),
fg_cyan=NSC('\x0310'),
fg_white=NSC('\x0300'),
fg_default=NSC('\x03'),
bg_black=NSC('\x03,01'),
bg_red=NSC('\x03,04'),
bg_green=NSC('\x03,03'),
bg_yellow=NSC('\x03,08'),
bg_blue=NSC('\x03,02'),
bg_magenta=NSC('\x03,06'),
bg_cyan=NSC('\x03,10'),
bg_white=NSC('\x03,00'),
bg_default=NSC('\x03,'),
fx_reset=NSC('\x03'),
fx_bold=NSC('\x02'),
fx_italic=NSC('\x1D'),
fx_underline=NSC('\x1F'),
fx_not_italic=NSC('\x0F'),
fx_not_underline=NSC('\x0F'),
fx_normal=NSC('\x0F'),
fixed_width='',
end_fixed_width='',
inline_code='',
end_inline_code='')
IRC_NICK_REGEX = r'[a-zA-Z\[\]\\`_\^\{\|\}][a-zA-Z0-9\[\]\\`_\^\{\|\}-]+'
IRC_MESSAGE_SIZE_LIMIT = 510
try:
import irc.connection
from irc.client import ServerNotConnectedError, NickMask
from irc.bot import SingleServerIRCBot
except ImportError:
log.fatal("""You need the IRC support to use IRC, you can install it with:
pip install errbot[IRC]
""")
sys.exit(-1)
def irc_md():
"""This makes a converter from markdown to mirc color format.
"""
md = Markdown(output_format='irc', extensions=[ExtraExtension(), AnsiExtension()])
md.stripTopLevelTags = False
return md
class IRCPerson(Person):
def __init__(self, mask):
self._nickmask = NickMask(mask)
@property
def nick(self):
return self._nickmask.nick
@property
def user(self):
return self._nickmask.user
@property
def host(self):
return self._nickmask.host
# generic compatibility
person = nick
@property
def client(self):
return self._nickmask.userhost
@property
def fullname(self):
# TODO: this should be possible to get
return None
@property
def aclattr(self):
return IRCBackend.aclpattern.format(nick=self._nickmask.nick,
user=self._nickmask.user,
host=self._nickmask.host)
def __unicode__(self):
return str(self._nickmask)
def __str__(self):
return self.__unicode__()
def __eq__(self, other):
if not isinstance(other, IRCPerson):
log.warning("Weird you are comparing an IRCPerson to a %s.", type(other))
return False
return self.person == other.person
class IRCRoomOccupant(IRCPerson, RoomOccupant):
def __init__(self, mask, room):
super().__init__(mask)
self._room = room
@property
def room(self):
return self._room
def __unicode__(self):
return "%s" % self._nickmask
def __str__(self):
return self.__unicode__()
def __repr__(self):
return "<{} - {}>".format(self.__unicode__(), super().__repr__())
class IRCRoom(Room):
"""
Represent the specifics of a IRC Room/Channel.
This lifecycle of this object is:
- Created in IRCConnection.on_join
- The joined status change in IRCConnection on_join/on_part
- Deleted/destroyed in IRCConnection.on_disconnect
"""
def __init__(self, room, bot):
self._bot = bot
self.room = room
self.connection = self._bot.conn.connection
self._topic_lock = threading.Lock()
self._topic = None
def __unicode__(self):
return self.room
def __str__(self):
return self.__unicode__()
def __repr__(self):
return "<{} - {}>".format(self.__unicode__(), super().__repr__())
def cb_set_topic(self, current_topic):
"""
Store the current topic for this room.
This method is called by the IRC backend when a `currenttopic`,
`topic` or `notopic` IRC event is received to store the topic set for this channel.
This function is not meant to be executed by regular plugins.
To get or set
"""
with self._topic_lock:
self._topic = current_topic
def join(self, username=None, password=None):
"""
Join the room.
If the room does not exist yet, this will automatically call
:meth:`create` on it first.
"""
if username is not None:
log.debug("Ignored username parameter on join(), it is unsupported on this back-end.")
if password is None:
password = "" # nosec
self.connection.join(self.room, key=password)
log.info("Joined room {}".format(self.room))
def leave(self, reason=None):
"""
Leave the room.
:param reason:
An optional string explaining the reason for leaving the room
"""
if reason is None:
reason = ""
self.connection.part(self.room, reason)
log.info("Leaving room {} with reason '{}'".format(self.room, reason if reason is not None else ''))
def create(self):
"""
Not supported on this back-end. Will join the room to ensure it exists, instead.
"""
logging.warning(
"IRC back-end does not support explicit creation, joining room "
"instead to ensure it exists."
)
self.join()
def destroy(self):
"""
Not supported on IRC, will raise :class:`~errbot.backends.base.RoomError`.
"""
raise RoomError("IRC back-end does not support destroying rooms.")
@property
def exists(self):
"""
Boolean indicating whether this room already exists or not.
:getter:
Returns `True` if the room exists, `False` otherwise.
"""
logging.warning(
"IRC back-end does not support determining if a room exists. "
"Returning the result of joined instead."
)
return self.joined
@property
def joined(self):
"""
Boolean indicating whether this room has already been joined.
:getter:
Returns `True` if the room has been joined, `False` otherwise.
"""
return self.room in self._bot.conn.channels.keys()
@property
def topic(self):
"""
The room topic.
:getter:
Returns the topic (a string) if one is set, `None` if no
topic has been set at all.
"""
if not self.joined:
raise RoomNotJoinedError("Must join the room to get the topic")
with self._topic_lock:
return self._topic
@topic.setter
def topic(self, topic):
"""
Set the room's topic.
:param topic:
The topic to set.
"""
if not self.joined:
raise RoomNotJoinedError("Must join the room to set the topic")
self.connection.topic(self.room, topic)
@property
def occupants(self):
"""
The room's occupants.
:getter:
Returns a list of occupants.
:raises:
:class:`~MUCNotJoinedError` if the room has not yet been joined.
"""
occupants = []
try:
for nick in self._bot.conn.channels[self.room].users():
occupants.append(IRCRoomOccupant(nick, room=self.room))
except KeyError:
raise RoomNotJoinedError("Must be in a room in order to \
see occupants.")
return occupants
def invite(self, *args):
"""
Invite one or more people into the room.
:*args:
One or more nicks to invite into the room.
"""
for nick in args:
self.connection.invite(nick, self.room)
log.info("Invited {} to {}".format(nick, self.room))
def __eq__(self, other):
if not isinstance(other, IRCRoom):
log.warning("This is weird you are comparing an IRCRoom to a %s", type(other))
return False
return self.room == other.room
class IRCConnection(SingleServerIRCBot):
def __init__(self,
bot,
nickname,
server,
port=6667,
ssl=False,
bind_address=None,
ipv6=False,
password=None,
username=None,
nickserv_password=None,
private_rate=1,
channel_rate=1,
reconnect_on_kick=5,
reconnect_on_disconnect=5):
self.use_ssl = ssl
self.use_ipv6 = ipv6
self.bind_address = bind_address
self.bot = bot
# manually decorate functions
if private_rate:
self.send_private_message = rate_limited(private_rate)(self.send_private_message)
if channel_rate:
self.send_public_message = rate_limited(channel_rate)(self.send_public_message)
self._reconnect_on_kick = reconnect_on_kick
self._pending_transfers = {}
self._rooms_lock = threading.Lock()
self._rooms = {}
self._recently_joined_to = set()
self.nickserv_password = nickserv_password
if username is None:
username = nickname
self.transfers = {}
super().__init__([(server, port, password)], nickname, username, reconnection_interval=reconnect_on_disconnect)
def connect(self, *args, **kwargs):
# Decode all input to UTF-8, but use a replacement character for
# unrecognized byte sequences
# (as described at https://pypi.python.org/pypi/irc)
self.connection.buffer_class.errors = 'replace'
connection_factory_kwargs = {}
if self.use_ssl:
import ssl
connection_factory_kwargs['wrapper'] = ssl.wrap_socket
if self.bind_address is not None:
connection_factory_kwargs['bind_address'] = self.bind_address
if self.use_ipv6:
connection_factory_kwargs['ipv6'] = True
connection_factory = irc.connection.Factory(**connection_factory_kwargs)
self.connection.connect(*args, connect_factory=connection_factory, **kwargs)
def on_welcome(self, _, e):
log.info("IRC welcome %s" % e)
# try to identify with NickServ if there is a NickServ password in the
# config
if self.nickserv_password:
msg = 'identify %s' % self.nickserv_password
self.send_private_message('NickServ', msg)
# Must be done in a background thread, otherwise the join room
# from the ChatRoom plugin joining channels from CHATROOM_PRESENCE
# ends up blocking on connect.
t = threading.Thread(target=self.bot.connect_callback)
t.setDaemon(True)
t.start()
def _pubmsg(self, e, notice=False):
msg = Message(e.arguments[0], extras={'notice': notice})
room_name = e.target
if room_name[0] != '#' and room_name[0] != '$':
raise Exception('[%s] is not a room' % room_name)
room = IRCRoom(room_name, self.bot)
msg.frm = IRCRoomOccupant(e.source, room)
msg.to = room
msg.nick = msg.frm.nick # FIXME find the real nick in the channel
self.bot.callback_message(msg)
possible_mentions = re.findall(IRC_NICK_REGEX, e.arguments[0])
room_users = self.channels[room_name].users()
mentions = filter(lambda x: x in room_users, possible_mentions)
if mentions:
mentions = [self.bot.build_identifier(mention) for mention in mentions]
self.bot.callback_mention(msg, mentions)
def _privmsg(self, e, notice=False):
msg = Message(e.arguments[0], extras={'notice': notice})
msg.frm = IRCPerson(e.source)
msg.to = IRCPerson(e.target)
self.bot.callback_message(msg)
def on_pubmsg(self, _, e):
self._pubmsg(e)
def on_privmsg(self, _, e):
self._privmsg(e)
def on_pubnotice(self, _, e):
self._pubmsg(e, True)
def on_privnotice(self, _, e):
self._privmsg(e, True)
def on_kick(self, _, e):
if not self._reconnect_on_kick:
log.info("RECONNECT_ON_KICK is 0 or None, won't try to reconnect")
return
log.info("Got kicked out of %s... reconnect in %d seconds... " % (e.target, self._reconnect_on_kick))
def reconnect_channel(name):
log.info("Reconnecting to %s after having beeing kicked" % name)
self.bot.query_room(name).join()
t = threading.Timer(self._reconnect_on_kick, reconnect_channel, [e.target, ])
t.daemon = True
t.start()
def send_private_message(self, to, line):
try:
self.connection.privmsg(to, line)
except ServerNotConnectedError:
pass # the message will be lost
def send_public_message(self, to, line):
try:
self.connection.privmsg(to, line)
except ServerNotConnectedError:
pass # the message will be lost
def on_disconnect(self, connection, event):
self._rooms = {}
self.bot.disconnect_callback()
def send_stream_request(self, identifier, fsource, name=None, size=None, stream_type=None):
# Creates a new connection
dcc = self.dcc_listen("raw")
msg_parts = map(str, (
'SEND',
name,
irc.client.ip_quad_to_numstr(dcc.localaddress),
dcc.localport,
size,
))
msg = subprocess.list2cmdline(msg_parts)
self.connection.ctcp("DCC", identifier.nick, msg)
stream = Stream(identifier, fsource, name, size, stream_type)
self.transfers[dcc] = stream
return stream
def on_dcc_connect(self, dcc, event):
stream = self.transfers.get(dcc, None)
if stream is None:
log.error("DCC connect on a none registered connection")
return
log.debug("Start transfer for %s" % stream.identifier)
stream.accept()
self.send_chunk(stream, dcc)
def on_dcc_disconnect(self, dcc, event):
self.transfers.pop(dcc)
def on_part(self, connection, event):
"""
Handler of the part IRC Message/event.
The part message is sent to the client as a confirmation of a
/PART command sent by someone in the room/channel.
If the event.source contains the bot nickname then we need to fire
the :meth:`~errbot.backends.base.Backend.callback_room_left` event on the bot.
:param connection: Is an 'irc.client.ServerConnection' object
:param event: Is an 'irc.client.Event' object
The event.source contains the nickmask of the user that
leave the room
The event.target contains the channel name
"""
leaving_nick = event.source.nick
leaving_room = event.target
if self.bot.bot_identifier.nick == leaving_nick:
with self._rooms_lock:
self.bot.callback_room_left(self._rooms[leaving_room])
log.info("Left room {}".format(leaving_room))
def on_endofnames(self, connection, event):
"""
Handler of the enfofnames IRC message/event.
The endofnames message is sent to the client when the server finish
to send the list of names of the room ocuppants.
This usually happens when you join to the room.
So in this case, we use this event to determine that our bot is
finally joined to the room.
:param connection: Is an 'irc.client.ServerConnection' object
:param event: Is an 'irc.client.Event' object
the event.arguments[0] contains the channel name
"""
# The event.arguments[0] contains the channel name.
# We filter that to avoid a misfire of the event.
room_name = event.arguments[0]
with self._rooms_lock:
if room_name in self._recently_joined_to:
self._recently_joined_to.remove(room_name)
self.bot.callback_room_joined(self._rooms[room_name])
def on_join(self, connection, event):
"""
Handler of the join IRC message/event.
Is in response of a /JOIN client message.
:param connection: Is an 'irc.client.ServerConnection' object
:param event: Is an 'irc.client.Event' object
the event.target contains the channel name
"""
# We can't fire the room_joined event yet,
# because we don't have the occupants info.
# We need to wait to endofnames message.
room_name = event.target
with self._rooms_lock:
if room_name not in self._rooms:
self._rooms[room_name] = IRCRoom(room_name, self.bot)
self._recently_joined_to.add(room_name)
def on_currenttopic(self, connection, event):
"""
When you Join a room with a topic set this event fires up to
with the topic information.
If the room that you join don't have a topic set, nothing happens.
Here is NOT the place to fire the :meth:`~errbot.backends.base.Backend.callback_room_topic` event for
that case exist on_topic.
:param connection: Is an 'irc.client.ServerConnection' object
:param event: Is an 'irc.client.Event' object
The event.arguments[0] contains the room name
The event.arguments[1] contains the topic of the room.
"""
room_name, current_topic = event.arguments
with self._rooms_lock:
self._rooms[room_name].cb_set_topic(current_topic)
def on_topic(self, connection, event):
"""
On response to the /TOPIC command if the room have a topic.
If the room don't have a topic the event fired is on_notopic
:param connection: Is an 'irc.client.ServerConnection' object
:param event: Is an 'irc.client.Event' object
The event.target contains the room name.
The event.arguments[0] contains the topic name
"""
room_name = event.target
current_topic = event.arguments[0]
with self._rooms_lock:
self._rooms[room_name].cb_set_topic(current_topic)
self.bot.callback_room_topic(self._rooms[room_name])
def on_notopic(self, connection, event):
"""
This event fires ip when there is no topic set on a room
:param connection: Is an 'irc.client.ServerConnection' object
:param event: Is an 'irc.client.Event' object
The event.arguments[0] contains the room name
"""
room_name = event.arguments[0]
with self._rooms_lock:
self._rooms[room_name].cb_set_topic(None)
self.bot.callback_room_topic(self._rooms[room_name])
@staticmethod
def send_chunk(stream, dcc):
data = stream.read(4096)
dcc.send_bytes(data)
stream.ack_data(len(data))
def on_dccmsg(self, dcc, event):
stream = self.transfers.get(dcc, None)
if stream is None:
log.error("DCC connect on a none registered connection")
return
acked = struct.unpack("!I", event.arguments[0])[0]
if acked == stream.size:
log.info("File %s successfully transfered to %s" % (stream.name, stream.identifier))
dcc.disconnect()
self.transfers.pop(dcc)
elif acked == stream.transfered:
log.debug("Chunk for file %s successfully transfered to %s (%d/%d) " %
(stream.name, stream.identifier, stream.transfered, stream.size))
self.send_chunk(stream, dcc)
else:
log.debug("Partial chunk for file %s successfully transfered to %s (%d/%d), wait for more" %
(stream.name, stream.identifier, stream.transfered, stream.size))
def away(self, message=""):
"""
Extend the original implementation to support AWAY.
To set an away message, set message to something.
To cancel an away message, leave message at empty string.
"""
self.connection.send_raw(" ".join(["AWAY", message]).strip())
class IRCBackend(ErrBot):
aclpattern = '{nick}!{user}@{host}'
def __init__(self, config):
if hasattr(config, 'IRC_ACL_PATTERN'):
IRCBackend.aclpattern = config.IRC_ACL_PATTERN
identity = config.BOT_IDENTITY
nickname = identity['nickname']
server = identity['server']
port = identity.get('port', 6667)
password = identity.get('password', None)
ssl = identity.get('ssl', False)
bind_address = identity.get('bind_address', None)
ipv6 = identity.get('ipv6', False)
username = identity.get('username', None)
nickserv_password = identity.get('nickserv_password', None)
compact = config.COMPACT_OUTPUT if hasattr(config, 'COMPACT_OUTPUT') else True
enable_format('irc', IRC_CHRS, borders=not compact)
private_rate = getattr(config, 'IRC_PRIVATE_RATE', 1)
channel_rate = getattr(config, 'IRC_CHANNEL_RATE', 1)
reconnect_on_kick = getattr(config, 'IRC_RECONNECT_ON_KICK', 5)
reconnect_on_disconnect = getattr(config, 'IRC_RECONNECT_ON_DISCONNECT', 5)
self.bot_identifier = IRCPerson(nickname + '!' + nickname + '@' + server)
super().__init__(config)
self.conn = IRCConnection(bot=self,
nickname=nickname,
server=server,
port=port,
ssl=ssl,
bind_address=bind_address,
ipv6=ipv6,
password=password,
username=username,
nickserv_password=nickserv_password,
private_rate=private_rate,
channel_rate=channel_rate,
reconnect_on_kick=reconnect_on_kick,
reconnect_on_disconnect=reconnect_on_disconnect,
)
self.md = irc_md()
config.MESSAGE_SIZE_LIMIT = IRC_MESSAGE_SIZE_LIMIT
def send_message(self, msg):
super().send_message(msg)
if msg.is_direct:
msg_func = self.conn.send_private_message
msg_to = msg.to.person
else:
msg_func = self.conn.send_public_message
msg_to = msg.to.room
body = self.md.convert(msg.body)
for line in body.split('\n'):
msg_func(msg_to, line)
def change_presence(self, status: str = ONLINE, message: str = '') -> None:
if status == ONLINE:
self.conn.away() # cancels the away message
else:
self.conn.away('[%s] %s' % (status, message))
def send_stream_request(self, identifier, fsource, name=None, size=None, stream_type=None):
return self.conn.send_stream_request(identifier, fsource, name, size, stream_type)
def build_reply(self, msg, text=None, private=False, threaded=False):
response = self.build_message(text)
if msg.is_group:
if private:
response.frm = self.bot_identifier
response.to = IRCPerson(str(msg.frm))
else:
response.frm = IRCRoomOccupant(str(self.bot_identifier), msg.frm.room)
response.to = msg.frm.room
else:
response.frm = self.bot_identifier
response.to = msg.frm
return response
def serve_forever(self):
try:
self.conn.start()
except KeyboardInterrupt:
log.info("Interrupt received, shutting down")
finally:
self.conn.disconnect("Shutting down")
log.debug("Trigger disconnect callback")
self.disconnect_callback()
log.debug("Trigger shutdown")
self.shutdown()
def connect(self):
return self.conn
def build_message(self, text):
text = text.replace('', '*') # there is a weird chr IRC is sending that we need to filter out
return super().build_message(text)
def build_identifier(self, txtrep):
log.debug("Build identifier from [%s]" % txtrep)
# A textual representation starting with # means that we are talking
# about an IRC channel -- IRCRoom in internal err-speak.
if txtrep.startswith('#'):
return IRCRoom(txtrep, self)
# Occupants are represented as 2 lines, one is the IRC mask and the second is the Room.
if '\n' in txtrep:
m, r = txtrep.split('\n')
return IRCRoomOccupant(m, IRCRoom(r, self))
return IRCPerson(txtrep)
def shutdown(self):
super().shutdown()
def query_room(self, room):
"""
Query a room for information.
:param room:
The channel name to query for.
:returns:
An instance of :class:`~IRCMUCRoom`.
"""
with self.conn._rooms_lock:
if room not in self.conn._rooms:
self.conn._rooms[room] = IRCRoom(room, self)
return self.conn._rooms[room]
@property
def mode(self):
return 'irc'
def rooms(self):
"""
Return a list of rooms the bot is currently in.
:returns:
A list of :class:`~IRCMUCRoom` instances.
"""
with self.conn._rooms_lock:
return self.conn._rooms.values()
def prefix_groupchat_reply(self, message, identifier):
super().prefix_groupchat_reply(message, identifier)
message.body = '{0}: {1}'.format(identifier.nick, message.body)