mirror of
https://github.com/zedeus/nitter.git
synced 2025-12-06 03:55:36 -05:00
@@ -1,6 +1,7 @@
|
|||||||
import std/[options, tables, strutils, strformat, sugar]
|
import std/[options, tables, strutils, strformat, sugar]
|
||||||
import jsony
|
import jsony
|
||||||
import user, ../types/unifiedcard
|
import user, ../types/unifiedcard
|
||||||
|
import ../../formatters
|
||||||
from ../../types import Card, CardKind, Video
|
from ../../types import Card, CardKind, Video
|
||||||
from ../../utils import twimg, https
|
from ../../utils import twimg, https
|
||||||
|
|
||||||
@@ -77,6 +78,18 @@ proc parseMedia(component: Component; card: UnifiedCard; result: var Card) =
|
|||||||
of model3d:
|
of model3d:
|
||||||
result.title = "Unsupported 3D model ad"
|
result.title = "Unsupported 3D model ad"
|
||||||
|
|
||||||
|
proc parseGrokShare(data: ComponentData; card: UnifiedCard; result: var Card) =
|
||||||
|
result.kind = summaryLarge
|
||||||
|
|
||||||
|
data.destination.parseDestination(card, result)
|
||||||
|
result.dest = "Answer by Grok"
|
||||||
|
|
||||||
|
for msg in data.conversationPreview:
|
||||||
|
if msg.sender == "USER":
|
||||||
|
result.title = msg.message.shorten(70)
|
||||||
|
elif msg.sender == "AGENT":
|
||||||
|
result.text = msg.message.shorten(500)
|
||||||
|
|
||||||
proc parseUnifiedCard*(json: string): Card =
|
proc parseUnifiedCard*(json: string): Card =
|
||||||
let card = json.fromJson(UnifiedCard)
|
let card = json.fromJson(UnifiedCard)
|
||||||
|
|
||||||
@@ -92,6 +105,8 @@ proc parseUnifiedCard*(json: string): Card =
|
|||||||
component.parseMedia(card, result)
|
component.parseMedia(card, result)
|
||||||
of buttonGroup:
|
of buttonGroup:
|
||||||
discard
|
discard
|
||||||
|
of grokShare:
|
||||||
|
component.data.parseGrokShare(card, result)
|
||||||
of ComponentType.jobDetails:
|
of ComponentType.jobDetails:
|
||||||
component.data.parseJobDetails(card, result)
|
component.data.parseJobDetails(card, result)
|
||||||
of ComponentType.hidden:
|
of ComponentType.hidden:
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ type
|
|||||||
communityDetails
|
communityDetails
|
||||||
mediaWithDetailsHorizontal
|
mediaWithDetailsHorizontal
|
||||||
hidden
|
hidden
|
||||||
|
grokShare
|
||||||
unknown
|
unknown
|
||||||
|
|
||||||
Component* = object
|
Component* = object
|
||||||
@@ -42,6 +43,7 @@ type
|
|||||||
topicDetail*: tuple[title: Text]
|
topicDetail*: tuple[title: Text]
|
||||||
profileUser*: User
|
profileUser*: User
|
||||||
shortDescriptionText*: string
|
shortDescriptionText*: string
|
||||||
|
conversationPreview*: seq[GrokConversation]
|
||||||
|
|
||||||
MediaItem* = object
|
MediaItem* = object
|
||||||
id*: string
|
id*: string
|
||||||
@@ -76,6 +78,10 @@ type
|
|||||||
title*: Text
|
title*: Text
|
||||||
category*: Text
|
category*: Text
|
||||||
|
|
||||||
|
GrokConversation* = object
|
||||||
|
message*: string
|
||||||
|
sender*: string
|
||||||
|
|
||||||
TypeField = Component | Destination | MediaEntity | AppStoreData
|
TypeField = Component | Destination | MediaEntity | AppStoreData
|
||||||
|
|
||||||
converter fromText*(text: Text): string = string(text)
|
converter fromText*(text: Text): string = string(text)
|
||||||
@@ -96,6 +102,7 @@ proc enumHook*(s: string; v: var ComponentType) =
|
|||||||
of "community_details": communityDetails
|
of "community_details": communityDetails
|
||||||
of "media_with_details_horizontal": mediaWithDetailsHorizontal
|
of "media_with_details_horizontal": mediaWithDetailsHorizontal
|
||||||
of "commerce_drop_details": hidden
|
of "commerce_drop_details": hidden
|
||||||
|
of "grok_share": grokShare
|
||||||
else: echo "ERROR: Unknown enum value (ComponentType): ", s; unknown
|
else: echo "ERROR: Unknown enum value (ComponentType): ", s; unknown
|
||||||
|
|
||||||
proc enumHook*(s: string; v: var AppType) =
|
proc enumHook*(s: string; v: var AppType) =
|
||||||
|
|||||||
@@ -33,10 +33,13 @@ proc getUrlPrefix*(cfg: Config): string =
|
|||||||
if cfg.useHttps: https & cfg.hostname
|
if cfg.useHttps: https & cfg.hostname
|
||||||
else: "http://" & cfg.hostname
|
else: "http://" & cfg.hostname
|
||||||
|
|
||||||
proc shortLink*(text: string; length=28): string =
|
proc shorten*(text: string; length=28): string =
|
||||||
result = text.replace(wwwRegex, "")
|
result = text
|
||||||
if result.len > length:
|
if result.len > length:
|
||||||
result = result[0 ..< length] & "…"
|
result = result[0 ..< length] & "…"
|
||||||
|
|
||||||
|
proc shortLink*(text: string; length=28): string =
|
||||||
|
result = text.replace(wwwRegex, "").shorten(length)
|
||||||
|
|
||||||
proc stripHtml*(text: string; shorten=false): string =
|
proc stripHtml*(text: string; shorten=false): string =
|
||||||
var html = parseHtml(text)
|
var html = parseHtml(text)
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
.card-description {
|
.card-description {
|
||||||
margin: 0.3em 0;
|
margin: 0.3em 0;
|
||||||
|
white-space: pre-wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card-destination {
|
.card-destination {
|
||||||
|
|||||||
Reference in New Issue
Block a user