# totp.py
import flume
try:
import pyotp
HAS_PYOTP = True
except ImportError:
HAS_PYOTP = False
def handle_totp(args):
if not HAS_PYOTP:
flume.buffer.print("", "", "pyotp not installed. Run: pip install pyotp")
return
parts = args.strip().split(None, 1)
if parts and parts[0] == "set":
if len(parts) < 2:
flume.buffer.print("", "", "Usage: /totp set <secret>")
return
flume.config.set("secret", parts[1])
flume.buffer.print("", "", "TOTP secret saved")
return
secret = args.strip() if args.strip() else flume.config.get("secret")
if not secret:
flume.buffer.print("", "", "Usage: /totp <secret> or /totp set <secret>")
return
code = pyotp.TOTP(secret).now()
flume.buffer.print("", "", f"TOTP code: {code}")
flume.command.register("totp", handle_totp, "Generate TOTP code")