Ported to Python 3
This commit is contained in:
53
bot.py
53
bot.py
@@ -1,12 +1,16 @@
|
||||
from tox import Tox
|
||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
||||
from wrapper.tox import Tox
|
||||
import os
|
||||
from settings import *
|
||||
from toxcore_enums_and_consts import *
|
||||
from wrapper.toxcore_enums_and_consts import *
|
||||
from ctypes import *
|
||||
from util import Singleton, folder_size
|
||||
from file_transfers import *
|
||||
from collections import defaultdict
|
||||
|
||||
global LOG
|
||||
import logging
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
class Bot(Singleton):
|
||||
|
||||
@@ -174,10 +178,10 @@ class Bot(Singleton):
|
||||
fl = ' '.join(message.split(' ')[2:])
|
||||
try:
|
||||
num = self._tox.friend_by_public_key(message.split(' ')[1][:TOX_PUBLIC_KEY_SIZE * 2])
|
||||
print num
|
||||
LOG.debug(num)
|
||||
self.send_file(settings['folder'] + '/' + fl, num)
|
||||
except Exception as ex:
|
||||
print ex
|
||||
LOG.warn(ex)
|
||||
self.send_message(friend_num, 'Friend not found'.encode('utf-8'))
|
||||
else:
|
||||
fl = ' '.join(message.split(' ')[2:])
|
||||
@@ -289,7 +293,7 @@ class Bot(Singleton):
|
||||
:param tox_id: tox id of contact
|
||||
:param message: message
|
||||
"""
|
||||
print 'Friend request:', message
|
||||
LOG.info('Friend request:' +message)
|
||||
self._tox.friend_add_norequest(tox_id)
|
||||
settings = Settings.get_instance()
|
||||
# give friend default rights
|
||||
@@ -395,16 +399,28 @@ def tox_factory(data=None, settings=None):
|
||||
:return: new tox instance
|
||||
"""
|
||||
if settings is None:
|
||||
settings = {
|
||||
'ipv6_enabled': True,
|
||||
'udp_enabled': True,
|
||||
'proxy_type': 0,
|
||||
'proxy_host': '0',
|
||||
'proxy_port': 0,
|
||||
'start_port': 0,
|
||||
'end_port': 0,
|
||||
'tcp_port': 0
|
||||
}
|
||||
if os.getenv('socks_proxy') != '':
|
||||
settings = {
|
||||
'ipv6_enabled': False,
|
||||
'udp_enabled': False,
|
||||
'proxy_type': 2,
|
||||
'proxy_host': b'127.0.0.1',
|
||||
'proxy_port': 9050,
|
||||
'start_port': 0,
|
||||
'end_port': 0,
|
||||
'tcp_port': 0
|
||||
}
|
||||
else:
|
||||
settings = {
|
||||
'ipv6_enabled': True,
|
||||
'udp_enabled': True,
|
||||
'proxy_type': 0,
|
||||
'proxy_host': '0',
|
||||
'proxy_port': 0,
|
||||
'start_port': 0,
|
||||
'end_port': 0,
|
||||
'tcp_port': 0
|
||||
}
|
||||
tox_options = Tox.options_new()
|
||||
tox_options.contents.udp_enabled = settings['udp_enabled']
|
||||
tox_options.contents.proxy_type = settings['proxy_type']
|
||||
@@ -421,4 +437,11 @@ def tox_factory(data=None, settings=None):
|
||||
tox_options.contents.savedata_type = TOX_SAVEDATA_TYPE['NONE']
|
||||
tox_options.contents.savedata_data = None
|
||||
tox_options.contents.savedata_length = 0
|
||||
# overrides
|
||||
tox_options.contents.local_discovery_enabled = False
|
||||
tox_options.contents.ipv6_enabled = False
|
||||
tox_options.contents.hole_punching_enabled = False
|
||||
|
||||
LOG.debug("wrapper.tox.Tox settings: " +repr(settings))
|
||||
|
||||
return Tox(tox_options)
|
||||
|
||||
Reference in New Issue
Block a user