social media crossposting tool. 3rd time's the charm
mastodon misskey crossposting bluesky

fix: use match/case in bluesky.common

zenfyr.dev 92636ae6 4d0cc0f2

verified
Changed files
+23 -21
bluesky
+23 -21
bluesky/common.py
···
feature = features[0]
feature_type = feature['$type']
index = facet['index']
-
if feature_type == 'app.bsky.richtext.facet#tag':
-
slices.append((index['byteStart'], index['byteEnd'], 'tag', feature['tag']))
-
elif feature_type == 'app.bsky.richtext.facet#link':
-
slices.append((index['byteStart'], index['byteEnd'], 'link', feature['uri']))
-
elif feature_type == 'app.bsky.richtext.facet#mention':
-
slices.append((index['byteStart'], index['byteEnd'], 'mention', feature['did']))
+
match feature_type:
+
case 'app.bsky.richtext.facet#tag':
+
slices.append((index['byteStart'], index['byteEnd'], 'tag', feature['tag']))
+
case 'app.bsky.richtext.facet#link':
+
slices.append((index['byteStart'], index['byteEnd'], 'link', feature['uri']))
+
case 'app.bsky.richtext.facet#mention':
+
slices.append((index['byteStart'], index['byteEnd'], 'mention', feature['did']))
if not slices:
return [cross.TextToken(text)]
···
# text between facets
tokens.append(cross.TextToken(text[prev:start]))
# facet token
-
if ttype == 'link':
-
label = text[start:end]
+
match ttype:
+
case 'link':
+
label = text[start:end]
-
# try to unflatten links
-
split = val.split('://')
-
if len(split) > 1:
-
if split[1].startswith(label):
-
tokens.append(cross.LinkToken(val, ''))
-
elif label.endswith('...') and split[1].startswith(label[:-3]):
-
tokens.append(cross.LinkToken(val, ''))
-
else:
-
tokens.append(cross.LinkToken(val, label))
-
elif ttype == 'tag':
-
tokens.append(cross.TagToken(text[start:end]))
-
elif ttype == 'mention':
-
tokens.append(cross.MentionToken(text[start:end], val))
+
# try to unflatten links
+
split = val.split('://')
+
if len(split) > 1:
+
if split[1].startswith(label):
+
tokens.append(cross.LinkToken(val, ''))
+
elif label.endswith('...') and split[1].startswith(label[:-3]):
+
tokens.append(cross.LinkToken(val, ''))
+
else:
+
tokens.append(cross.LinkToken(val, label))
+
case 'tag':
+
tokens.append(cross.TagToken(text[start:end]))
+
case 'mention':
+
tokens.append(cross.MentionToken(text[start:end], val))
prev = end
if prev < len(text):