Merge pull request #29 from ZavaruKitsu/development
QoL changes accepted.
This commit is contained in:
commit
f70531dd73
@ -1,378 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<configuration>
|
|
||||||
<startup>
|
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
|
|
||||||
</startup>
|
|
||||||
<runtime>
|
|
||||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="Microsoft.VisualBasic.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-10.0.6.0" newVersion="10.0.6.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="Microsoft.Win32.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="Microsoft.Win32.Registry" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="netstandard" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Collections" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Collections.Concurrent" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Collections.NonGeneric" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Collections.Specialized" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.ComponentModel" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.ComponentModel.EventBasedAsync" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.ComponentModel.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.ComponentModel.TypeConverter" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Console" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Data.Common" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Diagnostics.Contracts" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Diagnostics.Debug" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Diagnostics.FileVersionInfo" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Diagnostics.Process" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Diagnostics.StackTrace" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.4.0" newVersion="4.0.4.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Diagnostics.TextWriterTraceListener" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Diagnostics.TraceSource" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Diagnostics.Tracing" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Drawing.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.1.3.0" newVersion="4.1.3.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.IO.Compression.ZipFile" publicKeyToken="b77a5c561934e089" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.IO.FileSystem" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.IO.FileSystem.DriveInfo" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.IO.FileSystem.Watcher" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.IO.IsolatedStorage" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.IO.MemoryMappedFiles" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.IO.Pipes" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Linq" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Linq.Expressions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Linq.Parallel" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Linq.Queryable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Net.NameResolution" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Net.NetworkInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Net.Ping" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Net.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Net.Requests" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Net.Security" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Net.ServicePoint" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Net.Sockets" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Net.WebHeaderCollection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Net.WebSockets" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Net.WebSockets.Client" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.ObjectModel" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Reflection.Emit.ILGeneration" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Reflection.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Resources.ResourceManager" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Resources.Writer" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Runtime.CompilerServices.VisualC" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Runtime.Extensions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Runtime.InteropServices" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Runtime.Numerics" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Runtime.Serialization.Formatters" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Runtime.Serialization.Json" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Runtime.Serialization.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.1.3.0" newVersion="4.1.3.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Runtime.Serialization.Xml" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.1.3.0" newVersion="4.1.3.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Security.AccessControl" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Security.Claims" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Security.Cryptography.Algorithms" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.2.2.0" newVersion="4.2.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Security.Cryptography.Csp" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Security.Cryptography.Encoding" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Security.Cryptography.X509Certificates" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Security.Principal" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Security.Principal.Windows" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Text.Encoding.Extensions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Text.RegularExpressions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Threading" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Threading.Overlapped" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Threading.Tasks.Parallel" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Threading.Thread" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Threading.ThreadPool" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.12.0" newVersion="4.0.12.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Transactions.Local" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Xml.ReaderWriter" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Xml.XDocument" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Xml.XmlSerializer" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Xml.XPath" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="System.Xml.XPath.XDocument" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
|
||||||
</dependentAssembly>
|
|
||||||
</assemblyBinding>
|
|
||||||
</runtime>
|
|
||||||
</configuration>
|
|
||||||
@ -1,74 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
|
||||||
<ProjectGuid>{673A56F5-6110-4AED-A68D-562FD6ED3EA6}</ProjectGuid>
|
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<RootNamespace>AsyncFormUpdates</RootNamespace>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<AssemblyName>AsyncFormUpdates</AssemblyName>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
<Nullable>disable</Nullable>
|
||||||
<FileAlignment>512</FileAlignment>
|
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
|
||||||
<Deterministic>true</Deterministic>
|
|
||||||
<TargetFrameworkProfile />
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
|
||||||
<DebugType>pdbonly</DebugType>
|
|
||||||
<Optimize>true</Optimize>
|
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="mscorlib" />
|
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj"/>
|
||||||
<Reference Include="System" />
|
|
||||||
<Reference Include="System.Core" />
|
|
||||||
<Reference Include="System.Xml.Linq" />
|
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
|
||||||
<Reference Include="Microsoft.CSharp" />
|
|
||||||
<Reference Include="System.Data" />
|
|
||||||
<Reference Include="System.Net.Http" />
|
|
||||||
<Reference Include="System.Xml" />
|
|
||||||
<Reference Include="Telegram.Bot, Version=17.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\packages\Telegram.Bot.17.0.0\lib\netstandard2.0\Telegram.Bot.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="forms\AsyncFormEdit.cs" />
|
|
||||||
<Compile Include="forms\AsyncFormUpdate.cs" />
|
|
||||||
<Compile Include="forms\Start.cs" />
|
|
||||||
<Compile Include="Program.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<None Include="App.config" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj">
|
|
||||||
<Project>{0bd16fb9-7ed4-4ccb-83eb-5cee538e1b6c}</Project>
|
|
||||||
<Name>TelegramBotBase</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
|
||||||
<PackageReference Include="System.Net.Requests" Version="4.3.0" />
|
|
||||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
|
|
||||||
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
|
|
||||||
<PackageReference Include="Telegram.Bot" Version="18.0.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
|
||||||
</Project>
|
</Project>
|
||||||
48
Examples/AsyncFormUpdates/Forms/AsyncFormEdit.cs
Normal file
48
Examples/AsyncFormUpdates/Forms/AsyncFormEdit.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
using TelegramBotBase.Attributes;
|
||||||
|
using TelegramBotBase.Base;
|
||||||
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
|
namespace AsyncFormUpdates.Forms;
|
||||||
|
|
||||||
|
public class AsyncFormEdit : FormBase
|
||||||
|
{
|
||||||
|
[SaveState] private int _counter;
|
||||||
|
|
||||||
|
private int _messageId;
|
||||||
|
|
||||||
|
public override Task Load(MessageResult message)
|
||||||
|
{
|
||||||
|
_counter++;
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task Action(MessageResult message)
|
||||||
|
{
|
||||||
|
await message.ConfirmAction();
|
||||||
|
|
||||||
|
switch (message.RawData ?? "")
|
||||||
|
{
|
||||||
|
case "back":
|
||||||
|
var st = new Start();
|
||||||
|
await NavigateTo(st);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task Render(MessageResult message)
|
||||||
|
{
|
||||||
|
var bf = new ButtonForm();
|
||||||
|
bf.AddButtonRow("Back", "back");
|
||||||
|
|
||||||
|
if (_messageId != 0)
|
||||||
|
{
|
||||||
|
await Device.Edit(_messageId, $"Your current count is at: {_counter}", bf);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var m = await Device.Send($"Your current count is at: {_counter}", bf, disableNotification: true);
|
||||||
|
_messageId = m.MessageId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
38
Examples/AsyncFormUpdates/Forms/AsyncFormUpdate.cs
Normal file
38
Examples/AsyncFormUpdates/Forms/AsyncFormUpdate.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using TelegramBotBase.Attributes;
|
||||||
|
using TelegramBotBase.Base;
|
||||||
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
|
namespace AsyncFormUpdates.Forms;
|
||||||
|
|
||||||
|
public class AsyncFormUpdate : AutoCleanForm
|
||||||
|
{
|
||||||
|
[SaveState] private int _counter;
|
||||||
|
|
||||||
|
public override Task Load(MessageResult message)
|
||||||
|
{
|
||||||
|
_counter++;
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task Action(MessageResult message)
|
||||||
|
{
|
||||||
|
await message.ConfirmAction();
|
||||||
|
|
||||||
|
switch (message.RawData ?? "")
|
||||||
|
{
|
||||||
|
case "back":
|
||||||
|
var st = new Start();
|
||||||
|
await NavigateTo(st);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task Render(MessageResult message)
|
||||||
|
{
|
||||||
|
var bf = new ButtonForm();
|
||||||
|
bf.AddButtonRow("Back", "back");
|
||||||
|
|
||||||
|
await Device.Send($"Your current count is at: {_counter}", bf, disableNotification: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
42
Examples/AsyncFormUpdates/Forms/Start.cs
Normal file
42
Examples/AsyncFormUpdates/Forms/Start.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
using TelegramBotBase.Base;
|
||||||
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
|
namespace AsyncFormUpdates.Forms;
|
||||||
|
|
||||||
|
public class Start : AutoCleanForm
|
||||||
|
{
|
||||||
|
public override async Task Action(MessageResult message)
|
||||||
|
{
|
||||||
|
await message.ConfirmAction();
|
||||||
|
|
||||||
|
switch (message.RawData ?? "")
|
||||||
|
{
|
||||||
|
case "async":
|
||||||
|
|
||||||
|
var afe = new AsyncFormEdit();
|
||||||
|
await NavigateTo(afe);
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "async_del":
|
||||||
|
|
||||||
|
var afu = new AsyncFormUpdate();
|
||||||
|
await NavigateTo(afu);
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task Render(MessageResult message)
|
||||||
|
{
|
||||||
|
var bf = new ButtonForm();
|
||||||
|
|
||||||
|
bf.AddButtonRow("Open Async Form with AutoCleanupForm", "async_del");
|
||||||
|
|
||||||
|
bf.AddButtonRow("Open Async Form with Edit", "async");
|
||||||
|
|
||||||
|
await Device.Send("Choose your option", bf);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,26 +1,23 @@
|
|||||||
using System;
|
using System.Timers;
|
||||||
using System.Collections.Generic;
|
using AsyncFormUpdates.Forms;
|
||||||
using System.Linq;
|
using TelegramBotBase;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Timers;
|
|
||||||
using TelegramBotBase.Builder;
|
using TelegramBotBase.Builder;
|
||||||
|
using Timer = System.Timers.Timer;
|
||||||
|
|
||||||
namespace AsyncFormUpdates
|
namespace AsyncFormUpdates;
|
||||||
{
|
|
||||||
class Program
|
|
||||||
{
|
|
||||||
static TelegramBotBase.BotBase bot = null;
|
|
||||||
|
|
||||||
static void Main(string[] args)
|
internal class Program
|
||||||
{
|
{
|
||||||
String apiKey = "APIKey";
|
private static BotBase __bot;
|
||||||
|
|
||||||
bot = BotBaseBuilder.Create()
|
private static async Task Main(string[] args)
|
||||||
.QuickStart<forms.Start>(apiKey)
|
{
|
||||||
|
__bot = BotBaseBuilder.Create()
|
||||||
|
.QuickStart<Start>(Environment.GetEnvironmentVariable("API_KEY") ??
|
||||||
|
throw new Exception("API_KEY is not set"))
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
bot.Start();
|
await __bot.Start();
|
||||||
|
|
||||||
var timer = new Timer(5000);
|
var timer = new Timer(5000);
|
||||||
|
|
||||||
@ -30,22 +27,21 @@ namespace AsyncFormUpdates
|
|||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
|
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
bot.Stop();
|
await __bot.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async void Timer_Elapsed(object sender, ElapsedEventArgs e)
|
private static async void Timer_Elapsed(object sender, ElapsedEventArgs e)
|
||||||
{
|
{
|
||||||
|
foreach (var s in __bot.Sessions.SessionList)
|
||||||
foreach(var s in bot.Sessions.SessionList)
|
|
||||||
{
|
{
|
||||||
//Only for AsyncUpdateForm
|
//Only for AsyncUpdateForm
|
||||||
if (s.Value.ActiveForm.GetType() != typeof(forms.AsyncFormUpdate) && s.Value.ActiveForm.GetType() != typeof(forms.AsyncFormEdit))
|
if (s.Value.ActiveForm.GetType() != typeof(AsyncFormUpdate) &&
|
||||||
|
s.Value.ActiveForm.GetType() != typeof(AsyncFormEdit))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
await bot.InvokeMessageLoop(s.Key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await __bot.InvokeMessageLoop(s.Key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,36 +0,0 @@
|
|||||||
using System.Reflection;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
|
||||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
|
||||||
// die einer Assembly zugeordnet sind.
|
|
||||||
[assembly: AssemblyTitle("AsyncFormUpdates")]
|
|
||||||
[assembly: AssemblyDescription("")]
|
|
||||||
[assembly: AssemblyConfiguration("")]
|
|
||||||
[assembly: AssemblyCompany("")]
|
|
||||||
[assembly: AssemblyProduct("AsyncFormUpdates")]
|
|
||||||
[assembly: AssemblyCopyright("Copyright © 2021")]
|
|
||||||
[assembly: AssemblyTrademark("")]
|
|
||||||
[assembly: AssemblyCulture("")]
|
|
||||||
|
|
||||||
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
|
|
||||||
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
|
|
||||||
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
|
|
||||||
[assembly: ComVisible(false)]
|
|
||||||
|
|
||||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
|
||||||
[assembly: Guid("673a56f5-6110-4aed-a68d-562fd6ed3ea6")]
|
|
||||||
|
|
||||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
|
||||||
//
|
|
||||||
// Hauptversion
|
|
||||||
// Nebenversion
|
|
||||||
// Buildnummer
|
|
||||||
// Revision
|
|
||||||
//
|
|
||||||
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
|
||||||
// indem Sie "*" wie unten gezeigt eingeben:
|
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
||||||
@ -1,57 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Attributes;
|
|
||||||
using TelegramBotBase.Base;
|
|
||||||
using TelegramBotBase.Form;
|
|
||||||
|
|
||||||
namespace AsyncFormUpdates.forms
|
|
||||||
{
|
|
||||||
public class AsyncFormEdit : FormBase
|
|
||||||
{
|
|
||||||
[SaveState]
|
|
||||||
int counter = 0;
|
|
||||||
|
|
||||||
int MessageId = 0;
|
|
||||||
|
|
||||||
public override async Task Load(MessageResult message)
|
|
||||||
{
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task Action(MessageResult message)
|
|
||||||
{
|
|
||||||
await message.ConfirmAction("");
|
|
||||||
|
|
||||||
switch (message.RawData ?? "")
|
|
||||||
{
|
|
||||||
case "back":
|
|
||||||
|
|
||||||
var st = new Start();
|
|
||||||
await NavigateTo(st);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task Render(MessageResult message)
|
|
||||||
{
|
|
||||||
var bf = new ButtonForm();
|
|
||||||
bf.AddButtonRow("Back", "back");
|
|
||||||
|
|
||||||
if (MessageId != 0)
|
|
||||||
{
|
|
||||||
await Device.Edit(MessageId, $"Your current count is at: {counter}", bf);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var m = await Device.Send($"Your current count is at: {counter}", bf, disableNotification: true);
|
|
||||||
MessageId = m.MessageId;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,48 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Attributes;
|
|
||||||
using TelegramBotBase.Base;
|
|
||||||
using TelegramBotBase.Form;
|
|
||||||
|
|
||||||
namespace AsyncFormUpdates.forms
|
|
||||||
{
|
|
||||||
public class AsyncFormUpdate : AutoCleanForm
|
|
||||||
{
|
|
||||||
[SaveState]
|
|
||||||
int counter = 0;
|
|
||||||
|
|
||||||
|
|
||||||
public override async Task Load(MessageResult message)
|
|
||||||
{
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task Action(MessageResult message)
|
|
||||||
{
|
|
||||||
await message.ConfirmAction("");
|
|
||||||
|
|
||||||
switch (message.RawData ?? "")
|
|
||||||
{
|
|
||||||
case "back":
|
|
||||||
|
|
||||||
var st = new Start();
|
|
||||||
await NavigateTo(st);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task Render(MessageResult message)
|
|
||||||
{
|
|
||||||
var bf = new ButtonForm();
|
|
||||||
bf.AddButtonRow("Back", "back");
|
|
||||||
|
|
||||||
await Device.Send($"Your current count is at: {counter}", bf, disableNotification: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,52 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Base;
|
|
||||||
using TelegramBotBase.Form;
|
|
||||||
|
|
||||||
namespace AsyncFormUpdates.forms
|
|
||||||
{
|
|
||||||
public class Start : AutoCleanForm
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
public override async Task Action(MessageResult message)
|
|
||||||
{
|
|
||||||
await message.ConfirmAction("");
|
|
||||||
|
|
||||||
switch (message.RawData ?? "")
|
|
||||||
{
|
|
||||||
case "async":
|
|
||||||
|
|
||||||
var afe = new AsyncFormEdit();
|
|
||||||
await NavigateTo(afe);
|
|
||||||
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "async_del":
|
|
||||||
|
|
||||||
var afu = new AsyncFormUpdate();
|
|
||||||
await NavigateTo(afu);
|
|
||||||
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task Render(MessageResult message)
|
|
||||||
{
|
|
||||||
var bf = new ButtonForm();
|
|
||||||
|
|
||||||
bf.AddButtonRow("Open Async Form with AutoCleanupForm", "async_del");
|
|
||||||
|
|
||||||
bf.AddButtonRow("Open Async Form with Edit", "async");
|
|
||||||
|
|
||||||
await Device.Send("Choose your option", bf);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -10,7 +10,8 @@ var serviceCollection = new ServiceCollection()
|
|||||||
var serviceProvider = serviceCollection.BuildServiceProvider();
|
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||||
|
|
||||||
var bot = BotBaseBuilder.Create()
|
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()
|
.DefaultMessageLoop()
|
||||||
.WithServiceProvider<StartForm>(serviceProvider)
|
.WithServiceProvider<StartForm>(serviceProvider)
|
||||||
.NoProxy()
|
.NoProxy()
|
||||||
@ -19,5 +20,5 @@ var bot = BotBaseBuilder.Create()
|
|||||||
.DefaultLanguage()
|
.DefaultLanguage()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
bot.Start();
|
await bot.Start();
|
||||||
await Task.Delay(-1);
|
await Task.Delay(-1);
|
||||||
|
|||||||
21
Examples/JoinHiderBot/Forms/GroupManageForm.cs
Normal file
21
Examples/JoinHiderBot/Forms/GroupManageForm.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using Telegram.Bot.Types.Enums;
|
||||||
|
using TelegramBotBase.Args;
|
||||||
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
23
Examples/JoinHiderBot/Forms/Start.cs
Normal file
23
Examples/JoinHiderBot/Forms/Start.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using TelegramBotBase.Base;
|
||||||
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
|
namespace JoinHiderBot.Forms;
|
||||||
|
|
||||||
|
public class Start : SplitterForm
|
||||||
|
{
|
||||||
|
public override async Task<bool> Open(MessageResult e)
|
||||||
|
{
|
||||||
|
await Device.Send("This bot works only in groups.");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<bool> OpenGroup(MessageResult e)
|
||||||
|
{
|
||||||
|
var gmf = new GroupManageForm();
|
||||||
|
|
||||||
|
await NavigateTo(gmf);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,10 +3,12 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>disable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="TelegramBotBase" Version="5.0.0" />
|
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -1,22 +1,19 @@
|
|||||||
using System;
|
using JoinHiderBot.Forms;
|
||||||
using TelegramBotBase.Builder;
|
using TelegramBotBase.Builder;
|
||||||
|
|
||||||
namespace JoinHiderBot
|
namespace JoinHiderBot;
|
||||||
{
|
|
||||||
class Program
|
|
||||||
{
|
|
||||||
static void Main(string[] args)
|
|
||||||
{
|
|
||||||
|
|
||||||
String apiKey = "";
|
|
||||||
|
|
||||||
|
internal class Program
|
||||||
|
{
|
||||||
|
private static async Task Main(string[] args)
|
||||||
|
{
|
||||||
var bot = BotBaseBuilder.Create()
|
var bot = BotBaseBuilder.Create()
|
||||||
.QuickStart<forms.Start>(apiKey)
|
.QuickStart<Start>(Environment.GetEnvironmentVariable("API_KEY") ??
|
||||||
|
throw new Exception("API_KEY is not set"))
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
bot.Start();
|
await bot.Start();
|
||||||
|
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@ -1,25 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Args;
|
|
||||||
using TelegramBotBase.Form;
|
|
||||||
|
|
||||||
namespace JoinHiderBot.forms
|
|
||||||
{
|
|
||||||
public class GroupManageForm : GroupForm
|
|
||||||
{
|
|
||||||
|
|
||||||
public override async Task OnMemberChanges(MemberChangeEventArgs e)
|
|
||||||
{
|
|
||||||
if (e.Type != Telegram.Bot.Types.Enums.MessageType.ChatMembersAdded && e.Type != Telegram.Bot.Types.Enums.MessageType.ChatMemberLeft)
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
var m = e.Result.Message;
|
|
||||||
|
|
||||||
await this.Device.DeleteMessage(m);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Base;
|
|
||||||
using TelegramBotBase.Form;
|
|
||||||
|
|
||||||
namespace JoinHiderBot.forms
|
|
||||||
{
|
|
||||||
public class Start : SplitterForm
|
|
||||||
{
|
|
||||||
public override async Task<bool> Open(MessageResult e)
|
|
||||||
{
|
|
||||||
await this.Device.Send("This bot works only in groups.");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task<bool> OpenGroup(MessageResult e)
|
|
||||||
{
|
|
||||||
var gmf = new GroupManageForm();
|
|
||||||
|
|
||||||
await this.NavigateTo(gmf);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
21
Examples/SystemCommandsBot/Command.cs
Normal file
21
Examples/SystemCommandsBot/Command.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
namespace SystemCommandsBot;
|
||||||
|
|
||||||
|
public class Command
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Title { get; set; }
|
||||||
|
|
||||||
|
public string ShellCmd { get; set; }
|
||||||
|
|
||||||
|
public bool Enabled { get; set; } = true;
|
||||||
|
|
||||||
|
public string Action { get; set; }
|
||||||
|
|
||||||
|
public bool UseShell { get; set; } = true;
|
||||||
|
|
||||||
|
|
||||||
|
public int? MaxInstances { get; set; }
|
||||||
|
|
||||||
|
public string ProcName { get; set; }
|
||||||
|
}
|
||||||
90
Examples/SystemCommandsBot/Config.cs
Normal file
90
Examples/SystemCommandsBot/Config.cs
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace SystemCommandsBot;
|
||||||
|
|
||||||
|
public class Config
|
||||||
|
{
|
||||||
|
public Config()
|
||||||
|
{
|
||||||
|
Commands = new List<Command>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Password { get; set; }
|
||||||
|
|
||||||
|
public string ApiKey { get; set; }
|
||||||
|
|
||||||
|
public List<Command> Commands { get; set; }
|
||||||
|
|
||||||
|
public void LoadDefaultValues()
|
||||||
|
{
|
||||||
|
ApiKey = "";
|
||||||
|
Commands.Add(new Command
|
||||||
|
{
|
||||||
|
Id = 0, Enabled = true, Title = "Test Befehl", ShellCmd = "explorer.exe", Action = "start",
|
||||||
|
MaxInstances = 2
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Config Load()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Load(AppContext.BaseDirectory + "config\\default.cfg");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Config Load(string path)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var cfg = JsonConvert.DeserializeObject<Config>(File.ReadAllText(path));
|
||||||
|
return cfg;
|
||||||
|
}
|
||||||
|
catch (DirectoryNotFoundException)
|
||||||
|
{
|
||||||
|
var di = new DirectoryInfo(path);
|
||||||
|
|
||||||
|
if (!Directory.Exists(di.Parent.FullName))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(di.Parent.FullName);
|
||||||
|
}
|
||||||
|
|
||||||
|
var cfg = new Config();
|
||||||
|
cfg.LoadDefaultValues();
|
||||||
|
cfg.Save(path);
|
||||||
|
return cfg;
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException)
|
||||||
|
{
|
||||||
|
var cfg = new Config();
|
||||||
|
cfg.LoadDefaultValues();
|
||||||
|
cfg.Save(path);
|
||||||
|
return cfg;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Save(string path)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.WriteAllText(path, JsonConvert.SerializeObject(this));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
156
Examples/SystemCommandsBot/Forms/CmdForm.cs
Normal file
156
Examples/SystemCommandsBot/Forms/CmdForm.cs
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using TelegramBotBase.Base;
|
||||||
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
|
namespace SystemCommandsBot.Forms;
|
||||||
|
|
||||||
|
public class CmdForm : AutoCleanForm
|
||||||
|
{
|
||||||
|
public DateTime ExpiresAt { get; set; }
|
||||||
|
|
||||||
|
public int? MessageId { get; set; }
|
||||||
|
|
||||||
|
public override Task Load(MessageResult message)
|
||||||
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task Action(MessageResult message)
|
||||||
|
{
|
||||||
|
var btn = message.RawData;
|
||||||
|
|
||||||
|
var id = -1;
|
||||||
|
|
||||||
|
if (!int.TryParse(btn, out id))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var cmd = Program.BotConfig.Commands.Where(a => a.Enabled && a.Id == id).FirstOrDefault();
|
||||||
|
if (cmd == null)
|
||||||
|
{
|
||||||
|
await Device.Send("Cmd nicht verfügbar.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
message.Handled = true;
|
||||||
|
|
||||||
|
switch (cmd.Action)
|
||||||
|
{
|
||||||
|
case "start":
|
||||||
|
|
||||||
|
var fi = new FileInfo(cmd.ShellCmd);
|
||||||
|
|
||||||
|
if (cmd.MaxInstances != null && cmd.MaxInstances >= 0)
|
||||||
|
{
|
||||||
|
if (Process.GetProcessesByName(cmd.ProcName).Count() >= cmd.MaxInstances)
|
||||||
|
{
|
||||||
|
await Device.Send("Anwendung läuft bereits.");
|
||||||
|
await message.ConfirmAction("Anwendung läuft bereits.");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var psi = new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = cmd.ShellCmd,
|
||||||
|
WorkingDirectory = fi.DirectoryName,
|
||||||
|
UseShellExecute = cmd.UseShell
|
||||||
|
};
|
||||||
|
|
||||||
|
Process.Start(psi);
|
||||||
|
|
||||||
|
await Device.Send(fi.Name + " wurde gestarted.");
|
||||||
|
|
||||||
|
await message.ConfirmAction(fi.Name + " wurde gestarted.");
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "kill":
|
||||||
|
|
||||||
|
var fi2 = new FileInfo(cmd.ShellCmd);
|
||||||
|
|
||||||
|
var pros = fi2.Name.Replace(fi2.Extension, "");
|
||||||
|
|
||||||
|
var proc = Process.GetProcessesByName(pros).ToList();
|
||||||
|
|
||||||
|
foreach (var p in proc)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
p.Kill();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await Device.Send(fi2.Name + " wurde beendet.");
|
||||||
|
|
||||||
|
await message.ConfirmAction(fi2.Name + " wurde beendet.");
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "restart":
|
||||||
|
|
||||||
|
var fi3 = new FileInfo(cmd.ShellCmd);
|
||||||
|
|
||||||
|
var pros2 = fi3.Name.Replace(fi3.Extension, "");
|
||||||
|
|
||||||
|
var proc2 = Process.GetProcessesByName(pros2).ToList();
|
||||||
|
|
||||||
|
foreach (var p in proc2)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
p.Kill();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var fi4 = new FileInfo(cmd.ShellCmd);
|
||||||
|
|
||||||
|
var psi2 = new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = cmd.ShellCmd,
|
||||||
|
WorkingDirectory = fi4.DirectoryName
|
||||||
|
};
|
||||||
|
psi2.FileName = cmd.ShellCmd;
|
||||||
|
psi2.UseShellExecute = cmd.UseShell;
|
||||||
|
|
||||||
|
Process.Start(psi2);
|
||||||
|
|
||||||
|
await Device.Send(fi3.Name + " wurde neugestarted.");
|
||||||
|
await message.ConfirmAction(fi3.Name + " wurde neugestarted.");
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
|
||||||
|
await message.ConfirmAction();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task Render(MessageResult message)
|
||||||
|
{
|
||||||
|
if (MessageId == null)
|
||||||
|
{
|
||||||
|
var buttons = Program.BotConfig.Commands.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
38
Examples/SystemCommandsBot/Forms/StartForm.cs
Normal file
38
Examples/SystemCommandsBot/Forms/StartForm.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using TelegramBotBase.Base;
|
||||||
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
|
namespace SystemCommandsBot.Forms;
|
||||||
|
|
||||||
|
public class StartForm : FormBase
|
||||||
|
{
|
||||||
|
public string Password { get; set; }
|
||||||
|
|
||||||
|
public override Task Load(MessageResult message)
|
||||||
|
{
|
||||||
|
var inp = message.MessageText;
|
||||||
|
if (Program.BotConfig.Password == inp)
|
||||||
|
{
|
||||||
|
Password = inp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override async Task Render(MessageResult message)
|
||||||
|
{
|
||||||
|
if (Password == null || Password.Trim() == "")
|
||||||
|
{
|
||||||
|
await Device.Send("Bitte gib dein Passwort an.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var cmd = new CmdForm();
|
||||||
|
cmd.ExpiresAt = DateTime.Now.AddDays(14);
|
||||||
|
|
||||||
|
await NavigateTo(cmd);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,17 +1,17 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using SystemCommandsBot.Forms;
|
||||||
using TelegramBotBase.Builder;
|
using TelegramBotBase.Builder;
|
||||||
|
|
||||||
namespace SystemCommandsBot
|
namespace SystemCommandsBot;
|
||||||
{
|
|
||||||
class Program
|
|
||||||
{
|
|
||||||
public static config.Config BotConfig { get; set; }
|
|
||||||
|
|
||||||
|
internal class Program
|
||||||
static void Main(string[] args)
|
|
||||||
{
|
{
|
||||||
|
public static Config BotConfig { get; set; }
|
||||||
|
|
||||||
BotConfig = config.Config.load();
|
private static async Task Main(string[] args)
|
||||||
|
{
|
||||||
|
BotConfig = Config.Load();
|
||||||
|
|
||||||
if (BotConfig.ApiKey == null || BotConfig.ApiKey.Trim() == "")
|
if (BotConfig.ApiKey == null || BotConfig.ApiKey.Trim() == "")
|
||||||
{
|
{
|
||||||
@ -21,19 +21,15 @@ namespace SystemCommandsBot
|
|||||||
}
|
}
|
||||||
|
|
||||||
var bot = BotBaseBuilder.Create()
|
var bot = BotBaseBuilder.Create()
|
||||||
.QuickStart<forms.StartForm>(BotConfig.ApiKey)
|
.QuickStart<StartForm>(BotConfig.ApiKey)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
bot.Start();
|
await bot.Start();
|
||||||
|
|
||||||
Console.WriteLine("Bot started");
|
Console.WriteLine("Bot started");
|
||||||
|
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
|
|
||||||
|
|
||||||
bot.Stop();
|
await bot.Stop();
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,11 +3,12 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>disable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
<ProjectReference Include="..\..\TelegramBotBase\TelegramBotBase.csproj"/>
|
||||||
<PackageReference Include="TelegramBotBase" Version="5.0.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@ -1,30 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace SystemCommandsBot.commands
|
|
||||||
{
|
|
||||||
public class Commando
|
|
||||||
{
|
|
||||||
public int ID { get; set; }
|
|
||||||
|
|
||||||
public String Title { get; set; }
|
|
||||||
|
|
||||||
public String ShellCmd { get; set; }
|
|
||||||
|
|
||||||
public bool Enabled { get; set; } = true;
|
|
||||||
|
|
||||||
public String Action { get; set; }
|
|
||||||
|
|
||||||
public bool UseShell { get; set; } = true;
|
|
||||||
|
|
||||||
|
|
||||||
public int? MaxInstances { get; set; }
|
|
||||||
|
|
||||||
public String ProcName
|
|
||||||
{
|
|
||||||
get;set;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,92 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace SystemCommandsBot.config
|
|
||||||
{
|
|
||||||
public class Config
|
|
||||||
{
|
|
||||||
public String Password { get; set; }
|
|
||||||
|
|
||||||
public String ApiKey { get; set; }
|
|
||||||
|
|
||||||
public List<commands.Commando> Commandos { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
public Config()
|
|
||||||
{
|
|
||||||
this.Commandos = new List<commands.Commando>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadDefaultValues()
|
|
||||||
{
|
|
||||||
this.ApiKey = "";
|
|
||||||
this.Commandos.Add(new commands.Commando() { ID = 0, Enabled = true, Title = "Test Befehl", ShellCmd = "explorer.exe", Action = "start", MaxInstances = 2 });
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Config load()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return load(AppContext.BaseDirectory + "config\\default.cfg");
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
catch(Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine(ex.Message);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Config load(String path)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var cfg = Newtonsoft.Json.JsonConvert.DeserializeObject<Config>(File.ReadAllText(path)) as Config;
|
|
||||||
return cfg;
|
|
||||||
}
|
|
||||||
catch (DirectoryNotFoundException ex)
|
|
||||||
{
|
|
||||||
DirectoryInfo di = new DirectoryInfo(path);
|
|
||||||
|
|
||||||
if (!Directory.Exists(di.Parent.FullName))
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(di.Parent.FullName);
|
|
||||||
}
|
|
||||||
|
|
||||||
var cfg = new Config();
|
|
||||||
cfg.loadDefaultValues();
|
|
||||||
cfg.save(path);
|
|
||||||
return cfg;
|
|
||||||
}
|
|
||||||
catch (FileNotFoundException ex)
|
|
||||||
{
|
|
||||||
var cfg = new Config();
|
|
||||||
cfg.loadDefaultValues();
|
|
||||||
cfg.save(path);
|
|
||||||
return cfg;
|
|
||||||
}
|
|
||||||
catch(Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine(ex.Message);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(String path)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File.WriteAllText(path, Newtonsoft.Json.JsonConvert.SerializeObject(this));
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,172 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Base;
|
|
||||||
using TelegramBotBase.Form;
|
|
||||||
|
|
||||||
namespace SystemCommandsBot.forms
|
|
||||||
{
|
|
||||||
public class CmdForm : TelegramBotBase.Form.AutoCleanForm
|
|
||||||
{
|
|
||||||
public DateTime ExpiresAt { get; set; }
|
|
||||||
|
|
||||||
public int? MessageId { get; set; }
|
|
||||||
|
|
||||||
public override async Task Load(MessageResult message)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task Action(MessageResult message)
|
|
||||||
{
|
|
||||||
var btn = message.RawData;
|
|
||||||
|
|
||||||
int id = -1;
|
|
||||||
|
|
||||||
if (!int.TryParse(btn, out id))
|
|
||||||
{
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var cmd = Program.BotConfig.Commandos.Where(a => a.Enabled && a.ID == id).FirstOrDefault();
|
|
||||||
if (cmd == null)
|
|
||||||
{
|
|
||||||
await this.Device.Send("Cmd nicht verfügbar.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
message.Handled = true;
|
|
||||||
|
|
||||||
switch (cmd.Action)
|
|
||||||
{
|
|
||||||
case "start":
|
|
||||||
|
|
||||||
FileInfo fi = new FileInfo(cmd.ShellCmd);
|
|
||||||
|
|
||||||
if (cmd.MaxInstances != null && cmd.MaxInstances >= 0)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (Process.GetProcessesByName(cmd.ProcName).Count() >= cmd.MaxInstances)
|
|
||||||
{
|
|
||||||
await this.Device.Send("Anwendung läuft bereits.");
|
|
||||||
await message.ConfirmAction("Anwendung läuft bereits.");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ProcessStartInfo psi = new ProcessStartInfo();
|
|
||||||
psi.FileName = cmd.ShellCmd;
|
|
||||||
psi.WorkingDirectory = fi.DirectoryName;
|
|
||||||
psi.UseShellExecute = cmd.UseShell;
|
|
||||||
|
|
||||||
Process.Start(psi);
|
|
||||||
|
|
||||||
await this.Device.Send(fi.Name + " wurde gestarted.");
|
|
||||||
|
|
||||||
await message.ConfirmAction(fi.Name + " wurde gestarted.");
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "kill":
|
|
||||||
|
|
||||||
FileInfo fi2 = new FileInfo(cmd.ShellCmd);
|
|
||||||
|
|
||||||
String pros = fi2.Name.Replace(fi2.Extension, "");
|
|
||||||
|
|
||||||
var proc = Process.GetProcessesByName(pros).ToList();
|
|
||||||
|
|
||||||
foreach (var p in proc)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
p.Kill();
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.Device.Send(fi2.Name + " wurde beendet.");
|
|
||||||
|
|
||||||
await message.ConfirmAction(fi2.Name + " wurde beendet.");
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "restart":
|
|
||||||
|
|
||||||
FileInfo fi3 = new FileInfo(cmd.ShellCmd);
|
|
||||||
|
|
||||||
String pros2 = fi3.Name.Replace(fi3.Extension, "");
|
|
||||||
|
|
||||||
var proc2 = Process.GetProcessesByName(pros2).ToList();
|
|
||||||
|
|
||||||
foreach (var p in proc2)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
p.Kill();
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FileInfo fi4 = new FileInfo(cmd.ShellCmd);
|
|
||||||
|
|
||||||
ProcessStartInfo psi2 = new ProcessStartInfo();
|
|
||||||
psi2.FileName = cmd.ShellCmd;
|
|
||||||
psi2.WorkingDirectory = fi4.DirectoryName;
|
|
||||||
psi2.FileName = cmd.ShellCmd;
|
|
||||||
psi2.UseShellExecute = cmd.UseShell;
|
|
||||||
|
|
||||||
Process.Start(psi2);
|
|
||||||
|
|
||||||
await this.Device.Send(fi3.Name + " wurde neugestarted.");
|
|
||||||
await message.ConfirmAction(fi3.Name + " wurde neugestarted.");
|
|
||||||
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
|
|
||||||
await message.ConfirmAction();
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task Render(MessageResult message)
|
|
||||||
{
|
|
||||||
if (this.MessageId == null)
|
|
||||||
{
|
|
||||||
var buttons = Program.BotConfig.Commandos.Where(a => a.Enabled).Select(a => new ButtonBase(a.Title, a.ID.ToString()));
|
|
||||||
|
|
||||||
ButtonForm bf = new ButtonForm();
|
|
||||||
bf.AddSplitted(buttons, 1);
|
|
||||||
await this.Device.Send("Deine Optionen", bf);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,42 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Base;
|
|
||||||
|
|
||||||
namespace SystemCommandsBot.forms
|
|
||||||
{
|
|
||||||
public class StartForm : TelegramBotBase.Form.FormBase
|
|
||||||
{
|
|
||||||
public String Password { get; set; }
|
|
||||||
|
|
||||||
public override async Task Load(MessageResult message)
|
|
||||||
{
|
|
||||||
var inp = message.MessageText;
|
|
||||||
if (Program.BotConfig.Password == inp)
|
|
||||||
{
|
|
||||||
this.Password = inp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public override async Task Render(MessageResult message)
|
|
||||||
{
|
|
||||||
if (this.Password == null || this.Password.Trim() == "")
|
|
||||||
{
|
|
||||||
await this.Device.Send("Bitte gib dein Passwort an.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var cmd = new forms.CmdForm();
|
|
||||||
cmd.ExpiresAt = DateTime.Now.AddDays(14);
|
|
||||||
|
|
||||||
await this.NavigateTo(cmd);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
63
README.md
63
README.md
@ -91,8 +91,7 @@ var bot = BotBaseBuilder
|
|||||||
.NoProxy()
|
.NoProxy()
|
||||||
.CustomCommands(a =>
|
.CustomCommands(a =>
|
||||||
{
|
{
|
||||||
a.Start("Starts the bot")
|
a.Start("Starts the bot");
|
||||||
|
|
||||||
})
|
})
|
||||||
.NoSerialization()
|
.NoSerialization()
|
||||||
.UseEnglish()
|
.UseEnglish()
|
||||||
@ -102,16 +101,18 @@ var bot = BotBaseBuilder
|
|||||||
await bot.UploadBotCommands();
|
await bot.UploadBotCommands();
|
||||||
|
|
||||||
// Start your Bot
|
// Start your Bot
|
||||||
bot.Start();
|
await bot.Start();
|
||||||
```
|
```
|
||||||
|
|
||||||
The `BotBase` class will manage a lot of things for you, like bot commands, action events and so on.
|
The `BotBase` class will manage a lot of things for you, like bot commands, action events and so on.
|
||||||
`StartForm` is your first form which every user will get internally redirected to, *just like a start page*.
|
`StartForm` is your first form which every user will get internally redirected to, *just like a start page*.
|
||||||
It needs to be a subclass of `FormBase` you will find in namespace `TelegramBotBase.Base`
|
It needs to be a subclass of `FormBase` you will find in namespace `TelegramBotBase.Base`
|
||||||
|
|
||||||
Every `Form` has some events which will get raised at specific times. On every form you are able to get notes about
|
Every `Form` has some events which will get raised at specific times.
|
||||||
|
In every form, you are able to get notes about
|
||||||
the *Remote Device*,
|
the *Remote Device*,
|
||||||
like ChatId and other stuff your carrying. From there you build up your bots:
|
like ChatId and other stuff your carrying.
|
||||||
|
From there you build up your bots:
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
public class StartForm : FormBase
|
public class StartForm : FormBase
|
||||||
@ -175,7 +176,7 @@ var bot = BotBaseBuilder
|
|||||||
.QuickStart<StartForm>("{YOUR API KEY}")
|
.QuickStart<StartForm>("{YOUR API KEY}")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
bot.Start();
|
await bot.Start();
|
||||||
```
|
```
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
@ -183,7 +184,7 @@ bot.Start();
|
|||||||
### System calls & bot commands
|
### System calls & bot commands
|
||||||
|
|
||||||
Using BotFather you can add *Commands* to your bot. The user will see them as popups in a dialog.
|
Using BotFather you can add *Commands* to your bot. The user will see them as popups in a dialog.
|
||||||
Before start (and later for sure) you could add them to your BotBase.
|
Before starting (and later, for sure), you could add them to your BotBase.
|
||||||
If the message contains a command, a special *event handler* will get raised.
|
If the message contains a command, a special *event handler* will get raised.
|
||||||
|
|
||||||
Below we have 4 commands.
|
Below we have 4 commands.
|
||||||
@ -237,7 +238,7 @@ bot.BotCommand += async (s, en) =>
|
|||||||
|
|
||||||
await bot.UploadBotCommands()
|
await bot.UploadBotCommands()
|
||||||
|
|
||||||
bot.Start();
|
await bot.Start();
|
||||||
```
|
```
|
||||||
|
|
||||||
On every input the user is sending back to the bot, the `Action` event gets raised. So here we could manage to send
|
On every input the user is sending back to the bot, the `Action` event gets raised. So here we could manage to send
|
||||||
@ -358,7 +359,7 @@ public class ButtonTestForm : AutoCleanForm
|
|||||||
|
|
||||||
### Custom controls
|
### Custom controls
|
||||||
|
|
||||||
There are a bunch of ready to use controls. For example, progress bar.
|
There is a bunch of ready to use controls. For example, progress bar.
|
||||||
|
|
||||||
<img src=".github/images/example3.PNG" />
|
<img src=".github/images/example3.PNG" />
|
||||||
|
|
||||||
@ -553,7 +554,7 @@ public class PerForm : AutoCleanForm
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
[Another case](TelegramBotBase.Test/Tests/Register/PerStep.cs), where every of these 3 inputs gets requested by a
|
[Another case](TelegramBotBase.Test/Tests/Register/PerStep.cs), where every of these 3 inputs gets requested by
|
||||||
different forms. Just for
|
different forms. Just for
|
||||||
imagination of the possibilities.
|
imagination of the possibilities.
|
||||||
|
|
||||||
@ -595,7 +596,7 @@ await this.NavigateTo(ad);
|
|||||||
|
|
||||||
### AutoCleanForm
|
### AutoCleanForm
|
||||||
|
|
||||||
Just try it by youself.
|
Just try it by yourself.
|
||||||
|
|
||||||
### Prompt Dialog
|
### Prompt Dialog
|
||||||
|
|
||||||
@ -680,7 +681,7 @@ await this.NavigateTo(cd);
|
|||||||
|
|
||||||
## Groups
|
## Groups
|
||||||
|
|
||||||
For groups, there are multiple different tools which helps to work with and allows bot also to manage
|
For groups, there are multiple different tools which help to work with and allows bot also to manage
|
||||||
"Single-User" chats and group chats.
|
"Single-User" chats and group chats.
|
||||||
|
|
||||||
### Splitter Form
|
### Splitter Form
|
||||||
@ -781,9 +782,9 @@ public class GroupForm : FormBase
|
|||||||
|
|
||||||
## Statemachine and Sessions
|
## Statemachine and Sessions
|
||||||
|
|
||||||
Depending on the use-cases and the overall structure of a Telegram Bot it is essential to have some kind of session
|
Depending on the use-cases and the overall structure of a Telegram Bot, it is essential to have some kind of session
|
||||||
serialization or state machine to keep the user context after bot restarts (i.e. due to updates) or crashes.
|
serialization or state machine to keep the user context after bot restarts (i.e. due to updates) or crashes.
|
||||||
For this we have some structures which fits into the current environment.
|
For this, we have some structures which fit into the current environment.
|
||||||
|
|
||||||
### Statemachines
|
### Statemachines
|
||||||
|
|
||||||
@ -809,13 +810,13 @@ var bot = BotBaseBuilder
|
|||||||
.UseEnglish()
|
.UseEnglish()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
bot.Start();
|
await bot.Start();
|
||||||
```
|
```
|
||||||
|
|
||||||
#### JSONStateMachine
|
#### JSONStateMachine
|
||||||
|
|
||||||
Is easy to use too, but works for complex datatypes, because it saves there namespaces and additional type info
|
It is easy to use too, but it works for complex datatypes, because it saves their namespaces and additional type info
|
||||||
into the JSON file too.
|
into the JSON file.
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
var bot = BotBaseBuilder
|
var bot = BotBaseBuilder
|
||||||
@ -832,12 +833,12 @@ var bot = BotBaseBuilder
|
|||||||
.UseEnglish()
|
.UseEnglish()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
bot.Start();
|
await bot.Start();
|
||||||
```
|
```
|
||||||
|
|
||||||
#### XMLStateMachine
|
#### XMLStateMachine
|
||||||
|
|
||||||
The last one, should work like the others.
|
The last one should work like the others.
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
var bot = BotBaseBuilder
|
var bot = BotBaseBuilder
|
||||||
@ -854,7 +855,7 @@ var bot = BotBaseBuilder
|
|||||||
.UseEnglish()
|
.UseEnglish()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
bot.Start();
|
await bot.Start();
|
||||||
```
|
```
|
||||||
|
|
||||||
### Interfaces
|
### Interfaces
|
||||||
@ -899,7 +900,7 @@ keep and restore, use the following attributes.
|
|||||||
|
|
||||||
#### SaveState
|
#### SaveState
|
||||||
|
|
||||||
This will let the engine know, that you want too keep and restore this field automatically. Unlike the IStateForm
|
This will let the engine know that you want to keep and restore this field automatically. Unlike the IStateForm
|
||||||
methods, you have no option to manipulate data.
|
methods, you have no option to manipulate data.
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
@ -909,9 +910,9 @@ public long UserId { get; set; }
|
|||||||
|
|
||||||
#### IgnoreState
|
#### IgnoreState
|
||||||
|
|
||||||
Due to the fact that Attribute implementation and interaction is optional, you want to let the engine maybe know, that
|
Due to the fact that Attribute implementation and interaction is optional, you want to let the engine maybe know that
|
||||||
you don't want to keep a specific form. So it should get *lost*. This attribute will help you here, add it to the form
|
you don't want to keep a specific form. So it should get *lost*. This attribute will help you here, add it to the form
|
||||||
class and it will not get serialized, even if it implements IStateForm or the SaveState attributes.
|
class, and it will not get serialized, even if it implements IStateForm or the SaveState attributes.
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
[IgnoreState]
|
[IgnoreState]
|
||||||
@ -932,21 +933,20 @@ var f = new FormBase();
|
|||||||
await this.NavigateTo(f);
|
await this.NavigateTo(f);
|
||||||
```
|
```
|
||||||
|
|
||||||
Depending on the model and structure of your bot it can make sense, to have more linear navigation instead of *cross*
|
Depending on the model and structure of your bot, it can make sense, to have more linear navigation instead of *cross*-navigation.
|
||||||
navigation.
|
|
||||||
|
|
||||||
For example, you have a bot which shows a list of football teams. And when clicking on it you want to open the team
|
For example, you have a bot which shows a list of football teams. And when clicking on it, you want to open the team
|
||||||
details and latest matches.
|
details and the latest matches.
|
||||||
|
|
||||||
After the matches, you want to maybe switch to different teams and take a look at their statistics and matches.
|
After the matches, you want to maybe switch to different teams and take a look at their statistics and matches.
|
||||||
|
|
||||||
At some point, you *just* want to get back to the first team so like on Android you're clicking the "back" button
|
At some point, you *just* want to get back to the first team, so like on Android you're clicking the "back" button
|
||||||
multiple
|
multiple
|
||||||
times.
|
times.
|
||||||
|
|
||||||
This can become really complicated, when not having some controller below which handle these "Push/Pop" calls.
|
This can become really complicated, when not having some controller below which handle these "Push/Pop" calls.
|
||||||
|
|
||||||
Thats why we hace a NavigationController class which manages these situations and the stack.
|
That's why we have a NavigationController class which manages these situations and the stack.
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
@ -956,7 +956,7 @@ navigation.
|
|||||||
You will use the current FormBase instance as a root class within the constructor, so you can later come back to this
|
You will use the current FormBase instance as a root class within the constructor, so you can later come back to this
|
||||||
one.
|
one.
|
||||||
|
|
||||||
**Tip**: *You can add also a completely new instance of i.e. a main menu form here to get back to it then. So you are
|
**Tip**: *You can also add a completely new instance of i.e. a main menu form here to get back to it then. So you are
|
||||||
free to choose.*
|
free to choose.*
|
||||||
|
|
||||||
We are using the same `FormBase` instance as above.
|
We are using the same `FormBase` instance as above.
|
||||||
@ -1027,6 +1027,7 @@ Will delete Join and Leave messages automatically in groups.
|
|||||||
|
|
||||||
- [Examples/JoinHiderBot](Examples/JoinHiderBot)
|
- [Examples/JoinHiderBot](Examples/JoinHiderBot)
|
||||||
|
|
||||||
When you want to update forms async without any user interaction (message/action) before. Use the new InvokeMessageLoop method of BotBase.
|
When you want to update forms async without any user interaction (message/action) before. Use the new InvokeMessageLoop
|
||||||
|
method of BotBase.
|
||||||
|
|
||||||
- [Examples/AsyncFormUpdates](Examples/AsyncFormUpdates)
|
- [Examples/AsyncFormUpdates](Examples/AsyncFormUpdates)
|
||||||
|
|||||||
@ -1,12 +1,11 @@
|
|||||||
using System;
|
using System.Drawing;
|
||||||
using System.Drawing;
|
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Telegram.Bot.Types.InputFiles;
|
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using TelegramBotBase.Sessions;
|
using Telegram.Bot.Types.InputFiles;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
using TelegramBotBase.Sessions;
|
||||||
|
|
||||||
namespace TelegramBotBase.Extensions.Images
|
namespace TelegramBotBase.Extensions.Images
|
||||||
{
|
{
|
||||||
@ -14,7 +13,7 @@ namespace TelegramBotBase.Extensions.Images
|
|||||||
{
|
{
|
||||||
public static Stream ToStream(this Image image, ImageFormat format)
|
public static Stream ToStream(this Image image, ImageFormat format)
|
||||||
{
|
{
|
||||||
var stream = new System.IO.MemoryStream();
|
var stream = new MemoryStream();
|
||||||
image.Save(stream, format);
|
image.Save(stream, format);
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
return stream;
|
return stream;
|
||||||
@ -29,13 +28,15 @@ namespace TelegramBotBase.Extensions.Images
|
|||||||
/// <param name="replyTo"></param>
|
/// <param name="replyTo"></param>
|
||||||
/// <param name="disableNotification"></param>
|
/// <param name="disableNotification"></param>
|
||||||
/// <returns></returns>
|
/// <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))
|
using (var fileStream = ToStream(image, ImageFormat.Png))
|
||||||
{
|
{
|
||||||
InputOnlineFile fts = new InputOnlineFile(fileStream, name);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,13 +49,15 @@ namespace TelegramBotBase.Extensions.Images
|
|||||||
/// <param name="replyTo"></param>
|
/// <param name="replyTo"></param>
|
||||||
/// <param name="disableNotification"></param>
|
/// <param name="disableNotification"></param>
|
||||||
/// <returns></returns>
|
/// <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))
|
using (var fileStream = ToStream(image, ImageFormat.Png))
|
||||||
{
|
{
|
||||||
InputOnlineFile fts = new InputOnlineFile(fileStream, name);
|
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.nuget.org/packages/TelegramBotBase.Extensions.Images/)
|
||||||
[](https://www.t.me/tgbotbase)
|
[](https://www.t.me/tgbotbase)
|
||||||
|
|
||||||
|
|
||||||
[](https://raw.githubusercontent.com/MajMcCloud/TelegramBotFramework/master/LICENCE.md)
|
[](https://raw.githubusercontent.com/MajMcCloud/TelegramBotFramework/master/LICENCE.md)
|
||||||
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images)
|
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Images)
|
||||||
|
|||||||
@ -1,8 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Builder;
|
using TelegramBotBase.Builder;
|
||||||
using TelegramBotBase.Builder.Interfaces;
|
using TelegramBotBase.Builder.Interfaces;
|
||||||
|
|
||||||
@ -10,18 +6,19 @@ namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
|||||||
{
|
{
|
||||||
public static class BotBaseBuilderExtensions
|
public static class BotBaseBuilderExtensions
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Uses an Microsoft SQL Server Database to save and restore sessions.
|
/// Uses an Microsoft SQL Server Database to save and restore sessions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="builder"></param>
|
/// <param name="builder"></param>
|
||||||
/// <param name="ConnectionString"></param>
|
/// <param name="connectionString"></param>
|
||||||
/// <param name="tablePrefix"></param>
|
/// <param name="tablePrefix"></param>
|
||||||
/// <param name="fallbackForm"></param>
|
/// <param name="fallbackForm"></param>
|
||||||
/// <returns></returns>
|
/// <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);
|
var serializer = new MssqlSerializer(connectionString, tablePrefix, fallbackForm);
|
||||||
|
|
||||||
builder.UseSerialization(serializer);
|
builder.UseSerialization(serializer);
|
||||||
|
|
||||||
@ -33,18 +30,21 @@ namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
|||||||
/// Uses an Microsoft SQL Server Database to save and restore sessions.
|
/// Uses an Microsoft SQL Server Database to save and restore sessions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="builder"></param>
|
/// <param name="builder"></param>
|
||||||
/// <param name="HostOrIP"></param>
|
/// <param name="hostOrIP"></param>
|
||||||
/// <param name="UserId"></param>
|
/// <param name="userId"></param>
|
||||||
/// <param name="Password"></param>
|
/// <param name="password"></param>
|
||||||
/// <param name="DatabaseName"></param>
|
/// <param name="databaseName"></param>
|
||||||
/// <param name="tablePrefix"></param>
|
/// <param name="tablePrefix"></param>
|
||||||
/// <param name="fallbackForm"></param>
|
/// <param name="fallbackForm"></param>
|
||||||
/// <returns></returns>
|
/// <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);
|
var serializer = new MssqlSerializer(connectionString, tablePrefix, fallbackForm);
|
||||||
|
|
||||||
builder.UseSerialization(serializer);
|
builder.UseSerialization(serializer);
|
||||||
|
|
||||||
@ -55,19 +55,24 @@ namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
|||||||
/// Uses an Microsoft SQL Server Database with Windows Authentication to save and restore sessions.
|
/// Uses an Microsoft SQL Server Database with Windows Authentication to save and restore sessions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="builder"></param>
|
/// <param name="builder"></param>
|
||||||
/// <param name="HostOrIP"></param>
|
/// <param name="hostOrIP"></param>
|
||||||
/// <param name="DatabaseName"></param>
|
/// <param name="databaseName"></param>
|
||||||
/// <param name="tablePrefix"></param>
|
/// <param name="tablePrefix"></param>
|
||||||
/// <param name="fallbackForm"></param>
|
/// <param name="fallbackForm"></param>
|
||||||
/// <returns></returns>
|
/// <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)
|
||||||
{
|
{
|
||||||
if (!IntegratedSecurity)
|
|
||||||
throw new ArgumentOutOfRangeException();
|
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);
|
var serializer = new MssqlSerializer(connectionString, tablePrefix, fallbackForm);
|
||||||
|
|
||||||
builder.UseSerialization(serializer);
|
builder.UseSerialization(serializer);
|
||||||
|
|
||||||
|
|||||||
@ -1,45 +1,44 @@
|
|||||||
using TelegramBotBase.Interfaces;
|
using System;
|
||||||
using TelegramBotBase.Builder.Interfaces;
|
|
||||||
using System;
|
|
||||||
using TelegramBotBase.Base;
|
|
||||||
using TelegramBotBase.Args;
|
|
||||||
using TelegramBotBase.Form;
|
|
||||||
using Microsoft.Data.SqlClient;
|
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using Microsoft.Data.SqlClient;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using TelegramBotBase.Args;
|
||||||
|
using TelegramBotBase.Base;
|
||||||
|
using TelegramBotBase.Form;
|
||||||
|
using TelegramBotBase.Interfaces;
|
||||||
|
|
||||||
namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
||||||
{
|
{
|
||||||
public class MSSQLSerializer : IStateMachine
|
public class MssqlSerializer : IStateMachine
|
||||||
{
|
{
|
||||||
public Type FallbackStateForm { get; set; }
|
|
||||||
public string ConnectionString { get; }
|
|
||||||
public String TablePrefix { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Will initialize the state machine.
|
/// Will initialize the state machine.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="file">Path of the file and name where to save the session details.</param>
|
/// <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>
|
/// <param name="overwrite">Declares of the file could be overwritten.</param>
|
||||||
public MSSQLSerializer(String ConnectionString, String tablePrefix = "tgb_", Type fallbackStateForm = null)
|
public MssqlSerializer(string connectionString, string tablePrefix = "tgb_", Type fallbackStateForm = null)
|
||||||
{
|
{
|
||||||
if (ConnectionString is null)
|
ConnectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(ConnectionString));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.ConnectionString = ConnectionString;
|
TablePrefix = tablePrefix;
|
||||||
|
|
||||||
this.TablePrefix = tablePrefix;
|
FallbackStateForm = fallbackStateForm;
|
||||||
|
|
||||||
this.FallbackStateForm = fallbackStateForm;
|
if (FallbackStateForm != null && !FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
||||||
|
|
||||||
if (this.FallbackStateForm != null && !this.FallbackStateForm.IsSubclassOf(typeof(FormBase)))
|
|
||||||
{
|
{
|
||||||
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
throw new ArgumentException("FallbackStateForm is not a subclass of FormBase");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string ConnectionString { get; }
|
||||||
|
public string TablePrefix { get; set; }
|
||||||
|
public Type FallbackStateForm { get; set; }
|
||||||
|
|
||||||
public StateContainer LoadFormStates()
|
public StateContainer LoadFormStates()
|
||||||
{
|
{
|
||||||
var sc = new StateContainer();
|
var sc = new StateContainer();
|
||||||
@ -49,7 +48,8 @@ namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
|||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
var command = connection.CreateCommand();
|
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();
|
var dataTable = new DataTable();
|
||||||
using (var dataAdapter = new SqlDataAdapter(command))
|
using (var dataAdapter = new SqlDataAdapter(command))
|
||||||
@ -58,7 +58,7 @@ namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
|||||||
|
|
||||||
foreach (DataRow r in dataTable.Rows)
|
foreach (DataRow r in dataTable.Rows)
|
||||||
{
|
{
|
||||||
var se = new StateEntry()
|
var se = new StateEntry
|
||||||
{
|
{
|
||||||
DeviceId = (long)r["deviceId"],
|
DeviceId = (long)r["deviceId"],
|
||||||
ChatTitle = r["deviceTitle"].ToString(),
|
ChatTitle = r["deviceTitle"].ToString(),
|
||||||
@ -77,32 +77,30 @@ namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
|||||||
sc.GroupIds.Add(se.DeviceId);
|
sc.GroupIds.Add(se.DeviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
var data_command = connection.CreateCommand();
|
var command2 = connection.CreateCommand();
|
||||||
data_command.CommandText = "SELECT [key], value, type FROM " + TablePrefix + "devices_sessions_data WHERE deviceId = @deviceId";
|
command2.CommandText = "SELECT [key], value, type FROM " + TablePrefix +
|
||||||
data_command.Parameters.Add(new SqlParameter("@deviceId", r["deviceId"]));
|
"devices_sessions_data WHERE deviceId = @deviceId";
|
||||||
|
command2.Parameters.Add(new SqlParameter("@deviceId", r["deviceId"]));
|
||||||
|
|
||||||
var data_table = new DataTable();
|
var dataTable2 = new DataTable();
|
||||||
using (var dataAdapter2 = new SqlDataAdapter(data_command))
|
using (var dataAdapter2 = new SqlDataAdapter(command2))
|
||||||
{
|
{
|
||||||
dataAdapter2.Fill(data_table);
|
dataAdapter2.Fill(dataTable2);
|
||||||
|
|
||||||
foreach (DataRow r2 in data_table.Rows)
|
foreach (DataRow r2 in dataTable2.Rows)
|
||||||
{
|
{
|
||||||
var key = r2["key"].ToString();
|
var key = r2["key"].ToString();
|
||||||
var type = Type.GetType(r2["type"].ToString());
|
var type = Type.GetType(r2["type"].ToString());
|
||||||
|
|
||||||
var value = Newtonsoft.Json.JsonConvert.DeserializeObject(r2["value"].ToString(), type);
|
var value = JsonConvert.DeserializeObject(r2["value"].ToString(), type);
|
||||||
|
|
||||||
se.Values.Add(key, value);
|
se.Values.Add(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
connection.Close();
|
connection.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,69 +116,68 @@ namespace TelegramBotBase.Extensions.Serializer.Database.MSSQL
|
|||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
//Cleanup old Session data
|
//Cleanup old Session data
|
||||||
var clear_command = connection.CreateCommand();
|
var clearCommand = connection.CreateCommand();
|
||||||
|
|
||||||
clear_command.CommandText = $"DELETE FROM {TablePrefix}devices_sessions_data";
|
clearCommand.CommandText = $"DELETE FROM {TablePrefix}devices_sessions_data";
|
||||||
|
|
||||||
clear_command.ExecuteNonQuery();
|
clearCommand.ExecuteNonQuery();
|
||||||
|
|
||||||
clear_command.CommandText = $"DELETE FROM {TablePrefix}devices_sessions";
|
clearCommand.CommandText = $"DELETE FROM {TablePrefix}devices_sessions";
|
||||||
|
|
||||||
clear_command.ExecuteNonQuery();
|
clearCommand.ExecuteNonQuery();
|
||||||
|
|
||||||
//Prepare new session commands
|
//Prepare new session commands
|
||||||
var session_command = connection.CreateCommand();
|
var sessionCommand = connection.CreateCommand();
|
||||||
var data_command = connection.CreateCommand();
|
var dataCommand = connection.CreateCommand();
|
||||||
|
|
||||||
session_command.CommandText = "INSERT INTO " + TablePrefix + "devices_sessions (deviceId, deviceTitle, FormUri, QualifiedName) VALUES (@deviceId, @deviceTitle, @FormUri, @QualifiedName)";
|
sessionCommand.CommandText = "INSERT INTO " + TablePrefix +
|
||||||
session_command.Parameters.Add(new SqlParameter("@deviceId", ""));
|
"devices_sessions (deviceId, deviceTitle, FormUri, QualifiedName) VALUES (@deviceId, @deviceTitle, @FormUri, @QualifiedName)";
|
||||||
session_command.Parameters.Add(new SqlParameter("@deviceTitle", ""));
|
sessionCommand.Parameters.Add(new SqlParameter("@deviceId", ""));
|
||||||
session_command.Parameters.Add(new SqlParameter("@FormUri", ""));
|
sessionCommand.Parameters.Add(new SqlParameter("@deviceTitle", ""));
|
||||||
session_command.Parameters.Add(new SqlParameter("@QualifiedName", ""));
|
sessionCommand.Parameters.Add(new SqlParameter("@FormUri", ""));
|
||||||
|
sessionCommand.Parameters.Add(new SqlParameter("@QualifiedName", ""));
|
||||||
|
|
||||||
data_command.CommandText = "INSERT INTO " + TablePrefix + "devices_sessions_data (deviceId, [key], value, type) VALUES (@deviceId, @key, @value, @type)";
|
dataCommand.CommandText = "INSERT INTO " + TablePrefix +
|
||||||
data_command.Parameters.Add(new SqlParameter("@deviceId", ""));
|
"devices_sessions_data (deviceId, [key], value, type) VALUES (@deviceId, @key, @value, @type)";
|
||||||
data_command.Parameters.Add(new SqlParameter("@key", ""));
|
dataCommand.Parameters.Add(new SqlParameter("@deviceId", ""));
|
||||||
data_command.Parameters.Add(new SqlParameter("@value", ""));
|
dataCommand.Parameters.Add(new SqlParameter("@key", ""));
|
||||||
data_command.Parameters.Add(new SqlParameter("@type", ""));
|
dataCommand.Parameters.Add(new SqlParameter("@value", ""));
|
||||||
|
dataCommand.Parameters.Add(new SqlParameter("@type", ""));
|
||||||
|
|
||||||
//Store session data in database
|
//Store session data in database
|
||||||
foreach (var state in container.States)
|
foreach (var state in container.States)
|
||||||
{
|
{
|
||||||
session_command.Parameters["@deviceId"].Value = state.DeviceId;
|
sessionCommand.Parameters["@deviceId"].Value = state.DeviceId;
|
||||||
session_command.Parameters["@deviceTitle"].Value = state.ChatTitle ?? "";
|
sessionCommand.Parameters["@deviceTitle"].Value = state.ChatTitle ?? "";
|
||||||
session_command.Parameters["@FormUri"].Value = state.FormUri;
|
sessionCommand.Parameters["@FormUri"].Value = state.FormUri;
|
||||||
session_command.Parameters["@QualifiedName"].Value = state.QualifiedName;
|
sessionCommand.Parameters["@QualifiedName"].Value = state.QualifiedName;
|
||||||
|
|
||||||
session_command.ExecuteNonQuery();
|
sessionCommand.ExecuteNonQuery();
|
||||||
|
|
||||||
foreach (var data in state.Values)
|
foreach (var data in state.Values)
|
||||||
{
|
{
|
||||||
data_command.Parameters["@deviceId"].Value = state.DeviceId;
|
dataCommand.Parameters["@deviceId"].Value = state.DeviceId;
|
||||||
data_command.Parameters["@key"].Value = data.Key;
|
dataCommand.Parameters["@key"].Value = data.Key;
|
||||||
|
|
||||||
var type = data.Value.GetType();
|
var type = data.Value.GetType();
|
||||||
|
|
||||||
if (type.IsPrimitive || type.Equals(typeof(string)))
|
if (type.IsPrimitive || type.Equals(typeof(string)))
|
||||||
{
|
{
|
||||||
data_command.Parameters["@value"].Value = data.Value;
|
dataCommand.Parameters["@value"].Value = data.Value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
data_command.Parameters["@value"].Value = Newtonsoft.Json.JsonConvert.SerializeObject(data.Value);
|
dataCommand.Parameters["@value"].Value = JsonConvert.SerializeObject(data.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
data_command.Parameters["@type"].Value = type.AssemblyQualifiedName;
|
dataCommand.Parameters["@type"].Value = type.AssemblyQualifiedName;
|
||||||
|
|
||||||
data_command.ExecuteNonQuery();
|
dataCommand.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
connection.Close();
|
connection.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,7 +3,6 @@
|
|||||||
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Serializer.Database.MSSQL/)
|
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Serializer.Database.MSSQL/)
|
||||||
[](https://www.t.me/tgbotbase)
|
[](https://www.t.me/tgbotbase)
|
||||||
|
|
||||||
|
|
||||||
[](https://raw.githubusercontent.com/MajMcCloud/TelegramBotFramework/master/LICENCE.md)
|
[](https://raw.githubusercontent.com/MajMcCloud/TelegramBotFramework/master/LICENCE.md)
|
||||||
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Serializer.Database.MSSQL)
|
[](https://www.nuget.org/packages/TelegramBotBase.Extensions.Serializer.Database.MSSQL)
|
||||||
|
|
||||||
|
|||||||
@ -1,37 +1,81 @@
|
|||||||
USE [telegram_bot]
|
USE
|
||||||
|
[telegram_bot]
|
||||||
GO
|
GO
|
||||||
/****** Object: Table [dbo].[tgb_devices_sessions] Script Date: 30.06.2022 16:22:09 ******/
|
/****** Object: Table [dbo].[tgb_devices_sessions] Script Date: 30.06.2022 16:22:09 ******/
|
||||||
SET ANSI_NULLS ON
|
SET ANSI_NULLS ON
|
||||||
GO
|
GO
|
||||||
SET QUOTED_IDENTIFIER ON
|
SET QUOTED_IDENTIFIER ON
|
||||||
GO
|
GO
|
||||||
CREATE TABLE [dbo].[tgb_devices_sessions](
|
CREATE TABLE [dbo].[tgb_devices_sessions]
|
||||||
[deviceId] [bigint] NOT NULL,
|
(
|
||||||
[deviceTitle] [nvarchar](512) NOT NULL,
|
[
|
||||||
[FormUri] [nvarchar](512) NOT NULL,
|
deviceId] [
|
||||||
[QualifiedName] [nvarchar](512) NOT NULL,
|
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
|
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]
|
deviceId] ASC
|
||||||
) ON [PRIMARY]
|
)
|
||||||
|
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
|
GO
|
||||||
/****** Object: Table [dbo].[tgb_devices_sessions_data] Script Date: 30.06.2022 16:22:09 ******/
|
/****** Object: Table [dbo].[tgb_devices_sessions_data] Script Date: 30.06.2022 16:22:09 ******/
|
||||||
SET ANSI_NULLS ON
|
SET ANSI_NULLS
|
||||||
|
ON
|
||||||
GO
|
GO
|
||||||
SET QUOTED_IDENTIFIER ON
|
SET QUOTED_IDENTIFIER
|
||||||
|
ON
|
||||||
GO
|
GO
|
||||||
CREATE TABLE [dbo].[tgb_devices_sessions_data](
|
CREATE TABLE [dbo].[tgb_devices_sessions_data]
|
||||||
[Id] [uniqueidentifier] NOT NULL,
|
(
|
||||||
[deviceId] [bigint] NOT NULL,
|
[
|
||||||
[key] [nvarchar](512) NOT NULL,
|
Id] [
|
||||||
[value] [nvarchar](max) NOT NULL,
|
uniqueidentifier]
|
||||||
[type] [nvarchar](512) NOT NULL,
|
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
|
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]
|
Id] ASC
|
||||||
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
|
)
|
||||||
|
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
|
GO
|
||||||
ALTER TABLE [dbo].[tgb_devices_sessions_data] ADD CONSTRAINT [DF_tgb_devices_session_data_Id] DEFAULT (newid()) FOR [Id]
|
ALTER TABLE [dbo].[tgb_devices_sessions_data] ADD CONSTRAINT [DF_tgb_devices_session_data_Id] DEFAULT (newid()) FOR [Id]
|
||||||
GO
|
GO
|
||||||
|
|||||||
@ -1,14 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<configuration>
|
|
||||||
<startup>
|
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
|
|
||||||
</startup>
|
|
||||||
<runtime>
|
|
||||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
|
||||||
<dependentAssembly>
|
|
||||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
|
|
||||||
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0"/>
|
|
||||||
</dependentAssembly>
|
|
||||||
</assemblyBinding>
|
|
||||||
</runtime>
|
|
||||||
</configuration>
|
|
||||||
@ -1,27 +1,22 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Telegram.Bot.Types;
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase;
|
|
||||||
using TelegramBotBase.Form;
|
|
||||||
using TelegramBotBaseTest.Tests;
|
|
||||||
using TelegramBotBase.Commands;
|
|
||||||
using TelegramBotBase.Builder;
|
using TelegramBotBase.Builder;
|
||||||
|
using TelegramBotBase.Commands;
|
||||||
|
using TelegramBotBase.Enums;
|
||||||
|
using TelegramBotBase.Example.Tests;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest
|
namespace TelegramBotBase.Example;
|
||||||
{
|
|
||||||
class Program
|
|
||||||
{
|
|
||||||
static async void Main(string[] args)
|
|
||||||
{
|
|
||||||
|
|
||||||
String APIKey = "";
|
internal class Program
|
||||||
|
{
|
||||||
var bb = BotBaseBuilder
|
private static async Task Main(string[] args)
|
||||||
|
{
|
||||||
|
var bot = BotBaseBuilder
|
||||||
.Create()
|
.Create()
|
||||||
.WithAPIKey(APIKey)
|
.WithAPIKey(Environment.GetEnvironmentVariable("API_KEY") ??
|
||||||
|
throw new Exception("API_KEY is not set"))
|
||||||
.DefaultMessageLoop()
|
.DefaultMessageLoop()
|
||||||
.WithStartForm<Start>()
|
.WithStartForm<Start>()
|
||||||
.NoProxy()
|
.NoProxy()
|
||||||
@ -40,32 +35,29 @@ namespace TelegramBotBaseTest
|
|||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
|
||||||
bb.BotCommand += Bb_BotCommand;
|
bot.BotCommand += Bb_BotCommand;
|
||||||
|
|
||||||
//Update Bot commands to botfather
|
//Update Bot commands to botfather
|
||||||
await bb.UploadBotCommands();
|
bot.UploadBotCommands().Wait();
|
||||||
|
|
||||||
bb.SetSetting(TelegramBotBase.Enums.eSettings.LogAllMessages, true);
|
bot.SetSetting(ESettings.LogAllMessages, true);
|
||||||
|
|
||||||
bb.Message += (s, en) =>
|
bot.Message += (s, en) =>
|
||||||
{
|
{
|
||||||
Console.WriteLine(en.DeviceId + " " + en.Message.MessageText + " " + (en.Message.RawData ?? ""));
|
Console.WriteLine(en.DeviceId + " " + en.Message.MessageText + " " + (en.Message.RawData ?? ""));
|
||||||
};
|
};
|
||||||
|
|
||||||
bb.Start();
|
await bot.Start();
|
||||||
|
|
||||||
Console.WriteLine("Telegram Bot started...");
|
Console.WriteLine("Telegram Bot started...");
|
||||||
|
|
||||||
Console.WriteLine("Press q to quit application.");
|
Console.WriteLine("Press q to quit application.");
|
||||||
|
|
||||||
|
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
|
|
||||||
bb.Stop();
|
await bot.Stop();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task Bb_BotCommand(object sender, TelegramBotBase.Args.BotCommandEventArgs en)
|
private static async Task Bb_BotCommand(object sender, BotCommandEventArgs en)
|
||||||
{
|
{
|
||||||
switch (en.Command)
|
switch (en.Command)
|
||||||
{
|
{
|
||||||
@ -105,7 +97,7 @@ namespace TelegramBotBaseTest
|
|||||||
|
|
||||||
case "/params":
|
case "/params":
|
||||||
|
|
||||||
String m = en.Parameters.DefaultIfEmpty("").Aggregate((a, b) => a + " and " + b);
|
var m = en.Parameters.DefaultIfEmpty("").Aggregate((a, b) => a + " and " + b);
|
||||||
|
|
||||||
await en.Device.Send("Your parameters are: " + m, replyTo: en.Device.LastMessageId);
|
await en.Device.Send("Your parameters are: " + m, replyTo: en.Device.LastMessageId);
|
||||||
|
|
||||||
@ -115,4 +107,3 @@ namespace TelegramBotBaseTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@ -1,36 +0,0 @@
|
|||||||
using System.Reflection;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
|
||||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
|
||||||
// die einer Assembly zugeordnet sind.
|
|
||||||
[assembly: AssemblyTitle("TelegramBotBaseTest")]
|
|
||||||
[assembly: AssemblyDescription("")]
|
|
||||||
[assembly: AssemblyConfiguration("")]
|
|
||||||
[assembly: AssemblyCompany("")]
|
|
||||||
[assembly: AssemblyProduct("TelegramBotBaseTest")]
|
|
||||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
|
||||||
[assembly: AssemblyTrademark("")]
|
|
||||||
[assembly: AssemblyCulture("")]
|
|
||||||
|
|
||||||
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
|
|
||||||
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
|
|
||||||
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
|
|
||||||
[assembly: ComVisible(false)]
|
|
||||||
|
|
||||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
|
||||||
[assembly: Guid("5817184c-0d59-4924-ac6c-6b943967811c")]
|
|
||||||
|
|
||||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
|
||||||
//
|
|
||||||
// Hauptversion
|
|
||||||
// Nebenversion
|
|
||||||
// Buildnummer
|
|
||||||
// Revision
|
|
||||||
//
|
|
||||||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
|
||||||
// übernehmen, indem Sie "*" eingeben:
|
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
||||||
15
TelegramBotBase.Test/TelegramBotBase.Example.csproj
Normal file
15
TelegramBotBase.Test/TelegramBotBase.Example.csproj
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>disable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\TelegramBotBase.Extensions.Images\TelegramBotBase.Extensions.Images.csproj" />
|
||||||
|
<ProjectReference Include="..\TelegramBotBase\TelegramBotBase.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@ -1,34 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>Exe</OutputType>
|
|
||||||
<TargetFrameworks>netcoreapp3.1;net5;net6</TargetFrameworks>
|
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
|
||||||
<Configurations>Debug;Release</Configurations>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
|
||||||
<DebugType>pdbonly</DebugType>
|
|
||||||
<Optimize>true</Optimize>
|
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\TelegramBotBase.Extensions.Images\TelegramBotBase.Extensions.Images.csproj" />
|
|
||||||
<ProjectReference Include="..\TelegramBotBase\TelegramBotBase.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@ -1,36 +1,33 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests
|
namespace TelegramBotBase.Example.Tests;
|
||||||
{
|
|
||||||
public class ButtonTestForm : AutoCleanForm
|
public class ButtonTestForm : AutoCleanForm
|
||||||
{
|
{
|
||||||
|
|
||||||
public ButtonTestForm()
|
public ButtonTestForm()
|
||||||
{
|
{
|
||||||
this.Opened += ButtonTestForm_Opened;
|
Opened += ButtonTestForm_Opened;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ButtonTestForm_Opened(object sender, EventArgs e)
|
private async Task ButtonTestForm_Opened(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await this.Device.Send("Hello world! (Click 'back' to get back to Start)");
|
await Device.Send("Hello world! (Click 'back' to get back to Start)");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Action(MessageResult message)
|
public override async Task Action(MessageResult message)
|
||||||
{
|
{
|
||||||
|
|
||||||
var call = message.GetData<CallbackData>();
|
var call = message.GetData<CallbackData>();
|
||||||
|
|
||||||
await message.ConfirmAction();
|
await message.ConfirmAction();
|
||||||
|
|
||||||
|
|
||||||
if (call == null)
|
if (call == null)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
message.Handled = true;
|
message.Handled = true;
|
||||||
|
|
||||||
@ -38,25 +35,25 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
{
|
{
|
||||||
case "button1":
|
case "button1":
|
||||||
|
|
||||||
await this.Device.Send("Button 1 pressed");
|
await Device.Send("Button 1 pressed");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "button2":
|
case "button2":
|
||||||
|
|
||||||
await this.Device.Send("Button 2 pressed");
|
await Device.Send("Button 2 pressed");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "button3":
|
case "button3":
|
||||||
|
|
||||||
await this.Device.Send("Button 3 pressed");
|
await Device.Send("Button 3 pressed");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "button4":
|
case "button4":
|
||||||
|
|
||||||
await this.Device.Send("Button 4 pressed");
|
await Device.Send("Button 4 pressed");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -64,7 +61,7 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
var st = new Menu();
|
var st = new Menu();
|
||||||
|
|
||||||
await this.NavigateTo(st);
|
await NavigateTo(st);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -74,29 +71,24 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override async Task Render(MessageResult message)
|
public override async Task Render(MessageResult message)
|
||||||
{
|
{
|
||||||
|
var btn = new ButtonForm();
|
||||||
|
|
||||||
ButtonForm 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()));
|
btn.AddButtonRow(new ButtonBase("Back", new CallbackData("a", "back").Serialize()));
|
||||||
|
|
||||||
await this.Device.Send("Click a button", btn);
|
await Device.Send("Click a button", btn);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,34 +1,30 @@
|
|||||||
using System;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase.Controls;
|
|
||||||
using TelegramBotBase.Controls.Hybrid;
|
using TelegramBotBase.Controls.Hybrid;
|
||||||
|
using TelegramBotBase.Enums;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Controls
|
namespace TelegramBotBase.Example.Tests.Controls;
|
||||||
{
|
|
||||||
public class ButtonGridForm : AutoCleanForm
|
public class ButtonGridForm : AutoCleanForm
|
||||||
{
|
{
|
||||||
|
private ButtonGrid _mButtons;
|
||||||
ButtonGrid m_Buttons = null;
|
|
||||||
|
|
||||||
public ButtonGridForm()
|
public ButtonGridForm()
|
||||||
{
|
{
|
||||||
this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
|
DeleteMode = EDeleteMode.OnLeavingForm;
|
||||||
|
|
||||||
this.Init += ButtonGridForm_Init;
|
Init += ButtonGridForm_Init;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ButtonGridForm_Init(object sender, InitEventArgs e)
|
private Task ButtonGridForm_Init(object sender, InitEventArgs e)
|
||||||
{
|
{
|
||||||
m_Buttons = new ButtonGrid();
|
_mButtons = new ButtonGrid
|
||||||
|
{
|
||||||
|
KeyboardType = EKeyboardType.InlineKeyBoard
|
||||||
|
};
|
||||||
|
|
||||||
m_Buttons.KeyboardType = TelegramBotBase.Enums.eKeyboardType.InlineKeyBoard;
|
var bf = new ButtonForm();
|
||||||
|
|
||||||
ButtonForm bf = new ButtonForm();
|
|
||||||
|
|
||||||
bf.AddButtonRow(new ButtonBase("Back", "back"), new ButtonBase("Switch Keyboard", "switch"));
|
bf.AddButtonRow(new ButtonBase("Back", "back"), new ButtonBase("Switch Keyboard", "switch"));
|
||||||
|
|
||||||
@ -36,46 +32,38 @@ namespace TelegramBotBaseTest.Tests.Controls
|
|||||||
|
|
||||||
bf.AddButtonRow(new ButtonBase("Button3", "b3"), new ButtonBase("Button4", "b4"));
|
bf.AddButtonRow(new ButtonBase("Button3", "b3"), new ButtonBase("Button4", "b4"));
|
||||||
|
|
||||||
m_Buttons.ButtonsForm = bf;
|
_mButtons.DataSource.ButtonForm = bf;
|
||||||
|
|
||||||
m_Buttons.ButtonClicked += Bg_ButtonClicked;
|
|
||||||
|
|
||||||
this.AddControl(m_Buttons);
|
|
||||||
|
|
||||||
|
_mButtons.ButtonClicked += Bg_ButtonClicked;
|
||||||
|
|
||||||
|
AddControl(_mButtons);
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Bg_ButtonClicked(object sender, ButtonClickedEventArgs e)
|
private async Task Bg_ButtonClicked(object sender, ButtonClickedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Button == null)
|
if (e.Button == null)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (e.Button.Value == "back")
|
if (e.Button.Value == "back")
|
||||||
{
|
{
|
||||||
var start = new Menu();
|
var start = new Menu();
|
||||||
await this.NavigateTo(start);
|
await NavigateTo(start);
|
||||||
}
|
}
|
||||||
else if (e.Button.Value == "switch")
|
else if (e.Button.Value == "switch")
|
||||||
{
|
{
|
||||||
switch (m_Buttons.KeyboardType)
|
_mButtons.KeyboardType = _mButtons.KeyboardType switch
|
||||||
{
|
{
|
||||||
case TelegramBotBase.Enums.eKeyboardType.ReplyKeyboard:
|
EKeyboardType.ReplyKeyboard => EKeyboardType.InlineKeyBoard,
|
||||||
m_Buttons.KeyboardType = TelegramBotBase.Enums.eKeyboardType.InlineKeyBoard;
|
EKeyboardType.InlineKeyBoard => EKeyboardType.ReplyKeyboard,
|
||||||
break;
|
_ => _mButtons.KeyboardType
|
||||||
case TelegramBotBase.Enums.eKeyboardType.InlineKeyBoard:
|
};
|
||||||
m_Buttons.KeyboardType = TelegramBotBase.Enums.eKeyboardType.ReplyKeyboard;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
await Device.Send($"Button clicked with Text: {e.Button.Text} and Value {e.Button.Value}");
|
||||||
await this.Device.Send($"Button clicked with Text: {e.Button.Text} and Value {e.Button.Value}");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,74 +1,66 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase.Controls;
|
|
||||||
using TelegramBotBase.Controls.Hybrid;
|
using TelegramBotBase.Controls.Hybrid;
|
||||||
|
using TelegramBotBase.Enums;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Controls
|
namespace TelegramBotBase.Example.Tests.Controls;
|
||||||
{
|
|
||||||
public class ButtonGridPagingForm : AutoCleanForm
|
public class ButtonGridPagingForm : AutoCleanForm
|
||||||
{
|
{
|
||||||
|
private ButtonGrid _mButtons;
|
||||||
ButtonGrid m_Buttons = null;
|
|
||||||
|
|
||||||
public ButtonGridPagingForm()
|
public ButtonGridPagingForm()
|
||||||
{
|
{
|
||||||
this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
|
DeleteMode = EDeleteMode.OnLeavingForm;
|
||||||
|
|
||||||
this.Init += ButtonGridForm_Init;
|
Init += ButtonGridForm_Init;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ButtonGridForm_Init(object sender, InitEventArgs e)
|
private Task ButtonGridForm_Init(object sender, InitEventArgs e)
|
||||||
{
|
{
|
||||||
m_Buttons = new ButtonGrid();
|
_mButtons = new ButtonGrid
|
||||||
|
{
|
||||||
m_Buttons.KeyboardType = TelegramBotBase.Enums.eKeyboardType.ReplyKeyboard;
|
KeyboardType = EKeyboardType.ReplyKeyboard,
|
||||||
|
EnablePaging = true,
|
||||||
m_Buttons.EnablePaging = true;
|
EnableSearch = true,
|
||||||
m_Buttons.EnableSearch = true;
|
HeadLayoutButtonRow = new List<ButtonBase> { new("Back", "back") }
|
||||||
|
};
|
||||||
m_Buttons.HeadLayoutButtonRow = new List<ButtonBase>() { new ButtonBase("Back", "back") };
|
|
||||||
|
|
||||||
var countries = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
|
var countries = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
|
||||||
|
|
||||||
ButtonForm bf = new ButtonForm();
|
var bf = new ButtonForm();
|
||||||
|
|
||||||
foreach (var c in countries)
|
foreach (var c in countries)
|
||||||
{
|
{
|
||||||
bf.AddButtonRow(new ButtonBase(c.EnglishName, c.EnglishName));
|
bf.AddButtonRow(new ButtonBase(c.EnglishName, c.EnglishName));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Buttons.ButtonsForm = bf;
|
_mButtons.DataSource.ButtonForm = bf;
|
||||||
|
|
||||||
m_Buttons.ButtonClicked += Bg_ButtonClicked;
|
|
||||||
|
|
||||||
this.AddControl(m_Buttons);
|
|
||||||
|
|
||||||
|
_mButtons.ButtonClicked += Bg_ButtonClicked;
|
||||||
|
|
||||||
|
AddControl(_mButtons);
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Bg_ButtonClicked(object sender, ButtonClickedEventArgs e)
|
private async Task Bg_ButtonClicked(object sender, ButtonClickedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Button == null)
|
if (e.Button == null)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (e.Button.Value == "back")
|
if (e.Button.Value == "back")
|
||||||
{
|
{
|
||||||
var start = new Menu();
|
var start = new Menu();
|
||||||
await this.NavigateTo(start);
|
await NavigateTo(start);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
await Device.Send($"Button clicked with Text: {e.Button.Text} and Value {e.Button.Value}");
|
||||||
await this.Device.Send($"Button clicked with Text: {e.Button.Text} and Value {e.Button.Value}");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,77 +1,74 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase.Controls;
|
|
||||||
using TelegramBotBase.Controls.Hybrid;
|
using TelegramBotBase.Controls.Hybrid;
|
||||||
|
using TelegramBotBase.DataSources;
|
||||||
|
using TelegramBotBase.Enums;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Controls
|
namespace TelegramBotBase.Example.Tests.Controls;
|
||||||
{
|
|
||||||
public class ButtonGridTagForm : AutoCleanForm
|
public class ButtonGridTagForm : AutoCleanForm
|
||||||
{
|
{
|
||||||
|
private TaggedButtonGrid _mButtons;
|
||||||
TaggedButtonGrid m_Buttons = null;
|
|
||||||
|
|
||||||
public ButtonGridTagForm()
|
public ButtonGridTagForm()
|
||||||
{
|
{
|
||||||
this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
|
DeleteMode = EDeleteMode.OnLeavingForm;
|
||||||
|
|
||||||
this.Init += ButtonGridTagForm_Init;
|
Init += ButtonGridTagForm_Init;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ButtonGridTagForm_Init(object sender, InitEventArgs e)
|
private Task ButtonGridTagForm_Init(object sender, InitEventArgs e)
|
||||||
{
|
{
|
||||||
m_Buttons = new TaggedButtonGrid();
|
_mButtons = new TaggedButtonGrid
|
||||||
|
{
|
||||||
m_Buttons.KeyboardType = TelegramBotBase.Enums.eKeyboardType.ReplyKeyboard;
|
KeyboardType = EKeyboardType.ReplyKeyboard,
|
||||||
|
EnablePaging = true,
|
||||||
m_Buttons.EnablePaging = true;
|
HeadLayoutButtonRow = new List<ButtonBase> { new("Back", "back") }
|
||||||
|
};
|
||||||
m_Buttons.HeadLayoutButtonRow = new List<ButtonBase>() { new ButtonBase("Back", "back") };
|
|
||||||
|
|
||||||
|
|
||||||
var countries = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
|
var countries = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
|
||||||
|
|
||||||
ButtonForm bf = new ButtonForm();
|
var bf = new ButtonForm();
|
||||||
|
|
||||||
foreach (var c in countries)
|
foreach (var c in countries)
|
||||||
{
|
{
|
||||||
bf.AddButtonRow(new TagButtonBase(c.EnglishName, c.EnglishName, c.Parent.EnglishName));
|
bf.AddButtonRow(new TagButtonBase(c.EnglishName, c.EnglishName, c.Parent.EnglishName));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Buttons.Tags = countries.Select(a => a.Parent.EnglishName).Distinct().OrderBy(a => a).ToList();
|
_mButtons.Tags = countries.Select(a => a.Parent.EnglishName).Distinct().OrderBy(a => a).ToList();
|
||||||
m_Buttons.SelectedTags = countries.Select(a => a.Parent.EnglishName).Distinct().OrderBy(a => a).ToList();
|
_mButtons.SelectedTags = countries.Select(a => a.Parent.EnglishName).Distinct().OrderBy(a => a).ToList();
|
||||||
|
|
||||||
m_Buttons.EnableCheckAllTools = true;
|
_mButtons.EnableCheckAllTools = true;
|
||||||
|
|
||||||
m_Buttons.DataSource = new TelegramBotBase.Datasources.ButtonFormDataSource(bf);
|
_mButtons.DataSource = new ButtonFormDataSource(bf);
|
||||||
|
|
||||||
m_Buttons.ButtonClicked += Bg_ButtonClicked;
|
_mButtons.ButtonClicked += Bg_ButtonClicked;
|
||||||
|
|
||||||
this.AddControl(m_Buttons);
|
AddControl(_mButtons);
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Bg_ButtonClicked(object sender, ButtonClickedEventArgs e)
|
private async Task Bg_ButtonClicked(object sender, ButtonClickedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Button == null)
|
if (e.Button == null)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (e.Button.Value)
|
switch (e.Button.Value)
|
||||||
{
|
{
|
||||||
|
|
||||||
case "back":
|
case "back":
|
||||||
var start = new Menu();
|
var start = new Menu();
|
||||||
await this.NavigateTo(start);
|
await NavigateTo(start);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
await this.Device.Send($"Button clicked with Text: {e.Button.Text} and Value {e.Button.Value}");
|
await Device.Send($"Button clicked with Text: {e.Button.Text} and Value {e.Button.Value}");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,81 +1,69 @@
|
|||||||
using System;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Base;
|
|
||||||
using TelegramBotBase.Form;
|
|
||||||
using TelegramBotBase.Controls;
|
|
||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Controls.Inline;
|
using TelegramBotBase.Controls.Inline;
|
||||||
|
using TelegramBotBase.Enums;
|
||||||
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
|
namespace TelegramBotBase.Example.Tests.Controls;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Controls
|
|
||||||
{
|
|
||||||
public class CalendarPickerForm : AutoCleanForm
|
public class CalendarPickerForm : AutoCleanForm
|
||||||
{
|
{
|
||||||
|
public CalendarPickerForm()
|
||||||
|
{
|
||||||
|
DeleteMode = EDeleteMode.OnLeavingForm;
|
||||||
|
Init += CalendarPickerForm_Init;
|
||||||
|
}
|
||||||
|
|
||||||
public CalendarPicker Picker { get; set; }
|
public CalendarPicker Picker { get; set; }
|
||||||
|
|
||||||
int? selectedDateMessage { get; set; }
|
private int? SelectedDateMessage { get; set; }
|
||||||
|
|
||||||
public CalendarPickerForm()
|
private Task CalendarPickerForm_Init(object sender, InitEventArgs e)
|
||||||
{
|
{
|
||||||
this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
|
Picker = new CalendarPicker
|
||||||
this.Init += CalendarPickerForm_Init;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task CalendarPickerForm_Init(object sender, InitEventArgs e)
|
|
||||||
{
|
{
|
||||||
this.Picker = new CalendarPicker();
|
Title = "Datum auswählen / Pick date"
|
||||||
this.Picker.Title = "Datum auswählen / Pick date";
|
};
|
||||||
|
|
||||||
this.AddControl(Picker);
|
AddControl(Picker);
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override async Task Action(MessageResult message)
|
public override async Task Action(MessageResult message)
|
||||||
{
|
{
|
||||||
|
|
||||||
switch (message.RawData)
|
switch (message.RawData)
|
||||||
{
|
{
|
||||||
case "back":
|
case "back":
|
||||||
|
|
||||||
var s = new Menu();
|
var s = new Menu();
|
||||||
|
|
||||||
await this.NavigateTo(s);
|
await NavigateTo(s);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Render(MessageResult message)
|
public override async Task Render(MessageResult message)
|
||||||
{
|
{
|
||||||
String s = "";
|
var s = "";
|
||||||
|
|
||||||
s = "Selected date is " + this.Picker.SelectedDate.ToShortDateString() + "\r\n";
|
s = "Selected date is " + Picker.SelectedDate.ToShortDateString() + "\r\n";
|
||||||
s += "Selected month is " + this.Picker.Culture.DateTimeFormat.MonthNames[this.Picker.VisibleMonth.Month - 1] + "\r\n";
|
s += "Selected month is " + Picker.Culture.DateTimeFormat.MonthNames[Picker.VisibleMonth.Month - 1] + "\r\n";
|
||||||
s += "Selected year is " + this.Picker.VisibleMonth.Year.ToString();
|
s += "Selected year is " + Picker.VisibleMonth.Year;
|
||||||
|
|
||||||
ButtonForm bf = new ButtonForm();
|
var bf = new ButtonForm();
|
||||||
bf.AddButtonRow(new ButtonBase("Back", "back"));
|
bf.AddButtonRow(new ButtonBase("Back", "back"));
|
||||||
|
|
||||||
if (selectedDateMessage != null)
|
if (SelectedDateMessage != null)
|
||||||
{
|
{
|
||||||
await this.Device.Edit(this.selectedDateMessage.Value, s, bf);
|
await Device.Edit(SelectedDateMessage.Value, s, bf);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var m = await this.Device.Send(s, bf);
|
var m = await Device.Send(s, bf);
|
||||||
this.selectedDateMessage = m.MessageId;
|
SelectedDateMessage = m.MessageId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,62 +1,63 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase.Controls;
|
|
||||||
using TelegramBotBase.Controls.Hybrid;
|
using TelegramBotBase.Controls.Hybrid;
|
||||||
|
using TelegramBotBase.DataSources;
|
||||||
|
using TelegramBotBase.Enums;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Controls
|
namespace TelegramBotBase.Example.Tests.Controls;
|
||||||
{
|
|
||||||
public class CheckedButtonListForm : AutoCleanForm
|
public class CheckedButtonListForm : AutoCleanForm
|
||||||
{
|
{
|
||||||
|
private CheckedButtonList _mButtons;
|
||||||
CheckedButtonList m_Buttons = null;
|
|
||||||
|
|
||||||
public CheckedButtonListForm()
|
public CheckedButtonListForm()
|
||||||
{
|
{
|
||||||
this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
|
DeleteMode = EDeleteMode.OnLeavingForm;
|
||||||
|
|
||||||
this.Init += CheckedButtonListForm_Init;
|
Init += CheckedButtonListForm_Init;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CheckedButtonListForm_Init(object sender, InitEventArgs e)
|
private Task CheckedButtonListForm_Init(object sender, InitEventArgs e)
|
||||||
{
|
{
|
||||||
m_Buttons = new CheckedButtonList();
|
_mButtons = new CheckedButtonList
|
||||||
|
{
|
||||||
|
KeyboardType = EKeyboardType.InlineKeyBoard,
|
||||||
|
EnablePaging = true,
|
||||||
|
HeadLayoutButtonRow = new List<ButtonBase> { new("Back", "back"), new("Switch Keyboard", "switch") },
|
||||||
|
SubHeadLayoutButtonRow = new List<ButtonBase> { new("No checked items", "$") }
|
||||||
|
};
|
||||||
|
|
||||||
m_Buttons.KeyboardType = TelegramBotBase.Enums.eKeyboardType.InlineKeyBoard;
|
var bf = new ButtonForm();
|
||||||
m_Buttons.EnablePaging = true;
|
|
||||||
|
|
||||||
m_Buttons.HeadLayoutButtonRow = new List<ButtonBase>() { new ButtonBase("Back", "back"), new ButtonBase("Switch Keyboard", "switch") };
|
for (var i = 0; i < 30; i++)
|
||||||
|
|
||||||
m_Buttons.SubHeadLayoutButtonRow = new List<ButtonBase>() { new ButtonBase("No checked items", "$") };
|
|
||||||
|
|
||||||
ButtonForm bf = new ButtonForm();
|
|
||||||
|
|
||||||
for (int i = 0; i < 30; i++)
|
|
||||||
{
|
{
|
||||||
bf.AddButtonRow($"{i + 1}. Item", i.ToString());
|
bf.AddButtonRow($"{i + 1}. Item", i.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Buttons.DataSource = new TelegramBotBase.Datasources.ButtonFormDataSource(bf);
|
_mButtons.DataSource = new ButtonFormDataSource(bf);
|
||||||
|
|
||||||
m_Buttons.ButtonClicked += Bg_ButtonClicked;
|
_mButtons.ButtonClicked += Bg_ButtonClicked;
|
||||||
m_Buttons.CheckedChanged += M_Buttons_CheckedChanged;
|
_mButtons.CheckedChanged += M_Buttons_CheckedChanged;
|
||||||
|
|
||||||
this.AddControl(m_Buttons);
|
AddControl(_mButtons);
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task M_Buttons_CheckedChanged(object sender, CheckedChangedEventArgs e)
|
private Task M_Buttons_CheckedChanged(object sender, CheckedChangedEventArgs e)
|
||||||
{
|
{
|
||||||
m_Buttons.SubHeadLayoutButtonRow = new List<ButtonBase>() { new ButtonBase($"{m_Buttons.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)
|
private async Task Bg_ButtonClicked(object sender, ButtonClickedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Button == null)
|
if (e.Button == null)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (e.Button.Value)
|
switch (e.Button.Value)
|
||||||
{
|
{
|
||||||
@ -68,16 +69,12 @@ namespace TelegramBotBaseTest.Tests.Controls
|
|||||||
|
|
||||||
|
|
||||||
case "switch":
|
case "switch":
|
||||||
switch (m_Buttons.KeyboardType)
|
_mButtons.KeyboardType = _mButtons.KeyboardType switch
|
||||||
{
|
{
|
||||||
case TelegramBotBase.Enums.eKeyboardType.ReplyKeyboard:
|
EKeyboardType.ReplyKeyboard => EKeyboardType.InlineKeyBoard,
|
||||||
m_Buttons.KeyboardType = TelegramBotBase.Enums.eKeyboardType.InlineKeyBoard;
|
EKeyboardType.InlineKeyBoard => EKeyboardType.ReplyKeyboard,
|
||||||
break;
|
_ => _mButtons.KeyboardType
|
||||||
case TelegramBotBase.Enums.eKeyboardType.InlineKeyBoard:
|
};
|
||||||
m_Buttons.KeyboardType = TelegramBotBase.Enums.eKeyboardType.ReplyKeyboard;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -85,8 +82,5 @@ namespace TelegramBotBaseTest.Tests.Controls
|
|||||||
await Device.Send($"Button clicked with Text: {e.Button.Text} and Value {e.Button.Value}");
|
await Device.Send($"Button clicked with Text: {e.Button.Text} and Value {e.Button.Value}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,79 +1,67 @@
|
|||||||
using System;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Base;
|
|
||||||
using TelegramBotBase.Form;
|
|
||||||
using TelegramBotBase.Controls;
|
|
||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Controls.Inline;
|
using TelegramBotBase.Controls.Inline;
|
||||||
|
using TelegramBotBase.Enums;
|
||||||
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
|
namespace TelegramBotBase.Example.Tests.Controls;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Controls
|
|
||||||
{
|
|
||||||
public class MonthPickerForm : AutoCleanForm
|
public class MonthPickerForm : AutoCleanForm
|
||||||
{
|
{
|
||||||
|
public MonthPickerForm()
|
||||||
|
{
|
||||||
|
DeleteMode = EDeleteMode.OnLeavingForm;
|
||||||
|
Init += MonthPickerForm_Init;
|
||||||
|
}
|
||||||
|
|
||||||
public MonthPicker Picker { get; set; }
|
public MonthPicker Picker { get; set; }
|
||||||
|
|
||||||
int? selectedDateMessage { get; set; }
|
private int? SelectedDateMessage { get; set; }
|
||||||
|
|
||||||
public MonthPickerForm()
|
private Task MonthPickerForm_Init(object sender, InitEventArgs e)
|
||||||
{
|
{
|
||||||
this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
|
Picker = new MonthPicker
|
||||||
this.Init += MonthPickerForm_Init;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task MonthPickerForm_Init(object sender, InitEventArgs e)
|
|
||||||
{
|
{
|
||||||
this.Picker = new MonthPicker();
|
Title = "Monat auswählen / Pick month"
|
||||||
this.Picker.Title = "Monat auswählen / Pick month";
|
};
|
||||||
this.AddControl(Picker);
|
AddControl(Picker);
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override async Task Action(MessageResult message)
|
public override async Task Action(MessageResult message)
|
||||||
{
|
{
|
||||||
|
|
||||||
switch (message.RawData)
|
switch (message.RawData)
|
||||||
{
|
{
|
||||||
case "back":
|
case "back":
|
||||||
|
|
||||||
var s = new Menu();
|
var s = new Menu();
|
||||||
|
|
||||||
await this.NavigateTo(s);
|
await NavigateTo(s);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Render(MessageResult message)
|
public override async Task Render(MessageResult message)
|
||||||
{
|
{
|
||||||
String s = "";
|
var s = "";
|
||||||
|
|
||||||
s += "Selected month is " + this.Picker.Culture.DateTimeFormat.MonthNames[this.Picker.SelectedDate.Month - 1] + "\r\n";
|
s += "Selected month is " + Picker.Culture.DateTimeFormat.MonthNames[Picker.SelectedDate.Month - 1] + "\r\n";
|
||||||
s += "Selected year is " + this.Picker.VisibleMonth.Year.ToString();
|
s += "Selected year is " + Picker.VisibleMonth.Year;
|
||||||
|
|
||||||
ButtonForm bf = new ButtonForm();
|
var bf = new ButtonForm();
|
||||||
bf.AddButtonRow(new ButtonBase("Back", "back"));
|
bf.AddButtonRow(new ButtonBase("Back", "back"));
|
||||||
|
|
||||||
if (selectedDateMessage != null)
|
if (SelectedDateMessage != null)
|
||||||
{
|
{
|
||||||
await this.Device.Edit(this.selectedDateMessage.Value, s, bf);
|
await Device.Edit(SelectedDateMessage.Value, s, bf);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var m = await this.Device.Send(s, bf);
|
var m = await Device.Send(s, bf);
|
||||||
this.selectedDateMessage = m.MessageId;
|
SelectedDateMessage = m.MessageId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,41 +1,44 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase.Controls;
|
|
||||||
using TelegramBotBase.Controls.Inline;
|
using TelegramBotBase.Controls.Inline;
|
||||||
|
using TelegramBotBase.Enums;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Controls
|
namespace TelegramBotBase.Example.Tests.Controls;
|
||||||
{
|
|
||||||
public class MultiToggleButtons : AutoCleanForm
|
public class MultiToggleButtons : AutoCleanForm
|
||||||
{
|
{
|
||||||
public MultiToggleButtons()
|
public MultiToggleButtons()
|
||||||
{
|
{
|
||||||
this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
|
DeleteMode = EDeleteMode.OnLeavingForm;
|
||||||
|
|
||||||
this.Init += ToggleButtons_Init;
|
Init += ToggleButtons_Init;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ToggleButtons_Init(object sender, InitEventArgs e)
|
private Task ToggleButtons_Init(object sender, InitEventArgs e)
|
||||||
{
|
{
|
||||||
|
var mtb = new MultiToggleButton
|
||||||
|
{
|
||||||
|
Options = new List<ButtonBase> { new("Option 1", "1"), new("Option 2", "2"), new("Option 3", "3") }
|
||||||
|
};
|
||||||
|
|
||||||
var mtb = new MultiToggleButton();
|
|
||||||
|
|
||||||
mtb.Options = new List<ButtonBase>() { new ButtonBase("Option 1", "1"), new ButtonBase("Option 2", "2"), new ButtonBase("Option 3", "3") };
|
|
||||||
mtb.SelectedOption = mtb.Options.FirstOrDefault();
|
mtb.SelectedOption = mtb.Options.FirstOrDefault();
|
||||||
mtb.Toggled += Tb_Toggled;
|
mtb.Toggled += Tb_Toggled;
|
||||||
this.AddControl(mtb);
|
AddControl(mtb);
|
||||||
|
|
||||||
mtb = new MultiToggleButton();
|
mtb = new MultiToggleButton
|
||||||
|
{
|
||||||
|
Options = new List<ButtonBase> { new("Option 4", "4"), new("Option 5", "5"), new("Option 6", "6") }
|
||||||
|
};
|
||||||
|
|
||||||
mtb.Options = new List<ButtonBase>() { new ButtonBase("Option 4", "4"), new ButtonBase("Option 5", "5"), new ButtonBase("Option 6", "6") };
|
|
||||||
mtb.SelectedOption = mtb.Options.FirstOrDefault();
|
mtb.SelectedOption = mtb.Options.FirstOrDefault();
|
||||||
mtb.AllowEmptySelection = false;
|
mtb.AllowEmptySelection = false;
|
||||||
mtb.Toggled += Tb_Toggled;
|
mtb.Toggled += Tb_Toggled;
|
||||||
this.AddControl(mtb);
|
AddControl(mtb);
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Tb_Toggled(object sender, EventArgs e)
|
private void Tb_Toggled(object sender, EventArgs e)
|
||||||
@ -43,11 +46,10 @@ namespace TelegramBotBaseTest.Tests.Controls
|
|||||||
var tb = sender as MultiToggleButton;
|
var tb = sender as MultiToggleButton;
|
||||||
if (tb.SelectedOption != null)
|
if (tb.SelectedOption != null)
|
||||||
{
|
{
|
||||||
Console.WriteLine(tb.ID.ToString() + " was pressed, and toggled to " + tb.SelectedOption.Value);
|
Console.WriteLine(tb.Id + " was pressed, and toggled to " + tb.SelectedOption.Value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.WriteLine("Selection for " + tb.ID.ToString() + " has been removed.");
|
Console.WriteLine("Selection for " + tb.Id + " has been removed.");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,41 +1,42 @@
|
|||||||
using System;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
using TelegramBotBase.Args;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Base;
|
|
||||||
using TelegramBotBase.Controls.Hybrid;
|
using TelegramBotBase.Controls.Hybrid;
|
||||||
|
using TelegramBotBase.DataSources;
|
||||||
|
using TelegramBotBase.Enums;
|
||||||
|
using TelegramBotBase.Example.Tests.Controls.Subclass;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Controls
|
namespace TelegramBotBase.Example.Tests.Controls;
|
||||||
{
|
|
||||||
public class MultiViewForm : AutoCleanForm
|
public class MultiViewForm : AutoCleanForm
|
||||||
{
|
{
|
||||||
|
private ButtonGrid _bg;
|
||||||
Subclass.MultiViewTest mvt = null;
|
private MultiViewTest _mvt;
|
||||||
|
|
||||||
ButtonGrid bg = null;
|
|
||||||
|
|
||||||
public MultiViewForm()
|
public MultiViewForm()
|
||||||
{
|
{
|
||||||
this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
|
DeleteMode = EDeleteMode.OnLeavingForm;
|
||||||
this.Init += MultiViewForm_Init;
|
Init += MultiViewForm_Init;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task MultiViewForm_Init(object sender, TelegramBotBase.Args.InitEventArgs e)
|
private Task MultiViewForm_Init(object sender, InitEventArgs e)
|
||||||
{
|
{
|
||||||
mvt = new Subclass.MultiViewTest();
|
_mvt = new MultiViewTest();
|
||||||
|
|
||||||
AddControl(mvt);
|
AddControl(_mvt);
|
||||||
|
|
||||||
bg = new ButtonGrid();
|
_bg = new ButtonGrid
|
||||||
bg.ButtonsForm = new ButtonForm();
|
{
|
||||||
bg.ButtonsForm.AddButtonRow("Back", "$back$");
|
DataSource = new ButtonFormDataSource()
|
||||||
bg.ButtonClicked += Bg_ButtonClicked;
|
};
|
||||||
bg.KeyboardType = TelegramBotBase.Enums.eKeyboardType.ReplyKeyboard;
|
_bg.DataSource.ButtonForm.AddButtonRow("Back", "$back$");
|
||||||
AddControl(bg);
|
_bg.ButtonClicked += Bg_ButtonClicked;
|
||||||
|
_bg.KeyboardType = EKeyboardType.ReplyKeyboard;
|
||||||
|
AddControl(_bg);
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Bg_ButtonClicked(object sender, TelegramBotBase.Args.ButtonClickedEventArgs e)
|
private async Task Bg_ButtonClicked(object sender, ButtonClickedEventArgs e)
|
||||||
{
|
{
|
||||||
switch (e.Button.Value)
|
switch (e.Button.Value)
|
||||||
{
|
{
|
||||||
@ -47,7 +48,4 @@ namespace TelegramBotBaseTest.Tests.Controls
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,40 +1,35 @@
|
|||||||
using System;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
|
using TelegramBotBase.Controls.Hybrid;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Controls.Subclass
|
namespace TelegramBotBase.Example.Tests.Controls.Subclass;
|
||||||
{
|
|
||||||
public class MultiViewTest : TelegramBotBase.Controls.Hybrid.MultiView
|
|
||||||
{
|
|
||||||
|
|
||||||
|
public class MultiViewTest : MultiView
|
||||||
public override async Task Action(MessageResult result, string value = null)
|
{
|
||||||
|
public override Task Action(MessageResult result, string value = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
switch (result.RawData)
|
switch (result.RawData)
|
||||||
{
|
{
|
||||||
case "back":
|
case "back":
|
||||||
|
|
||||||
this.SelectedViewIndex--;
|
SelectedViewIndex--;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "next":
|
case "next":
|
||||||
|
|
||||||
this.SelectedViewIndex++;
|
SelectedViewIndex++;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task RenderView(RenderViewEventArgs e)
|
public override async Task RenderView(RenderViewEventArgs e)
|
||||||
{
|
{
|
||||||
|
var bf = new ButtonForm();
|
||||||
ButtonForm bf = new ButtonForm();
|
|
||||||
bf.AddButtonRow(new ButtonBase("Back", "back"), new ButtonBase("Next", "next"));
|
bf.AddButtonRow(new ButtonBase("Back", "back"), new ButtonBase("Next", "next"));
|
||||||
|
|
||||||
switch (e.CurrentView)
|
switch (e.CurrentView)
|
||||||
@ -52,13 +47,6 @@ namespace TelegramBotBaseTest.Tests.Controls.Subclass
|
|||||||
await Device.Send("Unknown Page", bf);
|
await Device.Send("Unknown Page", bf);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,51 +1,52 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase.Controls;
|
|
||||||
using TelegramBotBase.Controls.Inline;
|
using TelegramBotBase.Controls.Inline;
|
||||||
|
using TelegramBotBase.Enums;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Controls
|
namespace TelegramBotBase.Example.Tests.Controls;
|
||||||
{
|
|
||||||
public class ToggleButtons : AutoCleanForm
|
public class ToggleButtons : AutoCleanForm
|
||||||
{
|
{
|
||||||
public ToggleButtons()
|
public ToggleButtons()
|
||||||
{
|
{
|
||||||
this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
|
DeleteMode = EDeleteMode.OnLeavingForm;
|
||||||
|
|
||||||
this.Init += ToggleButtons_Init;
|
Init += ToggleButtons_Init;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ToggleButtons_Init(object sender, InitEventArgs e)
|
private Task ToggleButtons_Init(object sender, InitEventArgs e)
|
||||||
{
|
{
|
||||||
|
var tb = new ToggleButton
|
||||||
var tb = new ToggleButton();
|
{
|
||||||
tb.Checked = true;
|
Checked = true
|
||||||
|
};
|
||||||
tb.Toggled += Tb_Toggled;
|
tb.Toggled += Tb_Toggled;
|
||||||
|
|
||||||
this.AddControl(tb);
|
AddControl(tb);
|
||||||
|
|
||||||
tb = new ToggleButton();
|
tb = new ToggleButton
|
||||||
tb.Checked = false;
|
{
|
||||||
|
Checked = false
|
||||||
|
};
|
||||||
tb.Toggled += Tb_Toggled;
|
tb.Toggled += Tb_Toggled;
|
||||||
|
|
||||||
this.AddControl(tb);
|
AddControl(tb);
|
||||||
|
|
||||||
tb = new ToggleButton();
|
tb = new ToggleButton
|
||||||
tb.Checked = true;
|
{
|
||||||
|
Checked = true
|
||||||
|
};
|
||||||
tb.Toggled += Tb_Toggled;
|
tb.Toggled += Tb_Toggled;
|
||||||
|
|
||||||
this.AddControl(tb);
|
AddControl(tb);
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Tb_Toggled(object sender, EventArgs e)
|
private void Tb_Toggled(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var tb = sender as ToggleButton;
|
var tb = sender as ToggleButton;
|
||||||
Console.WriteLine(tb.ID.ToString() + " was pressed, and toggled to " + (tb.Checked ? "Checked" : "Unchecked"));
|
Console.WriteLine(tb.Id + " was pressed, and toggled to " + (tb.Checked ? "Checked" : "Unchecked"));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,41 +1,40 @@
|
|||||||
using System;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Form;
|
|
||||||
using TelegramBotBase.Controls;
|
|
||||||
using TelegramBotBase.Base;
|
|
||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Controls.Inline;
|
using TelegramBotBase.Controls.Inline;
|
||||||
|
using TelegramBotBase.Enums;
|
||||||
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
|
namespace TelegramBotBase.Example.Tests.Controls;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Controls
|
|
||||||
{
|
|
||||||
public class TreeViewForms : AutoCleanForm
|
public class TreeViewForms : AutoCleanForm
|
||||||
{
|
{
|
||||||
public TreeView view { get; set; }
|
public TreeViewForms()
|
||||||
|
{
|
||||||
|
DeleteMode = EDeleteMode.OnLeavingForm;
|
||||||
|
Init += TreeViewForms_Init;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TreeView View { get; set; }
|
||||||
|
|
||||||
private int? MessageId { get; set; }
|
private int? MessageId { get; set; }
|
||||||
|
|
||||||
public TreeViewForms()
|
private Task TreeViewForms_Init(object sender, InitEventArgs e)
|
||||||
{
|
{
|
||||||
this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
|
View = new TreeView();
|
||||||
this.Init += TreeViewForms_Init;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task TreeViewForms_Init(object sender, InitEventArgs e)
|
|
||||||
{
|
|
||||||
view = new TreeView();
|
|
||||||
|
|
||||||
var tvn = new TreeViewNode("Cars", "cars");
|
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("BMW", "bmw"));
|
||||||
tvn.AddNode(new TreeViewNode("Audi", "audi"));
|
tvn.AddNode(new TreeViewNode("Audi", "audi"));
|
||||||
tvn.AddNode(new TreeViewNode("VW", "vw"));
|
tvn.AddNode(new TreeViewNode("VW", "vw"));
|
||||||
tvn.AddNode(new TreeViewNode("Lamborghini", "lamborghini"));
|
tvn.AddNode(new TreeViewNode("Lamborghini", "lamborghini"));
|
||||||
|
|
||||||
view.Nodes.Add(tvn);
|
View.Nodes.Add(tvn);
|
||||||
|
|
||||||
tvn = new TreeViewNode("Fruits", "fruits");
|
tvn = new TreeViewNode("Fruits", "fruits");
|
||||||
|
|
||||||
@ -43,10 +42,10 @@ namespace TelegramBotBaseTest.Tests.Controls
|
|||||||
tvn.AddNode(new TreeViewNode("Orange", "orange"));
|
tvn.AddNode(new TreeViewNode("Orange", "orange"));
|
||||||
tvn.AddNode(new TreeViewNode("Lemon", "lemon"));
|
tvn.AddNode(new TreeViewNode("Lemon", "lemon"));
|
||||||
|
|
||||||
view.Nodes.Add(tvn);
|
View.Nodes.Add(tvn);
|
||||||
|
|
||||||
this.AddControl(view);
|
|
||||||
|
|
||||||
|
AddControl(View);
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Action(MessageResult message)
|
public override async Task Action(MessageResult message)
|
||||||
@ -54,7 +53,9 @@ namespace TelegramBotBaseTest.Tests.Controls
|
|||||||
await message.ConfirmAction();
|
await message.ConfirmAction();
|
||||||
|
|
||||||
if (message.Handled)
|
if (message.Handled)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (message.RawData)
|
switch (message.RawData)
|
||||||
{
|
{
|
||||||
@ -64,38 +65,34 @@ namespace TelegramBotBaseTest.Tests.Controls
|
|||||||
|
|
||||||
var start = new Menu();
|
var start = new Menu();
|
||||||
|
|
||||||
await this.NavigateTo(start);
|
await NavigateTo(start);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Render(MessageResult message)
|
public override async Task Render(MessageResult message)
|
||||||
{
|
{
|
||||||
String s = "";
|
var s = "";
|
||||||
|
|
||||||
s += "Selected Node: " + (this.view.SelectedNode?.Text ?? "(null)") + "\r\n";
|
s += "Selected Node: " + (View.SelectedNode?.Text ?? "(null)") + "\r\n";
|
||||||
|
|
||||||
s += "Visible Node: " + (this.view.VisibleNode?.Text ?? "(top)") + "\r\n";
|
s += "Visible Node: " + (View.VisibleNode?.Text ?? "(top)") + "\r\n";
|
||||||
|
|
||||||
s += "Visible Path: " + this.view.GetPath() + "\r\n";
|
s += "Visible Path: " + View.GetPath() + "\r\n";
|
||||||
s += "Selected Path: " + (this.view.SelectedNode?.GetPath() ?? "(null)") + "\r\n";
|
s += "Selected Path: " + (View.SelectedNode?.GetPath() ?? "(null)") + "\r\n";
|
||||||
|
|
||||||
ButtonForm bf = new ButtonForm();
|
var bf = new ButtonForm();
|
||||||
bf.AddButtonRow(new ButtonBase("Back", "back"));
|
bf.AddButtonRow(new ButtonBase("Back", "back"));
|
||||||
|
|
||||||
if (MessageId != null)
|
if (MessageId != null)
|
||||||
{
|
{
|
||||||
await this.Device.Edit(this.MessageId.Value, s, bf);
|
await Device.Edit(MessageId.Value, s, bf);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var m = await this.Device.Send(s, bf);
|
var m = await Device.Send(s, bf);
|
||||||
this.MessageId = m.MessageId;
|
MessageId = m.MessageId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,89 +1,83 @@
|
|||||||
using System;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types.Enums;
|
||||||
using Telegram.Bot.Types.InputFiles;
|
using Telegram.Bot.Types.InputFiles;
|
||||||
using Telegram.Bot.Types.ReplyMarkups;
|
using Telegram.Bot.Types.ReplyMarkups;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests
|
namespace TelegramBotBase.Example.Tests;
|
||||||
{
|
|
||||||
public class DataForm : AutoCleanForm
|
public class DataForm : AutoCleanForm
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public override async Task SentData(DataResult data)
|
public override async Task SentData(DataResult data)
|
||||||
{
|
{
|
||||||
String tmp = "";
|
var tmp = "";
|
||||||
InputOnlineFile file;
|
InputOnlineFile file;
|
||||||
|
|
||||||
switch (data.Type)
|
switch (data.Type)
|
||||||
{
|
{
|
||||||
case Telegram.Bot.Types.Enums.MessageType.Contact:
|
case MessageType.Contact:
|
||||||
|
|
||||||
tmp += "Firstname: " + data.Contact.FirstName + "\r\n";
|
tmp += "Firstname: " + data.Contact.FirstName + "\r\n";
|
||||||
tmp += "Lastname: " + data.Contact.LastName + "\r\n";
|
tmp += "Lastname: " + data.Contact.LastName + "\r\n";
|
||||||
tmp += "Phonenumber: " + data.Contact.PhoneNumber + "\r\n";
|
tmp += "Phonenumber: " + data.Contact.PhoneNumber + "\r\n";
|
||||||
tmp += "UserId: " + data.Contact.UserId + "\r\n";
|
tmp += "UserId: " + data.Contact.UserId + "\r\n";
|
||||||
|
|
||||||
await this.Device.Send("Your contact: \r\n" + tmp, replyTo: data.MessageId);
|
await Device.Send("Your contact: \r\n" + tmp, replyTo: data.MessageId);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Telegram.Bot.Types.Enums.MessageType.Document:
|
case MessageType.Document:
|
||||||
|
|
||||||
file = new InputOnlineFile(data.Document.FileId);
|
file = new InputOnlineFile(data.Document.FileId);
|
||||||
|
|
||||||
await this.Device.SendDocument(file, "Your uploaded document");
|
await Device.SendDocument(file, "Your uploaded document");
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Telegram.Bot.Types.Enums.MessageType.Video:
|
case MessageType.Video:
|
||||||
|
|
||||||
file = new InputOnlineFile(data.Document.FileId);
|
file = new InputOnlineFile(data.Document.FileId);
|
||||||
|
|
||||||
await this.Device.SendDocument(file, "Your uploaded video");
|
await Device.SendDocument(file, "Your uploaded video");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Telegram.Bot.Types.Enums.MessageType.Audio:
|
case MessageType.Audio:
|
||||||
|
|
||||||
file = new InputOnlineFile(data.Document.FileId);
|
file = new InputOnlineFile(data.Document.FileId);
|
||||||
|
|
||||||
await this.Device.SendDocument(file, "Your uploaded audio");
|
await Device.SendDocument(file, "Your uploaded audio");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Telegram.Bot.Types.Enums.MessageType.Location:
|
case MessageType.Location:
|
||||||
|
|
||||||
tmp += "Lat: " + data.Location.Latitude + "\r\n";
|
tmp += "Lat: " + data.Location.Latitude + "\r\n";
|
||||||
tmp += "Lng: " + data.Location.Longitude + "\r\n";
|
tmp += "Lng: " + data.Location.Longitude + "\r\n";
|
||||||
|
|
||||||
await this.Device.Send("Your location: \r\n" + tmp, replyTo: data.MessageId);
|
await Device.Send("Your location: \r\n" + tmp, replyTo: data.MessageId);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Telegram.Bot.Types.Enums.MessageType.Photo:
|
case MessageType.Photo:
|
||||||
|
|
||||||
InputOnlineFile photo = new InputOnlineFile(data.Photos.Last().FileId);
|
var photo = new InputOnlineFile(data.Photos.Last().FileId);
|
||||||
|
|
||||||
await this.Device.Send("Your image: ", replyTo: data.MessageId);
|
await Device.Send("Your image: ", replyTo: data.MessageId);
|
||||||
await this.Client.TelegramClient.SendPhotoAsync(this.Device.DeviceId, photo);
|
await Client.TelegramClient.SendPhotoAsync(Device.DeviceId, photo);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
await this.Device.Send("Unknown response");
|
await Device.Send("Unknown response");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Action(MessageResult message)
|
public override async Task Action(MessageResult message)
|
||||||
@ -91,19 +85,21 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
await message.ConfirmAction();
|
await message.ConfirmAction();
|
||||||
|
|
||||||
if (message.Handled)
|
if (message.Handled)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (message.RawData)
|
switch (message.RawData)
|
||||||
{
|
{
|
||||||
case "contact":
|
case "contact":
|
||||||
|
|
||||||
await this.Device.RequestContact();
|
await Device.RequestContact();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "location":
|
case "location":
|
||||||
|
|
||||||
await this.Device.RequestLocation();
|
await Device.RequestLocation();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -113,17 +109,15 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
var start = new Menu();
|
var start = new Menu();
|
||||||
|
|
||||||
await this.NavigateTo(start);
|
await NavigateTo(start);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Render(MessageResult message)
|
public override async Task Render(MessageResult message)
|
||||||
{
|
{
|
||||||
ButtonForm bf = new ButtonForm();
|
var bf = new ButtonForm();
|
||||||
|
|
||||||
bf.AddButtonRow(new ButtonBase("Request User contact", "contact"));
|
bf.AddButtonRow(new ButtonBase("Request User contact", "contact"));
|
||||||
|
|
||||||
@ -133,11 +127,6 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
InlineKeyboardMarkup ikv = bf;
|
InlineKeyboardMarkup ikv = bf;
|
||||||
|
|
||||||
await this.Device.Send("Please upload a contact, photo, video, audio, document or location.", 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 TelegramBotBase.Example.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 TelegramBotBase.Example.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,163 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
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 = Newtonsoft.Json.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 = Newtonsoft.Json.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);
|
|
||||||
|
|
||||||
List<ButtonRow> lst = new List<ButtonRow>();
|
|
||||||
foreach (var c in items)
|
|
||||||
{
|
|
||||||
lst.Add(Render(c));
|
|
||||||
}
|
|
||||||
|
|
||||||
return lst;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override List<ButtonRow> AllItems()
|
|
||||||
{
|
|
||||||
List<ButtonRow> 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)
|
|
||||||
{
|
|
||||||
List<ButtonRow> rows = ItemRange(start, count);
|
|
||||||
|
|
||||||
ButtonForm lst = new ButtonForm();
|
|
||||||
foreach (var c in rows)
|
|
||||||
{
|
|
||||||
lst.AddButtonRow(c);
|
|
||||||
}
|
|
||||||
return lst;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override ButtonForm PickAllItems(string filter = null)
|
|
||||||
{
|
|
||||||
List<ButtonRow> rows = AllItems();
|
|
||||||
|
|
||||||
ButtonForm 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)
|
|
||||||
{
|
|
||||||
var s = data as String;
|
|
||||||
if (s == null)
|
|
||||||
return new ButtonRow(new ButtonBase("Empty", "zero"));
|
|
||||||
|
|
||||||
return new ButtonRow(new ButtonBase(s, s));
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Count
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return Countries.Count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int ColumnCount
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int RowCount
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return this.Count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,54 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Base;
|
|
||||||
using TelegramBotBase.Controls.Hybrid;
|
|
||||||
using TelegramBotBase.Form;
|
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Datasources
|
|
||||||
{
|
|
||||||
public class List : FormBase
|
|
||||||
{
|
|
||||||
ButtonGrid __buttons = null;
|
|
||||||
|
|
||||||
public List()
|
|
||||||
{
|
|
||||||
this.Init += List_Init;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task List_Init(object sender, TelegramBotBase.Args.InitEventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
__buttons = new ButtonGrid();
|
|
||||||
|
|
||||||
__buttons.EnablePaging = true;
|
|
||||||
__buttons.EnableSearch = false;
|
|
||||||
__buttons.ButtonClicked += __buttons_ButtonClicked;
|
|
||||||
__buttons.KeyboardType = TelegramBotBase.Enums.eKeyboardType.ReplyKeyboard;
|
|
||||||
__buttons.DeleteReplyMessage = true;
|
|
||||||
|
|
||||||
__buttons.HeadLayoutButtonRow = new ButtonRow(new ButtonBase("Back", "back"));
|
|
||||||
|
|
||||||
var cds = new CustomDataSource();
|
|
||||||
__buttons.DataSource = cds;
|
|
||||||
|
|
||||||
AddControl(__buttons);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task __buttons_ButtonClicked(object sender, TelegramBotBase.Args.ButtonClickedEventArgs e)
|
|
||||||
{
|
|
||||||
switch(e.Button.Value)
|
|
||||||
{
|
|
||||||
case "back":
|
|
||||||
|
|
||||||
var mn = new Menu();
|
|
||||||
await NavigateTo(mn);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,38 +1,36 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Groups
|
namespace TelegramBotBase.Example.Tests.Groups;
|
||||||
{
|
|
||||||
public class GroupChange : TelegramBotBase.Form.GroupForm
|
public class GroupChange : GroupForm
|
||||||
{
|
{
|
||||||
public GroupChange()
|
public GroupChange()
|
||||||
{
|
{
|
||||||
this.Opened += GroupChange_Opened;
|
Opened += GroupChange_Opened;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private async Task GroupChange_Opened(object sender, EventArgs e)
|
private async Task GroupChange_Opened(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
var bf = new ButtonForm();
|
||||||
ButtonForm bf = new ButtonForm();
|
|
||||||
|
|
||||||
bf.AddButtonRow(new ButtonBase("Open GroupChange Test", "groupchange"));
|
bf.AddButtonRow(new ButtonBase("Open GroupChange Test", "groupchange"));
|
||||||
bf.AddButtonRow(new ButtonBase("Open WelcomeUser Test", "welcomeuser"));
|
bf.AddButtonRow(new ButtonBase("Open WelcomeUser Test", "welcomeuser"));
|
||||||
bf.AddButtonRow(new ButtonBase("Open LinkReplace Test", "linkreplace"));
|
bf.AddButtonRow(new ButtonBase("Open LinkReplace Test", "linkreplace"));
|
||||||
|
|
||||||
await this.Device.Send("GroupChange started, click to switch", bf);
|
await Device.Send("GroupChange started, click to switch", bf);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Action(MessageResult message)
|
public override async Task Action(MessageResult message)
|
||||||
{
|
{
|
||||||
if (message.Handled)
|
if (message.Handled)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var bn = message.RawData;
|
var bn = message.RawData;
|
||||||
@ -46,31 +44,29 @@ namespace TelegramBotBaseTest.Tests.Groups
|
|||||||
|
|
||||||
var gc = new GroupChange();
|
var gc = new GroupChange();
|
||||||
|
|
||||||
await this.NavigateTo(gc);
|
await NavigateTo(gc);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "welcomeuser":
|
case "welcomeuser":
|
||||||
|
|
||||||
var wu = new WelcomeUser();
|
var wu = new WelcomeUser();
|
||||||
|
|
||||||
await this.NavigateTo(wu);
|
await NavigateTo(wu);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "linkreplace":
|
case "linkreplace":
|
||||||
|
|
||||||
var lr = new LinkReplaceTest();
|
var lr = new LinkReplaceTest();
|
||||||
|
|
||||||
await this.NavigateTo(lr);
|
await NavigateTo(lr);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task OnGroupChanged(GroupChangedEventArgs e)
|
public override async Task OnGroupChanged(GroupChangedEventArgs e)
|
||||||
{
|
{
|
||||||
await this.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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,44 +1,43 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
using Telegram.Bot.Types.Enums;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Groups
|
namespace TelegramBotBase.Example.Tests.Groups;
|
||||||
{
|
|
||||||
public class LinkReplaceTest : TelegramBotBase.Form.GroupForm
|
|
||||||
{
|
|
||||||
|
|
||||||
Dictionary<long, int> Counter { get; set; } = new Dictionary<long, int>();
|
|
||||||
|
|
||||||
|
public class LinkReplaceTest : GroupForm
|
||||||
|
{
|
||||||
private const int Maximum = 3;
|
private const int Maximum = 3;
|
||||||
|
|
||||||
|
|
||||||
public LinkReplaceTest()
|
public LinkReplaceTest()
|
||||||
{
|
{
|
||||||
this.Opened += LinkReplaceTest_Opened;
|
Opened += LinkReplaceTest_Opened;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Dictionary<long, int> Counter { get; } = new();
|
||||||
|
|
||||||
private async Task LinkReplaceTest_Opened(object sender, EventArgs e)
|
private async Task LinkReplaceTest_Opened(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
var bf = new ButtonForm();
|
||||||
ButtonForm bf = new ButtonForm();
|
|
||||||
|
|
||||||
bf.AddButtonRow(new ButtonBase("Open GroupChange Test", "groupchange"));
|
bf.AddButtonRow(new ButtonBase("Open GroupChange Test", "groupchange"));
|
||||||
bf.AddButtonRow(new ButtonBase("Open WelcomeUser Test", "welcomeuser"));
|
bf.AddButtonRow(new ButtonBase("Open WelcomeUser Test", "welcomeuser"));
|
||||||
bf.AddButtonRow(new ButtonBase("Open LinkReplace Test", "linkreplace"));
|
bf.AddButtonRow(new ButtonBase("Open LinkReplace Test", "linkreplace"));
|
||||||
|
|
||||||
await this.Device.Send("LinkReplaceTest started, click to switch", bf);
|
await Device.Send("LinkReplaceTest started, click to switch", bf);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Action(MessageResult message)
|
public override async Task Action(MessageResult message)
|
||||||
{
|
{
|
||||||
if (message.Handled)
|
if (message.Handled)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var bn = message.RawData;
|
var bn = message.RawData;
|
||||||
|
|
||||||
@ -51,25 +50,24 @@ namespace TelegramBotBaseTest.Tests.Groups
|
|||||||
|
|
||||||
var gc = new GroupChange();
|
var gc = new GroupChange();
|
||||||
|
|
||||||
await this.NavigateTo(gc);
|
await NavigateTo(gc);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "welcomeuser":
|
case "welcomeuser":
|
||||||
|
|
||||||
var wu = new WelcomeUser();
|
var wu = new WelcomeUser();
|
||||||
|
|
||||||
await this.NavigateTo(wu);
|
await NavigateTo(wu);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "linkreplace":
|
case "linkreplace":
|
||||||
|
|
||||||
var lr = new LinkReplaceTest();
|
var lr = new LinkReplaceTest();
|
||||||
|
|
||||||
await this.NavigateTo(lr);
|
await NavigateTo(lr);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task OnMessage(MessageResult e)
|
public override async Task OnMessage(MessageResult e)
|
||||||
@ -77,32 +75,38 @@ namespace TelegramBotBaseTest.Tests.Groups
|
|||||||
var from = e.Message.From.Id;
|
var from = e.Message.From.Id;
|
||||||
|
|
||||||
if (e.Message.From.IsBot)
|
if (e.Message.From.IsBot)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//Are urls inside his message ?
|
//Are urls inside his message ?
|
||||||
if (!HasLinks(e.MessageText))
|
if (!HasLinks(e.MessageText))
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var u = await Device.GetChatUser(from);
|
var u = await Device.GetChatUser(from);
|
||||||
|
|
||||||
//Don't kick Admins or Creators
|
//Don't kick Admins or Creators
|
||||||
if (u.Status == Telegram.Bot.Types.Enums.ChatMemberStatus.Administrator | u.Status == Telegram.Bot.Types.Enums.ChatMemberStatus.Creator)
|
if ((u.Status == ChatMemberStatus.Administrator) | (u.Status == ChatMemberStatus.Creator))
|
||||||
{
|
{
|
||||||
await this.Device.Send("You won't get kicked,...not this time.");
|
await Device.Send("You won't get kicked,...not this time.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await e.Device.DeleteMessage(e.MessageId);
|
await e.Device.DeleteMessage(e.MessageId);
|
||||||
|
|
||||||
var cp = new ChatPermissions();
|
var cp = new ChatPermissions
|
||||||
cp.CanAddWebPagePreviews = false;
|
{
|
||||||
cp.CanChangeInfo = false;
|
CanAddWebPagePreviews = false,
|
||||||
cp.CanInviteUsers = false;
|
CanChangeInfo = false,
|
||||||
cp.CanPinMessages = false;
|
CanInviteUsers = false,
|
||||||
cp.CanSendMediaMessages = false;
|
CanPinMessages = false,
|
||||||
cp.CanSendMessages = false;
|
CanSendMediaMessages = false,
|
||||||
cp.CanSendOtherMessages = false;
|
CanSendMessages = false,
|
||||||
cp.CanSendPolls = false;
|
CanSendOtherMessages = false,
|
||||||
|
CanSendPolls = false
|
||||||
|
};
|
||||||
|
|
||||||
//Collect user "mistakes" with sending url, after 3 he gets kicked out.
|
//Collect user "mistakes" with sending url, after 3 he gets kicked out.
|
||||||
if (Counter.ContainsKey(from))
|
if (Counter.ContainsKey(from))
|
||||||
@ -117,19 +121,18 @@ namespace TelegramBotBaseTest.Tests.Groups
|
|||||||
|
|
||||||
if (Counter[from] >= 3)
|
if (Counter[from] >= 3)
|
||||||
{
|
{
|
||||||
await e.Device.KickUser(from);
|
await e.Device.BanUser(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
|
else
|
||||||
{
|
{
|
||||||
await e.Device.RestrictUser(from, cp, DateTime.UtcNow.AddSeconds(30));
|
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>
|
/// <summary>
|
||||||
@ -147,18 +150,16 @@ namespace TelegramBotBaseTest.Tests.Groups
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="str"></param>
|
/// <param name="str"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private bool HasLinks(String str)
|
private bool HasLinks(string str)
|
||||||
{
|
{
|
||||||
var tmp = str;
|
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 =
|
||||||
Regex r = new Regex(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);
|
var matches = r.Matches(tmp);
|
||||||
|
|
||||||
return (matches.Count > 0);
|
return matches.Count > 0;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,40 +1,38 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Telegram.Bot.Types.Enums;
|
||||||
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
using TelegramBotBase.Args;
|
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Groups
|
namespace TelegramBotBase.Example.Tests.Groups;
|
||||||
{
|
|
||||||
public class WelcomeUser : TelegramBotBase.Form.GroupForm
|
|
||||||
{
|
|
||||||
|
|
||||||
|
public class WelcomeUser : GroupForm
|
||||||
|
{
|
||||||
public WelcomeUser()
|
public WelcomeUser()
|
||||||
{
|
{
|
||||||
this.Opened += WelcomeUser_Opened;
|
Opened += WelcomeUser_Opened;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private async Task WelcomeUser_Opened(object sender, EventArgs e)
|
private async Task WelcomeUser_Opened(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
var bf = new ButtonForm();
|
||||||
ButtonForm bf = new ButtonForm();
|
|
||||||
|
|
||||||
bf.AddButtonRow(new ButtonBase("Open GroupChange Test", "groupchange"));
|
bf.AddButtonRow(new ButtonBase("Open GroupChange Test", "groupchange"));
|
||||||
bf.AddButtonRow(new ButtonBase("Open WelcomeUser Test", "welcomeuser"));
|
bf.AddButtonRow(new ButtonBase("Open WelcomeUser Test", "welcomeuser"));
|
||||||
bf.AddButtonRow(new ButtonBase("Open LinkReplace Test", "linkreplace"));
|
bf.AddButtonRow(new ButtonBase("Open LinkReplace Test", "linkreplace"));
|
||||||
|
|
||||||
await this.Device.Send("WelcomeUser started, click to switch", bf);
|
await Device.Send("WelcomeUser started, click to switch", bf);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Action(MessageResult message)
|
public override async Task Action(MessageResult message)
|
||||||
{
|
{
|
||||||
if (message.Handled)
|
if (message.Handled)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var bn = message.RawData;
|
var bn = message.RawData;
|
||||||
|
|
||||||
@ -47,46 +45,38 @@ namespace TelegramBotBaseTest.Tests.Groups
|
|||||||
|
|
||||||
var gc = new GroupChange();
|
var gc = new GroupChange();
|
||||||
|
|
||||||
await this.NavigateTo(gc);
|
await NavigateTo(gc);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "welcomeuser":
|
case "welcomeuser":
|
||||||
|
|
||||||
var wu = new WelcomeUser();
|
var wu = new WelcomeUser();
|
||||||
|
|
||||||
await this.NavigateTo(wu);
|
await NavigateTo(wu);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "linkreplace":
|
case "linkreplace":
|
||||||
|
|
||||||
var lr = new LinkReplaceTest();
|
var lr = new LinkReplaceTest();
|
||||||
|
|
||||||
await this.NavigateTo(lr);
|
await NavigateTo(lr);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task OnMemberChanges(MemberChangeEventArgs e)
|
public override async Task OnMemberChanges(MemberChangeEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (e.Type == MessageType.ChatMembersAdded)
|
||||||
if (e.Type == Telegram.Bot.Types.Enums.MessageType.ChatMembersAdded)
|
|
||||||
{
|
{
|
||||||
|
await Device.Send("Welcome you new members!\r\n\r\n" + e.Members.Select(a => a.FirstName + " " + a.LastName)
|
||||||
await this.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));
|
.Aggregate((a, b) => a + "\r\n" + b));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (e.Type == Telegram.Bot.Types.Enums.MessageType.ChatMemberLeft)
|
else if (e.Type == MessageType.ChatMemberLeft)
|
||||||
{
|
{
|
||||||
await this.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");
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,30 +1,28 @@
|
|||||||
using System;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
using Telegram.Bot.Types.Enums;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
|
using TelegramBotBase.Enums;
|
||||||
|
using TelegramBotBase.Example.Tests.Controls;
|
||||||
|
using TelegramBotBase.Example.Tests.DataSources;
|
||||||
|
using TelegramBotBase.Example.Tests.Groups;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
using TelegramBotBaseTest.Tests.Controls;
|
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests
|
namespace TelegramBotBase.Example.Tests;
|
||||||
{
|
|
||||||
public class Menu : AutoCleanForm
|
public class Menu : AutoCleanForm
|
||||||
{
|
{
|
||||||
public Menu()
|
public Menu()
|
||||||
{
|
{
|
||||||
this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
|
DeleteMode = EDeleteMode.OnLeavingForm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Load(MessageResult message)
|
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 == Telegram.Bot.Types.Enums.ChatType.Group | message.Message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Supergroup)
|
|
||||||
{
|
{
|
||||||
var sf = new TelegramBotBaseTest.Tests.Groups.WelcomeUser();
|
var sf = new WelcomeUser();
|
||||||
|
|
||||||
await this.NavigateTo(sf);
|
await NavigateTo(sf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -39,7 +37,9 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
|
|
||||||
if (call == null)
|
if (call == null)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
message.Handled = true;
|
message.Handled = true;
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
var sf = new SimpleForm();
|
var sf = new SimpleForm();
|
||||||
|
|
||||||
await this.NavigateTo(sf);
|
await NavigateTo(sf);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
var bf = new ButtonTestForm();
|
var bf = new ButtonTestForm();
|
||||||
|
|
||||||
await this.NavigateTo(bf);
|
await NavigateTo(bf);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
var pf = new ProgressTest();
|
var pf = new ProgressTest();
|
||||||
|
|
||||||
await this.NavigateTo(pf);
|
await NavigateTo(pf);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
var reg = new Register.Start();
|
var reg = new Register.Start();
|
||||||
|
|
||||||
await this.NavigateTo(reg);
|
await NavigateTo(reg);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
var form1 = new TestForm();
|
var form1 = new TestForm();
|
||||||
|
|
||||||
await this.NavigateTo(form1);
|
await NavigateTo(form1);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
var form2 = new TestForm2();
|
var form2 = new TestForm2();
|
||||||
|
|
||||||
await this.NavigateTo(form2);
|
await NavigateTo(form2);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -97,71 +97,71 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
var data = new DataForm();
|
var data = new DataForm();
|
||||||
|
|
||||||
await this.NavigateTo(data);
|
await NavigateTo(data);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "calendar":
|
case "calendar":
|
||||||
|
|
||||||
var calendar = new Controls.CalendarPickerForm();
|
var calendar = new CalendarPickerForm();
|
||||||
|
|
||||||
await this.NavigateTo(calendar);
|
await NavigateTo(calendar);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "month":
|
case "month":
|
||||||
|
|
||||||
var month = new Controls.MonthPickerForm();
|
var month = new MonthPickerForm();
|
||||||
|
|
||||||
await this.NavigateTo(month);
|
await NavigateTo(month);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "treeview":
|
case "treeview":
|
||||||
|
|
||||||
var tree = new Controls.TreeViewForms();
|
var tree = new TreeViewForms();
|
||||||
|
|
||||||
await this.NavigateTo(tree);
|
await NavigateTo(tree);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "togglebuttons":
|
case "togglebuttons":
|
||||||
|
|
||||||
var tb = new Controls.ToggleButtons();
|
var tb = new ToggleButtons();
|
||||||
|
|
||||||
await this.NavigateTo(tb);
|
await NavigateTo(tb);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "multitogglebuttons":
|
case "multitogglebuttons":
|
||||||
|
|
||||||
var mtb = new Controls.MultiToggleButtons();
|
var mtb = new MultiToggleButtons();
|
||||||
|
|
||||||
await this.NavigateTo(mtb);
|
await NavigateTo(mtb);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "buttongrid":
|
case "buttongrid":
|
||||||
|
|
||||||
var bg = new Controls.ButtonGridForm();
|
var bg = new ButtonGridForm();
|
||||||
|
|
||||||
await this.NavigateTo(bg);
|
await NavigateTo(bg);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "buttongridfilter":
|
case "buttongridfilter":
|
||||||
|
|
||||||
var bg2 = new Controls.ButtonGridPagingForm();
|
var bg2 = new ButtonGridPagingForm();
|
||||||
|
|
||||||
await this.NavigateTo(bg2);
|
await NavigateTo(bg2);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "buttongridtags":
|
case "buttongridtags":
|
||||||
|
|
||||||
var bg3 = new Controls.ButtonGridTagForm();
|
var bg3 = new ButtonGridTagForm();
|
||||||
|
|
||||||
await this.NavigateTo(bg3);
|
await NavigateTo(bg3);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
case "dynamicbuttongrid":
|
case "dynamicbuttongrid":
|
||||||
|
|
||||||
var dg = new Datasources.List();
|
var dg = new List();
|
||||||
|
|
||||||
await NavigateTo(dg);
|
await NavigateTo(dg);
|
||||||
|
|
||||||
@ -213,16 +213,14 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Render(MessageResult message)
|
public override async Task Render(MessageResult message)
|
||||||
{
|
{
|
||||||
|
var btn = new ButtonForm();
|
||||||
|
|
||||||
ButtonForm 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("#3 Progress Bar", new CallbackData("a", "progress").Serialize()));
|
||||||
btn.AddButtonRow(new ButtonBase("#4 Registration Example", new CallbackData("a", "registration").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 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("#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("#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()));
|
btn.AddButtonRow(new ButtonBase("#19 Notifications", new CallbackData("a", "notifications").Serialize()));
|
||||||
|
|
||||||
await this.Device.Send("Choose your test:", btn);
|
await Device.Send("Choose your test:", btn);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,23 +1,20 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
using TelegramBotBase.Form.Navigation;
|
using TelegramBotBase.Form.Navigation;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Navigation
|
namespace TelegramBotBase.Example.Tests.Navigation;
|
||||||
{
|
|
||||||
class CustomController : NavigationController
|
internal class CustomController : NavigationController
|
||||||
{
|
{
|
||||||
public CustomController(FormBase form) : base(form)
|
public CustomController(FormBase form) : base(form)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override Task PushAsync(FormBase form, params object[] args)
|
public override Task PushAsync(FormBase form, params object[] args)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Pushes form (Count on stack {this.Index + 1})");
|
Console.WriteLine($"Pushes form (Count on stack {Index + 1})");
|
||||||
//Device.Send($"Pushes form (Count on stack {this.Index + 1})");
|
//Device.Send($"Pushes form (Count on stack {this.Index + 1})");
|
||||||
|
|
||||||
return base.PushAsync(form, args);
|
return base.PushAsync(form, args);
|
||||||
@ -26,7 +23,7 @@ namespace TelegramBotBaseTest.Tests.Navigation
|
|||||||
|
|
||||||
public override Task PopAsync()
|
public override Task PopAsync()
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Pops one form (Count on stack {this.Index + 1})");
|
Console.WriteLine($"Pops one form (Count on stack {Index + 1})");
|
||||||
//Device.Send($"Pops one form (Count on stack {this.Index + 1})");
|
//Device.Send($"Pops one form (Count on stack {this.Index + 1})");
|
||||||
|
|
||||||
return base.PopAsync();
|
return base.PopAsync();
|
||||||
@ -34,11 +31,9 @@ namespace TelegramBotBaseTest.Tests.Navigation
|
|||||||
|
|
||||||
public override Task PopToRootAsync()
|
public override Task PopToRootAsync()
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Moved back to root (Count on stack {this.Index + 1})");
|
Console.WriteLine($"Moved back to root (Count on stack {Index + 1})");
|
||||||
//Device.Send($"Moved back to root (Count on stack {this.Index + 1})");
|
//Device.Send($"Moved back to root (Count on stack {this.Index + 1})");
|
||||||
|
|
||||||
return base.PopToRootAsync();
|
return base.PopToRootAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,34 +1,36 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Navigation
|
namespace TelegramBotBase.Example.Tests.Navigation;
|
||||||
{
|
|
||||||
public class Form1 : FormBase
|
public class Form1 : FormBase
|
||||||
{
|
{
|
||||||
Message msg = null;
|
private Message _msg;
|
||||||
|
|
||||||
public Form1()
|
public Form1()
|
||||||
{
|
{
|
||||||
this.Closed += Form1_Closed;
|
Closed += Form1_Closed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Form1_Closed(object sender, EventArgs e)
|
private async Task Form1_Closed(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (msg == null)
|
if (_msg == null)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await Device.DeleteMessage(msg);
|
await Device.DeleteMessage(_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Action(MessageResult message)
|
public override async Task Action(MessageResult message)
|
||||||
{
|
{
|
||||||
if (message.Handled)
|
if (message.Handled)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await message.ConfirmAction();
|
await message.ConfirmAction();
|
||||||
|
|
||||||
@ -61,28 +63,21 @@ namespace TelegramBotBaseTest.Tests.Navigation
|
|||||||
await NavigationController.PopToRootAsync();
|
await NavigationController.PopToRootAsync();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Render(MessageResult message)
|
public override async Task Render(MessageResult message)
|
||||||
{
|
{
|
||||||
if (msg != null)
|
if (_msg != null)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var bf = new ButtonForm();
|
var bf = new ButtonForm();
|
||||||
bf.AddButtonRow("Next page", "next");
|
bf.AddButtonRow("Next page", "next");
|
||||||
bf.AddButtonRow("Previous page", "previous");
|
bf.AddButtonRow("Previous page", "previous");
|
||||||
bf.AddButtonRow("Back to root", "root");
|
bf.AddButtonRow("Back to root", "root");
|
||||||
|
|
||||||
msg = await Device.Send($"Choose your options (Count on stack {NavigationController.Index + 1})", bf);
|
_msg = await Device.Send($"Choose your options (Count on stack {NavigationController.Index + 1})", bf);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,36 +1,26 @@
|
|||||||
using System;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
using TelegramBotBase.Form.Navigation;
|
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Navigation
|
namespace TelegramBotBase.Example.Tests.Navigation;
|
||||||
{
|
|
||||||
public class Start : FormBase
|
public class Start : FormBase
|
||||||
{
|
{
|
||||||
|
private Message _msg;
|
||||||
|
|
||||||
Message msg = null;
|
|
||||||
|
|
||||||
public Start()
|
public override Task Load(MessageResult message)
|
||||||
{
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public override async Task Load(MessageResult message)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Action(MessageResult message)
|
public override async Task Action(MessageResult message)
|
||||||
{
|
{
|
||||||
if (message.Handled)
|
if (message.Handled)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await message.ConfirmAction();
|
await message.ConfirmAction();
|
||||||
|
|
||||||
@ -50,10 +40,12 @@ namespace TelegramBotBaseTest.Tests.Navigation
|
|||||||
|
|
||||||
await NavigateTo(nc);
|
await NavigateTo(nc);
|
||||||
|
|
||||||
if (msg == null)
|
if (_msg == null)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await Device.DeleteMessage(msg);
|
await Device.DeleteMessage(_msg);
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -65,14 +57,15 @@ namespace TelegramBotBaseTest.Tests.Navigation
|
|||||||
|
|
||||||
await NavigateTo(mn);
|
await NavigateTo(mn);
|
||||||
|
|
||||||
if (msg == null)
|
if (_msg == null)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await Device.DeleteMessage(msg);
|
await Device.DeleteMessage(_msg);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Render(MessageResult message)
|
public override async Task Render(MessageResult message)
|
||||||
@ -82,10 +75,6 @@ namespace TelegramBotBaseTest.Tests.Navigation
|
|||||||
bf.AddButtonRow("Yes", "yes");
|
bf.AddButtonRow("Yes", "yes");
|
||||||
bf.AddButtonRow("No", "no");
|
bf.AddButtonRow("No", "no");
|
||||||
|
|
||||||
msg = await Device.Send("Open controller?", bf);
|
_msg = await Device.Send("Open controller?", bf);
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,25 +1,25 @@
|
|||||||
using System;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
|
using TelegramBotBase.Enums;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Notifications
|
namespace TelegramBotBase.Example.Tests.Notifications;
|
||||||
{
|
|
||||||
public class Start : AutoCleanForm
|
public class Start : AutoCleanForm
|
||||||
{
|
{
|
||||||
bool sent = false;
|
private bool _sent;
|
||||||
|
|
||||||
public Start()
|
public Start()
|
||||||
{
|
{
|
||||||
this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
|
DeleteMode = EDeleteMode.OnLeavingForm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Action(MessageResult message)
|
public override async Task Action(MessageResult message)
|
||||||
{
|
{
|
||||||
if (message.Handled)
|
if (message.Handled)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (message.RawData)
|
switch (message.RawData)
|
||||||
{
|
{
|
||||||
@ -39,15 +39,15 @@ namespace TelegramBotBaseTest.Tests.Notifications
|
|||||||
await message.ConfirmAction("This is feedback");
|
await message.ConfirmAction("This is feedback");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Render(MessageResult message)
|
public override async Task Render(MessageResult message)
|
||||||
{
|
{
|
||||||
if (sent)
|
if (_sent)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var bf = new ButtonForm();
|
var bf = new ButtonForm();
|
||||||
bf.AddButtonRow("Normal feeback", "normal");
|
bf.AddButtonRow("Normal feeback", "normal");
|
||||||
@ -56,8 +56,6 @@ namespace TelegramBotBaseTest.Tests.Notifications
|
|||||||
|
|
||||||
await Device.Send("Choose your test", bf);
|
await Device.Send("Choose your test", bf);
|
||||||
|
|
||||||
sent = true;
|
_sent = true;
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,29 +1,26 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Controls.Inline;
|
using TelegramBotBase.Controls.Inline;
|
||||||
|
using TelegramBotBase.Enums;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests
|
namespace TelegramBotBase.Example.Tests;
|
||||||
{
|
|
||||||
public class ProgressTest : AutoCleanForm
|
public class ProgressTest : AutoCleanForm
|
||||||
{
|
{
|
||||||
|
|
||||||
public ProgressTest()
|
public ProgressTest()
|
||||||
{
|
{
|
||||||
this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
|
DeleteMode = EDeleteMode.OnLeavingForm;
|
||||||
this.Opened += ProgressTest_Opened;
|
Opened += ProgressTest_Opened;
|
||||||
this.Closed += ProgressTest_Closed;
|
Closed += ProgressTest_Closed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private async Task ProgressTest_Opened(object sender, EventArgs e)
|
private async Task ProgressTest_Opened(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await this.Device.Send("Welcome to ProgressTest");
|
await Device.Send("Welcome to ProgressTest");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Action(MessageResult message)
|
public override async Task Action(MessageResult message)
|
||||||
@ -34,44 +31,56 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
|
|
||||||
if (call == null)
|
if (call == null)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ProgressBar Bar = null;
|
ProgressBar bar = null;
|
||||||
|
|
||||||
switch (call.Value)
|
switch (call.Value)
|
||||||
{
|
{
|
||||||
case "standard":
|
case "standard":
|
||||||
|
|
||||||
Bar = new ProgressBar(0, 100, ProgressBar.eProgressStyle.standard);
|
bar = new ProgressBar(0, 100, ProgressBar.EProgressStyle.standard)
|
||||||
Bar.Device = this.Device;
|
{
|
||||||
|
Device = Device
|
||||||
|
};
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "squares":
|
case "squares":
|
||||||
|
|
||||||
Bar = new ProgressBar(0, 100, ProgressBar.eProgressStyle.squares);
|
bar = new ProgressBar(0, 100, ProgressBar.EProgressStyle.squares)
|
||||||
Bar.Device = this.Device;
|
{
|
||||||
|
Device = Device
|
||||||
|
};
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "circles":
|
case "circles":
|
||||||
|
|
||||||
Bar = new ProgressBar(0, 100, ProgressBar.eProgressStyle.circles);
|
bar = new ProgressBar(0, 100, ProgressBar.EProgressStyle.circles)
|
||||||
Bar.Device = this.Device;
|
{
|
||||||
|
Device = Device
|
||||||
|
};
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "lines":
|
case "lines":
|
||||||
|
|
||||||
Bar = new ProgressBar(0, 100, ProgressBar.eProgressStyle.lines);
|
bar = new ProgressBar(0, 100, ProgressBar.EProgressStyle.lines)
|
||||||
Bar.Device = this.Device;
|
{
|
||||||
|
Device = Device
|
||||||
|
};
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "squaredlines":
|
case "squaredlines":
|
||||||
|
|
||||||
Bar = new ProgressBar(0, 100, ProgressBar.eProgressStyle.squaredLines);
|
bar = new ProgressBar(0, 100, ProgressBar.EProgressStyle.squaredLines)
|
||||||
Bar.Device = this.Device;
|
{
|
||||||
|
Device = Device
|
||||||
|
};
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -79,52 +88,49 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
var sf = new Menu();
|
var sf = new Menu();
|
||||||
|
|
||||||
await this.NavigateTo(sf);
|
await NavigateTo(sf);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Render Progress bar and show some "example" progress
|
//Render Progress bar and show some "example" progress
|
||||||
await Bar.Render(message);
|
await bar.Render(message);
|
||||||
|
|
||||||
this.Controls.Add(Bar);
|
Controls.Add(bar);
|
||||||
|
|
||||||
for (int i = 0; i <= 100; i++)
|
for (var i = 0; i <= 100; i++)
|
||||||
{
|
{
|
||||||
Bar.Value++;
|
bar.Value++;
|
||||||
await Bar.Render(message);
|
await bar.Render(message);
|
||||||
|
|
||||||
Thread.Sleep(250);
|
Thread.Sleep(250);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override async Task Render(MessageResult message)
|
public override async Task Render(MessageResult message)
|
||||||
{
|
{
|
||||||
ButtonForm btn = new ButtonForm();
|
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()));
|
btn.AddButtonRow(new ButtonBase("Squared Line", new CallbackData("a", "squaredlines").Serialize()));
|
||||||
|
|
||||||
btn.AddButtonRow(new ButtonBase("Back to start", new CallbackData("a", "start").Serialize()));
|
btn.AddButtonRow(new ButtonBase("Back to start", new CallbackData("a", "start").Serialize()));
|
||||||
|
|
||||||
await this.Device.Send("Choose your progress bar:", btn);
|
await Device.Send("Choose your progress bar:", btn);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ProgressTest_Closed(object sender, EventArgs e)
|
private async Task ProgressTest_Closed(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await this.Device.Send("Ciao from ProgressTest");
|
await Device.Send("Ciao from ProgressTest");
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,54 +1,55 @@
|
|||||||
using System;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Register
|
namespace TelegramBotBase.Example.Tests.Register;
|
||||||
{
|
|
||||||
public class PerForm : AutoCleanForm
|
public class PerForm : AutoCleanForm
|
||||||
{
|
{
|
||||||
public String EMail { get; set; }
|
public string EMail { get; set; }
|
||||||
|
|
||||||
public String Firstname { get; set; }
|
public string Firstname { get; set; }
|
||||||
|
|
||||||
public String Lastname { get; set; }
|
public string Lastname { get; set; }
|
||||||
|
|
||||||
public async override Task Load(MessageResult message)
|
public override Task Load(MessageResult message)
|
||||||
{
|
{
|
||||||
if (message.MessageText.Trim() == "")
|
if (message.MessageText.Trim() == "")
|
||||||
return;
|
|
||||||
|
|
||||||
if (this.Firstname == null)
|
|
||||||
{
|
{
|
||||||
this.Firstname = message.MessageText;
|
return Task.CompletedTask;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.Lastname == null)
|
if (Firstname == null)
|
||||||
{
|
{
|
||||||
this.Lastname = message.MessageText;
|
Firstname = message.MessageText;
|
||||||
return;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.EMail == null)
|
if (Lastname == null)
|
||||||
{
|
{
|
||||||
this.EMail = message.MessageText;
|
Lastname = message.MessageText;
|
||||||
return;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (EMail == null)
|
||||||
|
{
|
||||||
|
EMail = message.MessageText;
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async override Task Action(MessageResult message)
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task Action(MessageResult message)
|
||||||
{
|
{
|
||||||
var call = message.GetData<CallbackData>();
|
var call = message.GetData<CallbackData>();
|
||||||
|
|
||||||
await message.ConfirmAction();
|
await message.ConfirmAction();
|
||||||
|
|
||||||
if (call == null)
|
if (call == null)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (call.Value)
|
switch (call.Value)
|
||||||
{
|
{
|
||||||
@ -56,48 +57,42 @@ namespace TelegramBotBaseTest.Tests.Register
|
|||||||
|
|
||||||
var start = new Start();
|
var start = new Start();
|
||||||
|
|
||||||
await this.NavigateTo(start);
|
await NavigateTo(start);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override async Task Render(MessageResult message)
|
||||||
}
|
|
||||||
|
|
||||||
public async override Task Render(MessageResult message)
|
|
||||||
{
|
{
|
||||||
if (this.Firstname == null)
|
if (Firstname == null)
|
||||||
{
|
{
|
||||||
await this.Device.Send("Please sent your firstname:");
|
await Device.Send("Please sent your firstname:");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.Lastname == null)
|
if (Lastname == null)
|
||||||
{
|
{
|
||||||
await this.Device.Send("Please sent your lastname:");
|
await Device.Send("Please sent your lastname:");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.EMail == null)
|
if (EMail == null)
|
||||||
{
|
{
|
||||||
await this.Device.Send("Please sent your email address:");
|
await Device.Send("Please sent your email address:");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String s = "";
|
var s = "";
|
||||||
|
|
||||||
s += "Firstname: " + this.Firstname + "\r\n";
|
s += "Firstname: " + Firstname + "\r\n";
|
||||||
s += "Lastname: " + this.Lastname + "\r\n";
|
s += "Lastname: " + Lastname + "\r\n";
|
||||||
s += "E-Mail: " + this.EMail + "\r\n";
|
s += "E-Mail: " + EMail + "\r\n";
|
||||||
|
|
||||||
ButtonForm bf = new ButtonForm();
|
var bf = new ButtonForm();
|
||||||
bf.AddButtonRow(new ButtonBase("Back", new CallbackData("a", "back").Serialize()));
|
bf.AddButtonRow(new ButtonBase("Back", new CallbackData("a", "back").Serialize()));
|
||||||
|
|
||||||
await this.Device.Send("Your details:\r\n" + s, bf);
|
await Device.Send("Your details:\r\n" + s, bf);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,17 +1,13 @@
|
|||||||
using System;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
|
using TelegramBotBase.Example.Tests.Register.Steps;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Register
|
namespace TelegramBotBase.Example.Tests.Register;
|
||||||
{
|
|
||||||
public class PerStep : AutoCleanForm
|
public class PerStep : AutoCleanForm
|
||||||
{
|
{
|
||||||
|
public override async Task Action(MessageResult message)
|
||||||
public async override Task Action(MessageResult message)
|
|
||||||
{
|
{
|
||||||
await message.ConfirmAction();
|
await message.ConfirmAction();
|
||||||
|
|
||||||
@ -19,29 +15,27 @@ namespace TelegramBotBaseTest.Tests.Register
|
|||||||
{
|
{
|
||||||
case "start":
|
case "start":
|
||||||
|
|
||||||
var step1 = new Steps.Step1();
|
var step1 = new Step1();
|
||||||
|
|
||||||
await this.NavigateTo(step1);
|
await NavigateTo(step1);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "back":
|
case "back":
|
||||||
|
|
||||||
var start = new Start();
|
var start = new Start();
|
||||||
|
|
||||||
await this.NavigateTo(start);
|
await NavigateTo(start);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async override Task Render(MessageResult message)
|
public override async Task Render(MessageResult message)
|
||||||
{
|
{
|
||||||
ButtonForm bf = new ButtonForm();
|
var bf = new ButtonForm();
|
||||||
bf.AddButtonRow(new ButtonBase("Goto Step 1", "start"));
|
bf.AddButtonRow(new ButtonBase("Goto Step 1", "start"));
|
||||||
bf.AddButtonRow(new ButtonBase("Back", "back"));
|
bf.AddButtonRow(new ButtonBase("Back", "back"));
|
||||||
|
|
||||||
await this.Device.Send("Register Steps", bf);
|
await Device.Send("Register Steps", bf);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,21 +1,12 @@
|
|||||||
using System;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Register
|
namespace TelegramBotBase.Example.Tests.Register;
|
||||||
{
|
|
||||||
public class Start : AutoCleanForm
|
public class Start : AutoCleanForm
|
||||||
{
|
{
|
||||||
public Start()
|
public override async Task Action(MessageResult message)
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public async override Task Action(MessageResult message)
|
|
||||||
{
|
{
|
||||||
var call = message.GetData<CallbackData>();
|
var call = message.GetData<CallbackData>();
|
||||||
|
|
||||||
@ -23,7 +14,9 @@ namespace TelegramBotBaseTest.Tests.Register
|
|||||||
|
|
||||||
|
|
||||||
if (call == null)
|
if (call == null)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (call.Value)
|
switch (call.Value)
|
||||||
{
|
{
|
||||||
@ -31,42 +24,34 @@ namespace TelegramBotBaseTest.Tests.Register
|
|||||||
|
|
||||||
var form = new PerForm();
|
var form = new PerForm();
|
||||||
|
|
||||||
await this.NavigateTo(form);
|
await NavigateTo(form);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "step":
|
case "step":
|
||||||
|
|
||||||
var step = new PerStep();
|
var step = new PerStep();
|
||||||
|
|
||||||
await this.NavigateTo(step);
|
await NavigateTo(step);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "backtodashboard":
|
case "backtodashboard":
|
||||||
|
|
||||||
var start = new Tests.Menu();
|
var start = new Menu();
|
||||||
|
|
||||||
await this.NavigateTo(start);
|
await NavigateTo(start);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async override Task Render(MessageResult message)
|
public override async Task Render(MessageResult message)
|
||||||
{
|
{
|
||||||
|
var btn = new ButtonForm();
|
||||||
ButtonForm btn = new ButtonForm();
|
|
||||||
|
|
||||||
btn.AddButtonRow(new ButtonBase("#4.1 Per Form", new CallbackData("a", "form").Serialize()));
|
btn.AddButtonRow(new ButtonBase("#4.1 Per Form", new CallbackData("a", "form").Serialize()));
|
||||||
btn.AddButtonRow(new ButtonBase("#4.2 Per Step", new CallbackData("a", "step").Serialize()));
|
btn.AddButtonRow(new ButtonBase("#4.2 Per Step", new CallbackData("a", "step").Serialize()));
|
||||||
btn.AddButtonRow(new ButtonBase("Back", new CallbackData("a", "backtodashboard").Serialize()));
|
btn.AddButtonRow(new ButtonBase("Back", new CallbackData("a", "backtodashboard").Serialize()));
|
||||||
|
|
||||||
await this.Device.Send("Choose your test:", btn);
|
await Device.Send("Choose your test:", btn);
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,18 +1,10 @@
|
|||||||
using System;
|
namespace TelegramBotBase.Example.Tests.Register.Steps;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Register.Steps
|
|
||||||
{
|
|
||||||
public class Data
|
public class Data
|
||||||
{
|
{
|
||||||
public String EMail { get; set; }
|
public string EMail { get; set; }
|
||||||
|
|
||||||
public String Firstname { get; set; }
|
public string Firstname { get; set; }
|
||||||
|
|
||||||
public String Lastname { get; set; }
|
|
||||||
|
|
||||||
}
|
public string Lastname { get; set; }
|
||||||
}
|
}
|
||||||
@ -1,49 +1,52 @@
|
|||||||
using System;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Register.Steps
|
namespace TelegramBotBase.Example.Tests.Register.Steps;
|
||||||
{
|
|
||||||
public class Step1 : AutoCleanForm
|
public class Step1 : AutoCleanForm
|
||||||
{
|
{
|
||||||
public Data UserData { get; set; }
|
|
||||||
|
|
||||||
public Step1()
|
public Step1()
|
||||||
{
|
{
|
||||||
this.Init += Step1_Init;
|
Init += Step1_Init;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Step1_Init(object sender, InitEventArgs e)
|
public Data UserData { get; set; }
|
||||||
|
|
||||||
|
private Task Step1_Init(object sender, InitEventArgs e)
|
||||||
{
|
{
|
||||||
this.UserData = new Data();
|
UserData = new Data();
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async override Task Load(MessageResult message)
|
public override Task Load(MessageResult message)
|
||||||
{
|
{
|
||||||
if (message.Handled)
|
if (message.Handled)
|
||||||
return;
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
if (message.MessageText.Trim() == "")
|
if (message.MessageText.Trim() == "")
|
||||||
return;
|
|
||||||
|
|
||||||
if (this.UserData.Firstname == null)
|
|
||||||
{
|
{
|
||||||
this.UserData.Firstname = message.MessageText;
|
return Task.CompletedTask;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async override Task Render(MessageResult message)
|
if (UserData.Firstname == null)
|
||||||
{
|
{
|
||||||
if (this.UserData.Firstname == null)
|
UserData.Firstname = message.MessageText;
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task Render(MessageResult message)
|
||||||
{
|
{
|
||||||
await this.Device.Send("Please sent your firstname:");
|
if (UserData.Firstname == null)
|
||||||
|
{
|
||||||
|
await Device.Send("Please sent your firstname:");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,10 +54,8 @@ namespace TelegramBotBaseTest.Tests.Register.Steps
|
|||||||
|
|
||||||
var step2 = new Step2();
|
var step2 = new Step2();
|
||||||
|
|
||||||
step2.UserData = this.UserData;
|
step2.UserData = UserData;
|
||||||
|
|
||||||
await this.NavigateTo(step2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
await NavigateTo(step2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,39 +1,41 @@
|
|||||||
using System;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Register.Steps
|
namespace TelegramBotBase.Example.Tests.Register.Steps;
|
||||||
{
|
|
||||||
public class Step2 : AutoCleanForm
|
public class Step2 : AutoCleanForm
|
||||||
{
|
{
|
||||||
public Data UserData { get; set; }
|
public Data UserData { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public async override Task Load(MessageResult message)
|
public override Task Load(MessageResult message)
|
||||||
{
|
{
|
||||||
if (message.Handled)
|
if (message.Handled)
|
||||||
return;
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
if (message.MessageText.Trim() == "")
|
if (message.MessageText.Trim() == "")
|
||||||
return;
|
|
||||||
|
|
||||||
if (this.UserData.Lastname == null)
|
|
||||||
{
|
{
|
||||||
this.UserData.Lastname = message.MessageText;
|
return Task.CompletedTask;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (UserData.Lastname == null)
|
||||||
|
{
|
||||||
|
UserData.Lastname = message.MessageText;
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async override Task Render(MessageResult message)
|
public override async Task Render(MessageResult message)
|
||||||
{
|
{
|
||||||
if (this.UserData.Lastname == null)
|
if (UserData.Lastname == null)
|
||||||
{
|
{
|
||||||
await this.Device.Send("Please sent your lastname:");
|
await Device.Send("Please sent your lastname:");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,10 +43,8 @@ namespace TelegramBotBaseTest.Tests.Register.Steps
|
|||||||
|
|
||||||
var step3 = new Step3();
|
var step3 = new Step3();
|
||||||
|
|
||||||
step3.UserData = this.UserData;
|
step3.UserData = UserData;
|
||||||
|
|
||||||
await this.NavigateTo(step3);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
await NavigateTo(step3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,33 +1,35 @@
|
|||||||
using System;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests.Register.Steps
|
namespace TelegramBotBase.Example.Tests.Register.Steps;
|
||||||
{
|
|
||||||
public class Step3 : AutoCleanForm
|
public class Step3 : AutoCleanForm
|
||||||
{
|
{
|
||||||
public Data UserData { get; set; }
|
public Data UserData { get; set; }
|
||||||
|
|
||||||
public async override Task Load(MessageResult message)
|
public override Task Load(MessageResult message)
|
||||||
{
|
{
|
||||||
if (message.Handled)
|
if (message.Handled)
|
||||||
return;
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
if (message.MessageText.Trim() == "")
|
if (message.MessageText.Trim() == "")
|
||||||
return;
|
|
||||||
|
|
||||||
if (this.UserData.EMail == null)
|
|
||||||
{
|
{
|
||||||
this.UserData.EMail = message.MessageText;
|
return Task.CompletedTask;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async override Task Action(MessageResult message)
|
if (UserData.EMail == null)
|
||||||
|
{
|
||||||
|
UserData.EMail = message.MessageText;
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task Action(MessageResult message)
|
||||||
{
|
{
|
||||||
await message.ConfirmAction();
|
await message.ConfirmAction();
|
||||||
|
|
||||||
@ -37,35 +39,31 @@ namespace TelegramBotBaseTest.Tests.Register.Steps
|
|||||||
|
|
||||||
var start = new Start();
|
var start = new Start();
|
||||||
|
|
||||||
await this.NavigateTo(start);
|
await NavigateTo(start);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public override async Task Render(MessageResult message)
|
||||||
|
|
||||||
public async override Task Render(MessageResult message)
|
|
||||||
{
|
{
|
||||||
if (this.UserData.EMail == null)
|
if (UserData.EMail == null)
|
||||||
{
|
{
|
||||||
await this.Device.Send("Please sent your email:");
|
await Device.Send("Please sent your email:");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
message.Handled = true;
|
message.Handled = true;
|
||||||
|
|
||||||
String s = "";
|
var s = "";
|
||||||
|
|
||||||
s += "Firstname: " + this.UserData.Firstname + "\r\n";
|
s += "Firstname: " + UserData.Firstname + "\r\n";
|
||||||
s += "Lastname: " + this.UserData.Lastname + "\r\n";
|
s += "Lastname: " + UserData.Lastname + "\r\n";
|
||||||
s += "E-Mail: " + this.UserData.EMail + "\r\n";
|
s += "E-Mail: " + UserData.EMail + "\r\n";
|
||||||
|
|
||||||
ButtonForm bf = new ButtonForm();
|
var bf = new ButtonForm();
|
||||||
bf.AddButtonRow(new ButtonBase("Back", "back"));
|
bf.AddButtonRow(new ButtonBase("Back", "back"));
|
||||||
|
|
||||||
await this.Device.Send("Your details:\r\n" + s, bf);
|
await Device.Send("Your details:\r\n" + s, bf);
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,27 +1,24 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
|
using TelegramBotBase.Enums;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests
|
namespace TelegramBotBase.Example.Tests;
|
||||||
{
|
|
||||||
public class SimpleForm : AutoCleanForm
|
public class SimpleForm : AutoCleanForm
|
||||||
{
|
{
|
||||||
|
|
||||||
public SimpleForm()
|
public SimpleForm()
|
||||||
{
|
{
|
||||||
this.DeleteSide = TelegramBotBase.Enums.eDeleteSide.Both;
|
DeleteSide = EDeleteSide.Both;
|
||||||
this.DeleteMode = TelegramBotBase.Enums.eDeleteMode.OnLeavingForm;
|
DeleteMode = EDeleteMode.OnLeavingForm;
|
||||||
|
|
||||||
this.Opened += SimpleForm_Opened;
|
Opened += SimpleForm_Opened;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SimpleForm_Opened(object sender, EventArgs e)
|
private async Task SimpleForm_Opened(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await this.Device.Send("Hello world! (send 'back' to get back to Start)\r\nOr\r\nhi, hello, maybe, bye and ciao");
|
await Device.Send("Hello world! (send 'back' to get back to Start)\r\nOr\r\nhi, hello, maybe, bye and ciao");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Load(MessageResult message)
|
public override async Task Load(MessageResult message)
|
||||||
@ -36,13 +33,13 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
case "hi":
|
case "hi":
|
||||||
|
|
||||||
//Send him a simple message
|
//Send him a simple message
|
||||||
await this.Device.Send("Hello you there !");
|
await Device.Send("Hello you there !");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "maybe":
|
case "maybe":
|
||||||
|
|
||||||
//Send him a simple message and reply to the one of himself
|
//Send him a simple message and reply to the one of himself
|
||||||
await this.Device.Send("Maybe what?", replyTo: messageId);
|
await Device.Send("Maybe what?", replyTo: messageId);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -50,19 +47,16 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
case "ciao":
|
case "ciao":
|
||||||
|
|
||||||
//Send him a simple message
|
//Send him a simple message
|
||||||
await this.Device.Send("Ok, take care !");
|
await Device.Send("Ok, take care !");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "back":
|
case "back":
|
||||||
|
|
||||||
var st = new Menu();
|
var st = new Menu();
|
||||||
|
|
||||||
await this.NavigateTo(st);
|
await NavigateTo(st);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,18 +1,16 @@
|
|||||||
using System;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
|
using TelegramBotBase.Example.Tests.Groups;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests
|
namespace TelegramBotBase.Example.Tests;
|
||||||
{
|
|
||||||
public class Start : SplitterForm
|
public class Start : SplitterForm
|
||||||
{
|
{
|
||||||
public override async Task<bool> Open(MessageResult e)
|
public override async Task<bool> Open(MessageResult e)
|
||||||
{
|
{
|
||||||
var st = new Menu();
|
var st = new Menu();
|
||||||
await this.NavigateTo(st);
|
await NavigateTo(st);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -20,8 +18,8 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
public override async Task<bool> OpenGroup(MessageResult e)
|
public override async Task<bool> OpenGroup(MessageResult e)
|
||||||
{
|
{
|
||||||
var st = new Groups.LinkReplaceTest();
|
var st = new LinkReplaceTest();
|
||||||
await this.NavigateTo(st);
|
await NavigateTo(st);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -35,6 +33,4 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
{
|
{
|
||||||
return base.OpenSupergroup(e);
|
return base.OpenSupergroup(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,34 +1,28 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Telegram.Bot.Types;
|
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests
|
namespace TelegramBotBase.Example.Tests;
|
||||||
{
|
|
||||||
public class TestForm : FormBase
|
public class TestForm : FormBase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
String LastMessage { get; set; }
|
|
||||||
|
|
||||||
public TestForm()
|
public TestForm()
|
||||||
{
|
{
|
||||||
this.Opened += TestForm_Opened;
|
Opened += TestForm_Opened;
|
||||||
this.Closed += TestForm_Closed;
|
Closed += TestForm_Closed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string LastMessage { get; set; }
|
||||||
|
|
||||||
private async Task TestForm_Opened(object sender, EventArgs e)
|
private async Task TestForm_Opened(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await this.Device.Send("Welcome to Form 1");
|
await Device.Send("Welcome to Form 1");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task TestForm_Closed(object sender, EventArgs e)
|
private async Task TestForm_Closed(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await this.Device.Send("Ciao from Form 1");
|
await Device.Send("Ciao from Form 1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -45,21 +39,21 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
var tf = new TestForm2();
|
var tf = new TestForm2();
|
||||||
|
|
||||||
await this.NavigateTo(tf);
|
await NavigateTo(tf);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
if (message.UpdateData == null)
|
if (message.UpdateData == null)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.LastMessage = message.Message.Text;
|
LastMessage = message.Message.Text;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -67,12 +61,7 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
{
|
{
|
||||||
if (message.Command == "reply")
|
if (message.Command == "reply")
|
||||||
{
|
{
|
||||||
|
await Device.Send("Last message: " + LastMessage);
|
||||||
await this.Device.Send("Last message: " + this.LastMessage);
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,41 +1,32 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types.Enums;
|
||||||
using Telegram.Bot.Types.ReplyMarkups;
|
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Extensions.Images;
|
using TelegramBotBase.Extensions.Images;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBaseTest.Tests
|
namespace TelegramBotBase.Example.Tests;
|
||||||
{
|
|
||||||
public class TestForm2 : FormBase
|
public class TestForm2 : FormBase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public TestForm2()
|
public TestForm2()
|
||||||
{
|
{
|
||||||
this.Opened += TestForm2_Opened;
|
Opened += TestForm2_Opened;
|
||||||
this.Closed += TestForm2_Closed;
|
Closed += TestForm2_Closed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task TestForm2_Opened(object sender, EventArgs e)
|
private async Task TestForm2_Opened(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await this.Device.Send("Welcome to Form 2");
|
await Device.Send("Welcome to Form 2");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task TestForm2_Closed(object sender, EventArgs e)
|
private async Task TestForm2_Closed(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await this.Device.Send("Ciao from Form 2");
|
await Device.Send("Ciao from Form 2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public override async Task Action(MessageResult message)
|
public override async Task Action(MessageResult message)
|
||||||
{
|
{
|
||||||
var call = message.GetData<CallbackData>();
|
var call = message.GetData<CallbackData>();
|
||||||
@ -48,26 +39,26 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
|
|
||||||
if (call.Value == "testform1")
|
if (call.Value == "testform1")
|
||||||
{
|
{
|
||||||
|
|
||||||
var tf = new TestForm();
|
var tf = new TestForm();
|
||||||
|
|
||||||
await this.NavigateTo(tf);
|
await NavigateTo(tf);
|
||||||
}
|
}
|
||||||
else if (call.Value == "alert")
|
else if (call.Value == "alert")
|
||||||
{
|
{
|
||||||
AlertDialog ad = new AlertDialog("This is a message", "Ok");
|
var ad = new AlertDialog("This is a message", "Ok");
|
||||||
|
|
||||||
ad.ButtonClicked += async (s, en) =>
|
ad.ButtonClicked += async (s, en) =>
|
||||||
{
|
{
|
||||||
var fto = new TestForm2();
|
var fto = new TestForm2();
|
||||||
await this.NavigateTo(fto);
|
await NavigateTo(fto);
|
||||||
};
|
};
|
||||||
|
|
||||||
await this.NavigateTo(ad);
|
await OpenModal(ad);
|
||||||
}
|
}
|
||||||
else if (call.Value == "confirm")
|
else if (call.Value == "confirm")
|
||||||
{
|
{
|
||||||
ConfirmDialog 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) =>
|
pd.ButtonClicked += async (s, en) =>
|
||||||
{
|
{
|
||||||
@ -76,39 +67,32 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
await pd.NavigateTo(tf);
|
await pd.NavigateTo(tf);
|
||||||
};
|
};
|
||||||
|
|
||||||
await this.NavigateTo(pd);
|
await OpenModal(pd);
|
||||||
}
|
}
|
||||||
else if (call.Value == "prompt")
|
else if (call.Value == "prompt")
|
||||||
{
|
{
|
||||||
PromptDialog pd = new PromptDialog("Please tell me your name ?");
|
var pd = new PromptDialog("Please tell me your name ?");
|
||||||
|
|
||||||
pd.Completed += async (s, en) =>
|
pd.Completed += async (s, en) => { await Device.Send("Hello " + pd.Value); };
|
||||||
{
|
|
||||||
await this.Device.Send("Hello " + pd.Value);
|
|
||||||
};
|
|
||||||
|
|
||||||
await this.OpenModal(pd);
|
await OpenModal(pd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task Render(MessageResult message)
|
public override async Task Render(MessageResult message)
|
||||||
{
|
{
|
||||||
|
var bmp = new Bitmap(800, 600);
|
||||||
Bitmap bmp = new Bitmap(800, 600);
|
using (var g = Graphics.FromImage(bmp))
|
||||||
using (Graphics g = Graphics.FromImage(bmp))
|
|
||||||
{
|
{
|
||||||
|
|
||||||
g.FillRectangle(Brushes.White, 0, 0, bmp.Width, bmp.Height);
|
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 this.Device.SetAction(Telegram.Bot.Types.Enums.ChatAction.UploadPhoto);
|
await Device.SetAction(ChatAction.UploadPhoto);
|
||||||
|
|
||||||
ButtonForm btn = new ButtonForm();
|
var btn = new ButtonForm();
|
||||||
|
|
||||||
//btn.AddButtonRow(new ButtonBase("Zum Testformular 1", CallbackData.Create("navigate", "testform1")), new ButtonBase("Zum Testformular 1", CallbackData.Create("navigate", "testform1")));
|
//btn.AddButtonRow(new ButtonBase("Zum Testformular 1", CallbackData.Create("navigate", "testform1")), new ButtonBase("Zum Testformular 1", CallbackData.Create("navigate", "testform1")));
|
||||||
|
|
||||||
@ -119,10 +103,6 @@ namespace TelegramBotBaseTest.Tests
|
|||||||
btn.AddButtonRow(new ButtonBase("Request Prompt", CallbackData.Create("navigate", "prompt")));
|
btn.AddButtonRow(new ButtonBase("Request Prompt", CallbackData.Create("navigate", "prompt")));
|
||||||
|
|
||||||
|
|
||||||
await this.Device.SendPhoto(bmp, "Test", "", btn);
|
await Device.SendPhoto(bmp, "Test", "", btn);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,6 +1 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<packages>
|
|
||||||
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net5" />
|
|
||||||
<package id="System.Net.Requests" version="4.3.0" targetFramework="net5" />
|
|
||||||
<package id="Telegram.Bot" version="14.12.0" targetFramework="net5" />
|
|
||||||
</packages>
|
|
||||||
@ -1,21 +1,32 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using TelegramBotBase.Sessions;
|
using TelegramBotBase.Sessions;
|
||||||
|
|
||||||
namespace TelegramBotBase.Args
|
namespace TelegramBotBase.Args;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Base class for given bot command results
|
/// Base class for given bot command results
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class BotCommandEventArgs : EventArgs
|
public class BotCommandEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
public String Command { get; set; }
|
public BotCommandEventArgs()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> Parameters { get; set; }
|
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; }
|
||||||
|
|
||||||
public long DeviceId { get; set; }
|
public long DeviceId { get; set; }
|
||||||
|
|
||||||
@ -24,22 +35,4 @@ namespace TelegramBotBase.Args
|
|||||||
public bool Handled { get; set; } = false;
|
public bool Handled { get; set; } = false;
|
||||||
|
|
||||||
public Message OriginalMessage { get; set; }
|
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;
|
|
||||||
this.OriginalMessage = Message;
|
|
||||||
this.DeviceId = DeviceId;
|
|
||||||
this.Device = Device;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,18 +1,37 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Controls.Hybrid;
|
using TelegramBotBase.Controls.Hybrid;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
|
||||||
namespace TelegramBotBase.Args
|
namespace TelegramBotBase.Args;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Button get clicked event
|
/// Button get clicked event
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ButtonClickedEventArgs : EventArgs
|
public class ButtonClickedEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
|
public ButtonClickedEventArgs()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public ButtonClickedEventArgs(ButtonBase button)
|
||||||
|
{
|
||||||
|
Button = button;
|
||||||
|
Index = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ButtonClickedEventArgs(ButtonBase button, int index)
|
||||||
|
{
|
||||||
|
Button = button;
|
||||||
|
Index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ButtonClickedEventArgs(ButtonBase button, int index, ButtonRow row)
|
||||||
|
{
|
||||||
|
Button = button;
|
||||||
|
Index = index;
|
||||||
|
Row = row;
|
||||||
|
}
|
||||||
|
|
||||||
public ButtonBase Button { get; set; }
|
public ButtonBase Button { get; set; }
|
||||||
|
|
||||||
public int Index { get; set; }
|
public int Index { get; set; }
|
||||||
@ -20,30 +39,4 @@ namespace TelegramBotBase.Args
|
|||||||
public object Tag { get; set; }
|
public object Tag { get; set; }
|
||||||
|
|
||||||
public ButtonRow Row { get; set; }
|
public ButtonRow Row { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public ButtonClickedEventArgs()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public ButtonClickedEventArgs(ButtonBase button)
|
|
||||||
{
|
|
||||||
this.Button = button;
|
|
||||||
this.Index = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ButtonClickedEventArgs(ButtonBase button, int Index)
|
|
||||||
{
|
|
||||||
this.Button = button;
|
|
||||||
this.Index = Index;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ButtonClickedEventArgs(ButtonBase button, int Index, ButtonRow row)
|
|
||||||
{
|
|
||||||
this.Button = button;
|
|
||||||
this.Index = Index;
|
|
||||||
this.Row = row;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,13 +1,21 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using TelegramBotBase.Controls.Hybrid;
|
using TelegramBotBase.Controls.Hybrid;
|
||||||
using TelegramBotBase.Form;
|
|
||||||
|
|
||||||
namespace TelegramBotBase.Args
|
namespace TelegramBotBase.Args;
|
||||||
{
|
|
||||||
public class CheckedChangedEventArgs : EventArgs
|
public class CheckedChangedEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
|
public CheckedChangedEventArgs()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckedChangedEventArgs(ButtonRow row, int index, bool @checked)
|
||||||
|
{
|
||||||
|
Row = row;
|
||||||
|
Index = index;
|
||||||
|
Checked = @checked;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains the index of the row where the button is inside.
|
/// Contains the index of the row where the button is inside.
|
||||||
/// Contains -1 when it is a layout button or not found.
|
/// Contains -1 when it is a layout button or not found.
|
||||||
@ -25,20 +33,4 @@ namespace TelegramBotBase.Args
|
|||||||
/// Contains the new checked status of the row.
|
/// Contains the new checked status of the row.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Checked { get; set; }
|
public bool Checked { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public CheckedChangedEventArgs()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public CheckedChangedEventArgs(ButtonRow row, int Index, bool Checked)
|
|
||||||
{
|
|
||||||
this.Row = row;
|
|
||||||
this.Index = Index;
|
|
||||||
this.Checked = Checked;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,24 +1,18 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
|
|
||||||
namespace TelegramBotBase.Args
|
namespace TelegramBotBase.Args;
|
||||||
{
|
|
||||||
public class GroupChangedEventArgs : EventArgs
|
public class GroupChangedEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
|
public GroupChangedEventArgs(MessageType type, MessageResult message)
|
||||||
|
{
|
||||||
|
Type = type;
|
||||||
|
OriginalMessage = message;
|
||||||
|
}
|
||||||
|
|
||||||
public MessageType Type { get; set; }
|
public MessageType Type { get; set; }
|
||||||
|
|
||||||
public MessageResult OriginalMessage { get; set; }
|
public MessageResult OriginalMessage { get; set; }
|
||||||
|
|
||||||
public GroupChangedEventArgs(MessageType type, MessageResult message)
|
|
||||||
{
|
|
||||||
this.Type = type;
|
|
||||||
this.OriginalMessage = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,18 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace TelegramBotBase.Args
|
namespace TelegramBotBase.Args;
|
||||||
{
|
|
||||||
public class InitEventArgs : EventArgs
|
public class InitEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
public object[] Args { get; set; }
|
|
||||||
|
|
||||||
public InitEventArgs(params object[] args)
|
public InitEventArgs(params object[] args)
|
||||||
{
|
{
|
||||||
this.Args = args;
|
Args = args;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public object[] Args { get; set; }
|
||||||
}
|
}
|
||||||
@ -1,63 +1,59 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace TelegramBotBase.Args
|
namespace TelegramBotBase.Args;
|
||||||
{
|
|
||||||
public class LoadStateEventArgs
|
public class LoadStateEventArgs
|
||||||
{
|
{
|
||||||
public Dictionary<String,object> Values { get; set; }
|
|
||||||
|
|
||||||
public LoadStateEventArgs()
|
public LoadStateEventArgs()
|
||||||
{
|
{
|
||||||
Values = new Dictionary<string, object>();
|
Values = new Dictionary<string, object>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> Keys
|
public Dictionary<string, object> Values { get; set; }
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return Values.Keys.ToList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String Get(String key)
|
public List<string> Keys => Values.Keys.ToList();
|
||||||
|
|
||||||
|
public string Get(string key)
|
||||||
{
|
{
|
||||||
return Values[key].ToString();
|
return Values[key].ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetInt(String key)
|
public int GetInt(string key)
|
||||||
{
|
{
|
||||||
int i = 0;
|
var i = 0;
|
||||||
if (int.TryParse(Values[key].ToString(), out i))
|
if (int.TryParse(Values[key].ToString(), out i))
|
||||||
|
{
|
||||||
return i;
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double GetDouble(String key)
|
public double GetDouble(string key)
|
||||||
{
|
{
|
||||||
double d = 0;
|
double d = 0;
|
||||||
if (double.TryParse(Values[key].ToString(), out d))
|
if (double.TryParse(Values[key].ToString(), out d))
|
||||||
|
{
|
||||||
return d;
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool GetBool(String key)
|
public bool GetBool(string key)
|
||||||
{
|
{
|
||||||
bool b = false;
|
var b = false;
|
||||||
if (bool.TryParse(Values[key].ToString(), out b))
|
if (bool.TryParse(Values[key].ToString(), out b))
|
||||||
|
{
|
||||||
return b;
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public object GetObject(String key)
|
public object GetObject(string key)
|
||||||
{
|
{
|
||||||
return Values[key];
|
return Values[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,37 +1,29 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
|
|
||||||
namespace TelegramBotBase.Args
|
namespace TelegramBotBase.Args;
|
||||||
{
|
|
||||||
public class MemberChangeEventArgs : EventArgs
|
public class MemberChangeEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
|
public MemberChangeEventArgs()
|
||||||
|
{
|
||||||
|
Members = new List<User>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MemberChangeEventArgs(MessageType type, MessageResult result, params User[] members)
|
||||||
|
{
|
||||||
|
Type = type;
|
||||||
|
Result = result;
|
||||||
|
Members = members.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
public List<User> Members { get; set; }
|
public List<User> Members { get; set; }
|
||||||
|
|
||||||
public MessageType Type { get; set; }
|
public MessageType Type { get; set; }
|
||||||
|
|
||||||
public MessageResult Result { get; set; }
|
public MessageResult Result { get; set; }
|
||||||
|
|
||||||
public MemberChangeEventArgs()
|
|
||||||
{
|
|
||||||
this.Members = new List<User>();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public MemberChangeEventArgs(MessageType type, MessageResult result, params User[] members)
|
|
||||||
{
|
|
||||||
this.Type = type;
|
|
||||||
this.Result = result;
|
|
||||||
this.Members = members.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,23 +1,11 @@
|
|||||||
using System;
|
namespace TelegramBotBase.Args;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Telegram.Bot.Types;
|
|
||||||
|
|
||||||
namespace TelegramBotBase.Args
|
|
||||||
{
|
|
||||||
public class MessageDeletedEventArgs
|
public class MessageDeletedEventArgs
|
||||||
{
|
{
|
||||||
public int MessageId
|
|
||||||
{
|
|
||||||
get;set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageDeletedEventArgs(int messageId)
|
public MessageDeletedEventArgs(int messageId)
|
||||||
{
|
{
|
||||||
this.MessageId = messageId;
|
MessageId = messageId;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public int MessageId { get; set; }
|
||||||
}
|
}
|
||||||
@ -1,30 +1,20 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Sessions;
|
using TelegramBotBase.Sessions;
|
||||||
|
|
||||||
namespace TelegramBotBase.Base
|
namespace TelegramBotBase.Base;
|
||||||
{
|
|
||||||
public class MessageIncomeEventArgs : EventArgs
|
public class MessageIncomeEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
|
public MessageIncomeEventArgs(long deviceId, DeviceSession device, MessageResult message)
|
||||||
|
{
|
||||||
|
DeviceId = deviceId;
|
||||||
|
Device = device;
|
||||||
|
Message = message;
|
||||||
|
}
|
||||||
|
|
||||||
public long DeviceId { get; set; }
|
public long DeviceId { get; set; }
|
||||||
|
|
||||||
public DeviceSession Device { get; set; }
|
public DeviceSession Device { get; set; }
|
||||||
|
|
||||||
public MessageResult Message { get; set; }
|
public MessageResult Message { get; set; }
|
||||||
|
|
||||||
public MessageIncomeEventArgs(long DeviceId, DeviceSession Device, MessageResult message)
|
|
||||||
{
|
|
||||||
this.DeviceId = DeviceId;
|
|
||||||
this.Device = Device;
|
|
||||||
this.Message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,28 +1,15 @@
|
|||||||
using System;
|
using Telegram.Bot.Types;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
namespace TelegramBotBase.Args;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Telegram.Bot.Types;
|
|
||||||
|
|
||||||
namespace TelegramBotBase.Args
|
|
||||||
{
|
|
||||||
public class MessageReceivedEventArgs
|
public class MessageReceivedEventArgs
|
||||||
{
|
{
|
||||||
public int MessageId
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return this.Message.MessageId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Message Message { get; set; }
|
|
||||||
|
|
||||||
public MessageReceivedEventArgs(Message m)
|
public MessageReceivedEventArgs(Message m)
|
||||||
{
|
{
|
||||||
this.Message = m;
|
Message = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public int MessageId => Message.MessageId;
|
||||||
|
|
||||||
|
public Message Message { get; set; }
|
||||||
}
|
}
|
||||||
@ -1,36 +1,22 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
|
||||||
namespace TelegramBotBase.Args
|
namespace TelegramBotBase.Args;
|
||||||
{
|
|
||||||
public class MessageSentEventArgs : EventArgs
|
public class MessageSentEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
public int MessageId
|
public MessageSentEventArgs(Message message, Type origin)
|
||||||
{
|
{
|
||||||
get
|
Message = message;
|
||||||
{
|
Origin = origin;
|
||||||
return this.Message.MessageId;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int MessageId => Message.MessageId;
|
||||||
|
|
||||||
public Message Message { get; set; }
|
public Message Message { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains the element, which has called the method.
|
/// Contains the element, which has called the method.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Type Origin { get; set; }
|
public Type Origin { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public MessageSentEventArgs(Message message, Type Origin)
|
|
||||||
{
|
|
||||||
this.Message = message;
|
|
||||||
this.Origin = Origin;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,14 +1,8 @@
|
|||||||
using System;
|
namespace TelegramBotBase.Args;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace TelegramBotBase.Args
|
|
||||||
{
|
|
||||||
public class PromptDialogCompletedEventArgs
|
public class PromptDialogCompletedEventArgs
|
||||||
{
|
{
|
||||||
public object Tag { get; set; }
|
public object Tag { get; set; }
|
||||||
|
|
||||||
public String Value { get; set; }
|
public string Value { get; set; }
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,20 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace TelegramBotBase.Args
|
namespace TelegramBotBase.Args;
|
||||||
{
|
|
||||||
public class RenderViewEventArgs : EventArgs
|
public class RenderViewEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
public int CurrentView { get; set; }
|
public RenderViewEventArgs(int viewIndex)
|
||||||
|
|
||||||
|
|
||||||
public RenderViewEventArgs(int ViewIndex)
|
|
||||||
{
|
{
|
||||||
|
CurrentView = viewIndex;
|
||||||
CurrentView = ViewIndex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int CurrentView { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,41 +1,38 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
namespace TelegramBotBase.Args;
|
||||||
|
|
||||||
namespace TelegramBotBase.Args
|
|
||||||
{
|
|
||||||
public class SaveStateEventArgs
|
public class SaveStateEventArgs
|
||||||
{
|
{
|
||||||
public Dictionary<String, object> Values { get; set; }
|
|
||||||
|
|
||||||
public SaveStateEventArgs()
|
public SaveStateEventArgs()
|
||||||
{
|
{
|
||||||
Values = new Dictionary<string, object>();
|
Values = new Dictionary<string, object>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Set(String key, String value)
|
public Dictionary<string, object> Values { get; set; }
|
||||||
|
|
||||||
|
public void Set(string key, string value)
|
||||||
{
|
{
|
||||||
Values[key] = value;
|
Values[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetInt(String key, int value)
|
public void SetInt(string key, int value)
|
||||||
{
|
{
|
||||||
Values[key] = value;
|
Values[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetBool(String key, bool value)
|
public void SetBool(string key, bool value)
|
||||||
{
|
{
|
||||||
Values[key] = value;
|
Values[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetDouble(String key, double value)
|
public void SetDouble(string key, double value)
|
||||||
{
|
|
||||||
Values[key] = value;
|
|
||||||
}
|
|
||||||
public void SetObject(String key, object value)
|
|
||||||
{
|
{
|
||||||
Values[key] = value;
|
Values[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetObject(string key, object value)
|
||||||
|
{
|
||||||
|
Values[key] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,20 +1,13 @@
|
|||||||
using System;
|
using TelegramBotBase.Base;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
namespace TelegramBotBase.Args;
|
||||||
using System.Text;
|
|
||||||
using TelegramBotBase.Base;
|
|
||||||
using TelegramBotBase.Sessions;
|
|
||||||
|
|
||||||
namespace TelegramBotBase.Args
|
|
||||||
{
|
|
||||||
public class SaveStatesEventArgs
|
public class SaveStatesEventArgs
|
||||||
{
|
{
|
||||||
public StateContainer States { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
public SaveStatesEventArgs(StateContainer states)
|
public SaveStatesEventArgs(StateContainer states)
|
||||||
{
|
{
|
||||||
this.States = states;
|
States = states;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StateContainer States { get; set; }
|
||||||
}
|
}
|
||||||
@ -1,22 +1,17 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Sessions;
|
using TelegramBotBase.Sessions;
|
||||||
|
|
||||||
namespace TelegramBotBase.Base
|
namespace TelegramBotBase.Base;
|
||||||
{
|
|
||||||
public class SessionBeginEventArgs : EventArgs
|
public class SessionBeginEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
|
public SessionBeginEventArgs(long deviceId, DeviceSession device)
|
||||||
|
{
|
||||||
|
DeviceId = deviceId;
|
||||||
|
Device = device;
|
||||||
|
}
|
||||||
|
|
||||||
public long DeviceId { get; set; }
|
public long DeviceId { get; set; }
|
||||||
|
|
||||||
public DeviceSession Device { get; set; }
|
public DeviceSession Device { get; set; }
|
||||||
|
|
||||||
public SessionBeginEventArgs(long DeviceId, DeviceSession Device)
|
|
||||||
{
|
|
||||||
this.DeviceId = DeviceId;
|
|
||||||
this.Device = Device;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,36 +1,27 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using TelegramBotBase.Sessions;
|
using TelegramBotBase.Sessions;
|
||||||
|
|
||||||
namespace TelegramBotBase.Args
|
namespace TelegramBotBase.Args;
|
||||||
{
|
|
||||||
public class SystemExceptionEventArgs : EventArgs
|
public class SystemExceptionEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
|
public SystemExceptionEventArgs()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public String Command { get; set; }
|
public SystemExceptionEventArgs(string command, long deviceId, DeviceSession device, Exception error)
|
||||||
|
{
|
||||||
|
Command = command;
|
||||||
|
DeviceId = deviceId;
|
||||||
|
Device = device;
|
||||||
|
Error = error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Command { get; set; }
|
||||||
|
|
||||||
public long DeviceId { get; set; }
|
public long DeviceId { get; set; }
|
||||||
|
|
||||||
public DeviceSession Device { get; set; }
|
public DeviceSession Device { get; set; }
|
||||||
|
|
||||||
public Exception Error { 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;
|
|
||||||
this.Error = error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,45 +1,38 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using TelegramBotBase.Sessions;
|
using TelegramBotBase.Sessions;
|
||||||
|
|
||||||
namespace TelegramBotBase.Args
|
namespace TelegramBotBase.Args;
|
||||||
{
|
|
||||||
public class UnhandledCallEventArgs : EventArgs
|
public class UnhandledCallEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
public String Command { get; set; }
|
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; }
|
public long DeviceId { get; set; }
|
||||||
|
|
||||||
public DeviceSession Device { get; set; }
|
public DeviceSession Device { get; set; }
|
||||||
|
|
||||||
public String RawData { get; set; }
|
public string RawData { get; set; }
|
||||||
|
|
||||||
public int MessageId { get; set; }
|
public int MessageId { get; set; }
|
||||||
|
|
||||||
public Message Message { get; set; }
|
public Message Message { get; set; }
|
||||||
|
|
||||||
public bool Handled { get; set; }
|
public bool Handled { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public UnhandledCallEventArgs()
|
|
||||||
{
|
|
||||||
this.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;
|
|
||||||
this.Message = message;
|
|
||||||
this.Device = Device;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,9 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace TelegramBotBase.Attributes
|
namespace TelegramBotBase.Attributes;
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Declares that this class should not be getting serialized
|
/// Declares that this class should not be getting serialized
|
||||||
@ -11,7 +8,4 @@ namespace TelegramBotBase.Attributes
|
|||||||
[AttributeUsage(AttributeTargets.Class)]
|
[AttributeUsage(AttributeTargets.Class)]
|
||||||
public class IgnoreState : Attribute
|
public class IgnoreState : Attribute
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,15 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace TelegramBotBase.Attributes
|
namespace TelegramBotBase.Attributes;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Declares that the field or property should be save and recovered an restart.
|
/// Declares that the field or property should be save and recovered an restart.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SaveState : Attribute
|
public class SaveState : Attribute
|
||||||
{
|
{
|
||||||
public String Key { get; set; }
|
public string Key { get; set; }
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,25 +1,27 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace TelegramBotBase.Base
|
namespace TelegramBotBase.Base;
|
||||||
{
|
|
||||||
public static class Async
|
public static class Async
|
||||||
{
|
{
|
||||||
public delegate Task AsyncEventHandler<TEventArgs>(object sender, TEventArgs e) where TEventArgs : EventArgs;
|
public delegate Task AsyncEventHandler<in TEventArgs>(object sender, TEventArgs e) where TEventArgs : EventArgs;
|
||||||
|
|
||||||
public static IEnumerable<AsyncEventHandler<TEventArgs>> GetHandlers<TEventArgs>(
|
public static IEnumerable<AsyncEventHandler<TEventArgs>> GetHandlers<TEventArgs>(
|
||||||
this AsyncEventHandler<TEventArgs> handler)
|
this AsyncEventHandler<TEventArgs> handler)
|
||||||
where TEventArgs : EventArgs
|
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
|
where TEventArgs : EventArgs
|
||||||
=> Task.WhenAll(
|
{
|
||||||
|
return Task.WhenAll(
|
||||||
handler.GetHandlers()
|
handler.GetHandlers()
|
||||||
.Select(handleAsync => handleAsync(sender, e)));
|
.Select(handleAsync => handleAsync(sender, e)));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,27 +1,18 @@
|
|||||||
using System;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
using TelegramBotBase.Sessions;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
namespace TelegramBotBase.Base;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace TelegramBotBase.Base
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Base class for controls
|
/// Base class for controls
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ControlBase
|
public class ControlBase
|
||||||
{
|
{
|
||||||
public Sessions.DeviceSession Device { get; set; }
|
public DeviceSession Device { get; set; }
|
||||||
|
|
||||||
public int ID { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
public String ControlID
|
public string ControlId => "#c" + Id;
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "#c" + this.ID.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines if the control should be rendered and invoked with actions
|
/// Defines if the control should be rendered and invoked with actions
|
||||||
@ -34,47 +25,35 @@ namespace TelegramBotBase.Base
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual void Init()
|
public virtual void Init()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task Load(MessageResult result)
|
public virtual Task Load(MessageResult result)
|
||||||
{
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task Action(MessageResult result, String value = null)
|
public virtual Task Action(MessageResult result, string value = null)
|
||||||
{
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public virtual Task Render(MessageResult result)
|
||||||
public virtual async Task Render(MessageResult result)
|
|
||||||
{
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual async Task Hidden(bool FormClose)
|
public virtual Task Hidden(bool formClose)
|
||||||
{
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Will be called on a cleanup.
|
/// Will be called on a cleanup.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual async Task Cleanup()
|
public virtual Task Cleanup()
|
||||||
{
|
{
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,118 +1,64 @@
|
|||||||
using System;
|
using System.IO;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
using Telegram.Bot.Types.Enums;
|
||||||
using Telegram.Bot.Types.InputFiles;
|
using Telegram.Bot.Types.InputFiles;
|
||||||
|
|
||||||
namespace TelegramBotBase.Base
|
namespace TelegramBotBase.Base;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a class to manage attachments within messages.
|
/// Returns a class to manage attachments within messages.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DataResult : ResultBase
|
public class DataResult : ResultBase
|
||||||
{
|
{
|
||||||
|
public DataResult(UpdateResult update)
|
||||||
|
{
|
||||||
|
UpdateData = update;
|
||||||
|
}
|
||||||
|
|
||||||
//public Telegram.Bot.Args.MessageEventArgs RawMessageData { get; set; }
|
//public Telegram.Bot.Args.MessageEventArgs RawMessageData { get; set; }
|
||||||
|
|
||||||
public UpdateResult UpdateData { get; set; }
|
public UpdateResult UpdateData { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public Contact Contact
|
public Contact Contact => Message.Contact;
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return this.Message.Contact;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location Location
|
public Location Location => Message.Location;
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return this.Message.Location;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Document Document
|
public Document Document => Message.Document;
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return this.Message.Document;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Audio Audio
|
public Audio Audio => Message.Audio;
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return this.Message.Audio;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Video Video
|
public Video Video => Message.Video;
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return this.Message.Video;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public PhotoSize[] Photos
|
public PhotoSize[] Photos => Message.Photo;
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return this.Message.Photo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Telegram.Bot.Types.Enums.MessageType Type
|
public MessageType Type => Message?.Type ?? MessageType.Unknown;
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return this.Message?.Type ?? Telegram.Bot.Types.Enums.MessageType.Unknown;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Message Message
|
public override Message Message => UpdateData?.Message;
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return this.UpdateData?.Message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the FileId of the first reachable element.
|
/// Returns the FileId of the first reachable element.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public String FileId
|
public string FileId =>
|
||||||
{
|
Document?.FileId ??
|
||||||
get
|
Audio?.FileId ??
|
||||||
{
|
Video?.FileId ??
|
||||||
return (this.Document?.FileId ??
|
Photos.FirstOrDefault()?.FileId;
|
||||||
this.Audio?.FileId ??
|
|
||||||
this.Video?.FileId ??
|
|
||||||
this.Photos.FirstOrDefault()?.FileId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public DataResult(UpdateResult update)
|
|
||||||
{
|
|
||||||
this.UpdateData = update;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<InputOnlineFile> DownloadDocument()
|
public async Task<InputOnlineFile> DownloadDocument()
|
||||||
{
|
{
|
||||||
var encryptedContent = new System.IO.MemoryStream();
|
var encryptedContent = new MemoryStream();
|
||||||
encryptedContent.SetLength(this.Document.FileSize.Value);
|
encryptedContent.SetLength(Document.FileSize.Value);
|
||||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Document.FileId, encryptedContent);
|
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Document.FileId,
|
||||||
|
encryptedContent);
|
||||||
|
|
||||||
return new InputOnlineFile(encryptedContent, this.Document.FileName);
|
return new InputOnlineFile(encryptedContent, Document.FileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -121,10 +67,10 @@ namespace TelegramBotBase.Base
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path"></param>
|
/// <param name="path"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task DownloadDocument(String path)
|
public async Task DownloadDocument(string path)
|
||||||
{
|
{
|
||||||
var file = await Device.Client.TelegramClient.GetFileAsync(this.Document.FileId);
|
var file = await Device.Client.TelegramClient.GetFileAsync(Document.FileId);
|
||||||
FileStream fs = new FileStream(path, FileMode.Create);
|
var fs = new FileStream(path, FileMode.Create);
|
||||||
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||||
fs.Close();
|
fs.Close();
|
||||||
fs.Dispose();
|
fs.Dispose();
|
||||||
@ -136,8 +82,8 @@ namespace TelegramBotBase.Base
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<byte[]> DownloadRawDocument()
|
public async Task<byte[]> DownloadRawDocument()
|
||||||
{
|
{
|
||||||
MemoryStream ms = new MemoryStream();
|
var ms = new MemoryStream();
|
||||||
await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Document.FileId, ms);
|
await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Document.FileId, ms);
|
||||||
return ms.ToArray();
|
return ms.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +91,7 @@ namespace TelegramBotBase.Base
|
|||||||
/// Downloads a document and returns it as string. (txt,csv,etc) Default encoding ist UTF8.
|
/// Downloads a document and returns it as string. (txt,csv,etc) Default encoding ist UTF8.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<String> DownloadRawTextDocument()
|
public async Task<string> DownloadRawTextDocument()
|
||||||
{
|
{
|
||||||
return await DownloadRawTextDocument(Encoding.UTF8);
|
return await DownloadRawTextDocument(Encoding.UTF8);
|
||||||
}
|
}
|
||||||
@ -154,10 +100,10 @@ namespace TelegramBotBase.Base
|
|||||||
/// Downloads a document and returns it as string. (txt,csv,etc)
|
/// Downloads a document and returns it as string. (txt,csv,etc)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<String> DownloadRawTextDocument(Encoding encoding)
|
public async Task<string> DownloadRawTextDocument(Encoding encoding)
|
||||||
{
|
{
|
||||||
MemoryStream ms = new MemoryStream();
|
var ms = new MemoryStream();
|
||||||
await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Document.FileId, ms);
|
await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Document.FileId, ms);
|
||||||
|
|
||||||
ms.Position = 0;
|
ms.Position = 0;
|
||||||
|
|
||||||
@ -168,17 +114,17 @@ namespace TelegramBotBase.Base
|
|||||||
|
|
||||||
public async Task<InputOnlineFile> DownloadVideo()
|
public async Task<InputOnlineFile> DownloadVideo()
|
||||||
{
|
{
|
||||||
var encryptedContent = new System.IO.MemoryStream();
|
var encryptedContent = new MemoryStream();
|
||||||
encryptedContent.SetLength(this.Video.FileSize.Value);
|
encryptedContent.SetLength(Video.FileSize.Value);
|
||||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Video.FileId, encryptedContent);
|
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Video.FileId, encryptedContent);
|
||||||
|
|
||||||
return new InputOnlineFile(encryptedContent, "");
|
return new InputOnlineFile(encryptedContent, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DownloadVideo(String path)
|
public async Task DownloadVideo(string path)
|
||||||
{
|
{
|
||||||
var file = await Device.Client.TelegramClient.GetFileAsync(this.Video.FileId);
|
var file = await Device.Client.TelegramClient.GetFileAsync(Video.FileId);
|
||||||
FileStream fs = new FileStream(path, FileMode.Create);
|
var fs = new FileStream(path, FileMode.Create);
|
||||||
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||||
fs.Close();
|
fs.Close();
|
||||||
fs.Dispose();
|
fs.Dispose();
|
||||||
@ -186,17 +132,17 @@ namespace TelegramBotBase.Base
|
|||||||
|
|
||||||
public async Task<InputOnlineFile> DownloadAudio()
|
public async Task<InputOnlineFile> DownloadAudio()
|
||||||
{
|
{
|
||||||
var encryptedContent = new System.IO.MemoryStream();
|
var encryptedContent = new MemoryStream();
|
||||||
encryptedContent.SetLength(this.Audio.FileSize.Value);
|
encryptedContent.SetLength(Audio.FileSize.Value);
|
||||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Audio.FileId, encryptedContent);
|
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Audio.FileId, encryptedContent);
|
||||||
|
|
||||||
return new InputOnlineFile(encryptedContent, "");
|
return new InputOnlineFile(encryptedContent, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DownloadAudio(String path)
|
public async Task DownloadAudio(string path)
|
||||||
{
|
{
|
||||||
var file = await Device.Client.TelegramClient.GetFileAsync(this.Audio.FileId);
|
var file = await Device.Client.TelegramClient.GetFileAsync(Audio.FileId);
|
||||||
FileStream fs = new FileStream(path, FileMode.Create);
|
var fs = new FileStream(path, FileMode.Create);
|
||||||
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||||
fs.Close();
|
fs.Close();
|
||||||
fs.Dispose();
|
fs.Dispose();
|
||||||
@ -204,23 +150,21 @@ namespace TelegramBotBase.Base
|
|||||||
|
|
||||||
public async Task<InputOnlineFile> DownloadPhoto(int index)
|
public async Task<InputOnlineFile> DownloadPhoto(int index)
|
||||||
{
|
{
|
||||||
var photo = this.Photos[index];
|
var photo = Photos[index];
|
||||||
var encryptedContent = new System.IO.MemoryStream();
|
var encryptedContent = new MemoryStream();
|
||||||
encryptedContent.SetLength(photo.FileSize.Value);
|
encryptedContent.SetLength(photo.FileSize.Value);
|
||||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(photo.FileId, encryptedContent);
|
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(photo.FileId, encryptedContent);
|
||||||
|
|
||||||
return new InputOnlineFile(encryptedContent, "");
|
return new InputOnlineFile(encryptedContent, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DownloadPhoto(int index, String path)
|
public async Task DownloadPhoto(int index, string path)
|
||||||
{
|
{
|
||||||
var photo = this.Photos[index];
|
var photo = Photos[index];
|
||||||
var file = await Device.Client.TelegramClient.GetFileAsync(photo.FileId);
|
var file = await Device.Client.TelegramClient.GetFileAsync(photo.FileId);
|
||||||
FileStream fs = new FileStream(path, FileMode.Create);
|
var fs = new FileStream(path, FileMode.Create);
|
||||||
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||||
fs.Close();
|
fs.Close();
|
||||||
fs.Dispose();
|
fs.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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