Ported to Python 3

This commit is contained in:
emdee
2022-10-06 13:44:35 +00:00
parent 87638269c8
commit fc4548bbe5
10 changed files with 144 additions and 56 deletions

View File

@@ -1,8 +1,12 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
from settings import Settings
from bot import Bot
from toxcore_enums_and_consts import *
from tox import bin_to_string
from wrapper.toxcore_enums_and_consts import *
from wrapper.tox import bin_to_string
global LOG
import logging
LOG = logging.getLogger(__name__)
# -----------------------------------------------------------------------------------------------------------------
# Callbacks - current user
@@ -14,7 +18,7 @@ def self_connection_status():
Current user changed connection status (offline, UDP, TCP)
"""
def wrapped(tox, connection, user_data):
print 'Connection status: ', str(connection)
LOG.debug('Connection status: ' + str(connection))
return wrapped
@@ -27,7 +31,7 @@ def friend_connection_status(tox, friend_num, new_status, user_data):
"""
Check friend's connection status (offline, udp, tcp)
"""
print "Friend #{} connected! Friend's status: {}".format(friend_num, new_status)
LOG.info("Friend #{} connected! Friend's status: {}".format(friend_num, new_status))
def friend_message():
@@ -35,7 +39,7 @@ def friend_message():
New message from friend
"""
def wrapped(tox, friend_number, message_type, message, size, user_data):
print message.decode('utf-8')
LOG.info(message.decode('utf-8'))
Bot.get_instance().new_message(friend_number, message.decode('utf-8'))
# parse message
return wrapped
@@ -62,7 +66,7 @@ def tox_file_recv(tox_link):
def wrapped(tox, friend_number, file_number, file_type, size, file_name, file_name_size, user_data):
profile = Bot.get_instance()
if file_type == TOX_FILE_KIND['DATA']:
print 'file'
LOG.info('file')
file_name = unicode(file_name[:file_name_size].decode('utf-8'))
profile.incoming_file_transfer(friend_number, file_number, size, file_name)
else: # AVATAR
@@ -109,13 +113,13 @@ def init_callbacks(tox):
Initialization of all callbacks.
:param tox: tox instance
"""
tox.callback_self_connection_status(self_connection_status(), 0)
tox.callback_self_connection_status(self_connection_status())
tox.callback_friend_message(friend_message(), 0)
tox.callback_friend_connection_status(friend_connection_status, 0)
tox.callback_friend_request(friend_request, 0)
tox.callback_friend_message(friend_message())
tox.callback_friend_connection_status(friend_connection_status)
tox.callback_friend_request(friend_request)
tox.callback_file_recv(tox_file_recv(tox), 0)
tox.callback_file_recv_chunk(file_recv_chunk, 0)
tox.callback_file_chunk_request(file_chunk_request, 0)
tox.callback_file_recv_control(file_recv_control, 0)
tox.callback_file_recv(tox_file_recv(tox))
tox.callback_file_recv_chunk(file_recv_chunk)
tox.callback_file_chunk_request(file_chunk_request)
tox.callback_file_recv_control(file_recv_control)