From 85e0634660dab7b3a8c75c05c9f35bfb319c44fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=92=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=B8=D0=BC=D0=B8=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Fri, 19 Feb 2016 00:40:30 +0300 Subject: [PATCH] friends beginning --- src/tox.py | 31 +++++++++++++++++++++++++++++++ src/toxcore_enums_and_consts.py | 2 ++ 2 files changed, 33 insertions(+) diff --git a/src/tox.py b/src/tox.py index 512cb4a..d8cde60 100644 --- a/src/tox.py +++ b/src/tox.py @@ -205,6 +205,37 @@ class Tox(object): self.libtoxcore.tox_self_get_status_message(self._tox_pointer, status_message) return status_message + def self_set_status(self, status): + self.libtoxcore.tox_self_set_status(self._tox_pointer, c_int(status)) + + def self_get_status(self): + return self.libtoxcore.tox_self_get_status(self._tox_pointer) + + def friend_add(self, address, message, length): + tox_err_friend_add = c_int() + result = self.libtoxcore.tox_friend_add(self._tox_pointer, c_char_p(address), c_char_p(message), + c_size_t(length), addressof(tox_err_friend_add)) + if tox_err_friend_add == TOX_ERR_FRIEND_ADD['TOX_ERR_FRIEND_ADD_OK']: + return int(result.value) + elif tox_err_friend_add == TOX_ERR_FRIEND_ADD['TOX_ERR_FRIEND_ADD_NULL']: + raise ArgumentError('One of the arguments to the function was NULL when it was not expected.') + elif tox_err_friend_add == TOX_ERR_FRIEND_ADD['TOX_ERR_FRIEND_ADD_TOO_LONG']: + raise ArgumentError('The length of the friend request message exceeded TOX_MAX_FRIEND_REQUEST_LENGTH.') + elif tox_err_friend_add == TOX_ERR_FRIEND_ADD['TOX_ERR_FRIEND_ADD_NO_MESSAGE']: + raise ArgumentError('The friend request message was empty. This, and the TOO_LONG code will never be' + ' returned from tox_friend_add_norequest.') + elif tox_err_friend_add == TOX_ERR_FRIEND_ADD['TOX_ERR_FRIEND_ADD_OWN_KEY']: + raise ArgumentError('The friend address belongs to the sending client.') + elif tox_err_friend_add == TOX_ERR_FRIEND_ADD['TOX_ERR_FRIEND_ADD_ALREADY_SENT']: + raise ArgumentError('A friend request has already been sent, or the address belongs to a friend that is' + ' already on the friend list.') + elif tox_err_friend_add == TOX_ERR_FRIEND_ADD['TOX_ERR_FRIEND_ADD_BAD_CHECKSUM']: + raise ArgumentError('The friend address checksum failed.') + elif tox_err_friend_add == TOX_ERR_FRIEND_ADD['TOX_ERR_FRIEND_ADD_SET_NEW_NOSPAM']: + raise ArgumentError('The friend was already there, but the nospam value was different.') + elif tox_err_friend_add == TOX_ERR_FRIEND_ADD['TOX_ERR_FRIEND_ADD_MALLOC']: + raise MemoryError('A memory allocation failed when trying to increase the friend list size.') + def __del__(self): if hasattr(self, 'tox_options'): self.libtoxcore.tox_kill(self._tox_pointer) diff --git a/src/toxcore_enums_and_consts.py b/src/toxcore_enums_and_consts.py index 66b8909..8dfd765 100644 --- a/src/toxcore_enums_and_consts.py +++ b/src/toxcore_enums_and_consts.py @@ -191,3 +191,5 @@ TOX_ERR_GET_PORT = { TOX_PUBLIC_KEY_SIZE = 32 TOX_ADDRESS_SIZE = TOX_PUBLIC_KEY_SIZE + 48 + +TOX_MAX_FRIEND_REQUEST_LENGTH = 1016