Change line handling
This commit is contained in:
parent
e232ad5dae
commit
caab9b6714
4 changed files with 166 additions and 144 deletions
|
@ -59,6 +59,7 @@ class EventHook(object):
|
||||||
return multiple_event_hook
|
return multiple_event_hook
|
||||||
return self.get_child(subevent)
|
return self.get_child(subevent)
|
||||||
def call(self, max=None, **kwargs):
|
def call(self, max=None, **kwargs):
|
||||||
|
if "data" in kwargs: kwargs.update(kwargs["data"].map())
|
||||||
event = Event(self.bot, self.name, **kwargs)
|
event = Event(self.bot, self.name, **kwargs)
|
||||||
if self._call_notify:
|
if self._call_notify:
|
||||||
self._call_notify(self, event)
|
self._call_notify(self, event)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import re, threading
|
import re, threading
|
||||||
|
|
||||||
import Utils
|
import Utils
|
||||||
|
|
||||||
RE_PREFIXES = re.compile(r"\bPREFIX=\((\w+)\)(\W+)(?:\b|$)")
|
RE_PREFIXES = re.compile(r"\bPREFIX=\((\w+)\)(\W+)(?:\b|$)")
|
||||||
|
@ -12,7 +13,22 @@ default_events = {}
|
||||||
current_description = None
|
current_description = None
|
||||||
current_default_event = False
|
current_default_event = False
|
||||||
handle_lock = threading.Lock()
|
handle_lock = threading.Lock()
|
||||||
line, line_split, bot, server = None, None, None, None
|
bot = None
|
||||||
|
|
||||||
|
class LineData:
|
||||||
|
def __init__(self, line, line_split, prefix, command, args, is_final, server):
|
||||||
|
self.line, self.prefix = line, prefix
|
||||||
|
self.command, self.args = command, args
|
||||||
|
self.is_final = is_final,
|
||||||
|
self.server, self.line_split = server, line_split
|
||||||
|
|
||||||
|
def map(self):
|
||||||
|
return {
|
||||||
|
"line": self.line, "line_split": self.line_split,
|
||||||
|
"prefix": self.prefix, "command": self.command,
|
||||||
|
"args": self.args, "is_final": self.is_final,
|
||||||
|
"server": self.server,
|
||||||
|
}
|
||||||
|
|
||||||
def handler(f=None, description=None, default_event=False):
|
def handler(f=None, description=None, default_event=False):
|
||||||
global current_description, current_default_event
|
global current_description, current_default_event
|
||||||
|
@ -26,47 +42,43 @@ def handler(f=None, description=None, default_event=False):
|
||||||
descriptions[name] = current_description
|
descriptions[name] = current_description
|
||||||
default_events[name] = current_default_event
|
default_events[name] = current_default_event
|
||||||
current_description, current_default_event = None, False
|
current_description, current_default_event = None, False
|
||||||
def handle(_line, _line_split, _bot, _server):
|
|
||||||
global line, line_split, bot, server
|
def handle(line, prefix, command, args, is_final, _bot, _server):
|
||||||
|
global bot
|
||||||
|
line_split = line.split(" ")
|
||||||
|
data = LineData(line, line_split, prefix, command, args, is_final, _server)
|
||||||
handler_function = None
|
handler_function = None
|
||||||
|
|
||||||
if len(_line_split) > 1:
|
if command in handlers:
|
||||||
name = _line_split[1]
|
handler_function = handlers[command]
|
||||||
if _line_split[0][0] == ":":
|
if default_events.get(command, False) or not command in handlers:
|
||||||
if name in handlers:
|
if command.isdigit():
|
||||||
handler_function = handlers[name]
|
_bot.events.on("received").on("numeric").on(
|
||||||
if default_events.get(name, False) or not name in handlers:
|
command).call(data=data, number=command)
|
||||||
if name.isdigit():
|
else:
|
||||||
_bot.events.on("received").on("numeric").on(
|
_bot.events.on("received").on(command).call(data=data)
|
||||||
name).call(line=_line,
|
|
||||||
line_split=_line_split, server=_server,
|
|
||||||
number=name)
|
|
||||||
else:
|
|
||||||
_bot.events.on("received").on(name).call(
|
|
||||||
line=_line, line_split=_line_split, server=_server,
|
|
||||||
command=name)
|
|
||||||
elif _line_split[0] in handlers:
|
|
||||||
handler_function = handlers[_line_split[0]]
|
|
||||||
if handler_function:
|
if handler_function:
|
||||||
with handle_lock:
|
with handle_lock:
|
||||||
line, line_split, bot, server = (_line, _line_split,
|
bot = _bot
|
||||||
_bot, _server)
|
handler_function(data)
|
||||||
handler_function()
|
|
||||||
line, line_split, bot, server = None, None, None, None
|
|
||||||
@handler(description="reply to a ping")
|
@handler(description="reply to a ping")
|
||||||
def handle_PING():
|
def handle_PING(data):
|
||||||
nonce = Utils.remove_colon(line_split[1])
|
nonce = data.args[0]
|
||||||
server.send_pong(Utils.remove_colon(line_split[1]))
|
data.server.send_pong(nonce)
|
||||||
bot.events.on("received").on("ping").call(line=line,
|
bot.events.on("received").on("ping").call(data=data, nonce=nonce)
|
||||||
line_split=line_split, server=server, nonce=nonce)
|
|
||||||
@handler(description="the first line sent to a registered client", default_event=True)
|
@handler(description="the first line sent to a registered client", default_event=True)
|
||||||
def handle_001():
|
def handle_001(data):
|
||||||
server.set_own_nickname(line_split[2])
|
server = data.server
|
||||||
|
server.set_own_nickname(data.args[0])
|
||||||
server.send_whois(server.nickname)
|
server.send_whois(server.nickname)
|
||||||
|
|
||||||
@handler(description="the extra supported things line")
|
@handler(description="the extra supported things line")
|
||||||
def handle_005():
|
def handle_005(data):
|
||||||
isupport_line = Utils.arbitrary(line_split, 3)
|
server = data.server
|
||||||
if "NAMESX" in line:
|
isupport_line = " ".join(data.args[1:])
|
||||||
|
if "NAMESX" in data.line:
|
||||||
server.send("PROTOCTL NAMESX")
|
server.send("PROTOCTL NAMESX")
|
||||||
match = re.search(RE_PREFIXES, isupport_line)
|
match = re.search(RE_PREFIXES, isupport_line)
|
||||||
if match:
|
if match:
|
||||||
|
@ -82,39 +94,41 @@ def handle_005():
|
||||||
if match:
|
if match:
|
||||||
server.channel_types = list(match.group(1))
|
server.channel_types = list(match.group(1))
|
||||||
bot.events.on("received").on("numeric").on("005").call(
|
bot.events.on("received").on("numeric").on("005").call(
|
||||||
line=line, line_split=line_split, server=server,
|
data=data, isupport=isupport_line, number="005")
|
||||||
isupport=isupport_line, number="005")
|
|
||||||
@handler(description="whois respose (nickname, username, realname, hostname)", default_event=True)
|
@handler(description="whois respose (nickname, username, realname, hostname)", default_event=True)
|
||||||
def handle_311():
|
def handle_311(data):
|
||||||
nickname = line_split[3]
|
server = data.server
|
||||||
|
nickname = data.args[1]
|
||||||
if server.is_own_nickname(nickname):
|
if server.is_own_nickname(nickname):
|
||||||
target = server
|
target = server
|
||||||
else:
|
else:
|
||||||
target = server.get_user(nickname)
|
target = server.get_user(nickname)
|
||||||
username = line_split[4]
|
target.username = data.args[2]
|
||||||
hostname = line_split[5]
|
target.hostname = data.args[3]
|
||||||
target.username = username
|
target.realname = data.args[-1]
|
||||||
target.hostname = hostname
|
|
||||||
@handler(description="on-join channel topic line", default_event=True)
|
@handler(description="on-join channel topic line", default_event=True)
|
||||||
def handle_332():
|
def handle_332(data):
|
||||||
channel = server.get_channel(line_split[3])
|
channel = data.server.get_channel(data.args[1])
|
||||||
topic = Utils.arbitrary(line_split, 4)
|
topic = data.args[2]
|
||||||
channel.set_topic(topic)
|
channel.set_topic(topic)
|
||||||
|
|
||||||
@handler(description="on-join channel topic set by/at", default_event=True)
|
@handler(description="on-join channel topic set by/at", default_event=True)
|
||||||
def handle_333():
|
def handle_333(data):
|
||||||
channel = server.get_channel(line_split[3])
|
channel = data.server.get_channel(data.args[1])
|
||||||
topic_setter_hostmask = line_split[4]
|
topic_setter_hostmask = data.args[2]
|
||||||
nickname, username, hostname = Utils.seperate_hostmask(
|
nickname, username, hostname = Utils.seperate_hostmask(
|
||||||
topic_setter_hostmask)
|
topic_setter_hostmask)
|
||||||
topic_time = int(line_split[5]) if line_split[5].isdigit(
|
topic_time = int(data.args[3]) if data.args[3].isdigit() else None
|
||||||
) else None
|
|
||||||
channel.set_topic_setter(nickname, username, hostname)
|
channel.set_topic_setter(nickname, username, hostname)
|
||||||
channel.set_topic_time(topic_time)
|
channel.set_topic_time(topic_time)
|
||||||
|
|
||||||
@handler(description="on-join user list with status symbols", default_event=True)
|
@handler(description="on-join user list with status symbols", default_event=True)
|
||||||
def handle_353():
|
def handle_353(data):
|
||||||
channel = server.get_channel(line_split[4])
|
server = data.server
|
||||||
nicknames = line_split[5:]
|
channel = server.get_channel(data.args[2])
|
||||||
nicknames[0] = Utils.remove_colon(nicknames[0])
|
nicknames = data.args[3].split()
|
||||||
for nickname in nicknames:
|
for nickname in nicknames:
|
||||||
if nickname.strip():
|
if nickname.strip():
|
||||||
modes = set([])
|
modes = set([])
|
||||||
|
@ -126,10 +140,12 @@ def handle_353():
|
||||||
channel.add_user(user)
|
channel.add_user(user)
|
||||||
for mode in modes:
|
for mode in modes:
|
||||||
channel.add_mode(mode, nickname)
|
channel.add_mode(mode, nickname)
|
||||||
|
|
||||||
@handler(description="on user joining channel")
|
@handler(description="on user joining channel")
|
||||||
def handle_JOIN():
|
def handle_JOIN(data):
|
||||||
nickname, username, hostname = Utils.seperate_hostmask(line_split[0])
|
server = data.server
|
||||||
channel = server.get_channel(Utils.remove_colon(line_split[2]))
|
nickname, username, hostname = Utils.seperate_hostmask(data.prefix)
|
||||||
|
channel = server.get_channel(Utils.remove_colon(data.args[0]))
|
||||||
if not server.is_own_nickname(nickname):
|
if not server.is_own_nickname(nickname):
|
||||||
user = server.get_user(nickname)
|
user = server.get_user(nickname)
|
||||||
if not server.has_user(nickname):
|
if not server.has_user(nickname):
|
||||||
|
@ -137,25 +153,24 @@ def handle_JOIN():
|
||||||
user.hostname = hostname
|
user.hostname = hostname
|
||||||
channel.add_user(user)
|
channel.add_user(user)
|
||||||
user.join_channel(channel)
|
user.join_channel(channel)
|
||||||
bot.events.on("received").on("join").call(line=line,
|
bot.events.on("received").on("join").call(data=data, channel=channel,
|
||||||
line_split=line_split, server=server, channel=channel,
|
|
||||||
user=user)
|
user=user)
|
||||||
else:
|
else:
|
||||||
if channel.name in server.attempted_join:
|
if channel.name in server.attempted_join:
|
||||||
del server.attempted_join[channel.name]
|
del server.attempted_join[channel.name]
|
||||||
bot.events.on("self").on("join").call(line=line,
|
bot.events.on("self").on("join").call(data=data, channel=channel)
|
||||||
line_split=line_split, server=server, channel=channel)
|
|
||||||
server.send_who(channel.name)
|
server.send_who(channel.name)
|
||||||
channel.send_mode()
|
channel.send_mode()
|
||||||
|
|
||||||
@handler(description="on user parting channel")
|
@handler(description="on user parting channel")
|
||||||
def handle_PART():
|
def handle_PART(data):
|
||||||
nickname, username, hostname = Utils.seperate_hostmask(line_split[0])
|
server = data.server
|
||||||
channel = server.get_channel(line_split[2])
|
nickname, username, hostname = Utils.seperate_hostmask(data.prefix)
|
||||||
reason = Utils.arbitrary(line_split, 3)
|
channel = server.get_channel(data.args[0])
|
||||||
|
reason = data.args[1]
|
||||||
if not server.is_own_nickname(nickname):
|
if not server.is_own_nickname(nickname):
|
||||||
user = server.get_user(nickname)
|
user = server.get_user(nickname)
|
||||||
bot.events.on("received").on("part").call(line=line,
|
bot.events.on("received").on("part").call(data=data, channel=channel,
|
||||||
line_split=line_split, server=server, channel=channel,
|
|
||||||
reason=reason, user=user)
|
reason=reason, user=user)
|
||||||
channel.remove_user(user)
|
channel.remove_user(user)
|
||||||
user.part_channel(channel)
|
user.part_channel(channel)
|
||||||
|
@ -163,60 +178,49 @@ def handle_PART():
|
||||||
server.remove_user(user)
|
server.remove_user(user)
|
||||||
else:
|
else:
|
||||||
server.remove_channel(channel)
|
server.remove_channel(channel)
|
||||||
bot.events.on("self").on("part").call(line=line,
|
bot.events.on("self").on("part").call(data=data, channel=channel,
|
||||||
line_split=line_split, server=server, channel=channel,
|
|
||||||
reason=reason)
|
reason=reason)
|
||||||
|
|
||||||
@handler(description="unknown command sent by us, oops!", default_event=True)
|
@handler(description="unknown command sent by us, oops!", default_event=True)
|
||||||
def handle_421():
|
def handle_421(data):
|
||||||
print("warning: unknown command '%s'." % line_split[3])
|
print("warning: unknown command '%s'." % data.args[1])
|
||||||
|
|
||||||
@handler(description="a user has disconnected!")
|
@handler(description="a user has disconnected!")
|
||||||
def handle_QUIT():
|
def handle_QUIT(data):
|
||||||
nickname, username, hostname = Utils.seperate_hostmask(line_split[0])
|
server = data.server
|
||||||
reason = Utils.arbitrary(line_split, 2)
|
nickname, username, hostname = Utils.seperate_hostmask(data.prefix)
|
||||||
|
reason = data.args[0]
|
||||||
if not server.is_own_nickname(nickname):
|
if not server.is_own_nickname(nickname):
|
||||||
user = server.get_user(nickname)
|
user = server.get_user(nickname)
|
||||||
server.remove_user(user)
|
server.remove_user(user)
|
||||||
bot.events.on("received").on("quit").call(line=line,
|
bot.events.on("received").on("quit").call(data=data, reason=reason,
|
||||||
line_split=line_split, server=server, reason=reason,
|
|
||||||
user=user)
|
user=user)
|
||||||
else:
|
else:
|
||||||
server.disconnect()
|
server.disconnect()
|
||||||
|
|
||||||
@handler(description="The server is telling us about its capabilities!")
|
@handler(description="The server is telling us about its capabilities!")
|
||||||
def handle_CAP():
|
def handle_CAP(data):
|
||||||
_line = line
|
capability_list = data.args[2].split()
|
||||||
_line_split = line_split
|
bot.events.on("received").on("cap").call(data=data,
|
||||||
if line.startswith(":"):
|
subcommand=data.args[1], capabilities=capability_list)
|
||||||
_line = " ".join(line_split[1:])
|
|
||||||
_line_split = _line.split()
|
|
||||||
|
|
||||||
capability_list = Utils.arbitrary(_line_split, 3).split()
|
|
||||||
bot.events.on("received").on("cap").call(line=line,
|
|
||||||
line_split=line_split, server=server,
|
|
||||||
nickname=_line_split[1], subcommand=_line_split[2],
|
|
||||||
capabilities=capability_list)
|
|
||||||
|
|
||||||
@handler(description="The server is asking for authentication")
|
@handler(description="The server is asking for authentication")
|
||||||
def handle_AUTHENTICATE():
|
def handle_AUTHENTICATE(data):
|
||||||
_line_split = line_split
|
bot.events.on("received").on("authenticate").call(data=data,
|
||||||
if line.startswith(":"):
|
message=data.args[0]
|
||||||
_line_split = line_split[1:]
|
|
||||||
bot.events.on("received").on("authenticate").call(line=line,
|
|
||||||
line_split=line_split, server=server,
|
|
||||||
message=Utils.arbitrary(_line_split, 1)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@handler(description="someone has changed their nickname")
|
@handler(description="someone has changed their nickname")
|
||||||
def handle_NICK():
|
def handle_NICK(data):
|
||||||
nickname, username, hostname = Utils.seperate_hostmask(line_split[0])
|
server = data.server
|
||||||
new_nickname = Utils.remove_colon(line_split[2])
|
nickname, username, hostname = Utils.seperate_hostmask(data.prefix)
|
||||||
|
new_nickname = data.args[0]
|
||||||
if not server.is_own_nickname(nickname):
|
if not server.is_own_nickname(nickname):
|
||||||
user = server.get_user(nickname)
|
user = server.get_user(nickname)
|
||||||
old_nickname = user.nickname
|
old_nickname = user.nickname
|
||||||
user.set_nickname(new_nickname)
|
user.set_nickname(new_nickname)
|
||||||
server.change_user_nickname(old_nickname, new_nickname)
|
server.change_user_nickname(old_nickname, new_nickname)
|
||||||
bot.events.on("received").on("nick").call(line=line,
|
bot.events.on("received").on("nick").call(data=data,
|
||||||
line_split=line_split, server=server,
|
|
||||||
new_nickname=new_nickname, old_nickname=old_nickname,
|
new_nickname=new_nickname, old_nickname=old_nickname,
|
||||||
user=user)
|
user=user)
|
||||||
else:
|
else:
|
||||||
|
@ -225,16 +229,18 @@ def handle_NICK():
|
||||||
bot.events.on("self").on("nick").call(line=line,
|
bot.events.on("self").on("nick").call(line=line,
|
||||||
line_split=line_split, server=server,
|
line_split=line_split, server=server,
|
||||||
new_nickname=new_nickname, old_nickname=old_nickname)
|
new_nickname=new_nickname, old_nickname=old_nickname)
|
||||||
|
|
||||||
@handler(description="something's mode has changed")
|
@handler(description="something's mode has changed")
|
||||||
def handle_MODE():
|
def handle_MODE(data):
|
||||||
nickname, username, hostname = Utils.seperate_hostmask(line_split[0])
|
server = data.server
|
||||||
target = line_split[2]
|
nickname, username, hostname = Utils.seperate_hostmask(data.prefix)
|
||||||
|
target = data.args[0]
|
||||||
is_channel = target[0] in server.channel_types
|
is_channel = target[0] in server.channel_types
|
||||||
if is_channel:
|
if is_channel:
|
||||||
channel = server.get_channel(target)
|
channel = server.get_channel(target)
|
||||||
remove = False
|
remove = False
|
||||||
args = line_split[4:]
|
args = data.args[2:]
|
||||||
modes = line_split[3]
|
modes = data.args[1]
|
||||||
for i, char in enumerate(modes):
|
for i, char in enumerate(modes):
|
||||||
if char == "+":
|
if char == "+":
|
||||||
remove = False
|
remove = False
|
||||||
|
@ -255,10 +261,9 @@ def handle_MODE():
|
||||||
elif len(args):
|
elif len(args):
|
||||||
args.pop(0)
|
args.pop(0)
|
||||||
bot.events.on("received").on("mode").call(
|
bot.events.on("received").on("mode").call(
|
||||||
line=line, line_split=line_split, server=server, modes=modes,
|
data=data, modes=modes, args=args, channel=channel)
|
||||||
args=args, channel=channel)
|
|
||||||
elif server.is_own_nickname(target):
|
elif server.is_own_nickname(target):
|
||||||
modes = Utils.remove_colon(line_split[3])
|
modes = Utils.remove_colon(data.args[1])
|
||||||
remove = False
|
remove = False
|
||||||
for i, char in enumerate(modes):
|
for i, char in enumerate(modes):
|
||||||
if char == "+":
|
if char == "+":
|
||||||
|
@ -270,62 +275,67 @@ def handle_MODE():
|
||||||
server.remove_own_mode(char)
|
server.remove_own_mode(char)
|
||||||
else:
|
else:
|
||||||
server.add_own_mode(char)
|
server.add_own_mode(char)
|
||||||
bot.events.on("self").on("mode").call(
|
bot.events.on("self").on("mode").call(data=data, modes=modes)
|
||||||
line=line, line_split=line_split, server=server, modes=modes)
|
#:nick!user@host MODE #chan +v-v nick nick
|
||||||
|
|
||||||
@handler(description="I've been invited somewhere")
|
@handler(description="I've been invited somewhere")
|
||||||
def handle_INVITE():
|
def handle_INVITE(data):
|
||||||
nickname, username, hostname = Utils.seperate_hostmask(line_split[0])
|
nickname, username, hostname = Utils.seperate_hostmask(data.prefix)
|
||||||
target_channel = Utils.remove_colon(line_split[3])
|
target_channel = Utils.remove_colon(data.args[1])
|
||||||
user = server.get_user(nickname)
|
user = data.server.get_user(nickname)
|
||||||
bot.events.on("received").on("invite").call(
|
bot.events.on("received").on("invite").call(
|
||||||
line=line, line_split=line_split, server=server,
|
data=data, user=user, target_channel=target_channel)
|
||||||
user=user, target_channel=target_channel)
|
|
||||||
@handler(description="we've received a message")
|
@handler(description="we've received a message")
|
||||||
def handle_PRIVMSG():
|
def handle_PRIVMSG(data):
|
||||||
nickname, username, hostname = Utils.seperate_hostmask(line_split[0])
|
server = data.server
|
||||||
|
nickname, username, hostname = Utils.seperate_hostmask(data.prefix)
|
||||||
user = server.get_user(nickname)
|
user = server.get_user(nickname)
|
||||||
message = Utils.arbitrary(line_split, 3)
|
message = data.args[1]
|
||||||
message_split = message.split(" ")
|
message_split = message.split(" ")
|
||||||
target = line_split[2]
|
target = data.args[0]
|
||||||
action = message.startswith("\01ACTION ") and message.endswith("\01")
|
action = message.startswith("\01ACTION ") and message.endswith("\01")
|
||||||
if action:
|
if action:
|
||||||
message = message.replace("\01ACTION ", "", 1)[:-1]
|
message = message.replace("\01ACTION ", "", 1)[:-1]
|
||||||
if target[0] in server.channel_types:
|
if target[0] in server.channel_types:
|
||||||
channel = server.get_channel(line_split[2])
|
channel = server.get_channel(line_split[2])
|
||||||
bot.events.on("received").on("message").on("channel").call(
|
bot.events.on("received").on("message").on("channel").call(
|
||||||
line=line, line_split=line_split, server=server,
|
data=data, user=user, message=message, message_split=message_split,
|
||||||
user=user, message=message, message_split=message_split,
|
|
||||||
channel=channel, action=action)
|
channel=channel, action=action)
|
||||||
channel.log.add_line(user.nickname, message, action)
|
channel.log.add_line(user.nickname, message, action)
|
||||||
elif server.is_own_nickname(target):
|
elif server.is_own_nickname(target):
|
||||||
bot.events.on("received").on("message").on("private").call(
|
bot.events.on("received").on("message").on("private").call(
|
||||||
line=line, line_split=line_split, server=server,
|
data=data, user=user, message=message, message_split=message_split,
|
||||||
user=user, message=message, message_split=message_split,
|
|
||||||
action=action)
|
action=action)
|
||||||
user.log.add_line(user.nickname, message, action)
|
user.log.add_line(user.nickname, message, action)
|
||||||
|
|
||||||
@handler(description="response to a WHO command for user information", default_event=True)
|
@handler(description="response to a WHO command for user information", default_event=True)
|
||||||
def handle_352():
|
def handle_352(data):
|
||||||
user = server.get_user(line_split[7])
|
user = data.server.get_user(data.args[5])
|
||||||
user.username = line_split[4]
|
user.username = data.args[2]
|
||||||
user.hostname = line_split[5]
|
user.hostname = data.args[3]
|
||||||
|
|
||||||
@handler(description="response to an empty mode command", default_event=True)
|
@handler(description="response to an empty mode command", default_event=True)
|
||||||
def handle_324():
|
def handle_324(data):
|
||||||
channel = server.get_channel(line_split[3])
|
channel = data.server.get_channel(data.args[1])
|
||||||
modes = line_split[4]
|
modes = data.args[2]
|
||||||
if modes[0] == "+" and modes[1:]:
|
if modes[0] == "+" and modes[1:]:
|
||||||
for mode in modes[1:]:
|
for mode in modes[1:]:
|
||||||
if mode in server.channel_modes:
|
if mode in data.server.channel_modes:
|
||||||
channel.add_mode(mode)
|
channel.add_mode(mode)
|
||||||
|
|
||||||
@handler(description="channel creation unix timestamp", default_event=True)
|
@handler(description="channel creation unix timestamp", default_event=True)
|
||||||
def handle_329():
|
def handle_329(data):
|
||||||
channel = server.get_channel(line_split[3])
|
channel = data.server.get_channel(data.args[1])
|
||||||
channel.creation_timestamp = int(line_split[4])
|
channel.creation_timestamp = int(data.args[2])
|
||||||
|
|
||||||
@handler(description="nickname already in use", default_event=True)
|
@handler(description="nickname already in use", default_event=True)
|
||||||
def handle_433():
|
def handle_433(data):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@handler(description="we need a registered nickname for this channel", default_event=True)
|
@handler(description="we need a registered nickname for this channel", default_event=True)
|
||||||
def handle_477():
|
def handle_477(data):
|
||||||
bot.add_timer("rejoin", 5, channel_name=line_split[3],
|
bot.add_timer("rejoin", 5, channel_name=data.args[1],
|
||||||
key=server.attempted_join[line_split[3].lower()],
|
key=data.server.attempted_join[data.args[1].lower()],
|
||||||
server_id=server.id)
|
server_id=data.server.id)
|
||||||
#:newirc.tripsit.me 477 BitBot ##nope :Cannot join channel (+r) - you need to be identified with services
|
#:newirc.tripsit.me 477 BitBot ##nope :Cannot join channel (+r) - you need to be identified with services
|
||||||
|
|
18
IRCServer.py
18
IRCServer.py
|
@ -128,10 +128,20 @@ class Server(object):
|
||||||
user.part_channel(channel)
|
user.part_channel(channel)
|
||||||
del self.channels[channel.name]
|
del self.channels[channel.name]
|
||||||
def parse_line(self, line):
|
def parse_line(self, line):
|
||||||
if line:
|
if not line: return
|
||||||
line_split = line.split(" ")
|
original_line = line
|
||||||
IRCLineHandler.handle(line, line_split, self.bot, self)
|
prefix, final = None, None
|
||||||
self.check_users()
|
if line[0]==":":
|
||||||
|
prefix, line = line[1:].split(" ", 1)
|
||||||
|
command, line = (line.split(" ", 1) + [""])[:2]
|
||||||
|
if line[:1]==":":
|
||||||
|
final, line = line[1:], ""
|
||||||
|
elif " :" in line:
|
||||||
|
line, final = line.split(" :", 1)
|
||||||
|
args_split = line.split(" ") if line else []
|
||||||
|
if final: args_split.append(final)
|
||||||
|
IRCLineHandler.handle(original_line, prefix, command, args_split, final!=None, self.bot, self)
|
||||||
|
self.check_users()
|
||||||
def check_users(self):
|
def check_users(self):
|
||||||
for user in self.new_users:
|
for user in self.new_users:
|
||||||
if not len(user.channels):
|
if not len(user.channels):
|
||||||
|
|
|
@ -7,6 +7,7 @@ class User(object):
|
||||||
self.set_nickname(nickname)
|
self.set_nickname(nickname)
|
||||||
self.username = None
|
self.username = None
|
||||||
self.hostname = None
|
self.hostname = None
|
||||||
|
self.realname = None
|
||||||
self.server = server
|
self.server = server
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.channels = set([])
|
self.channels = set([])
|
||||||
|
|
Loading…
Reference in a new issue