Created
January 9, 2015 19:47
-
-
Save ryancdotorg/ab244a6fe8129398c102 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
import xchat | |
import re | |
import time | |
__module_name__ = "seljp" | |
__module_version__ = "0.1.0" | |
__module_description__ = "Selectively show Join/Part messages only for recent speakers." | |
print "\0034",__module_name__,__module_version__,"has been loaded\003" | |
def unload_cb(userdata): | |
print "\0034",__module_name__,__module_version__,"has been unloaded\003" | |
time_window = 86400 | |
activity = {} | |
def active_cb(words, eol, userdata): | |
target = words[2] | |
if target[0] == '#' or target[0] == '&': | |
chan = target | |
m = re.match('\A:?([^!]+)!(.+)', words[0]) | |
if m is not None: | |
nick = m.group(1) | |
host = m.group(2) | |
mask = nick+'!'+host | |
activity[mask] = int(time.time()) | |
return xchat.EAT_NONE | |
def pjoin_cb(words, eol, userdata): | |
nick = words[0] | |
chan = words[1] | |
host = words[2] | |
return maybe_suppress(nick, host, chan, userdata) | |
def ppart_cb(words, eol, userdata): | |
nick = words[0] | |
chan = words[2] | |
host = words[1] | |
return maybe_suppress(nick, host, chan, userdata) | |
def pquit_cb(words, eol, userdata): | |
nick = words[0] | |
try: | |
chan = words[1] | |
except: | |
chan = '' | |
try: | |
host = words[2] | |
except: | |
host = '' | |
return maybe_suppress(nick, host, chan, userdata) | |
def maybe_suppress(nick, host, target, userdata): | |
mask = nick+'!'+host | |
now = int(time.time()) | |
if mask not in activity or activity[mask] < (now - time_window): | |
#if mask in activity: | |
# print '%s suppressed for %s (last activity %u seconds ago)' % (userdata, nick, now - activity[mask]) | |
#else: | |
# print '%s suppressed for %s (no activity)' % (userdata, nick) | |
return xchat.EAT_XCHAT | |
else: | |
return xchat.EAT_NONE | |
xchat.hook_unload(unload_cb) | |
xchat.hook_print('Join', pjoin_cb, 'Join') | |
xchat.hook_print('Part', ppart_cb, 'Part') | |
xchat.hook_print('Part with Reason', ppart_cb, 'Part with Reason') | |
xchat.hook_print('Quit', pquit_cb, 'Quit') | |
xchat.hook_server('PRIVMSG', active_cb, 'PRIVMSG') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment