Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def iteration_interval(self):
"""
Return the time in milliseconds before tox_iterate() should be called again for optimal performance.
:return: time in milliseconds
"""
return Tox.libtoxcore.tox_iteration_interval(self._tox_pointer)
def file_control(self, friend_number, file_number, control):
"""
Sends a file control command to a friend for a given file transfer.
:param friend_number: The friend number of the friend the file is being transferred to or received from.
:param file_number: The friend-specific identifier for the file transfer.
:param control: The control (TOX_FILE_CONTROL) command to send.
:return: True on success.
"""
tox_err_file_control = c_int()
result = Tox.libtoxcore.tox_file_control(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number),
c_int(control), byref(tox_err_file_control))
tox_err_file_control = tox_err_file_control.value
if tox_err_file_control == TOX_ERR_FILE_CONTROL['OK']:
return bool(result)
elif tox_err_file_control == TOX_ERR_FILE_CONTROL['FRIEND_NOT_FOUND']:
raise ArgumentError('The friend_number passed did not designate a valid friend.')
elif tox_err_file_control == TOX_ERR_FILE_CONTROL['FRIEND_NOT_CONNECTED']:
raise RuntimeError('This client is currently not connected to the friend.')
elif tox_err_file_control == TOX_ERR_FILE_CONTROL['NOT_FOUND']:
raise ArgumentError('No file transfer with the given file number was found for the given friend.')
elif tox_err_file_control == TOX_ERR_FILE_CONTROL['NOT_PAUSED']:
raise ArgumentError('A RESUME control was sent, but the file transfer is running normally.')
elif tox_err_file_control == TOX_ERR_FILE_CONTROL['DENIED']:
raise ArgumentError('A RESUME control was sent, but the file transfer was paused by the other party. Only '
'the party that paused the transfer can resume it.')
elif tox_err_file_control == TOX_ERR_FILE_CONTROL['ALREADY_PAUSED']:
Generates a cryptographic hash of the given data.
This function may be used by clients for any purpose, but is provided primarily for validating cached avatars.
This use is highly recommended to avoid unnecessary avatar updates.
If hash is NULL or data is NULL while length is not 0 the function returns false, otherwise it returns true.
This function is a wrapper to internal message-digest functions.
:param hash: A valid memory location the hash data. It must be at least TOX_HASH_LENGTH bytes in size.
:param data: Data to be hashed or NULL.
:return: true if hash was not NULL.
"""
if hash is None:
hash = create_string_buffer(TOX_HASH_LENGTH)
Tox.libtoxcore.tox_hash(hash, c_char_p(data), c_size_t(len(data)))
return bin_to_string(hash, TOX_HASH_LENGTH)
The message length may not exceed TOX_MAX_MESSAGE_LENGTH. Larger messages must be split by the client and sent
as separate messages. Other clients can then reassemble the fragments. Messages may not be empty.
The return value of this function is the message ID. If a read receipt is received, the triggered
`friend_read_receipt` event will be passed this message ID.
Message IDs are unique per friend. The first message ID is 0. Message IDs are incremented by 1 each time a
message is sent. If UINT32_MAX messages were sent, the next message ID is 0.
:param friend_number: The friend number of the friend to send the message to.
:param message_type: Message type (TOX_MESSAGE_TYPE).
:param message: A non-None message text.
:return: message ID
"""
tox_err_friend_send_message = c_int()
result = Tox.libtoxcore.tox_friend_send_message(self._tox_pointer, c_uint32(friend_number),
c_int(message_type), c_char_p(message), c_size_t(len(message)),
byref(tox_err_friend_send_message))
tox_err_friend_send_message = tox_err_friend_send_message.value
if tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['OK']:
return result
elif tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['NULL']:
raise ArgumentError('One of the arguments to the function was NULL when it was not expected.')
elif tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['FRIEND_NOT_FOUND']:
raise ArgumentError('The friend number did not designate a valid friend.')
elif tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['FRIEND_NOT_CONNECTED']:
raise ArgumentError('This client is currently not connected to the friend.')
elif tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['SENDQ']:
raise ArgumentError('An allocation error occurred while increasing the send queue size.')
elif tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['TOO_LONG']:
raise ArgumentError('Message length exceeded TOX_MAX_MESSAGE_LENGTH.')
elif tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['EMPTY']:
def callback_friend_typing(self, callback, user_data):
"""
Set the callback for the `friend_typing` event. Pass NULL to unset.
This event is triggered when a friend starts or stops typing.
:param callback: Python function. Should take pointer (c_void_p) to Tox object,
The friend number (c_uint32) of the friend who started or stopped typing,
The result of calling tox_friend_get_typing (c_bool) on the passed friend_number,
pointer (c_void_p) to user_data
:param user_data: pointer (c_void_p) to user data
"""
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_bool, c_void_p)
self.friend_typing_cb = c_callback(callback)
Tox.libtoxcore.tox_callback_friend_typing(self._tox_pointer, self.friend_typing_cb, c_void_p(user_data))
def self_set_nospam(self, nospam):
"""
Set the 4-byte nospam part of the address.
:param nospam: Any 32 bit unsigned integer.
"""
Tox.libtoxcore.tox_self_set_nospam(self._tox_pointer, c_uint32(nospam))
This event is triggered when a file control command is received from a friend.
:param callback: Python function.
When receiving TOX_FILE_CONTROL_CANCEL, the client should release the resources associated with the file number
and consider the transfer failed.
Should take pointer (c_void_p) to Tox object,
The friend number (c_uint32) of the friend who is sending the file.
The friend-specific file number (c_uint32) the data received is associated with.
The file control (TOX_FILE_CONTROL) command received.
pointer (c_void_p) to user_data
:param user_data: pointer (c_void_p) to user data
"""
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_uint32, c_int, c_void_p)
self.file_recv_control_cb = c_callback(callback)
Tox.libtoxcore.tox_callback_file_recv_control(self._tox_pointer,
self.file_recv_control_cb, user_data)
def callback_friend_name(self, callback, user_data):
"""
Set the callback for the `friend_name` event. Pass None to unset.
This event is triggered when a friend changes their name.
:param callback: Python function. Should take pointer (c_void_p) to Tox object,
The friend number (c_uint32) of the friend whose name changed,
A byte array (c_char_p) containing the same data as tox_friend_get_name would write to its `name` parameter,
A value (c_size_t) equal to the return value of tox_friend_get_name_size,
pointer (c_void_p) to user_data
:param user_data: pointer (c_void_p) to user data
"""
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_char_p, c_size_t, c_void_p)
self.friend_name_cb = c_callback(callback)
Tox.libtoxcore.tox_callback_friend_name(self._tox_pointer, self.friend_name_cb, user_data)
def self_get_status(self):
"""
Returns the client's user status.
:return: client's user status
"""
return Tox.libtoxcore.tox_self_get_status(self._tox_pointer)
def self_set_typing(self, friend_number, typing):
"""
Set the client's typing status for a friend.
The client is responsible for turning it on or off.
:param friend_number: The friend to which the client is typing a message.
:param typing: The typing status. True means the client is typing.
:return: True on success.
"""
tox_err_set_typing = c_int()
result = Tox.libtoxcore.tox_self_set_typing(self._tox_pointer, c_uint32(friend_number),
c_bool(typing), byref(tox_err_set_typing))
tox_err_set_typing = tox_err_set_typing.value
if tox_err_set_typing == TOX_ERR_SET_TYPING['OK']:
return bool(result)
elif tox_err_set_typing == TOX_ERR_SET_TYPING['FRIEND_NOT_FOUND']:
raise ArgumentError('The friend number did not designate a valid friend.')