Created
August 15, 2017 18:25
-
-
Save dermoth/e48acff691c7254ee7878d603a8efab3 to your computer and use it in GitHub Desktop.
AutoGhost X-Chat2 Module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""AutoGhost X-Chat2 Module | |
NB: This module assumes SASL Authentication. It does not perform any auth; | |
merely ghost on connect *after* successful SASL authentication (and likely | |
before any other module can perform manual service auth). | |
""" | |
import xchat # pylint: disable=F0401 | |
__module_name__ = "AutoGhost" | |
__module_author__ = "Thomas Guyot-Sionnest" | |
__module_description__ = "Plugin for X-Chat that auto-ghost primary nick" \ | |
" and take it back - to be used with SASL Auth" | |
__module_version__ = "0.01" | |
# List of blacklisted networks - default: () | |
AG_BLACKLIST = ('SpinVox',) | |
# NickServ ident | |
AG_NICKSERV = 'NickServ@services' | |
AG_LOADMSG = __module_name__ + ' v.' + __module_version__ + \ | |
' by ' + __module_author__ + ' loaded.' | |
AG_GLOBALS = { | |
'hook': None, | |
} | |
AG_DEBUG = False | |
def cb_ag_ghost(word, word_eol, userdata): | |
"""Initiates the ghost and set an handler for the NickServ ghost response | |
:param word: Xchat Callback word param | |
:param word_eol: Xchat Callback word_eol param | |
:param userdata: Xchat Callback userdata param | |
:return: xchat.EAT_NONE | |
""" | |
if AG_DEBUG: | |
xchat.prnt('ag_ghost()') | |
xchat.prnt(xchat.get_info('network')) | |
xchat.prnt(xchat.get_context().get_info('network')) | |
xchat.prnt(xchat.get_prefs('irc_nick1')) | |
xchat.prnt(xchat.get_info('nick')) | |
xchat.prnt(xchat.get_context().get_info('nick')) | |
if AG_GLOBALS['hook'] is not None: | |
xchat.prnt("Ghost already in progress") | |
return xchat.EAT_NONE | |
if xchat.get_info('network') in AG_BLACKLIST: | |
return xchat.EAT_NONE | |
pref_nick = xchat.get_prefs('irc_nick1') | |
curr_nick = xchat.get_info('nick') | |
if xchat.nickcmp(pref_nick, curr_nick) != 0: | |
xchat.command("msg NickServ ghost %s" % pref_nick) | |
# Hook on nickserv notice "nick has been ghosted" | |
AG_GLOBALS['hook'] = xchat.hook_server('NOTICE', cb_ag_setnick) | |
# TODO: Add timer to cleanup handler, ex no services or unresponsive | |
return xchat.EAT_NONE | |
def cb_ag_setnick(word, word_eol, userdata): | |
"""Hook handling the nnick change after ghost from NickServ | |
:param word: Xchat Callback word param | |
:param word_eol: Xchat Callback word_eol param | |
:param userdata: Xchat Callback userdata param | |
:return: xchat.EAT_NONE | |
""" | |
if AG_DEBUG: | |
xchat.prnt('ag_setnick()') | |
pref_nick = xchat.get_prefs('irc_nick1') | |
if word[0].find(AG_NICKSERV) >= 0 and word_eol[3].find(pref_nick) >= 0: | |
xchat.command("nick %s" % pref_nick) | |
xchat.unhook(AG_GLOBALS['hook']) | |
AG_GLOBALS['hook'] = None | |
return xchat.EAT_NONE | |
# Hook on events from the initial connect sequence (Numeric ids from RFC 2812) | |
# xchat.hook_server('001', ag_ghost) # Seems like this may be too early | |
# xchat.hook_server('MODE', ag_ghost) # That used to work ok... | |
xchat.hook_server('376', cb_ag_ghost) # 376 RPL_ENDOFMOTD :End of MOTD command | |
xchat.hook_server('422', cb_ag_ghost) # 422 ERR_NOMOTD :MOTD File is missing | |
xchat.prnt('\0032' + AG_LOADMSG + '\003') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment