Skip to content

Commit

Permalink
Minor change
Browse files Browse the repository at this point in the history
changed _proxy_settings return value(s)
  • Loading branch information
sot-tech authored Aug 6, 2019
1 parent e3a457f commit 01a58ad
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions mautrix_telegram/abstract_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from typing import Tuple, Optional, List, Union, Dict, TYPE_CHECKING
from typing import Tuple, Optional, List, Union, Dict, Type, TYPE_CHECKING
from abc import ABC, abstractmethod
import asyncio
import logging
import platform
import time

from telethon.network import (
ConnectionTcpMTProxyRandomizedIntermediate, ConnectionTcpFull)
ConnectionTcpMTProxyRandomizedIntermediate, ConnectionTcpFull, Connection)
from telethon.tl.patched import MessageService, Message
from telethon.tl.types import (
Channel, ChannelForbidden, Chat, ChatForbidden, MessageActionChannelMigrateFrom, PeerUser,
Expand Down Expand Up @@ -88,23 +88,27 @@ def connected(self) -> bool:
return self.client and self.client.is_connected()

@property
def _proxy_settings(self) -> Optional[Tuple[int, str, str, str, str, str]]:
def _proxy_settings(self) -> Tuple[Type[Connection], Optional[tuple]]:
proxy_type = config["telegram.proxy.type"].lower()
connection = ConnectionTcpFull
connection_data = (config["telegram.proxy.address"],
config["telegram.proxy.port"],
config["telegram.proxy.rdns"],
config["telegram.proxy.username"],
config["telegram.proxy.password"])
if proxy_type == "disabled":
return None
connection_data = None
elif proxy_type == "socks4":
proxy_type = 1
connection_data = (1,) + connection_data
elif proxy_type == "socks5":
proxy_type = 2
connection_data = (2,) + connection_data
elif proxy_type == "http":
proxy_type = 3
connection_data = (3,) + connection_data
elif proxy_type == "mtproxy":
proxy_type = 4
connection = ConnectionTcpMTProxyRandomizedIntermediate
connection_data = (connection_data[0], connection_data[1], connection_data[4])

return (proxy_type,
config["telegram.proxy.address"], config["telegram.proxy.port"],
config["telegram.proxy.rdns"],
config["telegram.proxy.username"], config["telegram.proxy.password"])
return connection, connection_data

def _init_client(self) -> None:
self.log.debug(f"Initializing client for {self.name}")
Expand All @@ -123,11 +127,7 @@ def _init_client(self) -> None:
device = config["telegram.device_info.device_model"]
sysversion = config["telegram.device_info.system_version"]
appversion = config["telegram.device_info.app_version"]
connection = ConnectionTcpFull
proxy = self._proxy_settings
if proxy is not None and proxy[0] == 4:
connection = ConnectionTcpMTProxyRandomizedIntermediate
proxy = (proxy[1], proxy[2], proxy[5])
connection, proxy = self._proxy_settings

self.client = MautrixTelegramClient(
session=self.session,
Expand Down

0 comments on commit 01a58ad

Please sign in to comment.