some fixes, readme update
This commit is contained in:
parent
ef7fbab1f7
commit
822b25fcdb
20
README.md
20
README.md
@ -22,10 +22,11 @@ Based on [toxygen](https://github.com/xveduk/toxygen/) toxcore wrapper
|
|||||||
|
|
||||||
### Linux
|
### Linux
|
||||||
|
|
||||||
1. [Download file bot](https://github.com/ingvar1995/filebot/archive/master.zip)
|
1. Install Python2.7: ``sudo apt-get install python2.7``
|
||||||
2. Unpack archive
|
2. [Download file bot](https://github.com/ingvar1995/filebot/archive/master.zip)
|
||||||
3. Install [toxcore](https://github.com/irungentoo/toxcore/blob/master/INSTALL.md) in your system
|
3. Unpack archive
|
||||||
4. Run app:
|
4. Install [toxcore](https://github.com/irungentoo/toxcore/blob/master/INSTALL.md) in your system
|
||||||
|
5. Run app:
|
||||||
``python main.py path_to_profile``
|
``python main.py path_to_profile``
|
||||||
|
|
||||||
#Commands:
|
#Commands:
|
||||||
@ -35,8 +36,6 @@ rights - get access rights
|
|||||||
|
|
||||||
files - show list of files (get access)
|
files - show list of files (get access)
|
||||||
|
|
||||||
stats - downloads statistics (get access)
|
|
||||||
|
|
||||||
id - get bot's id (get access)
|
id - get bot's id (get access)
|
||||||
|
|
||||||
share <ToxID> <file_name> - send file to friend (get access)
|
share <ToxID> <file_name> - send file to friend (get access)
|
||||||
@ -47,6 +46,8 @@ size <file_name> - get size of file (get access)
|
|||||||
|
|
||||||
get <file_name> - get file with specified filename (get access)
|
get <file_name> - get file with specified filename (get access)
|
||||||
|
|
||||||
|
stats - show statistics (write access)
|
||||||
|
|
||||||
del <file_name> - remove file with specified filename (delete access)
|
del <file_name> - remove file with specified filename (delete access)
|
||||||
|
|
||||||
rename <file_name> --new <new_file_name> - rename file (delete access)
|
rename <file_name> --new <new_file_name> - rename file (delete access)
|
||||||
@ -59,4 +60,9 @@ name <new_name> - new name (masters only)
|
|||||||
|
|
||||||
message <ToxID> <message_text> - send message to friend (masters only)
|
message <ToxID> <message_text> - send message to friend (masters only)
|
||||||
|
|
||||||
message --all <message_text> - send message to all friends (masters only)
|
message --all <message_text> - send message to all friends (masters only)
|
||||||
|
|
||||||
|
stop - stop bot (masters only)
|
||||||
|
|
||||||
|
|
||||||
|
Users with write access can send files to bot.
|
||||||
|
21
bot.py
21
bot.py
@ -90,19 +90,20 @@ class Bot(Singleton):
|
|||||||
self.send_message(friend_num, """help - list of commands\n
|
self.send_message(friend_num, """help - list of commands\n
|
||||||
rights - get access rights\n
|
rights - get access rights\n
|
||||||
files - show list of files (get access)\n
|
files - show list of files (get access)\n
|
||||||
stats - downloads statistics (get access)\n
|
|
||||||
id - get bot's id (get access)\n
|
id - get bot's id (get access)\n
|
||||||
share <ToxID> <file_name> - send file to friend (get access)\n
|
share <ToxID> <file_name> - send file to friend (get access)\n
|
||||||
share --all <file_name> - send file to all friends (get access)\n
|
share --all <file_name> - send file to all friends (get access)\n
|
||||||
size <file_name> - get size of file (get access)\n
|
size <file_name> - get size of file (get access)\n
|
||||||
get <file_name> - get file with specified filename (get access)\n
|
get <file_name> - get file with specified filename (get access)\n
|
||||||
|
stats - show statistics (write access)\n
|
||||||
del <file_name> - remove file with specified filename (delete access)\n
|
del <file_name> - remove file with specified filename (delete access)\n
|
||||||
rename <file_name> --new <new_file_name> - rename file (delete access)\n
|
rename <file_name> --new <new_file_name> - rename file (delete access)\n
|
||||||
user <ToxID> <rights> - new rights (example: rwdm) for user (masters only)\n
|
user <ToxID> <rights> - new rights (example: rwdm) for user (masters only)\n
|
||||||
status <new_status> - new status message (masters only)\n
|
status <new_status> - new status message (masters only)\n
|
||||||
name <new_name> - new name (masters only)\n
|
name <new_name> - new name (masters only)\n
|
||||||
message <ToxID> <message_text> - send message to friend (masters only)\n
|
message <ToxID> <message_text> - send message to friend (masters only)\n
|
||||||
message --all <message_text> - send message to all friends (masters only)
|
message --all <message_text> - send message to all friends (masters only)\n
|
||||||
|
stop - stop bot (masters only)\n
|
||||||
Users with write access can send files to bot.
|
Users with write access can send files to bot.
|
||||||
""".encode('utf-8'))
|
""".encode('utf-8'))
|
||||||
elif message == 'rights':
|
elif message == 'rights':
|
||||||
@ -227,7 +228,7 @@ class Bot(Singleton):
|
|||||||
if self._tox.friend_get_connection_status(num):
|
if self._tox.friend_get_connection_status(num):
|
||||||
self.send_message(num, s.encode('utf-8'))
|
self.send_message(num, s.encode('utf-8'))
|
||||||
elif message == 'stats':
|
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'))
|
self.send_message(friend_num, 'Not enough rights'.encode('utf-8'))
|
||||||
else:
|
else:
|
||||||
s = ''
|
s = ''
|
||||||
@ -240,7 +241,21 @@ class Bot(Singleton):
|
|||||||
s = 'Nothing found'
|
s = 'Nothing found'
|
||||||
else:
|
else:
|
||||||
s += u'Downloads count: {}'.format(sum(self._downloads.values()))
|
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'])
|
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:
|
else:
|
||||||
self.send_message(friend_num, 'Wrong command'.encode('utf-8'))
|
self.send_message(friend_num, 'Wrong command'.encode('utf-8'))
|
||||||
|
|
||||||
|
@ -46,7 +46,8 @@ def friend_request(tox, public_key, message, message_size, user_data):
|
|||||||
Called when user get new friend request
|
Called when user get new friend request
|
||||||
"""
|
"""
|
||||||
profile = Bot.get_instance()
|
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'))
|
profile.process_friend_request(tox_id, message.decode('utf-8'))
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -17,10 +17,10 @@ class Settings(Singleton, dict):
|
|||||||
else:
|
else:
|
||||||
super(self.__class__, self).__init__(Settings.get_default_settings())
|
super(self.__class__, self).__init__(Settings.get_default_settings())
|
||||||
self.save()
|
self.save()
|
||||||
self['read'] = map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], self['read'])
|
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], self['write'])
|
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], self['delete'])
|
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], self['master'])
|
self['master'] = map(lambda x: x[:TOX_PUBLIC_KEY_SIZE * 2], set(self['master']))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_default_settings():
|
def get_default_settings():
|
||||||
|
4
tox.py
4
tox.py
@ -994,13 +994,13 @@ class Tox(object):
|
|||||||
This event is triggered when a friend request is received.
|
This event is triggered when a friend request is received.
|
||||||
|
|
||||||
:param callback: Python function. Should take pointer (c_void_p) to Tox object,
|
: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 message (c_char_p) they sent along with the request,
|
||||||
The size (c_size_t) of the message byte array,
|
The size (c_size_t) of the message byte array,
|
||||||
pointer (c_void_p) to user_data
|
pointer (c_void_p) to user_data
|
||||||
:param user_data: 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)
|
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))
|
Tox.libtoxcore.tox_callback_friend_request(self._tox_pointer, self.friend_request_cb, c_void_p(user_data))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user