8
8
9
9
from zorak .utilities .cog_helpers ._embeds import embed_leaderboard
10
10
11
+
11
12
class Points (commands .Cog ):
12
13
"""
13
14
Handles automatic points based on activity.
14
15
"""
15
16
16
17
def __init__ (self , bot ):
17
18
if not hasattr (bot , "db_client" ):
19
+ print ('fuck' )
18
20
raise Exception ("Database client not found." )
19
21
self .bot = bot
20
22
21
23
@commands .Cog .listener ()
22
24
async def on_member_join (self , member : discord .Member ): # pylint: disable=E1101
25
+ print ('On_member_join' )
23
26
"""When a member joins, add them to the DB."""
24
27
self .bot .db_client .add_user_to_table (member )
25
28
26
29
@commands .Cog .listener ()
27
30
async def on_member_remove (self , member : discord .Member ): # pylint: disable=E1101
31
+ print ('On_member_rem' )
28
32
"""When a member leaves, remove them from the DB."""
29
33
self .bot .db_client .remove_user_from_table (member )
30
34
31
35
@commands .Cog .listener ()
32
36
async def on_message (self , message : discord .Message ):
37
+ print ('On_mess' )
33
38
"""When a member sends a message, give them 1 point."""
34
39
if message .author .bot :
35
40
return
36
41
self .bot .db_client .add_points_to_user (message .author .id , 1 )
37
42
38
43
@commands .Cog .listener ()
39
44
async def on_message_delete (self , message : discord .Message ):
45
+ print ('On_del' )
40
46
"""When a member deletes a message, remove a point."""
41
47
mod_log = await self .bot .fetch_channel (self .bot .server_settings .log_channel ["mod_log" ])
42
48
await mod_log .send (f"1 Point removed from { message .author } for deleting a message." )
43
49
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.")
52
58
53
59
@commands .slash_command ()
54
60
@commands .has_any_role ("Staff" , "Owner" , "Project Manager" )
55
61
async def add_all_members_to_db (self , ctx ):
62
+ print ('add all' )
56
63
"""Add all members to the database."""
57
64
self .bot .db_client .create_table_from_members (ctx .guild .members )
58
65
await ctx .respond ("All members added to database." )
59
66
60
67
@commands .slash_command ()
61
68
@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' )
63
71
"""Add points to a user."""
64
72
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 ))
94
74
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 } ." )
97
77
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}.")
107
119
108
120
@commands .slash_command ()
109
121
@commands .has_any_role ("Staff" , "Owner" , "Project Manager" )
110
122
async def reset_points_for_all_users (self , ctx ):
123
+ print ('reset all' )
111
124
"""Reset points for all users."""
112
125
self .bot .db_client .set_all_user_points (0 )
113
126
mod_log = await self .bot .fetch_channel (self .bot .server_settings .log_channel ["mod_log" ])
114
127
await mod_log .send (f"Points reset for all users by { ctx .author } ." )
115
128
await ctx .respond ("Points reset for all users." )
116
129
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]}.")
124
138
125
139
@commands .slash_command ()
126
140
async def leaderboard (self , ctx ):
141
+ print ('leader' )
127
142
"""Get your points."""
128
143
129
144
def is_staff (member_obj ):
@@ -142,9 +157,11 @@ def is_staff(member_obj):
142
157
if not is_staff (member ):
143
158
top10_no_staff .append ((member , person ['Points' ]))
144
159
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' ])
146
162
await ctx .respond (embed = embed )
147
163
164
+ print ('thru all defs' )
148
165
149
166
150
167
def setup (bot ):
0 commit comments