diff --git a/README.md b/README.md index 92af911..0ead880 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,19 @@ Based on [toxygen](https://github.com/xveduk/toxygen/) toxcore wrapper 1. [Download and install latest Python 2.7](https://www.python.org/downloads/windows/) 2. [Download file bot](https://github.com/ingvar1995/filebot/archive/master.zip) -3. Unpack archive -4. Download latest [libtox.dll](https://build.tox.chat/view/libtoxcore/job/libtoxcore_build_windows_x86_shared_release/lastSuccessfulBuild/artifact/libtoxcore_build_windows_x86_shared_release.zip) build, download latest [libsodium.a](https://build.tox.chat/view/libsodium/job/libsodium_build_windows_x86_static_release/lastSuccessfulBuild/artifact/libsodium_build_windows_x86_static_release.zip) build, put it into libs\ +3. Unpack archive +4. Download latest libtox.dll build, download latest libsodium.a build, put it into \libs\ 5. Run app: ``python main.py path_to_profile`` +[libtox.dll for 32-bit Python](https://build.tox.chat/view/libtoxcore/job/libtoxcore_build_windows_x86_shared_release/lastSuccessfulBuild/artifact/libtoxcore_build_windows_x86_shared_release.zip) + +[libtox.dll for 64-bit Python](https://build.tox.chat/view/libtoxcore/job/libtoxcore_build_windows_x86-64_shared_release/lastSuccessfulBuild/artifact/libtoxcore_build_windows_x86-64_shared_release.zip) + +[libsodium.a for 32-bit Python](https://build.tox.chat/view/libsodium/job/libsodium_build_windows_x86_static_release/lastSuccessfulBuild/artifact/libsodium_build_windows_x86_static_release.zip) + +[libsodium.a for 64-bit Python](https://build.tox.chat/view/libsodium/job/libsodium_build_windows_x86-64_static_release/lastSuccessfulBuild/artifact/libsodium_build_windows_x86-64_static_release.zip) + ### Linux diff --git a/bootstrap.py b/bootstrap.py index 340af37..87ead77 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -2,6 +2,7 @@ import random class Node(object): + def __init__(self, ip, port, tox_key, rand): self._ip, self._port, self._tox_key, self.rand = ip, port, tox_key, rand @@ -80,8 +81,3 @@ def node_generator(): arr = sorted(nodes, key=lambda x: x.rand)[:4] for elem in arr: yield elem.get_data() - - -if __name__ == "__main__": - for elem in node_generator(): - print str(elem) diff --git a/bot.py b/bot.py index b11740a..0d829a1 100644 --- a/bot.py +++ b/bot.py @@ -3,7 +3,7 @@ import os from settings import * from toxcore_enums_and_consts import * from ctypes import * -from util import log, Singleton +from util import Singleton from file_transfers import * from collections import defaultdict @@ -62,7 +62,7 @@ class Bot(Singleton): :param friend_num: number of friend who sent message :param message: text of message """ - id = self._tox.friend_get_public_key(friend_num) + id = self._tox.friend_get_public_key(friend_num) # public key of user settings = Settings.get_instance() message = message.strip() # message parsing @@ -277,6 +277,7 @@ class Bot(Singleton): :param tox_id: tox id of contact :param message: message """ + print 'Friend request:', message self._tox.friend_add_norequest(tox_id) settings = Settings.get_instance() # give friend default rights diff --git a/main.py b/main.py index 2006605..f20136f 100644 --- a/main.py +++ b/main.py @@ -13,7 +13,7 @@ class FileBot(object): self.stop = False self.profile = None self.path = path - print 'FileBot v0.1' + print 'FileBot v0.1.1' def main(self): self.tox = tox_factory(ProfileHelper.open_profile(self.path)) diff --git a/settings.py b/settings.py index 4b1db2d..bd5dff5 100644 --- a/settings.py +++ b/settings.py @@ -1,4 +1,3 @@ -from platform import system import json import os import locale diff --git a/tox.py b/tox.py index c28fa14..68fbc42 100644 --- a/tox.py +++ b/tox.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from ctypes import c_char_p, Structure, CDLL, c_bool, addressof, c_int, c_size_t, POINTER, c_uint16, c_void_p, c_uint64 +from ctypes import c_char_p, Structure, CDLL, c_bool, byref, c_int, c_size_t, POINTER, c_uint16, c_void_p, c_uint64 from ctypes import create_string_buffer, ArgumentError, CFUNCTYPE, c_uint32, sizeof, c_uint8 from platform import system from toxcore_enums_and_consts import * @@ -62,7 +62,7 @@ class Tox(object): else: tox_err_new = c_int() Tox.libtoxcore.tox_new.restype = POINTER(c_void_p) - self._tox_pointer = Tox.libtoxcore.tox_new(tox_options, addressof(tox_err_new)) + self._tox_pointer = Tox.libtoxcore.tox_new(tox_options, byref(tox_err_new)) tox_err_new = tox_err_new.value if tox_err_new == TOX_ERR_NEW['NULL']: raise ArgumentError('One of the arguments to the function was NULL when it was not expected.') @@ -138,7 +138,7 @@ class Tox(object): tox_err_options_new = c_int() f = Tox.libtoxcore.tox_options_new f.restype = POINTER(ToxOptions) - result = f(addressof(tox_err_options_new)) + result = f(byref(tox_err_options_new)) tox_err_options_new = tox_err_options_new.value if tox_err_options_new == TOX_ERR_OPTIONS_NEW['OK']: return result @@ -202,7 +202,7 @@ class Tox(object): """ tox_err_bootstrap = c_int() result = Tox.libtoxcore.tox_bootstrap(self._tox_pointer, c_char_p(address), c_uint16(port), - string_to_bin(public_key), addressof(tox_err_bootstrap)) + string_to_bin(public_key), byref(tox_err_bootstrap)) tox_err_bootstrap = tox_err_bootstrap.value if tox_err_bootstrap == TOX_ERR_BOOTSTRAP['OK']: return bool(result) @@ -228,7 +228,7 @@ class Tox(object): """ tox_err_bootstrap = c_int() result = Tox.libtoxcore.tox_add_tcp_relay(self._tox_pointer, c_char_p(address), c_uint16(port), - c_char_p(public_key), addressof(tox_err_bootstrap)) + c_char_p(public_key), byref(tox_err_bootstrap)) tox_err_bootstrap = tox_err_bootstrap.value if tox_err_bootstrap == TOX_ERR_BOOTSTRAP['OK']: return bool(result) @@ -355,7 +355,7 @@ class Tox(object): """ tox_err_set_info = c_int() result = Tox.libtoxcore.tox_self_set_name(self._tox_pointer, c_char_p(name), - c_size_t(len(name)), addressof(tox_err_set_info)) + c_size_t(len(name)), byref(tox_err_set_info)) tox_err_set_info = tox_err_set_info.value if tox_err_set_info == TOX_ERR_SET_INFO['OK']: return bool(result) @@ -403,7 +403,7 @@ class Tox(object): """ tox_err_set_info = c_int() result = Tox.libtoxcore.tox_self_set_status_message(self._tox_pointer, c_char_p(status_message), - c_size_t(len(status_message)), addressof(tox_err_set_info)) + c_size_t(len(status_message)), byref(tox_err_set_info)) tox_err_set_info = tox_err_set_info.value if tox_err_set_info == TOX_ERR_SET_INFO['OK']: return bool(result) @@ -479,7 +479,7 @@ class Tox(object): """ tox_err_friend_add = c_int() result = Tox.libtoxcore.tox_friend_add(self._tox_pointer, string_to_bin(address), c_char_p(message), - c_size_t(len(message)), addressof(tox_err_friend_add)) + c_size_t(len(message)), byref(tox_err_friend_add)) tox_err_friend_add = tox_err_friend_add.value if tox_err_friend_add == TOX_ERR_FRIEND_ADD['OK']: return result @@ -519,7 +519,7 @@ class Tox(object): """ tox_err_friend_add = c_int() result = Tox.libtoxcore.tox_friend_add_norequest(self._tox_pointer, string_to_bin(public_key), - addressof(tox_err_friend_add)) + byref(tox_err_friend_add)) tox_err_friend_add = tox_err_friend_add.value if tox_err_friend_add == TOX_ERR_FRIEND_ADD['OK']: return result @@ -554,7 +554,7 @@ class Tox(object): """ tox_err_friend_delete = c_int() result = Tox.libtoxcore.tox_friend_delete(self._tox_pointer, c_uint32(friend_number), - addressof(tox_err_friend_delete)) + byref(tox_err_friend_delete)) tox_err_friend_delete = tox_err_friend_delete.value if tox_err_friend_delete == TOX_ERR_FRIEND_DELETE['OK']: return bool(result) @@ -574,7 +574,7 @@ class Tox(object): """ tox_err_friend_by_public_key = c_int() result = Tox.libtoxcore.tox_friend_by_public_key(self._tox_pointer, string_to_bin(public_key), - addressof(tox_err_friend_by_public_key)) + byref(tox_err_friend_by_public_key)) tox_err_friend_by_public_key = tox_err_friend_by_public_key.value if tox_err_friend_by_public_key == TOX_ERR_FRIEND_BY_PUBLIC_KEY['OK']: return result @@ -629,7 +629,7 @@ class Tox(object): public_key = create_string_buffer(TOX_PUBLIC_KEY_SIZE) tox_err_friend_get_public_key = c_int() Tox.libtoxcore.tox_friend_get_public_key(self._tox_pointer, c_uint32(friend_number), public_key, - addressof(tox_err_friend_get_public_key)) + byref(tox_err_friend_get_public_key)) tox_err_friend_get_public_key = tox_err_friend_get_public_key.value if tox_err_friend_get_public_key == TOX_ERR_FRIEND_GET_PUBLIC_KEY['OK']: return bin_to_string(public_key, TOX_PUBLIC_KEY_SIZE) @@ -646,7 +646,7 @@ class Tox(object): """ tox_err_last_online = c_int() result = Tox.libtoxcore.tox_friend_get_last_online(self._tox_pointer, c_uint32(friend_number), - addressof(tox_err_last_online)) + byref(tox_err_last_online)) tox_err_last_online = tox_err_last_online.value if tox_err_last_online == TOX_ERR_FRIEND_GET_LAST_ONLINE['OK']: return result @@ -665,7 +665,7 @@ class Tox(object): """ tox_err_friend_query = c_int() result = Tox.libtoxcore.tox_friend_get_name_size(self._tox_pointer, c_uint32(friend_number), - addressof(tox_err_friend_query)) + byref(tox_err_friend_query)) tox_err_friend_query = tox_err_friend_query.value if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: return result @@ -691,7 +691,7 @@ class Tox(object): name = create_string_buffer(self.friend_get_name_size(friend_number)) tox_err_friend_query = c_int() Tox.libtoxcore.tox_friend_get_name(self._tox_pointer, c_uint32(friend_number), name, - addressof(tox_err_friend_query)) + byref(tox_err_friend_query)) tox_err_friend_query = tox_err_friend_query.value if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: return name.value.decode('utf8') @@ -727,7 +727,7 @@ class Tox(object): """ tox_err_friend_query = c_int() result = Tox.libtoxcore.tox_friend_get_status_message_size(self._tox_pointer, c_uint32(friend_number), - addressof(tox_err_friend_query)) + byref(tox_err_friend_query)) tox_err_friend_query = tox_err_friend_query.value if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: return result @@ -755,7 +755,7 @@ class Tox(object): status_message = create_string_buffer(self.friend_get_status_message_size(friend_number)) tox_err_friend_query = c_int() Tox.libtoxcore.tox_friend_get_status_message(self._tox_pointer, c_uint32(friend_number), status_message, - addressof(tox_err_friend_query)) + byref(tox_err_friend_query)) tox_err_friend_query = tox_err_friend_query.value if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: return status_message.value.decode('utf8') @@ -796,7 +796,7 @@ class Tox(object): """ tox_err_friend_query = c_int() result = Tox.libtoxcore.tox_friend_get_status(self._tox_pointer, c_uint32(friend_number), - addressof(tox_err_friend_query)) + byref(tox_err_friend_query)) tox_err_friend_query = tox_err_friend_query.value if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: return result @@ -835,7 +835,7 @@ class Tox(object): """ tox_err_friend_query = c_int() result = Tox.libtoxcore.tox_friend_get_connection_status(self._tox_pointer, c_uint32(friend_number), - addressof(tox_err_friend_query)) + byref(tox_err_friend_query)) tox_err_friend_query = tox_err_friend_query.value if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: return result @@ -875,7 +875,7 @@ class Tox(object): """ tox_err_friend_query = c_int() result = Tox.libtoxcore.tox_friend_get_typing(self._tox_pointer, c_uint32(friend_number), - addressof(tox_err_friend_query)) + byref(tox_err_friend_query)) tox_err_friend_query = tox_err_friend_query.value if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: return bool(result) @@ -918,7 +918,7 @@ class Tox(object): """ tox_err_set_typing = c_int() result = Tox.libtoxcore.tox_self_set_typing(self._tox_pointer, c_uint32(friend_number), - c_bool(typing), addressof(tox_err_set_typing)) + 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) @@ -948,7 +948,7 @@ class Tox(object): 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)), - addressof(tox_err_friend_send_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 @@ -1058,7 +1058,7 @@ class Tox(object): """ 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), addressof(tox_err_file_control)) + 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) @@ -1113,7 +1113,7 @@ class Tox(object): """ tox_err_file_seek = c_int() result = Tox.libtoxcore.tox_file_control(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number), - c_uint64(position), addressof(tox_err_file_seek)) + c_uint64(position), byref(tox_err_file_seek)) tox_err_file_seek = tox_err_file_seek.value if tox_err_file_seek == TOX_ERR_FILE_SEEK['OK']: return bool(result) @@ -1143,8 +1143,8 @@ class Tox(object): if file_id is None: file_id = create_string_buffer(TOX_FILE_ID_LENGTH) tox_err_file_get = c_int() - Tox.libtoxcore.tox_file_control(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number), file_id, - addressof(tox_err_file_get)) + Tox.libtoxcore.tox_get_file_id(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number), file_id, + byref(tox_err_file_get)) tox_err_file_get = tox_err_file_get.value if tox_err_file_get == TOX_ERR_FILE_GET['OK']: return bin_to_string(file_id, TOX_FILE_ID_LENGTH) @@ -1207,7 +1207,7 @@ class Tox(object): tox_err_file_send = c_int() result = self.libtoxcore.tox_file_send(self._tox_pointer, c_uint32(friend_number), c_uint32(kind), c_uint64(file_size), string_to_bin(file_id), c_char_p(filename), - c_size_t(len(filename)), addressof(tox_err_file_send)) + c_size_t(len(filename)), byref(tox_err_file_send)) tox_err_file_send = tox_err_file_send.value if tox_err_file_send == TOX_ERR_FILE_SEND['OK']: return result @@ -1242,7 +1242,7 @@ class Tox(object): tox_err_file_send_chunk = c_int() result = self.libtoxcore.tox_file_send_chunk(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number), c_uint64(position), c_char_p(data), c_size_t(len(data)), - addressof(tox_err_file_send_chunk)) + byref(tox_err_file_send_chunk)) tox_err_file_send_chunk = tox_err_file_send_chunk.value if tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['OK']: return bool(result) @@ -1383,7 +1383,7 @@ class Tox(object): Return the UDP port this Tox instance is bound to. """ tox_err_get_port = c_int() - result = Tox.libtoxcore.tox_self_get_udp_port(self._tox_pointer, addressof(tox_err_get_port)) + result = Tox.libtoxcore.tox_self_get_udp_port(self._tox_pointer, byref(tox_err_get_port)) tox_err_get_port = tox_err_get_port.value if tox_err_get_port == TOX_ERR_GET_PORT['OK']: return result @@ -1396,17 +1396,9 @@ class Tox(object): relay. """ tox_err_get_port = c_int() - result = Tox.libtoxcore.tox_self_get_tcp_port(self._tox_pointer, addressof(tox_err_get_port)) + result = Tox.libtoxcore.tox_self_get_tcp_port(self._tox_pointer, byref(tox_err_get_port)) tox_err_get_port = tox_err_get_port.value if tox_err_get_port == TOX_ERR_GET_PORT['OK']: return result elif tox_err_get_port == TOX_ERR_GET_PORT['NOT_BOUND']: raise RuntimeError('The instance was not bound to any port.') - - -if __name__ == '__main__': - tox = Tox(Tox.options_new()) - p = tox.get_savedata() - print type(p) - print p - del tox