<commit_before># -*- coding: utf-8 -*-

import random
from Plugin import *
from utilities import *

class QuotesPlugin(Plugin):
    """
    Quotes bot prints a random quote.
    """
    priority = 0
    name = "QuotesPlugin"
    author = "<NAME> <<EMAIL>>"
    description = "Quotes bot prints a random quote."
    nick = "HALiBot"
    filename = "extras/quotes.dat"
    filename_jeff = "extras/jeff_quotes.dat"
    filename_kim = "extras/kimjongil_quotes.dat"
    filename_newquotes = "extras/quotes_new.dat"
    separator = '%'
    commands = [
        dict(
            command = ['!citera', '!citat add', '!quote add'],
            handler = 'add_quote',
        ),
        dict(
            command = ['!kimjongil'],
            handler = 'random_kim',
        ),
        dict(
            command = ['!jeff', '!coupling'],
            handler = 'random_jeff',
        ),
        dict(
            command = ['!citat', '!quote'],
            handler = 'random_quote',
        ),
    ]

    def setup(self):
        """
        Setup method which is called once before any triggers methods are called.
        """
        self.quotes = read_file(self.filename, self.separator)
        self.quotes_kim = read_file(self.filename_kim, self.separator)
        self.quotes_jeff = read_file(self.filename_jeff, self.separator)

    def add_quote(self, text, nick, command, cmd):
        newquote = text.replace(command, '', 1).strip()
        if newquote:
            add_line_to_file(self.filename_newquotes, newquote, separator=self.separator)
            self.bridge.send_and_shout("Quote added for review.", self.nick)

    def random_kim(self, text, nick, command, cmd):
        self.bridge.send_and_shout(random.choice(self.quotes_kim), self.nick)

    def random_jeff(self, text, nick, command, cmd):
        self.bridge.send_and_shout(random.choice(self.quotes_jeff), self.nick)

    def random_quote(self, text, nick, command, cmd):
        self.bridge.send_and_shout(random.choice(self.quotes), self.nick)

def main():
    import sys
    import string
    from time import time
    from Conf import Conf
    import Shoutbox
    cfg = Conf('config.ini', 'LOCAL')
    args = sys.argv
    msg = ' '.join(args[1:])
    shout = Shoutbox.Shout(1, 4711, 'Test', msg, time())
    bridge = FakeBridge()
    plug = QuotesPlugin([bridge])
    plug.setup()
    print "Returned:", plug.handleShoutMessage(shout)
<commit_msg>Made QuotesPlugin a bit more generic to make it easier to add new quote files.<commit_after># -*- coding: utf-8 -*-

import random
from Plugin import *
from utilities import *

class QuotesPlugin(Plugin):
    """
    Quotes bot prints a random quote.
    """
    priority = 0
    name = "QuotesPlugin"
    author = "<NAME> <<EMAIL>>"
    description = "Quotes bot prints a random quote."
    separator = '%'
    commands = [
        dict(
            command = ['!citera', '!citat add', '!quote add'],
            handler = 'add_quote',
            quotefile = 'extras/quotes_new.dat',
        ),
        dict(
            command = ['!kimjongil', '!kim'],
            handler = 'random_quote',
            quotefile = 'extras/kimjongil_quotes.dat',
        ),
        dict(
            command = ['!jeff', '!coupling'],
            handler = 'random_quote',
            quotefile = 'extras/jeff_quotes.dat',
        ),
        dict(
            command = ['!citat', '!quote'],
            handler = 'random_quote',
            quotefile = 'extras/quotes.dat',
        ),
    ]

    def setup(self):
        """
        Setup method which is called once before any triggers methods are called.
        """
        for c in self.commands:
            c['quotes'] = read_file(c['quotefile'], self.separator)

    def add_quote(self, text, nick, command, cmd):
        newquote = text.replace(command, '', 1).strip()
        if newquote:
            add_line_to_file(cmd['quotefile'], newquote, separator=self.separator)
            self.bridge.send_and_shout("Quote added for review.", self.nick)

    def random_quote(self, text, nick, command, cmd):
        self.bridge.send_and_shout(random.choice(cmd['quotes']), self.nick)

def main():
    import sys
    import string
    from time import time
    from Conf import Conf
    import Shoutbox
    cfg = Conf('config.ini', 'LOCAL')
    args = sys.argv
    msg = ' '.join(args[1:])
    shout = Shoutbox.Shout(1, 4711, 'Test', msg, time())
    bridge = FakeBridge()
    plug = QuotesPlugin([bridge])
    plug.setup()
    print "Returned:", plug.handleShoutMessage(shout)

{'fraction_non_alphanumeric': 0.13177611282503304, 'fraction_numerical': 0.003966505068312032, 'mean_word_length': 2.374721189591078, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6461259', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1398, 'n_words': 343}