from typing import Optional


def getcid(cat: str, r: dict) -> Optional[str]:
	"""
	Get the category ID with the name `CAT` from the request `R`. This function doesn't do the
	request itself, since it's meant to work with both fullgame and IL's, amongst other reasons.

	>>> r = api_get(f"{API}/games/l3dxogdy/categories")
	>>> getcid("Nitro Tracks", r)
	'7kj6mz23'
	>>> getcid("Retro Tracks", r)
	'xk9v3gd0'
	>>> r = api_get(f"{API}/games/l3dxogdy/levels")
	>>> getcid("This game has no levels", r)
	>>> r = api_get(f"{API}/games/4d7e7z67/levels")
	>>> getcid("100m", r)
	'rdn25e5d'
	"""
	lcat = cat.lower()
	for c in r["data"]:
		if c["name"].lower() == lcat:
			return c["id"]
	return None