void onMsg(object obj, MessageEventArgs messageEventArgs)
        {
            var tId = string.Format("{0:d3}_newMsg_", Thread.CurrentThread.ManagedThreadId);
            tgLog.l(tId + DateTime.Now.ToString());
            var message = messageEventArgs.Message;
            //log.Info(message.Chat.Id.ToString());
            if (message == null) return;

            tgLog.l(tId + "Type " + message.Type);
            tgLog.l(tId + "From " + message.Chat.Id);
            FileStream s = null;
            string textFromVoice = "";
            if (message.Type == MessageType.VoiceMessage)
            {
                var remoteFile = message.Voice;
                var voice = bot.GetFileAsync(remoteFile.FileId, s).Result;
                var YandexMime = MimeConverter.Convert(remoteFile.MimeType);

                textFromVoice = YaSpeech.PostMethod(voice.FileStream, YandexMime);
                textFromVoice = Process(textFromVoice);
                if (String.IsNullOrWhiteSpace(textFromVoice)) textFromVoice = "#itsempty";
                bot.SendTextMessageAsync(message.Chat.Id, textFromVoice);
            }
            else if (message.Type == MessageType.DocumentMessage)
            {
                var remoteFile = message.Document;
                var docVoice = bot.GetFileAsync(remoteFile.FileId, s).Result;
                var YandexMime = MimeConverter.Convert(remoteFile.MimeType);

                textFromVoice = YaSpeech.PostMethod(docVoice.FileStream, YandexMime);
                textFromVoice = Process(textFromVoice);
                bot.SendTextMessageAsync(message.Chat.Id, textFromVoice);
            }
            tgLog.l(tId + textFromVoice);
        }
Ejemplo n.º 2
0
        // ReSharper disable once UnusedMember.Local
        private void OnExecute()
        {
            Console.OutputEncoding = Encoding.Unicode;

            ILoggerFactory loggerFactory     = LoggerFactory.Create(o => { o.AddConsole().SetMinimumLevel(LogLevel.Debug); });
            var            conversionOptions = new MimeConversionOptions
            {
                CompressCss           = true,
                CompressHtml          = true,
                CompressImages        = true,
                JpegCompressorQuality = 100,
                MaxPngColors          = 256
            };
            var    converter      = new MimeConverter(conversionOptions, loggerFactory.CreateLogger <MimeConverter>());
            string outputFilename = Path.ChangeExtension(Source, "html");

            using FileStream sourceStream      = File.OpenRead(Source);
            using FileStream destinationStream = File.Open(outputFilename, FileMode.Create);
            bool result = converter.Convert(sourceStream, destinationStream).Result;

            if (!result)
            {
                Environment.Exit(-1);
            }
        }