Last active
December 23, 2019 10:45
-
-
Save dukwon/d29f63a586fd3ea7622eab27cb323d05 to your computer and use it in GitHub Desktop.
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
__module_name__ = "strip_discord_bots" | |
__module_version__ = "1.0" | |
__module_description__ = "Treat messages from discord IRC bridges as if they came from IRC users" | |
import hexchat, re | |
discord_bridges = { | |
# define your discord bridge bots here | |
# network and channel names must be lower case | |
"snoonet": { | |
"#friends": "discord^", | |
"#psychic": "PsychicDiscord", | |
} | |
} | |
def strip_discord_bot(word, word_eol, userdata): | |
network = hexchat.get_info("network").lower() | |
channel = hexchat.get_info("channel").lower() | |
if network in discord_bridges and channel in discord_bridges[network]: | |
bot = discord_bridges[network][channel] | |
else: | |
return hexchat.EAT_NONE | |
nick = hexchat.strip(word[0]) | |
message = word[1] | |
if hexchat.nickcmp(bot, nick) == 0: | |
try: | |
discord_nick = re.match("<.*?>", message).group(0) | |
except AttributeError: | |
# Can happen when the orignial message is too long and gets split over multiple lines | |
return hexchat.EAT_NONE | |
message = message[len(discord_nick)+1:] | |
discord_nick = hexchat.strip(discord_nick).strip("<>") | |
if hexchat.nickcmp(bot, discord_nick) == 0: | |
# Prevent recursion if someone pretends to be the bot | |
return hexchat.EAT_NONE | |
hexchat.emit_print(userdata, discord_nick, message, "") | |
return hexchat.EAT_HEXCHAT | |
return hexchat.EAT_NONE | |
hooks = ["Channel Message", "Channel Msg Hilight"] | |
for name in hooks: | |
hexchat.hook_print(name, strip_discord_bot, userdata = name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment