From 0606ee7ace767d99a3b45a2b0b2543847272a093 Mon Sep 17 00:00:00 2001 From: Edward Powell Date: Fri, 13 Feb 2015 08:19:54 -0500 Subject: [PATCH] chanlogs: Do something about weird chars in filename This probably works, but tbh I'm just throwing it together and haven't actually tested it. If it does work, it'll close #490. --- chanlogs.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/chanlogs.py b/chanlogs.py index 9fc3a8c2da..3be29d6a83 100644 --- a/chanlogs.py +++ b/chanlogs.py @@ -10,6 +10,7 @@ from __future__ import unicode_literals import os import os.path +import re import threading import sys from datetime import datetime @@ -23,6 +24,8 @@ JOIN_TPL = "{datetime} *** {trigger.nick} has joined {trigger}" PART_TPL = "{datetime} *** {trigger.nick} has left {trigger}" QUIT_TPL = "{datetime} *** {trigger.nick} has quit IRC" +# According to Wikipedia +BAD_CHARS = re.compile(r'[\/?%*:|"<>. ]') def configure(config): @@ -48,6 +51,7 @@ def get_fpath(bot, trigger, channel=None): basedir = os.path.expanduser(bot.config.chanlogs.dir) channel = channel or trigger.sender channel = channel.lstrip("#") + channel = BAD_CHARS.sub('__') dt = datetime.utcnow() if not bot.config.chanlogs.microseconds: