Skip to content

Commit 4b56b54

Browse files
committed
feat(util.socials): add reddit command
1 parent 401ce69 commit 4b56b54

File tree

6 files changed

+135
-4
lines changed

6 files changed

+135
-4
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Changelog
2+
This project follows the [Semantic Versioning 2.0.0](https://semver.org/) specification as of 14.04.2025. This changelog was initiated at the same date.
3+
4+
## 1.0.0
5+
The initiating version. I used 1.0.0 instead of 0.1.0 as this project has already been in production for almost a year, and is stable.
6+
7+
#### 1.0.1
8+
Patched users being able to enter location names above 300 characters in util.time.
9+
10+
### 1.1.0
11+
Added the util.weather cog.
12+
13+
### 1.2.0
14+
Added the util.social cog with the github command.
15+
16+
#### 1.2.1
17+
Fixed the bot's name being hardcoded in some places as "Takina" instead of using the BOT_NAME environment variable.
18+
19+
### 1.3.0
20+
Added the reddit command to the util.socials cog.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Takina v1.2.1
1+
# Takina
22
A simple multipurpose bot for Discord. Also the very cutest Discord bot. Sakanaaa <3
33

44
For a list of features and other information please visit: https://takina.orangc.net.
@@ -44,6 +44,6 @@ Please see [CONTRIBUTING.md](CONTRIBUTING.md).
4444
- [Privacy Policy](https://orangc.net/takina/privacy.html)
4545

4646
## Specifications
47-
- This project follows the [Semantic Versioning 2.0.0](https://semver.org/) specification as of 14.04.2025.
47+
- This project follows the [Semantic Versioning 2.0.0](https://semver.org/) specification as of 14.04.2025. You may see the current version and changelog [here](./CHANGELOG.md).
4848
- This project follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification as of 01.10.2024.
4949
<!-- note to self: count takina loc with: `git ls-files | grep '\.py$' | xargs wc -l | tail -n 1`, 9,839 as of 14.04.2025 -->

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ services:
2121
- BOT_NAME=Takina
2222
- DB_NAME=takina
2323
- EMBED_COLOR=0x2B2D31
24+
- GITHUB_AUTH_TOKEN= # if you want the github command in util.socials to work, set this variable
25+
- REDDIT_CLIENT_ID= # You must set the REDDIT_CLIENT_ID and REDDIT_CLIENT_SECRET environment variables if you would like the reddit command in util.socials to work. To get your own Reddit client secret and ID visit https://www.reddit.com/prefs/apps.
26+
- REDDIT_CLIENT_SECRET= # see above
2427

2528
volumes:
2629
data-volume:

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ping3==4.0.8 # util.utils
1515
google-books-api-wrapper==1.0.5 # util.books
1616
aladhan.py==1.2.2 ## islam.salah
1717
PyGithub==2.6.1 # util.socials
18+
asyncpraw==7.8.1 # util.socials
1819
pytz==2025.2 # util.time
1920
tzfpy==1.0.0 # util.time
2021
geopy==2.4.1 # util.time

takina/cogs/util/socials.py

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import nextcord
1+
import nextcord, asyncpraw
22
from nextcord.ext import commands
33
from config import *
44
from ..libs.oclib import *
@@ -34,6 +34,7 @@ async def slash_github(
3434
await interaction.send(embed=embed)
3535

3636
async def fetch_user_information(self, username):
37+
username = username[1:] if username.startswith("@") else username
3738
embed = nextcord.Embed(color=EMBED_COLOR, description="", title=username)
3839
github = Github(GITHUB_AUTH_TOKEN)
3940
try:
@@ -75,5 +76,109 @@ async def fetch_user_information(self, username):
7576
# fmt: on
7677

7778

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+
78172
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+
)

takina/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
DB_NAME = getenv("DB_NAME").lower()
88
MONGO_URI = getenv("MONGO")
99
GITHUB_AUTH_TOKEN = getenv("GITHUB_AUTH_TOKEN")
10+
REDDIT_CLIENT_ID = getenv("REDDIT_CLIENT_ID")
11+
REDDIT_CLIENT_SECRET = getenv("REDDIT_CLIENT_SECRET")
1012
ERROR_COLOR = 0xFF0037
1113

1214
EMBED_COLOR_STR = getenv("EMBED_COLOR", "#2B2D31")

0 commit comments

Comments
 (0)