<commit_before>from hashlib import md5, sha256

from speakerlib import niceify_number

import requests

from config import config

class EventRecorder(object):

    def __init__(self, db):

        self.db = db

    def post_to_slack(self, speech_text, **kwargs):
        if config.get("slack_url", None):
            requests.post(config["slack_url"], data=speech_text)

    def record_utterance(self, speech_text, record_utterance=False, event_result=None):
        if not record_utterance:
            return

        sha = sha256()
        sha.update(speech_text)
        sha_hash = sha.hexdigest()

        matched_snippet = self.db.execute("SELECT votes FROM snippets where sha256=?", [sha_hash]).fetchone()

        if matched_snippet:
            votes = matched_snippet["votes"] + 1
            self.db.execute("UPDATE snippets set votes=? where sha256=?", [votes, sha_hash])
        else:
            self.db.execute("INSERT into snippets (sha256, speech_text, votes) VALUES (?, ?, 0) ", [sha_hash, speech_text])
<commit_msg>Skip plugins for slack post<commit_after>from hashlib import md5, sha256

from speakerlib import niceify_number

import requests

from config import config

class EventRecorder(object):

    def __init__(self, db):

        self.db = db

    def post_to_slack(self, speech_text, **kwargs):
        
        #Skip plugins
        if speech_text[0] == "!":
            return

        if config.get("slack_url", None):
            requests.post(config["slack_url"], data=speech_text)

    def record_utterance(self, speech_text, record_utterance=False, event_result=None):
        if not record_utterance:
            return

        sha = sha256()
        sha.update(speech_text)
        sha_hash = sha.hexdigest()

        matched_snippet = self.db.execute("SELECT votes FROM snippets where sha256=?", [sha_hash]).fetchone()

        if matched_snippet:
            votes = matched_snippet["votes"] + 1
            self.db.execute("UPDATE snippets set votes=? where sha256=?", [votes, sha_hash])
        else:
            self.db.execute("INSERT into snippets (sha256, speech_text, votes) VALUES (?, ?, 0) ", [sha_hash, speech_text])

{'fraction_non_alphanumeric': 0.10742277547256801, 'fraction_numerical': 0.01705855232826187, 'mean_word_length': 2.902877697841727, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5366913', 'n_tokens_mistral': 700, 'n_tokens_neox': 643, 'n_words': 163}