-
Notifications
You must be signed in to change notification settings - Fork 2
/
xpyhilight.py
147 lines (127 loc) · 3.72 KB
/
xpyhilight.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
"""xPyHilight v0.8b
A script for Xchat, HexChat and Xchat-WDK to log highlights
in a separate window.
It does not output anything publically.
Installation:
-------------
The script is ready to go out of the box, but there are some
settings you could modify if felt needed.
Settings are described below.
Dependencies:
-------------
* Python 2.7.3 <http://python.org/>
"""
__module_name__ = "xPyHilight"
__module_version__ = "0.8b"
__module_description__ = "Keeps track of highlights"
import xchat
from time import strftime
##
# The name of the window where highlights are logged.
#
# Must not be a valid IRC channel- or nickname as it may then collide
# with an actual entity.
##
WINDOW_NAME = "(Highlights)"
##
# The default value for the /SET VARIABLE `tab_new_to_front`.
#
# The plugin temporarily changes the setting and will set it
# to this value afterwards.
#
# Find out the default value by executing the following command:
# /SET tab_new_to_front
##
DEFAULT_SET_VALUE = 2
##
# Time formatting.
#
# Must comply with the parameter passed to time.strftime()
# <http://docs.python.org/2/library/time.html#time.strftime>
##
TIME_FORMAT = "%H:%M:%S"
##
# The text formatting for the logger.
#
# The dict items correspond to Xchat Text Events:
# MESSAGE: Channel Msg Hilight
# ACTION: Channel Action Hilight
#
# Both of these must be defined.
#
# Values must be a tuple with 2 items, where the first
# item is the left hand side and the second the
# right hand side of the separator.
#
# Each value is used with the String formatting operator (%)
# with named mappings.
# <http://docs.python.org/2/library/stdtypes.html#string-formatting>
#
# The following information is available:
# - channel
# - time
# - mode
# - nick
# - text
# All of them are sent to both tuple items,
# and any of them can be omitted.
#
# IRC specific text formatting codes can be represented
# as specified:
#
# Type HEX OCT
# -----------------------------
# Bold 0x02 002
# Color 0x03 003 (with 2 digits after, f.ex. \00304 = color 4)
# Underlined 0x1F 037
# Reverse/Italic 0x16 026
# Out/Escape 0x0F 017
##
OUT = {
"MESSAGE": ("%(channel)s", "\00321[%(time)s] <\002%(mode)s%(nick)s\002> %(text)s\017"),
"ACTION": ("%(channel)s", "\00321[%(time)s] * \002%(mode)s%(nick)s\002 %(text)s\017")
}
##
# Specifies whether highlights should only be logged when
# you are away.
##
ONLY_AWAY = False
def catch_hilight(word, word_eol, userdata):
if ONLY_AWAY:
# If you are not away
if xchat.get_info("away") is None:
return xchat.EAT_NONE
channel = xchat.get_info("channel")
server = xchat.get_info("server") # used to find the context
timestamp = strftime(TIME_FORMAT)
nick, message = word[:2]
mode = word[2] if len(word) >= 3 else ""
data = {
"channel": channel,
"time": timestamp,
"mode": mode,
"nick": nick,
"text": message
}
# Turns off automatic focusing of new tabs.
xchat.command("set -quiet tab_new_to_front 0")
# Opens a new window if there is none already.
xchat.command("query -nofocus %s" % WINDOW_NAME)
# Resets the focusing settings.
xchat.command("set -quiet tab_new_to_front %d" % DEFAULT_SET_VALUE)
# Fetches the context object of the window.
context = xchat.find_context(server=server, channel=WINDOW_NAME)
if context is not None:
context.emit_print("Generic Message",
OUT[userdata][0] % data,
OUT[userdata][1] % data
)
else: # this should never happen
xchat.emit_print("Generic Message",
__module_name__,
"Unknown error: Unable to create context object"
)
return xchat.EAT_NONE
xchat.hook_print("Channel Msg Hilight", catch_hilight, userdata="MESSAGE")
xchat.hook_print("Channel Action Hilight", catch_hilight, userdata="ACTION")
print __module_name__, __module_version__, "script loaded\003"