Ejemplo n.º 1
0
def remember_profile(ctx, text):
    """
    Remember profile.

    Associate the given profile text with the user.
    """

    try:
        user_data = yield UserData.lookup(ctx.client, ctx.origin)
    except UserData.DoesNotExist:
        ctx.respond(ctx._("Please authenticate before you add a profile."))
        return

    user_data["profile"] = text
    user_data.save()

    ctx.respond(ctx._("Okay, I'll remember you."))
Ejemplo n.º 2
0
def setup_user(ctx, lfm_username):
    """
    Set username.

    Associate a Last.fm username with your nickname.
    """

    try:
        user_data = yield UserData.lookup(ctx.client, ctx.origin)
    except UserData.DoesNotExist:
        ctx.respond(ctx._("You must be logged in to set your Last.fm username."))
        return

    user_data["lastfm_user"] = lfm_username
    user_data.save()

    ctx.respond(ctx._("You have been associated with the Last.fm username {user}.").format(user=lfm_username))
Ejemplo n.º 3
0
def check_user(ctx):
    """
    Now playing.

    Get the currently playing song for a user.
    """

    try:
        user_data = yield UserData.lookup(ctx.client, ctx.origin)
    except UserData.DoesNotExist:
        ctx.respond(ctx._("You must be logged in to set your Last.fm username."))
        return

    if "lastfm_user" not in user_data:
        ctx.respond(ctx._("You don't have a Last.fm username associated with your nickname. Please use \"!lfm\" to associate one."))
        return

    ctx.respond(ctx._("Your nickname is associated with {user}.").format(user=user_data["lastfm_user"]))
Ejemplo n.º 4
0
def setup_user(ctx, lfm_username):
    """
    Set username.

    Associate a Last.fm username with your nickname.
    """

    try:
        user_data = yield UserData.lookup(ctx.client, ctx.origin)
    except UserData.DoesNotExist:
        ctx.respond(
            ctx._("You must be logged in to set your Last.fm username."))
        return

    user_data["lastfm_user"] = lfm_username
    user_data.save()

    ctx.respond(
        ctx._("You have been associated with the Last.fm username {user}.").
        format(user=lfm_username))
Ejemplo n.º 5
0
def forget_profile(ctx):
    """
    Forget profile.

    Remove the given profile text from the user.
    """

    try:
        user_data = yield UserData.lookup(ctx.client, ctx.origin)
    except UserData.DoesNotExist:
        exists = False
    else:
        exists = "profile" in user_data

    if not exists:
        ctx.respond(ctx._("I don't know who you are."))
        return

    del user_data["profile"]
    user_data.save()

    ctx.respond(ctx._("Okay, I won't remember you anymore."))
Ejemplo n.º 6
0
def add_karma(ctx, who):
    """
    Add karma.

    Increment a user's karma.
    """

    now = datetime.utcnow()

    if ctx.client.normalize(ctx.origin) == ctx.client.normalize(who):
        ctx.respond(ctx._("You can't give yourself karma."))
        return

    last_grant = ctx.storage.granters.get((ctx.origin, ctx.client.network),
                                          datetime.fromtimestamp(0))

    if now - last_grant <= timedelta(seconds=ctx.config.timeout):
        ctx.respond(ctx._("Please wait a while before granting someone karma."))
        return

    try:
        user_data = yield UserData.lookup(ctx.client, who)
    except UserData.DoesNotExist:
        ctx.respond(ctx._("{who}'s account is not registered.").format(
            who=who
        ))
        return

    user_data.setdefault("karma", 0)
    user_data["karma"] += 1
    user_data.save()

    ctx.storage.granters[ctx.origin, ctx.client.network] = now

    ctx.respond(ctx._("{who} now has {n} karma.").format(
        who=who,
        n=user_data["karma"]
    ))
Ejemplo n.º 7
0
def add_karma(ctx, who):
    """
    Add karma.

    Increment a user's karma.
    """

    now = datetime.utcnow()

    if ctx.client.normalize(ctx.origin) == ctx.client.normalize(who):
        ctx.respond(ctx._("You can't give yourself karma."))
        return

    last_grant = ctx.storage.granters.get((ctx.origin, ctx.client.network),
                                          datetime.fromtimestamp(0))

    if now - last_grant <= timedelta(seconds=ctx.config.timeout):
        ctx.respond(
            ctx._("Please wait a while before granting someone karma."))
        return

    try:
        user_data = yield UserData.lookup(ctx.client, who)
    except UserData.DoesNotExist:
        ctx.respond(
            ctx._("{who}'s account is not registered.").format(who=who))
        return

    user_data.setdefault("karma", 0)
    user_data["karma"] += 1
    user_data.save()

    ctx.storage.granters[ctx.origin, ctx.client.network] = now

    ctx.respond(
        ctx._("{who} now has {n} karma.").format(who=who,
                                                 n=user_data["karma"]))
Ejemplo n.º 8
0
def check_user(ctx):
    """
    Now playing.

    Get the currently playing song for a user.
    """

    try:
        user_data = yield UserData.lookup(ctx.client, ctx.origin)
    except UserData.DoesNotExist:
        ctx.respond(
            ctx._("You must be logged in to set your Last.fm username."))
        return

    if "lastfm_user" not in user_data:
        ctx.respond(
            ctx.
            _("You don't have a Last.fm username associated with your nickname. Please use \"!lfm\" to associate one."
              ))
        return

    ctx.respond(
        ctx._("Your nickname is associated with {user}.").format(
            user=user_data["lastfm_user"]))