Skip to content

Commit 03e6ccf

Browse files
committed
v4.2.0: string.MarkdownEncode() extension added
1 parent 1fa9d80 commit 03e6ccf

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

NetTelegramBotApi/NetTelegramBotApi.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<PropertyGroup>
44
<Description>Telegram Bot API library</Description>
55
<AssemblyTitle>NetTelegramBotApi</AssemblyTitle>
6-
<VersionPrefix>4.1.0</VersionPrefix>
6+
<Version>4.2.0</Version>
77
<TargetFrameworks>net45;net46;netstandard1.3</TargetFrameworks>
88
<NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>
99
<AssemblyName>NetTelegramBotApi</AssemblyName>
1010
<PackageId>NetTelegramBotApi</PackageId>
1111
<PackageTags>telegram;bot;api</PackageTags>
12-
<PackageReleaseNotes>See https://github.com/justdmitry/NetTelegramBotApi/releases/tag/v4.0.0</PackageReleaseNotes>
12+
<PackageReleaseNotes>See https://github.com/justdmitry/NetTelegramBotApi/releases/tag/v4.2.0</PackageReleaseNotes>
1313
<PackageIconUrl>https://raw.githubusercontent.com/justdmitry/NetTelegramBotApi/master/package-icon.gif</PackageIconUrl>
1414
<PackageProjectUrl>https://github.com/justdmitry/NetTelegramBotApi</PackageProjectUrl>
1515
<RepositoryType>git</RepositoryType>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace System
2+
{
3+
using System.Text.RegularExpressions;
4+
5+
public static class StringExtensions
6+
{
7+
private static readonly Regex WrongChars = new Regex(@"([\*_`\[\]\(\)])");
8+
9+
public static string MarkdownEncode(this string value)
10+
{
11+
if (string.IsNullOrWhiteSpace(value))
12+
{
13+
return value;
14+
}
15+
16+
return WrongChars.Replace(value, @"\$1");
17+
}
18+
}
19+
}

TelegramBotDemo-vNext/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public static void RunBot(string accessToken)
200200
{
201201
bot.MakeRequestAsync(new SendMessage(
202202
update.Message.Chat.Id,
203-
"You wrote *" + update.Message.Text.Length + " characters*")
203+
"You wrote: \r\n" + update.Message.Text.MarkdownEncode())
204204
{
205205
ParseMode = SendMessage.ParseModeEnum.Markdown
206206
}).Wait();

TelegramBotDemo/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public static void RunBot(string accessToken)
171171
{
172172
bot.MakeRequestAsync(new SendMessage(
173173
update.Message.Chat.Id,
174-
"You wrote *" + update.Message.Text.Length + " characters*")
174+
"You wrote: \r\n_" + update.Message.Text.MarkdownEncode() + "_")
175175
{
176176
ParseMode = SendMessage.ParseModeEnum.Markdown
177177
}).Wait();

0 commit comments

Comments
 (0)