mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-28 05:29:25 +01:00
Make TS6 command parsing a shared library (#78)
This commit is contained in:
parent
ce83bea09a
commit
1be4034681
@ -4,9 +4,11 @@ import os
|
|||||||
import re
|
import re
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
|
||||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
curdir = os.path.dirname(__file__)
|
||||||
|
sys.path += [curdir, os.path.dirname(curdir)]
|
||||||
import utils
|
import utils
|
||||||
from log import log
|
from log import log
|
||||||
|
import proto_common
|
||||||
|
|
||||||
from classes import *
|
from classes import *
|
||||||
|
|
||||||
@ -597,26 +599,7 @@ def handle_events(irc, data):
|
|||||||
# Sanity check: set this AFTER we fetch the capabilities for the network!
|
# Sanity check: set this AFTER we fetch the capabilities for the network!
|
||||||
irc.connected.set()
|
irc.connected.set()
|
||||||
try:
|
try:
|
||||||
real_args = []
|
args = proto_common.parseTS6Args(args)
|
||||||
for idx, arg in enumerate(args):
|
|
||||||
real_args.append(arg)
|
|
||||||
# If the argument starts with ':' and ISN'T the first argument.
|
|
||||||
# The first argument is used for denoting the source UID/SID.
|
|
||||||
if arg.startswith(':') and idx != 0:
|
|
||||||
# : is used for multi-word arguments that last until the end
|
|
||||||
# of the message. We can use list splicing here to turn them all
|
|
||||||
# into one argument.
|
|
||||||
# Set the last arg to a joined version of the remaining args
|
|
||||||
arg = args[idx:]
|
|
||||||
arg = ' '.join(arg)[1:]
|
|
||||||
# Cut the original argument list right before the multi-word arg,
|
|
||||||
# and then append the multi-word arg.
|
|
||||||
real_args = args[:idx]
|
|
||||||
real_args.append(arg)
|
|
||||||
break
|
|
||||||
real_args[0] = real_args[0].split(':', 1)[1]
|
|
||||||
args = real_args
|
|
||||||
|
|
||||||
numeric = args[0]
|
numeric = args[0]
|
||||||
command = args[1]
|
command = args[1]
|
||||||
args = args[2:]
|
args = args[2:]
|
||||||
|
34
protocols/proto_common.py
Normal file
34
protocols/proto_common.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
def parseArgs(args):
|
||||||
|
"""<arg list>
|
||||||
|
Parses a string of RFC1459-style arguments split into a list, where ":" may
|
||||||
|
be used for multi-word arguments that last until the end of a line.
|
||||||
|
"""
|
||||||
|
real_args = []
|
||||||
|
for idx, arg in enumerate(args):
|
||||||
|
real_args.append(arg)
|
||||||
|
# If the argument starts with ':' and ISN'T the first argument.
|
||||||
|
# The first argument is used for denoting the source UID/SID.
|
||||||
|
if arg.startswith(':') and idx != 0:
|
||||||
|
# : is used for multi-word arguments that last until the end
|
||||||
|
# of the message. We can use list splicing here to turn them all
|
||||||
|
# into one argument.
|
||||||
|
# Set the last arg to a joined version of the remaining args
|
||||||
|
arg = args[idx:]
|
||||||
|
arg = ' '.join(arg)[1:]
|
||||||
|
# Cut the original argument list right before the multi-word arg,
|
||||||
|
# and then append the multi-word arg.
|
||||||
|
real_args = args[:idx]
|
||||||
|
real_args.append(arg)
|
||||||
|
break
|
||||||
|
return real_args
|
||||||
|
|
||||||
|
|
||||||
|
def parseTS6Args(args):
|
||||||
|
"""<arg list>
|
||||||
|
|
||||||
|
Similar to parseArgs(), but stripping leading colons from the first argument
|
||||||
|
of a line (usually the sender field)."""
|
||||||
|
args = parseArgs(args)
|
||||||
|
args[0] = args[0].split(':', 1)[1]
|
||||||
|
return args
|
||||||
|
|
@ -15,6 +15,7 @@ from inspircd import nickClient, kickServer, kickClient, _sendKick, quitClient,
|
|||||||
from inspircd import handle_privmsg, handle_kill, handle_kick, handle_error, \
|
from inspircd import handle_privmsg, handle_kill, handle_kick, handle_error, \
|
||||||
handle_quit, handle_nick, handle_save, handle_squit, handle_mode, handle_topic, \
|
handle_quit, handle_nick, handle_save, handle_squit, handle_mode, handle_topic, \
|
||||||
handle_notice
|
handle_notice
|
||||||
|
import proto_common
|
||||||
|
|
||||||
casemapping = 'rfc1459'
|
casemapping = 'rfc1459'
|
||||||
hook_map = {'SJOIN': 'JOIN', 'TB': 'TOPIC', 'TMODE': 'MODE', 'BMASK': 'MODE'}
|
hook_map = {'SJOIN': 'JOIN', 'TB': 'TOPIC', 'TMODE': 'MODE', 'BMASK': 'MODE'}
|
||||||
@ -577,25 +578,7 @@ def handle_events(irc, data):
|
|||||||
log.debug('(%s) Starting delay to send ENDBURST', irc.name)
|
log.debug('(%s) Starting delay to send ENDBURST', irc.name)
|
||||||
endburst_timer.start()
|
endburst_timer.start()
|
||||||
try:
|
try:
|
||||||
real_args = []
|
args = proto_common.parseTS6Args(args)
|
||||||
for idx, arg in enumerate(args):
|
|
||||||
real_args.append(arg)
|
|
||||||
# If the argument starts with ':' and ISN'T the first argument.
|
|
||||||
# The first argument is used for denoting the source UID/SID.
|
|
||||||
if arg.startswith(':') and idx != 0:
|
|
||||||
# : is used for multi-word arguments that last until the end
|
|
||||||
# of the message. We can use list splicing here to turn them all
|
|
||||||
# into one argument.
|
|
||||||
# Set the last arg to a joined version of the remaining args
|
|
||||||
arg = args[idx:]
|
|
||||||
arg = ' '.join(arg)[1:]
|
|
||||||
# Cut the original argument list right before the multi-word arg,
|
|
||||||
# and then append the multi-word arg.
|
|
||||||
real_args = args[:idx]
|
|
||||||
real_args.append(arg)
|
|
||||||
break
|
|
||||||
real_args[0] = real_args[0].split(':', 1)[1]
|
|
||||||
args = real_args
|
|
||||||
|
|
||||||
numeric = args[0]
|
numeric = args[0]
|
||||||
command = args[1]
|
command = args[1]
|
||||||
|
Loading…
Reference in New Issue
Block a user