Skip to content

Commit

Permalink
Add coordinates to pafta bulucu bot message (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrcn committed Jun 8, 2020
1 parent bc80386 commit 15f0dc2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
16 changes: 9 additions & 7 deletions src/Gu.PaftaBulucu.Bot/Services/BotService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using Gu.PaftaBulucu.Business.Services;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using Gu.PaftaBulucu.Bot.Models;
using System.Threading.Tasks;
using System.Web;

namespace Gu.PaftaBulucu.Bot.Services
{
Expand Down Expand Up @@ -81,7 +81,7 @@ public async Task<bool> QuerySheetAsync(int linkedMessageId, string callbackQuer
{
var coordinates = await _amazonDynamoDbService.QueryAsync(chatId);

var sheets = _sheetService.GetSheetsByCoordinate(coordinates.lat, coordinates.lon, scale);
var sheets = _sheetService.GetSheetsByCoordinate(coordinates.lat, coordinates.lon, scale).ToList();

if (!sheets.Any())
{
Expand All @@ -103,21 +103,23 @@ public async Task<bool> QuerySheetAsync(int linkedMessageId, string callbackQuer

await _telegramService.AnswerCallbackQuery(answerCallbackQuery);

var messageText = $"Arama sonucu (1:{scale}.000): ";

string messageText;
if (sheets.Count() > 1)
{
messageText = "\nBirden fazla pafta ile kesişiyor:\n";
messageText = "Birden fazla pafta ile kesişiyor:";
foreach (var sheetDto in sheets)
{
messageText += "\n" + sheetDto.Name;
}
}
else
{
messageText += sheets.FirstOrDefault().Name;
messageText = sheets.FirstOrDefault().Name;
}

messageText += $"\nÖlçek: 1:{scale}.000";
messageText += $"\nKoordinatlar: {coordinates.lat:F6}, {coordinates.lon:F6}";

var message = new TelegramMessage
{
ChatId = chatId.ToString(),
Expand Down
6 changes: 1 addition & 5 deletions src/Gu.PaftaBulucu.Bot/Services/TelegramService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ public async Task<bool> DeleteMessage(TelegramDeleteMessage telegramDeleteMessag

using var client = new HttpClient();
using var response = await client.PostAsync(url, content);
if (!response.IsSuccessStatusCode)
{
throw new Exception(await response.Content.ReadAsStringAsync());
}
return true;
return response.IsSuccessStatusCode;
}

public async Task<bool> SendMessage(TelegramMessage message)
Expand Down

0 comments on commit 15f0dc2

Please sign in to comment.