3333
3434from sopel import config , plugin
3535from sopel .irc import isupport , utils
36- from sopel .tools import events , Identifier , jobs , SopelMemory , target
36+ from sopel .tools import events , jobs , SopelMemory , target
3737
3838
3939LOGGER = logging .getLogger (__name__ )
@@ -143,7 +143,7 @@ def auth_after_register(bot):
143143
144144 # nickserv-based auth method needs to check for current nick
145145 if auth_method == 'nickserv' :
146- if bot .nick != bot .settings .core .nick :
146+ if bot .nick != bot .make_identifier ( bot . settings .core .nick ) :
147147 LOGGER .warning ("Sending nickserv GHOST command." )
148148 bot .say (
149149 'GHOST %s %s' % (bot .settings .core .nick , auth_password ),
@@ -347,6 +347,7 @@ def handle_isupport(bot, trigger):
347347 botmode_support = 'BOT' in bot .isupport
348348 namesx_support = 'NAMESX' in bot .isupport
349349 uhnames_support = 'UHNAMES' in bot .isupport
350+ casemapping_support = 'CASEMAPPING' in bot .isupport
350351
351352 # parse ISUPPORT message from server
352353 parameters = {}
@@ -367,6 +368,11 @@ def handle_isupport(bot, trigger):
367368 if 'PREFIX' in bot .isupport :
368369 bot .modeparser .privileges = set (bot .isupport .PREFIX .keys ())
369370
371+ # was CASEMAPPING support status updated?
372+ if not casemapping_support and 'CASEMAPPING' in bot .isupport :
373+ # Re-create the bot's nick with the proper identifier+casemapping
374+ bot .rebuild_nick ()
375+
370376 # was BOT mode support status updated?
371377 if not botmode_support and 'BOT' in bot .isupport :
372378 # yes it was! set our mode unless the config overrides it
@@ -482,9 +488,12 @@ def handle_names(bot, trigger):
482488 channels = re .search (r'(#\S*)' , trigger .raw )
483489 if not channels :
484490 return
485- channel = Identifier (channels .group (1 ))
491+ channel = bot . make_identifier (channels .group (1 ))
486492 if channel not in bot .channels :
487- bot .channels [channel ] = target .Channel (channel )
493+ bot .channels [channel ] = target .Channel (
494+ channel ,
495+ identifier_factory = bot .make_identifier ,
496+ )
488497
489498 # This could probably be made flexible in the future, but I don't think
490499 # it'd be worth it.
@@ -515,7 +524,7 @@ def handle_names(bot, trigger):
515524 if prefix in name :
516525 priv = priv | value
517526
518- nick = Identifier (name .lstrip ('' .join (mapping .keys ())))
527+ nick = bot . make_identifier (name .lstrip ('' .join (mapping .keys ())))
519528 user = bot .users .get (nick )
520529 if user is None :
521530 # The username/hostname will be included in a NAMES reply only if
@@ -559,7 +568,7 @@ def _parse_modes(bot, args, clear=False):
559568 modes at https://modern.ircdocs.horse/#channel-mode
560569
561570 """
562- channel_name = Identifier (args [0 ])
571+ channel_name = bot . make_identifier (args [0 ])
563572 if channel_name .is_nick ():
564573 # We don't do anything with user modes
565574 LOGGER .debug ("Ignoring user modes: %r" , args )
@@ -622,7 +631,7 @@ def _parse_modes(bot, args, clear=False):
622631 # modeinfo.privileges contains only the valid parsed privileges
623632 for privilege , is_added , param in modeinfo .privileges :
624633 # User privs modes, always have a param
625- nick = Identifier (param )
634+ nick = bot . make_identifier (param )
626635 priv = channel .privileges .get (nick , 0 )
627636 value = MODE_PREFIX_PRIVILEGES [privilege ]
628637 if is_added :
@@ -659,7 +668,7 @@ def _parse_modes(bot, args, clear=False):
659668def track_nicks (bot , trigger ):
660669 """Track nickname changes and maintain our chanops list accordingly."""
661670 old = trigger .nick
662- new = Identifier (trigger )
671+ new = bot . make_identifier (trigger )
663672
664673 # Give debug message, and PM the owner, if the bot's own nick changes.
665674 if old == bot .nick and new != bot .nick :
@@ -705,7 +714,7 @@ def track_part(bot, trigger):
705714@plugin .priority ('medium' )
706715def track_kick (bot , trigger ):
707716 """Track users kicked from channels."""
708- nick = Identifier (trigger .args [1 ])
717+ nick = bot . make_identifier (trigger .args [1 ])
709718 channel = trigger .sender
710719 _remove_from_channel (bot , nick , channel )
711720 LOGGER .info (
@@ -748,7 +757,9 @@ def _send_who(bot, channel):
748757 # We might be on an old network, but we still care about keeping our
749758 # user list updated
750759 bot .write (['WHO' , channel ])
751- bot .channels [Identifier (channel )].last_who = datetime .datetime .utcnow ()
760+
761+ channel_id = bot .make_identifier (channel )
762+ bot .channels [channel_id ].last_who = datetime .datetime .utcnow ()
752763
753764
754765@plugin .interval (30 )
@@ -793,7 +804,10 @@ def track_join(bot, trigger):
793804
794805 # is it a new channel?
795806 if channel not in bot .channels :
796- bot .channels [channel ] = target .Channel (channel )
807+ bot .channels [channel ] = target .Channel (
808+ channel ,
809+ identifier_factory = bot .make_identifier ,
810+ )
797811
798812 # did *we* just join?
799813 if trigger .nick == bot .nick :
@@ -836,7 +850,8 @@ def track_quit(bot, trigger):
836850
837851 LOGGER .info ("User quit: %s" , trigger .nick )
838852
839- if trigger .nick == bot .settings .core .nick and trigger .nick != bot .nick :
853+ configured_nick = bot .make_identifier (bot .settings .core .nick )
854+ if trigger .nick == configured_nick and trigger .nick != bot .nick :
840855 # old nick is now available, let's change nick again
841856 bot .change_current_nick (bot .settings .core .nick )
842857 auth_after_register (bot )
@@ -1229,7 +1244,7 @@ def blocks(bot, trigger):
12291244 }
12301245
12311246 masks = set (s for s in bot .config .core .host_blocks if s != '' )
1232- nicks = set (Identifier (nick )
1247+ nicks = set (bot . make_identifier (nick )
12331248 for nick in bot .config .core .nick_blocks
12341249 if nick != '' )
12351250 text = trigger .group ().split ()
@@ -1266,10 +1281,11 @@ def blocks(bot, trigger):
12661281
12671282 elif len (text ) == 4 and text [1 ] == "del" :
12681283 if text [2 ] == "nick" :
1269- if Identifier (text [3 ]) not in nicks :
1284+ nick = bot .make_identifier (text [3 ])
1285+ if nick not in nicks :
12701286 bot .reply (STRINGS ['no_nick' ] % (text [3 ]))
12711287 return
1272- nicks .remove (Identifier ( text [ 3 ]) )
1288+ nicks .remove (nick )
12731289 bot .config .core .nick_blocks = [str (n ) for n in nicks ]
12741290 bot .config .save ()
12751291 bot .reply (STRINGS ['success_del' ] % (text [3 ]))
@@ -1352,8 +1368,8 @@ def recv_whox(bot, trigger):
13521368
13531369
13541370def _record_who (bot , channel , user , host , nick , account = None , away = None , modes = None ):
1355- nick = Identifier (nick )
1356- channel = Identifier (channel )
1371+ nick = bot . make_identifier (nick )
1372+ channel = bot . make_identifier (channel )
13571373 if nick not in bot .users :
13581374 usr = target .User (nick , user , host )
13591375 bot .users [nick ] = usr
@@ -1383,7 +1399,11 @@ def _record_who(bot, channel, user, host, nick, account=None, away=None, modes=N
13831399 for c in modes :
13841400 priv = priv | mapping [c ]
13851401 if channel not in bot .channels :
1386- bot .channels [channel ] = target .Channel (channel )
1402+ bot .channels [channel ] = target .Channel (
1403+ channel ,
1404+ identifier_factory = bot .make_identifier ,
1405+ )
1406+
13871407 bot .channels [channel ].add_user (usr , privs = priv )
13881408
13891409
0 commit comments