Handle empty CAP, additional IRCLog feature, better tls, better channel_save logic, add sed-sender-only setting
Signed-off-by: jesopo <github@lolnerd.net>
This commit is contained in:
parent
72b2f3bc29
commit
0df7abb03e
6 changed files with 35 additions and 11 deletions
|
@ -200,9 +200,10 @@ def handle_QUIT(data):
|
||||||
|
|
||||||
@handler(description="The server is telling us about its capabilities!")
|
@handler(description="The server is telling us about its capabilities!")
|
||||||
def handle_CAP(data):
|
def handle_CAP(data):
|
||||||
capability_list = data.args[2].split()
|
if len(data.args) > 2:
|
||||||
bot.events.on("received").on("cap").call(data=data,
|
capability_list = data.args[2].split()
|
||||||
subcommand=data.args[1], capabilities=capability_list)
|
bot.events.on("received").on("cap").call(data=data,
|
||||||
|
subcommand=data.args[1], capabilities=capability_list)
|
||||||
|
|
||||||
@handler(description="The server is asking for authentication")
|
@handler(description="The server is asking for authentication")
|
||||||
def handle_AUTHENTICATE(data):
|
def handle_AUTHENTICATE(data):
|
||||||
|
|
|
@ -27,6 +27,8 @@ class Log(object):
|
||||||
return line
|
return line
|
||||||
def find(self, pattern, **kwargs):
|
def find(self, pattern, **kwargs):
|
||||||
from_self = kwargs.get("from_self", True)
|
from_self = kwargs.get("from_self", True)
|
||||||
|
for_user = kwargs.get("for_user", "")
|
||||||
|
for_user = for_user.lower() if for_user else None
|
||||||
not_pattern = kwargs.get("not_pattern", None)
|
not_pattern = kwargs.get("not_pattern", None)
|
||||||
for line in self.lines:
|
for line in self.lines:
|
||||||
if line.from_self and not from_self:
|
if line.from_self and not from_self:
|
||||||
|
@ -34,6 +36,8 @@ class Log(object):
|
||||||
elif re.search(pattern, line.message):
|
elif re.search(pattern, line.message):
|
||||||
if not_pattern and re.search(not_pattern, line.message):
|
if not_pattern and re.search(not_pattern, line.message):
|
||||||
continue
|
continue
|
||||||
|
if for_user and not line.sender.lower() == for_user:
|
||||||
|
continue
|
||||||
return line
|
return line
|
||||||
def skip_next(self):
|
def skip_next(self):
|
||||||
self._skip_next = True
|
self._skip_next = True
|
||||||
|
|
|
@ -38,7 +38,9 @@ class Server(object):
|
||||||
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
||||||
self.socket.settimeout(5.0)
|
self.socket.settimeout(5.0)
|
||||||
if self.tls:
|
if self.tls:
|
||||||
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
|
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
|
||||||
|
context.options |= ssl.OP_NO_SSLv2
|
||||||
|
context.options |= ssl.OP_NO_SSLv3
|
||||||
self.socket = context.wrap_socket(self.socket)
|
self.socket = context.wrap_socket(self.socket)
|
||||||
self.cached_fileno = self.socket.fileno()
|
self.cached_fileno = self.socket.fileno()
|
||||||
self.bot.events.on("timer").on("rejoin").hook(self.try_rejoin)
|
self.bot.events.on("timer").on("rejoin").hook(self.try_rejoin)
|
||||||
|
@ -178,7 +180,8 @@ class Server(object):
|
||||||
if len(encoded) > 450:
|
if len(encoded) > 450:
|
||||||
encoded = encoded[:450]
|
encoded = encoded[:450]
|
||||||
self.write_buffer += b"%s\r\n" % encoded
|
self.write_buffer += b"%s\r\n" % encoded
|
||||||
print(encoded.decode("utf8"))
|
if self.bot.args.verbose:
|
||||||
|
print(encoded.decode("utf8"))
|
||||||
def _send(self):
|
def _send(self):
|
||||||
self.write_buffer = self.write_buffer[self.socket.send(
|
self.write_buffer = self.write_buffer[self.socket.send(
|
||||||
self.write_buffer):]
|
self.write_buffer):]
|
||||||
|
|
|
@ -22,8 +22,12 @@ class Module(object):
|
||||||
if event["line_split"][3].lower() == "#bitbot" or event["number"]=="001":
|
if event["line_split"][3].lower() == "#bitbot" or event["number"]=="001":
|
||||||
channels = event["server"].get_setting("autojoin", [])
|
channels = event["server"].get_setting("autojoin", [])
|
||||||
chan_keys = event["server"].get_setting("channel_keys", {})
|
chan_keys = event["server"].get_setting("channel_keys", {})
|
||||||
for channel in channels:
|
channels_sorted = sorted(channels,
|
||||||
if channel in chan_keys:
|
key=lambda x: 0 if x in chan_keys else 1)
|
||||||
event["server"].send_join(channel, key=chan_keys[channel])
|
|
||||||
else:
|
keys_sorted = map(lambda x: x[1],
|
||||||
event["server"].send_join(channel)
|
sorted(chan_keys.items(),
|
||||||
|
key=lambda x: channels_sorted.index(x[0])))
|
||||||
|
event["server"].send_join(
|
||||||
|
",".join(channels_sorted), ",".join(keys_sorted))
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
import Utils
|
import Utils
|
||||||
|
|
||||||
STR_MORE = "%s (more...)" % Utils.FONT_RESET
|
STR_MORE = "%s (more...)" % Utils.FONT_RESET
|
||||||
|
@ -5,6 +6,8 @@ STR_CONTINUED = "(...continued) "
|
||||||
|
|
||||||
OUT_CUTOFF = 400
|
OUT_CUTOFF = 400
|
||||||
|
|
||||||
|
REGEX_CUTOFF = re.compile("^.{1,%d}(?:\s|$)" % OUT_CUTOFF)
|
||||||
|
|
||||||
class Out(object):
|
class Out(object):
|
||||||
def __init__(self, module_name, target):
|
def __init__(self, module_name, target):
|
||||||
self.module_name = module_name
|
self.module_name = module_name
|
||||||
|
|
|
@ -16,6 +16,11 @@ class Module(object):
|
||||||
"channelset").call(setting="sed",
|
"channelset").call(setting="sed",
|
||||||
help="Disable/Enable sed in a channel",
|
help="Disable/Enable sed in a channel",
|
||||||
validate=Utils.bool_or_none)
|
validate=Utils.bool_or_none)
|
||||||
|
self.bot.events.on("postboot").on("configure").on(
|
||||||
|
"channelset").call(setting="sed-sender-only",
|
||||||
|
help=
|
||||||
|
"Disable/Enable sed only looking at the messages sent by the user",
|
||||||
|
validate=Utils.bool_or_none)
|
||||||
|
|
||||||
def channel_message(self, event):
|
def channel_message(self, event):
|
||||||
if event["action"] or not Utils.get_closest_setting(event, "sed", True):
|
if event["action"] or not Utils.get_closest_setting(event, "sed", True):
|
||||||
|
@ -51,7 +56,11 @@ class Module(object):
|
||||||
return
|
return
|
||||||
replace = sed_split[2].replace("\\/", "/")
|
replace = sed_split[2].replace("\\/", "/")
|
||||||
|
|
||||||
line = event["channel"].log.find(pattern, from_self=False, not_pattern=REGEX_SED)
|
for_user = event["user"].nickname if Utils.get_closest_setting(
|
||||||
|
event, "sed-sender-only", False
|
||||||
|
) else None
|
||||||
|
line = event["channel"].log.find(pattern, from_self=False,
|
||||||
|
for_user=for_user, not_pattern=REGEX_SED)
|
||||||
if line:
|
if line:
|
||||||
new_message = re.sub(pattern, replace, line.message, count)
|
new_message = re.sub(pattern, replace, line.message, count)
|
||||||
if line.action:
|
if line.action:
|
||||||
|
|
Loading…
Reference in a new issue