From 0b71d3255c3f94019bc590c82e2e092d5d136972 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 18:35:08 +0300 Subject: [PATCH] Friend list queries --- src/tox.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/src/tox.py b/src/tox.py index d5979fc..fa08ed6 100644 --- a/src/tox.py +++ b/src/tox.py @@ -269,7 +269,48 @@ class Tox(object): elif tox_err_friend_delete == TOX_ERR_FRIEND_DELETE['TOX_ERR_FRIEND_DELETE_FRIEND_NOT_FOUND']: raise ArgumentError('There was no friend with the given friend number. No friends were deleted.') - # TODO Friend list queries + def friend_by_public_key(self, public_key): + tox_err_friend_by_public_key = c_int() + result = self.libtoxcore.tox_friend_by_public_key(self._tox_pointer, c_char_p(public_key), + addressof(tox_err_friend_by_public_key)) + if tox_err_friend_by_public_key == TOX_ERR_FRIEND_BY_PUBLIC_KEY['TOX_ERR_FRIEND_BY_PUBLIC_KEY_OK']: + return int(result.value) + elif tox_err_friend_by_public_key == TOX_ERR_FRIEND_BY_PUBLIC_KEY['TOX_ERR_FRIEND_BY_PUBLIC_KEY_NULL']: + raise ArgumentError('One of the arguments to the function was NULL when it was not expected.') + elif tox_err_friend_by_public_key == TOX_ERR_FRIEND_BY_PUBLIC_KEY['TOX_ERR_FRIEND_BY_PUBLIC_KEY_NOT_FOUND']: + raise ArgumentError('No friend with the given Public Key exists on the friend list.') + + def friend_exists(self, friend_number): + return bool(self.libtoxcore.tox_friend_by_public_key(self._tox_pointer, c_uint32(friend_number))) + + def self_get_friend_list_size(self): + return int(self.libtoxcore.tox_self_get_friend_list_size(self._tox_pointer).value) + + def self_get_friend_list(self, friend_list=None): + if friend_list is None: + friend_list = create_string_buffer(sizeof(c_uint32) * self.self_get_friend_list_size()) + friend_list = POINTER(c_uint32)(friend_list) + self.libtoxcore.tox_self_get_friend_list(self._tox_pointer, friend_list) + return friend_list + + def friend_get_public_key(self, friend_number, public_key): + tox_err_friend_get_public_key = c_int() + result = self.libtoxcore.tox_friend_get_public_key(self._tox_pointer, c_uint32(friend_number), + c_char_p(public_key), + addressof(tox_err_friend_get_public_key)) + if tox_err_friend_get_public_key == TOX_ERR_FRIEND_GET_PUBLIC_KEY['TOX_ERR_FRIEND_GET_PUBLIC_KEY_OK']: + return bool(result) + elif tox_err_friend_get_public_key == TOX_ERR_FRIEND_GET_PUBLIC_KEY['TOX_ERR_FRIEND_GET_PUBLIC_KEY_FRIEND_NOT_FOUND']: + raise ArgumentError('No friend with the given number exists on the friend list.') + + def friend_get_last_online(self, friend_number): + tox_err_last_online = c_int() + result = self.libtoxcore.tox_friend_get_last_online(self._tox_pointer, c_uint32(friend_number), + addressof(tox_err_last_online)) + if tox_err_last_online == TOX_ERR_FRIEND_GET_LAST_ONLINE['TOX_ERR_FRIEND_GET_LAST_ONLINE_OK']: + return int(result.value) + elif tox_err_last_online == TOX_ERR_FRIEND_GET_LAST_ONLINE['TOX_ERR_FRIEND_GET_LAST_ONLINE_FRIEND_NOT_FOUND']: + raise ArgumentError('No friend with the given number exists on the friend list.') # TODO Friend-specific state queries @@ -338,4 +379,7 @@ class Tox(object): if __name__ == '__main__': - pass + c = c_uint64(24) + c = int(c.value) + print type(c) + print(c)