@@ -17,6 +17,7 @@ class PendingPost:
1717 u_message_id: id of the original message of the post
1818 g_message_id: id of the post in the group
1919 admin_group_id: id of the admin group
20+ credit_username: username of the user that sent the post if it's a credit post
2021 date: when the post was sent
2122 """
2223
@@ -25,15 +26,19 @@ class PendingPost:
2526 g_message_id : int
2627 admin_group_id : int
2728 date : datetime
29+ credit_username : str | None = None
2830
2931 @classmethod
30- def create (cls , user_message : Message , g_message_id : int , admin_group_id : int ) -> "PendingPost" :
32+ def create (
33+ cls , user_message : Message , g_message_id : int , admin_group_id : int , credit_username : str | None = None
34+ ) -> "PendingPost" :
3135 """Creates a new post and inserts it in the table of pending posts
3236
3337 Args:
3438 user_message: message sent by the user that contains the post
3539 g_message_id: id of the post in the group
3640 admin_group_id: id of the admin group
41+ credit_username: username of the user that sent the post if it's a credit post
3742
3843 Returns:
3944 instance of the class
@@ -47,6 +52,7 @@ def create(cls, user_message: Message, g_message_id: int, admin_group_id: int) -
4752 u_message_id = u_message_id ,
4853 g_message_id = g_message_id ,
4954 admin_group_id = admin_group_id ,
55+ credit_username = credit_username ,
5056 date = date ,
5157 ).save_post ()
5258
@@ -76,6 +82,7 @@ def from_group(cls, g_message_id: int, admin_group_id: int) -> "PendingPost | No
7682 u_message_id = pending_post ["u_message_id" ],
7783 admin_group_id = pending_post ["admin_group_id" ],
7884 g_message_id = pending_post ["g_message_id" ],
85+ credit_username = pending_post ["credit_username" ],
7986 date = pending_post ["message_date" ],
8087 )
8188
@@ -101,6 +108,7 @@ def from_user(cls, user_id: int) -> "PendingPost | None":
101108 u_message_id = pending_post ["u_message_id" ],
102109 admin_group_id = pending_post ["admin_group_id" ],
103110 g_message_id = pending_post ["g_message_id" ],
111+ credit_username = pending_post ["credit_username" ],
104112 date = pending_post ["message_date" ],
105113 )
106114
@@ -138,10 +146,15 @@ def get_all(admin_group_id: int, before: datetime | None = None) -> list["Pendin
138146
139147 def save_post (self ) -> "PendingPost" :
140148 """Saves the pending_post in the database"""
149+ columns = ("user_id" , "u_message_id" , "g_message_id" , "admin_group_id" , "message_date" )
150+ values = (self .user_id , self .u_message_id , self .g_message_id , self .admin_group_id , self .date )
151+ if self .credit_username is not None :
152+ columns += ("credit_username" ,)
153+ values += (self .credit_username ,)
141154 DbManager .insert_into (
142155 table_name = "pending_post" ,
143- columns = ( "user_id" , "u_message_id" , "g_message_id" , "admin_group_id" , "message_date" ) ,
144- values = ( self . user_id , self . u_message_id , self . g_message_id , self . admin_group_id , self . date ) ,
156+ columns = columns ,
157+ values = values ,
145158 )
146159 return self
147160
@@ -160,6 +173,14 @@ def get_votes(self, vote: bool) -> int:
160173 where_args = (self .g_message_id , self .admin_group_id , vote ),
161174 )
162175
176+ def get_credit_username (self ) -> str | None :
177+ """Gets the username of the user that credited the post
178+
179+ Returns:
180+ username of the user that credited the post, or None if the post is not credited
181+ """
182+ return self .credit_username
183+
163184 def get_list_admin_votes (self , vote : "bool | None" = None ) -> "list[int] | list[tuple[int, bool]]" :
164185 """Gets the list of admins that approved or rejected the post
165186
@@ -257,5 +278,6 @@ def __repr__(self) -> str:
257278 f"u_message_id: { self .u_message_id } \n "
258279 f"admin_group_id: { self .admin_group_id } \n "
259280 f"g_message_id: { self .g_message_id } \n "
281+ f"credit_username: { self .credit_username } \n "
260282 f"date : { self .date } ]"
261283 )
0 commit comments