From 822b25fcdb5c10d44aca81431eea35f146942f30 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Tue, 26 Apr 2016 13:09:39 +0300 Subject: [PATCH] some fixes, readme update --- README.md | 20 +++++++++++++------- bot.py | 21 ++++++++++++++++++--- callbacks.py | 3 ++- settings.py | 8 ++++---- tox.py | 4 ++-- 5 files changed, 39 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 2addf5d..38ea3b8 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,11 @@ Based on [toxygen](https://github.com/xveduk/toxygen/) toxcore wrapper ### Linux -1. [Download file bot](https://github.com/ingvar1995/filebot/archive/master.zip) -2. Unpack archive -3. Install [toxcore](https://github.com/irungentoo/toxcore/blob/master/INSTALL.md) in your system -4. Run app: +1. Install Python2.7: ``sudo apt-get install python2.7`` +2. [Download file bot](https://github.com/ingvar1995/filebot/archive/master.zip) +3. Unpack archive +4. Install [toxcore](https://github.com/irungentoo/toxcore/blob/master/INSTALL.md) in your system +5. Run app: ``python main.py path_to_profile`` #Commands: @@ -35,8 +36,6 @@ rights - get access rights files - show list of files (get access) -stats - downloads statistics (get access) - id - get bot's id (get access) share - send file to friend (get access) @@ -47,6 +46,8 @@ size - get size of file (get access) get - get file with specified filename (get access) +stats - show statistics (write access) + del - remove file with specified filename (delete access) rename --new - rename file (delete access) @@ -59,4 +60,9 @@ name - new name (masters only) message - send message to friend (masters only) - message --all - send message to all friends (masters only) +message --all - send message to all friends (masters only) + +stop - stop bot (masters only) + + +Users with write access can send files to bot. diff --git a/bot.py b/bot.py index 151d48a..4725154 100644 --- a/bot.py +++ b/bot.py @@ -90,19 +90,20 @@ class Bot(Singleton): self.send_message(friend_num, """help - list of commands\n rights - get access rights\n files - show list of files (get access)\n - stats - downloads statistics (get access)\n id - get bot's id (get access)\n share - send file to friend (get access)\n share --all - send file to all friends (get access)\n size - get size of file (get access)\n get - get file with specified filename (get access)\n + stats - show statistics (write access)\n del - remove file with specified filename (delete access)\n rename --new - rename file (delete access)\n user - new rights (example: rwdm) for user (masters only)\n status - new status message (masters only)\n name - new name (masters only)\n message - send message to friend (masters only)\n - message --all - send message to all friends (masters only) + message --all - send message to all friends (masters only)\n + stop - stop bot (masters only)\n Users with write access can send files to bot. """.encode('utf-8')) elif message == 'rights': @@ -227,7 +228,7 @@ class Bot(Singleton): if self._tox.friend_get_connection_status(num): self.send_message(num, s.encode('utf-8')) elif message == 'stats': - if id not in settings['read']: + if id not in settings['write']: self.send_message(friend_num, 'Not enough rights'.encode('utf-8')) else: s = '' @@ -240,7 +241,21 @@ class Bot(Singleton): s = 'Nothing found' else: s += u'Downloads count: {}'.format(sum(self._downloads.values())) + count = 0 + for num in self._tox.self_get_friend_list(): + if self._tox.friend_get_connection_status(num): + count += 1 + s = 'Friends: {}\nOnline friends: {}\nFiles:\n'.format(self._tox.self_get_friend_list_size(), count) + s self.send_message(friend_num, s.encode('utf-8'), TOX_MESSAGE_TYPE['NORMAL']) + elif message == 'stop': + if id in settings['master']: + settings.save() + data = self._tox.get_savedata() + ProfileHelper.save_profile(data) + del self._tox + raise SystemExit() + else: + self.send_message(friend_num, 'Not enough rights'.encode('utf-8')) else: self.send_message(friend_num, 'Wrong command'.encode('utf-8')) diff --git a/callbacks.py b/callbacks.py index 171e637..31602fa 100644 --- a/callbacks.py +++ b/callbacks.py @@ -46,7 +46,8 @@ def friend_request(tox, public_key, message, message_size, user_data): Called when user get new friend request """ profile = Bot.get_instance() - tox_id = bin_to_string(public_key, TOX_PUBLIC_KEY_SIZE) + key = ''.join(chr(x) for x in public_key[:TOX_PUBLIC_KEY_SIZE]) + tox_id = bin_to_string(key, TOX_PUBLIC_KEY_SIZE) profile.process_friend_request(tox_id, message.decode('utf-8')) # ----------------------------------------------------------------------------------------------------------------- diff --git a/settings.py b/settings.py index 9adc568..a6b0789 100644 --- a/settings.py +++ b/settings.py @@ -17,10 +17,10 @@ class Settings(Singleton, dict): else: super(self.__class__, self).__init__(Settings.get_default_settings()) self.save() - self['read'] = map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], self['read']) - self['write'] = map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], self['write']) - self['delete'] = map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], self['delete']) - self['master'] = map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], self['master']) + self['read'] = map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['read'])) + self['write'] = map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['write'])) + self['delete'] = map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['delete'])) + self['master'] = map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['master'])) @staticmethod def get_default_settings(): diff --git a/tox.py b/tox.py index daf3225..c28fa14 100644 --- a/tox.py +++ b/tox.py @@ -994,13 +994,13 @@ class Tox(object): This event is triggered when a friend request is received. :param callback: Python function. Should take pointer (c_void_p) to Tox object, - The Public Key (c_char_p) of the user who sent the friend request, + The Public Key (c_uint8 array) of the user who sent the friend request, The message (c_char_p) they sent along with the request, The size (c_size_t) of the message byte array, 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_char_p, c_char_p, c_size_t, c_void_p) + c_callback = CFUNCTYPE(None, c_void_p, POINTER(c_uint8), c_char_p, c_size_t, c_void_p) self.friend_request_cb = c_callback(callback) Tox.libtoxcore.tox_callback_friend_request(self._tox_pointer, self.friend_request_cb, c_void_p(user_data))