bot.twitter Module#
Methods for creating the stickers.
- exception bot.twitter.HyphenationError
Bases:
Exception
Custom exception class for hyphenation exceptions.
- bot.twitter.build_body(text, text_direction='ltr', event=None)
Builds the body for the sticker by setting the given text.
- Parameters:
text (
str
) – The text to display.text_direction (
str
) – Optional. Direction of the text. Defaults to left-to-right. If libraqm is not available, this setting will be ignored.event (
Event
) – Optional. If passed,event.is_set()
will be checked before the time consuming parts of the body creation and if the event is set, the creation will be terminated.
- Returns:
The body as Pillow image.
- Return type:
PIL.Image.Image
- bot.twitter.build_footer(timezone='UTC', event=None)
Creates the footer for the sticker by adding the current timestamp.
- Parameters:
timezone (
str
) – Optional. The timezone to use for the timestamp. Must be one of the timezones supported bypytz
. Defaults to'Europe/Berlin'
.event (
Event
) – Optional. If passed,event.is_set()
will be checked before the time consuming parts of the footer creation and if the event is set, the creation will be terminated.
- Returns:
The footer as Pillow image.
- Return type:
PIL.Image.Image
- bot.twitter.build_header(user_data, user_picture=None, event=None)
Creates the header for the sticker customized for the given user. The header will be saved as file and can be reused.
- Parameters:
user_data (
UserData
) – The user data for the user this header is build for.user_picture (
Image
) – Optional. The profile picture of the user. Defaults to the bots logo.event (
Event
) – Optional. If passed,event.is_set()
will be checked before the time consuming parts of the header creation and if the event is set, the creation will be terminated.
- Returns:
The header as Pillow image.
- Return type:
PIL.Image.Image
- async bot.twitter.build_sticker(text, user, context, event=None)
Builds the sticker.
- Parameters:
text (
str
) – Text of the tweet.user (
User
) – The user the sticker is generated for.context (
CallbackContext
[ExtBot
,UserData
,dict
,dict
]) – The callback context as provided by the application.event (
Event
) – Optional. If passed,event.is_set()
will be checked before the time consuming parts of the sticker creation and if the event is set, the creation will be terminated.
- Return type:
Image
- async bot.twitter.get_header(user, context, event=None)
Gets the header for the sticker customized for the given user. The header either be loaded from file or created anew, if there is no header for the user or users info changed.
If the header needs to be generated anew, stored stickers are deleted.
- Parameters:
user (
User
) – The Telegram user this header is build for.context (
CallbackContext
[ExtBot
,UserData
,dict
,dict
]) – Thetelegram.ext.CallbackContext
as provided by thetelegram.ext.Dispatcher
. Used to check, if for the given user an up to date header already exists.event (
Event
) – Optional. If passed,event.is_set()
will be checked before the time consuming parts of the header creation and if the event is set, the creation will be terminated.
- Returns:
The header as Pillow image.
- Return type:
PIL.Image.Image
- bot.twitter.mask_circle_transparent(image)
Cuts a circle from an square image.
- bot.twitter.shorten_text(text, max_width, font)
Shortens the given text such that it does not exceeds
max_width
pixels wrt the givenfont
. Trailing dots are added to indicate that the text was shortened.