idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
26,300 | def wave ( self , wave_first = True , thread_id = None , thread_type = None ) : thread_id , thread_type = self . _getThread ( thread_id , thread_type ) data = self . _getSendData ( thread_id = thread_id , thread_type = thread_type ) data [ "action_type" ] = "ma-type:user-generated-message" data [ "lightweight_action_attachment[lwa_state]" ] = ( "INITIATED" if wave_first else "RECIPROCATED" ) data [ "lightweight_action_attachment[lwa_type]" ] = "WAVE" if thread_type == ThreadType . USER : data [ "specific_to_list[0]" ] = "fbid:{}" . format ( thread_id ) return self . _doSendRequest ( data ) | Says hello with a wave to a thread! |
26,301 | def quickReply ( self , quick_reply , payload = None , thread_id = None , thread_type = None ) : quick_reply . is_response = True if isinstance ( quick_reply , QuickReplyText ) : return self . send ( Message ( text = quick_reply . title , quick_replies = [ quick_reply ] ) ) elif isinstance ( quick_reply , QuickReplyLocation ) : if not isinstance ( payload , LocationAttachment ) : raise ValueError ( "Payload must be an instance of `fbchat.models.LocationAttachment`" ) return self . sendLocation ( payload , thread_id = thread_id , thread_type = thread_type ) elif isinstance ( quick_reply , QuickReplyEmail ) : if not payload : payload = self . getEmails ( ) [ 0 ] quick_reply . external_payload = quick_reply . payload quick_reply . payload = payload return self . send ( Message ( text = payload , quick_replies = [ quick_reply ] ) ) elif isinstance ( quick_reply , QuickReplyPhoneNumber ) : if not payload : payload = self . getPhoneNumbers ( ) [ 0 ] quick_reply . external_payload = quick_reply . payload quick_reply . payload = payload return self . send ( Message ( text = payload , quick_replies = [ quick_reply ] ) ) | Replies to a chosen quick reply |
26,302 | def sendLocation ( self , location , message = None , thread_id = None , thread_type = None ) : self . _sendLocation ( location = location , current = True , message = message , thread_id = thread_id , thread_type = thread_type , ) | Sends a given location to a thread as the user s current location |
26,303 | def sendPinnedLocation ( self , location , message = None , thread_id = None , thread_type = None ) : self . _sendLocation ( location = location , current = False , message = message , thread_id = thread_id , thread_type = thread_type , ) | Sends a given location to a thread as a pinned location |
26,304 | def _upload ( self , files , voice_clip = False ) : file_dict = { "upload_{}" . format ( i ) : f for i , f in enumerate ( files ) } data = { "voice_clip" : voice_clip } j = self . _postFile ( self . req_url . UPLOAD , files = file_dict , query = data , fix_request = True , as_json = True , ) if len ( j [ "payload" ] [ "metadata" ] ) != len ( files ) : raise FBchatException ( "Some files could not be uploaded: {}, {}" . format ( j , files ) ) return [ ( data [ mimetype_to_key ( data [ "filetype" ] ) ] , data [ "filetype" ] ) for data in j [ "payload" ] [ "metadata" ] ] | Uploads files to Facebook |
26,305 | def _sendFiles ( self , files , message = None , thread_id = None , thread_type = ThreadType . USER ) : thread_id , thread_type = self . _getThread ( thread_id , thread_type ) data = self . _getSendData ( message = self . _oldMessage ( message ) , thread_id = thread_id , thread_type = thread_type , ) data [ "action_type" ] = "ma-type:user-generated-message" data [ "has_attachment" ] = True for i , ( file_id , mimetype ) in enumerate ( files ) : data [ "{}s[{}]" . format ( mimetype_to_key ( mimetype ) , i ) ] = file_id return self . _doSendRequest ( data ) | Sends files from file IDs to a thread |
26,306 | def sendRemoteFiles ( self , file_urls , message = None , thread_id = None , thread_type = ThreadType . USER ) : file_urls = require_list ( file_urls ) files = self . _upload ( get_files_from_urls ( file_urls ) ) return self . _sendFiles ( files = files , message = message , thread_id = thread_id , thread_type = thread_type ) | Sends files from URLs to a thread |
26,307 | def sendLocalFiles ( self , file_paths , message = None , thread_id = None , thread_type = ThreadType . USER ) : file_paths = require_list ( file_paths ) with get_files_from_paths ( file_paths ) as x : files = self . _upload ( x ) return self . _sendFiles ( files = files , message = message , thread_id = thread_id , thread_type = thread_type ) | Sends local files to a thread |
26,308 | def sendRemoteVoiceClips ( self , clip_urls , message = None , thread_id = None , thread_type = ThreadType . USER ) : clip_urls = require_list ( clip_urls ) files = self . _upload ( get_files_from_urls ( clip_urls ) , voice_clip = True ) return self . _sendFiles ( files = files , message = message , thread_id = thread_id , thread_type = thread_type ) | Sends voice clips from URLs to a thread |
26,309 | def sendLocalVoiceClips ( self , clip_paths , message = None , thread_id = None , thread_type = ThreadType . USER ) : clip_paths = require_list ( clip_paths ) with get_files_from_paths ( clip_paths ) as x : files = self . _upload ( x , voice_clip = True ) return self . _sendFiles ( files = files , message = message , thread_id = thread_id , thread_type = thread_type ) | Sends local voice clips to a thread |
26,310 | def forwardAttachment ( self , attachment_id , thread_id = None ) : thread_id , thread_type = self . _getThread ( thread_id , None ) data = { "attachment_id" : attachment_id , "recipient_map[{}]" . format ( generateOfflineThreadingID ( ) ) : thread_id , } j = self . _post ( self . req_url . FORWARD_ATTACHMENT , data , fix_request = True , as_json = True ) | Forwards an attachment |
26,311 | def createGroup ( self , message , user_ids ) : data = self . _getSendData ( message = self . _oldMessage ( message ) ) if len ( user_ids ) < 2 : raise FBchatUserError ( "Error when creating group: Not enough participants" ) for i , user_id in enumerate ( user_ids + [ self . _uid ] ) : data [ "specific_to_list[{}]" . format ( i ) ] = "fbid:{}" . format ( user_id ) message_id , thread_id = self . _doSendRequest ( data , get_thread_id = True ) if not thread_id : raise FBchatException ( "Error when creating group: No thread_id could be found" ) return thread_id | Creates a group with the given ids |
26,312 | def addUsersToGroup ( self , user_ids , thread_id = None ) : thread_id , thread_type = self . _getThread ( thread_id , None ) data = self . _getSendData ( thread_id = thread_id , thread_type = ThreadType . GROUP ) data [ "action_type" ] = "ma-type:log-message" data [ "log_message_type" ] = "log:subscribe" user_ids = require_list ( user_ids ) for i , user_id in enumerate ( user_ids ) : if user_id == self . _uid : raise FBchatUserError ( "Error when adding users: Cannot add self to group thread" ) else : data [ "log_message_data[added_participants][{}]" . format ( i ) ] = "fbid:{}" . format ( user_id ) return self . _doSendRequest ( data ) | Adds users to a group . |
26,313 | def removeUserFromGroup ( self , user_id , thread_id = None ) : thread_id , thread_type = self . _getThread ( thread_id , None ) data = { "uid" : user_id , "tid" : thread_id } j = self . _post ( self . req_url . REMOVE_USER , data , fix_request = True , as_json = True ) | Removes users from a group . |
26,314 | def changeGroupApprovalMode ( self , require_admin_approval , thread_id = None ) : thread_id , thread_type = self . _getThread ( thread_id , None ) data = { "set_mode" : int ( require_admin_approval ) , "thread_fbid" : thread_id } j = self . _post ( self . req_url . APPROVAL_MODE , data , fix_request = True , as_json = True ) | Changes group s approval mode |
26,315 | def _changeGroupImage ( self , image_id , thread_id = None ) : thread_id , thread_type = self . _getThread ( thread_id , None ) data = { "thread_image_id" : image_id , "thread_id" : thread_id } j = self . _post ( self . req_url . THREAD_IMAGE , data , fix_request = True , as_json = True ) return image_id | Changes a thread image from an image id |
26,316 | def changeGroupImageRemote ( self , image_url , thread_id = None ) : ( image_id , mimetype ) , = self . _upload ( get_files_from_urls ( [ image_url ] ) ) return self . _changeGroupImage ( image_id , thread_id ) | Changes a thread image from a URL |
26,317 | def changeGroupImageLocal ( self , image_path , thread_id = None ) : with get_files_from_paths ( [ image_path ] ) as files : ( image_id , mimetype ) , = self . _upload ( files ) return self . _changeGroupImage ( image_id , thread_id ) | Changes a thread image from a local path |
26,318 | def changeThreadTitle ( self , title , thread_id = None , thread_type = ThreadType . USER ) : thread_id , thread_type = self . _getThread ( thread_id , thread_type ) if thread_type == ThreadType . USER : return self . changeNickname ( title , thread_id , thread_id = thread_id , thread_type = thread_type ) data = { "thread_name" : title , "thread_id" : thread_id } j = self . _post ( self . req_url . THREAD_NAME , data , fix_request = True , as_json = True ) | Changes title of a thread . If this is executed on a user thread this will change the nickname of that user effectively changing the title |
26,319 | def changeNickname ( self , nickname , user_id , thread_id = None , thread_type = ThreadType . USER ) : thread_id , thread_type = self . _getThread ( thread_id , thread_type ) data = { "nickname" : nickname , "participant_id" : user_id , "thread_or_other_fbid" : thread_id , } j = self . _post ( self . req_url . THREAD_NICKNAME , data , fix_request = True , as_json = True ) | Changes the nickname of a user in a thread |
26,320 | def reactToMessage ( self , message_id , reaction ) : data = { "action" : "ADD_REACTION" if reaction else "REMOVE_REACTION" , "client_mutation_id" : "1" , "actor_id" : self . _uid , "message_id" : str ( message_id ) , "reaction" : reaction . value if reaction else None , } data = { "doc_id" : 1491398900900362 , "variables" : json . dumps ( { "data" : data } ) } self . _post ( self . req_url . MESSAGE_REACTION , data , fix_request = True , as_json = True ) | Reacts to a message or removes reaction |
26,321 | def createPlan ( self , plan , thread_id = None ) : thread_id , thread_type = self . _getThread ( thread_id , None ) data = { "event_type" : "EVENT" , "event_time" : plan . time , "title" : plan . title , "thread_id" : thread_id , "location_id" : plan . location_id or "" , "location_name" : plan . location or "" , "acontext" : ACONTEXT , } j = self . _post ( self . req_url . PLAN_CREATE , data , fix_request = True , as_json = True ) | Sets a plan |
26,322 | def editPlan ( self , plan , new_plan ) : data = { "event_reminder_id" : plan . uid , "delete" : "false" , "date" : new_plan . time , "location_name" : new_plan . location or "" , "location_id" : new_plan . location_id or "" , "title" : new_plan . title , "acontext" : ACONTEXT , } j = self . _post ( self . req_url . PLAN_CHANGE , data , fix_request = True , as_json = True ) | Edits a plan |
26,323 | def deletePlan ( self , plan ) : data = { "event_reminder_id" : plan . uid , "delete" : "true" , "acontext" : ACONTEXT } j = self . _post ( self . req_url . PLAN_CHANGE , data , fix_request = True , as_json = True ) | Deletes a plan |
26,324 | def changePlanParticipation ( self , plan , take_part = True ) : data = { "event_reminder_id" : plan . uid , "guest_state" : "GOING" if take_part else "DECLINED" , "acontext" : ACONTEXT , } j = self . _post ( self . req_url . PLAN_PARTICIPATION , data , fix_request = True , as_json = True ) | Changes participation in a plan |
26,325 | def createPoll ( self , poll , thread_id = None ) : thread_id , thread_type = self . _getThread ( thread_id , None ) data = OrderedDict ( [ ( "question_text" , poll . title ) , ( "target_id" , thread_id ) ] ) for i , option in enumerate ( poll . options ) : data [ "option_text_array[{}]" . format ( i ) ] = option . text data [ "option_is_selected_array[{}]" . format ( i ) ] = str ( int ( option . vote ) ) j = self . _post ( self . req_url . CREATE_POLL , data , fix_request = True , as_json = True ) | Creates poll in a group thread |
26,326 | def updatePollVote ( self , poll_id , option_ids = [ ] , new_options = [ ] ) : data = { "question_id" : poll_id } for i , option_id in enumerate ( option_ids ) : data [ "selected_options[{}]" . format ( i ) ] = option_id for i , option_text in enumerate ( new_options ) : data [ "new_options[{}]" . format ( i ) ] = option_text j = self . _post ( self . req_url . UPDATE_VOTE , data , fix_request = True , as_json = True ) | Updates a poll vote |
26,327 | def setTypingStatus ( self , status , thread_id = None , thread_type = None ) : thread_id , thread_type = self . _getThread ( thread_id , thread_type ) data = { "typ" : status . value , "thread" : thread_id , "to" : thread_id if thread_type == ThreadType . USER else "" , "source" : "mercury-chat" , } j = self . _post ( self . req_url . TYPING , data , fix_request = True , as_json = True ) | Sets users typing status in a thread |
26,328 | def markAsDelivered ( self , thread_id , message_id ) : data = { "message_ids[0]" : message_id , "thread_ids[%s][0]" % thread_id : message_id , } r = self . _post ( self . req_url . DELIVERED , data ) return r . ok | Mark a message as delivered |
26,329 | def removeFriend ( self , friend_id = None ) : payload = { "friend_id" : friend_id , "unref" : "none" , "confirm" : "Confirm" } r = self . _post ( self . req_url . REMOVE_FRIEND , payload ) query = parse_qs ( urlparse ( r . url ) . query ) if "err" not in query : log . debug ( "Remove was successful!" ) return True else : log . warning ( "Error while removing friend" ) return False | Removes a specifed friend from your friend list |
26,330 | def blockUser ( self , user_id ) : data = { "fbid" : user_id } r = self . _post ( self . req_url . BLOCK_USER , data ) return r . ok | Blocks messages from a specifed user |
26,331 | def unblockUser ( self , user_id ) : data = { "fbid" : user_id } r = self . _post ( self . req_url . UNBLOCK_USER , data ) return r . ok | Unblocks messages from a blocked user |
26,332 | def moveThreads ( self , location , thread_ids ) : thread_ids = require_list ( thread_ids ) if location == ThreadLocation . PENDING : location = ThreadLocation . OTHER if location == ThreadLocation . ARCHIVED : data_archive = dict ( ) data_unpin = dict ( ) for thread_id in thread_ids : data_archive [ "ids[{}]" . format ( thread_id ) ] = "true" data_unpin [ "ids[{}]" . format ( thread_id ) ] = "false" r_archive = self . _post ( self . req_url . ARCHIVED_STATUS , data_archive ) r_unpin = self . _post ( self . req_url . PINNED_STATUS , data_unpin ) return r_archive . ok and r_unpin . ok else : data = dict ( ) for i , thread_id in enumerate ( thread_ids ) : data [ "{}[{}]" . format ( location . name . lower ( ) , i ) ] = thread_id r = self . _post ( self . req_url . MOVE_THREAD , data ) return r . ok | Moves threads to specifed location |
26,333 | def markAsSpam ( self , thread_id = None ) : thread_id , thread_type = self . _getThread ( thread_id , None ) r = self . _post ( self . req_url . MARK_SPAM , { "id" : thread_id } ) return r . ok | Mark a thread as spam and delete it |
26,334 | def deleteMessages ( self , message_ids ) : message_ids = require_list ( message_ids ) data = dict ( ) for i , message_id in enumerate ( message_ids ) : data [ "message_ids[{}]" . format ( i ) ] = message_id r = self . _post ( self . req_url . DELETE_MESSAGES , data ) return r . ok | Deletes specifed messages |
26,335 | def muteThreadReactions ( self , mute = True , thread_id = None ) : thread_id , thread_type = self . _getThread ( thread_id , None ) data = { "reactions_mute_mode" : int ( mute ) , "thread_fbid" : thread_id } r = self . _post ( self . req_url . MUTE_REACTIONS , data , fix_request = True ) | Mutes thread reactions |
26,336 | def muteThreadMentions ( self , mute = True , thread_id = None ) : thread_id , thread_type = self . _getThread ( thread_id , None ) data = { "mentions_mute_mode" : int ( mute ) , "thread_fbid" : thread_id } r = self . _post ( self . req_url . MUTE_MENTIONS , data , fix_request = True ) | Mutes thread mentions |
26,337 | def _pullMessage ( self ) : data = { "msgs_recv" : 0 , "sticky_token" : self . _sticky , "sticky_pool" : self . _pool , "clientid" : self . _client_id , "state" : "active" if self . _markAlive else "offline" , } return self . _get ( self . req_url . STICKY , data , fix_request = True , as_json = True ) | Call pull api with seq value to get message data . |
26,338 | def _parseMessage ( self , content ) : self . _seq = content . get ( "seq" , "0" ) if "lb_info" in content : self . _sticky = content [ "lb_info" ] [ "sticky" ] self . _pool = content [ "lb_info" ] [ "pool" ] if "batches" in content : for batch in content [ "batches" ] : self . _parseMessage ( batch ) if "ms" not in content : return for m in content [ "ms" ] : mtype = m . get ( "type" ) try : if mtype == "delta" : self . _parseDelta ( m ) elif mtype == "inbox" : self . onInbox ( unseen = m [ "unseen" ] , unread = m [ "unread" ] , recent_unread = m [ "recent_unread" ] , msg = m , ) elif mtype == "typ" or mtype == "ttyp" : author_id = str ( m . get ( "from" ) ) thread_id = m . get ( "thread_fbid" ) if thread_id : thread_type = ThreadType . GROUP thread_id = str ( thread_id ) else : thread_type = ThreadType . USER if author_id == self . _uid : thread_id = m . get ( "to" ) else : thread_id = author_id typing_status = TypingStatus ( m . get ( "st" ) ) self . onTyping ( author_id = author_id , status = typing_status , thread_id = thread_id , thread_type = thread_type , msg = m , ) elif mtype in [ "jewel_requests_add" ] : from_id = m [ "from" ] self . onFriendRequest ( from_id = from_id , msg = m ) elif mtype == "qprimer" : self . onQprimer ( ts = m . get ( "made" ) , msg = m ) elif mtype == "deltaflow" : pass elif mtype == "chatproxy-presence" : statuses = dict ( ) for id_ , data in m . get ( "buddyList" , { } ) . items ( ) : statuses [ id_ ] = ActiveStatus . _from_chatproxy_presence ( id_ , data ) self . _buddylist [ id_ ] = statuses [ id_ ] self . onChatTimestamp ( buddylist = statuses , msg = m ) elif mtype == "buddylist_overlay" : statuses = dict ( ) for id_ , data in m . get ( "overlay" , { } ) . items ( ) : old_in_game = None if id_ in self . _buddylist : old_in_game = self . _buddylist [ id_ ] . in_game statuses [ id_ ] = ActiveStatus . _from_buddylist_overlay ( data , old_in_game ) self . _buddylist [ id_ ] = statuses [ id_ ] self . onBuddylistOverlay ( statuses = statuses , msg = m ) else : self . onUnknownMesssageType ( msg = m ) except Exception as e : self . onMessageError ( exception = e , msg = m ) | Get message and author name from content . May contain multiple messages in the content . |
26,339 | def doOneListen ( self , markAlive = None ) : if markAlive is not None : self . _markAlive = markAlive try : if self . _markAlive : self . _ping ( ) content = self . _pullMessage ( ) if content : self . _parseMessage ( content ) except KeyboardInterrupt : return False except requests . Timeout : pass except requests . ConnectionError : time . sleep ( 30 ) except FBchatFacebookError as e : if e . request_status_code in [ 502 , 503 ] : self . req_url . change_pull_channel ( ) self . startListening ( ) else : raise e except Exception as e : return self . onListenError ( exception = e ) return True | Does one cycle of the listening loop . This method is useful if you want to control fbchat from an external event loop |
26,340 | def listen ( self , markAlive = None ) : if markAlive is not None : self . setActiveStatus ( markAlive ) self . startListening ( ) self . onListening ( ) while self . listening and self . doOneListen ( ) : pass self . stopListening ( ) | Initializes and runs the listening loop continually |
26,341 | def onMessage ( self , mid = None , author_id = None , message = None , message_object = None , thread_id = None , thread_type = ThreadType . USER , ts = None , metadata = None , msg = None , ) : log . info ( "{} from {} in {}" . format ( message_object , thread_id , thread_type . name ) ) | Called when the client is listening and somebody sends a message |
26,342 | def onColorChange ( self , mid = None , author_id = None , new_color = None , thread_id = None , thread_type = ThreadType . USER , ts = None , metadata = None , msg = None , ) : log . info ( "Color change from {} in {} ({}): {}" . format ( author_id , thread_id , thread_type . name , new_color ) ) | Called when the client is listening and somebody changes a thread s color |
26,343 | def onEmojiChange ( self , mid = None , author_id = None , new_emoji = None , thread_id = None , thread_type = ThreadType . USER , ts = None , metadata = None , msg = None , ) : log . info ( "Emoji change from {} in {} ({}): {}" . format ( author_id , thread_id , thread_type . name , new_emoji ) ) | Called when the client is listening and somebody changes a thread s emoji |
26,344 | def onTitleChange ( self , mid = None , author_id = None , new_title = None , thread_id = None , thread_type = ThreadType . USER , ts = None , metadata = None , msg = None , ) : log . info ( "Title change from {} in {} ({}): {}" . format ( author_id , thread_id , thread_type . name , new_title ) ) | Called when the client is listening and somebody changes the title of a thread |
26,345 | def onImageChange ( self , mid = None , author_id = None , new_image = None , thread_id = None , thread_type = ThreadType . GROUP , ts = None , msg = None , ) : log . info ( "{} changed thread image in {}" . format ( author_id , thread_id ) ) | Called when the client is listening and somebody changes the image of a thread |
26,346 | def onNicknameChange ( self , mid = None , author_id = None , changed_for = None , new_nickname = None , thread_id = None , thread_type = ThreadType . USER , ts = None , metadata = None , msg = None , ) : log . info ( "Nickname change from {} in {} ({}) for {}: {}" . format ( author_id , thread_id , thread_type . name , changed_for , new_nickname ) ) | Called when the client is listening and somebody changes the nickname of a person |
26,347 | def onAdminAdded ( self , mid = None , added_id = None , author_id = None , thread_id = None , thread_type = ThreadType . GROUP , ts = None , msg = None , ) : log . info ( "{} added admin: {} in {}" . format ( author_id , added_id , thread_id ) ) | Called when the client is listening and somebody adds an admin to a group thread |
26,348 | def onAdminRemoved ( self , mid = None , removed_id = None , author_id = None , thread_id = None , thread_type = ThreadType . GROUP , ts = None , msg = None , ) : log . info ( "{} removed admin: {} in {}" . format ( author_id , removed_id , thread_id ) ) | Called when the client is listening and somebody removes an admin from a group thread |
26,349 | def onApprovalModeChange ( self , mid = None , approval_mode = None , author_id = None , thread_id = None , thread_type = ThreadType . GROUP , ts = None , msg = None , ) : if approval_mode : log . info ( "{} activated approval mode in {}" . format ( author_id , thread_id ) ) else : log . info ( "{} disabled approval mode in {}" . format ( author_id , thread_id ) ) | Called when the client is listening and somebody changes approval mode in a group thread |
26,350 | def onMessageSeen ( self , seen_by = None , thread_id = None , thread_type = ThreadType . USER , seen_ts = None , ts = None , metadata = None , msg = None , ) : log . info ( "Messages seen by {} in {} ({}) at {}s" . format ( seen_by , thread_id , thread_type . name , seen_ts / 1000 ) ) | Called when the client is listening and somebody marks a message as seen |
26,351 | def onMessageDelivered ( self , msg_ids = None , delivered_for = None , thread_id = None , thread_type = ThreadType . USER , ts = None , metadata = None , msg = None , ) : log . info ( "Messages {} delivered to {} in {} ({}) at {}s" . format ( msg_ids , delivered_for , thread_id , thread_type . name , ts / 1000 ) ) | Called when the client is listening and somebody marks messages as delivered |
26,352 | def onMarkedSeen ( self , threads = None , seen_ts = None , ts = None , metadata = None , msg = None ) : log . info ( "Marked messages as seen in threads {} at {}s" . format ( [ ( x [ 0 ] , x [ 1 ] . name ) for x in threads ] , seen_ts / 1000 ) ) | Called when the client is listening and the client has successfully marked threads as seen |
26,353 | def onPeopleAdded ( self , mid = None , added_ids = None , author_id = None , thread_id = None , ts = None , msg = None , ) : log . info ( "{} added: {} in {}" . format ( author_id , ", " . join ( added_ids ) , thread_id ) ) | Called when the client is listening and somebody adds people to a group thread |
26,354 | def onPersonRemoved ( self , mid = None , removed_id = None , author_id = None , thread_id = None , ts = None , msg = None , ) : log . info ( "{} removed: {} in {}" . format ( author_id , removed_id , thread_id ) ) | Called when the client is listening and somebody removes a person from a group thread |
26,355 | def onGamePlayed ( self , mid = None , author_id = None , game_id = None , game_name = None , score = None , leaderboard = None , thread_id = None , thread_type = None , ts = None , metadata = None , msg = None , ) : log . info ( '{} played "{}" in {} ({})' . format ( author_id , game_name , thread_id , thread_type . name ) ) | Called when the client is listening and somebody plays a game |
26,356 | def onReactionAdded ( self , mid = None , reaction = None , author_id = None , thread_id = None , thread_type = None , ts = None , msg = None , ) : log . info ( "{} reacted to message {} with {} in {} ({})" . format ( author_id , mid , reaction . name , thread_id , thread_type . name ) ) | Called when the client is listening and somebody reacts to a message |
26,357 | def onReactionRemoved ( self , mid = None , author_id = None , thread_id = None , thread_type = None , ts = None , msg = None , ) : log . info ( "{} removed reaction from {} message in {} ({})" . format ( author_id , mid , thread_id , thread_type ) ) | Called when the client is listening and somebody removes reaction from a message |
26,358 | def onBlock ( self , author_id = None , thread_id = None , thread_type = None , ts = None , msg = None ) : log . info ( "{} blocked {} ({}) thread" . format ( author_id , thread_id , thread_type . name ) ) | Called when the client is listening and somebody blocks client |
26,359 | def onLiveLocation ( self , mid = None , location = None , author_id = None , thread_id = None , thread_type = None , ts = None , msg = None , ) : log . info ( "{} sent live location info in {} ({}) with latitude {} and longitude {}" . format ( author_id , thread_id , thread_type , location . latitude , location . longitude ) ) | Called when the client is listening and somebody sends live location info |
26,360 | def onUserJoinedCall ( self , mid = None , joined_id = None , is_video_call = None , thread_id = None , thread_type = None , ts = None , metadata = None , msg = None , ) : log . info ( "{} joined call in {} ({})" . format ( joined_id , thread_id , thread_type . name ) ) | Called when the client is listening and somebody joins a group call |
26,361 | def onPollCreated ( self , mid = None , poll = None , author_id = None , thread_id = None , thread_type = None , ts = None , metadata = None , msg = None , ) : log . info ( "{} created poll {} in {} ({})" . format ( author_id , poll , thread_id , thread_type . name ) ) | Called when the client is listening and somebody creates a group poll |
26,362 | def onPollVoted ( self , mid = None , poll = None , added_options = None , removed_options = None , author_id = None , thread_id = None , thread_type = None , ts = None , metadata = None , msg = None , ) : log . info ( "{} voted in poll {} in {} ({})" . format ( author_id , poll , thread_id , thread_type . name ) ) | Called when the client is listening and somebody votes in a group poll |
26,363 | def onPlanDeleted ( self , mid = None , plan = None , author_id = None , thread_id = None , thread_type = None , ts = None , metadata = None , msg = None , ) : log . info ( "{} deleted plan {} in {} ({})" . format ( author_id , plan , thread_id , thread_type . name ) ) | Called when the client is listening and somebody deletes a plan |
26,364 | def onPlanParticipation ( self , mid = None , plan = None , take_part = None , author_id = None , thread_id = None , thread_type = None , ts = None , metadata = None , msg = None , ) : if take_part : log . info ( "{} will take part in {} in {} ({})" . format ( author_id , plan , thread_id , thread_type . name ) ) else : log . info ( "{} won't take part in {} in {} ({})" . format ( author_id , plan , thread_id , thread_type . name ) ) | Called when the client is listening and somebody takes part in a plan or not |
26,365 | def graphql_queries_to_json ( * queries ) : rtn = { } for i , query in enumerate ( queries ) : rtn [ "q{}" . format ( i ) ] = query . value return json . dumps ( rtn ) | Queries should be a list of GraphQL objects |
26,366 | def get_tags ( ) : tags = getattr ( flask . g , 'bukudb' , get_bukudb ( ) ) . get_tag_all ( ) result = { 'tags' : tags [ 0 ] } if request . path . startswith ( '/api/' ) : res = jsonify ( result ) else : res = render_template ( 'bukuserver/tags.html' , result = result ) return res | get tags . |
26,367 | def create_app ( config_filename = None ) : app = FlaskAPI ( __name__ ) per_page = int ( os . getenv ( 'BUKUSERVER_PER_PAGE' , str ( views . DEFAULT_PER_PAGE ) ) ) per_page = per_page if per_page > 0 else views . DEFAULT_PER_PAGE app . config [ 'BUKUSERVER_PER_PAGE' ] = per_page url_render_mode = os . getenv ( 'BUKUSERVER_URL_RENDER_MODE' , views . DEFAULT_URL_RENDER_MODE ) if url_render_mode not in ( 'full' , 'netloc' ) : url_render_mode = views . DEFAULT_URL_RENDER_MODE app . config [ 'BUKUSERVER_URL_RENDER_MODE' ] = url_render_mode app . config [ 'SECRET_KEY' ] = os . getenv ( 'BUKUSERVER_SECRET_KEY' ) or os . urandom ( 24 ) app . config [ 'BUKUSERVER_DB_FILE' ] = os . getenv ( 'BUKUSERVER_DB_FILE' ) bukudb = BukuDb ( dbfile = app . config [ 'BUKUSERVER_DB_FILE' ] ) app . app_context ( ) . push ( ) setattr ( flask . g , 'bukudb' , bukudb ) @ app . shell_context_processor def shell_context ( ) : return { 'app' : app , 'bukudb' : bukudb } app . jinja_env . filters [ 'netloc' ] = lambda x : urlparse ( x ) . netloc Bootstrap ( app ) admin = Admin ( app , name = 'Buku Server' , template_mode = 'bootstrap3' , index_view = views . CustomAdminIndexView ( template = 'bukuserver/home.html' , url = '/' ) ) app . add_url_rule ( '/api/tags' , 'get_tags' , tag_list , methods = [ 'GET' ] ) app . add_url_rule ( '/api/tags/<tag>' , 'update_tag' , tag_detail , methods = [ 'GET' , 'PUT' ] ) app . add_url_rule ( '/api/network_handle' , 'networkk_handle' , network_handle_detail , methods = [ 'POST' ] ) app . add_url_rule ( '/api/bookmarks' , 'bookmarks' , bookmarks , methods = [ 'GET' , 'POST' , 'DELETE' ] ) app . add_url_rule ( '/api/bookmarks/refresh' , 'refresh_bookmarks' , refresh_bookmarks , methods = [ 'POST' ] ) app . add_url_rule ( '/api/bookmarks/<id>' , 'bookmark_api' , bookmark_api , methods = [ 'GET' , 'PUT' , 'DELETE' ] ) app . add_url_rule ( '/api/bookmarks/<id>/refresh' , 'refresh_bookmark' , refresh_bookmark , methods = [ 'POST' ] ) app . add_url_rule ( '/api/bookmarks/<id>/tiny' , 'get_tiny_url' , get_tiny_url , methods = [ 'GET' ] ) app . add_url_rule ( '/api/bookmarks/<id>/long' , 'get_long_url' , get_long_url , methods = [ 'GET' ] ) app . add_url_rule ( '/api/bookmarks/<starting_id>/<ending_id>' , 'bookmark_range_operations' , bookmark_range_operations , methods = [ 'GET' , 'PUT' , 'DELETE' ] ) app . add_url_rule ( '/api/bookmarks/search' , 'search_bookmarks' , search_bookmarks , methods = [ 'GET' , 'DELETE' ] ) admin . add_view ( views . BookmarkModelView ( bukudb , 'Bookmarks' , page_size = per_page , url_render_mode = url_render_mode ) ) admin . add_view ( views . TagModelView ( bukudb , 'Tags' , page_size = per_page ) ) admin . add_view ( views . StatisticView ( bukudb , 'Statistic' , endpoint = 'statistic' ) ) return app | create app . |
26,368 | def search ( self ) : "redirect to bookmark search" form = forms . HomeForm ( ) bbm_filter = bs_filters . BookmarkBukuFilter ( all_keywords = False , deep = form . deep . data , regex = form . regex . data ) op_text = bbm_filter . operation ( ) values_combi = sorted ( itertools . product ( [ True , False ] , repeat = 3 ) ) for idx , ( all_keywords , deep , regex ) in enumerate ( values_combi ) : if deep == form . deep . data and regex == form . regex . data and not all_keywords : choosen_idx = idx url_op_text = op_text . replace ( ', ' , '_' ) . replace ( ' ' , ' ' ) . replace ( ' ' , '_' ) key = '' . join ( [ 'flt' , str ( choosen_idx ) , '_buku_' , url_op_text ] ) kwargs = { key : form . keyword . data } url = url_for ( 'bookmark.index_view' , ** kwargs ) return redirect ( url ) | redirect to bookmark search |
26,369 | def autolink ( self , link , is_email = False ) : text = link = escape_link ( link ) if is_email : link = 'mailto:%s' % link return '<a href="%s">%s</a>' % ( link , text ) | Rendering a given link or email address . |
26,370 | def init ( * args , ** kwargs ) : global _initial_client client = Client ( * args , ** kwargs ) Hub . current . bind_client ( client ) rv = _InitGuard ( client ) if client is not None : _initial_client = weakref . ref ( client ) return rv | Initializes the SDK and optionally integrations . |
26,371 | def current ( self ) : rv = _local . get ( None ) if rv is None : rv = Hub ( GLOBAL_HUB ) _local . set ( rv ) return rv | Returns the current instance of the hub . |
26,372 | def get_integration ( self , name_or_class ) : if isinstance ( name_or_class , str ) : integration_name = name_or_class elif name_or_class . identifier is not None : integration_name = name_or_class . identifier else : raise ValueError ( "Integration has no name" ) client = self . _stack [ - 1 ] [ 0 ] if client is not None : rv = client . integrations . get ( integration_name ) if rv is not None : return rv initial_client = _initial_client if initial_client is not None : initial_client = initial_client ( ) if ( initial_client is not None and initial_client is not client and initial_client . integrations . get ( name_or_class ) is not None ) : warning = ( "Integration %r attempted to run but it was only " "enabled on init() but not the client that " "was bound to the current flow. Earlier versions of " "the SDK would consider these integrations enabled but " "this is no longer the case." % ( name_or_class , ) ) warn ( Warning ( warning ) , stacklevel = 3 ) logger . warning ( warning ) | Returns the integration for this hub by name or class . If there is no client bound or the client does not have that integration then None is returned . |
26,373 | def bind_client ( self , new ) : top = self . _stack [ - 1 ] self . _stack [ - 1 ] = ( new , top [ 1 ] ) | Binds a new client to the hub . |
26,374 | def capture_event ( self , event , hint = None ) : client , scope = self . _stack [ - 1 ] if client is not None : rv = client . capture_event ( event , hint , scope ) if rv is not None : self . _last_event_id = rv return rv return None | Captures an event . The return value is the ID of the event . |
26,375 | def capture_message ( self , message , level = None ) : if self . client is None : return None if level is None : level = "info" return self . capture_event ( { "message" : message , "level" : level } ) | Captures a message . The message is just a string . If no level is provided the default level is info . |
26,376 | def capture_exception ( self , error = None ) : client = self . client if client is None : return None if error is None : exc_info = sys . exc_info ( ) else : exc_info = exc_info_from_error ( error ) event , hint = event_from_exception ( exc_info , client_options = client . options ) try : return self . capture_event ( event , hint = hint ) except Exception : self . _capture_internal_exception ( sys . exc_info ( ) ) return None | Captures an exception . |
26,377 | def push_scope ( self , callback = None ) : if callback is not None : with self . push_scope ( ) as scope : callback ( scope ) return None client , scope = self . _stack [ - 1 ] new_layer = ( client , copy . copy ( scope ) ) self . _stack . append ( new_layer ) return _ScopeManager ( self ) | Pushes a new layer on the scope stack . Returns a context manager that should be used to pop the scope again . Alternatively a callback can be provided that is executed in the context of the scope . |
26,378 | def configure_scope ( self , callback = None ) : client , scope = self . _stack [ - 1 ] if callback is not None : if client is not None : callback ( scope ) return None @ contextmanager def inner ( ) : if client is not None : yield scope else : yield Scope ( ) return inner ( ) | Reconfigures the scope . |
26,379 | def flush ( self , timeout = None , callback = None ) : client , scope = self . _stack [ - 1 ] if client is not None : return client . flush ( timeout = timeout , callback = callback ) | Alias for self . client . flush |
26,380 | def capture_event ( self , event , hint = None , scope = None ) : if self . transport is None : return None if hint is None : hint = { } rv = event . get ( "event_id" ) if rv is None : event [ "event_id" ] = rv = uuid . uuid4 ( ) . hex if not self . _should_capture ( event , hint , scope ) : return None event = self . _prepare_event ( event , hint , scope ) if event is None : return None self . transport . capture_event ( event ) return rv | Captures an event . |
26,381 | def flush ( self , timeout = None , callback = None ) : if self . transport is not None : if timeout is None : timeout = self . options [ "shutdown_timeout" ] self . transport . flush ( timeout = timeout , callback = callback ) | Wait timeout seconds for the current events to be sent . If no timeout is provided the shutdown_timeout option value is used . |
26,382 | def setup_integrations ( integrations , with_defaults = True ) : integrations = dict ( ( integration . identifier , integration ) for integration in integrations or ( ) ) logger . debug ( "Setting up integrations (with default = %s)" , with_defaults ) if with_defaults : for integration_cls in iter_default_integrations ( ) : if integration_cls . identifier not in integrations : instance = integration_cls ( ) integrations [ instance . identifier ] = instance for identifier , integration in iteritems ( integrations ) : with _installer_lock : if identifier not in _installed_integrations : logger . debug ( "Setting up previously not enabled integration %s" , identifier ) try : type ( integration ) . setup_once ( ) except NotImplementedError : if getattr ( integration , "install" , None ) is not None : logger . warn ( "Integration %s: The install method is " "deprecated. Use `setup_once`." , identifier , ) integration . install ( ) else : raise _installed_integrations . add ( identifier ) for identifier in integrations : logger . debug ( "Enabling integration %s" , identifier ) return integrations | Given a list of integration instances this installs them all . When with_defaults is set to True then all default integrations are added unless they were already provided before . |
26,383 | def clear ( self ) : self . _level = None self . _fingerprint = None self . _transaction = None self . _user = None self . _tags = { } self . _contexts = { } self . _extras = { } self . clear_breadcrumbs ( ) self . _should_capture = True self . _span = None | Clears the entire scope . |
26,384 | def add_error_processor ( self , func , cls = None ) : if cls is not None : real_func = func def func ( event , exc_info ) : try : is_inst = isinstance ( exc_info [ 1 ] , cls ) except Exception : is_inst = False if is_inst : return real_func ( event , exc_info ) return event self . _error_processors . append ( func ) | Register a scope local error processor on the scope . |
26,385 | def apply_to_event ( self , event , hint = None ) : def _drop ( event , cause , ty ) : logger . info ( "%s (%s) dropped event (%s)" , ty , cause , event ) return None if self . _level is not None : event [ "level" ] = self . _level event . setdefault ( "breadcrumbs" , [ ] ) . extend ( self . _breadcrumbs ) if event . get ( "user" ) is None and self . _user is not None : event [ "user" ] = self . _user if event . get ( "transaction" ) is None and self . _transaction is not None : event [ "transaction" ] = self . _transaction if event . get ( "fingerprint" ) is None and self . _fingerprint is not None : event [ "fingerprint" ] = self . _fingerprint if self . _extras : event . setdefault ( "extra" , { } ) . update ( object_to_json ( self . _extras ) ) if self . _tags : event . setdefault ( "tags" , { } ) . update ( self . _tags ) if self . _contexts : event . setdefault ( "contexts" , { } ) . update ( self . _contexts ) if self . _span is not None : event . setdefault ( "contexts" , { } ) [ "trace" ] = { "trace_id" : self . _span . trace_id , "span_id" : self . _span . span_id , } exc_info = hint . get ( "exc_info" ) if hint is not None else None if exc_info is not None : for processor in self . _error_processors : new_event = processor ( event , exc_info ) if new_event is None : return _drop ( event , processor , "error processor" ) event = new_event for processor in chain ( global_event_processors , self . _event_processors ) : new_event = event with capture_internal_exceptions ( ) : new_event = processor ( event , hint ) if new_event is None : return _drop ( event , processor , "event processor" ) event = new_event return event | Applies the information contained on the scope to the given event . |
26,386 | def default_callback ( pending , timeout ) : def echo ( msg ) : sys . stderr . write ( msg + "\n" ) echo ( "Sentry is attempting to send %i pending error messages" % pending ) echo ( "Waiting up to %s seconds" % timeout ) echo ( "Press Ctrl-%s to quit" % ( os . name == "nt" and "Break" or "C" ) ) sys . stderr . flush ( ) | This is the default shutdown callback that is set on the options . It prints out a message to stderr that informs the user that some events are still pending and the process is waiting for them to flush out . |
26,387 | def get_host ( environ ) : if environ . get ( "HTTP_HOST" ) : rv = environ [ "HTTP_HOST" ] if environ [ "wsgi.url_scheme" ] == "http" and rv . endswith ( ":80" ) : rv = rv [ : - 3 ] elif environ [ "wsgi.url_scheme" ] == "https" and rv . endswith ( ":443" ) : rv = rv [ : - 4 ] elif environ . get ( "SERVER_NAME" ) : rv = environ [ "SERVER_NAME" ] if ( environ [ "wsgi.url_scheme" ] , environ [ "SERVER_PORT" ] ) not in ( ( "https" , "443" ) , ( "http" , "80" ) , ) : rv += ":" + environ [ "SERVER_PORT" ] else : rv = "unknown" return rv | Return the host for the given WSGI environment . Yanked from Werkzeug . |
26,388 | def get_request_url ( environ ) : return "%s://%s/%s" % ( environ . get ( "wsgi.url_scheme" ) , get_host ( environ ) , wsgi_decoding_dance ( environ . get ( "PATH_INFO" ) or "" ) . lstrip ( "/" ) , ) | Return the absolute URL without query string for the given WSGI environment . |
26,389 | def _get_environ ( environ ) : keys = [ "SERVER_NAME" , "SERVER_PORT" ] if _should_send_default_pii ( ) : keys += [ "REMOTE_ADDR" , "HTTP_X_FORWARDED_FOR" , "HTTP_X_REAL_IP" ] for key in keys : if key in environ : yield key , environ [ key ] | Returns our whitelisted environment variables . |
26,390 | def get_client_ip ( environ ) : try : return environ [ "HTTP_X_FORWARDED_FOR" ] . split ( "," ) [ 0 ] . strip ( ) except ( KeyError , IndexError ) : pass try : return environ [ "HTTP_X_REAL_IP" ] except KeyError : pass return environ . get ( "REMOTE_ADDR" ) | Infer the user IP address from various headers . This cannot be used in security sensitive situations since the value may be forged from a client but it s good enough for the event payload . |
26,391 | def event_hint_with_exc_info ( exc_info = None ) : if exc_info is None : exc_info = sys . exc_info ( ) else : exc_info = exc_info_from_error ( exc_info ) if exc_info [ 0 ] is None : exc_info = None return { "exc_info" : exc_info } | Creates a hint with the exc info filled in . |
26,392 | def format_and_strip ( template , params , strip_string = strip_string ) : chunks = template . split ( u"%s" ) if not chunks : raise ValueError ( "No formatting placeholders found" ) params = list ( reversed ( params ) ) rv_remarks = [ ] rv_original_length = 0 rv_length = 0 rv = [ ] def realign_remark ( remark ) : return [ ( rv_length + x if isinstance ( x , int_types ) and i < 4 else x ) for i , x in enumerate ( remark ) ] for chunk in chunks [ : - 1 ] : rv . append ( chunk ) rv_length += len ( chunk ) rv_original_length += len ( chunk ) if not params : raise ValueError ( "Not enough params." ) param = params . pop ( ) stripped_param = strip_string ( param ) if isinstance ( stripped_param , AnnotatedValue ) : rv_remarks . extend ( realign_remark ( remark ) for remark in stripped_param . metadata [ "rem" ] ) stripped_param = stripped_param . value rv_original_length += len ( param ) rv_length += len ( stripped_param ) rv . append ( stripped_param ) rv . append ( chunks [ - 1 ] ) rv_length += len ( chunks [ - 1 ] ) rv_original_length += len ( chunks [ - 1 ] ) rv = u"" . join ( rv ) assert len ( rv ) == rv_length if not rv_remarks : return rv return AnnotatedValue ( value = rv , metadata = { "len" : rv_original_length , "rem" : rv_remarks } ) | Format a string containing %s for placeholders and call strip_string on each parameter . The string template itself does not have a maximum length . |
26,393 | def store_api_url ( self ) : return "%s://%s%sapi/%s/store/" % ( self . scheme , self . host , self . path , self . project_id , ) | Returns the API url for storing events . |
26,394 | def to_header ( self , timestamp = None ) : rv = [ ( "sentry_key" , self . public_key ) , ( "sentry_version" , self . version ) ] if timestamp is not None : rv . append ( ( "sentry_timestamp" , str ( to_timestamp ( timestamp ) ) ) ) if self . client is not None : rv . append ( ( "sentry_client" , self . client ) ) if self . secret_key is not None : rv . append ( ( "sentry_secret" , self . secret_key ) ) return u"Sentry " + u", " . join ( "%s=%s" % ( key , value ) for key , value in rv ) | Returns the auth header a string . |
26,395 | def _register_bounds_validator_if_needed ( parser , name , flag_values ) : if parser . lower_bound is not None or parser . upper_bound is not None : def checker ( value ) : if value is not None and parser . is_outside_bounds ( value ) : message = '%s is not %s' % ( value , parser . syntactic_help ) raise _exceptions . ValidationError ( message ) return True _validators . register_validator ( name , checker , flag_values = flag_values ) | Enforces lower and upper bounds for numeric flags . |
26,396 | def DEFINE ( parser , name , default , help , flag_values = _flagvalues . FLAGS , serializer = None , module_name = None , ** args ) : DEFINE_flag ( _flag . Flag ( parser , serializer , name , default , help , ** args ) , flag_values , module_name ) | Registers a generic Flag object . |
26,397 | def DEFINE_string ( name , default , help , flag_values = _flagvalues . FLAGS , ** args ) : parser = _argument_parser . ArgumentParser ( ) serializer = _argument_parser . ArgumentSerializer ( ) DEFINE ( parser , name , default , help , flag_values , serializer , ** args ) | Registers a flag whose value can be any string . |
26,398 | def DEFINE_boolean ( name , default , help , flag_values = _flagvalues . FLAGS , module_name = None , ** args ) : DEFINE_flag ( _flag . BooleanFlag ( name , default , help , ** args ) , flag_values , module_name ) | Registers a boolean flag . |
26,399 | def DEFINE_float ( name , default , help , lower_bound = None , upper_bound = None , flag_values = _flagvalues . FLAGS , ** args ) : parser = _argument_parser . FloatParser ( lower_bound , upper_bound ) serializer = _argument_parser . ArgumentSerializer ( ) DEFINE ( parser , name , default , help , flag_values , serializer , ** args ) _register_bounds_validator_if_needed ( parser , name , flag_values = flag_values ) | Registers a flag whose value must be a float . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.