|
1 |
| -import nextcord |
| 1 | +import nextcord, asyncpraw |
2 | 2 | from nextcord.ext import commands
|
3 | 3 | from config import *
|
4 | 4 | from ..libs.oclib import *
|
@@ -34,6 +34,7 @@ async def slash_github(
|
34 | 34 | await interaction.send(embed=embed)
|
35 | 35 |
|
36 | 36 | async def fetch_user_information(self, username):
|
| 37 | + username = username[1:] if username.startswith("@") else username |
37 | 38 | embed = nextcord.Embed(color=EMBED_COLOR, description="", title=username)
|
38 | 39 | github = Github(GITHUB_AUTH_TOKEN)
|
39 | 40 | try:
|
@@ -75,5 +76,109 @@ async def fetch_user_information(self, username):
|
75 | 76 | # fmt: on
|
76 | 77 |
|
77 | 78 |
|
| 79 | +class SocialsReddit(commands.Cog): |
| 80 | + def __init__(self, bot: commands.Bot): |
| 81 | + self.bot = bot |
| 82 | + |
| 83 | + @commands.command( |
| 84 | + help="Social information command for Reddit. Usage: `reddit orangci`.", |
| 85 | + ) |
| 86 | + async def reddit(self, ctx: commands.Context, *, username: str): |
| 87 | + embed = await self.fetch_user_information(username) |
| 88 | + await ctx.reply(embed=embed, mention_author=False) |
| 89 | + pass |
| 90 | + |
| 91 | + @nextcord.slash_command( |
| 92 | + name="reddit", description="Social information command for Reddit." |
| 93 | + ) |
| 94 | + async def slash_reddit( |
| 95 | + self, |
| 96 | + interaction: nextcord.Interaction, |
| 97 | + *, |
| 98 | + username: str = nextcord.SlashOption( |
| 99 | + description="The Reddit username to fetch information on.", |
| 100 | + required=True, |
| 101 | + ), |
| 102 | + ): |
| 103 | + await interaction.response.defer() |
| 104 | + embed = await self.fetch_user_information(username) |
| 105 | + await interaction.send(embed=embed) |
| 106 | + |
| 107 | + async def fetch_user_information(self, username): |
| 108 | + username = username[3:] if username.startswith("/u/") else username |
| 109 | + username = username[2:] if username.startswith("u/") else username |
| 110 | + |
| 111 | + reddit = asyncpraw.Reddit( |
| 112 | + client_id=REDDIT_CLIENT_ID, |
| 113 | + client_secret=REDDIT_CLIENT_SECRET, |
| 114 | + user_agent=BOT_NAME, |
| 115 | + ) |
| 116 | + |
| 117 | + embed = nextcord.Embed(color=0xFF4500, description="") |
| 118 | + |
| 119 | + try: |
| 120 | + user = await reddit.redditor(username) |
| 121 | + await user.load() |
| 122 | + except: |
| 123 | + embed.color = ERROR_COLOR |
| 124 | + embed.description = ":x: That Reddit account does not exist." |
| 125 | + return embed |
| 126 | + |
| 127 | + # fmt: off |
| 128 | + embed.set_thumbnail(url=user.icon_img) |
| 129 | + embed.title = user.name |
| 130 | + embed.description += f"{user.subreddit.public_description}\n" if user.subreddit.public_description else "" |
| 131 | + embed.description += f"\n**Joined Reddit**: <t:{int(user.created_utc)}:D>" |
| 132 | + embed.description += f"\n**Post Karma**: {user.link_karma}" |
| 133 | + embed.description += f"\n**Comment Karma**: {user.comment_karma}" |
| 134 | + embed.description += f"\n**Total Posts**: {user.link_karma}" |
| 135 | + embed.description += f"\n**Total Comments**: {user.comment_karma}" |
| 136 | + moderated_subreddits = await user.moderated() |
| 137 | + moderated_subreddit_names = [f"r/{sub.display_name}" for sub in moderated_subreddits] |
| 138 | + embed.description += f"\n**Moderator in**: {', '.join(moderated_subreddit_names)}" if moderated_subreddit_names else "" |
| 139 | + return embed |
| 140 | + # fmt: on |
| 141 | + |
| 142 | + |
| 143 | +class SocialsPLACEHOLDER(commands.Cog): |
| 144 | + def __init__(self, bot: commands.Bot): |
| 145 | + self.bot = bot |
| 146 | + |
| 147 | + @commands.command( |
| 148 | + help="Social information command for PLACEHOLDER. Usage: `PLACEHOLDER orangci`.", |
| 149 | + ) |
| 150 | + async def PLACEHOLDER(self, ctx: commands.Context, *, username: str): |
| 151 | + embed = "" |
| 152 | + await ctx.reply(embed=embed, mention_author=False) |
| 153 | + pass |
| 154 | + |
| 155 | + @nextcord.slash_command( |
| 156 | + name="PLACEHOLDER", description="Social information command for PLACEHOLDER." |
| 157 | + ) |
| 158 | + async def slash_PLACEHOLDER( |
| 159 | + self, |
| 160 | + interaction: nextcord.Interaction, |
| 161 | + *, |
| 162 | + username: str = nextcord.SlashOption( |
| 163 | + description="The PLACEHOLDER username to fetch information on.", |
| 164 | + required=True, |
| 165 | + ), |
| 166 | + ): |
| 167 | + await interaction.response.defer() |
| 168 | + embed = "" |
| 169 | + await interaction.send(embed=embed) |
| 170 | + |
| 171 | + |
78 | 172 | def setup(bot: commands.Bot):
|
79 |
| - bot.add_cog(SocialsGitHub(bot)) |
| 173 | + if GITHUB_AUTH_TOKEN: |
| 174 | + bot.add_cog(SocialsGitHub(bot)) |
| 175 | + else: |
| 176 | + print( |
| 177 | + "You must set the GITHUB_AUTH_TOKEN environment variable if you want the github command to work. Skipping loading the github command. To get your own github auth token, visit <https://github.com/settings/tokens/new>." |
| 178 | + ) |
| 179 | + if REDDIT_CLIENT_ID and REDDIT_CLIENT_SECRET: |
| 180 | + bot.add_cog(SocialsReddit(bot)) |
| 181 | + else: |
| 182 | + print( |
| 183 | + "You must set the REDDIT_CLIENT_ID and REDDIT_CLIENT_SECRET environment variables if you would like the reddit command to work. Skipping loading the reddit command. \nTo get your own Reddit application visit <https://www.reddit.com/prefs/apps>." |
| 184 | + ) |
0 commit comments