Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
355c601e17 | ||
|
|
75a70c6ed4 | ||
|
|
8b2d70e016 | ||
|
|
ace936e2e8 | ||
|
|
2650144b19 | ||
|
|
dded0ae49e | ||
|
|
f39b1d11be | ||
|
|
91002c8271 | ||
|
|
561312eb87 | ||
|
|
ff21c86ce9 | ||
|
|
5f9ffb7ae4 | ||
|
|
920284d77d | ||
|
|
8ea8e5aa2d | ||
|
|
7f383a8a83 | ||
|
|
0e3cb79a2f | ||
|
|
a125addd2e | ||
|
|
869d16fa02 | ||
|
|
21cdbf4db6 | ||
|
|
16371b8c7a | ||
|
|
601ce32072 | ||
|
|
b2d4c4c3f8 | ||
|
|
75600d5e7f | ||
|
|
df7880fcf3 | ||
|
|
e814046d29 | ||
|
|
0ebce16490 | ||
|
|
863b2d0414 | ||
|
|
436566adeb | ||
|
|
4054fa3e85 | ||
|
|
e8279892e4 | ||
|
|
b32347ff4f | ||
|
|
b2ffacea2a | ||
|
|
0d0c2471b2 | ||
|
|
f5054c75d5 | ||
|
|
7a85b2fc31 | ||
|
|
348909f3ff | ||
|
|
78b3fbebc8 | ||
|
|
2a3d8c1b30 | ||
|
|
d99bb79849 | ||
|
|
3386db0f66 | ||
|
|
6aac7d887a | ||
|
|
707ffd492f | ||
|
|
2c567419ec | ||
|
|
e81f535f75 | ||
|
|
72a1fa3c99 | ||
|
|
d08cbe8b0e | ||
|
|
e2ac7975a5 | ||
|
|
d7a5c149b1 | ||
|
|
8fa952e68b | ||
|
|
a0b87887f7 | ||
|
|
f1c626a7ba | ||
|
|
46cf9b9f2e | ||
|
|
3340ef7b76 | ||
|
|
211424569b | ||
|
|
8303b0c87f | ||
|
|
19856ab044 | ||
|
|
5453add956 | ||
|
|
ff3c22566a | ||
|
|
50fd5255c8 | ||
|
|
4f85677deb | ||
|
|
7d2703138c | ||
|
|
d0d93a07c0 | ||
|
|
f03e67f345 | ||
|
|
18bb6584f4 | ||
|
|
d5a89a4ed8 | ||
|
|
09d7164385 | ||
|
|
2b914f6f58 | ||
|
|
b65ec13d8b | ||
|
|
ca1c382924 | ||
|
|
584bb76e0f | ||
|
|
c5fa153d54 | ||
|
|
c6106f17ec | ||
|
|
4f97e2a919 | ||
|
|
21c6b2fde5 | ||
|
|
caf9b3cc8e | ||
|
|
27e45b397d | ||
|
|
b8bdc756d4 | ||
|
|
e5d8e403a0 | ||
|
|
2c58f86524 | ||
|
|
4bd43de0fe | ||
|
|
871d25b95b | ||
|
|
b508a7e3ce | ||
|
|
0ebba5e204 | ||
|
|
1cc0a2bdf7 | ||
|
|
fc33da0496 | ||
|
|
35045f3aeb | ||
|
|
3b8b24593f | ||
|
|
03565aba98 | ||
|
|
bbc436d1d6 | ||
|
|
4026f9ba4e | ||
|
|
fb38d32e9e | ||
|
|
077bd1384f | ||
|
|
e28663138b | ||
|
|
65ec7f1c2b | ||
|
|
1fc581b959 | ||
|
|
31e52887ba | ||
|
|
e9c25ea9e4 | ||
|
|
2aee486370 | ||
|
|
c1a0b12a94 | ||
|
|
2bd4634624 | ||
|
|
0bc77ca79c | ||
|
|
d0edf8531c | ||
|
|
b001d5e9c4 | ||
|
|
e1d5051288 | ||
|
|
d00c5e1799 | ||
|
|
c4a31e987b | ||
|
|
eafb81bf7b | ||
|
|
1dff9d5ffe | ||
|
|
755f5a245b | ||
|
|
a22ede0f4f | ||
|
|
8e29652148 | ||
|
|
5bb316d874 | ||
|
|
d2ae08771e | ||
|
|
9162c0894c | ||
|
|
e0ec133209 |
|
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 784 KiB After Width: | Height: | Size: 784 KiB |
|
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 1.0 MiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 307 KiB After Width: | Height: | Size: 307 KiB |
|
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 1.0 MiB |
|
Before Width: | Height: | Size: 7.4 KiB After Width: | Height: | Size: 7.4 KiB |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 7.9 KiB |
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 8.4 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 9.2 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 328 KiB After Width: | Height: | Size: 328 KiB |
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 4.6 KiB |
|
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.1 KiB |
|
Before Width: | Height: | Size: 756 KiB After Width: | Height: | Size: 756 KiB |
|
Before Width: | Height: | Size: 185 KiB After Width: | Height: | Size: 185 KiB |
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
|
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
@@ -252,3 +252,8 @@ TelegramBotBase/Archive
|
||||
/TelegramBotBase/TelegramBotBase.1.5.2.zip
|
||||
/TelegramBotBase/cpush.ps1
|
||||
/TelegramBotBase/cpack.ps1
|
||||
*.ps1
|
||||
*.exe
|
||||
*.snupkg
|
||||
*.zip
|
||||
*.nuspec
|
||||
|
||||
@@ -1,6 +1,378 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
|
||||
</startup>
|
||||
</configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.VisualBasic.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-10.0.6.0" newVersion="10.0.6.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Win32.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Win32.Registry" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="netstandard" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Collections" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Collections.Concurrent" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Collections.NonGeneric" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Collections.Specialized" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.ComponentModel" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.ComponentModel.EventBasedAsync" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.ComponentModel.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.ComponentModel.TypeConverter" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Console" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Data.Common" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Diagnostics.Contracts" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Diagnostics.Debug" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Diagnostics.FileVersionInfo" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Diagnostics.Process" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Diagnostics.StackTrace" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.4.0" newVersion="4.0.4.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Diagnostics.TextWriterTraceListener" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Diagnostics.TraceSource" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Diagnostics.Tracing" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Drawing.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.3.0" newVersion="4.1.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.IO.Compression.ZipFile" publicKeyToken="b77a5c561934e089" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.IO.FileSystem" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.IO.FileSystem.DriveInfo" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.IO.FileSystem.Watcher" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.IO.IsolatedStorage" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.IO.MemoryMappedFiles" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.IO.Pipes" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Linq" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Linq.Expressions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Linq.Parallel" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Linq.Queryable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Net.NameResolution" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Net.NetworkInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Net.Ping" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Net.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Net.Requests" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Net.Security" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Net.ServicePoint" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Net.Sockets" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Net.WebHeaderCollection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Net.WebSockets" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Net.WebSockets.Client" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.ObjectModel" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Reflection.Emit.ILGeneration" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Reflection.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Resources.ResourceManager" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Resources.Writer" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.VisualC" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.Extensions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.InteropServices" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.Numerics" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.Serialization.Formatters" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.Serialization.Json" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.Serialization.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.3.0" newVersion="4.1.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.Serialization.Xml" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.3.0" newVersion="4.1.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Security.AccessControl" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Security.Claims" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Security.Cryptography.Algorithms" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.2.2.0" newVersion="4.2.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Security.Cryptography.Csp" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Security.Cryptography.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Security.Cryptography.X509Certificates" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Security.Principal" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Security.Principal.Windows" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Text.Encoding.Extensions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Text.RegularExpressions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Threading" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Threading.Overlapped" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Threading.Tasks.Parallel" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Threading.Thread" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Threading.ThreadPool" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.12.0" newVersion="4.0.12.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Transactions.Local" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Xml.ReaderWriter" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Xml.XDocument" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Xml.XmlSerializer" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Xml.XPath" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Xml.XPath.XDocument" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
|
||||
@@ -8,10 +8,11 @@
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>AsyncFormUpdates</RootNamespace>
|
||||
<AssemblyName>AsyncFormUpdates</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@@ -33,9 +34,7 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
@@ -44,8 +43,8 @@
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Telegram.Bot, Version=15.7.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Telegram.Bot.15.7.1\lib\net45\Telegram.Bot.dll</HintPath>
|
||||
<Reference Include="Telegram.Bot, Version=17.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Telegram.Bot.17.0.0\lib\netstandard2.0\Telegram.Bot.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -57,7 +56,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj">
|
||||
@@ -65,5 +63,12 @@
|
||||
<Name>TelegramBotBase</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="System.Net.Requests" Version="4.3.0" />
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
|
||||
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
|
||||
<PackageReference Include="Telegram.Bot" Version="18.0.0" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -4,18 +4,21 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using TelegramBotBase.Builder;
|
||||
|
||||
namespace AsyncFormUpdates
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static TelegramBotBase.BotBase<forms.Start> bot = null;
|
||||
static TelegramBotBase.BotBase bot = null;
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
String apiKey = "APIKey";
|
||||
|
||||
bot = new TelegramBotBase.BotBase<forms.Start>(apiKey);
|
||||
bot = BotBaseBuilder.Create()
|
||||
.QuickStart<forms.Start>(apiKey)
|
||||
.Build();
|
||||
|
||||
bot.Start();
|
||||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net472" />
|
||||
<package id="System.Net.Requests" version="4.3.0" targetFramework="net472" />
|
||||
<package id="Telegram.Bot" version="15.7.1" targetFramework="net472" />
|
||||
</packages>
|
||||
@@ -0,0 +1,12 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace EFCoreBot.Database;
|
||||
|
||||
public class BotDbContext : DbContext
|
||||
{
|
||||
public BotDbContext(DbContextOptions options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public DbSet<User> Users { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace EFCoreBot.Database;
|
||||
|
||||
public class User
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string LastMessage { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>disable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.9" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.9" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,23 @@
|
||||
using EFCoreBot;
|
||||
using EFCoreBot.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using TelegramBotBase.Builder;
|
||||
|
||||
var serviceCollection = new ServiceCollection()
|
||||
.AddDbContext<BotDbContext>(x => x.UseInMemoryDatabase("TelegramBotBase"));
|
||||
|
||||
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
var bot = BotBaseBuilder.Create()
|
||||
.WithAPIKey(Environment.GetEnvironmentVariable("API_KEY") ?? throw new Exception("API_KEY is not set"))
|
||||
.DefaultMessageLoop()
|
||||
.WithServiceProvider<StartForm>(serviceProvider)
|
||||
.NoProxy()
|
||||
.NoCommands()
|
||||
.NoSerialization()
|
||||
.DefaultLanguage()
|
||||
.Build();
|
||||
|
||||
bot.Start();
|
||||
await Task.Delay(-1);
|
||||
@@ -0,0 +1,36 @@
|
||||
using EFCoreBot.Database;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace EFCoreBot;
|
||||
|
||||
public class StartForm : FormBase
|
||||
{
|
||||
private readonly BotDbContext _dbContext;
|
||||
|
||||
public StartForm(BotDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public override async Task Load(MessageResult message)
|
||||
{
|
||||
var user = await _dbContext.Users.FindAsync(Device.DeviceId);
|
||||
if (user is null)
|
||||
{
|
||||
user = new User
|
||||
{
|
||||
Id = Device.DeviceId,
|
||||
LastMessage = "<unknown>"
|
||||
};
|
||||
|
||||
_dbContext.Users.Add(user);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
await Device.Send($"Your last message's text was: `{user.LastMessage}`");
|
||||
|
||||
user.LastMessage = string.IsNullOrWhiteSpace(message.MessageText) ? "<unknown>" : message.MessageText;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="TelegramBotBase" Version="3.1.1" />
|
||||
<PackageReference Include="TelegramBotBase" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using TelegramBotBase.Builder;
|
||||
|
||||
namespace JoinHiderBot
|
||||
{
|
||||
@@ -9,7 +10,9 @@ namespace JoinHiderBot
|
||||
|
||||
String apiKey = "";
|
||||
|
||||
var bot = new TelegramBotBase.BotBase<forms.Start>(apiKey);
|
||||
var bot = BotBaseBuilder.Create()
|
||||
.QuickStart<forms.Start>(apiKey)
|
||||
.Build();
|
||||
|
||||
bot.Start();
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using TelegramBotBase.Builder;
|
||||
|
||||
namespace SystemCommandsBot
|
||||
{
|
||||
@@ -19,7 +20,9 @@ namespace SystemCommandsBot
|
||||
return;
|
||||
}
|
||||
|
||||
var bot = new TelegramBotBase.BotBase<forms.StartForm>(BotConfig.ApiKey);
|
||||
var bot = BotBaseBuilder.Create()
|
||||
.QuickStart<forms.StartForm>(BotConfig.ApiKey)
|
||||
.Build();
|
||||
|
||||
bot.Start();
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="TelegramBotBase" Version="3.1.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="TelegramBotBase" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot.Types.InputFiles;
|
||||
using Telegram.Bot.Types;
|
||||
using TelegramBotBase.Sessions;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBase.Extensions.Images
|
||||
{
|
||||
public static class ImageExtensions
|
||||
{
|
||||
public static Stream ToStream(this Image image, ImageFormat format)
|
||||
{
|
||||
var stream = new System.IO.MemoryStream();
|
||||
image.Save(stream, format);
|
||||
stream.Position = 0;
|
||||
return stream;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends an image
|
||||
/// </summary>
|
||||
/// <param name="image"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="buttons"></param>
|
||||
/// <param name="replyTo"></param>
|
||||
/// <param name="disableNotification"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Message> SendPhoto(this DeviceSession session, Image image, String name, String caption, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false)
|
||||
{
|
||||
using (var fileStream = ToStream(image, ImageFormat.Png))
|
||||
{
|
||||
InputOnlineFile fts = new InputOnlineFile(fileStream, name);
|
||||
|
||||
return await session.SendPhoto(fts, caption: caption, buttons, replyTo, disableNotification);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends an image
|
||||
/// </summary>
|
||||
/// <param name="image"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="buttons"></param>
|
||||
/// <param name="replyTo"></param>
|
||||
/// <param name="disableNotification"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Message> SendPhoto(this DeviceSession session, Bitmap image, String name, String caption, ButtonForm buttons = null, int replyTo = 0, bool disableNotification = false)
|
||||
{
|
||||
using (var fileStream = ToStream(image, ImageFormat.Png))
|
||||
{
|
||||
InputOnlineFile fts = new InputOnlineFile(fileStream, name);
|
||||
|
||||
return await session.SendPhoto(fts, caption: caption, buttons, replyTo, disableNotification);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
# TelegramBotBase.Extensions.Images
|
||||
|
||||
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images/)
|
||||
[](https://www.t.me/tgbotbase)
|
||||
|
||||
|
||||
[](https://raw.githubusercontent.com/MajMcCloud/TelegramBotFramework/master/LICENCE.md)
|
||||
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images)
|
||||
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net5;netcoreapp3.1;net6</TargetFrameworks>
|
||||
<RepositoryUrl>https://github.com/MajMcCloud/TelegramBotFramework</RepositoryUrl>
|
||||
<PackageProjectUrl>https://github.com/MajMcCloud/TelegramBotFramework</PackageProjectUrl>
|
||||
<Copyright>MIT</Copyright>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TelegramBotBase\TelegramBotBase.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TelegramBotBase.Builder;
|
||||
using TelegramBotBase.Builder.Interfaces;
|
||||
|
||||
namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
||||
{
|
||||
public static class BotBaseBuilderExtensions
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Uses an Microsoft SQL Server Database to save and restore sessions.
|
||||
/// </summary>
|
||||
/// <param name="builder"></param>
|
||||
/// <param name="ConnectionString"></param>
|
||||
/// <param name="tablePrefix"></param>
|
||||
/// <param name="fallbackForm"></param>
|
||||
/// <returns></returns>
|
||||
public static ILanguageSelectionStage UseSQLDatabase(this ISessionSerializationStage builder, String ConnectionString, Type fallbackForm = null, String tablePrefix = "tgb_")
|
||||
{
|
||||
var serializer = new MSSQLSerializer(ConnectionString, tablePrefix, fallbackForm);
|
||||
|
||||
builder.UseSerialization(serializer);
|
||||
|
||||
return builder as BotBaseBuilder;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Uses an Microsoft SQL Server Database to save and restore sessions.
|
||||
/// </summary>
|
||||
/// <param name="builder"></param>
|
||||
/// <param name="HostOrIP"></param>
|
||||
/// <param name="UserId"></param>
|
||||
/// <param name="Password"></param>
|
||||
/// <param name="DatabaseName"></param>
|
||||
/// <param name="tablePrefix"></param>
|
||||
/// <param name="fallbackForm"></param>
|
||||
/// <returns></returns>
|
||||
public static ILanguageSelectionStage UseSQLDatabase(this ISessionSerializationStage builder, String HostOrIP, String DatabaseName, String UserId, String Password, Type fallbackForm = null, String tablePrefix = "tgb_")
|
||||
{
|
||||
var connectionString = $"Server={HostOrIP}; Database={DatabaseName}; User Id={UserId}; Password={Password}; TrustServerCertificate=true;";
|
||||
|
||||
var serializer = new MSSQLSerializer(connectionString, tablePrefix, fallbackForm);
|
||||
|
||||
builder.UseSerialization(serializer);
|
||||
|
||||
return builder as BotBaseBuilder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uses an Microsoft SQL Server Database with Windows Authentication to save and restore sessions.
|
||||
/// </summary>
|
||||
/// <param name="builder"></param>
|
||||
/// <param name="HostOrIP"></param>
|
||||
/// <param name="DatabaseName"></param>
|
||||
/// <param name="tablePrefix"></param>
|
||||
/// <param name="fallbackForm"></param>
|
||||
/// <returns></returns>
|
||||
public static ILanguageSelectionStage UseSQLDatabase(this ISessionSerializationStage builder, String HostOrIP, String DatabaseName, bool IntegratedSecurity = true, Type fallbackForm = null, String tablePrefix = "tgb_")
|
||||
{
|
||||
if (!IntegratedSecurity)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
|
||||
var connectionString = $"Server={HostOrIP}; Database={DatabaseName}; Integrated Security=true; TrustServerCertificate=true;";
|
||||
|
||||
var serializer = new MSSQLSerializer(connectionString, tablePrefix, fallbackForm);
|
||||
|
||||
builder.UseSerialization(serializer);
|
||||
|
||||
return builder as BotBaseBuilder;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
using TelegramBotBase.Interfaces;
|
||||
using TelegramBotBase.Builder.Interfaces;
|
||||
using System;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Args;
|
||||
using TelegramBotBase.Form;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using System.Data;
|
||||
|
||||
namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
||||
{
|
||||
public class MSSQLSerializer : IStateMachine
|
||||
{
|
||||
public Type FallbackStateForm { get; set; }
|
||||
public string ConnectionString { get; }
|
||||
public String TablePrefix { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Will initialize the state machine.
|
||||
/// </summary>
|
||||
/// <param name="file">Path of the file and name where to save the session details.</param>
|
||||
/// <param name="fallbackStateForm">Type of Form which will be saved instead of Form which has <seealso cref="Attributes.IgnoreState"/> attribute declared. Needs to be subclass of <seealso cref="Form.FormBase"/>.</param>
|
||||
/// <param name="overwrite">Declares of the file could be overwritten.</param>
|
||||
public MSSQLSerializer(String ConnectionString, String tablePrefix = "tgb_", Type fallbackStateForm = null)
|
||||
{
|
||||
if (ConnectionString is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(ConnectionString));
|
||||
}
|
||||
|
||||
this.ConnectionString = ConnectionString;
|
||||
|
||||
this.TablePrefix = tablePrefix;
|
||||
|
||||
this.FallbackStateForm = fallbackStateForm;
|
||||
|
||||
if (this.FallbackStateForm != null && !this.FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||
{
|
||||
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
||||
}
|
||||
}
|
||||
|
||||
public StateContainer LoadFormStates()
|
||||
{
|
||||
var sc = new StateContainer();
|
||||
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
var command = connection.CreateCommand();
|
||||
command.CommandText = "SELECT deviceId, deviceTitle, FormUri, QualifiedName FROM " + TablePrefix + "devices_sessions";
|
||||
|
||||
var dataTable = new DataTable();
|
||||
using (var dataAdapter = new SqlDataAdapter(command))
|
||||
{
|
||||
dataAdapter.Fill(dataTable);
|
||||
|
||||
foreach (DataRow r in dataTable.Rows)
|
||||
{
|
||||
var se = new StateEntry()
|
||||
{
|
||||
DeviceId = (long)r["deviceId"],
|
||||
ChatTitle = r["deviceTitle"].ToString(),
|
||||
FormUri = r["FormUri"].ToString(),
|
||||
QualifiedName = r["QualifiedName"].ToString()
|
||||
};
|
||||
|
||||
sc.States.Add(se);
|
||||
|
||||
if (se.DeviceId > 0)
|
||||
{
|
||||
sc.ChatIds.Add(se.DeviceId);
|
||||
}
|
||||
else
|
||||
{
|
||||
sc.GroupIds.Add(se.DeviceId);
|
||||
}
|
||||
|
||||
var data_command = connection.CreateCommand();
|
||||
data_command.CommandText = "SELECT [key], value, type FROM " + TablePrefix + "devices_sessions_data WHERE deviceId = @deviceId";
|
||||
data_command.Parameters.Add(new SqlParameter("@deviceId", r["deviceId"]));
|
||||
|
||||
var data_table = new DataTable();
|
||||
using (var dataAdapter2 = new SqlDataAdapter(data_command))
|
||||
{
|
||||
dataAdapter2.Fill(data_table);
|
||||
|
||||
foreach (DataRow r2 in data_table.Rows)
|
||||
{
|
||||
var key = r2["key"].ToString();
|
||||
var type = Type.GetType(r2["type"].ToString());
|
||||
|
||||
var value = Newtonsoft.Json.JsonConvert.DeserializeObject(r2["value"].ToString(), type);
|
||||
|
||||
se.Values.Add(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
connection.Close();
|
||||
}
|
||||
|
||||
return sc;
|
||||
}
|
||||
|
||||
public void SaveFormStates(SaveStatesEventArgs e)
|
||||
{
|
||||
var container = e.States;
|
||||
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
//Cleanup old Session data
|
||||
var clear_command = connection.CreateCommand();
|
||||
|
||||
clear_command.CommandText = $"DELETE FROM {TablePrefix}devices_sessions_data";
|
||||
|
||||
clear_command.ExecuteNonQuery();
|
||||
|
||||
clear_command.CommandText = $"DELETE FROM {TablePrefix}devices_sessions";
|
||||
|
||||
clear_command.ExecuteNonQuery();
|
||||
|
||||
//Prepare new session commands
|
||||
var session_command = connection.CreateCommand();
|
||||
var data_command = connection.CreateCommand();
|
||||
|
||||
session_command.CommandText = "INSERT INTO " + TablePrefix + "devices_sessions (deviceId, deviceTitle, FormUri, QualifiedName) VALUES (@deviceId, @deviceTitle, @FormUri, @QualifiedName)";
|
||||
session_command.Parameters.Add(new SqlParameter("@deviceId", ""));
|
||||
session_command.Parameters.Add(new SqlParameter("@deviceTitle", ""));
|
||||
session_command.Parameters.Add(new SqlParameter("@FormUri", ""));
|
||||
session_command.Parameters.Add(new SqlParameter("@QualifiedName", ""));
|
||||
|
||||
data_command.CommandText = "INSERT INTO " + TablePrefix + "devices_sessions_data (deviceId, [key], value, type) VALUES (@deviceId, @key, @value, @type)";
|
||||
data_command.Parameters.Add(new SqlParameter("@deviceId", ""));
|
||||
data_command.Parameters.Add(new SqlParameter("@key", ""));
|
||||
data_command.Parameters.Add(new SqlParameter("@value", ""));
|
||||
data_command.Parameters.Add(new SqlParameter("@type", ""));
|
||||
|
||||
//Store session data in database
|
||||
foreach (var state in container.States)
|
||||
{
|
||||
session_command.Parameters["@deviceId"].Value = state.DeviceId;
|
||||
session_command.Parameters["@deviceTitle"].Value = state.ChatTitle ?? "";
|
||||
session_command.Parameters["@FormUri"].Value = state.FormUri;
|
||||
session_command.Parameters["@QualifiedName"].Value = state.QualifiedName;
|
||||
|
||||
session_command.ExecuteNonQuery();
|
||||
|
||||
foreach (var data in state.Values)
|
||||
{
|
||||
data_command.Parameters["@deviceId"].Value = state.DeviceId;
|
||||
data_command.Parameters["@key"].Value = data.Key;
|
||||
|
||||
var type = data.Value.GetType();
|
||||
|
||||
if (type.IsPrimitive || type.Equals(typeof(string)))
|
||||
{
|
||||
data_command.Parameters["@value"].Value = data.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
data_command.Parameters["@value"].Value = Newtonsoft.Json.JsonConvert.SerializeObject(data.Value);
|
||||
}
|
||||
|
||||
data_command.Parameters["@type"].Value = type.AssemblyQualifiedName;
|
||||
|
||||
data_command.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
connection.Close();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
# TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
||||
|
||||
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Serializer.Database.MSSQL/)
|
||||
[](https://www.t.me/tgbotbase)
|
||||
|
||||
|
||||
[](https://raw.githubusercontent.com/MajMcCloud/TelegramBotFramework/master/LICENCE.md)
|
||||
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Serializer.Database.MSSQL)
|
||||
|
||||
## How to use
|
||||
|
||||
```csharp
|
||||
using TelegramBotBase.Extensions.Serializer.Database.MSSQL;
|
||||
|
||||
|
||||
var bot = BotBaseBuilder
|
||||
.Create()
|
||||
.WithAPIKey(APIKey)
|
||||
.DefaultMessageLoop()
|
||||
.WithStartForm<Start>()
|
||||
.NoProxy()
|
||||
.OnlyStart()
|
||||
.UseSQLDatabase("localhost", "telegram_bot")
|
||||
.UseEnglish()
|
||||
.Build();
|
||||
|
||||
bot.Start();
|
||||
```
|
||||
@@ -0,0 +1,30 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;net5;netcoreapp3.1;net6</TargetFrameworks>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<RepositoryUrl>https://github.com/MajMcCloud/TelegramBotFramework</RepositoryUrl>
|
||||
<PackageProjectUrl>https://github.com/MajMcCloud/TelegramBotFramework</PackageProjectUrl>
|
||||
<Copyright>MIT</Copyright>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<AssemblyVersion>1.0.1</AssemblyVersion>
|
||||
<FileVersion>1.0.1</FileVersion>
|
||||
<Version>1.0.1</Version>
|
||||
<Description>A session serializer for Microsoft SQL Server.
|
||||
</Description>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TelegramBotBase\TelegramBotBase.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,37 @@
|
||||
USE [telegram_bot]
|
||||
GO
|
||||
/****** Object: Table [dbo].[tgb_devices_sessions] Script Date: 30.06.2022 16:22:09 ******/
|
||||
SET ANSI_NULLS ON
|
||||
GO
|
||||
SET QUOTED_IDENTIFIER ON
|
||||
GO
|
||||
CREATE TABLE [dbo].[tgb_devices_sessions](
|
||||
[deviceId] [bigint] NOT NULL,
|
||||
[deviceTitle] [nvarchar](512) NOT NULL,
|
||||
[FormUri] [nvarchar](512) NOT NULL,
|
||||
[QualifiedName] [nvarchar](512) NOT NULL,
|
||||
CONSTRAINT [PK_tgb_devices_sessions_1] PRIMARY KEY CLUSTERED
|
||||
(
|
||||
[deviceId] ASC
|
||||
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
|
||||
) ON [PRIMARY]
|
||||
GO
|
||||
/****** Object: Table [dbo].[tgb_devices_sessions_data] Script Date: 30.06.2022 16:22:09 ******/
|
||||
SET ANSI_NULLS ON
|
||||
GO
|
||||
SET QUOTED_IDENTIFIER ON
|
||||
GO
|
||||
CREATE TABLE [dbo].[tgb_devices_sessions_data](
|
||||
[Id] [uniqueidentifier] NOT NULL,
|
||||
[deviceId] [bigint] NOT NULL,
|
||||
[key] [nvarchar](512) NOT NULL,
|
||||
[value] [nvarchar](max) NOT NULL,
|
||||
[type] [nvarchar](512) NOT NULL,
|
||||
CONSTRAINT [PK_tgb_devices_session_data] PRIMARY KEY CLUSTERED
|
||||
(
|
||||
[Id] ASC
|
||||
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
|
||||
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
|
||||
GO
|
||||
ALTER TABLE [dbo].[tgb_devices_sessions_data] ADD CONSTRAINT [DF_tgb_devices_session_data_Id] DEFAULT (newid()) FOR [Id]
|
||||
GO
|
||||
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot.Types;
|
||||
using TelegramBotBase;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBaseTest.Tests;
|
||||
using TelegramBotBase.Commands;
|
||||
using TelegramBotBase.Builder;
|
||||
|
||||
namespace TelegramBotBaseTest
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static async void Main(string[] args)
|
||||
{
|
||||
|
||||
String APIKey = "";
|
||||
|
||||
var bb = BotBaseBuilder
|
||||
.Create()
|
||||
.WithAPIKey(APIKey)
|
||||
.DefaultMessageLoop()
|
||||
.WithStartForm<Start>()
|
||||
.NoProxy()
|
||||
.CustomCommands(a =>
|
||||
{
|
||||
a.Start("Starts the bot");
|
||||
a.Add("myid", "Returns my Device ID");
|
||||
a.Help("Should show you some help");
|
||||
a.Settings("Should show you some settings");
|
||||
a.Add("form1", "Opens test form 1");
|
||||
a.Add("form2", "Opens test form 2");
|
||||
a.Add("params", "Returns all send parameters as a message.");
|
||||
})
|
||||
.NoSerialization()
|
||||
.UseEnglish()
|
||||
.Build();
|
||||
|
||||
|
||||
bb.BotCommand += Bb_BotCommand;
|
||||
|
||||
//Update Bot commands to botfather
|
||||
await bb.UploadBotCommands();
|
||||
|
||||
bb.SetSetting(TelegramBotBase.Enums.eSettings.LogAllMessages, true);
|
||||
|
||||
bb.Message += (s, en) =>
|
||||
{
|
||||
Console.WriteLine(en.DeviceId + " " + en.Message.MessageText + " " + (en.Message.RawData ?? ""));
|
||||
};
|
||||
|
||||
bb.Start();
|
||||
|
||||
Console.WriteLine("Telegram Bot started...");
|
||||
|
||||
Console.WriteLine("Press q to quit application.");
|
||||
|
||||
|
||||
Console.ReadLine();
|
||||
|
||||
bb.Stop();
|
||||
|
||||
}
|
||||
|
||||
private static async Task Bb_BotCommand(object sender, TelegramBotBase.Args.BotCommandEventArgs en)
|
||||
{
|
||||
switch (en.Command)
|
||||
{
|
||||
case "/start":
|
||||
|
||||
|
||||
var start = new Menu();
|
||||
|
||||
await en.Device.ActiveForm.NavigateTo(start);
|
||||
|
||||
break;
|
||||
case "/form1":
|
||||
|
||||
var form1 = new TestForm();
|
||||
|
||||
await en.Device.ActiveForm.NavigateTo(form1);
|
||||
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case "/form2":
|
||||
|
||||
var form2 = new TestForm2();
|
||||
|
||||
await en.Device.ActiveForm.NavigateTo(form2);
|
||||
|
||||
break;
|
||||
|
||||
case "/myid":
|
||||
|
||||
await en.Device.Send($"Your Device ID is: {en.DeviceId}");
|
||||
|
||||
en.Handled = true;
|
||||
|
||||
break;
|
||||
|
||||
case "/params":
|
||||
|
||||
String m = en.Parameters.DefaultIfEmpty("").Aggregate((a, b) => a + " and " + b);
|
||||
|
||||
await en.Device.Send("Your parameters are: " + m, replyTo: en.Device.LastMessageId);
|
||||
|
||||
en.Handled = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFrameworks>netcoreapp3.1;net5</TargetFrameworks>
|
||||
<TargetFrameworks>netcoreapp3.1;net5;net6</TargetFrameworks>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<Configurations>Debug;Release</Configurations>
|
||||
</PropertyGroup>
|
||||
@@ -27,6 +27,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TelegramBotBase.Extensions.Images\TelegramBotBase.Extensions.Images.csproj" />
|
||||
<ProjectReference Include="..\TelegramBotBase\TelegramBotBase.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -48,26 +48,6 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
}
|
||||
}
|
||||
|
||||
public override async Task Load(MessageResult message)
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override async Task Action(MessageResult message)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override async Task Render(MessageResult message)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.InputFiles;
|
||||
using Telegram.Bot.Types.ReplyMarkups;
|
||||
@@ -49,17 +49,6 @@ namespace TelegramBotBaseTest.Tests.Datasources
|
||||
}
|
||||
}
|
||||
|
||||
public override async Task Load(MessageResult message)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override async Task Render(MessageResult message)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -16,16 +16,9 @@ namespace TelegramBotBaseTest.Tests.Navigation
|
||||
|
||||
public Start()
|
||||
{
|
||||
this.Closed += Start_Closed;
|
||||
|
||||
}
|
||||
|
||||
private async Task Start_Closed(object sender, EventArgs e)
|
||||
{
|
||||
if (msg == null)
|
||||
return;
|
||||
|
||||
await Device.DeleteMessage(msg);
|
||||
}
|
||||
|
||||
public override async Task Load(MessageResult message)
|
||||
{
|
||||
@@ -49,12 +42,18 @@ namespace TelegramBotBaseTest.Tests.Navigation
|
||||
|
||||
//Create navigation controller and navigate to it, keep the current form as root form so we can get back to here later
|
||||
var nc = new CustomController(this);
|
||||
nc.ForceCleanupOnLastPop = true;
|
||||
|
||||
var f1 = new Form1();
|
||||
|
||||
await nc.PushAsync(f1);
|
||||
|
||||
await NavigateTo(nc);
|
||||
|
||||
await nc.PushAsync(f1);
|
||||
if (msg == null)
|
||||
return;
|
||||
|
||||
await Device.DeleteMessage(msg);
|
||||
|
||||
|
||||
break;
|
||||
@@ -66,6 +65,10 @@ namespace TelegramBotBaseTest.Tests.Navigation
|
||||
|
||||
await NavigateTo(mn);
|
||||
|
||||
if (msg == null)
|
||||
return;
|
||||
|
||||
await Device.DeleteMessage(msg);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -51,10 +51,10 @@ namespace TelegramBotBaseTest.Tests
|
||||
|
||||
default:
|
||||
|
||||
if (message.RawMessageData == null)
|
||||
if (message.UpdateData == null)
|
||||
return;
|
||||
|
||||
this.LastMessage = message.RawMessageData.Message.Text;
|
||||
this.LastMessage = message.Message.Text;
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.ReplyMarkups;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Extensions.Images;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net5" />
|
||||
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net5" />
|
||||
<package id="System.Net.Requests" version="4.3.0" targetFramework="net5" />
|
||||
<package id="Telegram.Bot" version="14.12.0" targetFramework="net5" />
|
||||
</packages>
|
||||
@@ -7,7 +7,7 @@ using Telegram.Bot.Types;
|
||||
|
||||
namespace TelegramBotBase.Args
|
||||
{
|
||||
public class MessageSentEventArgs
|
||||
public class MessageSentEventArgs : EventArgs
|
||||
{
|
||||
public int MessageId
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.InputFiles;
|
||||
|
||||
@@ -14,7 +15,11 @@ namespace TelegramBotBase.Base
|
||||
/// </summary>
|
||||
public class DataResult : ResultBase
|
||||
{
|
||||
public Telegram.Bot.Args.MessageEventArgs RawMessageData { get; set; }
|
||||
|
||||
//public Telegram.Bot.Args.MessageEventArgs RawMessageData { get; set; }
|
||||
|
||||
public UpdateResult UpdateData { get; set; }
|
||||
|
||||
|
||||
public Contact Contact
|
||||
{
|
||||
@@ -64,11 +69,20 @@ namespace TelegramBotBase.Base
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Telegram.Bot.Types.Enums.MessageType Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.RawMessageData?.Message?.Type ?? Telegram.Bot.Types.Enums.MessageType.Unknown;
|
||||
return this.Message?.Type ?? Telegram.Bot.Types.Enums.MessageType.Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
public override Message Message
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.UpdateData?.Message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,25 +100,17 @@ namespace TelegramBotBase.Base
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public DataResult(Telegram.Bot.Args.MessageEventArgs rawdata)
|
||||
public DataResult(UpdateResult update)
|
||||
{
|
||||
this.RawMessageData = rawdata;
|
||||
this.Message = rawdata.Message;
|
||||
this.UpdateData = update;
|
||||
}
|
||||
|
||||
public DataResult(MessageResult message)
|
||||
{
|
||||
this.RawMessageData = message.RawMessageData;
|
||||
this.Message = message.Message;
|
||||
|
||||
this.Client = message.Client;
|
||||
}
|
||||
|
||||
public async Task<InputOnlineFile> DownloadDocument()
|
||||
{
|
||||
var encryptedContent = new System.IO.MemoryStream(this.Document.FileSize);
|
||||
var file = await this.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Document.FileId, encryptedContent);
|
||||
var encryptedContent = new System.IO.MemoryStream();
|
||||
encryptedContent.SetLength(this.Document.FileSize.Value);
|
||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Document.FileId, encryptedContent);
|
||||
|
||||
return new InputOnlineFile(encryptedContent, this.Document.FileName);
|
||||
}
|
||||
@@ -117,9 +123,9 @@ namespace TelegramBotBase.Base
|
||||
/// <returns></returns>
|
||||
public async Task DownloadDocument(String path)
|
||||
{
|
||||
var file = await this.Client.TelegramClient.GetFileAsync(this.Document.FileId);
|
||||
var file = await Device.Client.TelegramClient.GetFileAsync(this.Document.FileId);
|
||||
FileStream fs = new FileStream(path, FileMode.Create);
|
||||
await this.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||
fs.Close();
|
||||
fs.Dispose();
|
||||
}
|
||||
@@ -131,7 +137,7 @@ namespace TelegramBotBase.Base
|
||||
public async Task<byte[]> DownloadRawDocument()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
await this.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Document.FileId, ms);
|
||||
await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Document.FileId, ms);
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
@@ -151,45 +157,47 @@ namespace TelegramBotBase.Base
|
||||
public async Task<String> DownloadRawTextDocument(Encoding encoding)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
await this.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Document.FileId, ms);
|
||||
await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Document.FileId, ms);
|
||||
|
||||
ms.Position = 0;
|
||||
|
||||
var sr = new StreamReader(ms, encoding);
|
||||
|
||||
|
||||
return sr.ReadToEnd();
|
||||
}
|
||||
|
||||
public async Task<InputOnlineFile> DownloadVideo()
|
||||
{
|
||||
var encryptedContent = new System.IO.MemoryStream(this.Video.FileSize);
|
||||
var file = await this.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Video.FileId, encryptedContent);
|
||||
var encryptedContent = new System.IO.MemoryStream();
|
||||
encryptedContent.SetLength(this.Video.FileSize.Value);
|
||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Video.FileId, encryptedContent);
|
||||
|
||||
return new InputOnlineFile(encryptedContent, "");
|
||||
}
|
||||
|
||||
public async Task DownloadVideo(String path)
|
||||
{
|
||||
var file = await this.Client.TelegramClient.GetFileAsync(this.Video.FileId);
|
||||
var file = await Device.Client.TelegramClient.GetFileAsync(this.Video.FileId);
|
||||
FileStream fs = new FileStream(path, FileMode.Create);
|
||||
await this.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||
fs.Close();
|
||||
fs.Dispose();
|
||||
}
|
||||
|
||||
public async Task<InputOnlineFile> DownloadAudio()
|
||||
{
|
||||
var encryptedContent = new System.IO.MemoryStream(this.Audio.FileSize);
|
||||
var file = await this.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Audio.FileId, encryptedContent);
|
||||
var encryptedContent = new System.IO.MemoryStream();
|
||||
encryptedContent.SetLength(this.Audio.FileSize.Value);
|
||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Audio.FileId, encryptedContent);
|
||||
|
||||
return new InputOnlineFile(encryptedContent, "");
|
||||
}
|
||||
|
||||
public async Task DownloadAudio(String path)
|
||||
{
|
||||
var file = await this.Client.TelegramClient.GetFileAsync(this.Audio.FileId);
|
||||
var file = await Device.Client.TelegramClient.GetFileAsync(this.Audio.FileId);
|
||||
FileStream fs = new FileStream(path, FileMode.Create);
|
||||
await this.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||
fs.Close();
|
||||
fs.Dispose();
|
||||
}
|
||||
@@ -197,8 +205,9 @@ namespace TelegramBotBase.Base
|
||||
public async Task<InputOnlineFile> DownloadPhoto(int index)
|
||||
{
|
||||
var photo = this.Photos[index];
|
||||
var encryptedContent = new System.IO.MemoryStream(photo.FileSize);
|
||||
var file = await this.Client.TelegramClient.GetInfoAndDownloadFileAsync(photo.FileId, encryptedContent);
|
||||
var encryptedContent = new System.IO.MemoryStream();
|
||||
encryptedContent.SetLength(photo.FileSize.Value);
|
||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(photo.FileId, encryptedContent);
|
||||
|
||||
return new InputOnlineFile(encryptedContent, "");
|
||||
}
|
||||
@@ -206,9 +215,9 @@ namespace TelegramBotBase.Base
|
||||
public async Task DownloadPhoto(int index, String path)
|
||||
{
|
||||
var photo = this.Photos[index];
|
||||
var file = await this.Client.TelegramClient.GetFileAsync(photo.FileId);
|
||||
var file = await Device.Client.TelegramClient.GetFileAsync(photo.FileId);
|
||||
FileStream fs = new FileStream(path, FileMode.Create);
|
||||
await this.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||
fs.Close();
|
||||
fs.Dispose();
|
||||
}
|
||||
|
||||
@@ -55,9 +55,6 @@ namespace TelegramBotBase.Form
|
||||
|
||||
public async Task OnInit(InitEventArgs e)
|
||||
{
|
||||
if (this.Events[__evInit] == null)
|
||||
return;
|
||||
|
||||
var handler = this.Events[__evInit]?.GetInvocationList().Cast<AsyncEventHandler<InitEventArgs>>();
|
||||
if (handler == null)
|
||||
return;
|
||||
@@ -87,9 +84,6 @@ namespace TelegramBotBase.Form
|
||||
|
||||
public async Task OnOpened(EventArgs e)
|
||||
{
|
||||
if (this.Events[__evOpened] == null)
|
||||
return;
|
||||
|
||||
var handler = this.Events[__evOpened]?.GetInvocationList().Cast<AsyncEventHandler<EventArgs>>();
|
||||
if (handler == null)
|
||||
return;
|
||||
@@ -120,9 +114,6 @@ namespace TelegramBotBase.Form
|
||||
|
||||
public async Task OnClosed(EventArgs e)
|
||||
{
|
||||
if (this.Events[__evClosed] == null)
|
||||
return;
|
||||
|
||||
var handler = this.Events[__evClosed]?.GetInvocationList().Cast<AsyncEventHandler<EventArgs>>();
|
||||
if (handler == null)
|
||||
return;
|
||||
|
||||
@@ -5,8 +5,13 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot.Exceptions;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
using Telegram.Bot.Extensions.Polling;
|
||||
|
||||
namespace TelegramBotBase.Base
|
||||
{
|
||||
@@ -19,16 +24,20 @@ namespace TelegramBotBase.Base
|
||||
|
||||
public String APIKey { get; set; }
|
||||
|
||||
public Telegram.Bot.TelegramBotClient TelegramClient { get; set; }
|
||||
public ITelegramBotClient TelegramClient { get; set; }
|
||||
|
||||
private EventHandlerList __Events { get; set; } = new EventHandlerList();
|
||||
|
||||
private static object __evOnMessageLoop = new object();
|
||||
|
||||
private static object __evOnMessage = new object();
|
||||
|
||||
private static object __evOnMessageEdit = new object();
|
||||
|
||||
private static object __evCallbackQuery = new object();
|
||||
|
||||
CancellationTokenSource __cancellationTokenSource;
|
||||
|
||||
|
||||
public MessageClient(String APIKey)
|
||||
{
|
||||
@@ -47,13 +56,22 @@ namespace TelegramBotBase.Base
|
||||
Prepare();
|
||||
}
|
||||
|
||||
public MessageClient(String APIKey, Uri proxyUrl)
|
||||
|
||||
|
||||
public MessageClient(String APIKey, Uri proxyUrl, NetworkCredential credential = null)
|
||||
{
|
||||
this.APIKey = APIKey;
|
||||
|
||||
var proxy = new WebProxy(proxyUrl);
|
||||
var proxy = new WebProxy(proxyUrl)
|
||||
{
|
||||
Credentials = credential
|
||||
};
|
||||
|
||||
this.TelegramClient = new Telegram.Bot.TelegramBotClient(APIKey, proxy);
|
||||
var httpClient = new HttpClient(
|
||||
new HttpClientHandler { Proxy = proxy, UseProxy = true }
|
||||
);
|
||||
|
||||
this.TelegramClient = new Telegram.Bot.TelegramBotClient(APIKey, httpClient);
|
||||
|
||||
Prepare();
|
||||
}
|
||||
@@ -70,11 +88,17 @@ namespace TelegramBotBase.Base
|
||||
|
||||
var proxy = new WebProxy(proxyHost, proxyPort);
|
||||
|
||||
this.TelegramClient = new Telegram.Bot.TelegramBotClient(APIKey, proxy);
|
||||
var httpClient = new HttpClient(
|
||||
new HttpClientHandler { Proxy = proxy, UseProxy = true }
|
||||
);
|
||||
|
||||
this.TelegramClient = new Telegram.Bot.TelegramBotClient(APIKey, httpClient);
|
||||
|
||||
Prepare();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public MessageClient(String APIKey, Telegram.Bot.TelegramBotClient Client)
|
||||
{
|
||||
this.APIKey = APIKey;
|
||||
@@ -88,135 +112,98 @@ namespace TelegramBotBase.Base
|
||||
{
|
||||
this.TelegramClient.Timeout = new TimeSpan(0, 0, 30);
|
||||
|
||||
this.TelegramClient.OnMessage += TelegramClient_OnMessage;
|
||||
this.TelegramClient.OnMessageEdited += TelegramClient_OnMessageEdited;
|
||||
this.TelegramClient.OnCallbackQuery += TelegramClient_OnCallbackQuery;
|
||||
}
|
||||
|
||||
private async void TelegramClient_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e)
|
||||
|
||||
|
||||
public void StartReceiving()
|
||||
{
|
||||
//Skip empty messages by default
|
||||
if (e.Message == null)
|
||||
return;
|
||||
__cancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
try
|
||||
{
|
||||
var mr = new MessageResult(e);
|
||||
mr.Client = this;
|
||||
OnMessage(mr);
|
||||
}
|
||||
catch
|
||||
var receiverOptions = new ReceiverOptions
|
||||
{
|
||||
AllowedUpdates = { } // receive all update types
|
||||
};
|
||||
|
||||
}
|
||||
this.TelegramClient.StartReceiving(HandleUpdateAsync, HandleErrorAsync, receiverOptions, __cancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
|
||||
private async void TelegramClient_OnMessageEdited(object sender, Telegram.Bot.Args.MessageEventArgs e)
|
||||
public void StopReceiving()
|
||||
{
|
||||
//Skip empty messages by default
|
||||
if (e.Message == null)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
var mr = new MessageResult(e);
|
||||
mr.Client = this;
|
||||
OnMessageEdit(mr);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
__cancellationTokenSource.Cancel();
|
||||
}
|
||||
|
||||
private async void TelegramClient_OnCallbackQuery(object sender, Telegram.Bot.Args.CallbackQueryEventArgs e)
|
||||
|
||||
public Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var ar = new MessageResult(e);
|
||||
ar.Client = this;
|
||||
OnAction(ar);
|
||||
}
|
||||
catch
|
||||
{
|
||||
OnMessageLoop(new UpdateResult(update, null));
|
||||
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken)
|
||||
{
|
||||
if (exception is ApiRequestException exAPI)
|
||||
{
|
||||
Console.WriteLine($"Telegram API Error:\n[{exAPI.ErrorCode}]\n{exAPI.Message}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(exception.ToString());
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This will return the current list of bot commands.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<BotCommand[]> GetBotCommands()
|
||||
public async Task<BotCommand[]> GetBotCommands(BotCommandScope scope = null, String languageCode = null)
|
||||
{
|
||||
return await this.TelegramClient.GetMyCommandsAsync();
|
||||
return await this.TelegramClient.GetMyCommandsAsync(scope, languageCode);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This will set your bot commands to the given list.
|
||||
/// </summary>
|
||||
/// <param name="botcommands"></param>
|
||||
/// <returns></returns>
|
||||
public async Task SetBotCommands(List<BotCommand> botcommands)
|
||||
public async Task SetBotCommands(List<BotCommand> botcommands, BotCommandScope scope = null, String languageCode = null)
|
||||
{
|
||||
await this.TelegramClient.SetMyCommandsAsync(botcommands);
|
||||
await this.TelegramClient.SetMyCommandsAsync(botcommands, scope, languageCode);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This will delete the current list of bot commands.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task DeleteBotCommands(BotCommandScope scope = null, String languageCode = null)
|
||||
{
|
||||
await this.TelegramClient.DeleteMyCommandsAsync(scope, languageCode);
|
||||
}
|
||||
|
||||
|
||||
#region "Events"
|
||||
|
||||
public event EventHandler<MessageResult> Message
|
||||
|
||||
|
||||
public event Async.AsyncEventHandler<UpdateResult> MessageLoop
|
||||
{
|
||||
add
|
||||
{
|
||||
this.__Events.AddHandler(__evOnMessage, value);
|
||||
this.__Events.AddHandler(__evOnMessageLoop, value);
|
||||
}
|
||||
remove
|
||||
{
|
||||
this.__Events.RemoveHandler(__evOnMessage, value);
|
||||
this.__Events.RemoveHandler(__evOnMessageLoop, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMessage(MessageResult result)
|
||||
public void OnMessageLoop(UpdateResult update)
|
||||
{
|
||||
(this.__Events[__evOnMessage] as EventHandler<MessageResult>)?.Invoke(this, result);
|
||||
}
|
||||
|
||||
public event EventHandler<MessageResult> MessageEdit
|
||||
{
|
||||
add
|
||||
{
|
||||
this.__Events.AddHandler(__evOnMessageEdit, value);
|
||||
}
|
||||
remove
|
||||
{
|
||||
this.__Events.RemoveHandler(__evOnMessageEdit, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMessageEdit(MessageResult result)
|
||||
{
|
||||
(this.__Events[__evOnMessageEdit] as EventHandler<MessageResult>)?.Invoke(this, result);
|
||||
}
|
||||
|
||||
public event EventHandler<MessageResult> Action
|
||||
{
|
||||
add
|
||||
{
|
||||
this.__Events.AddHandler(__evCallbackQuery, value);
|
||||
}
|
||||
remove
|
||||
{
|
||||
this.__Events.RemoveHandler(__evCallbackQuery, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnAction(MessageResult result)
|
||||
{
|
||||
(this.__Events[__evCallbackQuery] as EventHandler<MessageResult>)?.Invoke(this, result);
|
||||
(this.__Events[__evOnMessageLoop] as Async.AsyncEventHandler<UpdateResult>)?.Invoke(this, update);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,15 +3,16 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
using TelegramBotBase.Sessions;
|
||||
|
||||
namespace TelegramBotBase.Base
|
||||
{
|
||||
public class MessageResult : ResultBase
|
||||
{
|
||||
public Telegram.Bot.Args.MessageEventArgs RawMessageData { get; set; }
|
||||
|
||||
public Telegram.Bot.Args.CallbackQueryEventArgs RawCallbackData { get; set; }
|
||||
public Telegram.Bot.Types.Update UpdateData { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Device/ChatId
|
||||
@@ -20,19 +21,14 @@ namespace TelegramBotBase.Base
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.RawMessageData?.Message?.Chat.Id
|
||||
?? this.RawCallbackData?.CallbackQuery.Message?.Chat.Id
|
||||
return this.UpdateData?.Message?.Chat?.Id
|
||||
?? this.UpdateData?.EditedMessage?.Chat.Id
|
||||
?? this.UpdateData?.CallbackQuery.Message?.Chat.Id
|
||||
?? Device?.DeviceId
|
||||
?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
public DeviceSession Device
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The message id
|
||||
/// </summary>
|
||||
@@ -40,8 +36,9 @@ namespace TelegramBotBase.Base
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.Message?.MessageId
|
||||
?? this.RawCallbackData?.CallbackQuery?.Message?.MessageId
|
||||
return this.UpdateData?.Message?.MessageId
|
||||
?? this.Message?.MessageId
|
||||
?? this.UpdateData?.CallbackQuery?.Message?.MessageId
|
||||
?? 0;
|
||||
}
|
||||
}
|
||||
@@ -50,7 +47,7 @@ namespace TelegramBotBase.Base
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.RawMessageData?.Message?.Text ?? "";
|
||||
return this.UpdateData?.Message?.Text ?? "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +55,7 @@ namespace TelegramBotBase.Base
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.RawMessageData?.Message?.Text ?? "";
|
||||
return this.UpdateData?.Message?.Text ?? "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,8 +63,19 @@ namespace TelegramBotBase.Base
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.RawMessageData?.Message?.Type
|
||||
?? Telegram.Bot.Types.Enums.MessageType.Unknown;
|
||||
return Message?.Type ?? Telegram.Bot.Types.Enums.MessageType.Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
public Message Message
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.UpdateData?.Message
|
||||
?? this.UpdateData?.EditedMessage
|
||||
?? this.UpdateData?.ChannelPost
|
||||
?? this.UpdateData?.EditedChannelPost
|
||||
?? this.UpdateData?.CallbackQuery?.Message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +86,7 @@ namespace TelegramBotBase.Base
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this.RawCallbackData != null);
|
||||
return (this.UpdateData.CallbackQuery != null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +141,7 @@ namespace TelegramBotBase.Base
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.RawCallbackData?.CallbackQuery?.Data;
|
||||
return this.UpdateData?.CallbackQuery?.Data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,20 +164,13 @@ namespace TelegramBotBase.Base
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Confirm incomming action (i.e. Button click)
|
||||
/// Confirm incoming action (i.e. Button click)
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
public async Task ConfirmAction(String message = "", bool showAlert = false, String urlToOpen = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
await this.Client.TelegramClient.AnswerCallbackQueryAsync(this.RawCallbackData.CallbackQuery.Id, message, showAlert, urlToOpen);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
await this.Device.ConfirmAction(this.UpdateData.CallbackQuery.Id, message, showAlert, urlToOpen);
|
||||
}
|
||||
|
||||
public override async Task DeleteMessage()
|
||||
@@ -189,16 +190,10 @@ namespace TelegramBotBase.Base
|
||||
|
||||
}
|
||||
|
||||
public MessageResult(Telegram.Bot.Args.MessageEventArgs rawdata)
|
||||
public MessageResult(Telegram.Bot.Types.Update update)
|
||||
{
|
||||
this.RawMessageData = rawdata;
|
||||
this.Message = rawdata.Message;
|
||||
}
|
||||
this.UpdateData = update;
|
||||
|
||||
public MessageResult(Telegram.Bot.Args.CallbackQueryEventArgs callback)
|
||||
{
|
||||
this.RawCallbackData = callback;
|
||||
this.Message = callback.CallbackQuery.Message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,12 +3,18 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot;
|
||||
using TelegramBotBase.Sessions;
|
||||
|
||||
namespace TelegramBotBase.Base
|
||||
{
|
||||
public class ResultBase : EventArgs
|
||||
{
|
||||
public MessageClient Client { get; set; }
|
||||
public DeviceSession Device
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public virtual long DeviceId { get; set; }
|
||||
|
||||
@@ -20,7 +26,7 @@ namespace TelegramBotBase.Base
|
||||
}
|
||||
}
|
||||
|
||||
public Telegram.Bot.Types.Message Message { get; set; }
|
||||
public virtual Telegram.Bot.Types.Message Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the current message
|
||||
@@ -41,7 +47,7 @@ namespace TelegramBotBase.Base
|
||||
{
|
||||
try
|
||||
{
|
||||
await this.Client.TelegramClient.DeleteMessageAsync(this.DeviceId, (messageId == -1 ? this.MessageId : messageId));
|
||||
await Device.Client.TelegramClient.DeleteMessageAsync(this.DeviceId, (messageId == -1 ? this.MessageId : messageId));
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Telegram.Bot.Types;
|
||||
using TelegramBotBase.Sessions;
|
||||
|
||||
namespace TelegramBotBase.Base
|
||||
{
|
||||
public class UpdateResult : ResultBase
|
||||
{
|
||||
public UpdateResult(Update rawData, DeviceSession device)
|
||||
{
|
||||
RawData = rawData;
|
||||
Device = device;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Device/ChatId
|
||||
/// </summary>
|
||||
public override long DeviceId
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.RawData?.Message?.Chat?.Id
|
||||
?? this.RawData?.CallbackQuery?.Message?.Chat?.Id
|
||||
?? Device?.DeviceId
|
||||
?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
public Update RawData { get; set; }
|
||||
|
||||
public override Message Message
|
||||
{
|
||||
get
|
||||
{
|
||||
return RawData?.Message
|
||||
?? RawData?.EditedMessage
|
||||
?? RawData?.ChannelPost
|
||||
?? RawData?.EditedChannelPost
|
||||
?? RawData?.CallbackQuery?.Message;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public DeviceSession Device
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,13 +3,17 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Exceptions;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
using TelegramBotBase.Args;
|
||||
using TelegramBotBase.Attributes;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.MessageLoops;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBase.Interfaces;
|
||||
using TelegramBotBase.Sessions;
|
||||
@@ -20,8 +24,7 @@ namespace TelegramBotBase
|
||||
/// Bot base class for full Device/Context and Messagehandling
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class BotBase<T>
|
||||
where T : FormBase
|
||||
public sealed class BotBase
|
||||
{
|
||||
public MessageClient Client { get; set; }
|
||||
|
||||
@@ -33,17 +36,17 @@ namespace TelegramBotBase
|
||||
/// <summary>
|
||||
/// List of all running/active sessions
|
||||
/// </summary>
|
||||
public SessionBase<T> Sessions { get; set; }
|
||||
public SessionManager Sessions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Contains System commands which will be available at everytime and didnt get passed to forms, i.e. /start
|
||||
/// </summary>
|
||||
public List<BotCommand> BotCommands { get; set; }
|
||||
public Dictionary<BotCommandScope, List<BotCommand>> BotCommandScopes { get; set; } = new Dictionary<BotCommandScope, List<BotCommand>>();
|
||||
|
||||
|
||||
#region "Events"
|
||||
|
||||
private EventHandlerList __Events = new EventHandlerList();
|
||||
private EventHandlerList __events = new EventHandlerList();
|
||||
|
||||
private static object __evSessionBegins = new object();
|
||||
|
||||
@@ -65,12 +68,24 @@ namespace TelegramBotBase
|
||||
/// </summary>
|
||||
public IStateMachine StateMachine { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Offers functionality to manage the creation process of the start form.
|
||||
/// </summary>
|
||||
public IStartFormFactory StartFormFactory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Contains the message loop factory, which cares about "message-management."
|
||||
/// </summary>
|
||||
public IMessageLoopFactory MessageLoopFactory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// All internal used settings.
|
||||
/// </summary>
|
||||
public Dictionary<eSettings, uint> SystemSettings { get; private set; }
|
||||
|
||||
private BotBase()
|
||||
internal BotBase()
|
||||
{
|
||||
this.SystemSettings = new Dictionary<eSettings, uint>();
|
||||
SystemSettings = new Dictionary<eSettings, uint>();
|
||||
|
||||
SetSetting(eSettings.MaxNumberOfRetries, 5);
|
||||
SetSetting(eSettings.NavigationMaximum, 10);
|
||||
@@ -78,273 +93,48 @@ namespace TelegramBotBase
|
||||
SetSetting(eSettings.SkipAllMessages, false);
|
||||
SetSetting(eSettings.SaveSessionsOnConsoleExit, false);
|
||||
|
||||
this.BotCommands = new List<BotCommand>();
|
||||
BotCommandScopes = new Dictionary<BotCommandScope, List<BotCommand>>();
|
||||
|
||||
this.Sessions = new SessionBase<T>();
|
||||
this.Sessions.BotBase = this;
|
||||
Sessions = new SessionManager(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Simple start of your Bot with the APIKey
|
||||
/// </summary>
|
||||
/// <param name="apiKey"></param>
|
||||
public BotBase(String apiKey, bool initClient = true) : this()
|
||||
{
|
||||
this.APIKey = apiKey;
|
||||
|
||||
if (!initClient)
|
||||
return;
|
||||
|
||||
this.Client = new Base.MessageClient(this.APIKey);
|
||||
this.Client.TelegramClient.Timeout = new TimeSpan(0, 1, 0);
|
||||
|
||||
this.Sessions.Client = this.Client;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Simple start of your Bot with the APIKey and a proxyAdress
|
||||
/// </summary>
|
||||
/// <param name="apiKey"></param>
|
||||
/// <param name="proxyBaseAddress">i.e. https://127.0.0.1:10000</param>
|
||||
public BotBase(String apiKey, System.Net.Http.HttpClient proxy) : this(apiKey, false)
|
||||
{
|
||||
this.Client = new Base.MessageClient(this.APIKey, proxy);
|
||||
|
||||
this.Sessions.Client = this.Client;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Simple start of your Bot with the APIKey and a TelegramBotClient instance.
|
||||
/// </summary>
|
||||
/// <param name="apiKey"></param>
|
||||
/// <param name="client"></param>
|
||||
public BotBase(String apiKey, TelegramBotClient client) : this(apiKey, false)
|
||||
{
|
||||
this.Client = new Base.MessageClient(this.APIKey, client);
|
||||
|
||||
this.Sessions.Client = this.Client;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Simple start of your Bot with the APIKey and a proxyAdress
|
||||
/// </summary>
|
||||
/// <param name="apiKey"></param>
|
||||
/// <param name="proxyBaseAddress">i.e. https://127.0.0.1:10000</param>
|
||||
public BotBase(String apiKey, String proxyBaseAddress) : this(apiKey, false)
|
||||
{
|
||||
var url = new Uri(proxyBaseAddress);
|
||||
|
||||
this.Client = new Base.MessageClient(this.APIKey, url);
|
||||
|
||||
this.Sessions.Client = this.Client;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Simple start of your Bot with the APIKey and a proxyAdress
|
||||
/// </summary>
|
||||
/// <param name="apiKey"></param>
|
||||
/// <param name="proxyHost">i.e. 127.0.0.1</param>
|
||||
/// <param name="proxyPort">i.e. 10000</param>
|
||||
public BotBase(String apiKey, String proxyHost, int proxyPort) : this(apiKey, false)
|
||||
{
|
||||
this.Client = new Base.MessageClient(this.APIKey, proxyHost, proxyPort);
|
||||
|
||||
this.Sessions.Client = this.Client;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start your Bot
|
||||
/// </summary>
|
||||
public void Start()
|
||||
public async Task Start()
|
||||
{
|
||||
if (this.Client == null)
|
||||
return;
|
||||
Client.MessageLoop += Client_MessageLoop;
|
||||
|
||||
this.Client.Message += Client_Message;
|
||||
this.Client.MessageEdit += Client_MessageEdit;
|
||||
this.Client.Action += Client_Action;
|
||||
|
||||
if (this.StateMachine != null)
|
||||
{
|
||||
this.Sessions.LoadSessionStates(this.StateMachine);
|
||||
}
|
||||
if (StateMachine != null) await Sessions.LoadSessionStates(StateMachine);
|
||||
|
||||
|
||||
//Enable auto session saving
|
||||
if (this.GetSetting(eSettings.SaveSessionsOnConsoleExit, false))
|
||||
{
|
||||
TelegramBotBase.Tools.Console.SetHandler(() =>
|
||||
{
|
||||
this.Sessions.SaveSessionStates();
|
||||
});
|
||||
}
|
||||
if (GetSetting(eSettings.SaveSessionsOnConsoleExit, false))
|
||||
TelegramBotBase.Tools.Console.SetHandler(() => { Task.Run(Sessions.SaveSessionStates); });
|
||||
|
||||
|
||||
DeviceSession.MaxNumberOfRetries = this.GetSetting(eSettings.MaxNumberOfRetries, 5);
|
||||
DeviceSession.MaxNumberOfRetries = GetSetting(eSettings.MaxNumberOfRetries, 5);
|
||||
|
||||
this.Client.TelegramClient.StartReceiving();
|
||||
Client.StartReceiving();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Stop your Bot
|
||||
/// </summary>
|
||||
public void Stop()
|
||||
private async Task Client_MessageLoop(object sender, UpdateResult e)
|
||||
{
|
||||
if (this.Client == null)
|
||||
return;
|
||||
|
||||
this.Client.Message -= Client_Message;
|
||||
this.Client.Action -= Client_Action;
|
||||
|
||||
this.Client.TelegramClient.StopReceiving();
|
||||
|
||||
this.Sessions.SaveSessionStates();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a message to all active Sessions.
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
public async Task SentToAll(String message)
|
||||
{
|
||||
if (this.Client == null)
|
||||
return;
|
||||
|
||||
foreach (var s in this.Sessions.SessionList)
|
||||
{
|
||||
await this.Client.TelegramClient.SendTextMessageAsync(s.Key, message);
|
||||
}
|
||||
}
|
||||
|
||||
private async void Client_Message(object sender, MessageResult e)
|
||||
{
|
||||
if (this.GetSetting(eSettings.SkipAllMessages, false))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
DeviceSession ds = this.Sessions.GetSession(e.DeviceId);
|
||||
e.Device = ds;
|
||||
|
||||
if (this.GetSetting(eSettings.LogAllMessages, false))
|
||||
{
|
||||
OnMessage(new MessageIncomeEventArgs(e.DeviceId, ds, e));
|
||||
}
|
||||
|
||||
ds?.OnMessageReceived(new MessageReceivedEventArgs(e.Message));
|
||||
|
||||
await Client_Loop(sender, e);
|
||||
}
|
||||
catch (Telegram.Bot.Exceptions.ApiRequestException ex)
|
||||
{
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DeviceSession ds = this.Sessions.GetSession(e.DeviceId);
|
||||
OnException(new SystemExceptionEventArgs(e.Message.Text, ds?.DeviceId ?? -1, ds, ex));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//private async Task Client_TryMessage(object sender, MessageResult e)
|
||||
//{
|
||||
// DeviceSession ds = e.Device;
|
||||
// if (ds == null)
|
||||
// {
|
||||
// ds = await this.Sessions.StartSession<T>(e.DeviceId);
|
||||
// e.Device = ds;
|
||||
|
||||
// ds.LastMessage = e.Message;
|
||||
|
||||
// OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds));
|
||||
// }
|
||||
|
||||
// ds.LastAction = DateTime.Now;
|
||||
// ds.LastMessage = e.Message;
|
||||
|
||||
// //Is this a bot command ?
|
||||
// if (e.IsBotCommand && this.BotCommands.Count(a => "/" + a.Command == e.BotCommand) > 0)
|
||||
// {
|
||||
// var sce = new BotCommandEventArgs(e.BotCommand, e.BotCommandParameters, e.Message, ds.DeviceId, ds);
|
||||
// await OnBotCommand(sce);
|
||||
|
||||
// if (sce.Handled)
|
||||
// return;
|
||||
// }
|
||||
|
||||
// FormBase activeForm = null;
|
||||
|
||||
// int i = 0;
|
||||
|
||||
// //Should formulars get navigated (allow maximum of 10, to dont get loops)
|
||||
// do
|
||||
// {
|
||||
// i++;
|
||||
|
||||
// //Reset navigation
|
||||
// ds.FormSwitched = false;
|
||||
|
||||
// activeForm = ds.ActiveForm;
|
||||
|
||||
// //Pre Loading Event
|
||||
// await activeForm.PreLoad(e);
|
||||
|
||||
// //Send Load event to controls
|
||||
// await activeForm.LoadControls(e);
|
||||
|
||||
// //Loading Event
|
||||
// await activeForm.Load(e);
|
||||
|
||||
// //Is Attachment ? (Photo, Audio, Video, Contact, Location, Document)
|
||||
// if (e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Contact | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Document | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Location |
|
||||
// e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Photo | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Video | e.Message.Type == Telegram.Bot.Types.Enums.MessageType.Audio)
|
||||
// {
|
||||
// await activeForm.SentData(new DataResult(e));
|
||||
// }
|
||||
|
||||
// //Render Event
|
||||
// if (!ds.FormSwitched)
|
||||
// {
|
||||
// await activeForm.RenderControls(e);
|
||||
|
||||
// await activeForm.Render(e);
|
||||
// }
|
||||
|
||||
// e.IsFirstHandler = false;
|
||||
|
||||
// } while (ds.FormSwitched && i < this.GetSetting(eSettings.NavigationMaximum, 10));
|
||||
|
||||
|
||||
//}
|
||||
|
||||
private async Task Client_Loop(object sender, MessageResult e)
|
||||
{
|
||||
DeviceSession ds = e.Device;
|
||||
DeviceSession ds = this.Sessions.GetSession(e.DeviceId);
|
||||
if (ds == null)
|
||||
{
|
||||
ds = await this.Sessions.StartSession<T>(e.DeviceId);
|
||||
ds = Sessions.StartSession(e.DeviceId).GetAwaiter().GetResult();
|
||||
e.Device = ds;
|
||||
ds.LastMessage = e.Message;
|
||||
ds.LastMessage = e.RawData.Message;
|
||||
|
||||
OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds));
|
||||
}
|
||||
|
||||
ds.LastAction = DateTime.Now;
|
||||
ds.LastMessage = e.Message;
|
||||
|
||||
//Is this a bot command ?
|
||||
if (e.IsBotCommand && this.BotCommands.Count(a => "/" + a.Command == e.BotCommand) > 0)
|
||||
{
|
||||
var sce = new BotCommandEventArgs(e.BotCommand, e.BotCommandParameters, e.Message, ds.DeviceId, ds);
|
||||
await OnBotCommand(sce);
|
||||
|
||||
if (sce.Handled)
|
||||
return;
|
||||
}
|
||||
|
||||
FormBase activeForm = null;
|
||||
var mr = new MessageResult(e.RawData);
|
||||
|
||||
int i = 0;
|
||||
|
||||
@@ -356,65 +146,48 @@ namespace TelegramBotBase
|
||||
//Reset navigation
|
||||
ds.FormSwitched = false;
|
||||
|
||||
activeForm = ds.ActiveForm;
|
||||
|
||||
//Pre Loading Event
|
||||
await activeForm.PreLoad(e);
|
||||
|
||||
//Send Load event to controls
|
||||
await activeForm.LoadControls(e);
|
||||
|
||||
//Loading Event
|
||||
await activeForm.Load(e);
|
||||
|
||||
//Is Attachment ? (Photo, Audio, Video, Contact, Location, Document)
|
||||
if (e.MessageType == Telegram.Bot.Types.Enums.MessageType.Contact | e.MessageType == Telegram.Bot.Types.Enums.MessageType.Document | e.MessageType == Telegram.Bot.Types.Enums.MessageType.Location |
|
||||
e.MessageType == Telegram.Bot.Types.Enums.MessageType.Photo | e.MessageType == Telegram.Bot.Types.Enums.MessageType.Video | e.MessageType == Telegram.Bot.Types.Enums.MessageType.Audio)
|
||||
{
|
||||
await activeForm.SentData(new DataResult(e));
|
||||
}
|
||||
|
||||
//Action Event
|
||||
if (!ds.FormSwitched && e.IsAction)
|
||||
{
|
||||
//Send Action event to controls
|
||||
await activeForm.ActionControls(e);
|
||||
|
||||
//Send Action event to form itself
|
||||
await activeForm.Action(e);
|
||||
|
||||
if (!e.Handled)
|
||||
{
|
||||
var uhc = new UnhandledCallEventArgs(e.Message.Text, e.RawData, ds.DeviceId, e.MessageId, e.Message, ds);
|
||||
OnUnhandledCall(uhc);
|
||||
|
||||
if (uhc.Handled)
|
||||
{
|
||||
e.Handled = true;
|
||||
if (!ds.FormSwitched)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!ds.FormSwitched)
|
||||
{
|
||||
//Render Event
|
||||
await activeForm.RenderControls(e);
|
||||
|
||||
await activeForm.Render(e);
|
||||
}
|
||||
|
||||
e.IsFirstHandler = false;
|
||||
|
||||
} while (ds.FormSwitched && i < this.GetSetting(eSettings.NavigationMaximum, 10));
|
||||
await MessageLoopFactory.MessageLoop(this, ds, e, mr);
|
||||
|
||||
mr.IsFirstHandler = false;
|
||||
|
||||
} while (ds.FormSwitched && i < GetSetting(eSettings.NavigationMaximum, 10));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Stop your Bot
|
||||
/// </summary>
|
||||
public async Task Stop()
|
||||
{
|
||||
if (Client == null)
|
||||
return;
|
||||
|
||||
Client.MessageLoop -= Client_MessageLoop;
|
||||
|
||||
|
||||
Client.StopReceiving();
|
||||
|
||||
await Sessions.SaveSessionStates();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a message to all active Sessions.
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
public async Task SentToAll(String message)
|
||||
{
|
||||
if (Client == null)
|
||||
return;
|
||||
|
||||
foreach (var s in Sessions.SessionList)
|
||||
{
|
||||
await Client.TelegramClient.SendTextMessageAsync(s.Key, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This will invoke the full message loop for the device even when no "userevent" like message or action has been raised.
|
||||
/// </summary>
|
||||
@@ -423,6 +196,11 @@ namespace TelegramBotBase
|
||||
{
|
||||
var mr = new MessageResult();
|
||||
|
||||
mr.UpdateData = new Update()
|
||||
{
|
||||
Message = new Message()
|
||||
};
|
||||
|
||||
await InvokeMessageLoop(DeviceId, mr);
|
||||
}
|
||||
|
||||
@@ -438,7 +216,8 @@ namespace TelegramBotBase
|
||||
DeviceSession ds = this.Sessions.GetSession(DeviceId);
|
||||
e.Device = ds;
|
||||
|
||||
await Client_Loop(this, e);
|
||||
await MessageLoopFactory.MessageLoop(this, ds, new UpdateResult(e.UpdateData, ds), e);
|
||||
//await Client_Loop(this, e);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -447,162 +226,50 @@ namespace TelegramBotBase
|
||||
}
|
||||
}
|
||||
|
||||
private async void Client_MessageEdit(object sender, MessageResult e)
|
||||
|
||||
/// <summary>
|
||||
/// Will get invoke on an unhandled call.
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
public void MessageLoopFactory_UnhandledCall(object sender, UnhandledCallEventArgs e)
|
||||
{
|
||||
if (this.GetSetting(eSettings.SkipAllMessages, false))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
DeviceSession ds = this.Sessions.GetSession(e.DeviceId);
|
||||
e.Device = ds;
|
||||
|
||||
if (this.GetSetting(eSettings.LogAllMessages, false))
|
||||
{
|
||||
OnMessage(new MessageIncomeEventArgs(e.DeviceId, ds, e));
|
||||
}
|
||||
|
||||
//Call same, to handle received liked edited
|
||||
ds?.OnMessageReceived(new MessageReceivedEventArgs(e.Message));
|
||||
|
||||
await Client_TryMessageEdit(sender, e);
|
||||
}
|
||||
catch (Telegram.Bot.Exceptions.ApiRequestException ex)
|
||||
{
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DeviceSession ds = this.Sessions.GetSession(e.DeviceId);
|
||||
OnException(new SystemExceptionEventArgs(e.Message.Text, ds?.DeviceId ?? -1, ds, ex));
|
||||
}
|
||||
OnUnhandledCall(e);
|
||||
}
|
||||
|
||||
private async Task Client_TryMessageEdit(object sender, MessageResult e)
|
||||
{
|
||||
DeviceSession ds = e.Device;
|
||||
if (ds == null)
|
||||
{
|
||||
ds = await this.Sessions.StartSession<T>(e.DeviceId);
|
||||
e.Device = ds;
|
||||
}
|
||||
|
||||
ds.LastAction = DateTime.Now;
|
||||
ds.LastMessage = e.Message;
|
||||
|
||||
//Pre Loading Event
|
||||
await ds.ActiveForm.Edited(e);
|
||||
|
||||
//When form has been switched due navigation within the edit method, reopen Client_Message
|
||||
if (ds.FormSwitched)
|
||||
{
|
||||
await Client_Loop(sender, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private async void Client_Action(object sender, MessageResult e)
|
||||
{
|
||||
try
|
||||
{
|
||||
DeviceSession ds = this.Sessions.GetSession(e.DeviceId);
|
||||
e.Device = ds;
|
||||
|
||||
if (this.GetSetting(eSettings.LogAllMessages, false))
|
||||
{
|
||||
OnMessage(new MessageIncomeEventArgs(e.DeviceId, ds, e));
|
||||
}
|
||||
|
||||
await Client_Loop(sender, e);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DeviceSession ds = this.Sessions.GetSession(e.DeviceId);
|
||||
OnException(new SystemExceptionEventArgs(e.Message.Text, ds?.DeviceId ?? -1, ds, ex));
|
||||
}
|
||||
}
|
||||
|
||||
//private async void Client_TryAction(object sender, MessageResult e)
|
||||
//{
|
||||
// DeviceSession ds = e.Device;
|
||||
// if (ds == null)
|
||||
// {
|
||||
// ds = await this.Sessions.StartSession<T>(e.DeviceId);
|
||||
// e.Device = ds;
|
||||
// }
|
||||
|
||||
// ds.LastAction = DateTime.Now;
|
||||
// ds.LastMessage = e.Message;
|
||||
|
||||
// FormBase activeForm = null;
|
||||
|
||||
// int i = 0;
|
||||
|
||||
// //Should formulars get navigated (allow maximum of 10, to dont get loops)
|
||||
// do
|
||||
// {
|
||||
// i++;
|
||||
|
||||
// //Reset navigation
|
||||
// ds.FormSwitched = false;
|
||||
|
||||
// activeForm = ds.ActiveForm;
|
||||
|
||||
// //Pre Loading Event
|
||||
// await activeForm.PreLoad(e);
|
||||
|
||||
// //Send Load event to controls
|
||||
// await activeForm.LoadControls(e);
|
||||
|
||||
// //Loading Event
|
||||
// await activeForm.Load(e);
|
||||
|
||||
// //Action Event
|
||||
// if (!ds.FormSwitched)
|
||||
// {
|
||||
// //Send Action event to controls
|
||||
// await activeForm.ActionControls(e);
|
||||
|
||||
// //Send Action event to form itself
|
||||
// await activeForm.Action(e);
|
||||
|
||||
// if (!e.Handled)
|
||||
// {
|
||||
// var uhc = new UnhandledCallEventArgs(e.Message.Text, e.RawData, ds.DeviceId, e.MessageId, e.Message, ds);
|
||||
// OnUnhandledCall(uhc);
|
||||
|
||||
// if (uhc.Handled)
|
||||
// {
|
||||
// e.Handled = true;
|
||||
// if (!ds.FormSwitched)
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// //Render Event
|
||||
// if (!ds.FormSwitched)
|
||||
// {
|
||||
// await activeForm.RenderControls(e);
|
||||
|
||||
// await activeForm.Render(e);
|
||||
// }
|
||||
|
||||
// e.IsFirstHandler = false;
|
||||
|
||||
// } while (ds.FormSwitched && i < this.GetSetting(eSettings.NavigationMaximum, 10));
|
||||
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// This method will update all local created bot commands to the botfather.
|
||||
/// </summary>
|
||||
public async Task UploadBotCommands()
|
||||
{
|
||||
await this.Client.SetBotCommands(this.BotCommands);
|
||||
foreach (var bs in BotCommandScopes)
|
||||
{
|
||||
if (bs.Value != null)
|
||||
{
|
||||
await Client.SetBotCommands(bs.Value, bs.Key);
|
||||
}
|
||||
else
|
||||
{
|
||||
await Client.DeleteBotCommands(bs.Key);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searching if parameter is a known command in all configured BotCommandScopes.
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <returns></returns>
|
||||
public bool IsKnownBotCommand(String command)
|
||||
{
|
||||
foreach (var scope in BotCommandScopes)
|
||||
{
|
||||
if (scope.Value.Any(a => "/" + a.Command == command))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -612,7 +279,7 @@ namespace TelegramBotBase
|
||||
/// <param name="Value"></param>
|
||||
public void SetSetting(eSettings set, uint Value)
|
||||
{
|
||||
this.SystemSettings[set] = Value;
|
||||
SystemSettings[set] = Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -622,7 +289,7 @@ namespace TelegramBotBase
|
||||
/// <param name="Value"></param>
|
||||
public void SetSetting(eSettings set, bool Value)
|
||||
{
|
||||
this.SystemSettings[set] = (Value ? 1u : 0u);
|
||||
SystemSettings[set] = (Value ? 1u : 0u);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -633,10 +300,10 @@ namespace TelegramBotBase
|
||||
/// <returns></returns>
|
||||
public uint GetSetting(eSettings set, uint defaultValue)
|
||||
{
|
||||
if (!this.SystemSettings.ContainsKey(set))
|
||||
if (!SystemSettings.ContainsKey(set))
|
||||
return defaultValue;
|
||||
|
||||
return this.SystemSettings[set];
|
||||
return SystemSettings[set];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -647,10 +314,10 @@ namespace TelegramBotBase
|
||||
/// <returns></returns>
|
||||
public bool GetSetting(eSettings set, bool defaultValue)
|
||||
{
|
||||
if (!this.SystemSettings.ContainsKey(set))
|
||||
if (!SystemSettings.ContainsKey(set))
|
||||
return defaultValue;
|
||||
|
||||
return this.SystemSettings[set] == 0u ? false : true;
|
||||
return SystemSettings[set] == 0u ? false : true;
|
||||
}
|
||||
|
||||
#region "Events"
|
||||
@@ -663,17 +330,17 @@ namespace TelegramBotBase
|
||||
{
|
||||
add
|
||||
{
|
||||
this.__Events.AddHandler(__evSessionBegins, value);
|
||||
__events.AddHandler(__evSessionBegins, value);
|
||||
}
|
||||
remove
|
||||
{
|
||||
this.__Events.RemoveHandler(__evSessionBegins, value);
|
||||
__events.RemoveHandler(__evSessionBegins, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSessionBegins(SessionBeginEventArgs e)
|
||||
{
|
||||
(this.__Events[__evSessionBegins] as EventHandler<SessionBeginEventArgs>)?.Invoke(this, e);
|
||||
(__events[__evSessionBegins] as EventHandler<SessionBeginEventArgs>)?.Invoke(this, e);
|
||||
|
||||
}
|
||||
|
||||
@@ -684,17 +351,17 @@ namespace TelegramBotBase
|
||||
{
|
||||
add
|
||||
{
|
||||
this.__Events.AddHandler(__evMessage, value);
|
||||
__events.AddHandler(__evMessage, value);
|
||||
}
|
||||
remove
|
||||
{
|
||||
this.__Events.RemoveHandler(__evMessage, value);
|
||||
__events.RemoveHandler(__evMessage, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMessage(MessageIncomeEventArgs e)
|
||||
{
|
||||
(this.__Events[__evMessage] as EventHandler<MessageIncomeEventArgs>)?.Invoke(this, e);
|
||||
(__events[__evMessage] as EventHandler<MessageIncomeEventArgs>)?.Invoke(this, e);
|
||||
|
||||
}
|
||||
|
||||
@@ -706,7 +373,7 @@ namespace TelegramBotBase
|
||||
|
||||
public async Task OnBotCommand(BotCommandEventArgs e)
|
||||
{
|
||||
if (this.BotCommand != null)
|
||||
if (BotCommand != null)
|
||||
await BotCommand(this, e);
|
||||
}
|
||||
|
||||
@@ -717,17 +384,17 @@ namespace TelegramBotBase
|
||||
{
|
||||
add
|
||||
{
|
||||
this.__Events.AddHandler(__evException, value);
|
||||
__events.AddHandler(__evException, value);
|
||||
}
|
||||
remove
|
||||
{
|
||||
this.__Events.RemoveHandler(__evException, value);
|
||||
__events.RemoveHandler(__evException, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnException(SystemExceptionEventArgs e)
|
||||
{
|
||||
(this.__Events[__evException] as EventHandler<SystemExceptionEventArgs>)?.Invoke(this, e);
|
||||
(__events[__evException] as EventHandler<SystemExceptionEventArgs>)?.Invoke(this, e);
|
||||
|
||||
}
|
||||
|
||||
@@ -738,17 +405,17 @@ namespace TelegramBotBase
|
||||
{
|
||||
add
|
||||
{
|
||||
this.__Events.AddHandler(__evUnhandledCall, value);
|
||||
__events.AddHandler(__evUnhandledCall, value);
|
||||
}
|
||||
remove
|
||||
{
|
||||
this.__Events.RemoveHandler(__evUnhandledCall, value);
|
||||
__events.RemoveHandler(__evUnhandledCall, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnUnhandledCall(UnhandledCallEventArgs e)
|
||||
{
|
||||
(this.__Events[__evUnhandledCall] as EventHandler<UnhandledCallEventArgs>)?.Invoke(this, e);
|
||||
(__events[__evUnhandledCall] as EventHandler<UnhandledCallEventArgs>)?.Invoke(this, e);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,350 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Builder.Interfaces;
|
||||
using TelegramBotBase.Commands;
|
||||
using TelegramBotBase.Factories;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBase.Interfaces;
|
||||
using TelegramBotBase.Localizations;
|
||||
using TelegramBotBase.States;
|
||||
|
||||
namespace TelegramBotBase.Builder
|
||||
{
|
||||
public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage, IStartFormSelectionStage, IBuildingStage, INetworkingSelectionStage, IBotCommandsStage, ISessionSerializationStage, ILanguageSelectionStage
|
||||
{
|
||||
|
||||
String _apiKey = null;
|
||||
|
||||
IStartFormFactory _factory = null;
|
||||
|
||||
MessageClient _client = null;
|
||||
|
||||
/// <summary>
|
||||
/// Contains different Botcommands for different areas.
|
||||
/// </summary>
|
||||
Dictionary<BotCommandScope, List<BotCommand>> _BotCommandScopes { get; set; } = new Dictionary<BotCommandScope, List<BotCommand>>();
|
||||
|
||||
//List<BotCommand> _botcommands = new List<BotCommand>();
|
||||
|
||||
IStateMachine _statemachine = null;
|
||||
|
||||
IMessageLoopFactory _messageloopfactory = null;
|
||||
|
||||
private BotBaseBuilder()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static IAPIKeySelectionStage Create()
|
||||
{
|
||||
return new BotBaseBuilder();
|
||||
}
|
||||
|
||||
#region "Step 1 (Basic Stuff)"
|
||||
|
||||
public IMessageLoopSelectionStage WithAPIKey(string apiKey)
|
||||
{
|
||||
this._apiKey = apiKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public IBuildingStage QuickStart(string apiKey, Type StartForm)
|
||||
{
|
||||
this._apiKey = apiKey;
|
||||
this._factory = new Factories.DefaultStartFormFactory(StartForm);
|
||||
|
||||
DefaultMessageLoop();
|
||||
|
||||
NoProxy();
|
||||
|
||||
OnlyStart();
|
||||
|
||||
NoSerialization();
|
||||
|
||||
DefaultLanguage();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public IBuildingStage QuickStart<T>(string apiKey)
|
||||
where T : FormBase
|
||||
{
|
||||
this._apiKey = apiKey;
|
||||
this._factory = new Factories.DefaultStartFormFactory(typeof(T));
|
||||
|
||||
DefaultMessageLoop();
|
||||
|
||||
NoProxy();
|
||||
|
||||
OnlyStart();
|
||||
|
||||
NoSerialization();
|
||||
|
||||
DefaultLanguage();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public IBuildingStage QuickStart(string apiKey, IStartFormFactory StartFormFactory)
|
||||
{
|
||||
this._apiKey = apiKey;
|
||||
this._factory = StartFormFactory;
|
||||
|
||||
DefaultMessageLoop();
|
||||
|
||||
NoProxy();
|
||||
|
||||
OnlyStart();
|
||||
|
||||
NoSerialization();
|
||||
|
||||
DefaultLanguage();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region "Step 2 (Message Loop)"
|
||||
|
||||
public IStartFormSelectionStage DefaultMessageLoop()
|
||||
{
|
||||
_messageloopfactory = new MessageLoops.FormBaseMessageLoop();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public IStartFormSelectionStage MinimalMessageLoop()
|
||||
{
|
||||
_messageloopfactory = new MessageLoops.MinimalMessageLoop();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public IStartFormSelectionStage CustomMessageLoop(IMessageLoopFactory messageLoopClass)
|
||||
{
|
||||
_messageloopfactory = messageLoopClass;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public IStartFormSelectionStage CustomMessageLoop<T>()
|
||||
where T : class, new()
|
||||
{
|
||||
_messageloopfactory = typeof(T).GetConstructor(new Type[] { })?.Invoke(new object[] { }) as IMessageLoopFactory;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region "Step 3 (Start Form/Factory)"
|
||||
|
||||
public INetworkingSelectionStage WithStartForm(Type startFormClass)
|
||||
{
|
||||
this._factory = new Factories.DefaultStartFormFactory(startFormClass);
|
||||
return this;
|
||||
}
|
||||
|
||||
public INetworkingSelectionStage WithStartForm<T>()
|
||||
where T : FormBase, new()
|
||||
{
|
||||
this._factory = new Factories.DefaultStartFormFactory(typeof(T));
|
||||
return this;
|
||||
}
|
||||
|
||||
public INetworkingSelectionStage WithServiceProvider(Type startFormClass, IServiceProvider serviceProvider)
|
||||
{
|
||||
this._factory = new ServiceProviderStartFormFactory(startFormClass, serviceProvider);
|
||||
return this;
|
||||
}
|
||||
|
||||
public INetworkingSelectionStage WithServiceProvider<T>(IServiceProvider serviceProvider)
|
||||
where T : FormBase
|
||||
{
|
||||
this._factory = new ServiceProviderStartFormFactory<T>(serviceProvider);
|
||||
return this;
|
||||
}
|
||||
|
||||
public INetworkingSelectionStage WithStartFormFactory(IStartFormFactory factory)
|
||||
{
|
||||
this._factory = factory;
|
||||
return this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region "Step 4 (Network Settings)"
|
||||
|
||||
public IBotCommandsStage WithProxy(string proxyAddress)
|
||||
{
|
||||
var url = new Uri(proxyAddress);
|
||||
_client = new MessageClient(_apiKey, url);
|
||||
_client.TelegramClient.Timeout = new TimeSpan(0, 1, 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public IBotCommandsStage NoProxy()
|
||||
{
|
||||
_client = new MessageClient(_apiKey);
|
||||
_client.TelegramClient.Timeout = new TimeSpan(0, 1, 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public IBotCommandsStage WithBotClient(TelegramBotClient tgclient)
|
||||
{
|
||||
_client = new MessageClient(_apiKey, tgclient);
|
||||
_client.TelegramClient.Timeout = new TimeSpan(0, 1, 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public IBotCommandsStage WithHostAndPort(string proxyHost, int proxyPort)
|
||||
{
|
||||
_client = new MessageClient(_apiKey, proxyHost, proxyPort);
|
||||
_client.TelegramClient.Timeout = new TimeSpan(0, 1, 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IBotCommandsStage WithHttpClient(HttpClient tgclient)
|
||||
{
|
||||
_client = new MessageClient(_apiKey, tgclient);
|
||||
_client.TelegramClient.Timeout = new TimeSpan(0, 1, 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region "Step 5 (Bot Commands)"
|
||||
|
||||
public ISessionSerializationStage NoCommands()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISessionSerializationStage OnlyStart()
|
||||
{
|
||||
_BotCommandScopes.Start("Starts the bot");
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public ISessionSerializationStage DefaultCommands()
|
||||
{
|
||||
_BotCommandScopes.Start("Starts the bot");
|
||||
_BotCommandScopes.Help("Should show you some help");
|
||||
_BotCommandScopes.Settings("Should show you some settings");
|
||||
return this;
|
||||
}
|
||||
|
||||
public ISessionSerializationStage CustomCommands(Action<Dictionary<BotCommandScope, List<BotCommand>>> action)
|
||||
{
|
||||
action?.Invoke(_BotCommandScopes);
|
||||
return this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region "Step 6 (Serialization)"
|
||||
|
||||
public ILanguageSelectionStage NoSerialization()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public ILanguageSelectionStage UseSerialization(IStateMachine machine)
|
||||
{
|
||||
this._statemachine = machine;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public ILanguageSelectionStage UseJSON(string path)
|
||||
{
|
||||
this._statemachine = new JSONStateMachine(path);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ILanguageSelectionStage UseSimpleJSON(string path)
|
||||
{
|
||||
this._statemachine = new SimpleJSONStateMachine(path);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ILanguageSelectionStage UseXML(string path)
|
||||
{
|
||||
this._statemachine = new XMLStateMachine(path);
|
||||
return this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region "Step 7 (Language)"
|
||||
|
||||
public IBuildingStage DefaultLanguage()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public IBuildingStage UseEnglish()
|
||||
{
|
||||
Localizations.Default.Language = new Localizations.English();
|
||||
return this;
|
||||
}
|
||||
|
||||
public IBuildingStage UseGerman()
|
||||
{
|
||||
Localizations.Default.Language = new Localizations.German();
|
||||
return this;
|
||||
}
|
||||
|
||||
public IBuildingStage Custom(Localization language)
|
||||
{
|
||||
Localizations.Default.Language = language;
|
||||
return this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public BotBase Build()
|
||||
{
|
||||
var bb = new BotBase();
|
||||
|
||||
bb.APIKey = _apiKey;
|
||||
bb.StartFormFactory = _factory;
|
||||
|
||||
bb.Client = _client;
|
||||
|
||||
bb.BotCommandScopes = _BotCommandScopes;
|
||||
|
||||
bb.StateMachine = _statemachine;
|
||||
|
||||
bb.MessageLoopFactory = _messageloopfactory;
|
||||
|
||||
bb.MessageLoopFactory.UnhandledCall += bb.MessageLoopFactory_UnhandledCall;
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBase.Interfaces;
|
||||
|
||||
namespace TelegramBotBase.Builder.Interfaces
|
||||
{
|
||||
public interface IAPIKeySelectionStage
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the API Key which will be used by the telegram bot client.
|
||||
/// </summary>
|
||||
/// <param name="apiKey"></param>
|
||||
/// <returns></returns>
|
||||
IMessageLoopSelectionStage WithAPIKey(String apiKey);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Quick and easy way to create a BotBase instance.
|
||||
/// Uses: DefaultMessageLoop, NoProxy, OnlyStart, NoSerialization, DefaultLanguage
|
||||
/// </summary>
|
||||
/// <param name="apiKey"></param>
|
||||
/// <param name="StartForm"></param>
|
||||
/// <returns></returns>
|
||||
IBuildingStage QuickStart(String apiKey, Type StartForm);
|
||||
|
||||
/// <summary>
|
||||
/// Quick and easy way to create a BotBase instance.
|
||||
/// Uses: DefaultMessageLoop, NoProxy, OnlyStart, NoSerialization, DefaultLanguage
|
||||
/// </summary>
|
||||
/// <param name="apiKey"></param>
|
||||
/// <returns></returns>
|
||||
IBuildingStage QuickStart<T>(String apiKey) where T : FormBase;
|
||||
|
||||
/// <summary>
|
||||
/// Quick and easy way to create a BotBase instance.
|
||||
/// Uses: DefaultMessageLoop, NoProxy, OnlyStart, NoSerialization, DefaultLanguage
|
||||
/// </summary>
|
||||
/// <param name="apiKey"></param>
|
||||
/// <param name="StartFormFactory"></param>
|
||||
/// <returns></returns>
|
||||
IBuildingStage QuickStart(String apiKey, IStartFormFactory StartFormFactory);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace TelegramBotBase.Builder.Interfaces
|
||||
{
|
||||
public interface IBotCommandsStage
|
||||
{
|
||||
/// <summary>
|
||||
/// Does not create any commands.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
ISessionSerializationStage NoCommands();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates default commands for start, help and settings.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
ISessionSerializationStage DefaultCommands();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Only adds the start command.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
ISessionSerializationStage OnlyStart();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gives you the ability to add custom commands.
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
ISessionSerializationStage CustomCommands(Action<Dictionary<BotCommandScope, List<BotCommand>>> action);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace TelegramBotBase.Builder.Interfaces
|
||||
{
|
||||
public interface IBuildingStage
|
||||
{
|
||||
BotBase Build();
|
||||
}
|
||||
}
|
||||