Skip to content

Commit

Permalink
Renaming class File -> TGFile
Browse files Browse the repository at this point in the history
  • Loading branch information
wiz0u committed Dec 14, 2024
1 parent 29db3d6 commit 926dd07
Show file tree
Hide file tree
Showing 24 changed files with 70 additions and 72 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# .NET Client for Telegram Bot API

[![Nuget](https://img.shields.io/nuget/vpre/Telegram.Bot.svg?label=Telegram.Bot&style=flat-square&color=d8b541)](https://www.nuget.org/packages/Telegram.Bot)
[![Bot API Version](https://img.shields.io/badge/Bot_API-8.1-f36caf.svg?style=flat-square)](https://core.telegram.org/bots/api)
[![Bot API 8.1](https://img.shields.io/badge/Bot_API-8.1-f36caf.svg?style=flat-square)](https://core.telegram.org/bots/api)
[![Documentations](https://img.shields.io/badge/Documentations-Book-orange.svg?style=flat-square)](https://telegrambots.github.io/book/)
[![Telegram Chat](https://img.shields.io/badge/Support_Chat-Telegram-blue.svg?style=flat-square)](https://t.me/joinchat/B35YY0QbLfd034CFnvCtCA)
[![Master build](https://img.shields.io/azure-devops/build/tgbots/14f9ab3f-313a-4339-8534-e8b96c7763cc/6?style=flat-square&label=master)](https://dev.azure.com/tgbots/Telegram.Bot/_build/latest?definitionId=6&branchName=master)
Expand Down
3 changes: 1 addition & 2 deletions src/Telegram.Bot/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
global using System.Collections.Generic;
global using System.Diagnostics.CodeAnalysis;
global using System.Net.Http;
global using System.IO;
global using System.Text.Json;
global using System.Text.Json.Serialization;
global using Telegram.Bot.Extensions;
Expand All @@ -15,6 +16,4 @@
global using Telegram.Bot.Types.Passport;
global using Telegram.Bot.Types.Payments;
global using Telegram.Bot.Types.ReplyMarkups;
global using File = Telegram.Bot.Types.File;
global using Stream = System.IO.Stream;
global using LabeledPrice = Telegram.Bot.Types.Payments.LabeledPrice;
4 changes: 2 additions & 2 deletions src/Telegram.Bot/ITelegramBotClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public static partial class TelegramBotClientExtensions
/// <param name="fileId">File identifier to get info about</param>
/// <param name="destination">Destination stream to write file to</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation</param>
/// <returns>On success, a <see cref="File"/> object is returned.</returns>
public static async Task<File> GetInfoAndDownloadFile(this ITelegramBotClient botClient, string fileId, Stream destination,
/// <returns>On success, a <see cref="TGFile"/> object is returned.</returns>
public static async Task<TGFile> GetInfoAndDownloadFile(this ITelegramBotClient botClient, string fileId, Stream destination,
CancellationToken cancellationToken = default)
{
var file = await botClient.ThrowIfNull().SendRequest(new Requests.GetFileRequest { FileId = fileId },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Telegram.Bot.Requests;

/// <summary>Use this method to get basic information about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size.<para>Returns: A <see cref="File"/> object is returned. The file can then be downloaded via <see cref="TelegramBotClient.DownloadFile">DownloadFile</see>, where <c>&lt;FilePath&gt;</c> is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling <see cref="TelegramBotClientExtensions.GetFile">GetFile</see> again.<br/><b>Note:</b> This function may not preserve the original file name and MIME type. You should save the file's MIME type and name (if available) when the File object is received.</para></summary>
public partial class GetFileRequest() : RequestBase<File>("getFile")
/// <summary>Use this method to get basic information about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size.<para>Returns: A <see cref="TGFile"/> object is returned. The file can then be downloaded via <see cref="TelegramBotClient.DownloadFile">DownloadFile</see>, where <c>&lt;FilePath&gt;</c> is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling <see cref="TelegramBotClientExtensions.GetFile">GetFile</see> again.<br/><b>Note:</b> This function may not preserve the original file name and MIME type. You should save the file's MIME type and name (if available) when the File object is received.</para></summary>
public partial class GetFileRequest() : RequestBase<TGFile>("getFile")
{
/// <summary>File identifier to get information about</summary>
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Telegram.Bot.Requests;

/// <summary>Use this method to upload a file with a sticker for later use in the <see cref="TelegramBotClientExtensions.CreateNewStickerSet">CreateNewStickerSet</see>, <see cref="TelegramBotClientExtensions.AddStickerToSet">AddStickerToSet</see>, or <see cref="TelegramBotClientExtensions.ReplaceStickerInSet">ReplaceStickerInSet</see> methods (the file can be used multiple times).<para>Returns: The uploaded <see cref="File"/> on success.</para></summary>
public partial class UploadStickerFileRequest() : FileRequestBase<File>("uploadStickerFile"), IUserTargetable
/// <summary>Use this method to upload a file with a sticker for later use in the <see cref="TelegramBotClientExtensions.CreateNewStickerSet">CreateNewStickerSet</see>, <see cref="TelegramBotClientExtensions.AddStickerToSet">AddStickerToSet</see>, or <see cref="TelegramBotClientExtensions.ReplaceStickerInSet">ReplaceStickerInSet</see> methods (the file can be used multiple times).<para>Returns: The uploaded <see cref="TGFile"/> on success.</para></summary>
public partial class UploadStickerFileRequest() : FileRequestBase<TGFile>("uploadStickerFile"), IUserTargetable
{
/// <summary>User identifier of sticker file owner</summary>
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
Expand Down
2 changes: 1 addition & 1 deletion src/Telegram.Bot/Serialization/JsonBotSerializerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ namespace Telegram.Bot;
[JsonSerializable(typeof(ApiResponse<MessageId>))]
[JsonSerializable(typeof(ApiResponse<Message[]>))]
[JsonSerializable(typeof(ApiResponse<UserProfilePhotos>))]
[JsonSerializable(typeof(ApiResponse<File>))]
[JsonSerializable(typeof(ApiResponse<TGFile>))]
[JsonSerializable(typeof(ApiResponse<string>))]
[JsonSerializable(typeof(ApiResponse<ChatInviteLink>))]
[JsonSerializable(typeof(ApiResponse<ChatFullInfo>))]
Expand Down
12 changes: 6 additions & 6 deletions src/Telegram.Bot/TelegramBotClientExtensions.ApiMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1699,8 +1699,8 @@ public static Task SetUserEmojiStatusAsync(
/// <param name="botClient">An instance of <see cref="ITelegramBotClient"/></param>
/// <param name="fileId">File identifier to get information about</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation</param>
/// <returns>A <see cref="File"/> object is returned. The file can then be downloaded via <see cref="TelegramBotClient.DownloadFile">DownloadFile</see>, where <c>&lt;FilePath&gt;</c> is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling <see cref="TelegramBotClientExtensions.GetFile">GetFile</see> again.<br/><b>Note:</b> This function may not preserve the original file name and MIME type. You should save the file's MIME type and name (if available) when the File object is received.</returns>
public static async Task<File> GetFile(
/// <returns>A <see cref="TGFile"/> object is returned. The file can then be downloaded via <see cref="TelegramBotClient.DownloadFile">DownloadFile</see>, where <c>&lt;FilePath&gt;</c> is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling <see cref="TelegramBotClientExtensions.GetFile">GetFile</see> again.<br/><b>Note:</b> This function may not preserve the original file name and MIME type. You should save the file's MIME type and name (if available) when the File object is received.</returns>
public static async Task<TGFile> GetFile(
this ITelegramBotClient botClient,
string fileId,
CancellationToken cancellationToken = default
Expand All @@ -1711,7 +1711,7 @@ public static async Task<File> GetFile(

/// <summary>We removed all Async suffix from method names. Use <see cref="GetFile">GetFile</see> instead</summary>
[Obsolete("We removed all Async suffix from method names. Use GetFile instead")]
public static Task<File> GetFileAsync(
public static Task<TGFile> GetFileAsync(
this ITelegramBotClient botClient,
string fileId,
CancellationToken cancellationToken = default
Expand Down Expand Up @@ -4008,8 +4008,8 @@ public static Task<Sticker[]> GetCustomEmojiStickersAsync(
/// <param name="sticker">A file with the sticker in .WEBP, .PNG, .TGS, or .WEBM format. See <a href="https://core.telegram.org/stickers">https://core.telegram.org/stickers</a> for technical requirements. <a href="https://core.telegram.org/bots/api#sending-files">More information on Sending Files »</a></param>
/// <param name="stickerFormat">Format of the sticker, must be one of <see cref="StickerFormat.Static">Static</see>, <see cref="StickerFormat.Animated">Animated</see>, <see cref="StickerFormat.Video">Video</see></param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation</param>
/// <returns>The uploaded <see cref="File"/> on success.</returns>
public static async Task<File> UploadStickerFile(
/// <returns>The uploaded <see cref="TGFile"/> on success.</returns>
public static async Task<TGFile> UploadStickerFile(
this ITelegramBotClient botClient,
long userId,
InputFileStream sticker,
Expand All @@ -4024,7 +4024,7 @@ public static async Task<File> UploadStickerFile(

/// <summary>We removed all Async suffix from method names. Use <see cref="UploadStickerFile">UploadStickerFile</see> instead</summary>
[Obsolete("We removed all Async suffix from method names. Use UploadStickerFile instead")]
public static Task<File> UploadStickerFileAsync(
public static Task<TGFile> UploadStickerFileAsync(
this ITelegramBotClient botClient,
long userId,
InputFileStream sticker,
Expand Down
2 changes: 1 addition & 1 deletion src/Telegram.Bot/Types/Sticker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public partial class Sticker : FileBase
public string? SetName { get; set; }

/// <summary><em>Optional</em>. For premium regular stickers, premium animation for the sticker</summary>
public File? PremiumAnimation { get; set; }
public TGFile? PremiumAnimation { get; set; }

/// <summary><em>Optional</em>. For mask stickers, the position where the mask should be placed</summary>
public MaskPosition? MaskPosition { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Telegram.Bot.Types;

/// <summary>This object represents a file ready to be downloaded. The file can be downloaded via <see cref="TelegramBotClient.DownloadFile">DownloadFile</see>. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling <see cref="TelegramBotClientExtensions.GetFile">GetFile</see>.</summary>
/// <remarks>The maximum file size to download is 20 MB</remarks>
public partial class File : FileBase
public partial class TGFile : FileBase
{
/// <summary><em>Optional</em>. File path. Use <see cref="TelegramBotClient.DownloadFile">DownloadFile</see> to get the file.</summary>
public string? FilePath { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public async Task Should_Get_Chat_With_No_Pinned_Message()
[Trait(Constants.MethodTraitName, Constants.TelegramBotApiMethods.SetChatPhoto)]
public async Task Should_Set_Chat_Photo()
{
await using Stream stream = System.IO.File.OpenRead(Constants.PathToFile.Photos.Logo);
await using Stream stream = File.OpenRead(Constants.PathToFile.Photos.Logo);
await BotClient.WithStreams(stream).SetChatPhoto(
chatId: classFixture.Chat.Id,
photo: InputFile.FromStream(stream)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public async Task Should_Get_Chat_With_No_Pinned_Message()
[Trait(Constants.MethodTraitName, Constants.TelegramBotApiMethods.SetChatPhoto)]
public async Task Should_Set_Chat_Photo()
{
await using Stream stream = System.IO.File.OpenRead(Constants.PathToFile.Photos.Logo);
await using Stream stream = File.OpenRead(Constants.PathToFile.Photos.Logo);
await BotClient.WithStreams(stream).SetChatPhoto(
chatId: classFixture.Chat.Id,
photo: InputFile.FromStream(stream)
Expand Down
8 changes: 4 additions & 4 deletions test/Telegram.Bot.Tests.Integ/Inline Mode/InlineQueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ await Fixture.UpdateReceiver.GetInlineQueryResultUpdates(
public async Task Should_Answer_Inline_Query_With_Cached_Photo()
{
Message photoMessage;
await using (FileStream stream = System.IO.File.OpenRead(Constants.PathToFile.Photos.Apes))
await using (FileStream stream = File.OpenRead(Constants.PathToFile.Photos.Apes))
{
photoMessage = await BotClient.WithStreams(stream).SendPhoto(
chatId: Fixture.SupergroupChat,
Expand Down Expand Up @@ -505,7 +505,7 @@ await Fixture.UpdateReceiver.GetInlineQueryResultUpdates(
public async Task Should_Answer_Inline_Query_With_Cached_Audio()
{
Message audioMessage;
await using (FileStream stream = System.IO.File.OpenRead(Constants.PathToFile.Audio.CantinaRagMp3))
await using (FileStream stream = File.OpenRead(Constants.PathToFile.Audio.CantinaRagMp3))
{
audioMessage = await BotClient.WithStreams(stream).SendAudio(
chatId: Fixture.SupergroupChat,
Expand Down Expand Up @@ -595,7 +595,7 @@ await Fixture.UpdateReceiver.GetInlineQueryResultUpdates(
public async Task Should_Answer_Inline_Query_With_Cached_Voice()
{
Message voiceMessage;
await using (FileStream stream = System.IO.File.OpenRead(Constants.PathToFile.Audio.TestOgg))
await using (FileStream stream = File.OpenRead(Constants.PathToFile.Audio.TestOgg))
{
voiceMessage = await BotClient.WithStreams(stream).SendVoice(
chatId: Fixture.SupergroupChat,
Expand Down Expand Up @@ -685,7 +685,7 @@ await Fixture.UpdateReceiver.GetInlineQueryResultUpdates(
public async Task Should_Answer_Inline_Query_With_Cached_Document()
{
Message documentMessage;
await using (FileStream stream = System.IO.File.OpenRead(Constants.PathToFile.Documents.Hamlet))
await using (FileStream stream = File.OpenRead(Constants.PathToFile.Documents.Hamlet))
{
documentMessage = await BotClient.WithStreams(stream).SendDocument(
chatId: Fixture.SupergroupChat,
Expand Down
13 changes: 6 additions & 7 deletions test/Telegram.Bot.Tests.Integ/Other/FileDownloadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Telegram.Bot.Types;
using Xunit;
using Xunit.Abstractions;
using File = Telegram.Bot.Types.File;

namespace Telegram.Bot.Tests.Integ.Other;

Expand All @@ -24,7 +23,7 @@ public async Task Should_Get_File_Info()
#region Send Document

Message documentMessage;
await using (Stream stream = System.IO.File.OpenRead(Constants.PathToFile.Documents.Hamlet))
await using (FileStream stream = File.OpenRead(Constants.PathToFile.Documents.Hamlet))
{
fileSize = stream.Length;
documentMessage = await BotClient.WithStreams(stream).SendDocument(
Expand All @@ -37,7 +36,7 @@ public async Task Should_Get_File_Info()

#endregion

File file = await BotClient.GetFile(documentMessage.Document.FileId);
TGFile file = await BotClient.GetFile(documentMessage.Document.FileId);

Assert.Equal(fileId, file.FileId);
Assert.NotNull(file.FileSize);
Expand All @@ -56,7 +55,7 @@ public async Task Should_Download_Write_Using_FilePath()
string destinationFilePath = $"{Path.GetTempFileName()}.{ClassFixture.FileType}";
output.WriteLine($@"Writing file to ""{destinationFilePath}""");
await using FileStream fileStream = System.IO.File.OpenWrite(destinationFilePath);
await using FileStream fileStream = File.OpenWrite(destinationFilePath);
await BotClient.DownloadFile(
filePath: classFixture.File.FilePath!,
destination: fileStream
Expand All @@ -74,8 +73,8 @@ public async Task Should_Download_Write_Using_FileId()
string destinationFilePath = $"{Path.GetTempFileName()}.{ClassFixture.FileType}";
output.WriteLine($@"Writing file to ""{destinationFilePath}""");
await using FileStream fileStream = System.IO.File.OpenWrite(destinationFilePath);
File file = await BotClient.GetInfoAndDownloadFile(
await using FileStream fileStream = File.OpenWrite(destinationFilePath);
TGFile file = await BotClient.GetInfoAndDownloadFile(
fileId: classFixture.File.FileId,
destination: fileStream
);
Expand Down Expand Up @@ -114,6 +113,6 @@ public class ClassFixture
{
public const string FileType = "pdf";

public File File { get; set; }
public TGFile File { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public async Task Should_Upload_2_Photos_Album()
{
Message[] messages;
await using (Stream
stream1 = System.IO.File.OpenRead(Constants.PathToFile.Photos.Logo),
stream2 = System.IO.File.OpenRead(Constants.PathToFile.Photos.Bot)
stream1 = File.OpenRead(Constants.PathToFile.Photos.Logo),
stream2 = File.OpenRead(Constants.PathToFile.Photos.Bot)
)
{
messages = await BotClient.WithStreams(stream1, stream2).SendMediaGroup(
Expand Down Expand Up @@ -109,9 +109,9 @@ public async Task Should_Upload_2_Videos_Album()
{
Message[] messages;
await using (Stream
stream0 = System.IO.File.OpenRead(Constants.PathToFile.Videos.GoldenRatio),
stream1 = System.IO.File.OpenRead(Constants.PathToFile.Videos.MoonLanding),
stream2 = System.IO.File.OpenRead(Constants.PathToFile.Photos.Bot)
stream0 = File.OpenRead(Constants.PathToFile.Videos.GoldenRatio),
stream1 = File.OpenRead(Constants.PathToFile.Videos.MoonLanding),
stream2 = File.OpenRead(Constants.PathToFile.Photos.Bot)
)
{
messages = await BotClient.WithStreams(stream0, stream1, stream2).SendMediaGroup(
Expand Down Expand Up @@ -167,8 +167,8 @@ public async Task Should_Upload_2_Videos_Album()
public async Task Should_Upload_2_Photos_Album_With_Markdown_Encoded_Captions()
{
await using Stream
stream1 = System.IO.File.OpenRead(Constants.PathToFile.Photos.Logo),
stream2 = System.IO.File.OpenRead(Constants.PathToFile.Photos.Bot);
stream1 = File.OpenRead(Constants.PathToFile.Photos.Logo),
stream2 = File.OpenRead(Constants.PathToFile.Photos.Bot);


Message[] messages = await BotClient.WithStreams(stream1, stream2).SendMediaGroup(
Expand Down Expand Up @@ -210,8 +210,8 @@ public async Task Should_Upload_2_Photos_Album_With_Markdown_Encoded_Captions()
public async Task Should_Video_With_Thumbnail_In_Album()
{
await using Stream
stream1 = System.IO.File.OpenRead(Constants.PathToFile.Videos.GoldenRatio),
stream2 = System.IO.File.OpenRead(Constants.PathToFile.Thumbnail.Video);
stream1 = File.OpenRead(Constants.PathToFile.Videos.GoldenRatio),
stream2 = File.OpenRead(Constants.PathToFile.Thumbnail.Video);

Message[] messages = await BotClient.WithStreams(stream1, stream2).SendMediaGroup(
chatId: Fixture.SupergroupChat.Id,
Expand Down
Loading

0 comments on commit 926dd07

Please # to comment.