public async Task <bool?> Handle(InlineQuery data, object context = default, CancellationToken cancellationToken = default) { var queryParts = new StringSegment(data.Query).Split(new[] { ' ' }).FirstOrDefault().Split(new[] { ':' }); if (!PollEx.TryGetPollId(queryParts.ElementAtOrDefault(1), out var pollId, out var format)) { return(null); } var poll = (await myRaidService.GetOrCreatePollAndMessage(new PollMessage(data) { BotId = myBot.BotId, PollId = pollId }, myUrlHelper, format, cancellationToken))?.Poll; if (poll == null) { return(null); } var result = await GetResult(poll, cancellationToken); result ??= new InlineQueryResultArticle("NobodyToInvite", "Nobody to invite", new TextBuilder().Sanitize($"Nobody to invite").ToTextMessageContent()) { ThumbUrl = myUrlHelper.AssetsContent(@"static_assets/png/btn_close_normal.png").ToString() }; await myBot.AnswerInlineQueryWithValidationAsync(data.Id, new[] { result }, cacheTime : 0, isPersonal : true, cancellationToken : cancellationToken); return(true); }
public async Task <bool?> Handle(ChosenInlineResult data, object context = default, CancellationToken cancellationToken = default) { var resultParts = data.ResultId.Split(':'); switch (resultParts[0]) { case PollEx.InlineIdPrefix: if (!PollEx.TryGetPollId(resultParts.ElementAtOrDefault(1), out var pollId, out var format)) { return(null); } var pollMessage = await myRaidService.GetOrCreatePollAndMessage(new PollMessage(data) { PollId = pollId }, myUrlHelper, format, cancellationToken); if (pollMessage != null) { if (pollMessage.Poll is Poll poll && (poll.Portal?.Guid ?? poll.PortalId) is string guid) { await myPoGoToolsClient.UpdateWayspot(guid, poll.ExRaidGym?Wayspot.ExRaidGym : Wayspot.Gym, cancellationToken); } return(true); } return(false); } return(null); }
public async Task <(string, bool, string)> Handle(CallbackQuery data, object context = default, CancellationToken cancellationToken = default) { var callback = data.Data.Split(':'); if (callback[0] != "adjust") { return(null, false, null); } if (!PollEx.TryGetPollId(callback.ElementAtOrDefault(1), out var pollId, out var format)) { return("Poll is publishing. Try later.", true, null); } if (!int.TryParse(callback.ElementAtOrDefault(2) ?? "", NumberStyles.Integer, CultureInfo.InvariantCulture, out var offset)) { return("", false, null); } var poll = (await myRaidService.GetOrCreatePollAndMessage(new PollMessage(data) { PollId = pollId }, myUrlHelper, format, cancellationToken))?.Poll; if (poll == null) { return("Poll is not found.", true, null); } var user = data.From; if (!await myChatInfo.CandEditPoll(poll.Owner, user.Id, cancellationToken)) { return("You can't edit the poll.", true, null); } poll.Time = poll.Time?.AddMinutes(offset); if (poll.Time > poll.Raid?.RaidBossEndTime) { return($"Raid will end in {poll.Time:t}.", true, null); } var changed = await myContext.SaveChangesAsync(cancellationToken) > 0; if (changed) { await myRaidService.UpdatePoll(poll, myUrlHelper, cancellationToken); } return($"Poll is scheduled at {poll.Time:t}.", false, null); }
public async Task <(string, bool, string)> Handle(CallbackQuery data, object context = default, CancellationToken cancellationToken = default) { var callback = data.Data?.Split(':'); if (callback?[0] != ID) { return(null, false, null); } PollMessage pollMessage; if (callback.ElementAtOrDefault(1) is var pollIdSegment && PollEx.TryGetPollId(pollIdSegment, out var pollId, out var format)) { pollMessage = await myRaidService.GetOrCreatePollAndMessage(new PollMessage(data) { BotId = myBot.BotId, PollId = pollId }, myUrlHelper, format, cancellationToken); }
async Task <bool?> IHandler <InlineQuery, object, bool?> .Handle(InlineQuery data, object context, CancellationToken cancellationToken) { var queryParts = new StringSegment(data.Query).Split(new[] { ':' }); if (queryParts.First() != ID) { return(null); } var inlineQueryResults = Enumerable.Empty <InlineQueryResult>(); if (!PollEx.TryGetPollId(queryParts.ElementAtOrDefault(1), out var pollId, out var format)) { inlineQueryResults = await GetActivePolls(data.From, cancellationToken); }
public IActionResult Index(string id) { if (PollEx.TryGetPollId(id, out var pollId, out var format)) { return(Json(new { pollId, format, buttons = format?.ToString(), encoded = new PollId { Id = pollId, Format = format ?? VoteEnum.None }.ToString() })); } return(UnprocessableEntity()); }
public async Task <(string, bool, string)> Handle(CallbackQuery data, object context = default, CancellationToken cancellationToken = default) { var callback = data.Data.Split(':'); if (callback[0] != "cancel") { return(null, false, null); } if (!PollEx.TryGetPollId(callback.ElementAtOrDefault(1), out var pollId, out var format)) { return("Poll is publishing. Try later.", true, null); } var poll = (await myRaidService.GetOrCreatePollAndMessage(new PollMessage(data) { PollId = pollId }, myUrlHelper, format, cancellationToken))?.Poll; if (poll == null) { return("Poll is not found.", true, null); } var user = data.From; if (!await myChatInfo.CandEditPoll(poll.Owner, user.Id, cancellationToken)) { return("You can't cancel the poll.", true, null); } poll.Cancelled = true; var changed = await myContext.SaveChangesAsync(cancellationToken) > 0; if (changed) { await myRaidService.UpdatePoll(poll, myUrlHelper, cancellationToken); } return(changed ? "Poll is canceled." : "Poll is already canceled.", false, null); }
public async Task <(string text, bool showAlert, string url)> Handle(CallbackQuery data, object context = default, CancellationToken cancellationToken = default) { var callback = data.Data.Split(':'); if (callback[0] != ID) { return(null, false, null); } if (!PollEx.TryGetPollId(callback.ElementAtOrDefault(1), out var pollId, out var format)) { return("Poll is publishing. Try later.", true, null); } if (!Enum.TryParse <PollMode>(callback.ElementAtOrDefault(2) ?? "", out var pollMode)) { return("", false, null); } var pollMessage = await myRaidService.GetOrCreatePollAndMessage(new PollMessage(data) { BotId = myBot.BotId, PollId = pollId }, myUrlHelper, format, cancellationToken); if (pollMessage.Poll == null) { return("Poll is not found.", true, null); } pollMessage.PollMode = pollMode; var changed = await myDb.SaveChangesAsync(cancellationToken) > 0; if (changed) { await myRaidService.UpdatePollMessage(pollMessage, myUrlHelper, cancellationToken); return("Mode have been switched", false, null); } return(null, false, null); }
public async Task <(string, bool, string)> Handle(CallbackQuery data, object context = default, CancellationToken cancellationToken = default) { var callback = new StringSegment(data.Data).Split(new[] { ':' }); if (callback.First() != ID) { return(null, false, null); } if (myBlackList.Contains(data.From.Id)) { return(null, false, null); } Poll poll; if (callback.ElementAtOrDefault(1) is var pollIdSegment && PollEx.TryGetPollId(pollIdSegment, out var pollId, out var format)) { poll = (await myRaidService.GetOrCreatePollAndMessage(new PollMessage(data) { PollId = pollId }, myUrlHelper, format, cancellationToken))?.Poll; }