Example #1
0
async def remind(text, nick, chan, db, conn, event, async_call):
    """<1 minute, 30 seconds>: <do task> - reminds you to <do task> in <1 minute, 30 seconds>"""

    count = len([
        x for x in reminder_cache
        if x[0] == conn.name and x[3] == nick.lower()
    ])

    if text == "clear":
        if count == 0:
            return "You have no reminders to delete."

        await delete_all(async_call, db, conn.name, nick)
        await load_cache(async_call, db)
        return "Deleted all ({}) reminders for {}!".format(count, nick)

    # split the input on the first ":"
    parts = text.split(":", 1)

    if len(parts) == 1:
        # user didn't add a message, send them help
        event.notice_doc()
        return

    if count > 10:
        return "Sorry, you already have too many reminders queued (10), you will need to wait or " \
               "clear your reminders to add any more."

    time_string = parts[0].strip()
    message = colors.strip_all(parts[1].strip())

    # get the current time in both DateTime and Unix Epoch
    current_epoch = time.time()
    current_time = datetime.fromtimestamp(current_epoch)

    # parse the time input, return error if invalid
    seconds = time_parse(time_string)
    if not seconds:
        return "Invalid input."

    if seconds > 2764800 or seconds < 60:
        return "Sorry, remind input must be more than a minute, and less than one month."

    # work out the time to remind the user, and check if that time is in the past
    remind_time = datetime.fromtimestamp(current_epoch + seconds)
    if remind_time < current_time:  # pragma: no cover
        # This should technically be unreachable because of the previous checks
        return "I can't remind you in the past!"

    # finally, add the reminder and send a confirmation message
    await add_reminder(async_call, db, conn.name, nick, chan, message,
                       remind_time, current_time)
    await load_cache(async_call, db)

    remind_text = format_time(seconds, count=2)
    output = "Alright, I'll remind you \"{}\" in $(b){}$(clear)!".format(
        message, remind_text)

    return colors.parse(output)
def remind(text, nick, chan, db, conn, notice, async):
    """<1m30s>: <do task> -- reminds you to <do task> in <1 minute, 30 seconds>.If no colon is given, only the first word will be used to determine the time.
    """

    count = len([x for x in reminder_cache if x[0] == conn.name and x[4].lower() == nick.lower()])

    if text == "clear":
        if count == 0:
            return "You have no reminders to delete."

        yield from delete_all(async, db, conn.name, nick)
        yield from load_cache(async, db)
        return "Deleted all ({}) reminders for {}!".format(count, nick)

    if ":" in text:
        # split the input on the first ":"
        parts = text.split(":", 1)
    else:
        # take only the first word for the time value otherwise
        parts = text.split(" ", 1)

    if len(parts) == 1:
        # user didn't add a message, send them help
        notice(remind.__doc__)
        return

    if count > 10:
        notice("Sorry, you already have too many reminders queued (10), you will need to wait or clear your reminders to add any more")
        return

    time_string = parts[0].strip()
    message = colors.strip_all(parts[1].strip())

    # get the current time in both DateTime and Unix Epoch
    current_epoch = time.time()
    current_time = datetime.fromtimestamp(current_epoch)

    # parse the time input, return error if invalid
    seconds = time_parse(time_string)
    if not seconds:
        notice("Invalid time. Try something like '2m30s', '2 days 3 hours:', or '1:30s'")
        return

    if seconds > 2764800 or seconds < 60:
        return "Sorry, remind input must be more than a minute, and less than one month"

    # work out the time to remind the user, and check if that time is in the past
    remind_time = datetime.fromtimestamp(current_epoch + seconds)
    if remind_time < current_time:
        return "I can't remind you in the past!"

    # finally, add the reminder and send a confirmation message
    yield from add_reminder(async, db, conn.name, nick, chan, message, remind_time, current_time)
    yield from load_cache(async, db)

    remind_text = format_time(seconds, count=2)
    output = "Alright, I'll remind you \"{}\" in $(b){}$(clear)!".format(message, remind_text)
    notice(colors.parse(output))
Example #3
0
def remind(text, nick, chan, db, conn, notice, async):
    """<1 minute, 30 seconds>: <do task> -- reminds you to <do task> in <1 minute, 30 seconds>"""

    count = len([x for x in reminder_cache if x[0] == conn.name and x[3] == nick.lower()])

    if text == "clear":
        if count == 0:
            return "You have no reminders to delete."

        yield from delete_all(async, db, conn.name, nick)
        yield from load_cache(async, db)
        return "Deleted all ({}) reminders for {}!".format(count, nick)

    # split the input on the first ":"
    parts = text.split(":", 1)

    if len(parts) == 1:
        # user didn't add a message, send them help
        notice(remind.__doc__)
        return

    if count > 10:
        return (
            "Sorry, you already have too many reminders queued (10), you will need to wait or "
            "clear your reminders to add any more."
        )

    time_string = parts[0].strip()
    message = colors.strip_all(parts[1].strip())

    # get the current time in both DateTime and Unix Epoch
    current_epoch = time.time()
    current_time = datetime.fromtimestamp(current_epoch)

    # parse the time input, return error if invalid
    seconds = time_parse(time_string)
    if not seconds:
        return "Invalid input."

    if seconds > 2764800 or seconds < 60:
        return "Sorry, remind input must be more then a minute, and less then one month."

    # work out the time to remind the user, and check if that time is in the past
    remind_time = datetime.fromtimestamp(current_epoch + seconds)
    if remind_time < current_time:
        return "I can't remind you in the past!"

    # finally, add the reminder and send a confirmation message
    yield from add_reminder(async, db, conn.name, nick, chan, message, remind_time, current_time)
    yield from load_cache(async, db)

    remind_text = format_time(seconds, count=2)
    output = 'Alright, I\'ll remind you "{}" in $(b){}$(clear)!'.format(message, remind_text)

    return colors.parse(output)
Example #4
0
def bungeesec(reply, text, nick, notice):
    if getTokens(nick) < 15000:
        notice(
            "You don't have enough tokens to do a bungeesecure (15000 needed)... Help a little more !"
        )
        return None

    if not text:
        reply("Please specify an IP address/ dns ! !bungeesecure IP")

    takeTokens(2000, nick, notice)
    IP = text
    timeout = float((float(pingavg(IP)) / 100) + 0.1)
    socket.setdefaulttimeout(timeout)
    notice("I'm scanning with a timeout of " + str(timeout))
    reply("Scanning ports... Please wait a moment !")
    toreply = "List of minecraft servers found for : " + str(IP) + ":\n"

    start = 20000
    end = 40000

    scan = Scanner()
    scan.open = []
    scan.host = IP
    scan.ports = list(range(start, end))

    serversPorts = scan.start()
    others = []

    for port in serversPorts:
        mcinf = pingmc(IP, port)
        if mcinf:
            toreply += "Server found on port " + str(port) + " : " + str(
                mcinf) + "\n"
        else:
            others.append(port)

    if others:
        toreply += "Other(s) open ports found, but that don't seems to have a minecraft server on them :" + str(
            others)

    if len(serversPorts) == 0:
        toreply += "No servers found. Check the entered IP address."

    if len(serversPorts) < 5:
        return toreply
    else:
        return web.paste(
            strip_all(toreply).encode("latin-1", errors='replace'))
Example #5
0
def bungeesec(reply, text, nick, notice):
    if getTokens(nick) < 15000:
        notice("You don't have enough tokens to do a bungeesecure (15000 needed)... Help a little more !")
        return None

    if not text:
        reply("Please specify an IP address/ dns ! !bungeesecure IP")

    takeTokens(2000, nick, notice)
    IP = text
    timeout = float((float(pingavg(IP)) / 100) + 0.1)
    socket.setdefaulttimeout(timeout)
    notice("I'm scanning with a timeout of " + str(timeout))
    reply("Scanning ports... Please wait a moment !")
    toreply = "List of minecraft servers found for : " + str(IP) + ":\n"


    start = 20000
    end = 40000

    scan = Scanner()
    scan.open = []
    scan.host = IP
    scan.ports = list(range(start, end))

    serversPorts = scan.start()
    others = []

    for port in serversPorts:
        mcinf = pingmc(IP, port)
        if mcinf:
            toreply += "Server found on port " + str(port) + " : " + str(mcinf) + "\n"
        else:
            others.append(port)

    if others:
        toreply += "Other(s) open ports found, but that don't seems to have a minecraft server on them :" + str(others)



    if len(serversPorts) == 0:
        toreply += "No servers found. Check the entered IP address."

    if len(serversPorts) < 5:
        return toreply
    else:
        return web.paste(strip_all(toreply).encode("latin-1",errors='replace'))
Example #6
0
def test_strip():
    assert strip(test_input) == test_strip_output
    assert strip_irc(test_strip_irc_input) == test_strip_irc_result
    assert strip_all(test_strip_irc_input) == test_strip_all_result
Example #7
0
def test_strip():
    assert strip(test_input) == test_strip_output
    assert strip_irc(test_strip_irc_input) == test_strip_irc_result
    assert strip_all(test_strip_irc_input) == test_strip_all_result
Example #8
0
def remind(text, nick, chan, db, conn, notice, async):
    """<1m30s>: <do task> -- reminds you to <do task> in <1 minute, 30 seconds>.If no colon is given, only the first word will be used to determine the time.
    """

    count = len([
        x for x in reminder_cache
        if x[0] == conn.name and x[4].lower() == nick.lower()
    ])

    if text == "clear":
        if count == 0:
            return "You have no reminders to delete."

        yield from delete_all(async, db, conn.name, nick)
        yield from load_cache(async, db)
        return "Deleted all ({}) reminders for {}!".format(count, nick)

    if ":" in text:
        # split the input on the first ":"
        parts = text.split(":", 1)
    else:
        # take only the first word for the time value otherwise
        parts = text.split(" ", 1)

    if len(parts) == 1:
        # user didn't add a message, send them help
        notice(remind.__doc__)
        return

    if count > 10:
        notice(
            "Sorry, you already have too many reminders queued (10), you will need to wait or clear your reminders to add any more"
        )
        return

    time_string = parts[0].strip()
    message = colors.strip_all(parts[1].strip())

    # get the current time in both DateTime and Unix Epoch
    current_epoch = time.time()
    current_time = datetime.fromtimestamp(current_epoch)

    # parse the time input, return error if invalid
    seconds = time_parse(time_string)
    if not seconds:
        notice(
            "Invalid time. Try something like '2m30s', '2 days 3 hours:', or '1:30s'"
        )
        return

    if seconds > 2764800 or seconds < 60:
        return "Sorry, remind input must be more than a minute, and less than one month"

    # work out the time to remind the user, and check if that time is in the past
    remind_time = datetime.fromtimestamp(current_epoch + seconds)
    if remind_time < current_time:
        return "I can't remind you in the past!"

    # finally, add the reminder and send a confirmation message
    yield from add_reminder(async, db, conn.name, nick, chan, message,
                            remind_time, current_time)
    yield from load_cache(async, db)

    remind_text = format_time(seconds, count=2)
    output = "Alright, I'll remind you \"{}\" in $(b){}$(clear)!".format(
        message, remind_text)
    notice(colors.parse(output))