Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.

Commit 87a5bbd

Browse files
authored
Merge pull request #150 from umairkarel/patch-1
Added subreddit prefix
2 parents 6c5ccf4 + 9ea1d5e commit 87a5bbd

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

integrations/reddit/cog.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import datetime
22
from typing import Optional, List
3+
import re
34

45
from aiohttp import ClientSession
56
from discord import Embed, TextChannel
@@ -27,6 +28,7 @@
2728

2829

2930
async def exists_subreddit(subreddit: str) -> bool:
31+
subreddit = re.sub("^(/r/|r/)", "", subreddit)
3032
async with ClientSession() as session, session.get(
3133
# raw_json=1 as parameter to get unicode characters instead of html escape sequences
3234
f"https://www.reddit.com/r/{subreddit}/about.json?raw_json=1",
@@ -36,6 +38,7 @@ async def exists_subreddit(subreddit: str) -> bool:
3638

3739

3840
async def get_subreddit_name(subreddit: str) -> str:
41+
subreddit = re.sub("^(/r/|r/)", "", subreddit)
3942
async with ClientSession() as session, session.get(
4043
# raw_json=1 as parameter to get unicode characters instead of html escape sequences
4144
f"https://www.reddit.com/r/{subreddit}/about.json?raw_json=1",
@@ -45,6 +48,7 @@ async def get_subreddit_name(subreddit: str) -> str:
4548

4649

4750
async def fetch_reddit_posts(subreddit: str, limit: int) -> Optional[List[dict]]:
51+
subreddit = re.sub("^(/r/|r/)", "", subreddit)
4852
async with ClientSession() as session, session.get(
4953
# raw_json=1 as parameter to get unicode characters instead of html escape sequences
5054
f"https://www.reddit.com/r/{subreddit}/hot.json?raw_json=1",

0 commit comments

Comments
 (0)