@@ -37,6 +37,7 @@ class ItsAGramLive:
3737 broadcast_id : int = None
3838 stream_key : str = None
3939 stream_server : str = None
40+ pinned_comment_id : str = None
4041
4142 DEVICE_SETS = {
4243 "app_version" : "136.0.0.34.124" ,
@@ -285,13 +286,16 @@ def start(self):
285286 elif cmd == 'comments' :
286287 self .get_comments ()
287288
288- elif cmd [:11 ] == 'pin comment ' :
289- to_send = cmd [12 :]
289+ elif cmd [:3 ] == 'pin' :
290+ to_send = cmd [4 :]
290291 if to_send :
291292 self .pin_comment (to_send )
292293 else :
293294 print ('usage: chat <text to chat>' )
294295
296+ elif cmd [:5 ] == 'unpin' :
297+ self .unpin_comment ()
298+
295299 elif cmd [:4 ] == 'chat' :
296300 to_send = cmd [5 :]
297301 if to_send :
@@ -514,18 +518,32 @@ def get_comments(self):
514518 def pin_comment (self , to_send ):
515519 if self .send_comment (msg = to_send ):
516520 if self .send_request ("live/{}/get_comment/" .format (self .broadcast_id )):
521+ for comment in [comment for comment in self .LastJson ['comments' ]]:
522+ if comment .get ("text" ) == to_send :
523+ self .pinned_comment_id = comment .get ("pk" )
517524 data = json .dumps (
518525 {
519526 "_csrftoken" : self .token ,
520527 "_uid" : self .username_id ,
521528 "_uuid" : self .uuid ,
522- "comment_id" : self .LastJson [ 'comments' ][ - 1 ]. get ( "pk" )
529+ "comment_id" : self .pinned_comment_id
523530 })
524531 if self .send_request (endpoint = 'live/{}/pin_comment/' .format (self .broadcast_id ),
525532 post = self .generate_signature (data )):
526- print ('Live Posted to Story!' )
527- self .unmute_comment ()
533+ print ('Comment pinned!' )
528534 return True
529535
530- self .unmute_comment ()
536+ return False
537+
538+ def unpin_comment (self ):
539+ data = json .dumps ({
540+ "_csrftoken" : self .token ,
541+ "_uid" : self .username_id ,
542+ "_uuid" : self .uuid ,
543+ "comment_id" : self .pinned_comment_id
544+ })
545+ if self .send_request (endpoint = 'live/{}/unpin_comment/' .format (self .broadcast_id ),
546+ post = self .generate_signature (data )):
547+ print ('Comment unpinned!' )
548+ return True
531549 return False
0 commit comments