add new card kind, and do not raise error for unknown card kind (#467)

This commit is contained in:
jackyzy823 2021-11-20 22:12:33 +00:00 committed by GitHub
parent 5caf77481f
commit 68136de07b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View file

@ -169,7 +169,7 @@ proc parseCard(js: JsonNode; urls: JsonNode): Card =
let let
vals = ? js{"binding_values"} vals = ? js{"binding_values"}
name = js{"name"}.getStr name = js{"name"}.getStr
kind = parseEnum[CardKind](name[(name.find(":") + 1) ..< name.len]) kind = parseEnum[CardKind](name[(name.find(":") + 1) ..< name.len], unknown)
result = Card( result = Card(
kind: kind, kind: kind,
@ -195,7 +195,7 @@ proc parseCard(js: JsonNode; urls: JsonNode): Card =
result.url = vals{"player_url"}.getStrVal result.url = vals{"player_url"}.getStrVal
if "youtube.com" in result.url: if "youtube.com" in result.url:
result.url = result.url.replace("/embed/", "/watch?v=") result.url = result.url.replace("/embed/", "/watch?v=")
of unified: of unified, unknown:
result.title = "This card type is not supported." result.title = "This card type is not supported."
else: discard else: discard

View file

@ -126,6 +126,8 @@ type
videoDirectMessage = "video_direct_message" videoDirectMessage = "video_direct_message"
imageDirectMessage = "image_direct_message" imageDirectMessage = "image_direct_message"
audiospace = "audiospace" audiospace = "audiospace"
newsletter_publication = "newsletter_publication"
unknown
Card* = object Card* = object
kind*: CardKind kind*: CardKind