Пример #1
0
        private static void TelegramHandlerThread()
        {
            try
            {
                while (true)
                {
                    var telegramResponse = _telegramClient.Read();

                    if (telegramResponse != null)
                    {
                        // Get username and add colours
                        string username            = telegramResponse.Username;
                        string usernameWithColours = "\u0003" + "14" + username + "\u0003" + "\u0003" + "7" + "\u0002" + ":" + "\u0002" + "\u0003" + " ";

                        if (telegramResponse.IsImage)
                        {
                            string uploadUrl = _imgur.Upload(telegramResponse.ImageBytes).ImageUrl;
                            _ircClient.Write(ClientConnectionSettings.IRC_CHANNEL, usernameWithColours + uploadUrl);
                        }
                        else
                        {
                            string message = telegramResponse.Message;

                            // Don't want to send slash triggers to irc
                            if (message.StartsWith("/"))
                            {
                                HandleTelegramSlashTrigger(message);
                            }
                            else
                            {
                                _ircClient.Write(ClientConnectionSettings.IRC_CHANNEL, usernameWithColours + message);

                                if (message.StartsWith("!"))
                                {
                                    HandleTrigger(message);
                                }
                            }
                        }
                    }

                    Thread.Sleep(250);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.Write(ex.StackTrace);
            }
        }