Skip to content

Commit

Permalink
remove match-case for older python versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilgames32 committed Aug 26, 2024
1 parent 205a78e commit c5f06a5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 48 deletions.
27 changes: 13 additions & 14 deletions posts/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,19 @@ def webhook_message(self, include_author = False, markdown = False) -> str:
message += f"on [{self._platform}](<{self._url}>) "

# media
match self._type:
case PostType.TEXT:
pass
case PostType.IMAGE:
message += f"[.]({self._media[0]})"
case PostType.GALLERY:
for url in self._media:
message += f"[.]({url}) "
case PostType.VIDEO:
message += f"[.]({self._media[0]})"
case PostType.POLL:
raise Exception("Polls are not supported yet")
case PostType.CROSSPOST:
raise Exception("Crossposts are not supported yet")
if self._type is PostType.TEXT:
pass
elif self._type is PostType.IMAGE:
message += f"[.]({self._media[0]})"
elif self._type is PostType.GALLERY:
for url in self._media:
message += f"[.]({url}) "
elif self._type is PostType.VIDEO:
message += f"[.]({self._media[0]})"
elif self._type is PostType.POLL:
raise Exception("Polls are not supported yet")
elif self._type is PostType.CROSSPOST:
raise Exception("Crossposts are not supported yet")

if len(message) > 2000:
message = " ".join(message[:1997].split(" ")[:-1]) + "..." # profound mental retardation
Expand Down
67 changes: 33 additions & 34 deletions posts/redditpost.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,42 +43,41 @@ async def generate(self, submission):
# type
self._type = RedditPost.post_type(submission)

match self._type:
case PostType.IMAGE:
self._media.append(submission.url)

case PostType.GALLERY:
image_dict = submission.media_metadata
for i in image_dict:
pattern = r"/([^/?]+)(?:\?|$)"
self._media.append(
"https://i.redd.it/"
+ re.search(pattern, image_dict[i]["s"]["u"]).group(1)
)

case PostType.VIDEO:
# reddit is stupit and has the video and audio in separate sources
# besides discord doesnt allow videos in embeds
self._thumbnail = submission.thumbnail
self._media.append(submission.media["reddit_video"]["fallback_url"])

case PostType.POLL:
# TODO
self._text = "polls arent supported yet"

case PostType.CROSSPOST:
# TODO
self._text = "crossposts arent supported yet"
self._parent = Post(
reddit.submission(
url="https://reddit.com"
+ submission.crosspost_parent_list[0]["permalink"]
)
if self._type is PostType.IMAGE:
self._media.append(submission.url)

elif self._type is PostType.GALLERY:
image_dict = submission.media_metadata
for i in image_dict:
pattern = r"/([^/?]+)(?:\?|$)"
self._media.append(
"https://i.redd.it/"
+ re.search(pattern, image_dict[i]["s"]["u"]).group(1)
)
# self._parent.fetch()

case PostType.TEXT:
self._text = submission.selftext
elif self._type is PostType.VIDEO:
# reddit is stupit and has the video and audio in separate sources
# besides discord doesnt allow videos in embeds
self._thumbnail = submission.thumbnail
self._media.append(submission.media["reddit_video"]["fallback_url"])

elif self._type is PostType.POLL:
# TODO
self._text = "polls arent supported yet"

elif self._type is PostType.CROSSPOST:
# TODO
self._text = "crossposts arent supported yet"
self._parent = Post(
reddit.submission(
url="https://reddit.com"
+ submission.crosspost_parent_list[0]["permalink"]
)
)
# self._parent.fetch()

elif self._type is PostType.TEXT:
self._text = submission.selftext

await super().fetch()

Expand Down

0 comments on commit c5f06a5

Please sign in to comment.