PredaaA / predacogs

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

remove dead / private subreddits #82

Closed Motzumoto closed 7 months ago

Motzumoto commented 8 months ago

Had to make an entirely new pr because github fucked my branch.

Anyway, heres the code i used to check if the branches were dead / private. It uses praw which is blocking. However if you want an async version please let me know and ill give you an async version.

I had to change how things were listed, see screenshot: https://i.hep.gg/7PXwCsvWM

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",
        "SnakeButt",
        "TheUnderbun",
        "Upshorts",
        "ass",
        "asshole",
        "assinthong",
        "asstastic",
        "beautifulbutt",
        "bigasses",
        "booty",
        "datgap",
        "girlsinleggings",
        "girlsinyogapants",
        "hugeass",
        "paag",
        "pawg",
        "facedownassup",
]
   # every other category
}

reddit = praw.Reddit(
    client_id="8FTlc5hmH9lBGA",
    client_secret="oxZfsfCoL4o0eu_VBLh21o6mZmg",
    password="74MMBFDa3hHo",
    user_agent="asyncprawpython",
    username="OwO_ExaNori",
)

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 8 months ago

also dont worry the secrets and passwords in the code are invalid

Ginpachi98 commented 6 months ago

adjusted this cog by making people pay with economy currency (which they earn by !work or !payday daily) in order to reduce spam and it's been the backbone of our local town small community server, thank you