Advertisement
Guest User

hexchatscript

a guest
Feb 8th, 2016
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.11 KB | None | 0 0
  1. from __future__ import print_function
  2. import hexchat
  3.  
  4. __module_name__ = 'Hexchat Color Script'
  5. __module_version__ = '1.6'
  6. __module_description__ = 'Adds color to sent text'
  7. __author__ = 'NUDGERTONSKI and Death'
  8.  
  9. """
  10. Comments and help text added by Dr. Ambiguous
  11. This script will add color to a line of sent text in Hexchat.
  12. """
  13.  
  14. send_color = True
  15.  
  16. # Default color:
  17. color_code = '05'
  18.  
  19. # Add any aliases for color codes as strings (in quotes) on both sides:
  20. color_codes = {'white': '00',
  21. 'black': '01',
  22. 'blue': '02',
  23. 'green': '03',
  24. 'red': '04',
  25. 'brown': '05',
  26. 'purple': '06',
  27. 'violet': '06',
  28. 'orange': '07',
  29. 'yellow': '08',
  30. 'light green': '09',
  31. 'teal': '10',
  32. 'light blue': '11',
  33. 'royal blue': '12',
  34. 'pink': '13',
  35. 'grey': '14',
  36. 'gray': '14',
  37. 'light grey': '15',
  38. 'light gray': '15',}
  39.  
  40. def change_color(word, word_eol, userdata):
  41. global color_code
  42.  
  43. try:
  44. new_color = word_eol[1].lower().strip()
  45. except IndexError:
  46. # No argument passed (only typed in the command).
  47. display_color()
  48. return hexchat.EAT_ALL
  49.  
  50. try:
  51. # See if user tried the color name.
  52. color_code = color_codes[new_color]
  53. print('\003{color}Color changed to {}.'.format(new_color,
  54. color=color_code))
  55.  
  56. return hexchat.EAT_ALL
  57. except KeyError:
  58. pass
  59.  
  60. try:
  61. # See if user tried the color code (number).
  62. if int(new_color) not in [int(v) for v in color_codes.values()]:
  63. # Color code not in the color_codes dictionary.
  64. pass
  65. else:
  66. color_code = '{}'.format(new_color.lstrip('0').rjust(2, '0'))
  67. print('\003{color}Color changed to {}.'.format([c for c in color_codes if color_codes[c] == color_code][0],
  68. color=color_code))
  69.  
  70. return hexchat.EAT_ALL
  71. except ValueError:
  72. pass
  73.  
  74. print('\00304Invalid color code. Codes range from 0 to 15.')
  75.  
  76. return hexchat.EAT_NONE
  77.  
  78. def color_off(word, word_eol, userdata):
  79. global send_color
  80.  
  81. if send_color: # No point in changing if it's already False.
  82. send_color = False
  83. print('\00304Color is disabled.')
  84.  
  85. return hexchat.EAT_ALL
  86.  
  87. def color_on(word, word_eol, userdata):
  88. global send_color
  89.  
  90. if not send_color: # No point in changing if it's already True.
  91. send_color = True
  92. print('\00304Color is enabled.')
  93.  
  94. return hexchat.EAT_ALL
  95.  
  96. def display_color():
  97. print("Color: {} ({}).".format([c for c in color_codes if color_codes[c] == color_code][0],
  98. color_code))
  99.  
  100. return hexchat.EAT_NONE
  101.  
  102. def get_colors(word, word_eol, userdata):
  103. print('== Colors ==')
  104. for code in sorted(color_codes.values()):
  105. print('{num} - {name}'.format(name=", ".join([c for c in color_codes if color_codes[c] == code]),
  106. num=code))
  107. print('== End of color list ==')
  108.  
  109. return hexchat.EAT_ALL
  110.  
  111. def say_cb(word, word_eol, userdata):
  112. # Basically saying:
  113. # /msg [channel] [color code][message]
  114.  
  115. # See comments below for a list of color codes.
  116.  
  117. # 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']
  118. # 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']
  119. networks = ['EsperNet',]
  120. channels = ['',]
  121.  
  122. # Apparently Hexchat will split your message into multiple lines if you go past this.
  123. max_chars = 374
  124.  
  125. global send_color
  126.  
  127. network, channel = hexchat.get_info('network'), hexchat.get_info('channel')
  128.  
  129. if send_color: # If send_color is True (color toggled on),
  130. if (channel in channels) or (network in networks):
  131. message = word_eol[0]
  132. counter = 0
  133.  
  134. # For multiline support:
  135. while message:
  136. # Send first [max_chars amount of] characters in message.
  137. hexchat.command('msg {c} \003{color}{m}'.format(c=channel,
  138. color=color_code,
  139. m=message[:max_chars])
  140. )
  141.  
  142. # Discard sent characters from message.
  143. message = message[max_chars:]
  144.  
  145. return hexchat.EAT_ALL
  146. else:
  147. pass
  148.  
  149. 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.
  150.  
  151. return hexchat.EAT_ALL
  152.  
  153. c = '\x0312'
  154. def onUnload(userdata):
  155. hexchat.prnt('%s- %s version: %s has been unloaded.' % (c, __module_name__, __module_version__))
  156.  
  157. hexchat.hook_command('color', change_color, help='Change which color you want to use. For a list of colors, use /colorlist .')
  158. hexchat.hook_command('colorlist', get_colors, help='Displays the color codes you can switch to.')
  159. hexchat.hook_command('coloroff', color_off, help='Disable color.') # Toggles color off.
  160. hexchat.hook_command('coloron', color_on, help='Enable color. To change color, use /color .') # Toggles color on.
  161. hexchat.hook_command('', say_cb) # Calls say_cb when a message is sent the regular way, or with /say
  162. hexchat.hook_unload(onUnload)
  163.  
  164. print('%s- %s version: %s has been loaded.' % (c, __module_name__, __module_version__))
  165.  
  166. # Color Codes
  167. # 00 = White
  168. # 01 = Black
  169. # 02 = Blue
  170. # 03 = Green
  171. # 04 = Red
  172. # 05 = Brown
  173. # 06 = Purple
  174. # 07 = Orange
  175. # 08 = Yellow
  176. # 09 = Light Green
  177. # 10 = Teal
  178. # 11 = Light Blue
  179. # 12 = Royal Blue
  180. # 13 = Pink
  181. # 14 = Grey
  182. # 15 = Light Grey
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement