fix: reformat using C# rules
This commit is contained in:
parent
a731e2a8d0
commit
5ab15621a0
@ -10,11 +10,13 @@
|
||||
<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" />
|
||||
<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" />
|
||||
<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>
|
||||
@ -30,19 +32,23 @@
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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>
|
||||
@ -50,19 +56,23 @@
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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>
|
||||
@ -74,7 +84,8 @@
|
||||
<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" />
|
||||
<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>
|
||||
@ -82,31 +93,38 @@
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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>
|
||||
@ -118,7 +136,8 @@
|
||||
<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" />
|
||||
<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>
|
||||
@ -126,11 +145,13 @@
|
||||
<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" />
|
||||
<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" />
|
||||
<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>
|
||||
@ -138,7 +159,8 @@
|
||||
<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" />
|
||||
<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>
|
||||
@ -174,7 +196,8 @@
|
||||
<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" />
|
||||
<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>
|
||||
@ -202,7 +225,8 @@
|
||||
<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" />
|
||||
<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>
|
||||
@ -210,7 +234,8 @@
|
||||
<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" />
|
||||
<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>
|
||||
@ -222,15 +247,18 @@
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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>
|
||||
@ -242,7 +270,8 @@
|
||||
<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" />
|
||||
<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>
|
||||
@ -250,11 +279,13 @@
|
||||
<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" />
|
||||
<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" />
|
||||
<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>
|
||||
@ -262,23 +293,28 @@
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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>
|
||||
@ -286,23 +322,28 @@
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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" />
|
||||
<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>
|
||||
@ -310,11 +351,13 @@
|
||||
<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" />
|
||||
<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" />
|
||||
<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>
|
||||
@ -326,7 +369,8 @@
|
||||
<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" />
|
||||
<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>
|
||||
@ -334,11 +378,13 @@
|
||||
<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" />
|
||||
<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" />
|
||||
<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>
|
||||
@ -346,7 +392,8 @@
|
||||
<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" />
|
||||
<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>
|
||||
@ -370,7 +417,8 @@
|
||||
<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" />
|
||||
<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>
|
||||
|
||||
@ -33,17 +33,17 @@ namespace AsyncFormUpdates
|
||||
|
||||
private static async void Timer_Elapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
|
||||
foreach (var s in __bot.Sessions.SessionList)
|
||||
{
|
||||
//Only for AsyncUpdateForm
|
||||
if (s.Value.ActiveForm.GetType() != typeof(AsyncFormUpdate) && s.Value.ActiveForm.GetType() != typeof(AsyncFormEdit))
|
||||
if (s.Value.ActiveForm.GetType() != typeof(AsyncFormUpdate) &&
|
||||
s.Value.ActiveForm.GetType() != typeof(AsyncFormEdit))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
await __bot.InvokeMessageLoop(s.Key);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -46,8 +46,6 @@ namespace AsyncFormUpdates.forms
|
||||
var m = await Device.Send($"Your current count is at: {_counter}", bf, disableNotification: true);
|
||||
_messageId = m.MessageId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -38,7 +38,5 @@ namespace AsyncFormUpdates.forms
|
||||
|
||||
await Device.Send($"Your current count is at: {_counter}", bf, disableNotification: true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -6,8 +6,6 @@ namespace AsyncFormUpdates.forms
|
||||
{
|
||||
public class Start : AutoCleanForm
|
||||
{
|
||||
|
||||
|
||||
public override async Task Action(MessageResult message)
|
||||
{
|
||||
await message.ConfirmAction();
|
||||
@ -30,7 +28,6 @@ namespace AsyncFormUpdates.forms
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override async Task Render(MessageResult message)
|
||||
@ -43,6 +40,5 @@ namespace AsyncFormUpdates.forms
|
||||
|
||||
await Device.Send("Choose your option", bf);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -10,7 +10,8 @@ var serviceCollection = new ServiceCollection()
|
||||
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
var bot = BotBaseBuilder.Create()
|
||||
.WithAPIKey(Environment.GetEnvironmentVariable("API_KEY") ?? throw new Exception("API_KEY is not set"))
|
||||
.WithAPIKey(Environment.GetEnvironmentVariable("API_KEY") ??
|
||||
throw new Exception("API_KEY is not set"))
|
||||
.DefaultMessageLoop()
|
||||
.WithServiceProvider<StartForm>(serviceProvider)
|
||||
.NoProxy()
|
||||
|
||||
@ -2,13 +2,12 @@
|
||||
using JoinHiderBot.forms;
|
||||
using TelegramBotBase.Builder;
|
||||
|
||||
namespace JoinHiderBot
|
||||
{
|
||||
namespace JoinHiderBot;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
|
||||
var apiKey = "";
|
||||
|
||||
var bot = BotBaseBuilder.Create()
|
||||
@ -20,4 +19,3 @@ namespace JoinHiderBot
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,21 +3,20 @@ using Telegram.Bot.Types.Enums;
|
||||
using TelegramBotBase.Args;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace JoinHiderBot.forms
|
||||
{
|
||||
namespace JoinHiderBot.forms;
|
||||
|
||||
public class GroupManageForm : GroupForm
|
||||
{
|
||||
|
||||
public override async Task OnMemberChanges(MemberChangeEventArgs e)
|
||||
{
|
||||
if (e.Type != MessageType.ChatMembersAdded && e.Type != MessageType.ChatMemberLeft)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var m = e.Result.Message;
|
||||
|
||||
await Device.DeleteMessage(m);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -2,8 +2,8 @@
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace JoinHiderBot.forms
|
||||
{
|
||||
namespace JoinHiderBot.forms;
|
||||
|
||||
public class Start : SplitterForm
|
||||
{
|
||||
public override async Task<bool> Open(MessageResult e)
|
||||
@ -21,6 +21,4 @@ namespace JoinHiderBot.forms
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -3,8 +3,8 @@ using SystemCommandsBot.config;
|
||||
using SystemCommandsBot.forms;
|
||||
using TelegramBotBase.Builder;
|
||||
|
||||
namespace SystemCommandsBot
|
||||
{
|
||||
namespace SystemCommandsBot;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
public static Config BotConfig { get; set; }
|
||||
@ -12,7 +12,6 @@ namespace SystemCommandsBot
|
||||
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
|
||||
BotConfig = Config.Load();
|
||||
|
||||
if (BotConfig.ApiKey == null || BotConfig.ApiKey.Trim() == "")
|
||||
@ -34,8 +33,5 @@ namespace SystemCommandsBot
|
||||
|
||||
|
||||
bot.Stop();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
namespace SystemCommandsBot.commands
|
||||
{
|
||||
namespace SystemCommandsBot.commands;
|
||||
|
||||
public class Commando
|
||||
{
|
||||
public int Id { get; set; }
|
||||
@ -17,9 +17,5 @@
|
||||
|
||||
public int? MaxInstances { get; set; }
|
||||
|
||||
public string ProcName
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
}
|
||||
public string ProcName { get; set; }
|
||||
}
|
||||
@ -4,26 +4,28 @@ using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using SystemCommandsBot.commands;
|
||||
|
||||
namespace SystemCommandsBot.config
|
||||
{
|
||||
namespace SystemCommandsBot.config;
|
||||
|
||||
public class Config
|
||||
{
|
||||
public Config()
|
||||
{
|
||||
Commandos = new List<Commando>();
|
||||
}
|
||||
|
||||
public string Password { get; set; }
|
||||
|
||||
public string ApiKey { get; set; }
|
||||
|
||||
public List<Commando> Commandos { get; set; }
|
||||
|
||||
|
||||
public Config()
|
||||
{
|
||||
Commandos = new List<Commando>();
|
||||
}
|
||||
|
||||
public void LoadDefaultValues()
|
||||
{
|
||||
ApiKey = "";
|
||||
Commandos.Add(new Commando { Id = 0, Enabled = true, Title = "Test Befehl", ShellCmd = "explorer.exe", Action = "start", MaxInstances = 2 });
|
||||
Commandos.Add(new Commando
|
||||
{
|
||||
Id = 0, Enabled = true, Title = "Test Befehl", ShellCmd = "explorer.exe", Action = "start", MaxInstances = 2
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -32,13 +34,12 @@ namespace SystemCommandsBot.config
|
||||
try
|
||||
{
|
||||
return Load(AppContext.BaseDirectory + "config\\default.cfg");
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -75,6 +76,7 @@ namespace SystemCommandsBot.config
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -86,8 +88,6 @@ namespace SystemCommandsBot.config
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,8 +6,8 @@ using System.Threading.Tasks;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace SystemCommandsBot.forms
|
||||
{
|
||||
namespace SystemCommandsBot.forms;
|
||||
|
||||
public class CmdForm : AutoCleanForm
|
||||
{
|
||||
public DateTime ExpiresAt { get; set; }
|
||||
@ -27,7 +27,6 @@ namespace SystemCommandsBot.forms
|
||||
|
||||
if (!int.TryParse(btn, out id))
|
||||
{
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -48,7 +47,6 @@ namespace SystemCommandsBot.forms
|
||||
|
||||
if (cmd.MaxInstances != null && cmd.MaxInstances >= 0)
|
||||
{
|
||||
|
||||
if (Process.GetProcessesByName(cmd.ProcName).Count() >= cmd.MaxInstances)
|
||||
{
|
||||
await Device.Send("Anwendung läuft bereits.");
|
||||
@ -56,7 +54,6 @@ namespace SystemCommandsBot.forms
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var psi = new ProcessStartInfo
|
||||
@ -90,7 +87,6 @@ namespace SystemCommandsBot.forms
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,7 +112,6 @@ namespace SystemCommandsBot.forms
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,30 +138,19 @@ namespace SystemCommandsBot.forms
|
||||
await message.ConfirmAction();
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override async Task Render(MessageResult message)
|
||||
{
|
||||
if (MessageId == null)
|
||||
{
|
||||
var buttons = Program.BotConfig.Commandos.Where(a => a.Enabled).Select(a => new ButtonBase(a.Title, a.Id.ToString()));
|
||||
var buttons = Program.BotConfig.Commandos.Where(a => a.Enabled)
|
||||
.Select(a => new ButtonBase(a.Title, a.Id.ToString()));
|
||||
|
||||
var bf = new ButtonForm();
|
||||
bf.AddSplitted(buttons, 1);
|
||||
await Device.Send("Deine Optionen", bf);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -3,8 +3,8 @@ using System.Threading.Tasks;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace SystemCommandsBot.forms
|
||||
{
|
||||
namespace SystemCommandsBot.forms;
|
||||
|
||||
public class StartForm : FormBase
|
||||
{
|
||||
public string Password { get; set; }
|
||||
@ -34,8 +34,5 @@ namespace SystemCommandsBot.forms
|
||||
cmd.ExpiresAt = DateTime.Now.AddDays(14);
|
||||
|
||||
await NavigateTo(cmd);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -28,13 +28,15 @@ namespace TelegramBotBase.Extensions.Images
|
||||
/// <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)
|
||||
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))
|
||||
{
|
||||
var fts = new InputOnlineFile(fileStream, name);
|
||||
|
||||
return await session.SendPhoto(fts, caption: caption, buttons, replyTo, disableNotification);
|
||||
return await session.SendPhoto(fts, caption, buttons, replyTo, disableNotification);
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,13 +49,15 @@ namespace TelegramBotBase.Extensions.Images
|
||||
/// <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)
|
||||
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))
|
||||
{
|
||||
var fts = new InputOnlineFile(fileStream, name);
|
||||
|
||||
return await session.SendPhoto(fts, caption: caption, buttons, replyTo, disableNotification);
|
||||
return await session.SendPhoto(fts, caption, buttons, replyTo, disableNotification);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,5 @@
|
||||
[](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)
|
||||
|
||||
@ -6,7 +6,6 @@ namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
||||
{
|
||||
public static class BotBaseBuilderExtensions
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Uses an Microsoft SQL Server Database to save and restore sessions.
|
||||
/// </summary>
|
||||
@ -15,7 +14,9 @@ namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
||||
/// <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_")
|
||||
public static ILanguageSelectionStage UseSqlDatabase(this ISessionSerializationStage builder,
|
||||
string connectionString, Type fallbackForm = null,
|
||||
string tablePrefix = "tgb_")
|
||||
{
|
||||
var serializer = new MssqlSerializer(connectionString, tablePrefix, fallbackForm);
|
||||
|
||||
@ -36,9 +37,12 @@ namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
||||
/// <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_")
|
||||
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 connectionString =
|
||||
$"Server={hostOrIP}; Database={databaseName}; User Id={userId}; Password={password}; TrustServerCertificate=true;";
|
||||
|
||||
var serializer = new MssqlSerializer(connectionString, tablePrefix, fallbackForm);
|
||||
|
||||
@ -56,12 +60,17 @@ namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
||||
/// <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_")
|
||||
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 connectionString =
|
||||
$"Server={hostOrIP}; Database={databaseName}; Integrated Security=true; TrustServerCertificate=true;";
|
||||
|
||||
var serializer = new MssqlSerializer(connectionString, tablePrefix, fallbackForm);
|
||||
|
||||
|
||||
@ -11,19 +11,19 @@ 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="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)
|
||||
{
|
||||
this.ConnectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
|
||||
ConnectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
|
||||
|
||||
TablePrefix = tablePrefix;
|
||||
|
||||
@ -35,6 +35,10 @@ namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
||||
}
|
||||
}
|
||||
|
||||
public string ConnectionString { get; }
|
||||
public string TablePrefix { get; set; }
|
||||
public Type FallbackStateForm { get; set; }
|
||||
|
||||
public StateContainer LoadFormStates()
|
||||
{
|
||||
var sc = new StateContainer();
|
||||
@ -44,7 +48,8 @@ namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
||||
connection.Open();
|
||||
|
||||
var command = connection.CreateCommand();
|
||||
command.CommandText = "SELECT deviceId, deviceTitle, FormUri, QualifiedName FROM " + TablePrefix + "devices_sessions";
|
||||
command.CommandText = "SELECT deviceId, deviceTitle, FormUri, QualifiedName FROM " + TablePrefix +
|
||||
"devices_sessions";
|
||||
|
||||
var dataTable = new DataTable();
|
||||
using (var dataAdapter = new SqlDataAdapter(command))
|
||||
@ -73,7 +78,8 @@ namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
||||
}
|
||||
|
||||
var command2 = connection.CreateCommand();
|
||||
command2.CommandText = "SELECT [key], value, type FROM " + TablePrefix + "devices_sessions_data WHERE deviceId = @deviceId";
|
||||
command2.CommandText = "SELECT [key], value, type FROM " + TablePrefix +
|
||||
"devices_sessions_data WHERE deviceId = @deviceId";
|
||||
command2.Parameters.Add(new SqlParameter("@deviceId", r["deviceId"]));
|
||||
|
||||
var dataTable2 = new DataTable();
|
||||
@ -91,13 +97,10 @@ namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
||||
se.Values.Add(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
connection.Close();
|
||||
}
|
||||
|
||||
@ -127,13 +130,15 @@ namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
||||
var sessionCommand = connection.CreateCommand();
|
||||
var dataCommand = connection.CreateCommand();
|
||||
|
||||
sessionCommand.CommandText = "INSERT INTO " + TablePrefix + "devices_sessions (deviceId, deviceTitle, FormUri, QualifiedName) VALUES (@deviceId, @deviceTitle, @FormUri, @QualifiedName)";
|
||||
sessionCommand.CommandText = "INSERT INTO " + TablePrefix +
|
||||
"devices_sessions (deviceId, deviceTitle, FormUri, QualifiedName) VALUES (@deviceId, @deviceTitle, @FormUri, @QualifiedName)";
|
||||
sessionCommand.Parameters.Add(new SqlParameter("@deviceId", ""));
|
||||
sessionCommand.Parameters.Add(new SqlParameter("@deviceTitle", ""));
|
||||
sessionCommand.Parameters.Add(new SqlParameter("@FormUri", ""));
|
||||
sessionCommand.Parameters.Add(new SqlParameter("@QualifiedName", ""));
|
||||
|
||||
dataCommand.CommandText = "INSERT INTO " + TablePrefix + "devices_sessions_data (deviceId, [key], value, type) VALUES (@deviceId, @key, @value, @type)";
|
||||
dataCommand.CommandText = "INSERT INTO " + TablePrefix +
|
||||
"devices_sessions_data (deviceId, [key], value, type) VALUES (@deviceId, @key, @value, @type)";
|
||||
dataCommand.Parameters.Add(new SqlParameter("@deviceId", ""));
|
||||
dataCommand.Parameters.Add(new SqlParameter("@key", ""));
|
||||
dataCommand.Parameters.Add(new SqlParameter("@value", ""));
|
||||
@ -169,13 +174,10 @@ namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
||||
|
||||
dataCommand.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
connection.Close();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,6 @@
|
||||
[](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)
|
||||
|
||||
|
||||
@ -1,37 +1,81 @@
|
||||
USE [telegram_bot]
|
||||
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,
|
||||
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]
|
||||
[
|
||||
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
|
||||
SET ANSI_NULLS
|
||||
ON
|
||||
GO
|
||||
SET QUOTED_IDENTIFIER ON
|
||||
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,
|
||||
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]
|
||||
[
|
||||
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
|
||||
|
||||
@ -7,13 +7,12 @@ using TelegramBotBase.Commands;
|
||||
using TelegramBotBase.Enums;
|
||||
using TelegramBotBaseTest.Tests;
|
||||
|
||||
namespace TelegramBotBaseTest
|
||||
{
|
||||
namespace TelegramBotBaseTest;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
|
||||
var apiKey = "";
|
||||
|
||||
var bb = BotBaseBuilder
|
||||
@ -59,7 +58,6 @@ namespace TelegramBotBaseTest
|
||||
Console.ReadLine();
|
||||
|
||||
bb.Stop();
|
||||
|
||||
}
|
||||
|
||||
private static async Task Bb_BotCommand(object sender, BotCommandEventArgs en)
|
||||
@ -112,4 +110,3 @@ namespace TelegramBotBaseTest
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFrameworks>netcoreapp3.1;net5;net6</TargetFrameworks>
|
||||
<LangVersion>10</LangVersion>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<Configurations>Debug;Release</Configurations>
|
||||
</PropertyGroup>
|
||||
|
||||
@ -3,11 +3,10 @@ using System.Threading.Tasks;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests;
|
||||
|
||||
public class ButtonTestForm : AutoCleanForm
|
||||
{
|
||||
|
||||
public ButtonTestForm()
|
||||
{
|
||||
Opened += ButtonTestForm_Opened;
|
||||
@ -20,14 +19,15 @@ namespace TelegramBotBaseTest.Tests
|
||||
|
||||
public override async Task Action(MessageResult message)
|
||||
{
|
||||
|
||||
var call = message.GetData<CallbackData>();
|
||||
|
||||
await message.ConfirmAction();
|
||||
|
||||
|
||||
if (call == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
message.Handled = true;
|
||||
|
||||
@ -71,29 +71,24 @@ namespace TelegramBotBaseTest.Tests
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override async Task Render(MessageResult message)
|
||||
{
|
||||
|
||||
var btn = new ButtonForm();
|
||||
|
||||
btn.AddButtonRow(new ButtonBase("Button 1", new CallbackData("a", "button1").Serialize()), new ButtonBase("Button 2", new CallbackData("a", "button2").Serialize()));
|
||||
btn.AddButtonRow(new ButtonBase("Button 1", new CallbackData("a", "button1").Serialize()),
|
||||
new ButtonBase("Button 2", new CallbackData("a", "button2").Serialize()));
|
||||
|
||||
btn.AddButtonRow(new ButtonBase("Button 3", new CallbackData("a", "button3").Serialize()), new ButtonBase("Button 4", new CallbackData("a", "button4").Serialize()));
|
||||
btn.AddButtonRow(new ButtonBase("Button 3", new CallbackData("a", "button3").Serialize()),
|
||||
new ButtonBase("Button 4", new CallbackData("a", "button4").Serialize()));
|
||||
|
||||
btn.AddButtonRow(new ButtonBase("Google.com", "google", "https://www.google.com"), new ButtonBase("Telegram", "telegram", "https://telegram.org/"));
|
||||
btn.AddButtonRow(new ButtonBase("Google.com", "google", "https://www.google.com"),
|
||||
new ButtonBase("Telegram", "telegram", "https://telegram.org/"));
|
||||
|
||||
btn.AddButtonRow(new ButtonBase("Back", new CallbackData("a", "back").Serialize()));
|
||||
|
||||
await Device.Send("Click a button", btn);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -4,8 +4,8 @@ using TelegramBotBase.Controls.Hybrid;
|
||||
using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Controls
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Controls;
|
||||
|
||||
public class ButtonGridForm : AutoCleanForm
|
||||
{
|
||||
private ButtonGrid _mButtons;
|
||||
@ -43,7 +43,9 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
private async Task Bg_ButtonClicked(object sender, ButtonClickedEventArgs e)
|
||||
{
|
||||
if (e.Button == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.Button.Value == "back")
|
||||
{
|
||||
@ -61,11 +63,7 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
await Device.Send($"Button clicked with Text: {e.Button.Text} and Value {e.Button.Value}");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,8 +6,8 @@ using TelegramBotBase.Controls.Hybrid;
|
||||
using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Controls
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Controls;
|
||||
|
||||
public class ButtonGridPagingForm : AutoCleanForm
|
||||
{
|
||||
private ButtonGrid _mButtons;
|
||||
@ -26,7 +26,7 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
KeyboardType = EKeyboardType.ReplyKeyboard,
|
||||
EnablePaging = true,
|
||||
EnableSearch = true,
|
||||
HeadLayoutButtonRow = new List<ButtonBase> { new ButtonBase("Back", "back") }
|
||||
HeadLayoutButtonRow = new List<ButtonBase> { new("Back", "back") }
|
||||
};
|
||||
|
||||
var countries = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
|
||||
@ -49,7 +49,9 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
private async Task Bg_ButtonClicked(object sender, ButtonClickedEventArgs e)
|
||||
{
|
||||
if (e.Button == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.Button.Value == "back")
|
||||
{
|
||||
@ -58,11 +60,7 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
await Device.Send($"Button clicked with Text: {e.Button.Text} and Value {e.Button.Value}");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -8,8 +8,8 @@ using TelegramBotBase.DataSources;
|
||||
using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Controls
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Controls;
|
||||
|
||||
public class ButtonGridTagForm : AutoCleanForm
|
||||
{
|
||||
private TaggedButtonGrid _mButtons;
|
||||
@ -27,7 +27,7 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
{
|
||||
KeyboardType = EKeyboardType.ReplyKeyboard,
|
||||
EnablePaging = true,
|
||||
HeadLayoutButtonRow = new List<ButtonBase> { new ButtonBase("Back", "back") }
|
||||
HeadLayoutButtonRow = new List<ButtonBase> { new("Back", "back") }
|
||||
};
|
||||
|
||||
|
||||
@ -56,20 +56,19 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
private async Task Bg_ButtonClicked(object sender, ButtonClickedEventArgs e)
|
||||
{
|
||||
if (e.Button == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (e.Button.Value)
|
||||
{
|
||||
|
||||
case "back":
|
||||
var start = new Menu();
|
||||
await NavigateTo(start);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
await Device.Send($"Button clicked with Text: {e.Button.Text} and Value {e.Button.Value}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,21 +5,20 @@ using TelegramBotBase.Controls.Inline;
|
||||
using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Controls
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Controls;
|
||||
|
||||
public class CalendarPickerForm : AutoCleanForm
|
||||
{
|
||||
|
||||
public CalendarPicker Picker { get; set; }
|
||||
|
||||
private int? SelectedDateMessage { get; set; }
|
||||
|
||||
public CalendarPickerForm()
|
||||
{
|
||||
DeleteMode = EDeleteMode.OnLeavingForm;
|
||||
Init += CalendarPickerForm_Init;
|
||||
}
|
||||
|
||||
public CalendarPicker Picker { get; set; }
|
||||
|
||||
private int? SelectedDateMessage { get; set; }
|
||||
|
||||
private Task CalendarPickerForm_Init(object sender, InitEventArgs e)
|
||||
{
|
||||
Picker = new CalendarPicker
|
||||
@ -34,7 +33,6 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
|
||||
public override async Task Action(MessageResult message)
|
||||
{
|
||||
|
||||
switch (message.RawData)
|
||||
{
|
||||
case "back":
|
||||
@ -45,7 +43,6 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override async Task Render(MessageResult message)
|
||||
@ -68,12 +65,5 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
var m = await Device.Send(s, bf);
|
||||
SelectedDateMessage = m.MessageId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -6,8 +6,8 @@ using TelegramBotBase.DataSources;
|
||||
using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Controls
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Controls;
|
||||
|
||||
public class CheckedButtonListForm : AutoCleanForm
|
||||
{
|
||||
private CheckedButtonList _mButtons;
|
||||
@ -25,8 +25,8 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
{
|
||||
KeyboardType = EKeyboardType.InlineKeyBoard,
|
||||
EnablePaging = true,
|
||||
HeadLayoutButtonRow = new List<ButtonBase> { new ButtonBase("Back", "back"), new ButtonBase("Switch Keyboard", "switch") },
|
||||
SubHeadLayoutButtonRow = new List<ButtonBase> { new ButtonBase("No checked items", "$") }
|
||||
HeadLayoutButtonRow = new List<ButtonBase> { new("Back", "back"), new("Switch Keyboard", "switch") },
|
||||
SubHeadLayoutButtonRow = new List<ButtonBase> { new("No checked items", "$") }
|
||||
};
|
||||
|
||||
var bf = new ButtonForm();
|
||||
@ -47,14 +47,17 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
|
||||
private Task M_Buttons_CheckedChanged(object sender, CheckedChangedEventArgs e)
|
||||
{
|
||||
_mButtons.SubHeadLayoutButtonRow = new List<ButtonBase> { new ButtonBase($"{_mButtons.CheckedItems.Count} checked items", "$") };
|
||||
_mButtons.SubHeadLayoutButtonRow = new List<ButtonBase>
|
||||
{ new($"{_mButtons.CheckedItems.Count} checked items", "$") };
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task Bg_ButtonClicked(object sender, ButtonClickedEventArgs e)
|
||||
{
|
||||
if (e.Button == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (e.Button.Value)
|
||||
{
|
||||
@ -79,8 +82,5 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
await Device.Send($"Button clicked with Text: {e.Button.Text} and Value {e.Button.Value}");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,21 +5,20 @@ using TelegramBotBase.Controls.Inline;
|
||||
using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Controls
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Controls;
|
||||
|
||||
public class MonthPickerForm : AutoCleanForm
|
||||
{
|
||||
|
||||
public MonthPicker Picker { get; set; }
|
||||
|
||||
private int? SelectedDateMessage { get; set; }
|
||||
|
||||
public MonthPickerForm()
|
||||
{
|
||||
DeleteMode = EDeleteMode.OnLeavingForm;
|
||||
Init += MonthPickerForm_Init;
|
||||
}
|
||||
|
||||
public MonthPicker Picker { get; set; }
|
||||
|
||||
private int? SelectedDateMessage { get; set; }
|
||||
|
||||
private Task MonthPickerForm_Init(object sender, InitEventArgs e)
|
||||
{
|
||||
Picker = new MonthPicker
|
||||
@ -33,7 +32,6 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
|
||||
public override async Task Action(MessageResult message)
|
||||
{
|
||||
|
||||
switch (message.RawData)
|
||||
{
|
||||
case "back":
|
||||
@ -44,7 +42,6 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override async Task Render(MessageResult message)
|
||||
@ -66,12 +63,5 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
var m = await Device.Send(s, bf);
|
||||
SelectedDateMessage = m.MessageId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -7,8 +7,8 @@ using TelegramBotBase.Controls.Inline;
|
||||
using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Controls
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Controls;
|
||||
|
||||
public class MultiToggleButtons : AutoCleanForm
|
||||
{
|
||||
public MultiToggleButtons()
|
||||
@ -20,10 +20,9 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
|
||||
private Task ToggleButtons_Init(object sender, InitEventArgs e)
|
||||
{
|
||||
|
||||
var mtb = new MultiToggleButton
|
||||
{
|
||||
Options = new List<ButtonBase> { new ButtonBase("Option 1", "1"), new ButtonBase("Option 2", "2"), new ButtonBase("Option 3", "3") }
|
||||
Options = new List<ButtonBase> { new("Option 1", "1"), new("Option 2", "2"), new("Option 3", "3") }
|
||||
};
|
||||
|
||||
mtb.SelectedOption = mtb.Options.FirstOrDefault();
|
||||
@ -32,7 +31,7 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
|
||||
mtb = new MultiToggleButton
|
||||
{
|
||||
Options = new List<ButtonBase> { new ButtonBase("Option 4", "4"), new ButtonBase("Option 5", "5"), new ButtonBase("Option 6", "6") }
|
||||
Options = new List<ButtonBase> { new("Option 4", "4"), new("Option 5", "5"), new("Option 6", "6") }
|
||||
};
|
||||
|
||||
mtb.SelectedOption = mtb.Options.FirstOrDefault();
|
||||
@ -54,4 +53,3 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
Console.WriteLine("Selection for " + tb.Id + " has been removed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,13 +5,12 @@ using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBaseTest.Tests.Controls.Subclass;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Controls
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Controls;
|
||||
|
||||
public class MultiViewForm : AutoCleanForm
|
||||
{
|
||||
private MultiViewTest _mvt;
|
||||
|
||||
private ButtonGrid _bg;
|
||||
private MultiViewTest _mvt;
|
||||
|
||||
public MultiViewForm()
|
||||
{
|
||||
@ -48,7 +47,4 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -4,12 +4,10 @@ using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Controls.Hybrid;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Controls.Subclass
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Controls.Subclass;
|
||||
|
||||
public class MultiViewTest : MultiView
|
||||
{
|
||||
|
||||
|
||||
public override Task Action(MessageResult result, string value = null)
|
||||
{
|
||||
switch (result.RawData)
|
||||
@ -31,7 +29,6 @@ namespace TelegramBotBaseTest.Tests.Controls.Subclass
|
||||
|
||||
public override async Task RenderView(RenderViewEventArgs e)
|
||||
{
|
||||
|
||||
var bf = new ButtonForm();
|
||||
bf.AddButtonRow(new ButtonBase("Back", "back"), new ButtonBase("Next", "next"));
|
||||
|
||||
@ -50,13 +47,6 @@ namespace TelegramBotBaseTest.Tests.Controls.Subclass
|
||||
await Device.Send("Unknown Page", bf);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,8 +5,8 @@ using TelegramBotBase.Controls.Inline;
|
||||
using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Controls
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Controls;
|
||||
|
||||
public class ToggleButtons : AutoCleanForm
|
||||
{
|
||||
public ToggleButtons()
|
||||
@ -18,7 +18,6 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
|
||||
private Task ToggleButtons_Init(object sender, InitEventArgs e)
|
||||
{
|
||||
|
||||
var tb = new ToggleButton
|
||||
{
|
||||
Checked = true
|
||||
@ -51,4 +50,3 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
Console.WriteLine(tb.Id + " was pressed, and toggled to " + (tb.Checked ? "Checked" : "Unchecked"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,27 +5,30 @@ using TelegramBotBase.Controls.Inline;
|
||||
using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Controls
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Controls;
|
||||
|
||||
public class TreeViewForms : AutoCleanForm
|
||||
{
|
||||
public TreeView View { get; set; }
|
||||
|
||||
private int? MessageId { get; set; }
|
||||
|
||||
public TreeViewForms()
|
||||
{
|
||||
DeleteMode = EDeleteMode.OnLeavingForm;
|
||||
Init += TreeViewForms_Init;
|
||||
}
|
||||
|
||||
public TreeView View { get; set; }
|
||||
|
||||
private int? MessageId { get; set; }
|
||||
|
||||
private Task TreeViewForms_Init(object sender, InitEventArgs e)
|
||||
{
|
||||
View = new TreeView();
|
||||
|
||||
var tvn = new TreeViewNode("Cars", "cars");
|
||||
|
||||
tvn.AddNode(new TreeViewNode("Porsche", "porsche", new TreeViewNode("Website", "web", "https://www.porsche.com/germany/"), new TreeViewNode("911", "911"), new TreeViewNode("918 Spyder", "918")));
|
||||
tvn.AddNode(new TreeViewNode("Porsche", "porsche",
|
||||
new TreeViewNode("Website", "web", "https://www.porsche.com/germany/"),
|
||||
new TreeViewNode("911", "911"),
|
||||
new TreeViewNode("918 Spyder", "918")));
|
||||
tvn.AddNode(new TreeViewNode("BMW", "bmw"));
|
||||
tvn.AddNode(new TreeViewNode("Audi", "audi"));
|
||||
tvn.AddNode(new TreeViewNode("VW", "vw"));
|
||||
@ -50,7 +53,9 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
await message.ConfirmAction();
|
||||
|
||||
if (message.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (message.RawData)
|
||||
{
|
||||
@ -63,9 +68,7 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
await NavigateTo(start);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override async Task Render(MessageResult message)
|
||||
@ -92,6 +95,4 @@ namespace TelegramBotBaseTest.Tests.Controls
|
||||
MessageId = m.MessageId;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -7,12 +7,10 @@ using Telegram.Bot.Types.ReplyMarkups;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests;
|
||||
|
||||
public class DataForm : AutoCleanForm
|
||||
{
|
||||
|
||||
|
||||
public override async Task SentData(DataResult data)
|
||||
{
|
||||
var tmp = "";
|
||||
@ -80,7 +78,6 @@ namespace TelegramBotBaseTest.Tests
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override async Task Action(MessageResult message)
|
||||
@ -88,7 +85,9 @@ namespace TelegramBotBaseTest.Tests
|
||||
await message.ConfirmAction();
|
||||
|
||||
if (message.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (message.RawData)
|
||||
{
|
||||
@ -114,8 +113,6 @@ namespace TelegramBotBaseTest.Tests
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override async Task Render(MessageResult message)
|
||||
@ -131,10 +128,5 @@ namespace TelegramBotBaseTest.Tests
|
||||
InlineKeyboardMarkup ikv = bf;
|
||||
|
||||
await Device.Send("Please upload a contact, photo, video, audio, document or location.", bf);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
146
TelegramBotBase.Test/Tests/DataSources/CustomDataSource.cs
Normal file
146
TelegramBotBase.Test/Tests/DataSources/CustomDataSource.cs
Normal file
@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using TelegramBotBase.Controls.Hybrid;
|
||||
using TelegramBotBase.DataSources;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.DataSources;
|
||||
|
||||
public class CustomDataSource : ButtonFormDataSource
|
||||
{
|
||||
public List<string> Countries = new() { "Country 1", "Country 2", "Country 3" };
|
||||
|
||||
public CustomDataSource()
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
public override int Count => Countries.Count;
|
||||
|
||||
public override int ColumnCount => 1;
|
||||
|
||||
public override int RowCount => Count;
|
||||
|
||||
/// <summary>
|
||||
/// This method has the example purpose of creating and loading some example data.
|
||||
/// When using a database you do not need this kind of method.
|
||||
/// </summary>
|
||||
private void LoadData()
|
||||
{
|
||||
//Exists data source? Read it
|
||||
if (File.Exists(AppContext.BaseDirectory + "countries.json"))
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = JsonConvert.DeserializeObject<List<string>>(File.ReadAllText("countries.json"));
|
||||
|
||||
|
||||
Countries = list;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//If not, create it
|
||||
try
|
||||
{
|
||||
var countries = CultureInfo.GetCultures(CultureTypes.SpecificCultures).Select(a => a.DisplayName).ToList();
|
||||
|
||||
Countries = countries;
|
||||
|
||||
var tmp = JsonConvert.SerializeObject(countries);
|
||||
|
||||
File.WriteAllText(AppContext.BaseDirectory + "countries.json", tmp);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public override ButtonRow ItemAt(int index)
|
||||
{
|
||||
var item = Countries.ElementAt(index);
|
||||
if (item == null)
|
||||
{
|
||||
return new ButtonRow();
|
||||
}
|
||||
|
||||
return Render(item);
|
||||
}
|
||||
|
||||
public override List<ButtonRow> ItemRange(int start, int count)
|
||||
{
|
||||
var items = Countries.Skip(start).Take(count);
|
||||
|
||||
var lst = new List<ButtonRow>();
|
||||
foreach (var c in items)
|
||||
{
|
||||
lst.Add(Render(c));
|
||||
}
|
||||
|
||||
return lst;
|
||||
}
|
||||
|
||||
public override List<ButtonRow> AllItems()
|
||||
{
|
||||
var lst = new List<ButtonRow>();
|
||||
foreach (var c in Countries)
|
||||
{
|
||||
lst.Add(Render(c));
|
||||
}
|
||||
|
||||
return lst;
|
||||
}
|
||||
|
||||
public override ButtonForm PickItems(int start, int count, string filter = null)
|
||||
{
|
||||
var rows = ItemRange(start, count);
|
||||
|
||||
var lst = new ButtonForm();
|
||||
foreach (var c in rows)
|
||||
{
|
||||
lst.AddButtonRow(c);
|
||||
}
|
||||
|
||||
return lst;
|
||||
}
|
||||
|
||||
public override ButtonForm PickAllItems(string filter = null)
|
||||
{
|
||||
var rows = AllItems();
|
||||
|
||||
var bf = new ButtonForm();
|
||||
|
||||
bf.AddButtonRows(rows);
|
||||
|
||||
return bf;
|
||||
}
|
||||
|
||||
public override int CalculateMax(string filter = null)
|
||||
{
|
||||
if (filter == null)
|
||||
{
|
||||
return Countries.Count;
|
||||
}
|
||||
|
||||
return Countries.Where(a => a.IndexOf(filter, StringComparison.InvariantCultureIgnoreCase) != -1).Count();
|
||||
}
|
||||
|
||||
public override ButtonRow Render(object data)
|
||||
{
|
||||
if (!(data is string s))
|
||||
{
|
||||
return new ButtonRow(new ButtonBase("Empty", "zero"));
|
||||
}
|
||||
|
||||
return new ButtonRow(new ButtonBase(s, s));
|
||||
}
|
||||
}
|
||||
51
TelegramBotBase.Test/Tests/DataSources/List.cs
Normal file
51
TelegramBotBase.Test/Tests/DataSources/List.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using System.Threading.Tasks;
|
||||
using TelegramBotBase.Args;
|
||||
using TelegramBotBase.Controls.Hybrid;
|
||||
using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.DataSources;
|
||||
|
||||
public class List : FormBase
|
||||
{
|
||||
private ButtonGrid _buttons;
|
||||
|
||||
public List()
|
||||
{
|
||||
Init += List_Init;
|
||||
}
|
||||
|
||||
private Task List_Init(object sender, InitEventArgs e)
|
||||
{
|
||||
_buttons = new ButtonGrid
|
||||
{
|
||||
EnablePaging = true,
|
||||
EnableSearch = false
|
||||
};
|
||||
|
||||
_buttons.ButtonClicked += __buttons_ButtonClicked;
|
||||
_buttons.KeyboardType = EKeyboardType.ReplyKeyboard;
|
||||
_buttons.DeleteReplyMessage = true;
|
||||
|
||||
_buttons.HeadLayoutButtonRow = new ButtonRow(new ButtonBase("Back", "back"));
|
||||
|
||||
var cds = new CustomDataSource();
|
||||
_buttons.DataSource = cds;
|
||||
|
||||
AddControl(_buttons);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task __buttons_ButtonClicked(object sender, ButtonClickedEventArgs e)
|
||||
{
|
||||
switch (e.Button.Value)
|
||||
{
|
||||
case "back":
|
||||
|
||||
var mn = new Menu();
|
||||
await NavigateTo(mn);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,143 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using TelegramBotBase.Controls.Hybrid;
|
||||
using TelegramBotBase.DataSources;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Datasources
|
||||
{
|
||||
public class CustomDataSource : ButtonFormDataSource
|
||||
{
|
||||
|
||||
public List<string> Countries = new List<string> { "Country 1", "Country 2", "Country 3" };
|
||||
|
||||
public CustomDataSource()
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method has the example purpose of creating and loading some example data.
|
||||
/// When using a database you do not need this kind of method.
|
||||
/// </summary>
|
||||
private void LoadData()
|
||||
{
|
||||
//Exists data source? Read it
|
||||
if (File.Exists(AppContext.BaseDirectory + "countries.json"))
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = JsonConvert.DeserializeObject<List<string>>(File.ReadAllText("countries.json"));
|
||||
|
||||
|
||||
Countries = list;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//If not, create it
|
||||
try
|
||||
{
|
||||
var countries = CultureInfo.GetCultures(CultureTypes.SpecificCultures).Select(a => a.DisplayName).ToList();
|
||||
|
||||
Countries = countries;
|
||||
|
||||
var tmp = JsonConvert.SerializeObject(countries);
|
||||
|
||||
File.WriteAllText( AppContext.BaseDirectory + "countries.json", tmp);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override ButtonRow ItemAt(int index)
|
||||
{
|
||||
var item = Countries.ElementAt(index);
|
||||
if (item == null)
|
||||
return new ButtonRow();
|
||||
|
||||
return Render(item);
|
||||
}
|
||||
|
||||
public override List<ButtonRow> ItemRange(int start, int count)
|
||||
{
|
||||
var items = Countries.Skip(start).Take(count);
|
||||
|
||||
var lst = new List<ButtonRow>();
|
||||
foreach (var c in items)
|
||||
{
|
||||
lst.Add(Render(c));
|
||||
}
|
||||
|
||||
return lst;
|
||||
}
|
||||
|
||||
public override List<ButtonRow> AllItems()
|
||||
{
|
||||
var lst = new List<ButtonRow>();
|
||||
foreach (var c in Countries)
|
||||
{
|
||||
lst.Add(Render(c));
|
||||
}
|
||||
return lst;
|
||||
}
|
||||
|
||||
public override ButtonForm PickItems(int start, int count, string filter = null)
|
||||
{
|
||||
var rows = ItemRange(start, count);
|
||||
|
||||
var lst = new ButtonForm();
|
||||
foreach (var c in rows)
|
||||
{
|
||||
lst.AddButtonRow(c);
|
||||
}
|
||||
return lst;
|
||||
}
|
||||
|
||||
public override ButtonForm PickAllItems(string filter = null)
|
||||
{
|
||||
var rows = AllItems();
|
||||
|
||||
var bf = new ButtonForm();
|
||||
|
||||
bf.AddButtonRows(rows);
|
||||
|
||||
return bf;
|
||||
}
|
||||
|
||||
public override int CalculateMax(string filter = null)
|
||||
{
|
||||
if (filter == null)
|
||||
return Countries.Count;
|
||||
|
||||
return Countries.Where(a => a.IndexOf(filter, StringComparison.InvariantCultureIgnoreCase) != -1).Count();
|
||||
}
|
||||
|
||||
public override ButtonRow Render(object data)
|
||||
{
|
||||
if (!(data is string s))
|
||||
return new ButtonRow(new ButtonBase("Empty", "zero"));
|
||||
|
||||
return new ButtonRow(new ButtonBase(s, s));
|
||||
}
|
||||
|
||||
public override int Count => Countries.Count;
|
||||
|
||||
public override int ColumnCount => 1;
|
||||
|
||||
public override int RowCount => Count;
|
||||
}
|
||||
}
|
||||
@ -1,55 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using TelegramBotBase.Args;
|
||||
using TelegramBotBase.Controls.Hybrid;
|
||||
using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Datasources
|
||||
{
|
||||
public class List : FormBase
|
||||
{
|
||||
private ButtonGrid _buttons;
|
||||
|
||||
public List()
|
||||
{
|
||||
Init += List_Init;
|
||||
}
|
||||
|
||||
private Task List_Init(object sender, InitEventArgs e)
|
||||
{
|
||||
|
||||
_buttons = new ButtonGrid
|
||||
{
|
||||
EnablePaging = true,
|
||||
EnableSearch = false
|
||||
};
|
||||
|
||||
_buttons.ButtonClicked += __buttons_ButtonClicked;
|
||||
_buttons.KeyboardType = EKeyboardType.ReplyKeyboard;
|
||||
_buttons.DeleteReplyMessage = true;
|
||||
|
||||
_buttons.HeadLayoutButtonRow = new ButtonRow(new ButtonBase("Back", "back"));
|
||||
|
||||
var cds = new CustomDataSource();
|
||||
_buttons.DataSource = cds;
|
||||
|
||||
AddControl(_buttons);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task __buttons_ButtonClicked(object sender, ButtonClickedEventArgs e)
|
||||
{
|
||||
switch(e.Button.Value)
|
||||
{
|
||||
case "back":
|
||||
|
||||
var mn = new Menu();
|
||||
await NavigateTo(mn);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -4,8 +4,8 @@ using TelegramBotBase.Args;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Groups
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Groups;
|
||||
|
||||
public class GroupChange : GroupForm
|
||||
{
|
||||
public GroupChange()
|
||||
@ -16,7 +16,6 @@ namespace TelegramBotBaseTest.Tests.Groups
|
||||
|
||||
private async Task GroupChange_Opened(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
var bf = new ButtonForm();
|
||||
|
||||
bf.AddButtonRow(new ButtonBase("Open GroupChange Test", "groupchange"));
|
||||
@ -24,13 +23,14 @@ namespace TelegramBotBaseTest.Tests.Groups
|
||||
bf.AddButtonRow(new ButtonBase("Open LinkReplace Test", "linkreplace"));
|
||||
|
||||
await Device.Send("GroupChange started, click to switch", bf);
|
||||
|
||||
}
|
||||
|
||||
public override async Task Action(MessageResult message)
|
||||
{
|
||||
if (message.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var bn = message.RawData;
|
||||
@ -62,13 +62,11 @@ namespace TelegramBotBaseTest.Tests.Groups
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override async Task OnGroupChanged(GroupChangedEventArgs e)
|
||||
{
|
||||
await Device.Send("Group has been changed by " + e.OriginalMessage.Message.From.FirstName + " " + e.OriginalMessage.Message.From.LastName);
|
||||
}
|
||||
|
||||
await Device.Send("Group has been changed by " + e.OriginalMessage.Message.From.FirstName + " " +
|
||||
e.OriginalMessage.Message.From.LastName);
|
||||
}
|
||||
}
|
||||
@ -7,12 +7,10 @@ using Telegram.Bot.Types.Enums;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Groups
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Groups;
|
||||
|
||||
public class LinkReplaceTest : GroupForm
|
||||
{
|
||||
private Dictionary<long, int> Counter { get; set; } = new Dictionary<long, int>();
|
||||
|
||||
private const int Maximum = 3;
|
||||
|
||||
|
||||
@ -21,9 +19,10 @@ namespace TelegramBotBaseTest.Tests.Groups
|
||||
Opened += LinkReplaceTest_Opened;
|
||||
}
|
||||
|
||||
private Dictionary<long, int> Counter { get; } = new();
|
||||
|
||||
private async Task LinkReplaceTest_Opened(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
var bf = new ButtonForm();
|
||||
|
||||
bf.AddButtonRow(new ButtonBase("Open GroupChange Test", "groupchange"));
|
||||
@ -31,13 +30,14 @@ namespace TelegramBotBaseTest.Tests.Groups
|
||||
bf.AddButtonRow(new ButtonBase("Open LinkReplace Test", "linkreplace"));
|
||||
|
||||
await Device.Send("LinkReplaceTest started, click to switch", bf);
|
||||
|
||||
}
|
||||
|
||||
public override async Task Action(MessageResult message)
|
||||
{
|
||||
if (message.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var bn = message.RawData;
|
||||
|
||||
@ -68,7 +68,6 @@ namespace TelegramBotBaseTest.Tests.Groups
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override async Task OnMessage(MessageResult e)
|
||||
@ -76,16 +75,20 @@ namespace TelegramBotBaseTest.Tests.Groups
|
||||
var from = e.Message.From.Id;
|
||||
|
||||
if (e.Message.From.IsBot)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Are urls inside his message ?
|
||||
if (!HasLinks(e.MessageText))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var u = await Device.GetChatUser(from);
|
||||
|
||||
//Don't kick Admins or Creators
|
||||
if (u.Status == ChatMemberStatus.Administrator | u.Status == ChatMemberStatus.Creator)
|
||||
if ((u.Status == ChatMemberStatus.Administrator) | (u.Status == ChatMemberStatus.Creator))
|
||||
{
|
||||
await Device.Send("You won't get kicked,...not this time.");
|
||||
return;
|
||||
@ -120,17 +123,16 @@ namespace TelegramBotBaseTest.Tests.Groups
|
||||
{
|
||||
await e.Device.KickUser(from);
|
||||
|
||||
await e.Device.Send(e.Message.From.FirstName + " " + e.Message.From.LastName + " has been removed from the group");
|
||||
await e.Device.Send(e.Message.From.FirstName + " " + e.Message.From.LastName +
|
||||
" has been removed from the group");
|
||||
}
|
||||
else
|
||||
{
|
||||
await e.Device.RestrictUser(from, cp, DateTime.UtcNow.AddSeconds(30));
|
||||
|
||||
await e.Device.Send(e.Message.From.FirstName + " " + e.Message.From.LastName + " has been blocked for 30 seconds");
|
||||
await e.Device.Send(e.Message.From.FirstName + " " + e.Message.From.LastName +
|
||||
" has been blocked for 30 seconds");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -152,14 +154,12 @@ namespace TelegramBotBaseTest.Tests.Groups
|
||||
{
|
||||
var tmp = str;
|
||||
|
||||
var pattern = @"^(http|https|ftp|)\://|[a-zA-Z0-9\-\.]+\.[a-zA-Z](:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$";
|
||||
var pattern =
|
||||
@"^(http|https|ftp|)\://|[a-zA-Z0-9\-\.]+\.[a-zA-Z](:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$";
|
||||
var r = new Regex(pattern);
|
||||
|
||||
var matches = r.Matches(tmp);
|
||||
|
||||
return (matches.Count > 0);
|
||||
}
|
||||
|
||||
|
||||
return matches.Count > 0;
|
||||
}
|
||||
}
|
||||
@ -6,11 +6,10 @@ using TelegramBotBase.Args;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Groups
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Groups;
|
||||
|
||||
public class WelcomeUser : GroupForm
|
||||
{
|
||||
|
||||
public WelcomeUser()
|
||||
{
|
||||
Opened += WelcomeUser_Opened;
|
||||
@ -19,7 +18,6 @@ namespace TelegramBotBaseTest.Tests.Groups
|
||||
|
||||
private async Task WelcomeUser_Opened(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
var bf = new ButtonForm();
|
||||
|
||||
bf.AddButtonRow(new ButtonBase("Open GroupChange Test", "groupchange"));
|
||||
@ -27,13 +25,14 @@ namespace TelegramBotBaseTest.Tests.Groups
|
||||
bf.AddButtonRow(new ButtonBase("Open LinkReplace Test", "linkreplace"));
|
||||
|
||||
await Device.Send("WelcomeUser started, click to switch", bf);
|
||||
|
||||
}
|
||||
|
||||
public override async Task Action(MessageResult message)
|
||||
{
|
||||
if (message.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var bn = message.RawData;
|
||||
|
||||
@ -64,28 +63,20 @@ namespace TelegramBotBaseTest.Tests.Groups
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override async Task OnMemberChanges(MemberChangeEventArgs e)
|
||||
{
|
||||
|
||||
if (e.Type == MessageType.ChatMembersAdded)
|
||||
{
|
||||
|
||||
await Device.Send("Welcome you new members!\r\n\r\n" + e.Members.Select(a => a.FirstName + " " + a.LastName).Aggregate((a, b) => a + "\r\n" + b));
|
||||
|
||||
await Device.Send("Welcome you new members!\r\n\r\n" + e.Members.Select(a => a.FirstName + " " + a.LastName)
|
||||
.Aggregate((a, b) => a + "\r\n" + b));
|
||||
}
|
||||
else if (e.Type == MessageType.ChatMemberLeft)
|
||||
{
|
||||
await Device.Send(e.Members.Select(a => a.FirstName + " " + a.LastName).Aggregate((a, b) => a + " and " + b) + " has left the group");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
await Device.Send(
|
||||
e.Members.Select(a => a.FirstName + " " + a.LastName).Aggregate((a, b) => a + " and " + b) +
|
||||
" has left the group");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,11 +4,11 @@ using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBaseTest.Tests.Controls;
|
||||
using TelegramBotBaseTest.Tests.Datasources;
|
||||
using TelegramBotBaseTest.Tests.DataSources;
|
||||
using TelegramBotBaseTest.Tests.Groups;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests;
|
||||
|
||||
public class Menu : AutoCleanForm
|
||||
{
|
||||
public Menu()
|
||||
@ -18,9 +18,7 @@ namespace TelegramBotBaseTest.Tests
|
||||
|
||||
public override async Task Load(MessageResult message)
|
||||
{
|
||||
|
||||
|
||||
if (message.Message.Chat.Type == ChatType.Group | message.Message.Chat.Type == ChatType.Supergroup)
|
||||
if ((message.Message.Chat.Type == ChatType.Group) | (message.Message.Chat.Type == ChatType.Supergroup))
|
||||
{
|
||||
var sf = new WelcomeUser();
|
||||
|
||||
@ -39,7 +37,9 @@ namespace TelegramBotBaseTest.Tests
|
||||
|
||||
|
||||
if (call == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
message.Handled = true;
|
||||
|
||||
@ -213,16 +213,14 @@ namespace TelegramBotBaseTest.Tests
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override async Task Render(MessageResult message)
|
||||
{
|
||||
|
||||
var btn = new ButtonForm();
|
||||
|
||||
btn.AddButtonRow(new ButtonBase("#1 Simple Text", new CallbackData("a", "text").Serialize()), new ButtonBase("#2 Button Test", new CallbackData("a", "buttons").Serialize()));
|
||||
btn.AddButtonRow(new ButtonBase("#1 Simple Text", new CallbackData("a", "text").Serialize()),
|
||||
new ButtonBase("#2 Button Test", new CallbackData("a", "buttons").Serialize()));
|
||||
btn.AddButtonRow(new ButtonBase("#3 Progress Bar", new CallbackData("a", "progress").Serialize()));
|
||||
btn.AddButtonRow(new ButtonBase("#4 Registration Example", new CallbackData("a", "registration").Serialize()));
|
||||
|
||||
@ -238,27 +236,30 @@ namespace TelegramBotBaseTest.Tests
|
||||
|
||||
btn.AddButtonRow(new ButtonBase("#11 ToggleButtons", new CallbackData("a", "togglebuttons").Serialize()));
|
||||
|
||||
btn.AddButtonRow(new ButtonBase("#11.2 MultiToggleButtons", new CallbackData("a", "multitogglebuttons").Serialize()));
|
||||
btn.AddButtonRow(new ButtonBase("#11.2 MultiToggleButtons",
|
||||
new CallbackData("a", "multitogglebuttons").Serialize()));
|
||||
|
||||
btn.AddButtonRow(new ButtonBase("#12 ButtonGrid", new CallbackData("a", "buttongrid").Serialize()));
|
||||
|
||||
btn.AddButtonRow(new ButtonBase("#13 ButtonGrid Paging & Filter", new CallbackData("a", "buttongridfilter").Serialize()));
|
||||
btn.AddButtonRow(new ButtonBase("#13 ButtonGrid Paging & Filter",
|
||||
new CallbackData("a", "buttongridfilter").Serialize()));
|
||||
|
||||
btn.AddButtonRow(new ButtonBase("#14 ButtonGrid Tags (Filter)", new CallbackData("a", "buttongridtags").Serialize()));
|
||||
btn.AddButtonRow(new ButtonBase("#14 ButtonGrid Tags (Filter)",
|
||||
new CallbackData("a", "buttongridtags").Serialize()));
|
||||
|
||||
btn.AddButtonRow(new ButtonBase("#15 MultiView", new CallbackData("a", "multiview").Serialize()));
|
||||
|
||||
btn.AddButtonRow(new ButtonBase("#16 CheckedButtonList", new CallbackData("a", "checkedbuttonlist").Serialize()));
|
||||
btn.AddButtonRow(
|
||||
new ButtonBase("#16 CheckedButtonList", new CallbackData("a", "checkedbuttonlist").Serialize()));
|
||||
|
||||
btn.AddButtonRow(new ButtonBase("#17 NavigationController (Push/Pop)", new CallbackData("a", "navigationcontroller").Serialize()));
|
||||
btn.AddButtonRow(new ButtonBase("#17 NavigationController (Push/Pop)",
|
||||
new CallbackData("a", "navigationcontroller").Serialize()));
|
||||
|
||||
btn.AddButtonRow(new ButtonBase("#18 Dynamic ButtonGrid (DataSources)", new CallbackData("a", "dynamicbuttongrid").Serialize()));
|
||||
btn.AddButtonRow(new ButtonBase("#18 Dynamic ButtonGrid (DataSources)",
|
||||
new CallbackData("a", "dynamicbuttongrid").Serialize()));
|
||||
|
||||
btn.AddButtonRow(new ButtonBase("#19 Notifications", new CallbackData("a", "notifications").Serialize()));
|
||||
|
||||
await Device.Send("Choose your test:", btn);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,13 +3,12 @@ using System.Threading.Tasks;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBase.Form.Navigation;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Navigation
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Navigation;
|
||||
|
||||
internal class CustomController : NavigationController
|
||||
{
|
||||
public CustomController(FormBase form) : base(form)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -37,6 +36,4 @@ namespace TelegramBotBaseTest.Tests.Navigation
|
||||
|
||||
return base.PopToRootAsync();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -4,8 +4,8 @@ using Telegram.Bot.Types;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Navigation
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Navigation;
|
||||
|
||||
public class Form1 : FormBase
|
||||
{
|
||||
private Message _msg;
|
||||
@ -18,7 +18,9 @@ namespace TelegramBotBaseTest.Tests.Navigation
|
||||
private async Task Form1_Closed(object sender, EventArgs e)
|
||||
{
|
||||
if (_msg == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await Device.DeleteMessage(_msg);
|
||||
}
|
||||
@ -26,7 +28,9 @@ namespace TelegramBotBaseTest.Tests.Navigation
|
||||
public override async Task Action(MessageResult message)
|
||||
{
|
||||
if (message.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await message.ConfirmAction();
|
||||
|
||||
@ -59,18 +63,15 @@ namespace TelegramBotBaseTest.Tests.Navigation
|
||||
await NavigationController.PopToRootAsync();
|
||||
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override async Task Render(MessageResult message)
|
||||
{
|
||||
if (_msg != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var bf = new ButtonForm();
|
||||
bf.AddButtonRow("Next page", "next");
|
||||
@ -78,9 +79,5 @@ namespace TelegramBotBaseTest.Tests.Navigation
|
||||
bf.AddButtonRow("Back to root", "root");
|
||||
|
||||
_msg = await Device.Send($"Choose your options (Count on stack {NavigationController.Index + 1})", bf);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -3,8 +3,8 @@ using Telegram.Bot.Types;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Navigation
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Navigation;
|
||||
|
||||
public class Start : FormBase
|
||||
{
|
||||
private Message _msg;
|
||||
@ -18,7 +18,9 @@ namespace TelegramBotBaseTest.Tests.Navigation
|
||||
public override async Task Action(MessageResult message)
|
||||
{
|
||||
if (message.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await message.ConfirmAction();
|
||||
|
||||
@ -39,7 +41,9 @@ namespace TelegramBotBaseTest.Tests.Navigation
|
||||
await NavigateTo(nc);
|
||||
|
||||
if (_msg == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await Device.DeleteMessage(_msg);
|
||||
|
||||
@ -54,13 +58,14 @@ namespace TelegramBotBaseTest.Tests.Navigation
|
||||
await NavigateTo(mn);
|
||||
|
||||
if (_msg == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await Device.DeleteMessage(_msg);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override async Task Render(MessageResult message)
|
||||
@ -71,9 +76,5 @@ namespace TelegramBotBaseTest.Tests.Navigation
|
||||
bf.AddButtonRow("No", "no");
|
||||
|
||||
_msg = await Device.Send("Open controller?", bf);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -3,8 +3,8 @@ using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Notifications
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Notifications;
|
||||
|
||||
public class Start : AutoCleanForm
|
||||
{
|
||||
private bool _sent;
|
||||
@ -17,7 +17,9 @@ namespace TelegramBotBaseTest.Tests.Notifications
|
||||
public override async Task Action(MessageResult message)
|
||||
{
|
||||
if (message.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (message.RawData)
|
||||
{
|
||||
@ -37,15 +39,15 @@ namespace TelegramBotBaseTest.Tests.Notifications
|
||||
await message.ConfirmAction("This is feedback");
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override async Task Render(MessageResult message)
|
||||
{
|
||||
if (_sent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var bf = new ButtonForm();
|
||||
bf.AddButtonRow("Normal feeback", "normal");
|
||||
@ -56,6 +58,4 @@ namespace TelegramBotBaseTest.Tests.Notifications
|
||||
|
||||
_sent = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -6,11 +6,10 @@ using TelegramBotBase.Controls.Inline;
|
||||
using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests;
|
||||
|
||||
public class ProgressTest : AutoCleanForm
|
||||
{
|
||||
|
||||
public ProgressTest()
|
||||
{
|
||||
DeleteMode = EDeleteMode.OnLeavingForm;
|
||||
@ -32,7 +31,9 @@ namespace TelegramBotBaseTest.Tests
|
||||
|
||||
|
||||
if (call == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ProgressBar bar = null;
|
||||
|
||||
@ -94,7 +95,6 @@ namespace TelegramBotBaseTest.Tests
|
||||
default:
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -110,17 +110,17 @@ namespace TelegramBotBaseTest.Tests
|
||||
|
||||
Thread.Sleep(250);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override async Task Render(MessageResult message)
|
||||
{
|
||||
var btn = new ButtonForm();
|
||||
btn.AddButtonRow(new ButtonBase("Standard", new CallbackData("a", "standard").Serialize()), new ButtonBase("Squares", new CallbackData("a", "squares").Serialize()));
|
||||
btn.AddButtonRow(new ButtonBase("Standard", new CallbackData("a", "standard").Serialize()),
|
||||
new ButtonBase("Squares", new CallbackData("a", "squares").Serialize()));
|
||||
|
||||
btn.AddButtonRow(new ButtonBase("Circles", new CallbackData("a", "circles").Serialize()), new ButtonBase("Lines", new CallbackData("a", "lines").Serialize()));
|
||||
btn.AddButtonRow(new ButtonBase("Circles", new CallbackData("a", "circles").Serialize()),
|
||||
new ButtonBase("Lines", new CallbackData("a", "lines").Serialize()));
|
||||
|
||||
btn.AddButtonRow(new ButtonBase("Squared Line", new CallbackData("a", "squaredlines").Serialize()));
|
||||
|
||||
@ -133,6 +133,4 @@ namespace TelegramBotBaseTest.Tests
|
||||
{
|
||||
await Device.Send("Ciao from ProgressTest");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -2,8 +2,8 @@
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Register
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Register;
|
||||
|
||||
public class PerForm : AutoCleanForm
|
||||
{
|
||||
public string EMail { get; set; }
|
||||
@ -15,7 +15,9 @@ namespace TelegramBotBaseTest.Tests.Register
|
||||
public override Task Load(MessageResult message)
|
||||
{
|
||||
if (message.MessageText.Trim() == "")
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
if (Firstname == null)
|
||||
{
|
||||
@ -45,7 +47,9 @@ namespace TelegramBotBaseTest.Tests.Register
|
||||
await message.ConfirmAction();
|
||||
|
||||
if (call == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (call.Value)
|
||||
{
|
||||
@ -56,10 +60,7 @@ namespace TelegramBotBaseTest.Tests.Register
|
||||
await NavigateTo(start);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override async Task Render(MessageResult message)
|
||||
@ -94,7 +95,4 @@ namespace TelegramBotBaseTest.Tests.Register
|
||||
|
||||
await Device.Send("Your details:\r\n" + s, bf);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -3,11 +3,10 @@ using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBaseTest.Tests.Register.Steps;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Register
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Register;
|
||||
|
||||
public class PerStep : AutoCleanForm
|
||||
{
|
||||
|
||||
public override async Task Action(MessageResult message)
|
||||
{
|
||||
await message.ConfirmAction();
|
||||
@ -28,7 +27,6 @@ namespace TelegramBotBaseTest.Tests.Register
|
||||
await NavigateTo(start);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,4 +39,3 @@ namespace TelegramBotBaseTest.Tests.Register
|
||||
await Device.Send("Register Steps", bf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Register
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Register;
|
||||
|
||||
public class Start : AutoCleanForm
|
||||
{
|
||||
public override async Task Action(MessageResult message)
|
||||
@ -14,7 +14,9 @@ namespace TelegramBotBaseTest.Tests.Register
|
||||
|
||||
|
||||
if (call == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (call.Value)
|
||||
{
|
||||
@ -40,13 +42,10 @@ namespace TelegramBotBaseTest.Tests.Register
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override async Task Render(MessageResult message)
|
||||
{
|
||||
|
||||
var btn = new ButtonForm();
|
||||
|
||||
btn.AddButtonRow(new ButtonBase("#4.1 Per Form", new CallbackData("a", "form").Serialize()));
|
||||
@ -54,10 +53,5 @@ namespace TelegramBotBaseTest.Tests.Register
|
||||
btn.AddButtonRow(new ButtonBase("Back", new CallbackData("a", "backtodashboard").Serialize()));
|
||||
|
||||
await Device.Send("Choose your test:", btn);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
namespace TelegramBotBaseTest.Tests.Register.Steps
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Register.Steps;
|
||||
|
||||
public class Data
|
||||
{
|
||||
public string EMail { get; set; }
|
||||
@ -7,6 +7,4 @@
|
||||
public string Firstname { get; set; }
|
||||
|
||||
public string Lastname { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@ -3,17 +3,17 @@ using TelegramBotBase.Args;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Register.Steps
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Register.Steps;
|
||||
|
||||
public class Step1 : AutoCleanForm
|
||||
{
|
||||
public Data UserData { get; set; }
|
||||
|
||||
public Step1()
|
||||
{
|
||||
Init += Step1_Init;
|
||||
}
|
||||
|
||||
public Data UserData { get; set; }
|
||||
|
||||
private Task Step1_Init(object sender, InitEventArgs e)
|
||||
{
|
||||
UserData = new Data();
|
||||
@ -24,10 +24,14 @@ namespace TelegramBotBaseTest.Tests.Register.Steps
|
||||
public override Task Load(MessageResult message)
|
||||
{
|
||||
if (message.Handled)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
if (message.MessageText.Trim() == "")
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
if (UserData.Firstname == null)
|
||||
{
|
||||
@ -54,6 +58,4 @@ namespace TelegramBotBaseTest.Tests.Register.Steps
|
||||
|
||||
await NavigateTo(step2);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -2,8 +2,8 @@
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Register.Steps
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Register.Steps;
|
||||
|
||||
public class Step2 : AutoCleanForm
|
||||
{
|
||||
public Data UserData { get; set; }
|
||||
@ -12,10 +12,14 @@ namespace TelegramBotBaseTest.Tests.Register.Steps
|
||||
public override Task Load(MessageResult message)
|
||||
{
|
||||
if (message.Handled)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
if (message.MessageText.Trim() == "")
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
if (UserData.Lastname == null)
|
||||
{
|
||||
@ -43,6 +47,4 @@ namespace TelegramBotBaseTest.Tests.Register.Steps
|
||||
|
||||
await NavigateTo(step3);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -2,8 +2,8 @@
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests.Register.Steps
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests.Register.Steps;
|
||||
|
||||
public class Step3 : AutoCleanForm
|
||||
{
|
||||
public Data UserData { get; set; }
|
||||
@ -11,10 +11,14 @@ namespace TelegramBotBaseTest.Tests.Register.Steps
|
||||
public override Task Load(MessageResult message)
|
||||
{
|
||||
if (message.Handled)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
if (message.MessageText.Trim() == "")
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
if (UserData.EMail == null)
|
||||
{
|
||||
@ -38,9 +42,7 @@ namespace TelegramBotBaseTest.Tests.Register.Steps
|
||||
await NavigateTo(start);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override async Task Render(MessageResult message)
|
||||
@ -64,6 +66,4 @@ namespace TelegramBotBaseTest.Tests.Register.Steps
|
||||
|
||||
await Device.Send("Your details:\r\n" + s, bf);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -4,11 +4,10 @@ using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Enums;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests;
|
||||
|
||||
public class SimpleForm : AutoCleanForm
|
||||
{
|
||||
|
||||
public SimpleForm()
|
||||
{
|
||||
DeleteSide = EDeleteSide.Both;
|
||||
@ -60,7 +59,4 @@ namespace TelegramBotBaseTest.Tests
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -3,8 +3,8 @@ using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBaseTest.Tests.Groups;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests;
|
||||
|
||||
public class Start : SplitterForm
|
||||
{
|
||||
public override async Task<bool> Open(MessageResult e)
|
||||
@ -33,6 +33,4 @@ namespace TelegramBotBaseTest.Tests
|
||||
{
|
||||
return base.OpenSupergroup(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -3,18 +3,18 @@ using System.Threading.Tasks;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests;
|
||||
|
||||
public class TestForm : FormBase
|
||||
{
|
||||
private string LastMessage { get; set; }
|
||||
|
||||
public TestForm()
|
||||
{
|
||||
Opened += TestForm_Opened;
|
||||
Closed += TestForm_Closed;
|
||||
}
|
||||
|
||||
private string LastMessage { get; set; }
|
||||
|
||||
private async Task TestForm_Opened(object sender, EventArgs e)
|
||||
{
|
||||
await Device.Send("Welcome to Form 1");
|
||||
@ -46,14 +46,14 @@ namespace TelegramBotBaseTest.Tests
|
||||
default:
|
||||
|
||||
if (message.UpdateData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LastMessage = message.Message.Text;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -61,12 +61,7 @@ namespace TelegramBotBaseTest.Tests
|
||||
{
|
||||
if (message.Command == "reply")
|
||||
{
|
||||
|
||||
await Device.Send("Last message: " + LastMessage);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,12 +6,10 @@ using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Extensions.Images;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBaseTest.Tests
|
||||
{
|
||||
namespace TelegramBotBaseTest.Tests;
|
||||
|
||||
public class TestForm2 : FormBase
|
||||
{
|
||||
|
||||
|
||||
public TestForm2()
|
||||
{
|
||||
Opened += TestForm2_Opened;
|
||||
@ -29,8 +27,6 @@ namespace TelegramBotBaseTest.Tests
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public override async Task Action(MessageResult message)
|
||||
{
|
||||
var call = message.GetData<CallbackData>();
|
||||
@ -43,7 +39,6 @@ namespace TelegramBotBaseTest.Tests
|
||||
|
||||
if (call.Value == "testform1")
|
||||
{
|
||||
|
||||
var tf = new TestForm();
|
||||
|
||||
await NavigateTo(tf);
|
||||
@ -62,7 +57,8 @@ namespace TelegramBotBaseTest.Tests
|
||||
}
|
||||
else if (call.Value == "confirm")
|
||||
{
|
||||
var pd = new ConfirmDialog("Please confirm", new ButtonBase("Ok", "ok"), new ButtonBase("Cancel", "cancel"));
|
||||
var pd = new ConfirmDialog("Please confirm", new ButtonBase("Ok", "ok"),
|
||||
new ButtonBase("Cancel", "cancel"));
|
||||
|
||||
pd.ButtonClicked += async (s, en) =>
|
||||
{
|
||||
@ -77,28 +73,21 @@ namespace TelegramBotBaseTest.Tests
|
||||
{
|
||||
var pd = new PromptDialog("Please tell me your name ?");
|
||||
|
||||
pd.Completed += async (s, en) =>
|
||||
{
|
||||
await Device.Send("Hello " + pd.Value);
|
||||
};
|
||||
pd.Completed += async (s, en) => { await Device.Send("Hello " + pd.Value); };
|
||||
|
||||
await OpenModal(pd);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override async Task Render(MessageResult message)
|
||||
{
|
||||
|
||||
var bmp = new Bitmap(800, 600);
|
||||
using (var g = Graphics.FromImage(bmp))
|
||||
{
|
||||
|
||||
g.FillRectangle(Brushes.White, 0, 0, bmp.Width, bmp.Height);
|
||||
|
||||
g.DrawString("Test Image", new Font("Arial", 24, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Black, new PointF(50, 50));
|
||||
|
||||
g.DrawString("Test Image", new Font("Arial", 24, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Black,
|
||||
new PointF(50, 50));
|
||||
}
|
||||
|
||||
await Device.SetAction(ChatAction.UploadPhoto);
|
||||
@ -115,9 +104,5 @@ namespace TelegramBotBaseTest.Tests
|
||||
|
||||
|
||||
await Device.SendPhoto(bmp, "Test", "", btn);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -3,13 +3,27 @@ using System.Collections.Generic;
|
||||
using Telegram.Bot.Types;
|
||||
using TelegramBotBase.Sessions;
|
||||
|
||||
namespace TelegramBotBase.Args
|
||||
{
|
||||
namespace TelegramBotBase.Args;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for given bot command results
|
||||
/// </summary>
|
||||
public class BotCommandEventArgs : EventArgs
|
||||
{
|
||||
public BotCommandEventArgs()
|
||||
{
|
||||
}
|
||||
|
||||
public BotCommandEventArgs(string command, List<string> parameters, Message message, long deviceId,
|
||||
DeviceSession device)
|
||||
{
|
||||
Command = command;
|
||||
Parameters = parameters;
|
||||
OriginalMessage = message;
|
||||
DeviceId = deviceId;
|
||||
Device = device;
|
||||
}
|
||||
|
||||
public string Command { get; set; }
|
||||
|
||||
public List<string> Parameters { get; set; }
|
||||
@ -21,22 +35,4 @@ namespace TelegramBotBase.Args
|
||||
public bool Handled { get; set; } = false;
|
||||
|
||||
public Message OriginalMessage { get; set; }
|
||||
|
||||
|
||||
public BotCommandEventArgs()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public BotCommandEventArgs(string command, List<string> parameters, Message message, long deviceId, DeviceSession device)
|
||||
{
|
||||
this.Command = command;
|
||||
this.Parameters = parameters;
|
||||
OriginalMessage = message;
|
||||
this.DeviceId = deviceId;
|
||||
this.Device = device;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -2,25 +2,15 @@
|
||||
using TelegramBotBase.Controls.Hybrid;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBase.Args
|
||||
{
|
||||
namespace TelegramBotBase.Args;
|
||||
|
||||
/// <summary>
|
||||
/// Button get clicked event
|
||||
/// </summary>
|
||||
public class ButtonClickedEventArgs : EventArgs
|
||||
{
|
||||
public ButtonBase Button { get; set; }
|
||||
|
||||
public int Index { get; set; }
|
||||
|
||||
public object Tag { get; set; }
|
||||
|
||||
public ButtonRow Row { get; set; }
|
||||
|
||||
|
||||
public ButtonClickedEventArgs()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ButtonClickedEventArgs(ButtonBase button)
|
||||
@ -32,14 +22,21 @@ namespace TelegramBotBase.Args
|
||||
public ButtonClickedEventArgs(ButtonBase button, int index)
|
||||
{
|
||||
Button = button;
|
||||
this.Index = index;
|
||||
Index = index;
|
||||
}
|
||||
|
||||
public ButtonClickedEventArgs(ButtonBase button, int index, ButtonRow row)
|
||||
{
|
||||
Button = button;
|
||||
this.Index = index;
|
||||
Index = index;
|
||||
Row = row;
|
||||
}
|
||||
}
|
||||
|
||||
public ButtonBase Button { get; set; }
|
||||
|
||||
public int Index { get; set; }
|
||||
|
||||
public object Tag { get; set; }
|
||||
|
||||
public ButtonRow Row { get; set; }
|
||||
}
|
||||
@ -1,10 +1,21 @@
|
||||
using System;
|
||||
using TelegramBotBase.Controls.Hybrid;
|
||||
|
||||
namespace TelegramBotBase.Args
|
||||
{
|
||||
namespace TelegramBotBase.Args;
|
||||
|
||||
public class CheckedChangedEventArgs : EventArgs
|
||||
{
|
||||
public CheckedChangedEventArgs()
|
||||
{
|
||||
}
|
||||
|
||||
public CheckedChangedEventArgs(ButtonRow row, int index, bool @checked)
|
||||
{
|
||||
Row = row;
|
||||
Index = index;
|
||||
Checked = @checked;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains the index of the row where the button is inside.
|
||||
/// Contains -1 when it is a layout button or not found.
|
||||
@ -22,20 +33,4 @@ namespace TelegramBotBase.Args
|
||||
/// Contains the new checked status of the row.
|
||||
/// </summary>
|
||||
public bool Checked { get; set; }
|
||||
|
||||
|
||||
public CheckedChangedEventArgs()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public CheckedChangedEventArgs(ButtonRow row, int index, bool @checked)
|
||||
{
|
||||
Row = row;
|
||||
this.Index = index;
|
||||
this.Checked = @checked;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -2,21 +2,17 @@
|
||||
using Telegram.Bot.Types.Enums;
|
||||
using TelegramBotBase.Base;
|
||||
|
||||
namespace TelegramBotBase.Args
|
||||
{
|
||||
namespace TelegramBotBase.Args;
|
||||
|
||||
public class GroupChangedEventArgs : EventArgs
|
||||
{
|
||||
public MessageType Type { get; set; }
|
||||
|
||||
public MessageResult OriginalMessage { get; set; }
|
||||
|
||||
public GroupChangedEventArgs(MessageType type, MessageResult message)
|
||||
{
|
||||
Type = type;
|
||||
OriginalMessage = message;
|
||||
}
|
||||
|
||||
public MessageType Type { get; set; }
|
||||
|
||||
|
||||
}
|
||||
public MessageResult OriginalMessage { get; set; }
|
||||
}
|
||||
@ -1,14 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace TelegramBotBase.Args
|
||||
{
|
||||
namespace TelegramBotBase.Args;
|
||||
|
||||
public class InitEventArgs : EventArgs
|
||||
{
|
||||
public object[] Args { get; set; }
|
||||
|
||||
public InitEventArgs(params object[] args)
|
||||
{
|
||||
Args = args;
|
||||
}
|
||||
}
|
||||
|
||||
public object[] Args { get; set; }
|
||||
}
|
||||
@ -1,17 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace TelegramBotBase.Args
|
||||
{
|
||||
namespace TelegramBotBase.Args;
|
||||
|
||||
public class LoadStateEventArgs
|
||||
{
|
||||
public Dictionary<string,object> Values { get; set; }
|
||||
|
||||
public LoadStateEventArgs()
|
||||
{
|
||||
Values = new Dictionary<string, object>();
|
||||
}
|
||||
|
||||
public Dictionary<string, object> Values { get; set; }
|
||||
|
||||
public List<string> Keys => Values.Keys.ToList();
|
||||
|
||||
public string Get(string key)
|
||||
@ -23,7 +23,9 @@ namespace TelegramBotBase.Args
|
||||
{
|
||||
var i = 0;
|
||||
if (int.TryParse(Values[key].ToString(), out i))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -32,7 +34,9 @@ namespace TelegramBotBase.Args
|
||||
{
|
||||
double d = 0;
|
||||
if (double.TryParse(Values[key].ToString(), out d))
|
||||
{
|
||||
return d;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -41,7 +45,9 @@ namespace TelegramBotBase.Args
|
||||
{
|
||||
var b = false;
|
||||
if (bool.TryParse(Values[key].ToString(), out b))
|
||||
{
|
||||
return b;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -50,6 +56,4 @@ namespace TelegramBotBase.Args
|
||||
{
|
||||
return Values[key];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -5,20 +5,13 @@ using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
using TelegramBotBase.Base;
|
||||
|
||||
namespace TelegramBotBase.Args
|
||||
{
|
||||
namespace TelegramBotBase.Args;
|
||||
|
||||
public class MemberChangeEventArgs : EventArgs
|
||||
{
|
||||
public List<User> Members { get; set; }
|
||||
|
||||
public MessageType Type { get; set; }
|
||||
|
||||
public MessageResult Result { get; set; }
|
||||
|
||||
public MemberChangeEventArgs()
|
||||
{
|
||||
Members = new List<User>();
|
||||
|
||||
}
|
||||
|
||||
public MemberChangeEventArgs(MessageType type, MessageResult result, params User[] members)
|
||||
@ -28,9 +21,9 @@ namespace TelegramBotBase.Args
|
||||
Members = members.ToList();
|
||||
}
|
||||
|
||||
public List<User> Members { get; set; }
|
||||
|
||||
public MessageType Type { get; set; }
|
||||
|
||||
|
||||
|
||||
}
|
||||
public MessageResult Result { get; set; }
|
||||
}
|
||||
@ -1,16 +1,11 @@
|
||||
namespace TelegramBotBase.Args
|
||||
{
|
||||
namespace TelegramBotBase.Args;
|
||||
|
||||
public class MessageDeletedEventArgs
|
||||
{
|
||||
public int MessageId
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
|
||||
public MessageDeletedEventArgs(int messageId)
|
||||
{
|
||||
MessageId = messageId;
|
||||
}
|
||||
|
||||
}
|
||||
public int MessageId { get; set; }
|
||||
}
|
||||
@ -1,26 +1,20 @@
|
||||
using System;
|
||||
using TelegramBotBase.Sessions;
|
||||
|
||||
namespace TelegramBotBase.Base
|
||||
{
|
||||
namespace TelegramBotBase.Base;
|
||||
|
||||
public class MessageIncomeEventArgs : EventArgs
|
||||
{
|
||||
public MessageIncomeEventArgs(long deviceId, DeviceSession device, MessageResult message)
|
||||
{
|
||||
DeviceId = deviceId;
|
||||
Device = device;
|
||||
Message = message;
|
||||
}
|
||||
|
||||
public long DeviceId { get; set; }
|
||||
|
||||
public DeviceSession Device { get; set; }
|
||||
|
||||
public MessageResult Message { get; set; }
|
||||
|
||||
public MessageIncomeEventArgs(long deviceId, DeviceSession device, MessageResult message)
|
||||
{
|
||||
this.DeviceId = deviceId;
|
||||
this.Device = device;
|
||||
Message = message;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,17 +1,15 @@
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace TelegramBotBase.Args
|
||||
{
|
||||
namespace TelegramBotBase.Args;
|
||||
|
||||
public class MessageReceivedEventArgs
|
||||
{
|
||||
public int MessageId => Message.MessageId;
|
||||
|
||||
public Message Message { get; set; }
|
||||
|
||||
public MessageReceivedEventArgs(Message m)
|
||||
{
|
||||
Message = m;
|
||||
}
|
||||
|
||||
}
|
||||
public int MessageId => Message.MessageId;
|
||||
|
||||
public Message Message { get; set; }
|
||||
}
|
||||
@ -1,10 +1,16 @@
|
||||
using System;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace TelegramBotBase.Args
|
||||
{
|
||||
namespace TelegramBotBase.Args;
|
||||
|
||||
public class MessageSentEventArgs : EventArgs
|
||||
{
|
||||
public MessageSentEventArgs(Message message, Type origin)
|
||||
{
|
||||
Message = message;
|
||||
Origin = origin;
|
||||
}
|
||||
|
||||
public int MessageId => Message.MessageId;
|
||||
|
||||
public Message Message { get; set; }
|
||||
@ -13,14 +19,4 @@ namespace TelegramBotBase.Args
|
||||
/// Contains the element, which has called the method.
|
||||
/// </summary>
|
||||
public Type Origin { get; set; }
|
||||
|
||||
|
||||
public MessageSentEventArgs(Message message, Type origin)
|
||||
{
|
||||
Message = message;
|
||||
this.Origin = origin;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,8 @@
|
||||
namespace TelegramBotBase.Args
|
||||
{
|
||||
namespace TelegramBotBase.Args;
|
||||
|
||||
public class PromptDialogCompletedEventArgs
|
||||
{
|
||||
public object Tag { get; set; }
|
||||
|
||||
public string Value { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,18 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace TelegramBotBase.Args
|
||||
{
|
||||
namespace TelegramBotBase.Args;
|
||||
|
||||
public class RenderViewEventArgs : EventArgs
|
||||
{
|
||||
public int CurrentView { get; set; }
|
||||
|
||||
|
||||
public RenderViewEventArgs(int viewIndex)
|
||||
{
|
||||
|
||||
CurrentView = viewIndex;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public int CurrentView { get; set; }
|
||||
}
|
||||
@ -1,16 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TelegramBotBase.Args
|
||||
{
|
||||
namespace TelegramBotBase.Args;
|
||||
|
||||
public class SaveStateEventArgs
|
||||
{
|
||||
public Dictionary<string, object> Values { get; set; }
|
||||
|
||||
public SaveStateEventArgs()
|
||||
{
|
||||
Values = new Dictionary<string, object>();
|
||||
}
|
||||
|
||||
public Dictionary<string, object> Values { get; set; }
|
||||
|
||||
public void Set(string key, string value)
|
||||
{
|
||||
Values[key] = value;
|
||||
@ -30,10 +30,9 @@ namespace TelegramBotBase.Args
|
||||
{
|
||||
Values[key] = value;
|
||||
}
|
||||
|
||||
public void SetObject(string key, object value)
|
||||
{
|
||||
Values[key] = value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,15 +1,13 @@
|
||||
using TelegramBotBase.Base;
|
||||
|
||||
namespace TelegramBotBase.Args
|
||||
{
|
||||
namespace TelegramBotBase.Args;
|
||||
|
||||
public class SaveStatesEventArgs
|
||||
{
|
||||
public StateContainer States { get; set; }
|
||||
|
||||
|
||||
public SaveStatesEventArgs(StateContainer states)
|
||||
{
|
||||
States = states;
|
||||
}
|
||||
}
|
||||
|
||||
public StateContainer States { get; set; }
|
||||
}
|
||||
@ -1,18 +1,17 @@
|
||||
using System;
|
||||
using TelegramBotBase.Sessions;
|
||||
|
||||
namespace TelegramBotBase.Base
|
||||
{
|
||||
namespace TelegramBotBase.Base;
|
||||
|
||||
public class SessionBeginEventArgs : EventArgs
|
||||
{
|
||||
public SessionBeginEventArgs(long deviceId, DeviceSession device)
|
||||
{
|
||||
DeviceId = deviceId;
|
||||
Device = device;
|
||||
}
|
||||
|
||||
public long DeviceId { get; set; }
|
||||
|
||||
public DeviceSession Device { get; set; }
|
||||
|
||||
public SessionBeginEventArgs(long deviceId, DeviceSession device)
|
||||
{
|
||||
this.DeviceId = deviceId;
|
||||
this.Device = device;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,21 @@
|
||||
using System;
|
||||
using TelegramBotBase.Sessions;
|
||||
|
||||
namespace TelegramBotBase.Args
|
||||
{
|
||||
namespace TelegramBotBase.Args;
|
||||
|
||||
public class SystemExceptionEventArgs : EventArgs
|
||||
{
|
||||
public SystemExceptionEventArgs()
|
||||
{
|
||||
}
|
||||
|
||||
public SystemExceptionEventArgs(string command, long deviceId, DeviceSession device, Exception error)
|
||||
{
|
||||
Command = command;
|
||||
DeviceId = deviceId;
|
||||
Device = device;
|
||||
Error = error;
|
||||
}
|
||||
|
||||
public string Command { get; set; }
|
||||
|
||||
@ -13,20 +24,4 @@ namespace TelegramBotBase.Args
|
||||
public DeviceSession Device { get; set; }
|
||||
|
||||
public Exception Error { get; set; }
|
||||
|
||||
public SystemExceptionEventArgs()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public SystemExceptionEventArgs(string command, long deviceId, DeviceSession device, Exception error)
|
||||
{
|
||||
this.Command = command;
|
||||
this.DeviceId = deviceId;
|
||||
this.Device = device;
|
||||
Error = error;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,10 +2,26 @@
|
||||
using Telegram.Bot.Types;
|
||||
using TelegramBotBase.Sessions;
|
||||
|
||||
namespace TelegramBotBase.Args
|
||||
{
|
||||
namespace TelegramBotBase.Args;
|
||||
|
||||
public class UnhandledCallEventArgs : EventArgs
|
||||
{
|
||||
public UnhandledCallEventArgs()
|
||||
{
|
||||
Handled = false;
|
||||
}
|
||||
|
||||
public UnhandledCallEventArgs(string command, string rawData, long deviceId, int messageId, Message message,
|
||||
DeviceSession device) : this()
|
||||
{
|
||||
Command = command;
|
||||
RawData = rawData;
|
||||
DeviceId = deviceId;
|
||||
MessageId = messageId;
|
||||
Message = message;
|
||||
Device = device;
|
||||
}
|
||||
|
||||
public string Command { get; set; }
|
||||
|
||||
public long DeviceId { get; set; }
|
||||
@ -19,23 +35,4 @@ namespace TelegramBotBase.Args
|
||||
public Message Message { get; set; }
|
||||
|
||||
public bool Handled { get; set; }
|
||||
|
||||
|
||||
public UnhandledCallEventArgs()
|
||||
{
|
||||
Handled = false;
|
||||
|
||||
}
|
||||
|
||||
public UnhandledCallEventArgs(string command,string rawData, long deviceId, int messageId, Message message, DeviceSession device) : this()
|
||||
{
|
||||
this.Command = command;
|
||||
this.RawData = rawData;
|
||||
this.DeviceId = deviceId;
|
||||
this.MessageId = messageId;
|
||||
Message = message;
|
||||
this.Device = device;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace TelegramBotBase.Attributes
|
||||
{
|
||||
namespace TelegramBotBase.Attributes;
|
||||
|
||||
/// <summary>
|
||||
/// Declares that this class should not be getting serialized
|
||||
@ -9,7 +8,4 @@ namespace TelegramBotBase.Attributes
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class IgnoreState : Attribute
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,13 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace TelegramBotBase.Attributes
|
||||
{
|
||||
namespace TelegramBotBase.Attributes;
|
||||
|
||||
/// <summary>
|
||||
/// Declares that the field or property should be save and recovered an restart.
|
||||
/// </summary>
|
||||
public class SaveState : Attribute
|
||||
{
|
||||
public string Key { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@ -3,8 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TelegramBotBase.Base
|
||||
{
|
||||
namespace TelegramBotBase.Base;
|
||||
|
||||
public static class Async
|
||||
{
|
||||
public delegate Task AsyncEventHandler<TEventArgs>(object sender, TEventArgs e) where TEventArgs : EventArgs;
|
||||
@ -12,13 +12,16 @@ namespace TelegramBotBase.Base
|
||||
public static IEnumerable<AsyncEventHandler<TEventArgs>> GetHandlers<TEventArgs>(
|
||||
this AsyncEventHandler<TEventArgs> handler)
|
||||
where TEventArgs : EventArgs
|
||||
=> handler.GetInvocationList().Cast<AsyncEventHandler<TEventArgs>>();
|
||||
{
|
||||
return handler.GetInvocationList().Cast<AsyncEventHandler<TEventArgs>>();
|
||||
}
|
||||
|
||||
public static Task InvokeAllAsync<TEventArgs>(this AsyncEventHandler<TEventArgs> handler, object sender, TEventArgs e)
|
||||
public static Task InvokeAllAsync<TEventArgs>(this AsyncEventHandler<TEventArgs> handler, object sender,
|
||||
TEventArgs e)
|
||||
where TEventArgs : EventArgs
|
||||
=> Task.WhenAll(
|
||||
{
|
||||
return Task.WhenAll(
|
||||
handler.GetHandlers()
|
||||
.Select(handleAsync => handleAsync(sender, e)));
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,8 @@
|
||||
using System.Threading.Tasks;
|
||||
using TelegramBotBase.Sessions;
|
||||
|
||||
namespace TelegramBotBase.Base
|
||||
{
|
||||
namespace TelegramBotBase.Base;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for controls
|
||||
/// </summary>
|
||||
@ -25,7 +25,6 @@ namespace TelegramBotBase.Base
|
||||
/// <returns></returns>
|
||||
public virtual void Init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual Task Load(MessageResult result)
|
||||
@ -39,7 +38,6 @@ namespace TelegramBotBase.Base
|
||||
}
|
||||
|
||||
|
||||
|
||||
public virtual Task Render(MessageResult result)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
@ -58,6 +56,4 @@ namespace TelegramBotBase.Base
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -7,13 +7,17 @@ using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
using Telegram.Bot.Types.InputFiles;
|
||||
|
||||
namespace TelegramBotBase.Base
|
||||
{
|
||||
namespace TelegramBotBase.Base;
|
||||
|
||||
/// <summary>
|
||||
/// Returns a class to manage attachments within messages.
|
||||
/// </summary>
|
||||
public class DataResult : ResultBase
|
||||
{
|
||||
public DataResult(UpdateResult update)
|
||||
{
|
||||
UpdateData = update;
|
||||
}
|
||||
|
||||
//public Telegram.Bot.Args.MessageEventArgs RawMessageData { get; set; }
|
||||
|
||||
@ -41,22 +45,18 @@ namespace TelegramBotBase.Base
|
||||
/// Returns the FileId of the first reachable element.
|
||||
/// </summary>
|
||||
public string FileId =>
|
||||
(Document?.FileId ??
|
||||
Document?.FileId ??
|
||||
Audio?.FileId ??
|
||||
Video?.FileId ??
|
||||
Photos.FirstOrDefault()?.FileId);
|
||||
|
||||
public DataResult(UpdateResult update)
|
||||
{
|
||||
UpdateData = update;
|
||||
}
|
||||
Photos.FirstOrDefault()?.FileId;
|
||||
|
||||
|
||||
public async Task<InputOnlineFile> DownloadDocument()
|
||||
{
|
||||
var encryptedContent = new MemoryStream();
|
||||
encryptedContent.SetLength(Document.FileSize.Value);
|
||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Document.FileId, encryptedContent);
|
||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Document.FileId,
|
||||
encryptedContent);
|
||||
|
||||
return new InputOnlineFile(encryptedContent, Document.FileName);
|
||||
}
|
||||
@ -167,6 +167,4 @@ namespace TelegramBotBase.Base
|
||||
fs.Close();
|
||||
fs.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -9,13 +9,32 @@ using TelegramBotBase.Form.Navigation;
|
||||
using TelegramBotBase.Sessions;
|
||||
using static TelegramBotBase.Base.Async;
|
||||
|
||||
namespace TelegramBotBase.Form
|
||||
{
|
||||
namespace TelegramBotBase.Form;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for forms
|
||||
/// </summary>
|
||||
public class FormBase : IDisposable
|
||||
{
|
||||
private static readonly object EvInit = new();
|
||||
|
||||
private static readonly object EvOpened = new();
|
||||
|
||||
private static readonly object EvClosed = new();
|
||||
|
||||
|
||||
public EventHandlerList Events = new();
|
||||
|
||||
|
||||
public FormBase()
|
||||
{
|
||||
Controls = new List<ControlBase>();
|
||||
}
|
||||
|
||||
public FormBase(MessageClient client) : this()
|
||||
{
|
||||
Client = client;
|
||||
}
|
||||
|
||||
public NavigationController NavigationController { get; set; }
|
||||
|
||||
@ -30,25 +49,14 @@ namespace TelegramBotBase.Form
|
||||
|
||||
public List<ControlBase> Controls { get; set; }
|
||||
|
||||
|
||||
public EventHandlerList Events = new EventHandlerList();
|
||||
|
||||
|
||||
private static readonly object EvInit = new object();
|
||||
|
||||
private static readonly object EvOpened = new object();
|
||||
|
||||
private static readonly object EvClosed = new object();
|
||||
|
||||
|
||||
public FormBase()
|
||||
/// <summary>
|
||||
/// Cleanup
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Controls = new List<ControlBase>();
|
||||
}
|
||||
|
||||
public FormBase(MessageClient client) : this()
|
||||
{
|
||||
this.Client = client;
|
||||
Client = null;
|
||||
Device = null;
|
||||
IsDisposed = true;
|
||||
}
|
||||
|
||||
|
||||
@ -56,7 +64,9 @@ namespace TelegramBotBase.Form
|
||||
{
|
||||
var handler = Events[EvInit]?.GetInvocationList().Cast<AsyncEventHandler<InitEventArgs>>();
|
||||
if (handler == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var h in handler)
|
||||
{
|
||||
@ -74,12 +84,13 @@ namespace TelegramBotBase.Form
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task OnOpened(EventArgs e)
|
||||
{
|
||||
var handler = Events[EvOpened]?.GetInvocationList().Cast<AsyncEventHandler<EventArgs>>();
|
||||
if (handler == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var h in handler)
|
||||
{
|
||||
@ -98,12 +109,13 @@ namespace TelegramBotBase.Form
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task OnClosed(EventArgs e)
|
||||
{
|
||||
var handler = Events[EvClosed]?.GetInvocationList().Cast<AsyncEventHandler<EventArgs>>();
|
||||
if (handler == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var h in handler)
|
||||
{
|
||||
@ -173,7 +185,9 @@ namespace TelegramBotBase.Form
|
||||
foreach (var b in Controls)
|
||||
{
|
||||
if (!b.Enabled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
await b.Load(message);
|
||||
}
|
||||
@ -221,14 +235,18 @@ namespace TelegramBotBase.Form
|
||||
foreach (var b in Controls)
|
||||
{
|
||||
if (!b.Enabled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
await b.Action(message);
|
||||
|
||||
if (message.Handled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets invoked if the user has clicked a button.
|
||||
@ -260,7 +278,9 @@ namespace TelegramBotBase.Form
|
||||
foreach (var b in Controls)
|
||||
{
|
||||
if (!b.Enabled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
await b.Render(message);
|
||||
}
|
||||
@ -277,7 +297,6 @@ namespace TelegramBotBase.Form
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Navigates to a new form
|
||||
/// </summary>
|
||||
@ -287,7 +306,9 @@ namespace TelegramBotBase.Form
|
||||
{
|
||||
var ds = Device;
|
||||
if (ds == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ds.FormSwitched = true;
|
||||
|
||||
@ -301,7 +322,9 @@ namespace TelegramBotBase.Form
|
||||
foreach (var b in Controls)
|
||||
{
|
||||
if (!b.Enabled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
await b.Hidden(true);
|
||||
}
|
||||
@ -324,7 +347,9 @@ namespace TelegramBotBase.Form
|
||||
{
|
||||
var ds = Device;
|
||||
if (ds == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var parentForm = this;
|
||||
|
||||
@ -337,15 +362,14 @@ namespace TelegramBotBase.Form
|
||||
newForm.Device = ds;
|
||||
newForm.ParentForm = parentForm;
|
||||
|
||||
newForm.Closed += async (s, en) =>
|
||||
{
|
||||
await CloseModal(newForm, parentForm);
|
||||
};
|
||||
newForm.Closed += async (s, en) => { await CloseModal(newForm, parentForm); };
|
||||
|
||||
foreach (var b in Controls)
|
||||
{
|
||||
if (!b.Enabled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
await b.Hidden(false);
|
||||
}
|
||||
@ -359,10 +383,14 @@ namespace TelegramBotBase.Form
|
||||
{
|
||||
var ds = Device;
|
||||
if (ds == null)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
if (modalForm == null)
|
||||
{
|
||||
throw new Exception("No modal form");
|
||||
}
|
||||
|
||||
ds.FormSwitched = true;
|
||||
|
||||
@ -380,7 +408,9 @@ namespace TelegramBotBase.Form
|
||||
{
|
||||
//Duplicate check
|
||||
if (Controls.Contains(control))
|
||||
{
|
||||
throw new ArgumentException("Control has been already added.");
|
||||
}
|
||||
|
||||
control.Id = Controls.Count + 1;
|
||||
control.Device = Device;
|
||||
@ -396,7 +426,9 @@ namespace TelegramBotBase.Form
|
||||
public void RemoveControl(ControlBase control)
|
||||
{
|
||||
if (!Controls.Contains(control))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
control.Cleanup().Wait();
|
||||
|
||||
@ -415,15 +447,4 @@ namespace TelegramBotBase.Form
|
||||
Controls.Remove(c);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cleanup
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Client = null;
|
||||
Device = null;
|
||||
IsDisposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -10,35 +10,27 @@ using Telegram.Bot.Exceptions;
|
||||
using Telegram.Bot.Extensions.Polling;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace TelegramBotBase.Base
|
||||
{
|
||||
namespace TelegramBotBase.Base;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for message handling
|
||||
/// </summary>
|
||||
public class MessageClient
|
||||
{
|
||||
private static readonly object EvOnMessageLoop = new();
|
||||
|
||||
private static object __evOnMessage = new();
|
||||
|
||||
public string ApiKey { get; set; }
|
||||
private static object __evOnMessageEdit = new();
|
||||
|
||||
public ITelegramBotClient TelegramClient { get; set; }
|
||||
|
||||
private EventHandlerList Events { get; set; } = new EventHandlerList();
|
||||
|
||||
private static readonly object EvOnMessageLoop = new object();
|
||||
|
||||
private static object __evOnMessage = new object();
|
||||
|
||||
private static object __evOnMessageEdit = new object();
|
||||
|
||||
private static object __evCallbackQuery = new object();
|
||||
private static object __evCallbackQuery = new();
|
||||
|
||||
private CancellationTokenSource _cancellationTokenSource;
|
||||
|
||||
|
||||
public MessageClient(string apiKey)
|
||||
{
|
||||
this.ApiKey = apiKey;
|
||||
ApiKey = apiKey;
|
||||
TelegramClient = new TelegramBotClient(apiKey);
|
||||
|
||||
Prepare();
|
||||
@ -46,7 +38,7 @@ namespace TelegramBotBase.Base
|
||||
|
||||
public MessageClient(string apiKey, HttpClient proxy)
|
||||
{
|
||||
this.ApiKey = apiKey;
|
||||
ApiKey = apiKey;
|
||||
TelegramClient = new TelegramBotClient(apiKey, proxy);
|
||||
|
||||
|
||||
@ -54,10 +46,9 @@ namespace TelegramBotBase.Base
|
||||
}
|
||||
|
||||
|
||||
|
||||
public MessageClient(string apiKey, Uri proxyUrl, NetworkCredential credential = null)
|
||||
{
|
||||
this.ApiKey = apiKey;
|
||||
ApiKey = apiKey;
|
||||
|
||||
var proxy = new WebProxy(proxyUrl)
|
||||
{
|
||||
@ -81,7 +72,7 @@ namespace TelegramBotBase.Base
|
||||
/// <param name="proxyPort">i.e. 10000</param>
|
||||
public MessageClient(string apiKey, string proxyHost, int proxyPort)
|
||||
{
|
||||
this.ApiKey = apiKey;
|
||||
ApiKey = apiKey;
|
||||
|
||||
var proxy = new WebProxy(proxyHost, proxyPort);
|
||||
|
||||
@ -95,31 +86,36 @@ namespace TelegramBotBase.Base
|
||||
}
|
||||
|
||||
|
||||
|
||||
public MessageClient(string apiKey, TelegramBotClient client)
|
||||
{
|
||||
this.ApiKey = apiKey;
|
||||
ApiKey = apiKey;
|
||||
TelegramClient = client;
|
||||
|
||||
Prepare();
|
||||
}
|
||||
|
||||
|
||||
public string ApiKey { get; set; }
|
||||
|
||||
public ITelegramBotClient TelegramClient { get; set; }
|
||||
|
||||
private EventHandlerList Events { get; } = new();
|
||||
|
||||
|
||||
public void Prepare()
|
||||
{
|
||||
TelegramClient.Timeout = new TimeSpan(0, 0, 30);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void StartReceiving()
|
||||
{
|
||||
_cancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
var receiverOptions = new ReceiverOptions();
|
||||
|
||||
TelegramClient.StartReceiving(HandleUpdateAsync, HandleErrorAsync, receiverOptions, _cancellationTokenSource.Token);
|
||||
TelegramClient.StartReceiving(HandleUpdateAsync, HandleErrorAsync, receiverOptions,
|
||||
_cancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
public void StopReceiving()
|
||||
@ -135,7 +131,8 @@ namespace TelegramBotBase.Base
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception, CancellationToken cancellationToken)
|
||||
public Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (exception is ApiRequestException exApi)
|
||||
{
|
||||
@ -145,6 +142,7 @@ namespace TelegramBotBase.Base
|
||||
{
|
||||
Console.WriteLine(exception.ToString());
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@ -164,7 +162,8 @@ namespace TelegramBotBase.Base
|
||||
/// </summary>
|
||||
/// <param name="botcommands"></param>
|
||||
/// <returns></returns>
|
||||
public async Task SetBotCommands(List<BotCommand> botcommands, BotCommandScope scope = null, string languageCode = null)
|
||||
public async Task SetBotCommands(List<BotCommand> botcommands, BotCommandScope scope = null,
|
||||
string languageCode = null)
|
||||
{
|
||||
await TelegramClient.SetMyCommandsAsync(botcommands, scope, languageCode);
|
||||
}
|
||||
@ -181,8 +180,6 @@ namespace TelegramBotBase.Base
|
||||
|
||||
#region "Events"
|
||||
|
||||
|
||||
|
||||
public event Async.AsyncEventHandler<UpdateResult> MessageLoop
|
||||
{
|
||||
add => Events.AddHandler(EvOnMessageLoop, value);
|
||||
@ -194,9 +191,5 @@ namespace TelegramBotBase.Base
|
||||
(Events[EvOnMessageLoop] as Async.AsyncEventHandler<UpdateResult>)?.Invoke(this, update);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -5,10 +5,18 @@ using Newtonsoft.Json;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
|
||||
namespace TelegramBotBase.Base
|
||||
{
|
||||
namespace TelegramBotBase.Base;
|
||||
|
||||
public class MessageResult : ResultBase
|
||||
{
|
||||
internal MessageResult()
|
||||
{
|
||||
}
|
||||
|
||||
public MessageResult(Update update)
|
||||
{
|
||||
UpdateData = update;
|
||||
}
|
||||
|
||||
public Update UpdateData { get; set; }
|
||||
|
||||
@ -40,22 +48,25 @@ namespace TelegramBotBase.Base
|
||||
/// <summary>
|
||||
/// Is this an action ? (i.e. button click)
|
||||
/// </summary>
|
||||
public bool IsAction => (UpdateData.CallbackQuery != null);
|
||||
public bool IsAction => UpdateData.CallbackQuery != null;
|
||||
|
||||
/// <summary>
|
||||
/// Is this a command ? Starts with a slash '/' and a command
|
||||
/// </summary>
|
||||
public bool IsBotCommand => (MessageText.StartsWith("/"));
|
||||
public bool IsBotCommand => MessageText.StartsWith("/");
|
||||
|
||||
/// <summary>
|
||||
/// Returns a List of all parameters which has been sent with the command itself (i.e. /start 123 456 789 => 123,456,789)
|
||||
/// Returns a List of all parameters which has been sent with the command itself (i.e. /start 123 456 789 =>
|
||||
/// 123,456,789)
|
||||
/// </summary>
|
||||
public List<string> BotCommandParameters
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!IsBotCommand)
|
||||
{
|
||||
return new List<string>();
|
||||
}
|
||||
|
||||
//Split by empty space and skip first entry (command itself), return as list
|
||||
return MessageText.Split(' ').Skip(1).ToList();
|
||||
@ -70,7 +81,9 @@ namespace TelegramBotBase.Base
|
||||
get
|
||||
{
|
||||
if (!IsBotCommand)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return MessageText.Split(' ')[0];
|
||||
}
|
||||
@ -97,7 +110,6 @@ namespace TelegramBotBase.Base
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -121,20 +133,6 @@ namespace TelegramBotBase.Base
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
internal MessageResult()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public MessageResult(Update update)
|
||||
{
|
||||
UpdateData = update;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,15 +4,11 @@ using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
using TelegramBotBase.Sessions;
|
||||
|
||||
namespace TelegramBotBase.Base
|
||||
{
|
||||
namespace TelegramBotBase.Base;
|
||||
|
||||
public class ResultBase : EventArgs
|
||||
{
|
||||
public DeviceSession Device
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public DeviceSession Device { get; set; }
|
||||
|
||||
public virtual long DeviceId { get; set; }
|
||||
|
||||
@ -39,13 +35,11 @@ namespace TelegramBotBase.Base
|
||||
{
|
||||
try
|
||||
{
|
||||
await Device.Client.TelegramClient.DeleteMessageAsync(DeviceId, (messageId == -1 ? MessageId : messageId));
|
||||
await Device.Client.TelegramClient.DeleteMessageAsync(DeviceId,
|
||||
messageId == -1 ? MessageId : messageId);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,32 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace TelegramBotBase.Base
|
||||
{
|
||||
namespace TelegramBotBase.Base;
|
||||
|
||||
public class StateContainer
|
||||
{
|
||||
public List<StateEntry> States { get; set; }
|
||||
|
||||
public List<long> ChatIds
|
||||
{
|
||||
get
|
||||
{
|
||||
return States.Where(a => a.DeviceId > 0).Select(a => a.DeviceId).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public List<long> GroupIds
|
||||
{
|
||||
get
|
||||
{
|
||||
return States.Where(a => a.DeviceId < 0).Select(a => a.DeviceId).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public StateContainer()
|
||||
{
|
||||
States = new List<StateEntry>();
|
||||
}
|
||||
|
||||
public List<StateEntry> States { get; set; }
|
||||
|
||||
public List<long> ChatIds
|
||||
{
|
||||
get { return States.Where(a => a.DeviceId > 0).Select(a => a.DeviceId).ToList(); }
|
||||
}
|
||||
|
||||
public List<long> GroupIds
|
||||
{
|
||||
get { return States.Where(a => a.DeviceId < 0).Select(a => a.DeviceId).ToList(); }
|
||||
}
|
||||
}
|
||||
@ -1,12 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace TelegramBotBase.Base
|
||||
{
|
||||
namespace TelegramBotBase.Base;
|
||||
|
||||
[DebuggerDisplay("Device: {DeviceId}, {FormUri}")]
|
||||
public class StateEntry
|
||||
{
|
||||
public StateEntry()
|
||||
{
|
||||
Values = new Dictionary<string, object>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains the DeviceId of the entry.
|
||||
/// </summary>
|
||||
@ -31,11 +35,4 @@ namespace TelegramBotBase.Base
|
||||
/// Contains the assembly, where to find that form.
|
||||
/// </summary>
|
||||
public string QualifiedName { get; set; }
|
||||
|
||||
public StateEntry()
|
||||
{
|
||||
Values = new Dictionary<string, object>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,16 +1,14 @@
|
||||
using Telegram.Bot.Types;
|
||||
using TelegramBotBase.Sessions;
|
||||
|
||||
namespace TelegramBotBase.Base
|
||||
{
|
||||
namespace TelegramBotBase.Base;
|
||||
|
||||
public class UpdateResult : ResultBase
|
||||
{
|
||||
public UpdateResult(Update rawData, DeviceSession device)
|
||||
{
|
||||
RawData = rawData;
|
||||
Device = device;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -31,5 +29,3 @@ namespace TelegramBotBase.Base
|
||||
?? RawData?.EditedChannelPost
|
||||
?? RawData?.CallbackQuery?.Message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2,30 +2,42 @@
|
||||
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;
|
||||
using Console = TelegramBotBase.Tools.Console;
|
||||
|
||||
namespace TelegramBotBase;
|
||||
|
||||
namespace TelegramBotBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Bot base class for full Device/Context and Messagehandling
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class BotBase
|
||||
{
|
||||
public BotBase()
|
||||
{
|
||||
SystemSettings = new Dictionary<ESettings, uint>();
|
||||
|
||||
SetSetting(ESettings.MaxNumberOfRetries, 5);
|
||||
SetSetting(ESettings.NavigationMaximum, 10);
|
||||
SetSetting(ESettings.LogAllMessages, false);
|
||||
SetSetting(ESettings.SkipAllMessages, false);
|
||||
SetSetting(ESettings.SaveSessionsOnConsoleExit, false);
|
||||
|
||||
BotCommandScopes = new Dictionary<BotCommandScope, List<BotCommand>>();
|
||||
|
||||
Sessions = new SessionBase
|
||||
{
|
||||
BotBase = this
|
||||
};
|
||||
}
|
||||
|
||||
public MessageClient Client { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@ -41,26 +53,7 @@ namespace TelegramBotBase
|
||||
/// <summary>
|
||||
/// Contains System commands which will be available at everytime and didnt get passed to forms, i.e. /start
|
||||
/// </summary>
|
||||
public Dictionary<BotCommandScope, List<BotCommand>> BotCommandScopes { get; set; } = new Dictionary<BotCommandScope, List<BotCommand>>();
|
||||
|
||||
|
||||
#region "Events"
|
||||
|
||||
private readonly EventHandlerList _events = new EventHandlerList();
|
||||
|
||||
private static readonly object EvSessionBegins = new object();
|
||||
|
||||
private static readonly object EvMessage = new object();
|
||||
|
||||
private static object __evSystemCall = new object();
|
||||
|
||||
public delegate Task BotCommandEventHandler(object sender, BotCommandEventArgs e);
|
||||
|
||||
private static readonly object EvException = new object();
|
||||
|
||||
private static readonly object EvUnhandledCall = new object();
|
||||
|
||||
#endregion
|
||||
public Dictionary<BotCommandScope, List<BotCommand>> BotCommandScopes { get; set; } = new();
|
||||
|
||||
|
||||
/// <summary>
|
||||
@ -81,26 +74,7 @@ namespace TelegramBotBase
|
||||
/// <summary>
|
||||
/// All internal used settings.
|
||||
/// </summary>
|
||||
public Dictionary<ESettings, uint> SystemSettings { get; private set; }
|
||||
|
||||
public BotBase()
|
||||
{
|
||||
SystemSettings = new Dictionary<ESettings, uint>();
|
||||
|
||||
SetSetting(ESettings.MaxNumberOfRetries, 5);
|
||||
SetSetting(ESettings.NavigationMaximum, 10);
|
||||
SetSetting(ESettings.LogAllMessages, false);
|
||||
SetSetting(ESettings.SkipAllMessages, false);
|
||||
SetSetting(ESettings.SaveSessionsOnConsoleExit, false);
|
||||
|
||||
BotCommandScopes = new Dictionary<BotCommandScope, List<BotCommand>>();
|
||||
|
||||
Sessions = new SessionBase
|
||||
{
|
||||
BotBase = this
|
||||
};
|
||||
}
|
||||
|
||||
public Dictionary<ESettings, uint> SystemSettings { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
@ -109,7 +83,9 @@ namespace TelegramBotBase
|
||||
public void Start()
|
||||
{
|
||||
if (Client == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Client.MessageLoop += Client_MessageLoop;
|
||||
|
||||
@ -122,10 +98,7 @@ namespace TelegramBotBase
|
||||
//Enable auto session saving
|
||||
if (GetSetting(ESettings.SaveSessionsOnConsoleExit, false))
|
||||
{
|
||||
Tools.Console.SetHandler(() =>
|
||||
{
|
||||
Sessions.SaveSessionStates();
|
||||
});
|
||||
Console.SetHandler(() => { Sessions.SaveSessionStates(); });
|
||||
}
|
||||
|
||||
DeviceSession.MaxNumberOfRetries = GetSetting(ESettings.MaxNumberOfRetries, 5);
|
||||
@ -161,7 +134,6 @@ namespace TelegramBotBase
|
||||
await MessageLoopFactory.MessageLoop(this, ds, e, mr);
|
||||
|
||||
mr.IsFirstHandler = false;
|
||||
|
||||
} while (ds.FormSwitched && i < GetSetting(ESettings.NavigationMaximum, 10));
|
||||
}
|
||||
|
||||
@ -172,7 +144,9 @@ namespace TelegramBotBase
|
||||
public void Stop()
|
||||
{
|
||||
if (Client == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Client.MessageLoop -= Client_MessageLoop;
|
||||
|
||||
@ -190,7 +164,9 @@ namespace TelegramBotBase
|
||||
public async Task SentToAll(string message)
|
||||
{
|
||||
if (Client == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var s in Sessions.SessionList)
|
||||
{
|
||||
@ -199,16 +175,16 @@ namespace TelegramBotBase
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This will invoke the full message loop for the device even when no "userevent" like message or action has been raised.
|
||||
/// This will invoke the full message loop for the device even when no "userevent" like message or action has been
|
||||
/// raised.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Contains the device/chat id of the device to update.</param>
|
||||
public async Task InvokeMessageLoop(long deviceId)
|
||||
{
|
||||
var mr = new MessageResult
|
||||
{
|
||||
UpdateData = new Update()
|
||||
UpdateData = new Update
|
||||
{
|
||||
Message = new Message()
|
||||
}
|
||||
@ -218,7 +194,8 @@ namespace TelegramBotBase
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will invoke the full message loop for the device even when no "userevent" like message or action has been raised.
|
||||
/// This will invoke the full message loop for the device even when no "userevent" like message or action has been
|
||||
/// raised.
|
||||
/// </summary>
|
||||
/// <param name="deviceId">Contains the device/chat id of the device to update.</param>
|
||||
/// <param name="e"></param>
|
||||
@ -265,7 +242,6 @@ namespace TelegramBotBase
|
||||
{
|
||||
await Client.DeleteBotCommands(bs.Key);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -279,8 +255,10 @@ namespace TelegramBotBase
|
||||
foreach (var scope in BotCommandScopes)
|
||||
{
|
||||
if (scope.Value.Any(a => "/" + a.Command == command))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -302,7 +280,7 @@ namespace TelegramBotBase
|
||||
/// <param name="value"></param>
|
||||
public void SetSetting(ESettings set, bool value)
|
||||
{
|
||||
SystemSettings[set] = (value ? 1u : 0u);
|
||||
SystemSettings[set] = value ? 1u : 0u;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -314,7 +292,9 @@ namespace TelegramBotBase
|
||||
public uint GetSetting(ESettings set, uint defaultValue)
|
||||
{
|
||||
if (!SystemSettings.ContainsKey(set))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return SystemSettings[set];
|
||||
}
|
||||
@ -328,17 +308,37 @@ namespace TelegramBotBase
|
||||
public bool GetSetting(ESettings set, bool defaultValue)
|
||||
{
|
||||
if (!SystemSettings.ContainsKey(set))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return SystemSettings[set] == 0u ? false : true;
|
||||
}
|
||||
|
||||
|
||||
#region "Events"
|
||||
|
||||
private readonly EventHandlerList _events = new();
|
||||
|
||||
private static readonly object EvSessionBegins = new();
|
||||
|
||||
private static readonly object EvMessage = new();
|
||||
|
||||
private static object __evSystemCall = new();
|
||||
|
||||
public delegate Task BotCommandEventHandler(object sender, BotCommandEventArgs e);
|
||||
|
||||
private static readonly object EvException = new();
|
||||
|
||||
private static readonly object EvUnhandledCall = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region "Events"
|
||||
|
||||
/// <summary>
|
||||
/// Will be called if a session/context gets started
|
||||
/// </summary>
|
||||
|
||||
public event EventHandler<SessionBeginEventArgs> SessionBegins
|
||||
{
|
||||
add => _events.AddHandler(EvSessionBegins, value);
|
||||
@ -348,7 +348,6 @@ namespace TelegramBotBase
|
||||
public void OnSessionBegins(SessionBeginEventArgs e)
|
||||
{
|
||||
(_events[EvSessionBegins] as EventHandler<SessionBeginEventArgs>)?.Invoke(this, e);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -363,7 +362,6 @@ namespace TelegramBotBase
|
||||
public void OnMessage(MessageIncomeEventArgs e)
|
||||
{
|
||||
(_events[EvMessage] as EventHandler<MessageIncomeEventArgs>)?.Invoke(this, e);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -375,8 +373,10 @@ namespace TelegramBotBase
|
||||
public async Task OnBotCommand(BotCommandEventArgs e)
|
||||
{
|
||||
if (BotCommand != null)
|
||||
{
|
||||
await BotCommand(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Will be called on an inner exception
|
||||
@ -390,7 +390,6 @@ namespace TelegramBotBase
|
||||
public void OnException(SystemExceptionEventArgs e)
|
||||
{
|
||||
(_events[EvException] as EventHandler<SystemExceptionEventArgs>)?.Invoke(this, e);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -405,10 +404,7 @@ namespace TelegramBotBase
|
||||
public void OnUnhandledCall(UnhandledCallEventArgs e)
|
||||
{
|
||||
(_events[EvUnhandledCall] as EventHandler<UnhandledCallEventArgs>)?.Invoke(this, e);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@ -13,28 +13,52 @@ using TelegramBotBase.Localizations;
|
||||
using TelegramBotBase.MessageLoops;
|
||||
using TelegramBotBase.States;
|
||||
|
||||
namespace TelegramBotBase.Builder
|
||||
{
|
||||
public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage, IStartFormSelectionStage, IBuildingStage, INetworkingSelectionStage, IBotCommandsStage, ISessionSerializationStage, ILanguageSelectionStage
|
||||
namespace TelegramBotBase.Builder;
|
||||
|
||||
public class BotBaseBuilder : IAPIKeySelectionStage, IMessageLoopSelectionStage, IStartFormSelectionStage,
|
||||
IBuildingStage, INetworkingSelectionStage, IBotCommandsStage, ISessionSerializationStage,
|
||||
ILanguageSelectionStage
|
||||
{
|
||||
private string _apiKey;
|
||||
|
||||
private MessageClient _client;
|
||||
|
||||
private IStartFormFactory _factory;
|
||||
|
||||
private MessageClient _client;
|
||||
private IMessageLoopFactory _messageLoopFactory;
|
||||
|
||||
private IStateMachine _statemachine;
|
||||
|
||||
private BotBaseBuilder()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains different Botcommands for different areas.
|
||||
/// </summary>
|
||||
private Dictionary<BotCommandScope, List<BotCommand>> BotCommandScopes { get; set; } = new Dictionary<BotCommandScope, List<BotCommand>>();
|
||||
private Dictionary<BotCommandScope, List<BotCommand>> BotCommandScopes { get; } = new();
|
||||
|
||||
private IStateMachine _statemachine;
|
||||
|
||||
private IMessageLoopFactory _messageLoopFactory;
|
||||
|
||||
private BotBaseBuilder()
|
||||
public BotBase Build()
|
||||
{
|
||||
var bb = new BotBase
|
||||
{
|
||||
ApiKey = _apiKey,
|
||||
StartFormFactory = _factory,
|
||||
Client = _client
|
||||
};
|
||||
|
||||
bb.Sessions.Client = bb.Client;
|
||||
|
||||
bb.BotCommandScopes = BotCommandScopes;
|
||||
|
||||
bb.StateMachine = _statemachine;
|
||||
|
||||
bb.MessageLoopFactory = _messageLoopFactory;
|
||||
|
||||
bb.MessageLoopFactory.UnhandledCall += bb.MessageLoopFactory_UnhandledCall;
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
public static IAPIKeySelectionStage Create()
|
||||
@ -138,7 +162,8 @@ namespace TelegramBotBase.Builder
|
||||
public IStartFormSelectionStage CustomMessageLoop<T>()
|
||||
where T : class, new()
|
||||
{
|
||||
_messageLoopFactory = typeof(T).GetConstructor(new Type[] { })?.Invoke(new object[] { }) as IMessageLoopFactory;
|
||||
_messageLoopFactory =
|
||||
typeof(T).GetConstructor(new Type[] { })?.Invoke(new object[] { }) as IMessageLoopFactory;
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -249,7 +274,6 @@ namespace TelegramBotBase.Builder
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -265,7 +289,6 @@ namespace TelegramBotBase.Builder
|
||||
BotCommandScopes.Start("Starts the bot");
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public ISessionSerializationStage DefaultCommands()
|
||||
@ -346,29 +369,4 @@ namespace TelegramBotBase.Builder
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public BotBase Build()
|
||||
{
|
||||
var bb = new BotBase
|
||||
{
|
||||
ApiKey = _apiKey,
|
||||
StartFormFactory = _factory,
|
||||
Client = _client
|
||||
};
|
||||
|
||||
bb.Sessions.Client = bb.Client;
|
||||
|
||||
bb.BotCommandScopes = BotCommandScopes;
|
||||
|
||||
bb.StateMachine = _statemachine;
|
||||
|
||||
bb.MessageLoopFactory = _messageLoopFactory;
|
||||
|
||||
bb.MessageLoopFactory.UnhandledCall += bb.MessageLoopFactory_UnhandledCall;
|
||||
|
||||
return bb;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -2,8 +2,8 @@
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBase.Interfaces;
|
||||
|
||||
namespace TelegramBotBase.Builder.Interfaces
|
||||
{
|
||||
namespace TelegramBotBase.Builder.Interfaces;
|
||||
|
||||
public interface IAPIKeySelectionStage
|
||||
{
|
||||
/// <summary>
|
||||
@ -40,4 +40,3 @@ namespace TelegramBotBase.Builder.Interfaces
|
||||
/// <returns></returns>
|
||||
IBuildingStage QuickStart(string apiKey, IStartFormFactory StartFormFactory);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace TelegramBotBase.Builder.Interfaces
|
||||
{
|
||||
namespace TelegramBotBase.Builder.Interfaces;
|
||||
|
||||
public interface IBotCommandsStage
|
||||
{
|
||||
/// <summary>
|
||||
@ -32,9 +32,5 @@ namespace TelegramBotBase.Builder.Interfaces
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
ISessionSerializationStage CustomCommands(Action<Dictionary<BotCommandScope, List<BotCommand>>> action);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,6 @@
|
||||
namespace TelegramBotBase.Builder.Interfaces
|
||||
{
|
||||
namespace TelegramBotBase.Builder.Interfaces;
|
||||
|
||||
public interface IBuildingStage
|
||||
{
|
||||
BotBase Build();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
using TelegramBotBase.Localizations;
|
||||
|
||||
namespace TelegramBotBase.Builder.Interfaces
|
||||
{
|
||||
namespace TelegramBotBase.Builder.Interfaces;
|
||||
|
||||
public interface ILanguageSelectionStage
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Selects the default language for control usage. (English)
|
||||
/// </summary>
|
||||
@ -28,6 +27,4 @@ namespace TelegramBotBase.Builder.Interfaces
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IBuildingStage Custom(Localization language);
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,9 @@
|
||||
using TelegramBotBase.Interfaces;
|
||||
|
||||
namespace TelegramBotBase.Builder.Interfaces
|
||||
{
|
||||
namespace TelegramBotBase.Builder.Interfaces;
|
||||
|
||||
public interface IMessageLoopSelectionStage
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Chooses a default message loop.
|
||||
/// </summary>
|
||||
@ -34,7 +33,4 @@ namespace TelegramBotBase.Builder.Interfaces
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
IStartFormSelectionStage CustomMessageLoop<T>() where T : class, new();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,10 @@
|
||||
using System.Net.Http;
|
||||
using Telegram.Bot;
|
||||
|
||||
namespace TelegramBotBase.Builder.Interfaces
|
||||
{
|
||||
namespace TelegramBotBase.Builder.Interfaces;
|
||||
|
||||
public interface INetworkingSelectionStage
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Chooses a proxy as network configuration.
|
||||
/// </summary>
|
||||
@ -42,7 +41,4 @@ namespace TelegramBotBase.Builder.Interfaces
|
||||
/// <param name="client"></param>
|
||||
/// <returns></returns>
|
||||
IBotCommandsStage WithHttpClient(HttpClient client);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
using TelegramBotBase.Interfaces;
|
||||
|
||||
namespace TelegramBotBase.Builder.Interfaces
|
||||
{
|
||||
namespace TelegramBotBase.Builder.Interfaces;
|
||||
|
||||
public interface ISessionSerializationStage
|
||||
{
|
||||
/// <summary>
|
||||
@ -41,6 +41,4 @@ namespace TelegramBotBase.Builder.Interfaces
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
ILanguageSelectionStage UseXML(string path);
|
||||
|
||||
}
|
||||
}
|
||||
@ -2,11 +2,10 @@
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBase.Interfaces;
|
||||
|
||||
namespace TelegramBotBase.Builder.Interfaces
|
||||
{
|
||||
namespace TelegramBotBase.Builder.Interfaces;
|
||||
|
||||
public interface IStartFormSelectionStage
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Chooses a start form type which will be used for new sessions.
|
||||
/// </summary>
|
||||
@ -43,6 +42,4 @@ namespace TelegramBotBase.Builder.Interfaces
|
||||
/// <param name="factory"></param>
|
||||
/// <returns></returns>
|
||||
INetworkingSelectionStage WithStartFormFactory(IStartFormFactory factory);
|
||||
|
||||
}
|
||||
}
|
||||
@ -2,8 +2,8 @@
|
||||
using System.Linq;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace TelegramBotBase.Commands
|
||||
{
|
||||
namespace TelegramBotBase.Commands;
|
||||
|
||||
public static class Extensions
|
||||
{
|
||||
/// <summary>
|
||||
@ -12,7 +12,8 @@ namespace TelegramBotBase.Commands
|
||||
/// <param name="cmds"></param>
|
||||
/// <param name="command"></param>
|
||||
/// <param name="description"></param>
|
||||
public static void Add(this Dictionary<BotCommandScope, List<BotCommand>> cmds, string command, string description, BotCommandScope scope = null)
|
||||
public static void Add(this Dictionary<BotCommandScope, List<BotCommand>> cmds, string command,
|
||||
string description, BotCommandScope scope = null)
|
||||
{
|
||||
if (scope == null)
|
||||
{
|
||||
@ -27,7 +28,7 @@ namespace TelegramBotBase.Commands
|
||||
}
|
||||
else
|
||||
{
|
||||
cmds.Add(scope, new List<BotCommand> { new BotCommand { Command = command, Description = description } });
|
||||
cmds.Add(scope, new List<BotCommand> { new() { Command = command, Description = description } });
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,33 +62,48 @@ namespace TelegramBotBase.Commands
|
||||
/// </summary>
|
||||
/// <param name="cmds"></param>
|
||||
/// <param name="description"></param>
|
||||
public static void Start(this Dictionary<BotCommandScope, List<BotCommand>> cmds, string description) => Add(cmds, "start", description);
|
||||
public static void Start(this Dictionary<BotCommandScope, List<BotCommand>> cmds, string description)
|
||||
{
|
||||
Add(cmds, "start", description);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adding the default /help command with a description.
|
||||
/// </summary>
|
||||
/// <param name="cmds"></param>
|
||||
/// <param name="description"></param>
|
||||
public static void Help(this Dictionary<BotCommandScope, List<BotCommand>> cmds, string description) => Add(cmds, "help", description);
|
||||
public static void Help(this Dictionary<BotCommandScope, List<BotCommand>> cmds, string description)
|
||||
{
|
||||
Add(cmds, "help", description);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adding the default /settings command with a description.
|
||||
/// </summary>
|
||||
/// <param name="cmds"></param>
|
||||
/// <param name="description"></param>
|
||||
public static void Settings(this Dictionary<BotCommandScope, List<BotCommand>> cmds, string description) => Add(cmds, "settings", description);
|
||||
public static void Settings(this Dictionary<BotCommandScope, List<BotCommand>> cmds, string description)
|
||||
{
|
||||
Add(cmds, "settings", description);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears all default commands.
|
||||
/// </summary>
|
||||
/// <param name="cmds"></param>
|
||||
public static void ClearDefaultCommands(this Dictionary<BotCommandScope, List<BotCommand>> cmds) => Clear(cmds);
|
||||
public static void ClearDefaultCommands(this Dictionary<BotCommandScope, List<BotCommand>> cmds)
|
||||
{
|
||||
Clear(cmds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears all commands of a specific device.
|
||||
/// </summary>
|
||||
/// <param name="cmds"></param>
|
||||
public static void ClearChatCommands(this Dictionary<BotCommandScope, List<BotCommand>> cmds, long deviceId) => Clear(cmds, new BotCommandScopeChat { ChatId = deviceId });
|
||||
public static void ClearChatCommands(this Dictionary<BotCommandScope, List<BotCommand>> cmds, long deviceId)
|
||||
{
|
||||
Clear(cmds, new BotCommandScopeChat { ChatId = deviceId });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adding a chat command with a description.
|
||||
@ -95,7 +111,11 @@ namespace TelegramBotBase.Commands
|
||||
/// <param name="cmds"></param>
|
||||
/// <param name="command"></param>
|
||||
/// <param name="description"></param>
|
||||
public static void AddChatCommand(this Dictionary<BotCommandScope, List<BotCommand>> cmds, long deviceId, string command, string description) => Add(cmds, command, description, new BotCommandScopeChat { ChatId = deviceId });
|
||||
public static void AddChatCommand(this Dictionary<BotCommandScope, List<BotCommand>> cmds, long deviceId,
|
||||
string command, string description)
|
||||
{
|
||||
Add(cmds, command, description, new BotCommandScopeChat { ChatId = deviceId });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adding a group command with a description.
|
||||
@ -103,13 +123,20 @@ namespace TelegramBotBase.Commands
|
||||
/// <param name="cmds"></param>
|
||||
/// <param name="command"></param>
|
||||
/// <param name="description"></param>
|
||||
public static void AddGroupCommand(this Dictionary<BotCommandScope, List<BotCommand>> cmds, string command, string description) => Add(cmds, command, description, new BotCommandScopeAllGroupChats());
|
||||
public static void AddGroupCommand(this Dictionary<BotCommandScope, List<BotCommand>> cmds, string command,
|
||||
string description)
|
||||
{
|
||||
Add(cmds, command, description, new BotCommandScopeAllGroupChats());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears all group commands.
|
||||
/// </summary>
|
||||
/// <param name="cmds"></param>
|
||||
public static void ClearGroupCommands(this Dictionary<BotCommandScope, List<BotCommand>> cmds) => Clear(cmds, new BotCommandScopeAllGroupChats());
|
||||
public static void ClearGroupCommands(this Dictionary<BotCommandScope, List<BotCommand>> cmds)
|
||||
{
|
||||
Clear(cmds, new BotCommandScopeAllGroupChats());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adding group admin command with a description.
|
||||
@ -117,13 +144,20 @@ namespace TelegramBotBase.Commands
|
||||
/// <param name="cmds"></param>
|
||||
/// <param name="command"></param>
|
||||
/// <param name="description"></param>
|
||||
public static void AddGroupAdminCommand(this Dictionary<BotCommandScope, List<BotCommand>> cmds, string command, string description) => Add(cmds, command, description, new BotCommandScopeAllChatAdministrators());
|
||||
public static void AddGroupAdminCommand(this Dictionary<BotCommandScope, List<BotCommand>> cmds, string command,
|
||||
string description)
|
||||
{
|
||||
Add(cmds, command, description, new BotCommandScopeAllChatAdministrators());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears all group admin commands.
|
||||
/// </summary>
|
||||
/// <param name="cmds"></param>
|
||||
public static void ClearGroupAdminCommand(this Dictionary<BotCommandScope, List<BotCommand>> cmds) => Clear(cmds, new BotCommandScopeAllChatAdministrators());
|
||||
public static void ClearGroupAdminCommand(this Dictionary<BotCommandScope, List<BotCommand>> cmds)
|
||||
{
|
||||
Clear(cmds, new BotCommandScopeAllChatAdministrators());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adding a privat command with a description.
|
||||
@ -131,12 +165,18 @@ namespace TelegramBotBase.Commands
|
||||
/// <param name="cmds"></param>
|
||||
/// <param name="command"></param>
|
||||
/// <param name="description"></param>
|
||||
public static void AddPrivateChatCommand(this Dictionary<BotCommandScope, List<BotCommand>> cmds, string command, string description) => Add(cmds, command, description, new BotCommandScopeAllPrivateChats());
|
||||
public static void AddPrivateChatCommand(this Dictionary<BotCommandScope, List<BotCommand>> cmds,
|
||||
string command, string description)
|
||||
{
|
||||
Add(cmds, command, description, new BotCommandScopeAllPrivateChats());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears all private commands.
|
||||
/// </summary>
|
||||
/// <param name="cmds"></param>
|
||||
public static void ClearPrivateChatCommand(this Dictionary<BotCommandScope, List<BotCommand>> cmds) => Clear(cmds, new BotCommandScopeAllPrivateChats());
|
||||
public static void ClearPrivateChatCommand(this Dictionary<BotCommandScope, List<BotCommand>> cmds)
|
||||
{
|
||||
Clear(cmds, new BotCommandScopeAllPrivateChats());
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user