Skip to content

Instantly share code, notes, and snippets.

@CaitlynMainer
Created December 17, 2016 21:28
__module_name__ = "Discord Integration"
__module_version__ = "1.4"
__module_description__ = "Integrates messages from Discord's IRC bot"
import hexchat, re
hexchat.emit_print("Generic Message", "Loading", "{} {} - {}".format(
__module_name__, __module_version__,
__module_description__))
ignorelist = []
def loadlist():
global ignorelist
try:
ignorelist = hexchat.get_pluginpref('ignorelist').split(',')
except: pass
def savelist():
global ignorelist
ignorelist = filter(None, ignorelist)
hexchat.set_pluginpref('ignorelist', ','.join(ignorelist))
loadlist()
printlist()
def privmsg(word, word_eol, userdata, attrs):
global ignorelist
def send(*args, **kwargs):
if attrs.time:
kwargs.setdefault("time", attrs.time)
return hexchat.emit_print(*args, **kwargs)
bprefix = word[0]
if bprefix[0:1] != ':':
return hexchat.EAT_NONE
bprefix = bprefix[1:]
bnick, _, bhost = split_prefix(bprefix)
if bnick in ['cord', 'MrConductor','Corded','Yui','MCUpdaterBot','PCL-Minecraft','IServer','GamaxYuri','BBM-Discord']:
channel = word[2]
nick = word[3][1:]
for iggynick in ignorelist:
if re.search(iggynick, nick.replace('\u200b', '')) is not None:
return hexchat.EAT_ALL
if nick == '*':
if check_highlight(word_eol[5] if len(word_eol) >= 6 else ""):
send("Channel Action Hilight", hexchat.strip(word[4]), word_eol[5] if len(word_eol) >= 6 else "", "^")
hexchat.command('gui color 3')
else:
send("Channel Action", hexchat.strip(word[4]), word_eol[5] if len(word_eol) >= 6 else "", "^")
hexchat.command('gui color 2')
elif nick[0] == '<' and nick[-1] == '>':
if check_highlight(word_eol[4] if len(word_eol) >= 5 else ""):
send("Channel Msg Hilight", hexchat.strip(nick)[1:-1], word_eol[4] if len(word_eol) >= 5 else "", "^")
hexchat.command('gui color 3')
else:
send("Channel Message", hexchat.strip(nick)[1:-1], word_eol[4] if len(word_eol) >= 5 else "", "^")
hexchat.command('gui color 2')
elif nick[0] == '(' and nick[-1] == ')':
if check_highlight(word_eol[4] if len(word_eol) >= 5 else ""):
send("Channel Msg Hilight", hexchat.strip(nick)[1:-1], word_eol[4] if len(word_eol) >= 5 else "", "^")
hexchat.command('gui color 3')
else:
send("Channel Message", hexchat.strip(nick)[1:-1], word_eol[4] if len(word_eol) >= 5 else "", "^")
hexchat.command('gui color 2')
else:
return hexchat.EAT_NONE
return hexchat.EAT_HEXCHAT
return hexchat.EAT_NONE
def check_highlight(message):
hilights = hexchat.get_prefs("irc_extra_hilight")
hilight_list = hilights.split(",")
if hexchat.get_info("nick") in message:
return True
elif any(message.find(check) > -1 for check in hilight_list):
return True
else:
return False
def split_prefix(prefix):
if '!' in prefix:
nick, _, userhostpart = prefix.partition('!')
user, _, host = userhostpart.partition('@')
else:
nick, _, host = prefix.partition('@')
user = ''
return (nick, user, host)
def addignore(word, word_eol, userdata):
global ignorelist
ignorelist.append(word[1])
hexchat.prnt("Added " + word[1] + " to your ignore list.")
savelist()
return hexchat.EAT_ALL
def delignore(word, word_eol, userdata):
global ignorelist
try:
ignorelist.remove(word[1])
hexchat.prnt("Removed " + word[1] + " from your ignore list.")
savelist()
except: pass
return hexchat.EAT_ALL
def disignore(word, word_eol, userdata):
printlist()
def printlist():
global ignorelist
if len(ignorelist) == 0:
hexchat.prnt('Ignorelist is empty')
return
hexchat.prnt('Ignorelist: ' + ' '.join(ignorelist))
loadlist()
hexchat.hook_command("addignore", addignore)
hexchat.hook_command("delignore", delignore)
hexchat.hook_command("ignorelist", disignore)
hexchat.hook_server_attrs('PRIVMSG', privmsg)
hexchat.prnt(__module_name__ + " " + __module_version__ + " loaded!")
printlist()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment