Add _recv hook
This commit is contained in:
parent
895804e6c1
commit
dd171d568a
|
@ -9,3 +9,4 @@ pyircbot.egg-info
|
||||||
dev
|
dev
|
||||||
docs/builder/build.sh
|
docs/builder/build.sh
|
||||||
examples/config.test.json
|
examples/config.test.json
|
||||||
|
osxenv
|
||||||
|
|
|
@ -94,7 +94,7 @@ class IRCCore(asynchat.async_chat):
|
||||||
# Signal disconnection
|
# Signal disconnection
|
||||||
self.alive=alive
|
self.alive=alive
|
||||||
# Close socket
|
# Close socket
|
||||||
self.shutdown(SHUT_RDWR)
|
self.socket.shutdown(SHUT_RDWR)
|
||||||
self.close()
|
self.close()
|
||||||
self.log.info("Kill complete")
|
self.log.info("Kill complete")
|
||||||
|
|
||||||
|
@ -205,6 +205,7 @@ class IRCCore(asynchat.async_chat):
|
||||||
args = data.split(" ")
|
args = data.split(" ")
|
||||||
for index,arg in enumerate(args):
|
for index,arg in enumerate(args):
|
||||||
args[index]=arg.strip()
|
args[index]=arg.strip()
|
||||||
|
self.fire_hook("_RECV", args=args, prefix=prefix, trailing=trailing)
|
||||||
if not command in self.hookcalls:
|
if not command in self.hookcalls:
|
||||||
self.log.warning("Unknown command: cmd='%s' prefix='%s' args='%s' trailing='%s'" % (command, prefix, args, trailing))
|
self.log.warning("Unknown command: cmd='%s' prefix='%s' args='%s' trailing='%s'" % (command, prefix, args, trailing))
|
||||||
else:
|
else:
|
||||||
|
@ -217,6 +218,7 @@ class IRCCore(asynchat.async_chat):
|
||||||
self.hooks = [
|
self.hooks = [
|
||||||
'_CONNECT', # Called when the bot connects to IRC on the socket level
|
'_CONNECT', # Called when the bot connects to IRC on the socket level
|
||||||
'_DISCONNECT', # Called when the irc socket is forcibly closed
|
'_DISCONNECT', # Called when the irc socket is forcibly closed
|
||||||
|
'_RECV', # Called on network activity
|
||||||
'NOTICE', # :irc.129irc.com NOTICE AUTH :*** Looking up your hostname...
|
'NOTICE', # :irc.129irc.com NOTICE AUTH :*** Looking up your hostname...
|
||||||
'MODE', # :CloneABCD MODE CloneABCD :+iwx
|
'MODE', # :CloneABCD MODE CloneABCD :+iwx
|
||||||
'PING', # PING :irc.129irc.com
|
'PING', # PING :irc.129irc.com
|
||||||
|
@ -250,9 +252,7 @@ class IRCCore(asynchat.async_chat):
|
||||||
'433', # :nova.esper.net 433 * pyircbot3 :Nickname is already in use.
|
'433', # :nova.esper.net 433 * pyircbot3 :Nickname is already in use.
|
||||||
]
|
]
|
||||||
" mapping of hooks to methods "
|
" mapping of hooks to methods "
|
||||||
self.hookcalls = {}
|
self.hookcalls = {command:[] for command in self.hooks}
|
||||||
for command in self.hooks:
|
|
||||||
self.hookcalls[command]=[]
|
|
||||||
|
|
||||||
def fire_hook(self, command, args=None, prefix=None, trailing=None):
|
def fire_hook(self, command, args=None, prefix=None, trailing=None):
|
||||||
"""Run any listeners for a specific hook
|
"""Run any listeners for a specific hook
|
||||||
|
@ -319,7 +319,7 @@ class IRCCore(asynchat.async_chat):
|
||||||
|
|
||||||
return type('IRCEvent', (object,), {
|
return type('IRCEvent', (object,), {
|
||||||
"args": args,
|
"args": args,
|
||||||
"prefix": IRCCore.decodePrefix(prefix),
|
"prefix": IRCCore.decodePrefix(prefix) if prefix else None,
|
||||||
"trailing": trailing
|
"trailing": trailing
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue