aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jesopo2017-10-27 13:15:33 +0100
committerGravatar jesopo2017-10-27 13:15:33 +0100
commit0df7abb03e2a75744a575bc9a7b349fa98d6f485 (patch)
treef6a4a5f952f030108371588347a45f0cea684eed
parentAmber Rudd (diff)
signature
Handle empty CAP, additional IRCLog feature, better tls, better channel_save logic, add sed-sender-only setting
Signed-off-by: jesopo <github@lolnerd.net>
-rw-r--r--IRCLineHandler.py7
-rw-r--r--IRCLog.py4
-rw-r--r--IRCServer.py7
-rw-r--r--modules/channel_save.py14
-rw-r--r--modules/commands.py3
-rw-r--r--modules/sed.py11
6 files changed, 35 insertions, 11 deletions
diff --git a/IRCLineHandler.py b/IRCLineHandler.py
index 1bcc8f57..b36e6ac4 100644
--- a/IRCLineHandler.py
+++ b/IRCLineHandler.py
@@ -200,9 +200,10 @@ def handle_QUIT(data):
@handler(description="The server is telling us about its capabilities!")
def handle_CAP(data):
- capability_list = data.args[2].split()
- bot.events.on("received").on("cap").call(data=data,
- subcommand=data.args[1], capabilities=capability_list)
+ if len(data.args) > 2:
+ capability_list = data.args[2].split()
+ bot.events.on("received").on("cap").call(data=data,
+ subcommand=data.args[1], capabilities=capability_list)
@handler(description="The server is asking for authentication")
def handle_AUTHENTICATE(data):
diff --git a/IRCLog.py b/IRCLog.py
index abc3d715..834939e2 100644
--- a/IRCLog.py
+++ b/IRCLog.py
@@ -27,6 +27,8 @@ class Log(object):
return line
def find(self, pattern, **kwargs):
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)
for line in self.lines:
if line.from_self and not from_self:
@@ -34,6 +36,8 @@ class Log(object):
elif re.search(pattern, line.message):
if not_pattern and re.search(not_pattern, line.message):
continue
+ if for_user and not line.sender.lower() == for_user:
+ continue
return line
def skip_next(self):
self._skip_next = True
diff --git a/IRCServer.py b/IRCServer.py
index 2783ae91..0de4d854 100644
--- a/IRCServer.py
+++ b/IRCServer.py
@@ -38,7 +38,9 @@ class Server(object):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
self.socket.settimeout(5.0)
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.cached_fileno = self.socket.fileno()
self.bot.events.on("timer").on("rejoin").hook(self.try_rejoin)
@@ -178,7 +180,8 @@ class Server(object):
if len(encoded) > 450:
encoded = encoded[:450]
self.write_buffer += b"%s\r\n" % encoded
- print(encoded.decode("utf8"))
+ if self.bot.args.verbose:
+ print(encoded.decode("utf8"))
def _send(self):
self.write_buffer = self.write_buffer[self.socket.send(
self.write_buffer):]
diff --git a/modules/channel_save.py b/modules/channel_save.py
index 713a7cb5..35a62626 100644
--- a/modules/channel_save.py
+++ b/modules/channel_save.py
@@ -22,8 +22,12 @@ class Module(object):
if event["line_split"][3].lower() == "#bitbot" or event["number"]=="001":
channels = event["server"].get_setting("autojoin", [])
chan_keys = event["server"].get_setting("channel_keys", {})
- for channel in channels:
- if channel in chan_keys:
- event["server"].send_join(channel, key=chan_keys[channel])
- else:
- event["server"].send_join(channel)
+ channels_sorted = sorted(channels,
+ key=lambda x: 0 if x in chan_keys else 1)
+
+ keys_sorted = map(lambda x: x[1],
+ sorted(chan_keys.items(),
+ key=lambda x: channels_sorted.index(x[0])))
+ event["server"].send_join(
+ ",".join(channels_sorted), ",".join(keys_sorted))
+
diff --git a/modules/commands.py b/modules/commands.py
index 8a811e2e..6985c869 100644
--- a/modules/commands.py
+++ b/modules/commands.py
@@ -1,3 +1,4 @@
+import re
import Utils
STR_MORE = "%s (more...)" % Utils.FONT_RESET
@@ -5,6 +6,8 @@ STR_CONTINUED = "(...continued) "
OUT_CUTOFF = 400
+REGEX_CUTOFF = re.compile("^.{1,%d}(?:\s|$)" % OUT_CUTOFF)
+
class Out(object):
def __init__(self, module_name, target):
self.module_name = module_name
diff --git a/modules/sed.py b/modules/sed.py
index 460dfd81..77c6f9a2 100644
--- a/modules/sed.py
+++ b/modules/sed.py
@@ -16,6 +16,11 @@ class Module(object):
"channelset").call(setting="sed",
help="Disable/Enable sed in a channel",
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):
if event["action"] or not Utils.get_closest_setting(event, "sed", True):
@@ -51,7 +56,11 @@ class Module(object):
return
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:
new_message = re.sub(pattern, replace, line.message, count)
if line.action: