twtb.logic.shared.db.sharing_message#

Makes possible sharing messages between client and bot.

Because almost all IDs in Telegram are unique only to one bot. Here, we firstly send message to the shared chat, from where bot reforwards message to the end users.

This is the only way to share message ID that I found.

Module Contents#

Classes#

SharingMessageInDB

Class for sharing message in database.

Functions#

hash_with_fnv64(→ str)

FNV-1a 64-bit hash implementation.

hash_with_fnv64(string: str) str[source]#

FNV-1a 64-bit hash implementation.

It is a fast non-cryptographic hash function, which is good for us to transform the message data into short form.

class SharingMessageInDB(connection: redis.asyncio.Redis[bytes])[source]#

Class for sharing message in database.

async _check_shared_chat_availability() None[source]#
async get(message_hash: str) Set[int][source]#

Get users to send the message from message’s hash.

async set(message_hash: str, users_to_send: Set[int]) bool[source]#

Set users to send the message in database.

Returns:

Whether the message is duplicate. The function will raise warning if it’s True.

async get_shared_chat(*, both: bool) Tuple[int | None, int | None][source]#
async get_shared_chat(*, client: bool) int | None
async get_shared_chat(*, bot: bool) int | None

Get shared chat id as bot and client.

Returns:

Tuple, where first element is bot’s chat id and second is client’s chat id.

async set_shared_chat(bot_chat_id: int, client_chat_id: int) None[source]#

Set shared chat id as bot and client.

static hash_message(message: telethon.tl.custom.message.Message) str[source]#

Hash message to send.