async def view(ctx, url: str = None): masterpass = get_password(ctx.author.id) if url is not None: data = EntryHandler.get(ctx.author.id, url) if data is not None: username, err = await decrypt(data["username"], masterpass) if err: raise EncryptionError(err) password, err = await decrypt(data["password"], masterpass) if err: raise EncryptionError(err) await ctx.send( embed=discord.Embed( title=f":white_check_mark: {url}", colour=discord.Colour.teal(), ).add_field(name="username", value=username, inline=False). add_field(name="password", value=password, inline=False)) else: await ctx.send(f":x: No credentials found for <{url}>") else: # get all entries data = EntryHandler.getall(ctx.author.id) if len(data) > 0: for d in data: username, err = await decrypt(d["username"], masterpass) if err: raise EncryptionError(err) password, err = await decrypt(d["password"], masterpass) if err: raise EncryptionError(err) await ctx.send( embed=discord.Embed( title=f":white_check_mark: {d['url']}", colour=discord.Colour.teal(), ).add_field(name="username", value=username, inline=False). add_field(name="password", value=password, inline=False)) else: await ctx.send(":x: No credentials stored")
async def update(ctx, url: str, username: str, password: str): masterpass = get_password(ctx.author.id) enc_username, err = await encrypt(username, masterpass) if err: raise EncryptionError(err) enc_password, err = await encrypt(password, masterpass) if err: raise EncryptionError(err) updated = EntryHandler.add(ctx.author.id, url, enc_username, enc_password) if updated: await ctx.send("Credentials updated for <{}>".format(url)) else: await ctx.send("Entry doesn't exist")
async def update(ctx, url: str, username: str, password: str): if any(char in username or char in password for char in NOT_ALLOWED): await ctx.send(":x: Character not allowed") return masterpass = get_password(ctx.author.id) enc_username, err = await encrypt(username, masterpass) if err: raise EncryptionError(err) enc_password, err = await encrypt(password, masterpass) if err: raise EncryptionError(err) updated = EntryHandler.add(ctx.author.id, url, enc_username, enc_password) if updated: await ctx.send(f":white_check_mark: Credentials updated for <{url}>") else: await ctx.send(":x: Entry doesn't exist")
async def add(ctx, url: str, username: str, password: str): if not validators.url(url): await ctx.send("Not a valid URL") else: masterpass = get_password(ctx.author.id) enc_username, err = await encrypt(username, masterpass) if err: raise EncryptionError(err) enc_password, err = await encrypt(password, masterpass) if err: raise EncryptionError(err) added = EntryHandler.add(ctx.author.id, url, enc_username, enc_password) if added: await ctx.send("Credentials added for <{}>".format(url)) else: await ctx.send("Entry already exists")
async def add(ctx, url: str, username: str, password: str): if any(char in username or char in password for char in NOT_ALLOWED): await ctx.send(":x: Character not allowed") return if not validators.url(url): await ctx.send(":x: Not a valid URL") return masterpass = get_password(ctx.author.id) enc_username, err = await encrypt(username, masterpass) if err: raise EncryptionError(err) enc_password, err = await encrypt(password, masterpass) if err: raise EncryptionError(err) added = EntryHandler.add(ctx.author.id, url, enc_username, enc_password) if added: await ctx.send(f":white_check_mark: Credentials added for <{url}>") else: await ctx.send(":x: Entry already exists")
async def delete(ctx, url: str): deleted = EntryHandler.delete(ctx.author.id, url) if deleted: await ctx.send(f":white_check_mark: Credentials deleted for <{url}>") else: await ctx.send(":x: This URL doesn't exist")
async def delete(ctx, url: str): deleted = EntryHandler.delete(ctx.author.id, url) if deleted: await ctx.send("Credentials deleted for <{}>".format(url)) else: await ctx.send("This URL doesn't exist")