Skip to content

Commit

Permalink
Merge pull request #1247 from TelegramBots/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tuscen committed Apr 30, 2023
2 parents 1e8fe6c + 3e8f0a7 commit 9473a52
Show file tree
Hide file tree
Showing 152 changed files with 3,824 additions and 1,586 deletions.
8 changes: 3 additions & 5 deletions .azure-pipelines/ci.yml
Expand Up @@ -5,14 +5,12 @@ trigger:
- gh-pages
paths:
exclude:
- ".github/"
- docs/
- '.github'
- docs
- README.md
- CHANGELOG.md
- CONTRIBUTING.md

pr: none

variables:
- template: variables.yml

Expand Down Expand Up @@ -75,7 +73,7 @@ stages:
inputs:
packageType: sdk
version: $(netSdkVersion)
- task: NuGetAuthenticate@0
- task: NuGetAuthenticate@1
displayName: 'NuGet Authenticate'
- task: NuGetCommand@2
displayName: Publish CI package to Azure artifacts
Expand Down
1 change: 0 additions & 1 deletion .azure-pipelines/full-integration-tests.yml
@@ -1,5 +1,4 @@
trigger: none
pr: none

variables:
- template: variables.yml
Expand Down
1 change: 0 additions & 1 deletion .azure-pipelines/non-interactive-integration-tests.yml
@@ -1,5 +1,4 @@
trigger: none
pr: none

variables:
- template: variables.yml
Expand Down
4 changes: 2 additions & 2 deletions .azure-pipelines/release-pipeline.yml
Expand Up @@ -5,8 +5,8 @@ trigger:
- master
paths:
exclude:
- ".github/"
- docs/
- '.github'
- docs
- README.md
- CHANGELOG.md
- CONTRIBUTING.md
Expand Down
2 changes: 1 addition & 1 deletion .azure-pipelines/variables.yml
Expand Up @@ -3,7 +3,7 @@ variables:
- name: versionPrefix
value: 19.0.0
- name: versionSuffix
value: 'preview.2'
value: 'preview.4'
- name: ciVersionSuffix
value: ci.$(Build.BuildId)+git.commit.$(Build.SourceVersion)
- name: isPreRelease
Expand Down
163 changes: 162 additions & 1 deletion CHANGELOG.md
Expand Up @@ -21,7 +21,165 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

<!-- markdownlint-configure-file { "MD024": false } -->

## [v19.0.0-preview.2] - Unreleased
## [v19.0.0-preview.4] - Unreleased

> [Bot API 6.7](https://core.telegram.org/bots/api#april-21-2023) (April 21, 2023)
> [Bot API 6.6](https://core.telegram.org/bots/api#march-9-2023) (March 9, 2023)
### Added

- Type `InlineQueryResultsButton`
- Type `SwitchInlineQueryChosenChat`
- Type `BotName`
- Property `WebAppName` to the class `WriteAccessAllowed`
- Property `SwitchInlineQueryChosenChat` to the class `InlineKeyboardButton`
- Property `ViaChatFolderInviteLink` to the class `ChatMemberUpdated`
- Static method `InlineKeyboardButton.WithSwitchInlineQueryChosenChat`
- Requests related to bot's name:
- `SetMyNameRequest`
- `GetMyNameRequest`
- Methods related to bot's name:
- `ITelegramBotClient.SetMyNameAsync`
- `ITelegramBotClient.GetMyNameAsync`
- New requests related to description:
- `GetMyDescriptionRequest`
- `SetMyDescriptionRequest`
- New requests related to short description:
- `GetMyShortDescriptionRequest`
- `SetMyShortDescriptionRequest`
- New requests related to stickers:
- `DeleteStickerSetRequest`
- `SetCustomEmojiStickerSetThumbnailRequest`
- `SetStickerEmojiListRequest`
- `SetStickerKeywordsRequest`
- `SetStickerMaskPositionRequest`
- `SetStickerSetThumbnailRequest`
- `SetStickerSetTitleRequest`
- New methods related to description:
- `ITelegramBotClient.SetMyDescriptionAsync`
- `ITelegramBotClient.GetMyDescriptionAsync`
- New methods related to short description:
- `ITelegramBotClient.SetMyShortDescriptionAsync`
- `ITelegramBotClient.GetMyShortDescriptionAsync`
- New methods related to stickers:
- `ITelegramBotClient.DeleteStickerSetAsync`
- `ITelegramBotClient.SetCustomEmojiStickerSetThumbnailAsync`
- `ITelegramBotClient.SetStickerEmojiListAsync`
- `ITelegramBotClient.SetStickerKeywordsAsync`
- `ITelegramBotClient.SetStickerMaskPositionAsync`
- `ITelegramBotClient.SetStickerSetThumbnailAsync`
- `ITelegramBotClient.SetStickerSetTitleAsync`
- Enum `StickerFormat`
- Type `BotDescription`
- Type `BotShortDescription`
- Type `InputSticker`
- Added property `string? Emoji` to class `SendStickerRequest`
- Added property `bool? NeedsRepainting` to the following classes:
- `CreateNewStickerSetRequest`
- `Sticker`
- Added property `IEnumerable<InputSticker> Stickers` to class `CreateNewStickerSetRequest`
- Added property `StickerFormat` to class `CreateNewStickerSetRequest`
- Added property `InputSticker Stickers` to class `AddStickerToSetRequest`

### Changed

- Replace the parameters `switchPmText` and `switchPmParameter` of the method `AnswerInlineQueryAsync` with the parameter `button` of type `InlineQueryResultsButton`.
- Replace the properties `SwitchPmText` and `SwitchPmParameter` of the class `AnswerInlineQueryRequest` with the property `Button` of type `InlineQueryResultsButton`.
- Class `SetStickerSetThumbRequest` renamed to `SetStickerSetThumbnailRequest`
- Class `CreateNewStickerSetRequest` is no longer abstract
- Class `AddStickerToSetRequest` is no longer abstract
- Method `ITelegramBotClient.SetStickerSetThumbAsync` renamed to `ITelegramBotClient.SetStickerSetThumbnailAsync`
- Properties `PngSticker`, `TgsSticker`, `WebmSticker`, `Emojis`, `MaskPostion`
in class `AddStickerToSetRequest` replaced with `Sticker` on Type `InputSticker`
- Properties `PngSticker`, `TgsSticker`, `WebmSticker`, `Emojis`, `MaskPostion`
in class `CreateNewStickerSetRequest` replaced with `Stickers` on Type `IEnumerable<InputSticker>`
- Renamed property `Thumb` to `Thumbnail` to the following Types:
- `Animation`
- `Audio`
- `Document`
- `Sticker`
- `Video`
- `VideoNote`
- `InputMediaAnimation`
- `InputMediaAudio`
- `InputMediaDocument`
- `InputMediaVideo`
- `StickerSet`
- Renamed property `Thumb` to `Thumbnail` in the following classes:
- `SendAnimationRequest`
- `SendAudioRequest`
- `SendDocumentRequest`
- `SendVideoRequest`
- `SendVideoNoteRequest`
- Renamed properties `ThumbUrl`, `ThumbWidth`, `ThumbHeight` to
`ThumbnailUrl`, `ThumbnailWidth`, `ThumbnailHeight` in the following Types:
- `InlineQueryResultArticle`
- `InlineQueryResultContact`
- `InlineQueryResultDocument`
- `InlineQueryResultLocation`
- `InlineQueryResultVenue`
- Renamed property `ThumbUrl` to `ThumbnailUrl` in the following Types:
- `InlineQueryResultPhoto`
- `InlineQueryResultVideo`
- Renamed properties `ThumbUrl`, `ThumbMimeType` to `ThumbnailUrl`, `ThumbnailMimeType` in the following Types:
- `InlineQueryResultGif`
- `InlineQueryResultMpeg4Gif`
- Type of property `Sticker` changed from `string` to `InputFileId` in the following classes:
- `SetStickerPositionInSetRequest`
- `DeleteStickerFromSetRequest`

### Fixed

- Stickers tests

### Removed
- Class `AddAnimatedStickerToSetRequest`
- Class `AddStaticStickerToSetRequest`
- Class `AddVideoStickerToSetRequest`
- Class `CreateNewAnimatedStickerSetRequest`
- Class `CreateNewStaticStickerSetRequest`
- Class `CreateNewVideoStickerSetRequest`
- Method `ITelegramBotClient.AddAnimatedStickerToSetAsync`
- Method `ITelegramBotClient.AddStaticStickerToSetAsync`
- Method `ITelegramBotClient.AddVideoStickerToSetAsync`
- Method `ITelegramBotClient.CreateNewAnimatedStickerSetAsync`
- Method `ITelegramBotClient.CreateNewStaticStickerSetAsync`
- Method `ITelegramBotClient.CreateNewVideoStickerSetAsync`
- Properties `Emojis`, `MaskPostion` in classes `CreateNewStickerSetRequest`, `AddStickerToSetRequest`

## [v19.0.0-preview.3] - Unreleased

> [Bot API 6.5](https://core.telegram.org/bots/api#february-3-2023) (February 3, 2023)
### Added

- Types `KeyboardButtonRequestUser` and `KeyboardButtonRequestChat`
- Properties `RequestUser` and `RequestChat` to the type `KeyboardButton`
- Static methods `KeyboardButton.WithRequestUser` and `KeyboardButton.WithRequestChat`
- Types `UserShared` and `ChatShared`
- Properties `UserShared` and `ChatShared` to the type `Message`
- Members `UserShared` and `ChatShared` to the enum `MessageType`
- Following properties to the types `ChatMemberRestricted` and `ChatPermissions`:
- `CanSendAudios`
- `CanSendDocuments`
- `CanSendPhotos`
- `CanSendVideos`
- `CanSendVideoNotes`
- `CanSendVoiceNotes`
- Property `UseIndependentChatPermissions` to the types `RestrictChatMemberRequest` and `SetChatPermissionsRequest`
- Optional parameter `useIndependentChatPermissions` to the methods `ITelegramBotClient.RestrictChatMemberAsync` and `ITelegramBotClient.SetChatPermissionsAsync`
- Property `UserChatId` to the type `ChatJoinRequest`

### Removed

- Properties `CanSendMediaMessages` from the types `ChatMemberRestricted` and `ChatPermissions`
- Obsolete types `GetChatMembersCountRequest`, `KickChatMemberRequest`, `VoiceChatEnded`, `VoiceChatParticipantsInvited`,
`VoiceChatScheduled`, `VoiceChatStarted`.
- Obsolete methods `ITelegramBotClient.KickChatMemberAsync`, `ITelegramBotClient.GetChatMembersCountAsync`.
- Obsolete properties `CanManageVoiceChat` from `PromoteChatMemberRequest`, `CanManageVoiceChats` from `ChatMember`.

## [v19.0.0-preview.2] - 2023-01-02

> [Bot API 6.4](https://core.telegram.org/bots/api#december-30-2022) (December 30, 2022)
Expand All @@ -39,6 +197,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
- `ITelegramBotClient.ReopenGeneralForumTopicAsync`
- `ITelegramBotClient.HideGeneralForumTopicAsync`
- `ITelegramBotClient.UnhideGeneralForumTopicAsync`
- Following properties to type `Chat`:
- `bool? IsForum`
- `string[]? ActiveUsernames`
- Optional property `HasSpoiler`
- Added property `bool? HasSpoiler` to the following classes:
- `SendAnimationRequest`
Expand Down
2 changes: 1 addition & 1 deletion README.md
@@ -1,7 +1,7 @@
# .NET Client for Telegram Bot API

[![package](https://img.shields.io/nuget/vpre/Telegram.Bot.svg?label=Telegram.Bot&style=flat-square)](https://www.nuget.org/packages/Telegram.Bot)
[![Bot API Version](https://img.shields.io/badge/Bot%20API-6.4%20(December%2030,%202022)-f36caf.svg?style=flat-square)](https://core.telegram.org/bots/api#december-30-2022)
[![Bot API Version](https://img.shields.io/badge/Bot%20API-6.7%20(April%2021,%202023)-f36caf.svg?style=flat-square)](https://core.telegram.org/bots/api#march-9-2023)
[![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)

Expand Down
92 changes: 67 additions & 25 deletions src/EnumSerializer.Generator/EnumConverterGenerator.cs
Expand Up @@ -3,11 +3,12 @@
using Microsoft.CodeAnalysis.Text;
using Scriban;
using System.Collections.Immutable;
using System.Runtime.InteropServices;
using System.Text;

namespace EnumSerializer.Generator;

[Generator]
[Generator(LanguageNames.CSharp)]
public class EnumConverterGenerator : IIncrementalGenerator
{
const string JsonConverterAttribute = "Newtonsoft.Json.JsonConverterAttribute";
Expand Down Expand Up @@ -98,28 +99,11 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
continue;
}

string? displayName = null;
foreach (var attribute in member.GetAttributes())
{
if (attribute.AttributeClass is null
|| attribute.AttributeClass.Name != "DisplayAttribute")
{
continue;
}

foreach (var namedArgument in attribute.NamedArguments)
{
if (namedArgument.Key == "Name" && namedArgument.Value.Value?.ToString() is { } dn)
{
displayName = dn;
break;
}
}
}
string? displayName = GetDisplayName(member) ?? ToSnakeCase(member.Name);

members.Add(new(
member.Name,
displayName ?? ToSnakeCase(member.Name)
displayName
));
}

Expand All @@ -132,9 +116,67 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
return enumsToProcess;
}

static string ToSnakeCase(string name) =>
string.Concat(name.Select((x, i) => i > 0 && char.IsUpper(x)
? $"_{x}"
: x.ToString())
).ToLower();
static string? GetDisplayName(ISymbol member)
{
foreach (var attribute in member.GetAttributes())
{
if (attribute.AttributeClass is null
|| !string.Equals(attribute.AttributeClass.Name, "DisplayAttribute", StringComparison.InvariantCulture))
{
continue;
}

foreach (var namedArgument in attribute.NamedArguments)
{
if (string.Equals(namedArgument.Key, "Name", StringComparison.InvariantCulture)
&& namedArgument.Value.Value?.ToString() is { } displayName)
{
return displayName;
}
}
}

return null;
}

static string ToSnakeCase(string name)
{
StringBuilder sb = new();

State previous = default;

for (var index = 0; index < name.Length; index++)
{
char c = name[index];
State current = new(c, char.IsUpper(c));

if (current.IsUpper)
{
c = char.ToLowerInvariant(current.Character);

if (index > 0
&& previous.Character != '_'
&& !previous.IsUpper)
{
sb.Append('_');
}
}

sb.Append(c);
previous = current;
}
return sb.ToString();
}

[StructLayout(LayoutKind.Auto)]
private readonly struct State
{
public readonly char Character;
public readonly bool IsUpper;
public State(char character, bool isUpper)
{
Character = character;
IsUpper = isUpper;
}
}
}
9 changes: 5 additions & 4 deletions src/EnumSerializer.Generator/EnumSerializer.Generator.csproj
Expand Up @@ -9,14 +9,15 @@
<IsRoslynComponent>true</IsRoslynComponent>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>

<!-- The following libraries include the source generator interfaces and types we need -->
<ItemGroup>
<PackageReference Include="Meziantou.Analyzer" Version="1.0.757" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0" PrivateAssets="all" />
<PackageReference Include="Scriban" Version="5.5.1" GeneratePathProperty="true" PrivateAssets="all" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.45" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.5.0" PrivateAssets="all" />
<PackageReference Include="Scriban" Version="5.7.0" GeneratePathProperty="true" PrivateAssets="all" />

<!-- This ensures the library will be packaged as a source generator when we use `dotnet pack` -->
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
Expand Down

0 comments on commit 9473a52

Please sign in to comment.