-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
logging: don't log if opt_in_channels
is empty or channel not in it
#7
base: master
Are you sure you want to change the base?
Changes from 3 commits
05b5a54
12099b3
dc0f55a
9fbcd9b
530a9b6
70897af
d9fc0a1
5519459
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,7 @@ class ChanlogsSection(StaticSection): | |
topic_template = ValidatedAttribute('topic_template', default=None) | ||
opt_in_channels = ListAttribute('opt_in_channels') | ||
|
||
|
||
def configure(config): | ||
config.define_section('chanlogs', ChanlogsSection, validate=False) | ||
config.chanlogs.configure_setting( | ||
|
@@ -111,6 +112,17 @@ def _format_template(tpl, bot, trigger, **kwargs): | |
return formatted | ||
|
||
|
||
def _channel_is_opted_in(is_channel, channel, opted_in_channels): | ||
if is_channel and not opted_in_channels or str(channel) in opted_in_channels: # cast channel to string because I don't trust python | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Also PEP8 demands two spaces before There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't everything in the array be a string though? |
||
# returns true if channel should be logged. | ||
# If opted_in_channels is empty, assume logged. | ||
# If channel in opted_in_channels, logged | ||
# Otherwise, don't log | ||
return True | ||
else: | ||
return False | ||
|
||
|
||
def setup(bot): | ||
bot.config.define_section('chanlogs', ChanlogsSection) | ||
|
||
|
@@ -127,7 +139,7 @@ def log_message(bot, message): | |
# if this is a private message and we're not logging those, return early | ||
if message.sender.is_nick() and not bot.config.chanlogs.privmsg: | ||
return | ||
if message.sender.is_channel() and bot.config.chanlogs.opt_in_channels in not [] and trigger not in bot.config.chanlogs.opt_in_channels: | ||
if not _channel_is_opted_in(message.sender.is_channel(), trigger.sender, bot.config.chanlogs.opt_in_channels): | ||
return | ||
# determine which template we want, message or action | ||
if message.startswith("\001ACTION ") and message.endswith("\001"): | ||
|
@@ -148,7 +160,7 @@ def log_message(bot, message): | |
@sopel.module.event("JOIN") | ||
@sopel.module.unblockable | ||
def log_join(bot, trigger): | ||
if message.sender.is_channel() and bot.config.chanlogs.opt_in_channels in not [] and trigger not in bot.config.chanlogs.opt_in_channels: | ||
if not _channel_is_opted_in(message.sender.is_channel(), trigger.sender, bot.config.chanlogs.opt_in_channels) | ||
RhinosF1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return | ||
tpl = bot.config.chanlogs.join_template or JOIN_TPL | ||
logline = _format_template(tpl, bot, trigger) | ||
|
@@ -162,7 +174,7 @@ def log_join(bot, trigger): | |
@sopel.module.event("PART") | ||
@sopel.module.unblockable | ||
def log_part(bot, trigger): | ||
if message.sender.is_channel() and bot.config.chanlogs.opt_in_channels in not [] and trigger not in bot.config.chanlogs.opt_in_channels: | ||
if not _channel_is_opted_in(message.sender.is_channel(), trigger.sender, bot.config.chanlogs.opt_in_channels) | ||
RhinosF1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return | ||
tpl = bot.config.chanlogs.part_template or PART_TPL | ||
logline = _format_template(tpl, bot, trigger=trigger) | ||
|
@@ -183,12 +195,13 @@ def log_quit(bot, trigger): | |
# make a copy of bot.privileges that we can safely iterate over | ||
privcopy = list(bot.privileges.items()) | ||
# write logline to *all* channels that the user was present in | ||
for channel, privileges in privcopy: | ||
if trigger.nick in privileges: | ||
fpath = get_fpath(bot, trigger, channel) | ||
with bot.memory['chanlog_locks'][fpath]: | ||
with open(fpath, "ab") as f: | ||
f.write(logline.encode('utf8')) | ||
if not _channel_is_opted_in(message.sender.is_channel(), trigger.sender, bot.config.chanlogs.opt_in_channels) | ||
RhinosF1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for channel, privileges in privcopy: | ||
if trigger.nick in privileges: | ||
fpath = get_fpath(bot, trigger, channel) | ||
with bot.memory['chanlog_locks'][fpath]: | ||
with open(fpath, "ab") as f: | ||
f.write(logline.encode('utf8')) | ||
|
||
|
||
@sopel.module.rule('.*') | ||
|
@@ -203,7 +216,7 @@ def log_nick_change(bot, trigger): | |
privcopy = list(bot.privileges.items()) | ||
# write logline to *all* channels that the user is present in | ||
for channel, privileges in privcopy: | ||
if old_nick in privileges or new_nick in privileges and message.sender.is_channel() and bot.config.chanlogs.opt_in_channels in not [] and trigger not in bot.config.chanlogs.opt_in_channels: | ||
if old_nick in privileges or new_nick in privileges and not _channel_is_opted_in(message.sender.is_channel(), trigger.sender, bot.config.chanlogs.opt_in_channels): | ||
return | ||
fpath = get_fpath(bot, trigger, channel) | ||
with bot.memory['chanlog_locks'][fpath]: | ||
|
@@ -215,7 +228,7 @@ def log_nick_change(bot, trigger): | |
@sopel.module.event("TOPIC") | ||
@sopel.module.unblockable | ||
def log_topic(bot, trigger): | ||
if message.sender.is_channel() and bot.config.chanlogs.opt_in_channels in not [] and trigger not in bot.config.chanlogs.opt_in_channels: | ||
if not _channel_is_opted_in(message.sender.is_channel(), trigger.sender, bot.config.chanlogs.opt_in_channels) | ||
RhinosF1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return | ||
tpl = bot.config.chanlogs.topic_template or TOPIC_TPL | ||
logline = _format_template(tpl, bot, trigger) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this take
is_channel
as an argument? Callers derive it fromTrigger.sender.is_nick()
anyway, so… that can be part of the function.Also:
sopel.tools.Identifier
, of whichTrigger.sender
is an instance, doesn't have anis_channel()
method. Did you…test this patch?