Skip to content

Instantly share code, notes, and snippets.

@AwwCookies
Last active August 29, 2015 14:18
Show Gist options
  • Save AwwCookies/c90ff18dd5583bf6d916 to your computer and use it in GitHub Desktop.
Save AwwCookies/c90ff18dd5583bf6d916 to your computer and use it in GitHub Desktop.
A hexchat plugin that puts the persons real name [if known] next to their nick
import hexchat
import json
import os
__module_author__ = 'Aww'
__module_name__ = 'Nick to name'
__module_version__ = '1.0'
__module_description__ = 'Puts the persons real name [if known] next to their nick'
# SETTINGS
on = True
# END SETTINGS
f = "./nick2name.json"
nick_name_pair = {}
def on_message(word, word_eol, userdata=None):
# When the client gets a message check to see if there is
# a name paired with it. If there a name paired with it
# Display the name next to the nick.
if on:
if hexchat.strip(word[0]) in nick_name_pair:
hexchat.emit_print("Channel Message", \
hexchat.strip(word[0]) + " [%s]" % nick_name_pair[hexchat.strip(word[0])], word[1])
return hexchat.EAT_ALL
# /pair_nick <nick> <name>
def pair_nick(word, word_eol, userdata=None):
nick = word[1]
name = word[2]
nick_name_pair[nick] = name
save()
print("&Plugin[N2N]\tThe nick: %s is now paired with name: %s" % (nick, name))
# /remove_pair <nick>
def remove_pair(word, word_eol, userdata=None):
nick = word[1]
del nick_name_pair[nick]
print("&Plugin[N2N]\tThe nick: %s is no longer paired" % nick)
def turn_on(word, word_eol, userdata=None):
on = True
print("&Plugin[N2N]\ton: true")
def turn_off(word, word_eol, userdata=None):
on = False
print("&Plugin[N2N]\ton: false")
def save():
with open(f, 'w') as pair_file:
pair_file.write(json.dumps(nick_name_pair))
def help(word, word_eol, userdata=None):
print("\x0304Nick to Name Help")
print("\x0304Comamnds:")
print("\x0304 pair_nick: /pair_nick <nick> <name>")
print("\x0304 remove_pair: /remove_pair <nick>")
print("\x0304 n2n->on: Turns the plugin on")
print("\x0304 n2n->on: Turns the plugin off")
if os.path.exists(f):
nick_name_pair = json.loads(open(f, 'r').read())
hexchat.hook_command("pair_nick", pair_nick)
hexchat.hook_command("remove_pair", remove_pair)
hexchat.hook_command("n2n->on", turn_on)
hexchat.hook_command("n2n->off", turn_off)
hexchat.hook_command("n2n", help)
hexchat.hook_print("Channel Message", on_message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment