def choose_callback(word, word_eol, user_data): channel = hexchat.get_info("channel") if (channel in channels) and not (set(user.nick for user in hexchat.get_list("users")) & other_bots): option = None user = None input = None matches = choose_regex.match(word[1]) if matches: option = "CHOOSE" user = word[0] input = matches.group(1) else: matches = order_regex.match(word[1]) if matches: option = "ORDER" user = word[0] input = matches.group(1) if option == "CHOOSE" or option == "ORDER": for action in (try_choose, try_order): response = action(option, input) if response != None: context = hexchat.get_context() hexchat.hook_timer( 0, send_response, {"context": hexchat.get_context(), "user": user, "response": response} ) break return hexchat.EAT_NONE
def enchode_cb(word, word_eol, userdata): input = word_eol[1][:150] s = choder.enchode(input,2,340) buffer["input"] = s.splitlines() for dongs in buffer["input"]: hexchat.get_context().command('say ' + dongs) del buffer["input"] hexchat.emit_print("Channel Message", nick_format % hexchat.get_info('nick'), input, "") return hexchat.EAT_HEXCHAT
def pop_context(word, word_eol, userdata): context = hexchat.get_context() try: context_list.remove(context) except ValueError: pass return hexchat.EAT_NONE
def save_session(userdata): # Saves the network|channels dictionary in pluginpref networks = {} channels = hexchat.get_list('channels') if not hexchat.get_context(): return # Build dictionary 'networks' # Iterate 'channels' and add all the servers for chan in channels: if chan.type == 1: networks[chan.network] = [] # Iterate 'channels' and add channels. # networks={'freenode':[chan1, chan2, chan3], 'dalnet':[]} for chan in channels: if chan.type == 2 or chan.type == 3: # Ignore notices and server tabs networks[chan.network].append(chan.channel) # Iterate 'networks' and store in hexchat.pluginpref as # session_freenode = chan1,chan2. This is written to # 'addon_python.conf' eventually. for network, channels in networks.items(): if len(network): hexchat.set_pluginpref('session_' + network, ','.join(channels)) return hexchat.EAT_ALL
def qcbot_disconnect(word, word_eol, userdata, attributes): ctx = hexchat.get_context() if is_qcbot(ctx, word): match = qc_disconnect_mask.match(word[1]) if match: nick = match.group(1) if not _cols: nick = hexchat.strip(nick) else: # TODO cache evt = hexchat_parse(hexchat.get_info("event_text Part")) format = Formatting.RESET pevt = parse(evt) for pos, obj in enumerate(pevt): if isinstance(obj, str): for event_param in hexchat_event_param.finditer(obj): tag = event_param.group()[1] if tag == "1": targetfmt = parse(nick, True, format)-format fmtstr = str(targetfmt) nick = nick + fmtstr else: format = format + obj if attributes.time: ctx.emit_print("Part", compress_colors(nick), qc_player_host, ctx.get_info("channel"), time=attributes.time) else: ctx.emit_print("Part", compress_colors(nick), qc_player_host, ctx.get_info("channel")) return hexchat.EAT_ALL return hexchat.EAT_NONE
def _localend(word, word_eol, ud): hexchat.unhook(ud[2]) #hook_id hexchat.unhook(ud[3]) #hook_end_id hexchat.unhook(ud[4]) #hook_timeout_id hexchat.unhook(ud[5]) #hook_421_id ud[1](Context(hexchat.get_context()), ud[0]) return hexchat.EAT_HEXCHAT
def receive(word, word_eol, userdata): global PROCESSING if PROCESSING: return hexchat.EAT_NONE sender, message = word[0], word[1] ctxt = hexchat.get_context() """ If the first 11 characters of the received message is the word 'HEXCHATENC:' the text is probably encrypted """ if message[:11] == "HEXCHATENC:": try: plaintext = decrypt(message[11:]) """ If sender not in DIALOGS -> enable outgoing encryption for this context """ if channelServer(ctxt) not in DIALOGS: enable(ctxt) PROCESSING = True """ Message decrypted, print to dialog window""" ctxt.emit_print('Private Message to Dialog', sender, textPos(plaintext)) PROCESSING = False return hexchat.EAT_HEXCHAT except Exception as e: ctxt.prnt(textNeg("Could not decrypt!")) if DEBUG: ctxt.prnt(str(e)) return hexchat.EAT_NONE
def checkPrint(word, word_eol, userdata): del(word_eol, userdata) # shut up pylint now = int(time.time()) context = hexchat.get_context() chan = context.get_info('channel') if chan not in TIMEOUTS: return hexchat.EAT_NONE # who = word[0] if len(word) < 2: return None words = word[1].strip().split() if len(words) < 1: # degenerate case of "nick PRIVMSG #channel :\r\n" return None if words[0] in ('.dice', '.roll'): if now <= TIMEOUTS[chan]: return hexchat.EAT_NONE if len(words) < 2: words.append('2d6') print(repr(words)) result = _roll(words[1:]) if result: TIMEOUTS[chan] = now + TIMEOUT context.command("me rolls " + result) return hexchat.EAT_PLUGIN
def my_saymsg_cb(word, word_eol, data): if chantype(hexchat.get_context()) == 3: targ = hexchat.get_info('channel') self_msg(word_eol[0]) hexchat.command('PRIVMSG #jtv :/w {} {}'.format( targ, strip_cchars(word_eol[0]))) return hexchat.EAT_ALL
def hook_print_message(word, word_eol, userdata): nick = hexchat.strip(word[0]) message = hexchat.strip(word[1]) channel = hexchat.get_info('channel') context = hexchat.get_context() # AUTOCHANNEL Check key = hexchat.get_info('network') + ' ' + channel.lower() if key in AUTOCHANNEL: dest_lang, src_lang = AUTOCHANNEL[key] threading.Thread(target=worker_hook_print_message, args=(context, message, nick, src_lang, dest_lang)).start() #worker_hook_tr(message,'de','en') #worker_hook_print_message(context, message, nick, src_lang, dest_lang) return hexchat.EAT_NONE # AUTOUSER Check key_user = hexchat.get_info('network') + ' ' + channel + ' ' + nick.lower() if key in AUTOUSER: dest_lang, src_lang = AUTOUSER[key_user] worker_hook_tr(message, src_lang, dest_lang) return hexchat.EAT_NONE
def qcbot_disconnect(word, word_eol, userdata, attributes): ctx = hexchat.get_context() if is_qcbot(ctx, word): match = qc_disconnect_mask.match(word[1]) if match: nick = match.group(1) if not _cols: nick = hexchat.strip(nick) else: # TODO cache evt = hexchat_parse(hexchat.get_info("event_text Part")) format = Formatting.RESET pevt = parse(evt) for pos, obj in enumerate(pevt): if isinstance(obj, str): for event_param in hexchat_event_param.finditer(obj): tag = event_param.group()[1] if tag == "1": targetfmt = parse(nick, True, format) - format fmtstr = str(targetfmt) nick = nick + fmtstr else: format = format + obj if attributes.time: ctx.emit_print("Part", compress_colors(nick), qc_player_host, ctx.get_info("channel"), time=attributes.time) else: ctx.emit_print("Part", compress_colors(nick), qc_player_host, ctx.get_info("channel")) return hexchat.EAT_ALL return hexchat.EAT_NONE
def message_cb(word, word_eol, msgtype): # avoid infinite loop global message_cb_recurse if message_cb_recurse: return message_cb_recurse = True try: #log.debug("message_cb word=%s" % str(word)) #log.debug("message_cb word_eol=%s" % str(word_eol)) if len(word) < 1: return hexchat.EAT_NONE nick = twitch.normalize.nick(word[0]) try: text = word[1] except IndexError: text = '' user = twitch.user.get(nick) chan = twitch.channel.get(hexchat.get_context()) if chan is not None: user.joinChannel(chan) user.printMessage(chan, text, msgtype) else: log.error("Got user message for invalid channel: <%s> %s" % (nick, text)) return hexchat.EAT_ALL except: log.exception("Unhandled exception in twitch.message_cb") return hexchat.EAT_NONE finally: message_cb_recurse = False
def leftjoin(word, word_eol, userdata): ctx = hexchat.get_context() channel = ctx.get_info('channel') # we need the channel object to get the flags chanobj = None for chan in hexchat.get_list('channels'): if hexchat.nickcmp(chan.channel, channel) == 0: chanobj = chan break if chanobj is None: return hexchat.EAT_NONE # if is this isn't a channel with the "Hide Join/Left" option, just return. if chanobj.flags & 0x40 == 0: return hexchat.EAT_NONE cleanup(userdata['nicks']) lnick = hexchat.strip(word[0]) channel = chan.channel for dnick, dchannel in userdata['nicks']: if hexchat.nickcmp(lnick, dnick) == 0 \ and hexchat.nickcmp(dchannel, channel) == 0: if time.time() <= userdata['nicks'][(dnick, dchannel)]: _emit_print(userdata['type'], *word) return hexchat.EAT_ALL else: del userdata['nicks'][(dnick, dchannel)] return hexchat.EAT_NONE
def icu(word, word_eol, userdata): if len(word) < 4: hexchat.prnt(__module_help_message__) return hexchat.EAT_ALL contexts = userdata this_context = hexchat.get_context() operation = word[1] direction = word[2] destination = word[3] potential_context = hexchat.find_context(channel=destination) if potential_context == None: hexchat.prnt("Could not find {}.".format(destination)) return hexchat.EAT_ALL if operation == "add": if direction == "to": contexts["to"].append(potential_context) elif direction == "from": contexts["from"].append(potential_context) this_context.prnt("Added relay {} {}".format(direction, destination)) if operation == "del": if direction == "to": contexts["to"].remove(potential_context) elif direction == "from": contexts["from"].remove(potential_context) this_context.prnt("Deleted relay {} {}".format(direction, destination)) return hexchat.EAT_ALL
def trig_chan(word, word_eol, userdata): # Strip input word for i in range(len(word)): word[i] = hexchat.strip(word[i], -1, 3) # Telegram bridge IRC_to_Telegram(hexchat.get_context(), word[0], word[1]) return hexchat.EAT_NONE
def eat_privmsg(word, word_eol, userdata): context = hexchat.get_context() who = word[0][1:word[0].find('!')] # where = word[2] chan = context.get_info('channel') what = word_eol[3][1:] words = what.strip().split() if not words: # degenerate case of "nick PRIVMSG #channel :\r\n" return None now = nowtime() site = None for i in SITES: if SITES[i].get('listenfor') == words[0]: if SITES[i].get('listento'): if chan in SITES[i]['listento']: site = SITES[i] else: # assume all channels if none are mentioned site = SITES[i] if site is None: return None if (site['lastanno'] + site['throttle']) > now: # send message to just this person, and don't reset the lastasked time context = who # elif AFRAID_OF: # nicks = [i.nick.lower() for i in context.get_list('users')] # afraid = [i for i in nicks if i in AFRAID_OF] # if afraid: # send message to just this person, because I'm scared # context = who else: site['lastasked'] = now emit_mtime(context, site) return hexchat.EAT_PLUGIN
def sh0tssub(word, word_eol, userdata): if word[1].find("subscribed") != -1 and word[0] == "twitchnotify": currchan = hexchat.get_context() if currchan.get_info("channel") == "#sh0ts_tv": currchan.command( "say Thanks for subscribing! Welcome to Sh0ts Dinomites! sh0tsLove sh0tsLove sh0tsLove sh0tsLove sh0tsLove sh0tsSellout sh0tsSellout sh0tsSellout sh0tsSellout sh0tsSellout" )
def qcbot_msg(word, word_eol, userdata, attributes): ctx = hexchat.get_context() if is_qcbot(ctx, word): match = userdata[1].match(word[1]) if match: badge, nick, text = match.groups() if _badge: # to see this, see http://tinyurl.com/hexchatbadge if "Mod" in badge: badge = "%B%C07&%C%B" elif "Op" in badge: # or "SrOp" in badge: # redundant :P badge = "%B%C04@%C%B" elif "Owner" in badge or "Admin" in badge: badge = "%B%C02~%C%B" elif "Newbie" in badge: badge = "%B%C06?%C%B" else: # for members badge = "" badge = hexchat_parse(badge) # strip colors if not _cols: badge = hexchat.strip(badge) nick = hexchat.strip(nick) else: # TODO cache evt = hexchat_parse( hexchat.get_info("event_text {}".format(userdata[0]))) format = Formatting.RESET pevt = parse(evt) for pos, obj in enumerate(pevt): if isinstance(obj, str): for event_param in hexchat_event_param.finditer(obj): tag = event_param.group()[1] if tag == "1": targetfmt = parse(nick, True, format) - format fmtstr = str(targetfmt) nick = nick + fmtstr elif tag == "2": targetfmt = parse(text, True, format) - format fmtstr = str(targetfmt) text = text + fmtstr elif tag == "3": targetfmt = parse(badge, True, format) - format fmtstr = str(targetfmt) badge = badge + fmtstr else: format = format + obj if attributes.time: ctx.emit_print(userdata[0], compress_colors(nick), text, badge, time=attributes.time) else: ctx.emit_print(userdata[0], compress_colors(nick), text, badge) return hexchat.EAT_ALL return hexchat.EAT_NONE
def send(word, word_eol, userdata): ctxt = hexchat.get_context() """ Only encrypt outgoing message if channel/server is added to DIALOGS list """ if channelServer(ctxt) in DIALOGS: try: message = word_eol[0] """ To avoid the encrypted text gets cut off during transmission encrypt and send the message in chunks of MCHARSIZE character- length . """ for x in range(0, len(message), MCHARSIZE): """ To mark the message as encrypted, 'HEXCHATENC:' is concatenated to the encrypted message. """ hexchat.command('PRIVMSG %s :%s' % (ctxt.get_info('channel'), "HEXCHATENC:" + encrypt(message[x:x + MCHARSIZE]))) """ Message sent, print to dialog window""" hexchat.emit_print('Your Message', hexchat.get_info('nick'), textPos(message)) return hexchat.EAT_HEXCHAT except Exception as e: ctxt.prnt(textNeg("Could not encrypt!")) if DEBUG: ctxt.prnt(str(e)) return hexchat.EAT_ALL return hexchat.EAT_NONE
def natasub(word, word_eol, userdata): if word[1].find("subscribed") != -1 and word[0] == "twitchnotify": currchan = hexchat.get_context() if currchan.get_info("channel") == "#natawhee": currchan.command( "me MAN nataWut DOES nataWut IT nataWut FEEL nataWut GOOD nataWut TO nataWut BE nataWut A nataWut NATAWHEE nataWut SUB" )
def check_for_replacements(word, word_to_eol, userdata): global _replacements result = [] changed = False for w in word[1].split(): w = w.lower() if w in _replacements.keys(): result.append(_replacements[w]) changed = True else: result.append(w) if changed: if len(word) == 2: word.append('') hexchat.get_context().emit_print('Channel Message', word[0], ' '.join(result), word[2]) return hexchat.EAT_ALL
def _cb(word, word_eol, userdata): if hexchat.strip(word[0]) in ["gonzobot"]: duckDetect = re.search("o<|o<", hexchat.strip(word[1])) if duckDetect is not None: print("quack") context = hexchat.get_context() hexchat.hook_timer(randint(3000,7000), duck, context)
def say_yt_title(title): message = "\002Title:\002 " + title # Delay our "say" because otherwise it will occur before we have actually # sent the video url. context = hexchat.get_context() set_timeout(lambda: context.command("say {message}".format(message=message)))
def ptero(word, word_eol, userdata): if word[1] == "!ptero" and word[0] != "mhunt95": currchan = hexchat.get_context() if currchan.get_info("channel") == "#pterodactylsftw": currchan.command( "me KNEES DACTYLS HEARTS pteroKnee pteroKnee pteroKnee pteroKnee pteroKnee pteroKnee pteroDactyl pteroDactyl pteroDactyl pteroDactyl pteroDactyl pteroDactyl pteroHeart pteroHeart pteroHeart pteroHeart pteroHeart pteroHeart" )
def privmsg(word, word_eol, userdata, attrs): ctx = hexchat.get_context() users = ctx.get_list('users') nicks = {user.nick.lower() for user in users} words = {w.lower() for w in word_eol[3][1:].split()} if len(nicks & words) >= 5: return hexchat.EAT_ALL return hexchat.EAT_NONE
def netId(ctx = None): if ctx == None or ctx == hexchat.get_context(): return hexchat.get_prefs("id") else: for c in hexchat.get_list("channels"): if c.context == ctx: return c.id return "?"
def shroudew(word, word_eol, userdata): if word[1].find("shroudH") != -1: return elif word[1].find("shroud?") != -1 or word[1].find( "Shroud?") != -1 or word[1].find("shroud ") != -1: currchan = hexchat.get_context() if currchan.get_info("channel") == "#natawhee": currchan.command("say pteroGame pteroGame pteroGame")
def find(cls, server=None, channel=None, id=None): if id is None: return cls._make(hexchat.find_context(server, channel)) channel = channel.lower() for ch in hexchat.get_context().get_list('channels'): if ch.id == id and ch.channel == channel: return cls(ch.context) return None
def msg_cmd(word, word_eol, userdata): context = hexchat.get_context() for respoon in respoon_list: if respoon.checkOrigin(context.get_info("server"), context.get_info("channel")): params = respoon.checkTrigger(word[1]) if len(params) > 0: respoon.performAction(context, word[0], word[1], params)
def netId(ctx=None): if ctx == None or ctx == hexchat.get_context(): return hexchat.get_prefs("id") else: for c in hexchat.get_list("channels"): if c.context == ctx: return c.id return "?"
def tab_hilight_callback(word, word_eol, userdata, attributes): """Called when we expect a tab to be coloured '3', so we don't override that colour with the colour '2' in message_callback.""" ctx = hexchat.get_context() if ctx != current_focus_tab: color3_tabs.append(ctx) dmsg("Got highlight. Added this context to color3_tabs.", "GUICOLOR") return hexchat.EAT_NONE
def get_error_context(): global _use_error_context, _err_context_name if not _use_error_context: return hexchat.get_context() ctx = hexchat.find_context(server=_err_context_name) if ctx is None: hexchat.command('newserver -noconnect "{}"'.format(_err_context_name)) ctx = hexchat.find_context(server=_err_context_name) return ctx
def check_ignore(word, word_to_eol, userdata): ignoretarget = word[0] for user in _ignorelist: if hexchat.nickcmp(user, ignoretarget) == 0: context = hexchat.get_context() if len(word) == 2: word.append("") context.prnt("\x0314{}{} {}".format(word[2], ignoretarget, word[1])) return hexchat.EAT_ALL
def caps_cb(word, word_eol, userdata): desired_caps = {'twitch.tv/membership', 'twitch.tv/commands'} available_caps = set(word[1].split()) require_caps_str = " ".join(desired_caps & available_caps) if require_caps_str: hexchat.command("CAP REQ :%s" % require_caps_str) context = hexchat.get_context() set_timeout(lambda: context.emit_print('Capability Request', require_caps_str)) return hexchat.EAT_NONE
def get_channel_list(context=None): if context is None: context = hexchat.get_context() for item in context.get_list('channels'): if item.context == context: return item return None
def xxmessage_callback(word, word_eol, userdata, attributes): """"This function is called every time a new 'Channel Message' or 'Channel Action' (like '/me hugs elhaym') event is going to occur. Here, we change the event in the way we desire then pass it along.""" global chancolortable global defaultcolortable if playbychat_enabled: event_name = userdata nick = word[0] nick = hexchat.strip(nick, -1, 1) # remove existing colours # This bit prevents infinite loops. # Assumes nicks will never normally begin with "\017". if nick.startswith(ec["o"]): # We already did this event and are seeing it again, because this function gets triggered by events that even it generates. dmsg("Already-processed nick found: " + repr(nick), "LOOP") return hexchat.EAT_NONE dmsg("The time attribute for this event is {}".format(attributes.time), "PRINTEVENT") dmsg("COLORTABLE length = %d" % len(chancolortable), "PRINTEVENT") chan = hexchat.get_info("channel") net = hexchat.get_info("network") ctx = hexchat.get_context() if net not in chancolortable: # create an empty network entry dmsg("Making new network " + net, "COLORTABLE") chancolortable[net] = {} dmsg("chancolortable: %s" % (chancolortable)) if chan not in chancolortable[net]: # make new color table dmsg("Making new color table for " + chan, "COLORTABLE") chancolortable[net][chan] = defaultcolortable[:] dmsg("chancolortable: %s" % (chancolortable)) else: dmsg( "Found COLORTABLE of length " + str(len(chancolortable[net][chan])) + " for channel " + chan + " on network " + net, "COLORTABLE") ctable = chancolortable[net][chan] dmsg("COLORTABLE for " + chan + " on " + net + " = " + str(ctable), "COLORTABLE") color = get_color(ctable, nick) newnick = ecs('o') + col(color) + nick word[0] = newnick #word[1] = "\002\026{0}{1}".format(col(color), word[1]) word[1] = "\002\026{0}{1}".format(col(color), word[1]) dmsg('Old nick: %s - New Nick: %s' % (nick, newnick)) hexchat.emit_print(event_name, *word, time=attributes.time) #hexchat.emit_print(event_name, "\002\026{0}{1}".format(color, word_eol)) if not is_color3_tab(ctx): hexchat.command("gui color 2") # required since HexChat 2.12.4 return hexchat.EAT_ALL else: return hexchat.EAT_NONE
def url_highlight_cb(word, word_eol, userdata): """Looks for URLs and highlight them with the chosen color. 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 we are dealing with a CTCP, don't bother trying' if len(word[3]) > 1 and word[3][1] in ctcp_txt: return hexchat.EAT_NONE if helper.conf_read("highlight", "common") == "1": urls = re.compile("".join([ "((ftp|https?)://.*)|((www|ftp)\..*\..*)", "|([a-z0-9_\.-\\\+]+)\@([a-z0-9_\.-]+)\.([a-z\.]{2,6})"]), re.IGNORECASE) # Set the apropriate start depending on whether it's an action message # or the network it's received from action = False if word[3] in action_txt: words = word_eol[4][:-1].split(" ") action = True elif "freenode" in hexchat.get_info("server").lower(): words = word_eol[3][2:].split(" ") else: words = word_eol[3][1:].split(" ") address = [] # Find if there is any URL for i in words: if urls.match(i): address.append(i) # If there is any URL, colorize all of them new_msg_tmp = [] if address: for entry in words: if entry in address: new_msg_tmp.append("".join(["\003", color(), entry, "\003"])) else: new_msg_tmp.append(entry) new_msg = " ".join(new_msg_tmp) # Find the context: context = hexchat.get_context() # Find what's the appropiate event and emit the corresponding text if action is False: context.emit_print("Channel Message", word[0].split("!")[0][1:], new_msg) else: if word[2][0] == "#": context.emit_print("Channel Action", word[0].split("!")[0][1:], new_msg) else: context.emit_print("Private Action", word[0].split("!")[0][1:], new_msg) return hexchat.EAT_ALL else: return hexchat.EAT_NONE
def hook_str(word, word_eol, userdata): message = word_eol[1] context = hexchat.get_context() print(Bold + hexchat.get_info('nick') + NormalText + Color + '08 > ' + message) threading.Thread(target=worker_hook_str, args=( context, message, )).start() return hexchat.EAT_ALL
def trig_user_quit(word, word_eol, userdata): print("-- trig_user_quit(): word = '%s'" % word) user_nick = word[0] user_quit_reason = word[1] user_host = word[2] channel = hexchat.get_context().get_info("channel") print("-- trig_user_quit(): channel = %s" % channel) # Telegram bridge if channel.lower() in config["irc_params"]["irc_channels_for_telegram"]: telegram_bot_send_message(config["irc_params"]["irc_channels_for_telegram"][channel.lower()], "** *%s* (`%s`) has quit (Reason: _%s_)" % (user_nick, user_host, user_quit_reason), parse_mode = "Markdown")
def keypress(w, we, u): if re.search(affected_networks, hexchat.get_info("network")): key, state, key_str, str_len = w if int(key) == 65289: # <Tab> inputbox = hexchat.get_info("inputbox") pos = hexchat.get_prefs("state_cursor") text, suffix = inputbox[:pos], inputbox[pos:] prefix, space, word = text.rpartition(" ") if len(word): prefix += space if word[0] == '#': return hexchat.EAT_NONE # let the built-in completion handle channels if word[0] == '@': word = word[1:] users = [] for u in hexchat.get_list("users"): if not hexchat.nickcmp(u.nick[:len(word)], word): users.append((u.nick, u.lasttalk)) for c in hexchat.get_list("channels"): if c.context == hexchat.get_context(): if c.type == 3: if not hexchat.nickcmp(c.channel[:len(word)], word): users.append((c.channel, 0)) # if we're in a dialog, include the targer user if len(users): if len(users) == 1: completion = "@" + users[0][0] + " " else: if hexchat.get_prefs("completion_sort") == 1: users = sorted(users, key = lambda x: -x[1]) else: users = sorted(users, key = lambda x: x[0].lower()) nicks = [u[0] for u in users] print(" ".join(nicks)) common = None # longest common prefix for nick in nicks: if common == None: common = word + nick[len(word):] # copy the case of characters entered by the user else: while hexchat.nickcmp(nick[:len(common)], common): common = common[:-1] for nick in nicks: if not hexchat.nickcmp(nick, word): common = nick # if we have an exact match, ignore the case of user's characters completion = "@" + common hexchat.command("settext " + prefix + completion + suffix) hexchat.command("setcursor " + str(len(prefix) + len(completion))) return hexchat.EAT_ALL else: prevword = prefix.rpartition(" ")[2] if len(prevword) and prevword[0] == '@': return hexchat.EAT_ALL # don't let the built-in completion kick in if we just completed a nick else: return hexchat.EAT_NONE else: return hexchat.EAT_NONE
def qcbot_msg(word, word_eol, userdata, attributes): ctx = hexchat.get_context() if is_qcbot(ctx, word): match = userdata[1].match(word[1]) if match: badge, nick, text = match.groups() if _badge: # to see this, see http://tinyurl.com/hexchatbadge if "Mod" in badge: badge = "%B%C07&%C%B" elif "Op" in badge: # or "SrOp" in badge: # redundant :P badge = "%B%C04@%C%B" elif "Owner" in badge or "Admin" in badge: badge = "%B%C02~%C%B" elif "Newbie" in badge: badge = "%B%C06?%C%B" else: # for members badge = "" badge = hexchat_parse(badge) # strip colors if not _cols: badge = hexchat.strip(badge) nick = hexchat.strip(nick) else: # TODO cache evt = hexchat_parse(hexchat.get_info("event_text {}".format(userdata[0]))) format = Formatting.RESET pevt = parse(evt) for pos, obj in enumerate(pevt): if isinstance(obj, str): for event_param in hexchat_event_param.finditer(obj): tag = event_param.group()[1] if tag == "1": targetfmt = parse(nick, True, format)-format fmtstr = str(targetfmt) nick = nick + fmtstr elif tag == "2": targetfmt = parse(text, True, format)-format fmtstr = str(targetfmt) text = text + fmtstr elif tag == "3": targetfmt = parse(badge, True, format)-format fmtstr = str(targetfmt) badge = badge + fmtstr else: format = format + obj if attributes.time: ctx.emit_print(userdata[0], compress_colors(nick), text, badge, time=attributes.time) else: ctx.emit_print(userdata[0], compress_colors(nick), text, badge) return hexchat.EAT_ALL return hexchat.EAT_NONE
def check_for_highlight(word, word_to_eol, userdata): global _lastresponder channelname = hexchat.get_context().get_info('channel') windowname = hexchat.find_context().get_info('channel') if channelname in _lastresponder and _lastresponder[channelname] == hexchat.get_info('nick') and windowname != channelname: if len(word) == 2: word.append('') hexchat.emit_print('Channel Msg Hilight', word[0], word[1], word[2]) return hexchat.EAT_ALL update_responder(word, word_to_eol, userdata) return hexchat.EAT_NONE
def on_message(word, word_eol, userdata): contexts = userdata context = hexchat.get_context() this_word = word[1] for from_context in contexts['from']: if context.get_info("channel") == from_context.get_info("channel"): for to_context in contexts['to']: to_context.command("say <{}> {}".format(word[0], word[1])) return hexchat.EAT_NONE
def speechhandler( argv, argv_to_eol, c ): global _lastresponse, _seconds_between_responses if time.time() - _lastresponse >= _seconds_between_responses: context = hexchat.get_context() response = _cb.ask( argv[1:] ) time.sleep(3) context.command('say {}'.format( response ) ) _lastresponse = time.time() return hexchat.EAT_NONE
def metalk(word, word_eol, userdata): global NICK_TIMEOUT cleanup(userdata) text = word[1] ctx = hexchat.get_context() channel = ctx.get_info('channel').lower() for user in ctx.get_list('users'): if user.nick.lower() in text.lower(): userdata[(user.nick.lower(), channel)] = time.time() + NICK_TIMEOUT return hexchat.EAT_NONE
def __init__(self, bot, num): self.bot = str(bot) self.num = int(num) self.channel = hexchat.get_info("channel") self.network = hexchat.get_info("network") self.context = hexchat.get_context() self.file = "" self.retries = 0 self.queue_position = 0 self.queued = False self.transfering = False self.dead = False self.s = "ctcp %s xdcc send #%d" % (str(bot), int(num))
def hook_print_message(word, word_eol, userdata): nick = hexchat.strip(word[0]) message = hexchat.strip(word[1]) channel = hexchat.get_info('channel') context = hexchat.get_context() key = hexchat.get_info('network') + ' ' + channel + ' ' + nick.lower() if key in AUTOUSER: dest_lang, src_lang = AUTOUSER[key] threading.Thread(target=worker_hook_print_message, args=(context, message, nick, src_lang, dest_lang)).start() return hexchat.EAT_NONE