Skip to content

Commit 2df8b4b

Browse files
committed
Update points.py
typing issues when specifying the type in the function params. Remove the typing, and make sure you are passing the right shit to the DB.
1 parent 608df19 commit 2df8b4b

File tree

1 file changed

+74
-57
lines changed

1 file changed

+74
-57
lines changed

src/zorak/cogs/utility/points.py

Lines changed: 74 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,122 +8,137 @@
88

99
from zorak.utilities.cog_helpers._embeds import embed_leaderboard
1010

11+
1112
class Points(commands.Cog):
1213
"""
1314
Handles automatic points based on activity.
1415
"""
1516

1617
def __init__(self, bot):
1718
if not hasattr(bot, "db_client"):
19+
print('fuck')
1820
raise Exception("Database client not found.")
1921
self.bot = bot
2022

2123
@commands.Cog.listener()
2224
async def on_member_join(self, member: discord.Member): # pylint: disable=E1101
25+
print('On_member_join')
2326
"""When a member joins, add them to the DB."""
2427
self.bot.db_client.add_user_to_table(member)
2528

2629
@commands.Cog.listener()
2730
async def on_member_remove(self, member: discord.Member): # pylint: disable=E1101
31+
print('On_member_rem')
2832
"""When a member leaves, remove them from the DB."""
2933
self.bot.db_client.remove_user_from_table(member)
3034

3135
@commands.Cog.listener()
3236
async def on_message(self, message: discord.Message):
37+
print('On_mess')
3338
"""When a member sends a message, give them 1 point."""
3439
if message.author.bot:
3540
return
3641
self.bot.db_client.add_points_to_user(message.author.id, 1)
3742

3843
@commands.Cog.listener()
3944
async def on_message_delete(self, message: discord.Message):
45+
print('On_del')
4046
"""When a member deletes a message, remove a point."""
4147
mod_log = await self.bot.fetch_channel(self.bot.server_settings.log_channel["mod_log"])
4248
await mod_log.send(f"1 Point removed from {message.author} for deleting a message.")
4349
self.bot.db_client.remove_points_from_user(message.author.id, 1)
44-
45-
# TODO: Fix the backup command.
46-
# @commands.slash_command()
47-
# @commands.has_any_role("Staff", "Owner", "Project Manager")
48-
# async def backup_db(self, ctx):
49-
# """Backup the MongoDB instance."""
50-
# self.bot.db_client.backup_db()
51-
# await ctx.respond("Database backed up.")
50+
#
51+
# # TODO: Fix the backup command.
52+
# # @commands.slash_command()
53+
# # @commands.has_any_role("Staff", "Owner", "Project Manager")
54+
# # async def backup_db(self, ctx):
55+
# # """Backup the MongoDB instance."""
56+
# # self.bot.db_client.backup_db()
57+
# # await ctx.respond("Database backed up.")
5258

5359
@commands.slash_command()
5460
@commands.has_any_role("Staff", "Owner", "Project Manager")
5561
async def add_all_members_to_db(self, ctx):
62+
print('add all')
5663
"""Add all members to the database."""
5764
self.bot.db_client.create_table_from_members(ctx.guild.members)
5865
await ctx.respond("All members added to database.")
5966

6067
@commands.slash_command()
6168
@commands.has_any_role("Staff", "Owner", "Project Manager")
62-
async def add_points_to_user(self, ctx, mention: discord.Option[str], points: discord.Option[int]):
69+
async def add_points_to_user(self, ctx, mention, points):
70+
print('add to user')
6371
"""Add points to a user."""
6472
user = self.bot.get_user(int(mention.split("@")[1].split(">")[0]))
65-
self.bot.db_client.add_points_to_user(user.id, points)
66-
mod_log = await self.bot.fetch_channel(self.bot.server_settings.log_channel["mod_log"])
67-
await mod_log.send(f"{points} point{('s', '')[abs(points) == 1]} added to {mention} by {ctx.author}.")
68-
await ctx.respond(f"{points} point{('s', '')[abs(points) == 1]} added to {mention}.")
69-
70-
@commands.slash_command()
71-
@commands.has_any_role("Staff", "Owner", "Project Manager")
72-
async def add_points_to_all_users(self, ctx, points: discord.Option[int]):
73-
"""Add points to all users."""
74-
self.bot.db_client.add_points_to_all_users(points)
75-
mod_log = await self.bot.fetch_channel(self.bot.server_settings.log_channel["mod_log"])
76-
await mod_log.send(f"{points} point{('s', '')[abs(points) == 1]} added to all users by {ctx.author}.")
77-
await ctx.respond(f"{points} point{('s', '')[abs(points) == 1]} added to all users.")
78-
79-
@commands.slash_command()
80-
@commands.has_any_role("Staff", "Owner", "Project Manager")
81-
async def remove_points_from_user(self, ctx, mention: discord.Option[str], points: discord.Option[int]):
82-
"""Remove points from a user."""
83-
user = self.bot.get_user(int(mention.split("@")[1].split(">")[0]))
84-
self.bot.db_client.remove_points_from_user(user.id, points)
85-
mod_log = await self.bot.fetch_channel(self.bot.server_settings.log_channel["mod_log"])
86-
await mod_log.send(f"{points} point{('s', '')[abs(points) == 1]} removed from {mention} by {ctx.author}.")
87-
await ctx.respond(f"{points} point{('s', '')[abs(points) == 1]} removed from {mention}.")
88-
89-
@commands.slash_command()
90-
@commands.has_any_role("Staff", "Owner", "Project Manager")
91-
async def remove_points_from_all_users(self, ctx, points: discord.Option[int]):
92-
"""Remove points from all users."""
93-
self.bot.db_client.remove_points_from_all_users(points)
73+
self.bot.db_client.add_points_to_user(user.id, int(points))
9474
mod_log = await self.bot.fetch_channel(self.bot.server_settings.log_channel["mod_log"])
95-
await mod_log.send(f"{points} point{('s', '')[abs(points) == 1]} removed from all users by {ctx.author}.")
96-
await ctx.respond(f"{points} point{('s', '')[abs(points) == 1]} removed from all users.")
75+
await mod_log.send(f"{points} point{('s', '')[abs(int(points)) == 1]} added to {mention} by {ctx.author}.")
76+
await ctx.respond(f"{points} point{('s', '')[abs(int(points)) == 1]} added to {mention}.")
9777

98-
@commands.slash_command()
99-
@commands.has_any_role("Staff", "Owner", "Project Manager")
100-
async def reset_points_for_user(self, ctx, mention: discord.Option[str]):
101-
"""Reset points for a user."""
102-
user = self.bot.get_user(int(mention.split("@")[1].split(">")[0]))
103-
self.bot.db_client.set_user_points(user.id, 0)
104-
mod_log = await self.bot.fetch_channel(self.bot.server_settings.log_channel["mod_log"])
105-
await mod_log.send(f"Points reset for {mention} by {ctx.author}.")
106-
await ctx.respond(f"Points reset for {mention}.")
78+
# @commands.slash_command()
79+
# @commands.has_any_role("Staff", "Owner", "Project Manager")
80+
# async def add_points_to_all_users(self, ctx, points: discord.Option[int]):
81+
# print('add to all users')
82+
# """Add points to all users."""
83+
# self.bot.db_client.add_points_to_all_users(points)
84+
# mod_log = await self.bot.fetch_channel(self.bot.server_settings.log_channel["mod_log"])
85+
# await mod_log.send(f"{points} point{('s', '')[abs(points) == 1]} added to all users by {ctx.author}.")
86+
# await ctx.respond(f"{points} point{('s', '')[abs(points) == 1]} added to all users.")
87+
#
88+
# @commands.slash_command()
89+
# @commands.has_any_role("Staff", "Owner", "Project Manager")
90+
# async def remove_points_from_user(self, ctx, mention: discord.Option[str], points: discord.Option[int]):
91+
# print('remove user')
92+
# """Remove points from a user."""
93+
# user = self.bot.get_user(int(mention.split("@")[1].split(">")[0]))
94+
# self.bot.db_client.remove_points_from_user(user.id, points)
95+
# mod_log = await self.bot.fetch_channel(self.bot.server_settings.log_channel["mod_log"])
96+
# await mod_log.send(f"{points} point{('s', '')[abs(points) == 1]} removed from {mention} by {ctx.author}.")
97+
# await ctx.respond(f"{points} point{('s', '')[abs(points) == 1]} removed from {mention}.")
98+
#
99+
# @commands.slash_command()
100+
# @commands.has_any_role("Staff", "Owner", "Project Manager")
101+
# async def remove_points_from_all_users(self, ctx, points: discord.Option[int]):
102+
# print('remove all users')
103+
# """Remove points from all users."""
104+
# self.bot.db_client.remove_points_from_all_users(points)
105+
# mod_log = await self.bot.fetch_channel(self.bot.server_settings.log_channel["mod_log"])
106+
# await mod_log.send(f"{points} point{('s', '')[abs(points) == 1]} removed from all users by {ctx.author}.")
107+
# await ctx.respond(f"{points} point{('s', '')[abs(points) == 1]} removed from all users.")
108+
#
109+
# @commands.slash_command()
110+
# @commands.has_any_role("Staff", "Owner", "Project Manager")
111+
# async def reset_points_for_user(self, ctx, mention: discord.Option[str]):
112+
# print('reset')
113+
# """Reset points for a user."""
114+
# user = self.bot.get_user(int(mention.split("@")[1].split(">")[0]))
115+
# self.bot.db_client.set_user_points(user.id, 0)
116+
# mod_log = await self.bot.fetch_channel(self.bot.server_settings.log_channel["mod_log"])
117+
# await mod_log.send(f"Points reset for {mention} by {ctx.author}.")
118+
# await ctx.respond(f"Points reset for {mention}.")
107119

108120
@commands.slash_command()
109121
@commands.has_any_role("Staff", "Owner", "Project Manager")
110122
async def reset_points_for_all_users(self, ctx):
123+
print('reset all')
111124
"""Reset points for all users."""
112125
self.bot.db_client.set_all_user_points(0)
113126
mod_log = await self.bot.fetch_channel(self.bot.server_settings.log_channel["mod_log"])
114127
await mod_log.send(f"Points reset for all users by {ctx.author}.")
115128
await ctx.respond("Points reset for all users.")
116129

117-
@commands.slash_command()
118-
@commands.has_any_role("Staff", "Owner", "Project Manager")
119-
async def get_points_for_user(self, ctx, mention: discord.Option[str]):
120-
"""Get points for a user."""
121-
user = self.bot.get_user(int(mention.split("@")[1].split(">")[0]))
122-
points = self.bot.db_client.get_user_points(user.id)
123-
await ctx.respond(f"{mention} has {points} point{('s', '')[abs(points) == 1]}.")
130+
# @commands.slash_command()
131+
# @commands.has_any_role("Staff", "Owner", "Project Manager")
132+
# async def get_points_for_user(self, ctx, mention: discord.Option[str]):
133+
# print('get points')
134+
# """Get points for a user."""
135+
# user = self.bot.get_user(int(mention.split("@")[1].split(">")[0]))
136+
# points = self.bot.db_client.get_user_points(user.id)
137+
# await ctx.respond(f"{mention} has {points} point{('s', '')[abs(points) == 1]}.")
124138

125139
@commands.slash_command()
126140
async def leaderboard(self, ctx):
141+
print('leader')
127142
"""Get your points."""
128143

129144
def is_staff(member_obj):
@@ -142,9 +157,11 @@ def is_staff(member_obj):
142157
if not is_staff(member):
143158
top10_no_staff.append((member, person['Points']))
144159

145-
embed = embed_leaderboard(top10_no_staff, self.bot.server_settings.server_info['name'], self.bot.server_settings.server_info['logo'])
160+
embed = embed_leaderboard(top10_no_staff, self.bot.server_settings.server_info['name'],
161+
self.bot.server_settings.server_info['logo'])
146162
await ctx.respond(embed=embed)
147163

164+
print('thru all defs')
148165

149166

150167
def setup(bot):

0 commit comments

Comments
 (0)