Skip to content

Commit

Permalink
Qisqasi o'zgarish
Browse files Browse the repository at this point in the history
  • Loading branch information
SardorSohinazarov committed Oct 4, 2023
1 parent 7ce2fdc commit 6f0f5c4
Show file tree
Hide file tree
Showing 15 changed files with 246 additions and 7 deletions.
Binary file modified .vs/slnx.sqlite
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified FTelegramBot/.vs/FTelegramBot/v17/.suo
Binary file not shown.
4 changes: 4 additions & 0 deletions FTelegramBot/Film_bot/Film_bot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Telegram.Bot" Version="19.0.0" />
</ItemGroup>

</Project>
146 changes: 144 additions & 2 deletions FTelegramBot/Film_bot/Program.cs
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 FTelegramBot/Film_bot/obj/Debug/net6.0/Film_bot.assets.cache
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions FTelegramBot/Film_bot/obj/Film_bot.csproj.nuget.dgspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"dependencies": {
"Telegram.Bot": {
"target": "Package",
"version": "[19.0.0, )"
}
},
"imports": [
"net461",
"net462",
Expand Down
Binary file modified FTelegramBot/Film_bot/obj/Release/net6.0/Film_bot.assets.cache
Binary file not shown.
90 changes: 87 additions & 3 deletions FTelegramBot/Film_bot/obj/project.assets.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,89 @@
{
"version": 3,
"targets": {
"net6.0": {}
"net6.0": {
"Newtonsoft.Json/13.0.1": {
"type": "package",
"compile": {
"lib/netstandard2.0/Newtonsoft.Json.dll": {
"related": ".xml"
}
},
"runtime": {
"lib/netstandard2.0/Newtonsoft.Json.dll": {
"related": ".xml"
}
}
},
"Telegram.Bot/19.0.0": {
"type": "package",
"dependencies": {
"Newtonsoft.Json": "13.0.1"
},
"compile": {
"lib/net6.0/Telegram.Bot.dll": {
"related": ".pdb;.xml"
}
},
"runtime": {
"lib/net6.0/Telegram.Bot.dll": {
"related": ".pdb;.xml"
}
}
}
}
},
"libraries": {
"Newtonsoft.Json/13.0.1": {
"sha512": "ppPFpBcvxdsfUonNcvITKqLl3bqxWbDCZIzDWHzjpdAHRFfZe0Dw9HmA0+za13IdyrgJwpkDTDA9fHaxOrt20A==",
"type": "package",
"path": "newtonsoft.json/13.0.1",
"files": [
".nupkg.metadata",
".signature.p7s",
"LICENSE.md",
"lib/net20/Newtonsoft.Json.dll",
"lib/net20/Newtonsoft.Json.xml",
"lib/net35/Newtonsoft.Json.dll",
"lib/net35/Newtonsoft.Json.xml",
"lib/net40/Newtonsoft.Json.dll",
"lib/net40/Newtonsoft.Json.xml",
"lib/net45/Newtonsoft.Json.dll",
"lib/net45/Newtonsoft.Json.xml",
"lib/netstandard1.0/Newtonsoft.Json.dll",
"lib/netstandard1.0/Newtonsoft.Json.xml",
"lib/netstandard1.3/Newtonsoft.Json.dll",
"lib/netstandard1.3/Newtonsoft.Json.xml",
"lib/netstandard2.0/Newtonsoft.Json.dll",
"lib/netstandard2.0/Newtonsoft.Json.xml",
"newtonsoft.json.13.0.1.nupkg.sha512",
"newtonsoft.json.nuspec",
"packageIcon.png"
]
},
"Telegram.Bot/19.0.0": {
"sha512": "Q16IOitgjGoaJOuqgKQy0FeF+hr/ncmlX2esrhCC7aiyhSX7roYEriWaGAHkQZR8QzbImjFfl4eQh2IxcnOrPg==",
"type": "package",
"path": "telegram.bot/19.0.0",
"files": [
".nupkg.metadata",
".signature.p7s",
"lib/net6.0/Telegram.Bot.dll",
"lib/net6.0/Telegram.Bot.pdb",
"lib/net6.0/Telegram.Bot.xml",
"lib/netstandard2.0/Telegram.Bot.dll",
"lib/netstandard2.0/Telegram.Bot.pdb",
"lib/netstandard2.0/Telegram.Bot.xml",
"package-icon.png",
"telegram.bot.19.0.0.nupkg.sha512",
"telegram.bot.nuspec"
]
}
},
"libraries": {},
"projectFileDependencyGroups": {
"net6.0": []
"net6.0": [
"Telegram.Bot >= 19.0.0"
]
},
"packageFolders": {
"C:\\Users\\user\\.nuget\\packages\\": {}
Expand Down Expand Up @@ -45,6 +123,12 @@
"frameworks": {
"net6.0": {
"targetAlias": "net6.0",
"dependencies": {
"Telegram.Bot": {
"target": "Package",
"version": "[19.0.0, )"
}
},
"imports": [
"net461",
"net462",
Expand Down
7 changes: 5 additions & 2 deletions FTelegramBot/Film_bot/obj/project.nuget.cache
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": []
}

0 comments on commit 6f0f5c4

Please sign in to comment.