Created
August 25, 2015 21:41
-
-
Save LeoVerto/f8aa32ab8cf7ea8b3284 to your computer and use it in GitHub Desktop.
Download to root of project and run "git apply Add-ignore_prefix-configuration-option.patch" to apply.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 69b7d2a3d8f62edb717aabc7a094ee13798d4de5 Mon Sep 17 00:00:00 2001 | |
From: LeoVerto <[email protected]> | |
Date: Thu, 30 Jul 2015 04:41:22 +0300 | |
Subject: [PATCH] Add ignore_prefix configuration option | |
This option allows users to prevent a message from being logged by starting it with a configurable prefix. | |
Possible prefixes include: "[off]", ".off" and "[ignore]". | |
--- | |
botbot/apps/plugins/core/logger.py | 31 +++++++++++++++++++++---------- | |
1 file changed, 21 insertions(+), 10 deletions(-) | |
diff --git a/botbot/apps/plugins/core/logger.py b/botbot/apps/plugins/core/logger.py | |
index c5bbf14..0dacbc8 100644 | |
--- a/botbot/apps/plugins/core/logger.py | |
+++ b/botbot/apps/plugins/core/logger.py | |
@@ -1,6 +1,13 @@ | |
from botbot.apps.logs.models import Log | |
from botbot.apps.plugins.utils import convert_nano_timestamp | |
from botbot_plugins.base import BasePlugin | |
+import botbot_plugins.config as config | |
+ | |
+class Config(config.BaseConfig): | |
+ ignore_prefix = config.Field( | |
+ required=False, | |
+ help_text="Don't log lines starting with this string" | |
+ ) | |
class Plugin(BasePlugin): | |
""" | |
@@ -9,19 +16,23 @@ class Plugin(BasePlugin): | |
I keep extensive logs on all the activity in `{{ channel.name }}`. | |
You can read and search them at {{ SITE }}{{ channel.get_absolute_url }}. | |
""" | |
+ config_class = Config | |
+ | |
def logit(self, line): | |
"""Log a message to the database""" | |
- # If the Channel do not startswtih "#" that means the message | |
+ # If the channel does not start with "#" that means the message | |
# is part of a /query | |
if line._channel_name.startswith("#"): | |
- Log.objects.create( | |
- channel_id=line._channel.pk, | |
- timestamp=line._received, | |
- nick=line.user, | |
- text=line.full_text, | |
- room=line._channel, | |
- host=line._host, | |
- command=line._command, | |
- raw=line._raw) | |
+ ignore_prefix = self.config['ignore_prefix'] | |
+ if not (ignore_prefix and line.text.startswith(ignore_prefix)): | |
+ Log.objects.create( | |
+ channel_id=line._channel.pk, | |
+ timestamp=line._received, | |
+ nick=line.user, | |
+ text=line.full_text, | |
+ room=line._channel, | |
+ host=line._host, | |
+ command=line._command, | |
+ raw=line._raw) | |
logit.route_rule = ('firehose', ur'(.*)') | |
-- | |
2.1.4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment