Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- import hexchat
- __module_name__ = 'Hexchat Color Script'
- __module_version__ = '1.6'
- __module_description__ = 'Adds color to sent text'
- __author__ = 'NUDGERTONSKI and Death'
- """
- Comments and help text added by Dr. Ambiguous
- This script will add color to a line of sent text in Hexchat.
- """
- send_color = True
- # Default color:
- color_code = '05'
- # Add any aliases for color codes as strings (in quotes) on both sides:
- color_codes = {'white': '00',
- 'black': '01',
- 'blue': '02',
- 'green': '03',
- 'red': '04',
- 'brown': '05',
- 'purple': '06',
- 'violet': '06',
- 'orange': '07',
- 'yellow': '08',
- 'light green': '09',
- 'teal': '10',
- 'light blue': '11',
- 'royal blue': '12',
- 'pink': '13',
- 'grey': '14',
- 'gray': '14',
- 'light grey': '15',
- 'light gray': '15',}
- def change_color(word, word_eol, userdata):
- global color_code
- try:
- new_color = word_eol[1].lower().strip()
- except IndexError:
- # No argument passed (only typed in the command).
- display_color()
- return hexchat.EAT_ALL
- try:
- # See if user tried the color name.
- color_code = color_codes[new_color]
- print('\003{color}Color changed to {}.'.format(new_color,
- color=color_code))
- return hexchat.EAT_ALL
- except KeyError:
- pass
- try:
- # See if user tried the color code (number).
- if int(new_color) not in [int(v) for v in color_codes.values()]:
- # Color code not in the color_codes dictionary.
- pass
- else:
- color_code = '{}'.format(new_color.lstrip('0').rjust(2, '0'))
- print('\003{color}Color changed to {}.'.format([c for c in color_codes if color_codes[c] == color_code][0],
- color=color_code))
- return hexchat.EAT_ALL
- except ValueError:
- pass
- print('\00304Invalid color code. Codes range from 0 to 15.')
- return hexchat.EAT_NONE
- def color_off(word, word_eol, userdata):
- global send_color
- if send_color: # No point in changing if it's already False.
- send_color = False
- print('\00304Color is disabled.')
- return hexchat.EAT_ALL
- def color_on(word, word_eol, userdata):
- global send_color
- if not send_color: # No point in changing if it's already True.
- send_color = True
- print('\00304Color is enabled.')
- return hexchat.EAT_ALL
- def display_color():
- print("Color: {} ({}).".format([c for c in color_codes if color_codes[c] == color_code][0],
- color_code))
- return hexchat.EAT_NONE
- def get_colors(word, word_eol, userdata):
- print('== Colors ==')
- for code in sorted(color_codes.values()):
- print('{num} - {name}'.format(name=", ".join([c for c in color_codes if color_codes[c] == code]),
- num=code))
- print('== End of color list ==')
- return hexchat.EAT_ALL
- def say_cb(word, word_eol, userdata):
- # Basically saying:
- # /msg [channel] [color code][message]
- # See comments below for a list of color codes.
- # Add in the networks you want this script to run in here between the quotes. Separate additional networks with a comma. Ex: ['TCS','Example','Network']
- # Add in the channels you want this script to run in here between the quotes. Separate additional channels with a comma. Ex: ['#tcschat','#Example','#Channel']
- networks = ['EsperNet',]
- channels = ['',]
- # Apparently Hexchat will split your message into multiple lines if you go past this.
- max_chars = 374
- global send_color
- network, channel = hexchat.get_info('network'), hexchat.get_info('channel')
- if send_color: # If send_color is True (color toggled on),
- if (channel in channels) or (network in networks):
- message = word_eol[0]
- counter = 0
- # For multiline support:
- while message:
- # Send first [max_chars amount of] characters in message.
- hexchat.command('msg {c} \003{color}{m}'.format(c=channel,
- color=color_code,
- m=message[:max_chars])
- )
- # Discard sent characters from message.
- message = message[max_chars:]
- return hexchat.EAT_ALL
- else:
- pass
- hexchat.command('msg {c} {m}'.format(c=channel, m=word_eol[0])) # This will send the text unaltered if you're connected to a network that you don't want to use color.
- return hexchat.EAT_ALL
- c = '\x0312'
- def onUnload(userdata):
- hexchat.prnt('%s- %s version: %s has been unloaded.' % (c, __module_name__, __module_version__))
- hexchat.hook_command('color', change_color, help='Change which color you want to use. For a list of colors, use /colorlist .')
- hexchat.hook_command('colorlist', get_colors, help='Displays the color codes you can switch to.')
- hexchat.hook_command('coloroff', color_off, help='Disable color.') # Toggles color off.
- hexchat.hook_command('coloron', color_on, help='Enable color. To change color, use /color .') # Toggles color on.
- hexchat.hook_command('', say_cb) # Calls say_cb when a message is sent the regular way, or with /say
- hexchat.hook_unload(onUnload)
- print('%s- %s version: %s has been loaded.' % (c, __module_name__, __module_version__))
- # Color Codes
- # 00 = White
- # 01 = Black
- # 02 = Blue
- # 03 = Green
- # 04 = Red
- # 05 = Brown
- # 06 = Purple
- # 07 = Orange
- # 08 = Yellow
- # 09 = Light Green
- # 10 = Teal
- # 11 = Light Blue
- # 12 = Royal Blue
- # 13 = Pink
- # 14 = Grey
- # 15 = Light Grey
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement