PredaaA / predacogs

Cogs for Red Discordbot
MIT License
30 stars 25 forks source link

Remove more dead/private subreddits #81

Closed Motzumoto closed 9 months ago

Motzumoto commented 9 months ago

In the future, i recommend you use this code for checking your subreddits. You will have to change how they're listed (see screenshot): https://i.hep.gg/4bKN9xDwv

import praw
from prawcore.exceptions import NotFound, Redirect, Forbidden

categories = {
    # Subreddits
    "FOUR_K":[
        "Hegre",
        "HighResNSFW",
        "NSFW_Wallpapers",
        "UHDnsfw",
        "closeup",
    ],
    "AHEGAO":["AhegaoGirls", "EyeRollOrgasm", "O_Faces", "RealAhegao"],
    "ASS":[
        "AssOnTheGlass",
        "AssholeBehindThong",
        "ButtsAndBareFeet",
        "HungryButts",
        "Mooning",
]
. . . 

}

reddit = praw.Reddit(
    client_id="CLIENT_ID",
    client_secret="CLIENT_SECRET",
    password="CLIENT_PASSWORD",
    user_agent="asyncprawpython",
    username="CLIENT_USERNAME",
)

class SubStatus:
    SUB_GONE = "Subreddit Gone"
    SUB_EXISTS = "Subreddit Exists"

def check_banned_subreddits(category, subreddits):
    banned_subreddits = []

    for subreddit_name in subreddits:
        try:
            subreddit = reddit.subreddit(subreddit_name)
            # Accessing subreddit information to check existence
            subreddit.title
        except NotFound:
            # Subreddit does not exist
            print(f"Subreddit {subreddit_name} not found.")
        except Redirect:
            # Subreddit does not exist or has been banned
            banned_subreddits.append(subreddit_name)
        except Forbidden:
            # Subreddit is forbidden (403)
            print(f"Access forbidden for subreddit {subreddit_name}.")

    return banned_subreddits

# Check for banned subreddits in each category
banned_subreddits = []
for category, subreddits in categories.items():
    banned_subreddits.extend(check_banned_subreddits(category, subreddits))

if banned_subreddits:
    print(f"Banned subreddits: {', '.join(banned_subreddits)}")
else:
    print("No banned subreddits.")
Motzumoto commented 9 months ago

You can definitely use asyncpraw for this, however its just a single file, so it doesnt really matter if its blocking. If you want to incorporate this into your bot however, I can provide an async version.

Motzumoto commented 9 months ago

Accidently deleted some lists that were fine and didnt have dead subs, re-adding those in just a second.

Motzumoto commented 9 months ago

Github fucked my branch woo