Beispiel #1
0
    static async void BotOnInlineQueryReceived(object sender, InlineQueryEventArgs e)
    {
        var bot = (TelegramBotClient)sender;

        text.writeWithColor("InlineQuery (ID: ");
        text.writeWithColor(e.InlineQuery.Id, ConsoleColor.Blue);
        text.writeWithColor(" FromID: ");
        text.writeWithColor(e.InlineQuery.From.Id.ToString(), ConsoleColor.Blue);
        text.writeWithColor("): ");
        text.writeWithColor(e.InlineQuery.Query, ConsoleColor.DarkBlue, true);

        InlineQueryResult[] results =
        {
            new InlineQueryResultContact
            {
                Id                  = "1",
                FirstName           = "B.C.M.",
                PhoneNumber         = "+34 666777888",
                InputMessageContent = new InputContactMessageContent
                {
                    FirstName   = "Big Cash Monkeys",
                    PhoneNumber = "+34 666777888"
                }
            }
        };

        await bot.AnswerInlineQueryAsync(e.InlineQuery.Id, results, 0, true);
    }
Beispiel #2
0
        private async void BotOnInlineQueryReceived(object sender, InlineQueryEventArgs inlineQueryEventArgs)
        {
            //InlineQueryResult[] results = {
            //    new InlineQueryResultLocation
            //    {
            //        Id = "1",
            //        Latitude = 40.7058316f, // displayed result
            //        Longitude = -74.2581888f,
            //        Title = "New York",
            //        InputMessageContent = new InputLocationMessageContent // message if result is selected
            //        {
            //            Latitude = 40.7058316f,
            //            Longitude = -74.2581888f,
            //        }
            //    },

            //    new InlineQueryResultLocation
            //    {
            //        Id = "2",
            //        Longitude = 52.507629f, // displayed result
            //        Latitude = 13.1449577f,
            //        Title = "Berlin",
            //        InputMessageContent = new InputLocationMessageContent // message if result is selected
            //        {
            //            Longitude = 52.507629f,
            //            Latitude = 13.1449577f
            //        }
            //    }
            //};

            //await _bot.AnswerInlineQueryAsync(inlineQueryEventArgs.InlineQuery.Id, results, isPersonal: true, cacheTime: 0);
        }
Beispiel #3
0
        private async void BotClientOnOnInlineQuery(object sender, InlineQueryEventArgs inlineQueryEventArgs)
        {
            try
            {
                var queryString = inlineQueryEventArgs.InlineQuery.Query;
                var queries     = new[]
                {
                    QueryEvents(queryString),
                    //  QueryFursuitBadges(queryString)
                    //  QueryDealers(queryString)
                };

                Task.WaitAll(queries);
                var results = queries.SelectMany(task => task.Result).ToArray();

                if (results.Length == 0)
                {
                    return;
                }

                await _botClient.AnswerInlineQueryAsync(
                    inlineQueryEventArgs.InlineQuery.Id,
                    results,
                    cacheTime : 0);
            }
            catch (Exception ex)
            {
                _logger.LogError("BotClientOnOnInlineQuery failed: {Message} {StackTrace}",
                                 ex.Message, ex.StackTrace);
            }
        }
 async void InlineQueryHandlerForPrivateChat(object sender, InlineQueryEventArgs inlineQueryEventArgs)
 {
     await BotClient.AnswerInlineQueryAsync(inlineQueryEventArgs.InlineQuery.Id,
                                            new InlineQueryResult[] { },
                                            switchPmText : $"Go chat with {BotUser?.FirstName ?? "the bot"}"
                                            );
 }
Beispiel #5
0
        private static void BotOnOnInlineQuery(object sender, InlineQueryEventArgs inlineQueryEventArgs)
        {
            try
            {
                var query = inlineQueryEventArgs.InlineQuery;

                new Thread(() => HandleQuery(query)).Start();
            }
            catch (Exception e)
            {
                while (e.InnerException != null)
                {
                    e = e.InnerException;
                }
                var message = e.GetType() + " - " + e.Message;
                if (e is FileNotFoundException)
                {
                    message += " file: " + ((FileNotFoundException)e).FileName;
                }
                //else if (e is DirectoryNotFoundException)
                //    message += " file: " + ((DirectoryNotFoundException)e).;
                message += Environment.NewLine + e.StackTrace;
                Log.WriteLine($"Error in message handling: {message}", LogLevel.Error, fileName: "telegram.log");
            }
        }
Beispiel #6
0
        private async void BotOnInlineQueryReceived(object sender, InlineQueryEventArgs inlineQueryEventArgs)
        {
            logger.Info($"Received inline query from: {inlineQueryEventArgs.InlineQuery.From.Id}");

            InlineQueryResultBase[] results =
            {
                new InlineQueryResultLocation(
                    "1",
                    40.7058316f,
                    -74.2581888f,
                    "New York")     // displayed result
                {
                    InputMessageContent = new InputLocationMessageContent(
                        40.7058316f,
                        -74.2581888f)     // message if result is selected
                },

                new InlineQueryResultLocation(
                    "2",
                    13.1449577f,
                    52.507629f,
                    "Berlin")     // displayed result
                {
                    InputMessageContent = new InputLocationMessageContent(
                        13.1449577f,
                        52.507629f)     // message if result is selected
                }
            };

            await _bot.AnswerInlineQueryAsync(
                inlineQueryEventArgs.InlineQuery.Id,
                results,
                isPersonal : true,
                cacheTime : 0);
        }
        private void Client_OnInlineQuery(object sender, InlineQueryEventArgs e)
        {
            if (e.Query.Query.StartsWith(IqPrefix))
            {
                _log.Info($"Inline query from {e.Query.From.DisplayName()} ({e.Query.From.ID}) for query {e.Query.Query}");

                e.Query.Query = e.Query.Query.TrimEnd('@');
                string raidID         = e.Query.Query.Substring(IqPrefix.Length);
                var    raidCollection = DB.GetCollection <RaidParticipation>();
                var    raid           = raidCollection.Find(x => x.PublicID == raidID).FirstOrDefault();

                List <InlineQueryResultArticle> results = new List <InlineQueryResultArticle>();

                if (null != raid)
                {
                    string text   = CreateRaidText(raid);
                    var    markup = CreateMarkupFor(raid);
                    results.Add(new InlineQueryResultArticle
                    {
                        id                    = raid.PublicID,
                        title                 = $"{raid.Raid.Raid} {TimeService.AsShortTime(raid.Raid.RaidUnlockTime)}-{TimeService.AsShortTime(raid.Raid.RaidEndTime)}",
                        description           = _HTML_(I18N.GetString("{0} raid at {1} {2}", raid.Raid.Raid, raid.Raid.Gym, raid.Raid.Address)),
                        input_message_content = new InputMessageContent
                        {
                            message_text             = text,
                            parse_mode               = "HTML",
                            disable_web_page_preview = true,
                        },
                        reply_markup = markup,
                    });
                }

                Client.AnswerInlineQuery(e.Query.ID, results);
            }
        }
Beispiel #8
0
        private static async void OnInlineHandler(object sender, InlineQueryEventArgs e)
        {
            InlineQueryResultBase baseResult;

            try
            {
                Entity calculated = e.InlineQuery.Query.Solve("x");
                if (calculated.Complexity < bot.BotConfig.SimplifyComplexityThreshold)
                {
                    calculated = calculated.Simplify();
                }

                using var stream = bot.LatexRenderer.Render(@"Input: " + e.InlineQuery.Query.Latexise() + @"\\\\" + calculated.Latexise());
                baseResult       = await bot.TrySendPhoto(stream, e.InlineQuery.Query, calculated.Stringize());
            }
            catch (Exception ex)
            {
                baseResult = new InlineQueryResultArticle(
                    id: "0",
                    title: "We can't process your request.",
                    inputMessageContent: new InputTextMessageContent(ex.Message + ": " + e.InlineQuery.Query)
                    )
                {
                    Description = ex.Message
                };

                bot.Logger.Info(ex, $"Can't evaluate query {e.InlineQuery.Query}: {ex.Message}");
            }

            bot.SendSingleInlineQueryAnswer(e.InlineQuery.Id, baseResult);
        }
Beispiel #9
0
        private static async void BotOnInlineQueryReceived(object sender, InlineQueryEventArgs inlineQueryEventArgs)
        {
            InlineQueryResult[] results =
            {
                new InlineQueryResultLocation
                {
                    Id                  = "1",
                    Latitude            = 40.7058316f, // displayed result
                    Longitude           = -74.2581888f,
                    Title               = "New York",
                    InputMessageContent = new InputLocationMessageContent // message if result is selected
                    {
                        Latitude  = 40.7058316f,
                        Longitude = -74.2581888f,
                    }
                },

                new InlineQueryResultLocation
                {
                    Id                  = "2",
                    Longitude           = 52.507629f, // displayed result
                    Latitude            = 13.1449577f,
                    Title               = "Berlin",
                    InputMessageContent = new InputLocationMessageContent // message if result is selected
                    {
                        Longitude = 52.507629f,
                        Latitude  = 13.1449577f
                    }
                }
            };

            await Bot.AnswerInlineQueryAsync(inlineQueryEventArgs.InlineQuery.Id, results, isPersonal : true, cacheTime : 0);
        }
        private static async void BotOnInlineQueryReceived(object sender, InlineQueryEventArgs inlineQueryEventArgs)
        {
            InlineQueryResult[] results = {
                new InlineQueryResultLocation
                {
                    Id = "1",
                    Latitude = 40.7058316f, // displayed result
                    Longitude = -74.2581888f,
                    Title = "New York",
                    InputMessageContent = new InputLocationMessageContent // message if result is selected
                    {
                        Latitude = 40.7058316f,
                        Longitude = -74.2581888f,
                    }
                },

                new InlineQueryResultLocation
                {
                    Id = "2",
                    Longitude = 52.507629f, // displayed result
                    Latitude = 13.1449577f,
                    Title = "Berlin",
                    InputMessageContent = new InputLocationMessageContent // message if result is selected
                    {
                        Longitude = 52.507629f,
                        Latitude = 13.1449577f
                    }
                }
            };

            await Bot.AnswerInlineQueryAsync(inlineQueryEventArgs.InlineQuery.Id, results, isPersonal: true, cacheTime: 0);
        }
Beispiel #11
0
        public string GetResult(InlineQueryEventArgs inlineQueryEventArgs)
        {
            string result      = "";
            var    query       = inlineQueryEventArgs.InlineQuery.Query;
            var    command     = query.Substring(0, query.IndexOf("///")).Split(' ');
            var    projectName = command[0].ToLower();
            var    taskType    = command[1].ToLower();

            taskType = taskType.Contains("task") || taskType.Contains("feature") || taskType.Contains("bug") ? taskType : "";
            var taskName = command[2];
            var taskDesc = BuildDescription(command);

            Project currentProject = null;

            foreach (var item in Projects)
            {
                if (item.ShortName.ToLower() == projectName.ToLower())
                {
                    currentProject = item;
                    break;
                }
            }

            if (currentProject == null)
            {
                result = $"Проект с именем (ID) {projectName} не найден!";
            }
            else
            {
                result = Task.Run(async() => await youTrackPoster.PostIssue(currentProject, taskName, taskType, taskDesc)).Result;
                //result = $"Проект: {projectName}\r\nТип задачи: {taskType}\r\nНаменование: {taskName}\r\nОписание: {taskDesc}\r\nРезультат: Ok";
            }
            return(result);
        }
Beispiel #12
0
        private static async void BotOnInlineQueryReceived(object sender, InlineQueryEventArgs inlineQueryEventArgs)
        {
            Console.WriteLine($"Received inline query from: {inlineQueryEventArgs.InlineQuery.From.Id}");
            if (!inlineQueryEventArgs.InlineQuery.Query.EndsWith("///"))
            {
                return;
            }

            string result = new CommandParser(Settings).GetResult(inlineQueryEventArgs);

            InlineQueryResultBase[] results =
            {
                new InlineQueryResultArticle(id: QueryId.ToString(), title: "Результат", inputMessageContent: new InputTextMessageContent(result))
            };

            try {
                await Bot.AnswerInlineQueryAsync(
                    inlineQueryEventArgs.InlineQuery.Id,
                    results,
                    isPersonal : true,
                    cacheTime : 0);
            }
            catch (Exception)
            {
            }

            QueryId++;
        }
        private static async void BotOnInlineQueryReceived(object sender, InlineQueryEventArgs inlineQueryEventArgs)
        {
            Console.WriteLine($"Received inline query from: {inlineQueryEventArgs.InlineQuery.From.Id}");

            InlineQueryResultBase[] results =
            {
                new InlineQueryResultLocation(
                    id: "1",
                    latitude: 40.7058316f,
                    longitude: -74.2581888f,
                    title: "New York")   // displayed result
                {
                    InputMessageContent = new InputLocationMessageContent(
                        latitude: 40.7058316f,
                        longitude: -74.2581888f)        // message if result is selected
                },

                new InlineQueryResultLocation(
                    id: "2",
                    latitude: 13.1449577f,
                    longitude: 52.507629f,
                    title: "Berlin") // displayed result
                {
                    InputMessageContent = new InputLocationMessageContent(
                        latitude: 13.1449577f,
                        longitude: 52.507629f)       // message if result is selected
                }
            };

            await Bot.AnswerInlineQueryAsync(
                inlineQueryEventArgs.InlineQuery.Id,
                results,
                isPersonal : true,
                cacheTime : 0);
        }
Beispiel #14
0
        private static async void BotOnInlineQueryReceived(object sender, InlineQueryEventArgs inlineQueryEventArgs)
        {
            Console.WriteLine($"Received inline query from: {inlineQueryEventArgs.InlineQuery.From.Id}");

            Console.WriteLine($"Received inline query from: {inlineQueryEventArgs.InlineQuery.Query}");

            Utils.reflectInlineCommands(inlineQueryEventArgs.InlineQuery);
        }
Beispiel #15
0
 private static async void OnInlineQuery(object sender, InlineQueryEventArgs e)
 {
     if (e.InlineQuery != null)
     {
         await router.HandleAsync(e.InlineQuery.Query, e.InlineQuery);
     }
     Console.WriteLine($"{e.InlineQuery.From.FirstName} {e.InlineQuery.From.LastName}: {e.InlineQuery.Query}");
 }
Beispiel #16
0
        private async void Bot_OnInlineQuery(object sender, InlineQueryEventArgs e)
        {
            var message = e.InlineQuery;

            QSUser Usr = CheckTheUser(message.From.Id.ToString(),
                                      message.From,
                                      message.From.FirstName + " " + message.From.LastName);


            var vis       = Usr.QS.FindVisualization(e.InlineQuery.Query);
            var MasterMea = Usr.QS.GetMasterMeasure(e.InlineQuery.Query);
            var MasterVis = Usr.QS.GetMasterVisualizations(e.InlineQuery.Query);

            //var MasterDim = Usr.QS.GetMasterDimensions(e.InlineQuery.Query);
            //Console.WriteLine(Usr.QS.GetExpressionValue(MasterDim.Expression));
            Console.WriteLine("Inline query " + message.Query + " received by " + message.From.Id);
            InlineQueryResult[] results =
            {
                new InlineQueryResultArticle {
                    Description         = "Visualizations",
                    Id                  = "1",
                    Title               = vis.Title,
                    InputMessageContent = new InputTextMessageContent{
                        MessageText = vis.Title
                    }
                    , Url      = Usr.QS.PrepareVisualizationDirectLink(vis)
                    , ThumbUrl = Usr.QS.GetVisualizationThumbnailUrl(vis.Type), HideUrl = true
                },
                new InlineQueryResultArticle {
                    Description         = "Master Visualizations",
                    Id                  = "2",
                    Title               = MasterVis.Name,
                    InputMessageContent = new InputTextMessageContent{
                        MessageText = MasterVis.Name
                    },
                    Url     = Usr.QS.PrepareMasterVisualizationDirectLink(MasterVis),
                    HideUrl = true
                },
                new InlineQueryResultArticle {
                    Description         = "Measures",
                    Id                  = "3",
                    Title               = MasterMea.Name,
                    InputMessageContent = new InputTextMessageContent{
                        MessageText = ("The value of Measure " + MasterMea.Name + " is " + MasterMea.FormattedExpression)
                    }
                }
                //new InlineQueryResultArticle {
                //      Description = "Dimensions",
                //      Id ="4",
                //      Title = MasterDim.Name,
                //      InputMessageContent = new InputTextMessageContent { MessageText=  MasterDim.Name + ": " + Usr.QS.GetExpressionValue(MasterDim.Expression)}

                //  }
            };

            await Bot.AnswerInlineQueryAsync(e.InlineQuery.Id, results, isPersonal : true, cacheTime : 0);
        }
Beispiel #17
0
        private void BotClient_OnInlineQuery(object sender, InlineQueryEventArgs e)
        {
            InlineQuery inlineQuery = e ? .InlineQuery;

            if (!(inlineQuery is null))
            {
                string req = inlineQuery.Query;
            }
        }
        private static async void BotOnInlineQueryReceived(object sender, InlineQueryEventArgs inlineQueryEventArgs)
        {
            _rnd = new Random(DateTime.Now.Millisecond);
            var rand1 = _rnd.Next().ToString();
            var rand2 = _rnd.Next().ToString();
            var rand3 = _rnd.Next().ToString();
            var rand4 = _rnd.Next().ToString();

            InlineQueryResult[] results =
            {
                new InlineQueryResultArticle
                {
                    Id                  = "1",
                    Title               = "Random value:",
                    Description         = rand1,
                    InputMessageContent = new InputTextMessageContent
                    {
                        MessageText = rand1
                    }
                },
                new InlineQueryResultArticle
                {
                    Id                  = "2",
                    Title               = "Random value:",
                    Description         = rand2,
                    InputMessageContent = new InputTextMessageContent
                    {
                        ParseMode   = ParseMode.Default,
                        MessageText = rand2
                    }
                },
                new InlineQueryResultArticle
                {
                    Id                  = "3",
                    Title               = "Random value:",
                    Description         = rand3,
                    InputMessageContent = new InputTextMessageContent
                    {
                        ParseMode   = ParseMode.Default,
                        MessageText = rand3
                    }
                },
                new InlineQueryResultArticle
                {
                    Id                  = "4",
                    Title               = "Random value:",
                    Description         = rand4,
                    InputMessageContent = new InputTextMessageContent
                    {
                        ParseMode   = ParseMode.Default,
                        MessageText = rand4
                    }
                }
            };

            await Bot.AnswerInlineQueryAsync(inlineQueryEventArgs.InlineQuery.Id, results, isPersonal : true, cacheTime : 0);
        }
Beispiel #19
0
        private async void OnInlineQueryReceived(object sender, InlineQueryEventArgs inlineQueryEventArgs)
        {
            _logger.LogInformation($"Received inline query from: {inlineQueryEventArgs.InlineQuery.From.Id}");

            InlineQueryResultBase[] results =
            {
                new InlineQueryResultArticle("3", "Tg_clients", new InputTextMessageContent("hello"))
            };
            await _client.AnswerInlineQueryAsync(inlineQueryEventArgs.InlineQuery.Id, results, isPersonal : true, cacheTime : 0);
        }
Beispiel #20
0
    private static async void BotOnInlineQueryReceived(object sender, InlineQueryEventArgs inlineQueryEventArgs)
    {
        Console.WriteLine($"Received inline query from: {inlineQueryEventArgs.InlineQuery.From.Id}");



        await Bot.AnswerInlineQueryAsync(
            inlineQueryEventArgs.InlineQuery.Id,
            results,
            isPersonal : true,
            cacheTime : 0);
    }
Beispiel #21
0
        static async void Bot_OnInlineQuery(object sender, InlineQueryEventArgs e)
        {
            Console.WriteLine($"Received inline query from: {e.InlineQuery.From.Id}: {e.InlineQuery.Query}");
            var results = await SearchByQuery(e.InlineQuery.Query);

            await botClient.AnswerInlineQueryAsync(
                inlineQueryId : e.InlineQuery.Id,
                results : results,
                isPersonal : true,
                cacheTime : 0
                );
        }
        //: ALSO NEEDS TO BE TESTED. CREATE A NEW REGEX TO DETECT QUERIES
        public static bool TryGetArgs(this InlineQueryEventArgs e, [NotNull] out IReadOnlyList <string> args)
        {
            var match = FluentRegex.CheckCommand.Match(e?.InlineQuery?.Query ?? "");

            if (match.Success)
            {
                args = match.Groups[2].Value.Split(' ', StringSplitOptions.RemoveEmptyEntries); return(true);
            }
            else
            {
                args = Array.Empty <string>(); return(false);
            }
        }
Beispiel #23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async Task OnInlineQuery(object sender, InlineQueryEventArgs e)
        {
            _log.Information("Inline query {queryId} received.", e.InlineQuery.Id);

            try
            {
                await _queryHandler.HandleAsync(e.InlineQuery);
            }
            catch (Exception ex)
            {
                _log.Error(ex, "Inline query error");
            }
        }
Beispiel #24
0
        async void ProcessInline(object si, InlineQueryEventArgs ei)
        {
            var  query = ei.InlineQuery.Query;
            User user  = User.CreateNewUserFrom(ei.InlineQuery.From);

            Logger.Info("инлайн от " + user.NameWithTelegramId + ": " + query);
            var results = await CreateAnswerInline(query);

            if (results != null)
            {
                await SendAnswerInline(ei.InlineQuery.Id, results);
            }
        }
Beispiel #25
0
        private async void TelegramBotClientOnOnInlineQuery(object sender, InlineQueryEventArgs e)
        {
            string url = "https://images.ctfassets.net/9n3x4rtjlya6/2JnpX9q4fypdaeNjdhhbzz/dc2d2542b6fd121ed7a1e71d557802b6/prosin.jpg";
            var    l   = new List <InlineQueryResultPhoto>();

            l.Add(new InlineQueryResultPhoto("1", url + "?w=200", url + "?w=150")
            {
                Caption     = "Рома Просин",
                Description = "Спикер из Райфа",
                Title       = "Code Review",
            });

            await _telegramBotClient.AnswerInlineQueryAsync(e.InlineQuery.Id, l, isPersonal : true, cacheTime : 0);
        }
Beispiel #26
0
        public static void InlineActor(TelegramBotClient api, InlineQueryEventArgs e)
        {
            string text = e.InlineQuery.Query;

            string url = GetGifUrl(text);

            //Stream stream = new FileStream(path, FileMode.Open);

            Console.WriteLine(url);

            api.AnswerInlineQueryAsync(e.InlineQuery.Id, new Telegram.Bot.Types.InlineQueryResults.InlineQueryResultBase[] {
                new Telegram.Bot.Types.InlineQueryResults.InlineQueryResultGif("1", url, url)
            }, 12000);
        }
Beispiel #27
0
        private static async void OnInlineQueryAsync(object sender, InlineQueryEventArgs e)
        {
            try
            {
                var inlineQuery = e.InlineQuery;

                if (string.IsNullOrEmpty(inlineQuery.Query))
                {
                    return;
                }

                using var responseMessage = await HttpClient.PostAsync("https://www.shitexpress.com/status.php", new FormUrlEncodedContent (new Dictionary <string, string>()
                {
                    { "id", inlineQuery.Query }
                }));

                var contentString = await responseMessage.Content.ReadAsStringAsync();

                var text = new StringBuilder();

                if (contentString == string.Empty)
                {
                    text.AppendLine("Order not found - wrong ID. Try again, please.");
                }
                else
                {
                    string[] split = contentString.Split('|');

                    string status = int.Parse(split[1]) switch
                    {
                        0 => "Order received. Your package will be processed in 48 hours.",
                        1 => "Processing the order. Your package will be shipped in 48 hours.",
                        2 => "Your package has been shipped."
                    };

                    text.AppendLine("*Status:* " + status)
                    .AppendLine("*Last update:* " + split[2]);
                }

                await _bot.AnswerInlineQueryAsync(inlineQuery.Id, new[]
                {
                    new InlineQueryResultArticle(inlineQuery.Query, inlineQuery.Query, new InputTextMessageContent(text.ToString())
                    {
                        ParseMode = ParseMode.Markdown
                    })
                });
            }
            catch { }
        }
Beispiel #28
0
        private static async void OnInlineHandlerTimeout(object sender, InlineQueryEventArgs e)
        {
            var task = Task.Run(() => OnInlineHandler(sender, e));

            if (await Task.WhenAny(task, Task.Delay(bot.BotConfig.ComputationTimeLimit)) != task)
            {
                InlineQueryResultArticle result = new(
                    id : "0",
                    title : "Computation time exceeded",
                    inputMessageContent : new InputTextMessageContent("Computation time exceeded: " + e.InlineQuery.Query)
                    );

                bot.SendSingleInlineQueryAnswer(e.InlineQuery.Id, result);
                bot.Logger.Info($"Computation time exceeded for query '{e.InlineQuery.Query}'");
            }
        }
Beispiel #29
0
        // end

        private void UpdatesThread()
        {
            Logger.LogMessage("Бот запущен.");
            while (isRun)
            {
                var updates = GetUpdates();

                foreach (var update in updates)
                {
                    updateOffset = update.UpdateId + 1;

                    if (update.CallbackQuery != null && OnCallbackQuery != null)
                    {
                        var args = new CallbackQueryEventArgs
                        {
                            CallbackQuery = update.CallbackQuery
                        };

                        OnCallbackQuery(args);
                    }

                    if (update.Message != null && OnMessage != null)
                    {
                        var args = new TelegramMessageEventArgs
                        {
                            ChatId    = update.Message.Chat.Id,
                            MessageId = update.Message.MessageId,
                            From      = update.Message.From,
                            Message   = update.Message
                        };

                        OnMessage(args);
                    }
                    if (update.InlineQuery != null && OnInlineQuery != null)
                    {
                        var args = new InlineQueryEventArgs
                        {
                            InlineQuery = update.InlineQuery
                        };

                        OnInlineQuery(args);
                    }
                }

                System.Threading.Thread.Sleep(1000);
            }
        }
Beispiel #30
0
        private async void Bot_OnInlineQuery(object sender, InlineQueryEventArgs e)
        {
            int page = 0;

            if (lastFilesQuery == null)
            {
                await Task.FromResult(1);
            }
            else
            {
                int.TryParse(e.InlineQuery.Offset, out page);

                const int batchSize            = 30;
                var       accessor             = lastFilesQuery.Skip(page * batchSize).Take(batchSize);
                InlineQueryResultBase[] result = accessor.Select((file) => PhotoResult(file)).ToArray();

                var thrds = lastFilesQuery.Skip(page * batchSize).Take(batchSize).AsParallel().WithMergeOptions(ParallelMergeOptions.NotBuffered);
                Console.WriteLine("make file started " + thrds.Count());
                thrds.ForAll(storageItem =>
                {
                    if (!storageItem.IsFile)
                    {
                        return;
                    }
                    var mapa    = MemoryMappedFile.CreateOrOpen(storageItem.Hash, 8.KB(), MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.DelayAllocatePages, HandleInheritability.None);
                    var thumb   = mapa.CreateViewStream();
                    var command = FFTools.CreateInlineThumbnail(storageItem.FullPath, 120, ref thumb);
                    command.Wait();
                    thumb.Close();
                    memoryFiles.Add(mapa);
                });

                string nextPage = result.Length < batchSize ? "" :(page += 1).ToString();
                try
                {
                    await Task.Delay(1000).ContinueWith(t => Bot.AnswerInlineQueryAsync(e.InlineQuery.Id, result, 0, false, nextPage));
                }catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

                Console.WriteLine("method ended");
                Console.WriteLine("return");
            }
        }
Beispiel #31
0
        private async void BotOnInlineQueryReceived(object sender, InlineQueryEventArgs inlineQueryEventArgs)
        {
            var userfrom = inlineQueryEventArgs.InlineQuery.From;
            var user     = ApplicationData.GetUser(userfrom.Id);

            long   userId   = inlineQueryEventArgs.InlineQuery.From.Id;
            string userName = (inlineQueryEventArgs.InlineQuery.From.FirstName + " " + inlineQueryEventArgs.InlineQuery.From.LastName).Replace(" ", "\\ ").Replace("=", "\\=");

            InfluxDBLiteClient.Query($"bots,botname=wsizbusbot,user_id={userId},user_name={userName},actiontype=inline action=true");

            var handler = new InlineQueryController();

            handler.Bot  = Bot;
            handler.User = user;
            handler.InlineQueryEventArgs = inlineQueryEventArgs;

            await handler.Execute();
        }