10.1.6. Class cerebro.aclasses.NewAttachment

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

Bases: cerebro.aclasses.AbstractAttachment

New attachment class.

Methods

The objects of the class are used in the cerebro.events.BeforeEventMessage event in the new_attachments() method.

def before_event(event):

        evtype = event.event_type()
        if evtype == event.EVENT_CREATION_OF_MESSAGE or evtype == event.EVENT_CHANGING_OF_MESSAGE:
                new_attachs = event.new_attachments()
                for attach in new_attachs:
                        print(attach.name())    
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().

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().

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
set_name(name)[source]
Parameters:name (string) – attachment name.

Changes the name of the new attachment.

new_attachs = event.new_attachments()
for attach in new_attachs:
        if attach.is_link() != True: # if the new attachment is a file
                attach.set_name('Attachment - ' + i.name())  # changing the name