Ejemplo n.º 1
0
        public static TelegramBotClient InitBot()
        {
            HttpToSocks5Proxy = new MihaZupan.HttpToSocks5Proxy("127.0.0.1", 9150);
            string token = "";

            return(new TelegramBotClient(token, HttpToSocks5Proxy));
        }
Ejemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();
            HttpToSocks5Proxy = new MihaZupan.HttpToSocks5Proxy("127.0.0.1", 9150);

            bot                  = new TelegramBotClient("1207416695:AAHwctcnV7E088k3ScrLo9L5lTClJpI--FQ", HttpToSocks5Proxy);
            bot.OnMessage       += Bot_OnMessage;
            bot.OnCallbackQuery += Bot_OnCallbackQuery;
            var t = bot.GetMeAsync().Result;

            bot.StartReceiving();
        }
Ejemplo n.º 3
0
        public override async Task Run(object prm)
        {
            if (IsRunning || _me != null)
            {
                return;
            }
            IsRunning = true;
            try
            {
                await LogHelper.LogModule("Initializing Telegram module...", Category);

                if (Settings.TelegramModule == null || string.IsNullOrEmpty(Settings.TelegramModule.Token))
                {
                    await LogHelper.LogError("Token is not set for Telegram module!", Category);

                    return;
                }
                if (Settings.TelegramModule.RelayChannels.Count == 0 || Settings.TelegramModule.RelayChannels.All(a => a.Telegram == 0) ||
                    Settings.TelegramModule.RelayChannels.All(a => a.Discord == 0))
                {
                    await LogHelper.LogError("No relay channels set for Telegram module!", Category);

                    return;
                }
                //var proxy = new MihaZupan.HttpToSocks5Proxy("185.36.191.39", 4782, "userid63NM", "110jCb");
                var proxy = new MihaZupan.HttpToSocks5Proxy(Settings.TelegramModule.ProxyIp, Settings.TelegramModule.ProxyPort, Settings.TelegramModule.ProxyUser, Settings.TelegramModule.ProxyPass);
                _client            = new TelegramBotClient(Settings.TelegramModule.Token, proxy);
                _client.OnMessage += BotClient_OnMessage;
                if (!await _client.TestApiAsync())
                {
                    await LogHelper.LogError("API ERROR!", Category);

                    return;
                }
                _client.OnReceiveError        += _client_OnReceiveError;
                _client.OnReceiveGeneralError += _client_OnReceiveGeneralError;
                _me = await _client.GetMeAsync();

                _client.StartReceiving();
                await LogHelper.LogInfo("Telegram bot connected!", Category);
            }
            catch (Exception ex)
            {
                await LogHelper.LogEx(ex.Message, ex, Category);
            }
            finally
            {
                IsRunning = false;
            }
        }
Ejemplo n.º 4
0
        private TelegramBotClient CreateClient(Constants constants)
        {
            if (!string.IsNullOrWhiteSpace(constants.BotProxy))
            {
                _logger.LogDebug("Telegram client proxy {proxy}", constants.BotProxy);

                var proxyString = constants.BotProxy.Split(':');
                var proxyHost   = proxyString[0];
                var proxyPort   = int.Parse(proxyString[1]);

                var proxy = new MihaZupan.HttpToSocks5Proxy(proxyHost, proxyPort);
                proxy.ResolveHostnamesLocally = true;

                return(new TelegramBotClient(constants.BotToken, proxy));
            }

            return(new TelegramBotClient(constants.BotToken));
        }
Ejemplo n.º 5
0
        /// <summary>
        ///		启动
        /// </summary>
        /// <param name="server">服务器</param>
        /// <param name="mode">模式</param>
        /// <returns>是否启动成功</returns>
        public bool Start(Objects.Server server, Objects.Mode mode)
        {
            try
            {
                if (server.Type == "Socks5")
                {
                    if (!String.IsNullOrWhiteSpace(server.Username) && !String.IsNullOrWhiteSpace(server.Password))
                    {
                        Instance = new MihaZupan.HttpToSocks5Proxy(server.Address, server.Port, server.Username, server.Password, 2802);
                    }
                    else
                    {
                        Instance = new MihaZupan.HttpToSocks5Proxy(server.Address, server.Port, 2802);
                    }
                }
                else
                {
                    Instance = new MihaZupan.HttpToSocks5Proxy("127.0.0.1", 2801, 2802);
                }

                using (var registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true))
                {
                    registry.SetValue("ProxyEnable", 1);
                    registry.SetValue("ProxyServer", "127.0.0.1:2802");

                    Win32Native.InternetSetOption(IntPtr.Zero, 39, IntPtr.Zero, 0);
                    Win32Native.InternetSetOption(IntPtr.Zero, 37, IntPtr.Zero, 0);
                }
            }
            catch (Exception e)
            {
                Utils.Logging.Info(e.ToString());
                return(false);
            }

            return(true);
        }