示例#1
0
def init(context):
    global db
    db = zxJDBC.connect("jdbc:h2:" + context.storageFolder.getPath() + 
                     "/quotedb/db", "sa", "", "org.h2.Driver")
    execute("create table if not exists quotes (quotegroup text, "
            "quotenumber int, quotetext text, hidden boolean)")
    execute("create table if not exists quoteinfo (quotegroup text, "
            "quotenumber int,key text, value text)")
    execute("create table if not exists quotesequence (quotegroup text, "
            "nextquote int)")
    Configuration.register(None, "quote", "This folder holds configuration "
                           "variables related to the quote plugin.", 
                           VarType.folder, None)
    Configuration.register(None, "quote/groupnames", "A space-separated list "
                           "of groups that quotes can be added to.",
                           VarType.text, "")
    Configuration.register(None, "quote/port", "The port to listen for HTTP "
                           "requests on. If this is unset, the HTTP server "
                           "will not be started. This only takes effect "
                           "at restart.", VarType.integer, None)
    if Configuration.isSet(None, "quote/port"):
        server = HTTPServer(("", Configuration.getInt(None, "quote/port")), 
                            HTTPHandler)
        class ServerThread(Thread):
            def run(self):
                server.serve_forever()
        ServerThread().start()
示例#2
0
def addquote(sink, arguments, context):
    """
    Syntax: {addquote|<group>|<quote>} -- Adds a new quote to the specified
    group. This function then evaluates to the number that the new quote
    was assigned. Numbering starts at 1 for blank groups. Groups must already
    be present in the quote system configuration before quotes can be added
    to them; see ~config global quote. If the specified quote is empty, a
    ResponseException will be thrown.
    """
    quotegroup = arguments.resolveString(0)
    quotetext = arguments.resolveString(1)
    if quotetext.strip() == "":
        raise FactoidException("You can't add an empty quote")
    with quote_lock:
        if not quotegroup in Configuration.getText(None, 
                             "quote/groupnames").split(" "):
            raise FactoidException("The group " + quotegroup
                                 + " does not exist.")
        next_id_result = execute("select nextquote from quotesequence where "
                                 "quotegroup = ?", [quotegroup]).fetchone()
        if next_id_result is None:
            next_id_result = 0
            execute_commit("insert into quotesequence values (?, 0)", [quotegroup])
        else:
            next_id_result = next_id_result[0]
        next_id_result += 1
        execute_commit("update quotesequence set nextquote = ? where quotegroup = ?",
                [next_id_result, quotegroup])
        execute_commit("insert into quotes values(?, ?, ?, ?)", [quotegroup,
                next_id_result, quotetext, False])
        add_quote_info(quotegroup, next_id_result, 
                       nick=context.getSender().getNick(), 
                       user=context.getSender().getUsername(), 
                       host=context.getSender().getHostname(), 
                       server=context.getSender().getServerName(), 
                       scope=context.getCanonicalName(),
                       date=str(currentTimeMillis()))
        sink.write(next_id_result)