10.1.5. Class cerebro.aclasses.Attachment

class cerebro.aclasses.Attachment(message_id, attach_id)[source]

Bases: cerebro.aclasses.AbstractAttachment

Attachment class.

Methods

attach = cerebro.core.current_attachment()
attachs = message.attachments()
add_hashtags(hashtags)[source]
Parameters:hashtags (string, set(string, ) or list(string, )) – hashtag or array of hashtags (every hashtag should be written in one word without spaces).

Adds hashtags to the attachment.

See also

remove_hashtags().

data()[source]
Returns:tuple of the attachment.
Return type:tuple

Actually, the most part of the methods of this class are interfaces to this tuple. Therefore, you can use its data directly from the tuple.

attach.file_hash() == attach.data()[attach.DATA_FILE_HASH]
attach.is_link() == (attach.data()[attach.DATA_IS_LINK] != 0)
# и так далее                   
file_hash()[source]
Returns:file hash sum.
Return type:string

File hash sum is used by the Cargador file storage to identify files. If you have a file hash sum, you can get the path to the file or enqueue the file to download if it is absent in your file storage.

if attach.is_link() != True: # Checking if the attachment is a file, not a link
        # Downloading the file          
        file_name = cerebro.cargador.file_name_form_hash(attach.file_hash()) # attempting to resolve the file name from the file hash sum
        if file_name == '' or file_name == None: # if the file is missing in our file storage, attempting to download it
                cerebro.cargador.download_file(attach.file_hash())

If attachment is a link, it has no hash, as far as the linked files, are not added to Cargador file storage

id()[source]
Returns:attachment ID.
Return type:int
message_id()[source]
Returns:the ID of the message the attachment belongs to.
Return type:int
remove_hashtags(hashtags)[source]
Parameters:hashtags (string, set(string, ) or list(string, )) – hashtag or array of hashtags (every hashtag should be written in one word without spaces).

Remove hashtags from the attachment.

See also

add_hashtags().

review_hash()[source]
Returns:file hash sum of a review file (overlayed audiovisual comments).
Return type:string
set_comment(comment)[source]
Parameters:comment (string) – a comment to the attachment.

Changes a text comment to the new attachment.

new_attachs = event.new_attachments()
for attach in new_attachs:
        if attach.is_link() == True: # if the new attachment is a link
                attach.set_comment(i.comment() + '. It's a link')  # adding a comment
thumbnail_hashs()[source]
Returns:list of the hash sums of the file’s thumbnails.
Return type:list(string,)