def my_test():
    global tester
    t = tester
    if not t.test_is_active:
        return

    t.test("It's now %s. Hub has been running for %s seconds" % (datetime.now(), int(time.time() - vh.starttime)))
    t.test("Script: %s (%s), Python plugin ver. %s / %s" % (vh.name, vh.path, vh.__version__, vh.__version_string__))
    
    t1 = t.test("Checking vh.botname and vh.opchatname values", vh.botname == "Verlihub" and vh.opchatname == "OpChat",
        "They are: '%s' and '%s'" % (vh.botname, vh.opchatname))
    t2 = t.test_eq("Confirming that hublist_host is empty", vh.GetConfig("config", "hublist_host"), "")
    t3 = t.test_eq("Confirming that send_crash_report is 0", vh.GetConfig("config", "send_crash_report"), "0")
    t4 = t.test_eq("Checking usercount", vh.GetUsersCount(), 0)
    if not (t1 and t2 and t3 and t4):
        t.test("Cannot continue testing with these errors", 0)
        return t.finish_testing(1)


    t.test("Trying to set vh.name_and_version", vh.name_and_version(my_name, my_version))
    x = vh.name_and_version()
    t.test("Reading and verifying vh.name_and_version", x and x[0] == my_name and x[1] == my_version, x)

    t.test("Checking nicklists...")
    x = vh.GetRawNickList()
    t.test("Checking vh.GetRawNickList", "Verlihub$$" in x and "OpChat$$" in x and x.startswith("$NickList "), x)
    x = vh.GetRawOpList()
    t.test("Checking vh.GetRawOpList", "Verlihub$$" in x and "OpChat$$" in x and x.startswith("$OpList "), x)
    x = vh.GetRawBotList()
    t.test("Checking vh.GetRawBotList", "Verlihub$$" in x and "OpChat$$" in x and x.startswith("$BotList "), x)

    x = vh.GetNickList()
    t.test("Checking vh.GetNickList", "Verlihub" in x and "OpChat" in x and isinstance(x, list), x)
    x = vh.GetOpList()
    t.test("Checking vh.GetOpList", "Verlihub" in x and "OpChat" in x and isinstance(x, list), x)
    x = vh.GetBotList()
    t.test("Checking vh.GetBotList", "Verlihub" in x and "OpChat" in x and isinstance(x, list), x)


    t.test("")
    t.test("Testing vh.ScriptQuery and communication between scripts...")
    x = vh.ScriptQuery("_get_script_file", "")
    t.test("Getting a list of scripts", x and isinstance(x, list), "List is empty. Impossible!")
    t.test_in("Confirming that we are on it", vh.path, x)
    t.test("There are %s scripts on the list" % len(x))

    x = vh.ScriptQuery("_get_script_file", "", "python")
    if t.test("Getting a list of python scripts", x and isinstance(x, list), "List is empty. Impossible!"):
        py_len = len(x)
        if t.test_in("Confirming that we are on it", vh.path, x):
            my_pos = x.index(vh.path)
            t.test("The paths are: %s" % x)

            x = vh.ScriptQuery("_get_script_name", "", "python", True)
            if t.test("Getting a list of python script names", x and isinstance(x, list), "Got '%s'" % x):
                if t.test_eq("Confirming that results in long form have two elements", len(x[0]), 2):
                    t.test("The names are: %s" % [a[0] for a in x])
                    t.test("Checking our entry", x[my_pos][0] == my_name and x[my_pos][1] == vh.path, x)

            x = vh.ScriptQuery("_get_script_version", "", "", True)
            if t.test("Getting a list of python script versions", x and isinstance(x, list), "Got '%s'" % x):
                if t.test_eq("Confirming that results in long form have two elements", len(x[0]), 2):
                    t.test("The versions are: %s" % [a[0] for a in x])
                    t.test("Checking our entry", x[my_pos][0] == my_version and x[my_pos][1] == vh.path, x)
        else:
            t.test("Aborting this branch", False)
    else:
        t.test("Aborting this branch", False)

    x = vh.ScriptQuery("_get_script_file", "", vh.path)
    t.test_eq("Asking for our path directly", x, [vh.path])
    x = vh.ScriptQuery("_get_script_name", "", vh.path)
    t.test_eq("Asking for our name directly", x, [my_name])
    x = vh.ScriptQuery("_get_script_version", "", vh.path)
    t.test_eq("Asking for our version directly", x, [my_version])


    t.test("")
    t.test("Testing vh.ScriptQuery and vh.ScriptCommand for communication with scripts...")
    scripts = vh.ScriptQuery("_get_script_name", "", "python", True)
    for entry in scripts:
        if entry[0] == event_logger_name:
            script = entry[1]
            t.test("Found %s in %s" % (event_logger_name, script))
            if t.test_eq("Turning on logging", vh.ScriptQuery(event_logger_cmd, "1", script), ["is_on"]):
                t.test("Now you should start seeing output from %s" % event_logger_name)
                t.test_eq("Confirming that logging is active", vh.ScriptQuery(event_logger_cmd, "", script), ["is_on"])
                t.test_eq("Calling logger with sh2p43g cmd", vh.ScriptQuery("sh2p43g", "data", script), [])
                t.test_eq("Calling python with jm5f03c cmd", vh.ScriptQuery("jm5f03c", "data", "python"), [])
                t.test_eq("Calling all with pf6j76q cmd", vh.ScriptQuery("pf6j76q", "data"), [])
                t.test("Using ScriptCommand('wn3f98g', 'data')", vh.ScriptCommand("wn3f98g", "data"))
                t.test_eq("Turning off logging", vh.ScriptQuery(event_logger_cmd, "0", script), ["is_off"])


    return t.finish_testing(0)
示例#2
0
#!/usr/bin/python
#
# VH Event Logger - an example script for the Verlihub Python plugin
# Copyright (C) 2016 Verlihub Team, info at verlihub dot net
# Created in 2007 by Frog (frogged), the_frog at wp dot pl
# License: GNU General Public License v.3, see http://www.gnu.org/licenses/
# Last update: 2016-03-03
#
# This script prints all received hub events to stdout
# To turn on logging, use the !vh_event_log 1 admin command, and to turn off, !vh_event_log 0.
# You can also turn it on from another script using the vh_event_log script query.

import vh
import sys

vh.name_and_version("VH Event Logger", "1.1.0")

my_command = "vh_event_log"

messages = {
    "is_on": "Event logging is now active. ",
    "is_off": "Event logging is now disabled. ",
    "already_on": "Event logging was already active. ",
    "already_off": "Event logging was not active. ",
    "error": "Bad command argument. Should be 1 (to turn logging on), 0 (to turn it off), or nothing (to get status). ",
}

_log = 0


def log():
示例#3
0
#!/usr/bin/python
#
# VH Event Logger - an example script for the Verlihub Python plugin
# Copyright (C) 2016 Verlihub Team, info at verlihub dot net
# Created in 2007 by Frog (frogged), the_frog at wp dot pl
# License: GNU General Public License v.3, see http://www.gnu.org/licenses/
# Last update: 2016-03-03
#
# This script prints all received hub events to stdout
# To turn on logging, use the !vh_event_log 1 admin command, and to turn off, !vh_event_log 0.
# You can also turn it on from another script using the vh_event_log script query.

import vh
import sys

vh.name_and_version("VH Event Logger", "1.1.0")

my_command = "vh_event_log"

messages = {
    "is_on": "Event logging is now active. ",
    "is_off": "Event logging is now disabled. ",
    "already_on": "Event logging was already active. ",
    "already_off": "Event logging was not active. ",
    "error": "Bad command argument. Should be 1 (to turn logging on), 0 (to turn it off), or nothing (to get status). "
}

_log = 0

def log():
    global _log
示例#4
0
def my_test():
    global tester
    t = tester
    if not t.test_is_active:
        return

    t.test("It's now %s. Hub has been running for %s seconds" % (datetime.now(), int(time.time() - vh.starttime)))
    t.test("Script: %s (%s), Python plugin ver. %s / %s" % (vh.name, vh.path, vh.__version__, vh.__version_string__))
    
    t1 = t.test("Checking vh.botname and vh.opchatname values", vh.botname == "Verlihub" and vh.opchatname == "OpChat",
        "They are: '%s' and '%s'" % (vh.botname, vh.opchatname))
    t2 = t.test_eq("Confirming that hublist_host is empty", vh.GetConfig("config", "hublist_host"), "")
    t3 = t.test_eq("Confirming that send_crash_report is 0", vh.GetConfig("config", "send_crash_report"), "0")
    t4 = t.test_eq("Checking usercount", vh.GetUsersCount(), 0)
    if not (t1 and t2 and t3 and t4):
        t.test("Cannot continue testing with these errors", 0)
        return t.finish_testing(1)


    t.test("Trying to set vh.name_and_version", vh.name_and_version(my_name, my_version))
    x = vh.name_and_version()
    t.test("Reading and verifying vh.name_and_version", x and x[0] == my_name and x[1] == my_version, x)

    t.test("Checking nicklists...")
    x = vh.GetRawNickList()
    t.test("Checking vh.GetRawNickList", "Verlihub$$" in x and "OpChat$$" in x and x.startswith("$NickList "), x)
    x = vh.GetRawOpList()
    t.test("Checking vh.GetRawOpList", "Verlihub$$" in x and "OpChat$$" in x and x.startswith("$OpList "), x)
    x = vh.GetRawBotList()
    t.test("Checking vh.GetRawBotList", "Verlihub$$" in x and "OpChat$$" in x and x.startswith("$BotList "), x)

    x = vh.GetNickList()
    t.test("Checking vh.GetNickList", "Verlihub" in x and "OpChat" in x and isinstance(x, list), x)
    x = vh.GetOpList()
    t.test("Checking vh.GetOpList", "Verlihub" in x and "OpChat" in x and isinstance(x, list), x)
    x = vh.GetBotList()
    t.test("Checking vh.GetBotList", "Verlihub" in x and "OpChat" in x and isinstance(x, list), x)


    t.test("")
    t.test("Testing vh.ScriptQuery and communication between scripts...")
    x = vh.ScriptQuery("_get_script_file", "")
    t.test("Getting a list of scripts", x and isinstance(x, list), "List is empty. Impossible!")
    t.test_in("Confirming that we are on it", vh.path, x)
    t.test("There are %s scripts on the list" % len(x))

    x = vh.ScriptQuery("_get_script_file", "", "python")
    if t.test("Getting a list of python scripts", x and isinstance(x, list), "List is empty. Impossible!"):
        py_len = len(x)
        if t.test_in("Confirming that we are on it", vh.path, x):
            my_pos = x.index(vh.path)
            t.test("The paths are: %s" % x)

            x = vh.ScriptQuery("_get_script_name", "", "python", True)
            if t.test("Getting a list of python script names", x and isinstance(x, list), "Got '%s'" % x):
                if t.test_eq("Confirming that results in long form have two elements", len(x[0]), 2):
                    t.test("The names are: %s" % [a[0] for a in x])
                    t.test("Checking our entry", x[my_pos][0] == my_name and x[my_pos][1] == vh.path, x)

            x = vh.ScriptQuery("_get_script_version", "", "", True)
            if t.test("Getting a list of python script versions", x and isinstance(x, list), "Got '%s'" % x):
                if t.test_eq("Confirming that results in long form have two elements", len(x[0]), 2):
                    t.test("The versions are: %s" % [a[0] for a in x])
                    t.test("Checking our entry", x[my_pos][0] == my_version and x[my_pos][1] == vh.path, x)
        else:
            t.test("Aborting this branch", False)
    else:
        t.test("Aborting this branch", False)

    x = vh.ScriptQuery("_get_script_file", "", vh.path)
    t.test_eq("Asking for our path directly", x, [vh.path])
    x = vh.ScriptQuery("_get_script_name", "", vh.path)
    t.test_eq("Asking for our name directly", x, [my_name])
    x = vh.ScriptQuery("_get_script_version", "", vh.path)
    t.test_eq("Asking for our version directly", x, [my_version])


    t.test("")
    t.test("Testing vh.ScriptQuery and vh.ScriptCommand for communication with scripts...")
    scripts = vh.ScriptQuery("_get_script_name", "", "python", True)
    for entry in scripts:
        if entry[0] == event_logger_name:
            script = entry[1]
            t.test("Found %s in %s" % (event_logger_name, script))
            if t.test_eq("Turning on logging", vh.ScriptQuery(event_logger_cmd, "1", script), ["is_on"]):
                t.test("Now you should start seeing output from %s" % event_logger_name)
                t.test_eq("Confirming that logging is active", vh.ScriptQuery(event_logger_cmd, "", script), ["is_on"])
                t.test_eq("Calling logger with sh2p43g cmd", vh.ScriptQuery("sh2p43g", "data", script), [])
                t.test_eq("Calling python with jm5f03c cmd", vh.ScriptQuery("jm5f03c", "data", "python"), [])
                t.test_eq("Calling all with pf6j76q cmd", vh.ScriptQuery("pf6j76q", "data"), [])
                t.test("Using ScriptCommand('wn3f98g', 'data')", vh.ScriptCommand("wn3f98g", "data"))
                t.test_eq("Turning off logging", vh.ScriptQuery(event_logger_cmd, "0", script), ["is_off"])


    return t.finish_testing(0)