mirror of
https://github.com/jlu5/PyLink.git
synced 2025-01-24 03:04:05 +01:00
move hook calling out of pr/insp and into Irc
This commit is contained in:
parent
df595c65a1
commit
fdea348cbe
30
main.py
30
main.py
@ -7,6 +7,7 @@ import time
|
|||||||
import sys
|
import sys
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import threading
|
import threading
|
||||||
|
import traceback
|
||||||
|
|
||||||
from log import log
|
from log import log
|
||||||
import conf
|
import conf
|
||||||
@ -111,7 +112,34 @@ class Irc():
|
|||||||
while '\n' in buf:
|
while '\n' in buf:
|
||||||
line, buf = buf.split('\n', 1)
|
line, buf = buf.split('\n', 1)
|
||||||
log.debug("(%s) <- %s", self.name, line)
|
log.debug("(%s) <- %s", self.name, line)
|
||||||
proto.handle_events(self, line)
|
hook_args = self.proto.handle_events(self, line)
|
||||||
|
# Only call our hooks if there's data to process. Handlers that support
|
||||||
|
# hooks will return a dict of parsed arguments, which can be passed on
|
||||||
|
# to plugins and the like. For example, the JOIN handler will return
|
||||||
|
# something like: {'channel': '#whatever', 'users': ['UID1', 'UID2',
|
||||||
|
# 'UID3']}, etc.
|
||||||
|
if hook_args is not None:
|
||||||
|
self.callHooks(hook_args)
|
||||||
|
|
||||||
|
def callHooks(self, hook_args):
|
||||||
|
numeric, command, parsed_args = hook_args
|
||||||
|
# Always make sure TS is sent.
|
||||||
|
if 'ts' not in parsed_args:
|
||||||
|
parsed_args['ts'] = int(time.time())
|
||||||
|
hook_cmd = command
|
||||||
|
hook_map = self.proto.hook_map
|
||||||
|
if command in hook_map:
|
||||||
|
hook_cmd = hook_map[command]
|
||||||
|
log.debug('Parsed args %r received from %s handler (calling hook %s)', parsed_args, command, hook_cmd)
|
||||||
|
# Iterate over hooked functions, catching errors accordingly
|
||||||
|
for hook_func in utils.command_hooks[hook_cmd]:
|
||||||
|
try:
|
||||||
|
log.debug('Calling function %s', hook_func)
|
||||||
|
hook_func(self, numeric, command, parsed_args)
|
||||||
|
except Exception:
|
||||||
|
# We don't want plugins to crash our servers...
|
||||||
|
traceback.print_exc()
|
||||||
|
continue
|
||||||
|
|
||||||
def send(self, data):
|
def send(self, data):
|
||||||
# Safeguard against newlines in input!! Otherwise, each line gets
|
# Safeguard against newlines in input!! Otherwise, each line gets
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import traceback
|
|
||||||
import re
|
import re
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
|
||||||
@ -570,28 +569,8 @@ def handle_events(irc, data):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
parsed_args = func(irc, numeric, command, args)
|
parsed_args = func(irc, numeric, command, args)
|
||||||
# Only call our hooks if there's data to process. Handlers that support
|
|
||||||
# hooks will return a dict of parsed arguments, which can be passed on
|
|
||||||
# to plugins and the like. For example, the JOIN handler will return
|
|
||||||
# something like: {'channel': '#whatever', 'users': ['UID1', 'UID2',
|
|
||||||
# 'UID3']}, etc.
|
|
||||||
if parsed_args is not None:
|
if parsed_args is not None:
|
||||||
# Always make sure TS is sent.
|
return [numeric, command, parsed_args]
|
||||||
if 'ts' not in parsed_args:
|
|
||||||
parsed_args['ts'] = int(time.time())
|
|
||||||
hook_cmd = command
|
|
||||||
if command in hook_map:
|
|
||||||
hook_cmd = hook_map[command]
|
|
||||||
log.debug('Parsed args %r received from %s handler (calling hook %s)', parsed_args, command, hook_cmd)
|
|
||||||
# Iterate over hooked functions, catching errors accordingly
|
|
||||||
for hook_func in utils.command_hooks[hook_cmd]:
|
|
||||||
try:
|
|
||||||
log.debug('Calling function %s', hook_func)
|
|
||||||
hook_func(irc, numeric, command, parsed_args)
|
|
||||||
except Exception:
|
|
||||||
# We don't want plugins to crash our servers...
|
|
||||||
traceback.print_exc()
|
|
||||||
continue
|
|
||||||
|
|
||||||
def spawnServer(irc, name, sid=None, uplink=None, desc='PyLink Server', endburst=True):
|
def spawnServer(irc, name, sid=None, uplink=None, desc='PyLink Server', endburst=True):
|
||||||
# -> :0AL SERVER test.server * 1 0AM :some silly pseudoserver
|
# -> :0AL SERVER test.server * 1 0AM :some silly pseudoserver
|
||||||
|
Loading…
Reference in New Issue
Block a user