Ejemplo n.º 1
0
def link(ctx, account, network):
    """
    Link account.

    Link your account to another network. This account will then become the
    primary account, and the other account made an alias of the account
    requesting linkage.
    """

    try:
        user_data = yield ctx.lookup_user_data()
    except UserData.DoesNotExist:
        ctx.respond(
            ctx._("Please log in to NickServ before linking an account."))
        return

    try:
        alt_client, *_ = [
            client for client in ctx.bot.clients.values()
            if client.network == network
        ]
    except ValueError:
        ctx.respond(ctx._("I can't find that network."))
        return

    alt_user_data = yield UserData.lookup_default(alt_client, account)

    if user_data.account == alt_user_data.account and \
       user_data.network == alt_user_data.network:
        ctx.respond(ctx._("You can't link your account to itself."))
        return

    if "_alias" in alt_user_data:
        ctx.respond(ctx._("You can't link your account to an alias."))
        return

    ctx.respond(
        ctx.
        _("Okay, please message me \"!confirmlink {account} {network}\" on that network."
          ).format(account=ctx.origin, network=ctx.client.network))

    yield wait_for_confirmation(ctx.storage, ctx.origin, ctx.client.network,
                                account, network)

    data = dict(alt_user_data)
    data.update(user_data)
    user_data.update(data)
    user_data.save()

    alt_user_data.clear()
    alt_user_data["_alias"] = {
        "account": user_data.account,
        "network": user_data.network
    }
    alt_user_data.save()

    ctx.respond(
        ctx.
        _("Your account has been successfully linked with {account} on {network}."
          ).format(account=account, network=network))
Ejemplo n.º 2
0
def link(ctx, account, network):
    """
    Link account.

    Link your account to another network. This account will then become the
    primary account, and the other account made an alias of the account
    requesting linkage.
    """

    try:
        user_data = yield ctx.lookup_user_data()
    except UserData.DoesNotExist:
        ctx.respond(ctx._("Please log in to NickServ before linking an account."))
        return

    try:
        alt_client, *_ = [client for client in ctx.bot.clients.values()
                          if client.network == network]
    except ValueError:
        ctx.respond(ctx._("I can't find that network."))
        return

    alt_user_data = yield UserData.lookup_default(alt_client, account)

    if user_data.account == alt_user_data.account and \
       user_data.network == alt_user_data.network:
        ctx.respond(ctx._("You can't link your account to itself."))
        return

    if "_alias" in alt_user_data:
        ctx.respond(ctx._("You can't link your account to an alias."))
        return

    ctx.respond(ctx._("Okay, please message me \"!confirmlink {account} {network}\" on that network.").format(
        account=ctx.origin,
        network=ctx.client.network
    ))

    yield wait_for_confirmation(ctx.storage, ctx.origin, ctx.client.network,
                                account, network)

    data = dict(alt_user_data)
    data.update(user_data)
    user_data.update(data)
    user_data.save()

    alt_user_data.clear()
    alt_user_data["_alias"] = {
        "account": user_data.account,
        "network": user_data.network
    }
    alt_user_data.save()

    ctx.respond(ctx._("Your account has been successfully linked with {account} on {network}.").format(
        account=account,
        network=network
    ))
Ejemplo n.º 3
0
def get_karma(ctx, who):
    """
    Get karma.

    Get the amount of karma for a user.
    """

    user_data = yield UserData.lookup_default(ctx.client, who)
    karma = user_data.get("karma", 0)

    ctx.respond(ctx._("{who} has {n} karma.").format(who=who, n=karma))
Ejemplo n.º 4
0
def get_karma(ctx, who):
    """
    Get karma.

    Get the amount of karma for a user.
    """

    user_data = yield UserData.lookup_default(ctx.client, who)
    karma = user_data.get("karma", 0)

    ctx.respond(ctx._("{who} has {n} karma.").format(
        who=who,
        n=karma
    ))
Ejemplo n.º 5
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.º 6
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.º 7
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.º 8
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.º 9
0
def get_profile(ctx, who=None):
    """
    Get profile.

    Retrieve profile text for a user.
    """
    if who is None:
        who = ctx.origin

    user_data = yield UserData.lookup_default(ctx.client, who)

    if "profile" not in user_data:
        ctx.respond(ctx._("{who} hasn't told me who they are yet.").format(
            who=who
        ))
        return

    ctx.respond(ctx._("{who} is {text}").format(
        who=who,
        text=user_data["profile"]
    ))
Ejemplo n.º 10
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.º 11
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.º 12
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.º 13
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.º 14
0
def get_lfm_username(client, who):
    user_data = yield UserData.lookup_default(client, who)
    return user_data.get("lastfm_user", who)
Ejemplo n.º 15
0
def get_lfm_username(client, who):
    user_data = yield UserData.lookup_default(client, who)
    return user_data.get("lastfm_user", who)