-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ce2fdc
commit 6f0f5c4
Showing
15 changed files
with
246 additions
and
7 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file added
BIN
+13.3 KB
FTelegramBot/.vs/FTelegramBot/FileContentIndex/25bd8d74-8a3b-4a9f-a6f4-7c14661359d8.vsidx
Binary file not shown.
Binary file added
BIN
+107 Bytes
FTelegramBot/.vs/FTelegramBot/FileContentIndex/310c5a77-775b-41ab-92f7-adc1230910f5.vsidx
Binary file not shown.
Binary file removed
BIN
-3.26 KB
FTelegramBot/.vs/FTelegramBot/FileContentIndex/37af9485-709f-496d-868d-7120dc59cd56.vsidx
Binary file not shown.
Binary file added
BIN
+107 Bytes
FTelegramBot/.vs/FTelegramBot/FileContentIndex/3831d6b4-8217-4a02-a685-d5e1c97b0303.vsidx
Binary file not shown.
Binary file added
BIN
+107 Bytes
FTelegramBot/.vs/FTelegramBot/FileContentIndex/67f6e247-c3b6-48f9-822b-32f227bf8f31.vsidx
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,144 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
Console.WriteLine("Hello, World!"); | ||
using Film_bot.Broker; | ||
using Telegram.Bot; | ||
using Telegram.Bot.Exceptions; | ||
using Telegram.Bot.Polling; | ||
using Telegram.Bot.Types; | ||
using Telegram.Bot.Types.Enums; | ||
using Telegram.Bot.Types.ReplyMarkups; | ||
|
||
internal class Program | ||
{ | ||
private static async Task Main(string[] args) | ||
{ | ||
var botClient = new TelegramBotClient("6573404549:AAEpIzNU6T9bDXxkxnNeKbSfZqX9kMEowtg"); | ||
|
||
using CancellationTokenSource cts = new(); | ||
|
||
ReceiverOptions receiverOptions = new() | ||
{ | ||
AllowedUpdates = Array.Empty<UpdateType>() | ||
}; | ||
|
||
botClient.StartReceiving( | ||
updateHandler: HandleUpdateAsync, | ||
pollingErrorHandler: HandlePollingErrorAsync, | ||
receiverOptions: receiverOptions, | ||
cancellationToken: cts.Token | ||
); | ||
|
||
var me = await botClient.GetMeAsync(); | ||
|
||
Console.WriteLine($"Start listening for @{me.Username}"); | ||
Console.ReadLine(); | ||
|
||
cts.Cancel(); | ||
|
||
async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken) | ||
{ | ||
var handler = update.Type switch | ||
{ | ||
UpdateType.Message => HandleMessageAsync(botClient,update,cancellationToken), | ||
UpdateType.CallbackQuery => HandleCallBackQueryAsync(botClient,update,cancellationToken), | ||
_ => throw new Exception("Unknown update type") | ||
}; | ||
|
||
try | ||
{ | ||
await handler; | ||
} | ||
catch (Exception ex) | ||
{ | ||
await Console.Out.WriteLineAsync(ex.Message); | ||
} | ||
} | ||
|
||
Task HandlePollingErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken) | ||
{ | ||
var ErrorMessage = exception switch | ||
{ | ||
ApiRequestException apiRequestException | ||
=> $"Telegram API Error:\n[{apiRequestException.ErrorCode}]\n{apiRequestException.Message}", | ||
_ => exception.ToString() | ||
}; | ||
|
||
Console.WriteLine(ErrorMessage); | ||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
private static async Task HandleCallBackQueryAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
private static async Task HandleMessageAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken) | ||
{ | ||
|
||
if (update.Message is not { } message) | ||
return; | ||
if (message.Text is not { } messageText) | ||
return; | ||
|
||
await SendFilmList(botClient,update, cancellationToken); | ||
} | ||
|
||
private static async Task SendFilmList(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken) | ||
{ | ||
if (update.Message is not { } message) | ||
return; | ||
if (message.Text is not { } messageText) | ||
return; | ||
|
||
var searchReasult = await ApiBroker.GetSearchResult(messageText, 1); | ||
|
||
var textOfSearchResult = ""; | ||
|
||
int count = 1; | ||
foreach(var item in searchReasult.Search) | ||
{ | ||
textOfSearchResult += $"\n{count++}.{item.Title} -{item.Year}"; | ||
} | ||
|
||
List<List<InlineKeyboardButton>> inlineKeyboardButtons = new List<List<InlineKeyboardButton>>(); | ||
|
||
if(searchReasult.Search.Count <= 5) | ||
{ | ||
List<InlineKeyboardButton> list = new List<InlineKeyboardButton>(); | ||
for(int i = 0;i < searchReasult.Search.Count;i++) | ||
{ | ||
InlineKeyboardButton inlineKeyboard = InlineKeyboardButton.WithCallbackData( $"{i+1}", searchReasult.Search[i].imdbID); | ||
list.Add(inlineKeyboard); | ||
} | ||
inlineKeyboardButtons.Add(list); | ||
} | ||
else | ||
|
||
|
||
|
||
{ | ||
List<InlineKeyboardButton> list = new List<InlineKeyboardButton>(); | ||
for (int i = 0; i < 5; i++) | ||
{ | ||
InlineKeyboardButton inlineKeyboard = InlineKeyboardButton.WithCallbackData($"{i + 1}", searchReasult.Search[i].imdbID); | ||
list.Add(inlineKeyboard); | ||
} | ||
inlineKeyboardButtons.Add(list); | ||
list = new List<InlineKeyboardButton>(); | ||
for (int i = 5; i < searchReasult.Search.Count - 5; i++) | ||
{ | ||
InlineKeyboardButton inlineKeyboard = InlineKeyboardButton.WithCallbackData($"{i + 1}", searchReasult.Search[i].imdbID); | ||
list.Add(inlineKeyboard); | ||
} | ||
inlineKeyboardButtons.Add(list); | ||
} | ||
|
||
InlineKeyboardMarkup reply = new InlineKeyboardMarkup(inlineKeyboardButtons); | ||
|
||
await botClient.SendTextMessageAsync( | ||
chatId: update.Message.Chat.Id, | ||
text: textOfSearchResult, | ||
replyMarkup: reply, | ||
cancellationToken:cancellationToken | ||
); | ||
} | ||
} |
Binary file modified
BIN
+1.24 KB
(940%)
FTelegramBot/Film_bot/obj/Debug/net6.0/Film_bot.assets.cache
Binary file not shown.
Binary file added
BIN
+880 Bytes
FTelegramBot/Film_bot/obj/Debug/net6.0/Film_bot.csproj.AssemblyReference.cache
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+1.24 KB
(940%)
FTelegramBot/Film_bot/obj/Release/net6.0/Film_bot.assets.cache
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
{ | ||
"version": 2, | ||
"dgSpecHash": "XI7/e4TMt6XEGyBflRFGiaDnp6cexpS+rguTApxPWLRNI7lf2WDXCmenrGdLtBDDisvkj85FChzm9fIaU4P7fQ==", | ||
"dgSpecHash": "+/9l6OSRX/+gpio7LoRZwZk9gQiczLWoWucFwaklwYfVhNjFeR+B1X4iNqBBletpFqbdHykAggCXRnX4xPA+Lw==", | ||
"success": true, | ||
"projectFilePath": "C:\\Users\\user\\Desktop\\Film_Bot\\FTelegramBot\\Film_bot\\Film_bot.csproj", | ||
"expectedPackageFiles": [], | ||
"expectedPackageFiles": [ | ||
"C:\\Users\\user\\.nuget\\packages\\newtonsoft.json\\13.0.1\\newtonsoft.json.13.0.1.nupkg.sha512", | ||
"C:\\Users\\user\\.nuget\\packages\\telegram.bot\\19.0.0\\telegram.bot.19.0.0.nupkg.sha512" | ||
], | ||
"logs": [] | ||
} |