Ejemplo n.º 1
0
async def remove(context, id_name, attribute, *words):
    if attribute not in addable_attributes:
        return

    identity = db.get_user_identity_by_name(context.author, id_name)
    if identity is None:
        return

    lexicon_string = getattr(identity, attribute)
    lexicon = string_to_lexicon(lexicon_string)

    for word in words:
        logger.debug(f"removing {word} from {lexicon}")
        try:
            lexicon.remove(word)
        except:
            logger.info(
                f"Couldn't remove {word} from {lexicon}, already not present.")

    modified_lexicon_string = lexicon_to_string(lexicon)

    db.update_identity(identity, attribute, modified_lexicon_string)

    reply = discord.Embed(title="Lexicon successfully updated.")
    reply.add_field(name="New lexicon:",
                    value=modified_lexicon_string.replace(
                        SERIALIZER_DIVIDER, "\n"))
    await context.send(embed=reply)
Ejemplo n.º 2
0
async def add(context, id_name, attribute, *words):
    if attribute not in addable_attributes:
        return

    identity = db.get_user_identity_by_name(context.author, id_name)
    if identity is None:
        return

    original_lexicon_string = getattr(identity, attribute)
    original_lexicon = string_to_lexicon(original_lexicon_string)

    if original_lexicon is None:
        original_lexicon = []

    for entry in words:
        original_lexicon.append(entry)

    modified_lexicon_string = lexicon_to_string(original_lexicon)

    db.update_identity(identity, attribute, modified_lexicon_string)

    reply = discord.Embed(title="Lexicon successfully updated.")
    reply.add_field(name="New lexicon:",
                    value=modified_lexicon_string.replace(
                        SERIALIZER_DIVIDER, "\n"))
    await context.send(embed=reply)
Ejemplo n.º 3
0
async def _set(context, id_name, attribute, *new_values):

    if attribute is None or attribute not in settable_attributes:
        LOGGER.debug(f"Invalid set attribute: {attribute}")
        reply = discord.Embed(
            title="No valid attribute found.",
            description=
            f"Settable attributes are:\n {newline.join(viewable_attributes)}")
        await context.send(embed=reply)
        return

    identity = db.get_user_identity_by_name(context.author, id_name)

    if identity is None:
        await context.send(embed=discord.Embed(
            title="No identity by that name found.",
            description=
            f"You can list identities you own with '{bot.command_prefix}identities'"
        ))
        return

    #Validate display_name
    if attribute == "display_name" and len(new_values[0]) > 80:
        reply = discord.Embed(title="Could not update display name.")
        reply.add_field(name="Maximum length:", value="80")
        reply.add_field(name="Your length:", value=len(attribute))
        await context.send(embed=reply)
        return

    #Validate override_chance
    if attribute == "override_chance" and int(new_values[0]) > 100:
        new_values[0] == 100
    elif attribute == "override_chance" and int(new_values[0]) < 0:
        new_values[0] == 0

    if "lexicon" in attribute:
        update_value = lexicon_to_string(new_values)
    else:
        update_value = new_values[0]

    db.update_identity(identity, attribute, update_value)

    reply = discord.Embed(title=f"{id_name} successfully updated.")
    reply.add_field(name=f"New {attribute}:",
                    value=format_as_written_list(new_values)
                    if len(new_values) > 1 else new_values[0])

    if attribute == "avatar":
        reply.set_thumbnail(url=new_values[0])

    await context.send(embed=reply)
Ejemplo n.º 4
0
def format_as_written_list(input_obj) -> str:
    if type(input_obj) is tuple:
        try:
            input_obj = list(input_obj)
        except:
            return None

    if type(input_obj) is str:
        return input_obj.replace(SERIALIZER_DIVIDER, "\n")

    if type(input_obj) is not list:
        return None

    return lexicon_to_string(input_obj).replace(SERIALIZER_DIVIDER, "\n")
Ejemplo n.º 5
0
async def new(context, id_name=None, id_desc=None, *id_words):

    if db.get_user_identity_by_name(context.author, id_name) is not None:
        await context.send(
            "Sorry, that identity already exists in your inventory.")
        return

    if len(db.get_all_user_identities(context.author)) > 20:
        await context.send(
            "Sorry, you have too many identities. Please delete some.")
        return

    if id_name is None:
        await context.send("No name provided.")
        return

    if len(id_words) == 0:
        lexicon_string = None
    else:
        lexicon_string = lexicon_to_string(id_words)

    new_identity = Identity(name=id_name,
                            user_id=context.author.id,
                            description=id_desc,
                            replacement_lexicon=lexicon_string)

    db.create_identity(new_identity)

    reply = discord.Embed(title="New identity created. 🎉")
    reply.add_field(name="Name:", value=id_name, inline=False)
    reply.add_field(name="Description:", value=id_desc, inline=False)
    reply.add_field(
        name="Replacement words:",
        value=format_as_written_list(id_words) if len(id_words) > 0 else None,
        inline=False)

    await context.send(embed=reply)
    "🐾",
    "🐶‼️",
    "💖",
    "wauf",
    "woof!!",
]

PUPPY = Identity(
    name="Puppy",
    description=
    "Wuff wuff! This is a default identity created by the identity enforcement drone!",
    display_name=None,
    display_name_with_id=None,
    avatar=
    "https://raw.githubusercontent.com/avn-0216-m/identity-enforcement-images/master/puppy.jpeg",
    replacement_lexicon=lexicon_to_string(PUPPY_WORDS),
    allowance_lexicon=None,
    strict=0,
    override_lexicon=None,
    override_chance=0,
    user_id=ENFORCEMENT_DRONE)

KITTEN_WORDS = [
    "meow", "meow!", "mrow", "prrrr", "maiou!!!", ":3", "meww~", "meow~!",
    "prr! prrrr~", "prr prrrrr...", "🐾🐈"
]

KITTEN = Identity(
    name="Kitten",
    description=
    "Meoww~! This is a default identity created by the identity enforcement drone!",