def highlight_collect_cb(word, word_eol, userdata): """Looks for highlighted words (set on HexChat/X-Chat settings) and copy the entire line who contains it to the "GatoScript" tab. Arguments: word -- array of strings sent by HexChat/X-Chat to every hook word_eol -- array of strings sent by HexChat/X-Chat to every hook userdata -- optional variable that can be sent to a hook (ignored) """ if xchat.get_prefs("irc_extra_hilight") != '': highlight = xchat.get_prefs("irc_extra_hilight").split(",") # Extract some text to compose the output string channel = word[2] nick = word[0].split("!")[0][1:] text = word_eol[3][1:] # If there is any highlighted word, compose the string and write it to # the script query for highlighted in highlight: exp = re.compile(highlighted, re.IGNORECASE) if exp.search(text): if word[3] in action_txt: helper.query_line("".join([ nick, "has mentioned \003", color(), highlighted, "\003 in a query: <", nick, "> ", word_eol[4][:-1]])) else: helper.query_line("".join([ nick, " has mentioned \003", color(), highlighted, "\003 in ", channel, ": <", nick, "> ", text])) return xchat.EAT_NONE
def is_highlight(sender, recipient, message): """Are we being highlighted?""" message = irc_lower(message) sender = irc_lower(sender) # Only highlight channels if not recipient[0] in '#&@': return False # Nicks to never highlight nnh = irc_lower(xchat.get_prefs('irc_no_hilight') or '') if match_word(sender[:sender.find('!')], nnh.split(',')): return False # Nicks to always highlight nth = irc_lower(xchat.get_prefs('irc_nick_hilight') or '') if match_word(sender[:sender.find('!')], nth.split(',')): return True # Words to highlight on, masks allowed wth = [ irc_lower(xchat.get_prefs('irc_nick%d' % x) or '') for x in (1, 2, 3) ] + [irc_lower(xchat.get_info('nick'))] wth += irc_lower(xchat.get_prefs('irc_extra_hilight') or '').split(', ') for w in wth: w = w.strip() if w and w in message: return True return False
def setup(): global acceptlist global userlist global m acceptlist = [] userlist = xchat.get_list("users") m.SetInfo(xchat.get_info("server"), xchat.get_info("channel"), xchat.get_prefs("irc_nick1")) for x in userlist: if xchat.nickcmp(x.nick, xchat.get_prefs("irc_nick1")) == 0: acceptlist.append([x, 1]) else: acceptlist.append([x, 0])
def nickchange(word, word_eol, userdata): desired_nick = xchat.get_prefs("irc_nick1") password = xchat.get_info("nickserv") if xchat.get_info("nick") is desired_nick: lineprint("Got desired nick now: "+desired_nick) return SUCCESS return FAIL
def crypto_cb(word, word_eol, userdata): ''' Callback for /crypto command ''' global m global t0 if len(word) < 2: print "\nAvailable actions:" print " auth - initiate crypto session and authenticate participants" elif word[1] == "auth": m.SetUsers(xchat.get_list("users")) setup() if '-p2p' in word_eol: bcast(xchat.get_list("users"), 1) else: synchronize() elif word[1] == "y": m.SetUsers(xchat.get_list("users")) acknowledge() elif word[1] == "shutdown": digest = GetChatDigest(m.path) m.digestTable.update({xchat.get_prefs("irc_nick1"):digest}) bcast(xchat.get_list("users"), 0, "shutdown") bcast(xchat.get_list("users"), 0, '0x16' + str(digest)) else: xchat.prnt("Unknown action") return xchat.EAT_ALL
def bcast(users, p2p, msg): ''' Send a message to all users in a channel ''' print msg for x in users: if not xchat.nickcmp(x.nick, xchat.get_prefs("irc_nick1")) == 0: xchat.command("msg " + x.nick + " " + msg) return xchat.EAT_ALL
def notice(word, word_eol, userdata): password = xchat.get_info("nickserv") desired_nick = xchat.get_prefs("irc_nick1") if "This nickname is registered" in word_eol[0]: if password: lineprint("Registered nickname. Attempting to auto-identify.") xchat.command("msg nickserv identify "+password) return SUCCESS lineprint("Registered nickname, but we have no password!") return FAIL elif "has been ghosted" in word_eol[0] or "Ghost with your nick" in word_eol[0]: lineprint("Ghosting successful. Setting nick to "+desired_nick) xchat.command("nick "+desired_nick) return SUCCESS elif "is not a registered nickname." in word_eol[0] or "Your nick isn't registered." in word_eol[0]: lineprint("Not using desired nick. Setting nick to "+desired_nick) xchat.command("nick "+desired_nick) return SUCCESS elif "You are already identified." in word_eol[0] or "You are already logged in" in word_eol[0]: return SUCCESS return FAIL
def randomize(): os.chdir(xchat.get_prefs("sound_dir")) file_list = list() for file in os.listdir("./"): file_list.append(file) random.shuffle(file_list) return file_list[0]
def ghost(word, word_eol, userdata): desired_nick = xchat.get_prefs("irc_nick1") password = xchat.get_info("nickserv") lineprint("Desired nickname "+desired_nick+" is taken.") if password: lineprint("Attempting to ghost old session.") xchat.command("msg nickserv ghost "+desired_nick+" "+password) return SUCCESS lineprint("But we have no password!") return FAIL
def open_cb(word, word_eol, userdata): chan = hexchat.get_info('channel') # Assume nick if not prefixed with # # Ignore ZNC and Python # Use existing pref for nicks I usually ignore (i.e. chanserv) if chan and chan[0] != '#' \ and chan[0] != '*' \ and chan != '>>python<<' \ and chan not in hexchat.get_prefs('irc_no_hilight').split(','): hexchat.command('chanopt -quiet text_logging on') hexchat.command('chanopt -quiet text_scrollback on')
def emit_print(event_name, nick, msg, *args, context=None): if not context: context = xchat.get_context() for highlight in [xchat.get_info('nick')] + xchat.get_prefs('irc_extra_hilight').split(','): if highlight and highlight in msg: if event_name == 'Channel Message': event_name = 'Channel Msg Hilight' elif event_name == 'Channel Action': event_name = 'Channel Action Hilight' xchat.command('GUI COLOR 3') context.emit_print(event_name, nick, msg, *args)
def test_cb(word, word_eol, userdata): global FLAG if FLAG == 0 and m.currentState == "MSGSTATE_ENCRYPTED": FLAG = 1 m.t0 = time.clock() f = open('myfile.dat', 'w+') f.write(str(m.t0)) print str(m.t0) xchat.emit_print("Channel Message", xchat.get_prefs("irc_nick1"), word_eol[0], "@") encrypted_broadcast(xchat.get_list("users"), word_eol[0], m.groupkey) return xchat.EAT_ALL
def emit_print(event_name, nick, msg, *args, context=None): if not context: context = xchat.get_context() for highlight in [xchat.get_info('nick') ] + xchat.get_prefs('irc_extra_hilight').split(','): if highlight and highlight in msg: if event_name == 'Channel Message': event_name = 'Channel Msg Hilight' elif event_name == 'Channel Action': event_name = 'Channel Action Hilight' xchat.command('GUI COLOR 3') context.emit_print(event_name, nick, msg, *args)
def growlnotify(_type, title, desc='', pri=0): if xchat.get_prefs('away_omit_alerts') and xchat.get_info('away'): return if xchat.get_prefs('gui_focus_omitalerts') and xchat.get_info('win_status') == 'active': return try: growl.notify( noteType=_type, title=xchat.strip(title), description=xchat.strip(desc), icon=hexchatlogo, sticky=False, priority=pri ) except: global lasterrtime # Avoid more spam, 1 error a min. if lasterrtime + 60 < time(): xchat.prnt('Growl Error: Growl is not running.') lasterrtime = time()
def encrypted_broadcast(users, msg, key): global FLAG iv = crypto.GetIV() file = m.path f = open(file, 'a') f.write("\n" + time.strftime("%b") + " " + time.strftime("%a") + " " + time.strftime("%d") + " " + time.strftime("%X") + " <" + xchat.get_prefs("irc_nick1") + "> " + msg) encMsg = crypto.AES_Encrypt(b64encode(key), b64encode(iv), b64encode(msg)) sendMsg = b64encode(iv) + encMsg for x in users: if not xchat.nickcmp(x.nick, xchat.get_prefs("irc_nick1")) == 0: xchat.command("msg " + x.nick + " " + sendMsg) FLAG = 0 return xchat.EAT_ALL
def verify_errors(word, word_eol, userdata): global last_msg nick, rest = split_nick(word_eol[0], seps=[xchat.get_prefs('completion_suffix')]) if word_eol[0] != last_msg: last_msg = word_eol[0] if nick == xchat.get_info('nick'): print 'WARNING: Sending message to yourself - Repeat to confirm.' return xchat.EAT_ALL elif nick and all(nick != user.nick for user in xchat.get_list('users')): print 'WARNING: %r is not here. Repeat to confirm.' % nick return xchat.EAT_ALL
def set_nick(word, word_eol, userdata): desired_nick = xchat.get_prefs("irc_nick1") password = xchat.get_info("nickserv") if word[3] == desired_nick and password: randstring = ''.join(choice(string.ascii_lowercase) for i in range(16)) xchat.command("nick %s" % randstring) xchat.command("nickserv ghost %s %s" % (desired_nick, password)) xchat.command("nick %s" % desired_nick) xchat.command("nickserv identify %s" % password) return xchat.EAT_XCHAT return xchat.EAT_NONE
def dispatch_message(word, word_eol, event): network, channel = xchat.get_info("network"), xchat.get_info("channel") # Dispatch event to each group registered for this channel if network in registered_channels and channel in registered_channels[network]: for group in registered_channels[network][channel]: # Extract nick and coloring if xchat.get_prefs("text_color_nicks"): (nick_color, nick) = re_nick.search(word[0]).groups("") else: nick_color, nick = "", word[0] args = (word[1:] + padding) group.on_chat_message(network, channel, event, nick, nick_color, args, word, word_eol) return xchat.EAT_NONE
def set_nick(word, word_eol, userdata): desired_nick = xchat.get_prefs("irc_nick1") password = xchat.get_info("nickserv") if word[3] == desired_nick and password: randstring = ''.join(choice(string.lowercase) for i in xrange(16)) xchat.command("nick %s" % randstring) xchat.command("nickserv ghost %s %s" % (desired_nick, password)) xchat.command("nick %s" % desired_nick) xchat.command("nickserv identify %s" % password) return xchat.EAT_XCHAT return xchat.EAT_NONE
def servertext(word, word_eol, userdata): if "ickname" in word_eol[0] and "in use" in word_eol[0]: return ghost([],[],[]) elif "while banned on channel" in word_eol[0]: for w in word_eol[0].split(' '): if '#' in w: lineprint("Channel "+w+" prevents unregistered users from nick changes. Leaving, changing nick, rejoining.") xchat.command("part "+w) xchat.command("nick "+xchat.get_prefs("irc_nick1")) xchat.command("join "+w) return SUCCESS return FAIL
def __init__(self, prefs, lcd): if (DEBUG == True): self.writetolog("Init checker") if (xchat.get_prefs("irc_extra_hilight")): self.highlights = xchat.get_prefs("irc_extra_hilight").split(',') if (xchat.get_prefs("irc_nick1")): self.highlights.append(xchat.get_prefs("irc_nick1")) if (xchat.get_prefs("irc_nick2")): self.highlights.append(xchat.get_prefs("irc_nick2")) if (xchat.get_prefs("irc_nick3")): self.highlights.append(xchat.get_prefs("irc_nick3")) self.prefs = prefs self.lcd = lcd self.lcd.checker = self if (DEBUG == True): self.writetolog("Done")
def is_highlight(sender, recipient, message): """Are we being highlighted?""" message = irc_lower(message) sender = irc_lower(sender) # Only highlight channels if not recipient[0] in '#&@': return False # Nicks to never highlight nnh = irc_lower(xchat.get_prefs('irc_no_hilight') or '') if match_word(sender[:sender.find('!')], nnh.split(',')): return False # Nicks to always highlight nth = irc_lower(xchat.get_prefs('irc_nick_hilight') or '') if match_word(sender[:sender.find('!')], nth.split(',')): return True # Words to highlight on, masks allowed wth = [irc_lower(xchat.get_prefs('irc_nick%d' % x) or '') for x in (1,2,3)] + [irc_lower(xchat.get_info('nick'))] wth += irc_lower(xchat.get_prefs('irc_extra_hilight') or '').split(', ') for w in wth: w = w.strip() if w and w in message: return True return False
def on_key_press(self, key, modifiers): if key == TAB or key == LEFT_TAB: text = self.buffer.get_input().strip() word = text.split(" ", 1) num = len(word) if num == 2: (line, nick) = text.rsplit(" ", 1) # Generate autocomplete list if self.auto_first: if num == 1: # Tab to next channel if word[0] in self.chanrefs: self.auto_list_channels() self.auto_first = False # Complete channel name elif word[0] and not word[0].startswith("#"): self.auto_list_channels("#" + word[0]) # Search partial chanel else: self.auto_list_channels(word[0]) # Search nick elif num == 2 and word[0] in self.chanrefs: self.auto_list_users(self.chanrefs[word[0]][0], self.chanrefs[word[0]][1], nick) if self.auto_list: # Rotate to next if not self.auto_first: # Shift-tab if modifiers & 1: mod = 1 # Other-tab else: mod = -1 self.auto_list_rotate(mod, self.auto_type == 1 and word[0] or nick) # Complete channel if self.auto_type == 1: self.buffer.set_input(self.auto_list[0] + " " + (num > 1 and word[1] or "")) # Complete nick else: self.buffer.set_input("%s %s%s " % (line, self.auto_list[0], xchat.get_prefs("completion_suffix"))) self.auto_first = False return xchat.EAT_ALL elif key != SHIFT: self.auto_first = True self.last_action = time() self.auto_clear() return xchat.EAT_NONE
def poll_status_cb(self, userdata): self._process.poll() if self._process.returncode is None: rl, wl, xl = select.select([self._process.stdout], [], [], 0) if len(rl): event = self._process.stdout.readline() if event.startswith('BLANK') or event.startswith('LOCK'): xchat.command('away %s' % xchat.get_prefs('away_reason')) elif event.startswith('UNBLANK'): xchat.command('back') else: # pipe is broken. self._process = self._create_pipe() # Keep the timeout going return 1
def GhostThatFucker(word,word_eol,userdata): global dInfo hContext = xchat.get_context() sServ=hContext.get_info("network") if sServ != None: sNick=hContext.get_info("nick") sTmp="N="+sServ bFnd=False sPNick=None sPass=None iFlags=None for sI in lSL: sI = sI.rstrip() if bFnd and sI: if sI[0] == 'N': break elif sI[0] == 'I': sPNick=sI[2:] elif sI[0] == 'B': sPass=sI[2:] elif sI[0] == 'F': iFlags=int(sI[2:]) elif sI == sTmp: bFnd=True #endif #endfor if iFlags == None: iFlags=0 if iFlags&0x2: sPNick=None if sPNick == None: sPNick=xchat.get_prefs("irc_nick1") if sNick != sPNick: xchat.prnt("%s: Incorrect nick %s (should be %s)" % (__module_name__,sNick,sPNick)) if sPass != None: dInfo[sServ] = { "on": 1, "nick": sPNick, "pass": sPass } hContext.command("nickserv GHOST %s %s" % (sPNick,sPass)) xchat.prnt("%s: Ghosting.." % __module_name__) return xchat.EAT_NONE elif userdata: dInfo[sServ] = { "on": 3, # Listen for user lists, see if the nick you want is in the room "nick": sPNick } #endif #endif #endif return xchat.EAT_NONE
def compile_strings(): global events_decoded # Decode strings from Text Event settings re_move = re.compile(r"(.+)(%C\d*)(\$t)(.*)") # Message color code needs to be put after tab char next = "" stringfile = os.path.join(configdir, "pevents.conf") assert os.path.exists(stringfile), "Configuration file pevents.conf not found. You may need to use a (any) custom theme for this file to be created" with open(stringfile) as f: for line in f: words = line.split("=", 1) if words and words[0] != "\n": (key, value) = words value = value.strip() if key == "event_name" and value in chat_events: next = value elif key == "event_text" and next: # Add channel slot to pattern decoded = decode(re_move.sub(r"\1\3\2\4", value)) if xchat.get_prefs("text_indent"): events_decoded[next] = decoded.replace("\t", "\t{0}") else: events_decoded[next] = "{0}" + decoded next = ""
play_cmd = "afplay" sounds_dir = "/Users/chris/Library/Sounds" # Associate sounds with channels here sounds_dic = {'#mel' : 'mel_sound.wav', '#codebench' : 'morse-n.wav', '#watercooler' : '440-380-drop.wav', '#montavista' : 'bullet.wav', '#marketing' : 'Purr.aiff', '#platform' : 'chirp.wav', '#amd' : 'amd-sound.wav', '#test' : 'ringout.wav', 'hilite' : 'c-d-g.wav', 'other' : '440-short-dot.wav'} mynick = xchat.get_prefs("irc_nick1") print "mynick is %s - sounds are enabled" % mynick def play_mysound(sound): sound_command = 'afplay ' + sounds_dir + '/' + sound + ' &' os.system(sound_command) def channel_msg_processor(word, word_eol, userdata): if (sounds_on == 0): return xchat.EAT_NONE current_channel = xchat.get_info("channel") current_nick = xchat.get_info("nick") # print "Channel message received on %s" % (current_channel) if current_channel in sounds_dic:
def color_enabled(): """ Simple wrapper to check pref setting for automatic nick coloring """ pref = xchat.get_prefs('text_color_nicks') return pref is not None and pref == 1
def onconnectcb(word, word_eol, userdata): c = xchat.get_context() if xchat.nickcmp(c.get_info('nick'), xchat.get_prefs('irc_nick1')) != 0: c.command('nick ' + xchat.get_prefs('irc_nick1'))
def real_name(): return xchat.get_prefs("irc_real_name")
def BanNick(word, word_eol, kickAfter): global hosts, reNick, reMask, reBanType, reTime, banNums, banTimes, nextBanTime, bannedNicks if len(word) < 2: return xchat.EAT_NONE # Fixes complaining when I manually unban.. context = xchat.get_context() servChan = context.get_info("host") + "/" + context.get_info("channel") ttime = None if word[1][0] == '-': i = 1 while i < len(word[1]): if word[1][i] in 'kK': kickAfter = True elif word[1][i] in 'uU': try: ttime = int(word[1][i + 1:]) except ValueError: xchat.prnt( "u argument should come last and be followed only by numbers." ) #endtry #endif i += 1 #endwhile nick = word[2] args = 3 nickLoc = 2 else: nick = word[1] args = 2 nickLoc = 1 #endif btype = reBanType.match(word[args]) if len(word) > args else None if btype: args += 1 btime = reTime.match(word[args]) if len(word) > args else None if btime: args += 1 if reNick.match(nick): if (btype and btype.group(1)) or btype is None: if btype is None: btype = xchat.get_prefs("irc_ban_type") else: btype = int(btype.group(1)) try: btype = banNums[btype] except IndexError: xchat.prnt("Ban type numeric %s does not exist" % btype.group(1)) #endif nmask, umask, hmask = btype.groups()[1:] if servChan in hosts and nick in hosts[servChan]: user, host = hosts[servChan][nick] mask = (nmask.replace("nick", "n").replace("n", nick) + "!" + (lambda u: "*" + (user[1:] if user[0] == "~" else user) + u[2:] if umask[0:2] == "*u" else u.replace("u", user))( umask.replace("user", "u")) + "@" + (lambda h: "*" + host[host.index("."):] + h[3:] if h[0:3] == "*.h" else ("*" + host[host.rindex("."):] if h == "*.tld" else (h.replace("h", host))))(hmask.replace("host", "h"))) context.command("mode +b " + mask) else: xchat.prnt("Nick unknown.") return xchat.EAT_ALL #endif elif reMask.match(nick): context.command("mode +b " + nick) mask = nick else: xchat.prnt("No one to ban.") return xchat.EAT_ALL #endif if servChan not in bannedNicks: bannedNicks[servChan] = {} bannedNicks[servChan][nick] = mask if btime: if servChan not in banTimes: banTimes[servChan] = {} t = map(int, list(btime.groups("0"))) # w,d,h,m,s,h,m,s ttime = (t[0] * 604800 + t[1] * 86400 + t[2] * 3600 + t[3] * 60 + t[4] + t[5] * 3600 + t[6] * 60 + t[7]) #endif if ttime: xchat.prnt("Banning %s for %i seconds." % (nick, ttime)) ttime = banTimes[servChan][mask] = int(time()) + ttime BanTimerGo((servChan, mask), ttime) #endif if kickAfter: KickNick(word, word_eol, (nickLoc, args, btime.group(0) if btime else None)) return xchat.EAT_ALL
def BanNick(word,word_eol,kickAfter): global hosts,reNick,reMask,reBanType,reTime,banNums,banTimes,nextBanTime,bannedNicks if len(word) < 2: return xchat.EAT_NONE # Fixes complaining when I manually unban.. context = xchat.get_context() servChan = context.get_info("host")+"/"+context.get_info("channel") ttime = None if word[1][0] == '-': i = 1 while i < len(word[1]): if word[1][i] in 'kK': kickAfter = True elif word[1][i] in 'uU': try: ttime = int(word[1][i+1:]) except ValueError: xchat.prnt("u argument should come last and be followed only by numbers.") #endtry #endif i += 1 #endwhile nick = word[2] args = 3 nickLoc = 2 else: nick = word[1] args = 2 nickLoc = 1 #endif btype = reBanType.match(word[args]) if len(word) > args else None if btype: args += 1 btime = reTime.match(word[args]) if len(word) > args else None if btime: args += 1 if reNick.match(nick): if (btype and btype.group(1)) or btype is None: if btype is None: btype = xchat.get_prefs("irc_ban_type") else: btype = int(btype.group(1)) try: btype = banNums[btype] except IndexError: xchat.prnt("Ban type numeric %s does not exist" % btype.group(1)) #endif nmask,umask,hmask = btype.groups()[1:] if servChan in hosts and nick in hosts[servChan]: user,host = hosts[servChan][nick] mask = (nmask.replace("nick","n").replace("n",nick)+"!" +(lambda u: "*"+(user[1:] if user[0] == "~" else user)+u[2:] if umask[0:2] == "*u" else u.replace("u",user))( umask.replace("user","u") )+"@" +(lambda h: "*"+host[host.index("."):]+h[3:] if h[0:3] == "*.h" else ( "*"+host[host.rindex("."):] if h == "*.tld" else ( h.replace("h",host) )))( hmask.replace("host","h") )) context.command("mode +b "+mask) else: xchat.prnt("Nick unknown.") return xchat.EAT_ALL #endif elif reMask.match(nick): context.command("mode +b "+nick) mask = nick else: xchat.prnt("No one to ban.") return xchat.EAT_ALL #endif if servChan not in bannedNicks: bannedNicks[servChan] = {} bannedNicks[servChan][nick] = mask if btime: if servChan not in banTimes: banTimes[servChan] = {} t = map(int,list(btime.groups("0"))) # w,d,h,m,s,h,m,s ttime = (t[0]*604800 + t[1]*86400 + t[2]*3600 + t[3]*60 + t[4] + t[5]*3600 + t[6]*60 + t[7]) #endif if ttime: xchat.prnt("Banning %s for %i seconds." % (nick,ttime)) ttime = banTimes[servChan][mask] = int(time()) + ttime BanTimerGo((servChan,mask),ttime) #endif if kickAfter: KickNick(word,word_eol,(nickLoc,args,btime.group(0) if btime else None)) return xchat.EAT_ALL
def connected_cb(word, word_eol, userdata): if hexchat.get_info('network') in networks: username = hexchat.get_prefs ('irc_user_name') password = hexchat.get_info('password') hexchat.command('quote PASS {}:{}'.format(username, password))