Ejemplo n.º 1
0
    else:
        if server.persistent_data.get("messages.%s.autoremove" % user):
            display_event = irc.Irc_event("PRIVMSG", user,
                                          "You set autoremove to \"on\".")
            server.send_event(display_event)
        else:
            display_event = irc.Irc_event("PRIVMSG", user,
                                          "You set autoremove to \"off\".")
            server.send_event(display_event)


@plugin_manager.event_handler("JOIN")
def on_join(event, server):
    """Handle JOIN events."""

    # There are unseen messages
    if server.persistent_data.get("messages.%s.unseen" % event.name):
        # Notify user
        unseen_messages_event = irc.Irc_event("PRIVMSG", event.name,
                                              "You have unseen messages.")
        server.send_event(unseen_messages_event)


shared_data.set("help.msg", "Send a message to a user that is afk or offline.")
shared_data.set("help.cm", "Check your inbox.")
shared_data.set("help.rm",
                "Remove message at index; use rm all to remove all messages.")
shared_data.set(
    "help.autoremove",
    "Remove messages as soon as you've seen them. Valid options: on, off")
Ejemplo n.º 2
0
            irc.Irc_event("PRIVMSG", channel, "Started watching %s" % user))

    else:
        server.send_event(
            irc.Irc_event(
                "PRIVMSG", channel,
                "Usage: )gh_add <user> to start watching a user on github"))


@plugin_manager.command("gh_del")
def gh_del_cmd(command, server):
    """Execute the )gh_del command."""

    channel = command.event.args[0]

    if len(command.args) == 1:
        user = command.args[0]
        server.persistent_data.set("gh.%s.targets.%s" % (channel, user), None)
        server.send_event(
            irc.Irc_event("PRIVMSG", channel, "Stopped watching %s" % user))

    else:
        server.send_event(
            irc.Irc_event(
                "PRIVMSG", channel,
                "Usage: )gh_del <user> to stop watching a user on github"))


shared_data.set("help.gh_add", "Start watching a user on github")
shared_data.set("help.gh_del", "Stop watching a user on github")
Ejemplo n.º 3
0
@plugin_manager.command("roll")
def roll_command(command, server):
    """Execute the )roll command."""

    channel = command.event.args[0] if not command.event.args[
        0] == server.nick else command.event.name

    # Roll a number within the given range
    if len(command.args) > 0:
        for arg in command.args:
            if not arg == "":
                try:
                    number = random.randint(0, int(arg))
                    roll_event = irc.Irc_event(
                        "PRIVMSG", channel, "You rolled %d." % number)
                    server.send_event(roll_event)

                except ValueError:
                    error_event = irc.Irc_event(
                        "PRIVMSG", channel, "%s is no valid number." % arg)
                    server.send_event(error_event)

    # Roll a number from 0 trough 1
    else:
        number = random.random()
        roll_event = irc.Irc_event(
            "PRIVMSG", channel, "You rolled %f." % number)
        server.send_event(roll_event)

shared_data.set("help.roll", "Roll a random number.")
Ejemplo n.º 4
0
from pybot import plugin_manager, shared_data, irc


@plugin_manager.command("help")
def help_command(command, server):
    """Execute the )help command."""

    channel = command.event.args[0] if not command.event.args[
        0] == server.nick else command.event.name
    help_data = shared_data.get("help")

    if help_data:
        # Display all available topics
        if len(command.args) == 0:
            if len(help_data.keys()) > 0:
                help_message = "Available topics: %s" % ", ".join(
                    help_data.keys())
                help_event = irc.Irc_event("PRIVMSG", channel, help_message)
                server.send_event(help_event)

        # Display help for the topics
        else:
            for topic in command.args:
                if topic in help_data:
                    topic_event = irc.Irc_event(
                        "PRIVMSG", channel, "%s: %s" % (topic, help_data[topic]))
                    server.send_event(topic_event)

shared_data.set("help.help", "Display information about a topic.")
Ejemplo n.º 5
0
        # Already set etag and last_id, so the channel isn't spammend with 30
        # updates on the next query
        server.persistent_data.set("gh.%s.targets.%s" % (channel, user), {
            "etag": etag,
            "last_id": last_id
            })
        server.send_event(irc.Irc_event("PRIVMSG", channel, "Started watching %s" % user))

    else:
        server.send_event(irc.Irc_event("PRIVMSG", channel, "Usage: )gh_add <user> to start watching a user on github"))


@plugin_manager.command("gh_del")
def gh_del_cmd(command, server):
    """Execute the )gh_del command."""

    channel = command.event.args[0]

    if len(command.args) == 1:
        user = command.args[0]
        server.persistent_data.set("gh.%s.targets.%s" % (channel, user), None)
        server.send_event(irc.Irc_event("PRIVMSG", channel, "Stopped watching %s" % user))

    else:
        server.send_event(irc.Irc_event("PRIVMSG", channel, "Usage: )gh_del <user> to stop watching a user on github"))


shared_data.set("help.gh_add", "Start watching a user on github")
shared_data.set("help.gh_del", "Stop watching a user on github")
Ejemplo n.º 6
0
    is_marked = server.shared_data.get(
        "afk.%s.bool" % event.name) or server.shared_data.get("afk.%s.probably" % event.name)

    if is_marked:
        undo_afk(server, event.name)

        # Notify that user is back
        back_event = irc.Irc_event(
            "PRIVMSG", event.args[0], "%s is back." % event.name)
        server.send_event(back_event)


def afk_token(event, server):
    channel = server.user_data.get_channel(event.args[0])
    afk_nicks = []

    for user in channel.users:
        if server.shared_data.get("afk.%s.bool" % user.nick):
            afk_nicks.append(user.nick)
        if server.shared_data.get("afk.%s.probably" % user.nick):
            afk_nicks.append("~" + user.nick)

    return ", ".join(afk_nicks)

shared_data.set("help.afk", "Mark your self as afk. You can add a message.")
shared_data.set(
    "help.afkPropose", "Mark somebody else as probably afk. You can add a message.")
shared_data.set("help.status", "Get the status of a user.")

shared_data.set("greeter.tokens.afk", afk_token)
Ejemplo n.º 7
0

@plugin_manager.command("help")
def help_command(command, server):
    """Execute the )help command."""

    channel = command.event.args[
        0] if not command.event.args[0] == server.nick else command.event.name
    help_data = shared_data.get("help")

    if help_data:
        # Display all available topics
        if len(command.args) == 0:
            if len(help_data.keys()) > 0:
                help_message = "Available topics: %s" % ", ".join(
                    help_data.keys())
                help_event = irc.Irc_event("PRIVMSG", channel, help_message)
                server.send_event(help_event)

        # Display help for the topics
        else:
            for topic in command.args:
                if topic in help_data:
                    topic_event = irc.Irc_event(
                        "PRIVMSG", channel,
                        "%s: %s" % (topic, help_data[topic]))
                    server.send_event(topic_event)


shared_data.set("help.help", "Display information about a topic.")
Ejemplo n.º 8
0
    # Display the autoremove option
    else:
        if server.persistent_data.get("messages.%s.autoremove" % user):
            display_event = irc.Irc_event(
                "PRIVMSG", user, "You set autoremove to \"on\".")
            server.send_event(display_event)
        else:
            display_event = irc.Irc_event(
                "PRIVMSG", user, "You set autoremove to \"off\".")
            server.send_event(display_event)


@plugin_manager.event_handler("JOIN")
def on_join(event, server):
    """Handle JOIN events."""

    # There are unseen messages
    if server.persistent_data.get("messages.%s.unseen" % event.name):
        # Notify user
        unseen_messages_event = irc.Irc_event(
            "PRIVMSG", event.name, "You have unseen messages.")
        server.send_event(unseen_messages_event)

shared_data.set("help.msg", "Send a message to a user that is afk or offline.")
shared_data.set("help.cm", "Check your inbox.")
shared_data.set(
    "help.rm", "Remove message at index; use rm all to remove all messages.")
shared_data.set("help.autoremove",
                "Remove messages as soon as you've seen them. Valid options: on, off")
Ejemplo n.º 9
0
@plugin_manager.command("tokens")
def tokens_command(command, server):
    """Execute the )tokens command."""

    channel = command.event.args[0] if not command.event.args[
        0] == server.nick else command.event.name

    if shared_data.get("greeter.tokens"):
        tokens = shared_data.get("greeter.tokens")
        tokens_list = ", ".join(tokens.keys())

        tokens_event = irc.Irc_event(
            "PRIVMSG", channel, "Available tokens: %s" % tokens_list)
        server.send_event(tokens_event)

    else:
        no_tokens_event = irc.Irc_event(
            "PRIVMSG", channel, "No tokens available.")
        server.send_event(no_tokens_event)


def channel_token(event, server):
    return event.args[0]

shared_data.set("help.welcomemsg", "Change the bots greeting.")
shared_data.set(
    "help.tokens", "List all tokens available for use in welcome messages.")

shared_data.set("greeter.tokens.channel", channel_token)
Ejemplo n.º 10
0
def roll_command(command, server):
    """Execute the )roll command."""

    channel = command.event.args[
        0] if not command.event.args[0] == server.nick else command.event.name

    # Roll a number within the given range
    if len(command.args) > 0:
        for arg in command.args:
            if not arg == "":
                try:
                    number = random.randint(0, int(arg))
                    roll_event = irc.Irc_event("PRIVMSG", channel,
                                               "You rolled %d." % number)
                    server.send_event(roll_event)

                except ValueError:
                    error_event = irc.Irc_event("PRIVMSG", channel,
                                                "%s is no valid number." % arg)
                    server.send_event(error_event)

    # Roll a number from 0 trough 1
    else:
        number = random.random()
        roll_event = irc.Irc_event("PRIVMSG", channel,
                                   "You rolled %f." % number)
        server.send_event(roll_event)


shared_data.set("help.roll", "Roll a random number.")