Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 06a021de49 | |||
| 89b4f2db92 | |||
| 468022ae0e | |||
| cb024e52ff | |||
| 5dbf7f4073 | |||
| d4a5d3d6ee | |||
| 233a67f2b0 | |||
| ba772f3f7c | |||
| ee78703cd1 | |||
| 3d2d21f6c0 | |||
| 0dedd3c0f4 | |||
| 79d5df8291 | |||
| 899243c62b | |||
| 5f9c640930 | |||
| 0e445dd586 | |||
| da090627ff | |||
| 88bd12aadd | |||
| 162d4a1d05 | |||
| e28cc2b8da | |||
| c6cda703ef | |||
| 401c8d02aa | |||
| 2cf4910abd | |||
| 81da5e0bc7 | |||
| b42e03fe06 |
+2
-2
@@ -361,5 +361,5 @@ MigrationBackup/
|
|||||||
|
|
||||||
# Fody - auto-generated XML schema
|
# Fody - auto-generated XML schema
|
||||||
FodyWeavers.xsd
|
FodyWeavers.xsd
|
||||||
/GETTING_STARTED.md
|
|
||||||
/ANNOTATION_OVERVIEW.md
|
.aider*
|
||||||
|
|||||||
@@ -1,674 +1,7 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
Copyright (c) 2026 RikitavTimur
|
||||||
Version 3, 29 June 2007
|
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
software and other kinds of works.
|
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
|
||||||
to take away your freedom to share and change the works. By contrast,
|
|
||||||
the GNU General Public License is intended to guarantee your freedom to
|
|
||||||
share and change all versions of a program--to make sure it remains free
|
|
||||||
software for all its users. We, the Free Software Foundation, use the
|
|
||||||
GNU General Public License for most of our software; it applies also to
|
|
||||||
any other work released this way by its authors. You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
them if you wish), that you receive source code or can get it if you
|
|
||||||
want it, that you can change the software or use pieces of it in new
|
|
||||||
free programs, and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you
|
|
||||||
these rights or asking you to surrender the rights. Therefore, you have
|
|
||||||
certain responsibilities if you distribute copies of the software, or if
|
|
||||||
you modify it: responsibilities to respect the freedom of others.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
|
||||||
freedoms that you received. You must make sure that they, too, receive
|
|
||||||
or can get the source code. And you must show them these terms so they
|
|
||||||
know their rights.
|
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
|
||||||
that there is no warranty for this free software. For both users' and
|
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
|
||||||
changed, so that their problems will not be attributed erroneously to
|
|
||||||
authors of previous versions.
|
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run
|
|
||||||
modified versions of the software inside them, although the manufacturer
|
|
||||||
can do so. This is fundamentally incompatible with the aim of
|
|
||||||
protecting users' freedom to change the software. The systematic
|
|
||||||
pattern of such abuse occurs in the area of products for individuals to
|
|
||||||
use, which is precisely where it is most unacceptable. Therefore, we
|
|
||||||
have designed this version of the GPL to prohibit the practice for those
|
|
||||||
products. If such problems arise substantially in other domains, we
|
|
||||||
stand ready to extend this provision to those domains in future versions
|
|
||||||
of the GPL, as needed to protect the freedom of users.
|
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents.
|
|
||||||
States should not allow patents to restrict development and use of
|
|
||||||
software on general-purpose computers, but in those that do, we wish to
|
|
||||||
avoid the special danger that patents applied to a free program could
|
|
||||||
make it effectively proprietary. To prevent this, the GPL assures that
|
|
||||||
patents cannot be used to render the program non-free.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
0. Definitions.
|
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU General Public License.
|
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
|
||||||
works, such as semiconductor masks.
|
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
|
||||||
"recipients" may be individuals or organizations.
|
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
|
||||||
in a fashion requiring copyright permission, other than the making of an
|
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
|
||||||
earlier work or a work "based on" the earlier work.
|
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
|
||||||
on the Program.
|
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without
|
|
||||||
permission, would make you directly or secondarily liable for
|
|
||||||
infringement under applicable copyright law, except executing it on a
|
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
|
||||||
distribution (with or without modification), making available to the
|
|
||||||
public, and in some countries other activities as well.
|
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
|
||||||
to the extent that it includes a convenient and prominently visible
|
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
|
||||||
tells the user that there is no warranty for the work (except to the
|
|
||||||
extent that warranties are provided), that licensees may convey the
|
|
||||||
work under this License, and how to view a copy of this License. If
|
|
||||||
the interface presents a list of user commands or options, such as a
|
|
||||||
menu, a prominent item in the list meets this criterion.
|
|
||||||
|
|
||||||
1. Source Code.
|
|
||||||
|
|
||||||
The "source code" for a work means the preferred form of the work
|
|
||||||
for making modifications to it. "Object code" means any non-source
|
|
||||||
form of a work.
|
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official
|
|
||||||
standard defined by a recognized standards body, or, in the case of
|
|
||||||
interfaces specified for a particular programming language, one that
|
|
||||||
is widely used among developers working in that language.
|
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
|
||||||
packaging a Major Component, but which is not part of that Major
|
|
||||||
Component, and (b) serves only to enable use of the work with that
|
|
||||||
Major Component, or to implement a Standard Interface for which an
|
|
||||||
implementation is available to the public in source code form. A
|
|
||||||
"Major Component", in this context, means a major essential component
|
|
||||||
(kernel, window system, and so on) of the specific operating system
|
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
|
||||||
produce the work, or an object code interpreter used to run it.
|
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all
|
|
||||||
the source code needed to generate, install, and (for an executable
|
|
||||||
work) run the object code and to modify the work, including scripts to
|
|
||||||
control those activities. However, it does not include the work's
|
|
||||||
System Libraries, or general-purpose tools or generally available free
|
|
||||||
programs which are used unmodified in performing those activities but
|
|
||||||
which are not part of the work. For example, Corresponding Source
|
|
||||||
includes interface definition files associated with source files for
|
|
||||||
the work, and the source code for shared libraries and dynamically
|
|
||||||
linked subprograms that the work is specifically designed to require,
|
|
||||||
such as by intimate data communication or control flow between those
|
|
||||||
subprograms and other parts of the work.
|
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users
|
|
||||||
can regenerate automatically from other parts of the Corresponding
|
|
||||||
Source.
|
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that
|
|
||||||
same work.
|
|
||||||
|
|
||||||
2. Basic Permissions.
|
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
|
||||||
permission to run the unmodified Program. The output from running a
|
|
||||||
covered work is covered by this License only if the output, given its
|
|
||||||
content, constitutes a covered work. This License acknowledges your
|
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not
|
|
||||||
convey, without conditions so long as your license otherwise remains
|
|
||||||
in force. You may convey covered works to others for the sole purpose
|
|
||||||
of having them make modifications exclusively for you, or provide you
|
|
||||||
with facilities for running those works, provided that you comply with
|
|
||||||
the terms of this License in conveying all material for which you do
|
|
||||||
not control copyright. Those thus making or running the covered works
|
|
||||||
for you must do so exclusively on your behalf, under your direction
|
|
||||||
and control, on terms that prohibit them from making any copies of
|
|
||||||
your copyrighted material outside their relationship with you.
|
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under
|
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
|
||||||
makes it unnecessary.
|
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
|
||||||
measure under any applicable law fulfilling obligations under article
|
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
||||||
similar laws prohibiting or restricting circumvention of such
|
|
||||||
measures.
|
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
|
||||||
circumvention of technological measures to the extent such circumvention
|
|
||||||
is effected by exercising rights under this License with respect to
|
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
|
||||||
modification of the work as a means of enforcing, against the work's
|
|
||||||
users, your or third parties' legal rights to forbid circumvention of
|
|
||||||
technological measures.
|
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
|
||||||
receive it, in any medium, provided that you conspicuously and
|
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
|
||||||
keep intact all notices stating that this License and any
|
|
||||||
non-permissive terms added in accord with section 7 apply to the code;
|
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
|
||||||
recipients a copy of this License along with the Program.
|
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
|
||||||
and you may offer support or warranty protection for a fee.
|
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
|
||||||
produce it from the Program, in the form of source code under the
|
|
||||||
terms of section 4, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified
|
|
||||||
it, and giving a relevant date.
|
|
||||||
|
|
||||||
b) The work must carry prominent notices stating that it is
|
|
||||||
released under this License and any conditions added under section
|
|
||||||
7. This requirement modifies the requirement in section 4 to
|
|
||||||
"keep intact all notices".
|
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this
|
|
||||||
License to anyone who comes into possession of a copy. This
|
|
||||||
License will therefore apply, along with any applicable section 7
|
|
||||||
additional terms, to the whole of the work, and all its parts,
|
|
||||||
regardless of how they are packaged. This License gives no
|
|
||||||
permission to license the work in any other way, but it does not
|
|
||||||
invalidate such permission if you have separately received it.
|
|
||||||
|
|
||||||
d) If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
|
||||||
work need not make them do so.
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
|
||||||
works, which are not by their nature extensions of the covered work,
|
|
||||||
and which are not combined with it such as to form a larger program,
|
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
|
||||||
"aggregate" if the compilation and its resulting copyright are not
|
|
||||||
used to limit the access or legal rights of the compilation's users
|
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
|
||||||
in an aggregate does not cause this License to apply to the other
|
|
||||||
parts of the aggregate.
|
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
|
||||||
of sections 4 and 5, provided that you also convey the
|
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
|
||||||
in one of these ways:
|
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by the
|
|
||||||
Corresponding Source fixed on a durable physical medium
|
|
||||||
customarily used for software interchange.
|
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a
|
|
||||||
written offer, valid for at least three years and valid for as
|
|
||||||
long as you offer spare parts or customer support for that product
|
|
||||||
model, to give anyone who possesses the object code either (1) a
|
|
||||||
copy of the Corresponding Source for all the software in the
|
|
||||||
product that is covered by this License, on a durable physical
|
|
||||||
medium customarily used for software interchange, for a price no
|
|
||||||
more than your reasonable cost of physically performing this
|
|
||||||
conveying of source, or (2) access to copy the
|
|
||||||
Corresponding Source from a network server at no charge.
|
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the
|
|
||||||
written offer to provide the Corresponding Source. This
|
|
||||||
alternative is allowed only occasionally and noncommercially, and
|
|
||||||
only if you received the object code with such an offer, in accord
|
|
||||||
with subsection 6b.
|
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated
|
|
||||||
place (gratis or for a charge), and offer equivalent access to the
|
|
||||||
Corresponding Source in the same way through the same place at no
|
|
||||||
further charge. You need not require recipients to copy the
|
|
||||||
Corresponding Source along with the object code. If the place to
|
|
||||||
copy the object code is a network server, the Corresponding Source
|
|
||||||
may be on a different server (operated by you or a third party)
|
|
||||||
that supports equivalent copying facilities, provided you maintain
|
|
||||||
clear directions next to the object code saying where to find the
|
|
||||||
Corresponding Source. Regardless of what server hosts the
|
|
||||||
Corresponding Source, you remain obligated to ensure that it is
|
|
||||||
available for as long as needed to satisfy these requirements.
|
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided
|
|
||||||
you inform other peers where the object code and Corresponding
|
|
||||||
Source of the work are being offered to the general public at no
|
|
||||||
charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
|
||||||
included in conveying the object code work.
|
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
|
||||||
tangible personal property which is normally used for personal, family,
|
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
|
||||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
|
||||||
product received by a particular user, "normally used" refers to a
|
|
||||||
typical or common use of that class of product, regardless of the status
|
|
||||||
of the particular user or of the way in which the particular user
|
|
||||||
actually uses, or expects or is expected to use, the product. A product
|
|
||||||
is a consumer product regardless of whether the product has substantial
|
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
|
||||||
the only significant mode of use of the product.
|
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
|
||||||
procedures, authorization keys, or other information required to install
|
|
||||||
and execute modified versions of a covered work in that User Product from
|
|
||||||
a modified version of its Corresponding Source. The information must
|
|
||||||
suffice to ensure that the continued functioning of the modified object
|
|
||||||
code is in no case prevented or interfered with solely because
|
|
||||||
modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
|
||||||
part of a transaction in which the right of possession and use of the
|
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
|
||||||
by the Installation Information. But this requirement does not apply
|
|
||||||
if neither you nor any third party retains the ability to install
|
|
||||||
modified object code on the User Product (for example, the work has
|
|
||||||
been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
|
||||||
requirement to continue to provide support service, warranty, or updates
|
|
||||||
for a work that has been modified or installed by the recipient, or for
|
|
||||||
the User Product in which it has been modified or installed. Access to a
|
|
||||||
network may be denied when the modification itself materially and
|
|
||||||
adversely affects the operation of the network or violates the rules and
|
|
||||||
protocols for communication across the network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
|
||||||
in accord with this section must be in a format that is publicly
|
|
||||||
documented (and with an implementation available to the public in
|
|
||||||
source code form), and must require no special password or key for
|
|
||||||
unpacking, reading or copying.
|
|
||||||
|
|
||||||
7. Additional Terms.
|
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
|
||||||
License by making exceptions from one or more of its conditions.
|
|
||||||
Additional permissions that are applicable to the entire Program shall
|
|
||||||
be treated as though they were included in this License, to the extent
|
|
||||||
that they are valid under applicable law. If additional permissions
|
|
||||||
apply only to part of the Program, that part may be used separately
|
|
||||||
under those permissions, but the entire Program remains governed by
|
|
||||||
this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
|
||||||
remove any additional permissions from that copy, or from any part of
|
|
||||||
it. (Additional permissions may be written to require their own
|
|
||||||
removal in certain cases when you modify the work.) You may place
|
|
||||||
additional permissions on material, added by you to a covered work,
|
|
||||||
for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
|
||||||
that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the
|
|
||||||
terms of sections 15 and 16 of this License; or
|
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or
|
|
||||||
author attributions in that material or in the Appropriate Legal
|
|
||||||
Notices displayed by works containing it; or
|
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or
|
|
||||||
requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or
|
|
||||||
authors of the material; or
|
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some
|
|
||||||
trade names, trademarks, or service marks; or
|
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that
|
|
||||||
material by anyone who conveys the material (or modified versions of
|
|
||||||
it) with contractual assumptions of liability to the recipient, for
|
|
||||||
any liability that these contractual assumptions directly impose on
|
|
||||||
those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
|
||||||
received it, or any part of it, contains a notice stating that it is
|
|
||||||
governed by this License along with a term that is a further
|
|
||||||
restriction, you may remove that term. If a license document contains
|
|
||||||
a further restriction but permits relicensing or conveying under this
|
|
||||||
License, you may add to a covered work material governed by the terms
|
|
||||||
of that license document, provided that the further restriction does
|
|
||||||
not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
|
||||||
must place, in the relevant source files, a statement of the
|
|
||||||
additional terms that apply to those files, or a notice indicating
|
|
||||||
where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
|
||||||
form of a separately written license, or stated as exceptions;
|
|
||||||
the above requirements apply either way.
|
|
||||||
|
|
||||||
8. Termination.
|
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
|
||||||
modify it is void, and will automatically terminate your rights under
|
|
||||||
this License (including any patent licenses granted under the third
|
|
||||||
paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
|
||||||
license from a particular copyright holder is reinstated (a)
|
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
|
||||||
holder fails to notify you of the violation by some reasonable means
|
|
||||||
prior to 60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
|
||||||
violation by some reasonable means, this is the first time you have
|
|
||||||
received notice of violation of this License (for any work) from that
|
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
|
||||||
your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
|
||||||
licenses of parties who have received copies or rights from you under
|
|
||||||
this License. If your rights have been terminated and not permanently
|
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
|
||||||
material under section 10.
|
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
|
||||||
run a copy of the Program. Ancillary propagation of a covered work
|
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
|
||||||
to receive a copy likewise does not require acceptance. However,
|
|
||||||
nothing other than this License grants you permission to propagate or
|
|
||||||
modify any covered work. These actions infringe copyright if you do
|
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
|
||||||
receives a license from the original licensors, to run, modify and
|
|
||||||
propagate that work, subject to this License. You are not responsible
|
|
||||||
for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
|
||||||
organization, or substantially all assets of one, or subdividing an
|
|
||||||
organization, or merging organizations. If propagation of a covered
|
|
||||||
work results from an entity transaction, each party to that
|
|
||||||
transaction who receives a copy of the work also receives whatever
|
|
||||||
licenses to the work the party's predecessor in interest had or could
|
|
||||||
give under the previous paragraph, plus a right to possession of the
|
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
|
||||||
rights granted or affirmed under this License. For example, you may
|
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
|
||||||
rights granted under this License, and you may not initiate litigation
|
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
|
||||||
sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
11. Patents.
|
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
|
||||||
License of the Program or a work on which the Program is based. The
|
|
||||||
work thus licensed is called the contributor's "contributor version".
|
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
|
||||||
owned or controlled by the contributor, whether already acquired or
|
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
|
||||||
by this License, of making, using, or selling its contributor version,
|
|
||||||
but do not include claims that would be infringed only as a
|
|
||||||
consequence of further modification of the contributor version. For
|
|
||||||
purposes of this definition, "control" includes the right to grant
|
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
|
||||||
this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
patent license under the contributor's essential patent claims, to
|
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
|
||||||
propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
|
||||||
(such as an express permission to practice a patent or covenant not to
|
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
|
||||||
party means to make such an agreement or commitment not to enforce a
|
|
||||||
patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
|
||||||
and the Corresponding Source of the work is not available for anyone
|
|
||||||
to copy, free of charge and under the terms of this License, through a
|
|
||||||
publicly available network server or other readily accessible means,
|
|
||||||
then you must either (1) cause the Corresponding Source to be so
|
|
||||||
available, or (2) arrange to deprive yourself of the benefit of the
|
|
||||||
patent license for this particular work, or (3) arrange, in a manner
|
|
||||||
consistent with the requirements of this License, to extend the patent
|
|
||||||
license to downstream recipients. "Knowingly relying" means you have
|
|
||||||
actual knowledge that, but for the patent license, your conveying the
|
|
||||||
covered work in a country, or your recipient's use of the covered work
|
|
||||||
in a country, would infringe one or more identifiable patents in that
|
|
||||||
country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
|
||||||
covered work, and grant a patent license to some of the parties
|
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
|
||||||
or convey a specific copy of the covered work, then the patent license
|
|
||||||
you grant is automatically extended to all recipients of the covered
|
|
||||||
work and works based on it.
|
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
|
||||||
conditioned on the non-exercise of one or more of the rights that are
|
|
||||||
specifically granted under this License. You may not convey a covered
|
|
||||||
work if you are a party to an arrangement with a third party that is
|
|
||||||
in the business of distributing software, under which you make payment
|
|
||||||
to the third party based on the extent of your activity of conveying
|
|
||||||
the work, and under which the third party grants, to any of the
|
|
||||||
parties who would receive the covered work from you, a discriminatory
|
|
||||||
patent license (a) in connection with copies of the covered work
|
|
||||||
conveyed by you (or copies made from those copies), or (b) primarily
|
|
||||||
for and in connection with specific products or compilations that
|
|
||||||
contain the covered work, unless you entered into that arrangement,
|
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
|
||||||
any implied license or other defenses to infringement that may
|
|
||||||
otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you may
|
|
||||||
not convey it at all. For example, if you agree to terms that obligate you
|
|
||||||
to collect a royalty for further conveying from those to whom you convey
|
|
||||||
the Program, the only way you could satisfy both those terms and this
|
|
||||||
License would be to refrain entirely from conveying the Program.
|
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
|
||||||
under version 3 of the GNU Affero General Public License into a single
|
|
||||||
combined work, and to convey the resulting work. The terms of this
|
|
||||||
License will continue to apply to the part which is the covered work,
|
|
||||||
but the special requirements of the GNU Affero General Public License,
|
|
||||||
section 13, concerning interaction through a network will apply to the
|
|
||||||
combination as such.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
|
||||||
the GNU General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
|
||||||
Program specifies that a certain numbered version of the GNU General
|
|
||||||
Public License "or any later version" applies to it, you have the
|
|
||||||
option of following the terms and conditions either of that numbered
|
|
||||||
version or of any later version published by the Free Software
|
|
||||||
Foundation. If the Program does not specify a version number of the
|
|
||||||
GNU General Public License, you may choose any version ever published
|
|
||||||
by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
|
||||||
versions of the GNU General Public License can be used, that proxy's
|
|
||||||
public statement of acceptance of a version permanently authorizes you
|
|
||||||
to choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
|
||||||
permissions. However, no additional obligations are imposed on any
|
|
||||||
author or copyright holder as a result of your choosing to follow a
|
|
||||||
later version.
|
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
|
||||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. Limitation of Liability.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
|
||||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
|
||||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
|
||||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
|
||||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
|
||||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|
||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGES.
|
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
|
||||||
above cannot be given local legal effect according to their terms,
|
|
||||||
reviewing courts shall apply local law that most closely approximates
|
|
||||||
an absolute waiver of all civil liability in connection with the
|
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
|
||||||
copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
state the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
|
||||||
notice like this when it starts in an interactive mode:
|
|
||||||
|
|
||||||
<program> Copyright (C) <year> <name of author>
|
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, your program's commands
|
|
||||||
might be different; for a GUI interface, you would use an "about box".
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
||||||
For more information on this, and how to apply and follow the GNU GPL, see
|
|
||||||
<https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your program
|
|
||||||
into proprietary programs. If your program is a subroutine library, you
|
|
||||||
may consider it more useful to permit linking proprietary applications with
|
|
||||||
the library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License. But first, please read
|
|
||||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
# Telegrator
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
> **A modern reactive framework for Telegram bots in C# with aspect-oriented design, mediator-based dispatching, and flexible architecture.**
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 🚀 About Telegrator
|
## 🚀 About Telegrator
|
||||||
|
|
||||||
Telegrator is a next-generation framework for building Telegram bots in C#, inspired by AOP (Aspect-Oriented Programming) and the mediator pattern. It enables decentralized, easily extensible, and maintainable bot logic without traditional state machines or monolithic handlers.
|
Telegrator is a modern C# framework for building Telegram bots, inspired by AOP (Aspect-Oriented Programming) and the mediator pattern. It enables decentralized, easily extensible, and maintainable bot logic without traditional state machines or monolithic handlers.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
The documentation may not be completely transparent, informative or even actual to latest version, so if you have any questions or problems, please write them in the [Telegram.Bot](https://t.me/joinchat/B35YY0QbLfd034CFnvCtCA) group. I am a member of this group and will notice you! If you have any suggestions or want to participate in building documentation, make push requests and open issues on this repository!
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -95,13 +95,12 @@ bot.Handlers.AddHandler<StartCommandHandler>();
|
|||||||
using Telegrator.Handlers;
|
using Telegrator.Handlers;
|
||||||
using Telegrator.Annotations;
|
using Telegrator.Annotations;
|
||||||
|
|
||||||
[CommandHandler, CommandAlias("first"), NumericState(SpecialState.NoState)]
|
[CommandHandler, CommandAlias("first"), State<SetupWizard>(null)]
|
||||||
public class StateKeepFirst : CommandHandler
|
public class StateKeepFirst : CommandHandler
|
||||||
{
|
{
|
||||||
public override async Task<Result> Execute(IHandlerContainer<Message> container, CancellationToken cancellation)
|
public override async Task<Result> Execute(IHandlerContainer<Message> container, CancellationToken cancellation)
|
||||||
{
|
{
|
||||||
container.CreateNumericState();
|
StateStorage.GetStateMachine<SetupWizard>().BysenderId().Advance();
|
||||||
container.ForwardNumericState();
|
|
||||||
await Reply("first state moved (1)", cancellationToken: cancellation);
|
await Reply("first state moved (1)", cancellationToken: cancellation);
|
||||||
return Result.Ok();
|
return Result.Ok();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<Solution>
|
<Solution>
|
||||||
<Project Path="dev/Telegrator.RoslynGenerators/Telegrator.RoslynGenerators.csproj" />
|
<Project Path="dev/Telegrator.RoslynGenerators/Telegrator.RoslynGenerators.csproj" />
|
||||||
|
<Project Path="src/Telegartor.RedisStateStorage/Telegartor.RedisStateStorage.csproj" />
|
||||||
<Project Path="src/Telegrator.Analyzers/Telegrator.Analyzers.csproj" />
|
<Project Path="src/Telegrator.Analyzers/Telegrator.Analyzers.csproj" />
|
||||||
<Project Path="src/Telegrator.Hosting.Web/Telegrator.Hosting.Web.csproj" />
|
<Project Path="src/Telegrator.Hosting.Web/Telegrator.Hosting.Web.csproj" />
|
||||||
<Project Path="src/Telegrator.Hosting/Telegrator.Hosting.csproj" />
|
<Project Path="src/Telegrator.Hosting/Telegrator.Hosting.csproj" />
|
||||||
|
|||||||
@@ -5,10 +5,6 @@ using System.Collections.Immutable;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Telegrator.RoslynGenerators.RoslynExtensions;
|
using Telegrator.RoslynGenerators.RoslynExtensions;
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
using System.Diagnostics;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Telegrator.RoslynGenerators;
|
namespace Telegrator.RoslynGenerators;
|
||||||
|
|
||||||
[Generator(LanguageNames.CSharp)]
|
[Generator(LanguageNames.CSharp)]
|
||||||
@@ -72,6 +68,9 @@ public class ImplicitHandlerBuilderExtensionsGenerator : IIncrementalGenerator
|
|||||||
if (className == "FilterAnnotation")
|
if (className == "FilterAnnotation")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (className == "StateAttribute")
|
||||||
|
continue;
|
||||||
|
|
||||||
MethodDeclarationSyntax? targeter = classDeclaration.Members.OfType<MethodDeclarationSyntax>().SingleOrDefault(IsTargeterMethod);
|
MethodDeclarationSyntax? targeter = classDeclaration.Members.OfType<MethodDeclarationSyntax>().SingleOrDefault(IsTargeterMethod);
|
||||||
if (targeter != null)
|
if (targeter != null)
|
||||||
{
|
{
|
||||||
@@ -101,7 +100,13 @@ public class ImplicitHandlerBuilderExtensionsGenerator : IIncrementalGenerator
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
usings.UnionAdd(classDeclaration.FindAncestor<CompilationUnitSyntax>().Usings, UsingEqualityComparer);
|
usings.UnionAdd(classDeclaration.FindAncestor<CompilationUnitSyntax>().Usings, UsingEqualityComparer);
|
||||||
MethodDeclarationSyntax targeter = FindTargetterMethod(targetters, classDeclaration);
|
MethodDeclarationSyntax? targeter = FindTargetterMethod(targetters, classDeclaration);
|
||||||
|
|
||||||
|
if (targeter == null)
|
||||||
|
{
|
||||||
|
debugExport.AppendLine("Targetter not found");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (classDeclaration.ParameterList != null && classDeclaration.BaseList != null)
|
if (classDeclaration.ParameterList != null && classDeclaration.BaseList != null)
|
||||||
{
|
{
|
||||||
@@ -140,16 +145,16 @@ public class ImplicitHandlerBuilderExtensionsGenerator : IIncrementalGenerator
|
|||||||
{
|
{
|
||||||
ClassDeclarationSyntax extensionsClass = SyntaxFactory.ClassDeclaration("HandlerBuilderExtensions")
|
ClassDeclarationSyntax extensionsClass = SyntaxFactory.ClassDeclaration("HandlerBuilderExtensions")
|
||||||
.WithModifiers(Modifiers(SyntaxKind.PublicKeyword, SyntaxKind.StaticKeyword, SyntaxKind.PartialKeyword))
|
.WithModifiers(Modifiers(SyntaxKind.PublicKeyword, SyntaxKind.StaticKeyword, SyntaxKind.PartialKeyword))
|
||||||
.AddMembers([.. targetters.Values, .. extensions])
|
.AddMembers([.. targetters.Values, .. extensions]);
|
||||||
.DecorateType(1);
|
|
||||||
|
|
||||||
NamespaceDeclarationSyntax namespaceDeclaration = SyntaxFactory.NamespaceDeclaration(SyntaxFactory.ParseName("Telegrator"))
|
NamespaceDeclarationSyntax namespaceDeclaration = SyntaxFactory.NamespaceDeclaration(SyntaxFactory.ParseName("Telegrator"))
|
||||||
.WithMembers([extensionsClass])
|
.WithLeadingTrivia(SyntaxFactory.ParseLeadingTrivia("#pragma warning disable CS1591"))
|
||||||
.Decorate();
|
.WithMembers([extensionsClass]);
|
||||||
|
|
||||||
CompilationUnitSyntax compilationUnit = SyntaxFactory.CompilationUnit()
|
CompilationUnitSyntax compilationUnit = SyntaxFactory.CompilationUnit()
|
||||||
.WithUsings([.. usings])
|
.WithUsings([.. usings])
|
||||||
.WithMembers([namespaceDeclaration]);
|
.WithMembers([namespaceDeclaration])
|
||||||
|
.NormalizeWhitespace();
|
||||||
|
|
||||||
context.AddSource("GeneratedHandlerBuilderExtensions.cs", compilationUnit.ToFullString());
|
context.AddSource("GeneratedHandlerBuilderExtensions.cs", compilationUnit.ToFullString());
|
||||||
}
|
}
|
||||||
@@ -175,7 +180,7 @@ public class ImplicitHandlerBuilderExtensionsGenerator : IIncrementalGenerator
|
|||||||
if (targetterMethod.ExpressionBody != null)
|
if (targetterMethod.ExpressionBody != null)
|
||||||
method = method.WithExpressionBody(targetterMethod.ExpressionBody).WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken));
|
method = method.WithExpressionBody(targetterMethod.ExpressionBody).WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken));
|
||||||
|
|
||||||
return method.DecorateMember(2);
|
return method;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MethodDeclarationSyntax GeneratedExtensionsMethod(ClassDeclarationSyntax classDeclaration, ParameterListSyntax methodParameters, ArgumentListSyntax invokerArguments, MethodDeclarationSyntax targetterMethod)
|
private static MethodDeclarationSyntax GeneratedExtensionsMethod(ClassDeclarationSyntax classDeclaration, ParameterListSyntax methodParameters, ArgumentListSyntax invokerArguments, MethodDeclarationSyntax targetterMethod)
|
||||||
@@ -204,11 +209,10 @@ public class ImplicitHandlerBuilderExtensionsGenerator : IIncrementalGenerator
|
|||||||
|
|
||||||
MethodDeclarationSyntax method = SyntaxFactory.MethodDeclaration(returnType, identifier)
|
MethodDeclarationSyntax method = SyntaxFactory.MethodDeclaration(returnType, identifier)
|
||||||
.WithParameterList(parameters)
|
.WithParameterList(parameters)
|
||||||
.WithBody(body.DecorateBlock(2))
|
.WithBody(body)
|
||||||
.WithTypeParameterList(typeParameters)
|
.WithTypeParameterList(typeParameters)
|
||||||
.WithModifiers(Modifiers(SyntaxKind.PublicKeyword, SyntaxKind.StaticKeyword))
|
.WithModifiers(Modifiers(SyntaxKind.PublicKeyword, SyntaxKind.StaticKeyword))
|
||||||
.WithConstraintClauses([typeParameterConstraint])
|
.WithConstraintClauses([typeParameterConstraint])
|
||||||
.DecorateMember(2)
|
|
||||||
.WithLeadingTrivia(xmlDoc);
|
.WithLeadingTrivia(xmlDoc);
|
||||||
|
|
||||||
return method;
|
return method;
|
||||||
@@ -230,7 +234,7 @@ public class ImplicitHandlerBuilderExtensionsGenerator : IIncrementalGenerator
|
|||||||
private static IEnumerable<ConstructorDeclarationSyntax> GetConstructors(ClassDeclarationSyntax classDeclaration)
|
private static IEnumerable<ConstructorDeclarationSyntax> GetConstructors(ClassDeclarationSyntax classDeclaration)
|
||||||
=> classDeclaration.Members.OfType<ConstructorDeclarationSyntax>().Where(ctor => ctor.Modifiers.HasModifiers("public"));
|
=> classDeclaration.Members.OfType<ConstructorDeclarationSyntax>().Where(ctor => ctor.Modifiers.HasModifiers("public"));
|
||||||
|
|
||||||
private static MethodDeclarationSyntax FindTargetterMethod(Dictionary<string, MethodDeclarationSyntax> targeters, ClassDeclarationSyntax classDeclaration)
|
private static MethodDeclarationSyntax? FindTargetterMethod(Dictionary<string, MethodDeclarationSyntax> targeters, ClassDeclarationSyntax classDeclaration)
|
||||||
{
|
{
|
||||||
if (targeters.TryGetValue(classDeclaration.Identifier.ValueText, out MethodDeclarationSyntax targeter))
|
if (targeters.TryGetValue(classDeclaration.Identifier.ValueText, out MethodDeclarationSyntax targeter))
|
||||||
return targeter;
|
return targeter;
|
||||||
@@ -238,7 +242,7 @@ public class ImplicitHandlerBuilderExtensionsGenerator : IIncrementalGenerator
|
|||||||
if (classDeclaration.BaseList != null && targeters.TryGetValue(classDeclaration.BaseList.Types.ElementAt(0).Type.ToString(), out targeter))
|
if (classDeclaration.BaseList != null && targeters.TryGetValue(classDeclaration.BaseList.Types.ElementAt(0).Type.ToString(), out targeter))
|
||||||
return targeter;
|
return targeter;
|
||||||
|
|
||||||
throw new TargteterNotFoundException();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SyntaxTriviaList BuildExtensionXmlDocTrivia(ClassDeclarationSyntax classDeclaration, ParameterListSyntax methodParameters)
|
private static SyntaxTriviaList BuildExtensionXmlDocTrivia(ClassDeclarationSyntax classDeclaration, ParameterListSyntax methodParameters)
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
using Microsoft.CodeAnalysis;
|
|
||||||
using Microsoft.CodeAnalysis.CSharp;
|
|
||||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
||||||
|
|
||||||
namespace Telegrator.RoslynGenerators.RoslynExtensions
|
|
||||||
{
|
|
||||||
public static class MemberDeclarationSyntaxExtensions
|
|
||||||
{
|
|
||||||
private static SyntaxTrivia TabulationTrivia => SyntaxFactory.SyntaxTrivia(SyntaxKind.WhitespaceTrivia, "\t");
|
|
||||||
private static SyntaxTrivia WhitespaceTrivia => SyntaxFactory.SyntaxTrivia(SyntaxKind.WhitespaceTrivia, " ");
|
|
||||||
private static SyntaxTrivia NewLineTrivia => SyntaxFactory.SyntaxTrivia(SyntaxKind.EndOfLineTrivia, "\n");
|
|
||||||
|
|
||||||
public static SyntaxTokenList Decorate(this SyntaxTokenList tokens)
|
|
||||||
=> new SyntaxTokenList(tokens.Select(token => token.WithoutTrivia().WithTrailingTrivia(WhitespaceTrivia)).ToArray());
|
|
||||||
|
|
||||||
public static BlockSyntax DecorateBlock(this BlockSyntax block, int times) => block
|
|
||||||
.WithStatements([.. block.Statements.Select(statement => statement.DecorateStatememnt(times + 1))])
|
|
||||||
.WithOpenBraceToken(SyntaxFactory.Token(SyntaxKind.OpenBraceToken).WithLeadingTrivia(WhitespaceTrivia).WithTrailingTrivia(NewLineTrivia))
|
|
||||||
.WithCloseBraceToken(SyntaxFactory.Token(SyntaxKind.CloseBraceToken).WithLeadingTrivia(TabulationTrivia.Repeat(times)).WithTrailingTrivia(NewLineTrivia));
|
|
||||||
|
|
||||||
public static T DecorateStatememnt<T>(this T statememnt, int times) where T : StatementSyntax => statememnt
|
|
||||||
.WithoutTrivia().WithLeadingTrivia(TabulationTrivia.Repeat(times)).WithTrailingTrivia(NewLineTrivia);
|
|
||||||
|
|
||||||
public static T DecorateMember<T>(this T typeDeclaration, int times) where T : MemberDeclarationSyntax => typeDeclaration
|
|
||||||
.WithoutTrivia().WithLeadingTrivia(TabulationTrivia.Repeat(times)).WithTrailingTrivia(NewLineTrivia);
|
|
||||||
|
|
||||||
public static NamespaceDeclarationSyntax Decorate(this NamespaceDeclarationSyntax namespaceDeclaration) => namespaceDeclaration
|
|
||||||
.WithName(namespaceDeclaration.Name.WithoutTrivia().WithLeadingTrivia(WhitespaceTrivia))
|
|
||||||
.WithOpenBraceToken(SyntaxFactory.Token(SyntaxKind.OpenBraceToken).WithLeadingTrivia(NewLineTrivia).WithTrailingTrivia(NewLineTrivia))
|
|
||||||
.WithCloseBraceToken(SyntaxFactory.Token(SyntaxKind.CloseBraceToken));
|
|
||||||
|
|
||||||
public static T DecorateType<T>(this T typeDeclaration, int times = 1) where T : TypeDeclarationSyntax => (T)typeDeclaration
|
|
||||||
.WithoutTrivia().WithLeadingTrivia(TabulationTrivia.Repeat(times))
|
|
||||||
.WithIdentifier(typeDeclaration.Identifier.WithoutTrivia().WithLeadingTrivia(WhitespaceTrivia).WithTrailingTrivia(NewLineTrivia))
|
|
||||||
.WithOpenBraceToken(SyntaxFactory.Token(SyntaxKind.OpenBraceToken).WithLeadingTrivia(TabulationTrivia.Repeat(times)).WithTrailingTrivia(NewLineTrivia))
|
|
||||||
.WithCloseBraceToken(SyntaxFactory.Token(SyntaxKind.CloseBraceToken).WithLeadingTrivia(TabulationTrivia.Repeat(times)).WithTrailingTrivia(NewLineTrivia));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+64
-64
@@ -47,7 +47,7 @@ This guide will walk you through the core concepts and advanced features of **Te
|
|||||||
**Telegrator** is distributed as a NuGet package. You can install it using the .NET CLI, the NuGet Package Manager Console, or by managing NuGet packages in Visual Studio.
|
**Telegrator** is distributed as a NuGet package. You can install it using the .NET CLI, the NuGet Package Manager Console, or by managing NuGet packages in Visual Studio.
|
||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
- .NET >= 5.0 `or` .NET Core >= 2.0 `or` Framework >= 4.6.1 (.NET Standard 2.0 compatible)
|
- .NET >= 5.0 `or` .NET Core >= 2.0 `or` Framework >= 4.6.1 (.NET Standard 2.1 compatible)
|
||||||
- A Telegram Bot Token from [@BotFather](https://t.me/BotFather).
|
- A Telegram Bot Token from [@BotFather](https://t.me/BotFather).
|
||||||
|
|
||||||
### .NET CLI
|
### .NET CLI
|
||||||
@@ -61,7 +61,7 @@ Install-Package Telegrator
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Hosting Integrations
|
### Hosting Integrations
|
||||||
- .NET Core >= 8.0
|
- .NET Core >= 10.0
|
||||||
- `Telegrator.Hosting`: For console/background services
|
- `Telegrator.Hosting`: For console/background services
|
||||||
- `Telegrator.Hosting.Web`: For ASP.NET Core/Webhook
|
- `Telegrator.Hosting.Web`: For ASP.NET Core/Webhook
|
||||||
|
|
||||||
@@ -325,7 +325,7 @@ builder.Handlers.AddMethod<CallbackQuery>(Option1Handler);
|
|||||||
```csharp
|
```csharp
|
||||||
public enum UserState
|
public enum UserState
|
||||||
{
|
{
|
||||||
Start = SpecialState.NoState,
|
Start,
|
||||||
WaitingForName,
|
WaitingForName,
|
||||||
WaitingForAge
|
WaitingForAge
|
||||||
}
|
}
|
||||||
@@ -333,39 +333,40 @@ public enum UserState
|
|||||||
// Start conversation
|
// Start conversation
|
||||||
[CommandHandler]
|
[CommandHandler]
|
||||||
[CommandAlias("register")]
|
[CommandAlias("register")]
|
||||||
[EnumState<UserState>(UserState.Start)]
|
[State<UserState>(UserState.Start)]
|
||||||
private static async Task<Result> StartRegistration(IHandlerContainer<Message> container, CancellationToken cancellationToken)
|
private static async Task<Result> StartRegistration(IHandlerContainer<Message> container, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
container.ForwardEnumState<UserState>();
|
StateStorage.GetStateMachine<UserState>().BySenderId().Advance();
|
||||||
await container.Reply("Please enter your name:", cancellationToken: cancellationToken);
|
await container.Reply("Please enter your name:", cancellationToken: cancellationToken);
|
||||||
return Ok;
|
return Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle name input
|
// Handle name input
|
||||||
[MessageHandler]
|
[MessageHandler]
|
||||||
[EnumState<UserState>(UserState.WaitingForName)]
|
[State<UserState>(UserState.WaitingForName)]
|
||||||
private static async Task<Result> HandleName(IHandlerContainer<Message> container, CancellationToken cancellationToken)
|
private static async Task<Result> HandleName(IHandlerContainer<Message> container, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var name = container.Input.Text;
|
var name = container.Input.Text;
|
||||||
container.ForwardEnumState<UserState>();
|
StateStorage.GetStateMachine<UserState>().BySenderId().Advance();
|
||||||
await container.Reply($"Hello {name}! Please enter your age:", cancellationToken: cancellationToken);
|
await container.Reply($"Hello {name}! Please enter your age:", cancellationToken: cancellationToken);
|
||||||
return Ok;
|
return Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle age input
|
// Handle age input
|
||||||
[MessageHandler]
|
[MessageHandler]
|
||||||
[EnumState<UserState>(UserState.WaitingForAge)]
|
[State<UserState>(UserState.WaitingForAge)]
|
||||||
private static async Task<Result> HandleAge(IHandlerContainer<Message> container, CancellationToken cancellationToken)
|
private static async Task<Result> HandleAge(IHandlerContainer<Message> container, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (int.TryParse(container.Input.Text, out int age))
|
if (int.TryParse(container.Input.Text, out int age))
|
||||||
{
|
{
|
||||||
container.DeleteEnumState<UserState>();
|
StateStorage.GetStateMachine<UserState>().BySenderId().Reset();
|
||||||
await container.Reply($"Registration complete! Name: {name}, Age: {age}", cancellationToken: cancellationToken);
|
await container.Reply($"Registration complete! Name: {name}, Age: {age}", cancellationToken: cancellationToken);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await container.Reply("Please enter a valid age (number):", cancellationToken: cancellationToken);
|
await container.Reply("Please enter a valid age (number):", cancellationToken: cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok;
|
return Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -497,50 +498,43 @@ public class RestrictedHandler : MessageHandler
|
|||||||
|
|
||||||
### 3.3. State Management
|
### 3.3. State Management
|
||||||
|
|
||||||
Telegrator provides built-in state management for multi-step conversations (wizards, forms, quizzes) without a database.
|
Telegrator provides built-in state management for multi-step conversations (wizards, forms, quizzes) with or without a database.
|
||||||
|
|
||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
> Each type of `StateKeeper`'s (EnumStateKeeper, NumericStateKeeper) is shared between **EVERY** handler in project.
|
> Each type of `StateKeeper`'s keys and states are shared between **EVERY** handler in project.
|
||||||
|
|
||||||
**Types of State:**
|
|
||||||
- **NumericState**: Integer-based steps
|
|
||||||
- **StringState**: Named steps
|
|
||||||
- **EnumState**: Enum-based scenarios
|
|
||||||
|
|
||||||
**How to Use:**
|
**How to Use:**
|
||||||
1. Define your state (enum/int/string)
|
1. Define your state (enum/int/string)
|
||||||
2. Use a state filter attribute on your handler:
|
2. Use a state filter attribute on your handler:
|
||||||
- `[EnumState<MyEnum>(MyEnum.Step1)]`
|
- `[State<MyEnum>(MyEnum.Step1)]`
|
||||||
- `[NumericState(1)]`
|
|
||||||
- `[StringState("waiting_input")]`
|
|
||||||
3. Change state inside the handler using extension methods:
|
3. Change state inside the handler using extension methods:
|
||||||
- `container.ForwardEnumState<MyEnum>()`
|
- `StateStorage.GetStateMachine<MyEnum>().BySenderId().Current()`
|
||||||
- `container.ForwardNumericState()`
|
- `StateStorage.GetStateMachine<MyEnum>().BySenderId().Advance()`
|
||||||
- `container.ForwardStringState()`
|
- `StateStorage.GetStateMachine<MyEnum>().BySenderId().Retreat()`
|
||||||
- `container.DeleteEnumState<MyEnum>()`
|
- `StateStorage.GetStateMachine<MyEnum>().BySenderId().Reset()`
|
||||||
|
|
||||||
**Example:**
|
**Example:**
|
||||||
```csharp
|
```csharp
|
||||||
public enum QuizState
|
public enum QuizState
|
||||||
{
|
{
|
||||||
Start = SpecialState.NoState, Q1, Q2
|
Start, Q1, Q2
|
||||||
}
|
}
|
||||||
|
|
||||||
[CommandHandler]
|
[CommandHandler]
|
||||||
[CommandAlias("quiz")]
|
[CommandAlias("quiz")]
|
||||||
[EnumState<QuizState>(QuizState.Start)]
|
[State<QuizState>(QuizState.Start)]
|
||||||
public class StartQuizHandler : CommandHandler
|
public class StartQuizHandler : CommandHandler
|
||||||
{
|
{
|
||||||
public override async Task<Result> Execute(IHandlerContainer<Message> container, CancellationToken cancellation)
|
public override async Task<Result> Execute(IHandlerContainer<Message> container, CancellationToken cancellation)
|
||||||
{
|
{
|
||||||
container.ForwardEnumState<QuizState>();
|
StateStorage.GetStateMachine<QuizState>().BySenderId().Advance();
|
||||||
await Reply("Quiz started! Question 1: What is the capital of France?");
|
await Reply("Quiz started! Question 1: What is the capital of France?");
|
||||||
return Ok;
|
return Ok;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[MessageHandler]
|
[MessageHandler]
|
||||||
[EnumState<QuizState>(QuizState.Q1)]
|
[State<QuizState>(QuizState.Q1)]
|
||||||
public class Q1Handler : MessageHandler
|
public class Q1Handler : MessageHandler
|
||||||
{
|
{
|
||||||
public override async Task<Result> Execute(IHandlerContainer<Message> container, CancellationToken cancellation)
|
public override async Task<Result> Execute(IHandlerContainer<Message> container, CancellationToken cancellation)
|
||||||
@@ -550,7 +544,7 @@ public class Q1Handler : MessageHandler
|
|||||||
else
|
else
|
||||||
await Reply("Incorrect. The answer is Paris.");
|
await Reply("Incorrect. The answer is Paris.");
|
||||||
|
|
||||||
container.ForwardEnumState<QuizState>();
|
StateStorage.GetStateMachine<QuizState>().BySenderId().Advance();
|
||||||
await Reply("Question 2: What is 2 + 2?");
|
await Reply("Question 2: What is 2 + 2?");
|
||||||
return Ok;
|
return Ok;
|
||||||
}
|
}
|
||||||
@@ -559,8 +553,8 @@ public class Q1Handler : MessageHandler
|
|||||||
|
|
||||||
> **How is it working?**
|
> **How is it working?**
|
||||||
> 1. **Enum State Definition**: `QuizState` enum defines the conversation flow with `Start = SpecialState.NoState` indicating no initial state.
|
> 1. **Enum State Definition**: `QuizState` enum defines the conversation flow with `Start = SpecialState.NoState` indicating no initial state.
|
||||||
> 2. **State Filter**: `[EnumState<QuizState>(QuizState.Start)]` ensures the handler only runs when the user is in the "Start" state.
|
> 2. **State Filter**: `[State<QuizState>(QuizState.Start)]` ensures the handler only runs when the user is in the "Start" state.
|
||||||
> 3. **State Transition**: `container.ForwardEnumState<QuizState>()` moves the user to the next state (Q1).
|
> 3. **State Transition**: `StateStorage.GetStateMachine<QuizState>().BySenderId().Advance()` moves the user to the next state (Q1).
|
||||||
> 4. **Next Handler**: The `Q1Handler` will only run when the user is in state `QuizState.Q1`.
|
> 4. **Next Handler**: The `Q1Handler` will only run when the user is in state `QuizState.Q1`.
|
||||||
> 5. **State Management**: Each handler manages its own state transition, creating a clear conversation flow.
|
> 5. **State Management**: Each handler manages its own state transition, creating a clear conversation flow.
|
||||||
|
|
||||||
@@ -1078,7 +1072,7 @@ var host = webHost.Build();
|
|||||||
await host.StartAsync();
|
await host.StartAsync();
|
||||||
```
|
```
|
||||||
|
|
||||||
**Note:** For web hosting, you need to configure both `TelegramBotClientOptions` (for bot token) and `TelegratorWebOptions` (for webhook settings) in your `appsettings.json` file.
|
**Note:** For web hosting, you need to configure both `TelegratorOptions` (for bot token) and `WebhookerOptions` (for webhook settings) in your `appsettings.json` file.
|
||||||
|
|
||||||
> **How is it working?**
|
> **How is it working?**
|
||||||
> 1. **Console Integration**: `TelegratorClient` provides a simple way to create bots in console applications.
|
> 1. **Console Integration**: `TelegratorClient` provides a simple way to create bots in console applications.
|
||||||
@@ -1425,28 +1419,28 @@ public enum UserState
|
|||||||
// Start conversation
|
// Start conversation
|
||||||
[CommandHandler]
|
[CommandHandler]
|
||||||
[CommandAlias("register")]
|
[CommandAlias("register")]
|
||||||
[EnumState<UserState>(UserState.Start)]
|
[State<UserState>(UserState.Start)]
|
||||||
private static async Task<Result> StartRegistration(IHandlerContainer<Message> container, CancellationToken cancellationToken)
|
private static async Task<Result> StartRegistration(IHandlerContainer<Message> container, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
container.ForwardEnumState<UserState>();
|
StateStorage.GetStateMachine<UserState>().BySenderId().Advance();
|
||||||
await container.Reply("Please enter your name:", cancellationToken: cancellationToken);
|
await container.Reply("Please enter your name:", cancellationToken: cancellationToken);
|
||||||
return Ok;
|
return Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle name input
|
// Handle name input
|
||||||
[MessageHandler]
|
[MessageHandler]
|
||||||
[EnumState<UserState>(UserState.WaitingForName)]
|
[State<UserState>(UserState.WaitingForName)]
|
||||||
private static async Task<Result> HandleName(IHandlerContainer<Message> container, CancellationToken cancellationToken)
|
private static async Task<Result> HandleName(IHandlerContainer<Message> container, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var name = container.Input.Text;
|
var name = container.Input.Text;
|
||||||
container.ForwardEnumState<UserState>();
|
StateStorage.GetStateMachine<UserState>().BySenderId().Advance();
|
||||||
await container.Reply($"Hello {name}! Please enter your age:", cancellationToken: cancellationToken);
|
await container.Reply($"Hello {name}! Please enter your age:", cancellationToken: cancellationToken);
|
||||||
return Ok;
|
return Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle age input
|
// Handle age input
|
||||||
[MessageHandler]
|
[MessageHandler]
|
||||||
[EnumState<UserState>(UserState.WaitingForAge)]
|
[State<UserState>(UserState.WaitingForAge)]
|
||||||
private static async Task<Result> HandleAge(IHandlerContainer<Message> container, CancellationToken cancellationToken)
|
private static async Task<Result> HandleAge(IHandlerContainer<Message> container, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (int.TryParse(container.Input.Text, out int age))
|
if (int.TryParse(container.Input.Text, out int age))
|
||||||
@@ -1723,12 +1717,11 @@ dotnet add package Telegrator.Hosting.Web
|
|||||||
**Core Components:**
|
**Core Components:**
|
||||||
- `TelegramBotWebHost` - The main web hosted service for webhook handling
|
- `TelegramBotWebHost` - The main web hosted service for webhook handling
|
||||||
- `TelegramBotWebHostBuilder` - Builder pattern for configuring the web host
|
- `TelegramBotWebHostBuilder` - Builder pattern for configuring the web host
|
||||||
- `TelegramBotWebOptions` - Configuration options for web application settings
|
- `WebhookerOptions` - Configuration options for webhook settings
|
||||||
- `TelegratorWebOptions` - Configuration options for webhook settings
|
|
||||||
|
|
||||||
**Configuration Requirements:**
|
**Configuration Requirements:**
|
||||||
- `TelegramBotClientOptions` must be configured as it contains the bot token
|
- `TelegratorOptions` must be configured as it contains the bot token
|
||||||
- `TelegratorWebOptions` must be configured through external sources (appsettings.json) for webhook settings
|
- `WebhookerOptions` must be configured through external sources (appsettings.json) for webhook settings
|
||||||
|
|
||||||
**Basic Example:**
|
**Basic Example:**
|
||||||
```csharp
|
```csharp
|
||||||
@@ -1750,11 +1743,11 @@ await host.StartAsync();
|
|||||||
**Configuration via appsettings.json:**
|
**Configuration via appsettings.json:**
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"TelegramBotClientOptions": {
|
"TelegratorOptions": {
|
||||||
"Token": "YOUR_BOT_TOKEN"
|
"Token": "YOUR_BOT_TOKEN"
|
||||||
},
|
},
|
||||||
|
|
||||||
"TelegratorWebOptions": {
|
"WebhookerOptions": {
|
||||||
"WebhookUri": "https://your-domain.com/webhook",
|
"WebhookUri": "https://your-domain.com/webhook",
|
||||||
"SecretToken": "your-secret-token",
|
"SecretToken": "your-secret-token",
|
||||||
"MaxConnections": 40,
|
"MaxConnections": 40,
|
||||||
@@ -1790,7 +1783,7 @@ The bot token must be configured either in `appsettings.json` or through environ
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"TelegramBotClientOptions": {
|
"TelegratorOptions": {
|
||||||
"Token": "YOUR_BOT_TOKEN"
|
"Token": "YOUR_BOT_TOKEN"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1805,7 +1798,7 @@ export TelegramBotClientOptions__Token="YOUR_BOT_TOKEN"
|
|||||||
**Advanced Configuration:**
|
**Advanced Configuration:**
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"TelegramBotClientOptions": {
|
"TelegratorOptions": {
|
||||||
"Token": "YOUR_BOT_TOKEN",
|
"Token": "YOUR_BOT_TOKEN",
|
||||||
"BaseUrl": "https://api.telegram.org"
|
"BaseUrl": "https://api.telegram.org"
|
||||||
},
|
},
|
||||||
@@ -2158,10 +2151,11 @@ await host.StartAsync();
|
|||||||
**Configuration (appsettings.json):**
|
**Configuration (appsettings.json):**
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"TelegramBotClientOptions": {
|
"TelegratorOptions": {
|
||||||
"Token": "YOUR_BOT_TOKEN"
|
"Token": "YOUR_BOT_TOKEN"
|
||||||
},
|
},
|
||||||
"TelegratorWebOptions": {
|
|
||||||
|
"WebhookerOptions": {
|
||||||
"WebhookUri": "https://your-domain.com/webhook",
|
"WebhookUri": "https://your-domain.com/webhook",
|
||||||
"SecretToken": "your-secret-token",
|
"SecretToken": "your-secret-token",
|
||||||
"MaxConnections": 40,
|
"MaxConnections": 40,
|
||||||
@@ -2283,12 +2277,12 @@ public class StartWizardHandler : CommandHandler
|
|||||||
|
|
||||||
### 7.5. Logging System
|
### 7.5. Logging System
|
||||||
|
|
||||||
Telegrator provides a centralized logging system called "Alligator" that allows integration with various logging frameworks while maintaining zero dependencies in the core library.
|
Telegrator provides a centralized logging system called "TelegratorLogging" that allows integration with various logging frameworks while maintaining zero dependencies in the core library.
|
||||||
|
|
||||||
#### Overview
|
#### Overview
|
||||||
|
|
||||||
The logging system consists of:
|
The logging system consists of:
|
||||||
- **Alligator** - Centralized static logging system
|
- **TelegratorLogging** - Centralized static logging system
|
||||||
- **ITelegratorLogger** - Core logging interface
|
- **ITelegratorLogger** - Core logging interface
|
||||||
- **NullLogger** - No-op logger
|
- **NullLogger** - No-op logger
|
||||||
- **ConsoleLogger** - Simple console output
|
- **ConsoleLogger** - Simple console output
|
||||||
@@ -2301,11 +2295,11 @@ The logging system consists of:
|
|||||||
using Telegrator.Logging;
|
using Telegrator.Logging;
|
||||||
|
|
||||||
// Add console adapter
|
// Add console adapter
|
||||||
Alligator.AddAdapter(new ConsoleLoggerAdapter(LogLevel.Debug, includeTimestamp: true));
|
TelegratorLogging.AddAdapter(new ConsoleLoggerAdapter(LogLevel.Debug, includeTimestamp: true));
|
||||||
|
|
||||||
// Use logging
|
// Use logging
|
||||||
Alligator.LogInformation("Bot started");
|
TelegratorLogging.LogInformation("Bot started");
|
||||||
Alligator.LogError("Something went wrong", exception);
|
TelegratorLogging.LogError("Something went wrong", exception);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Custom Logger Adapter:**
|
**Custom Logger Adapter:**
|
||||||
@@ -2322,7 +2316,7 @@ public class CustomLogger : ITelegratorLogger
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add custom adapter
|
// Add custom adapter
|
||||||
Alligator.AddAdapter(new CustomLogger());
|
TelegratorLogging.AddAdapter(new CustomLogger());
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Hosting Integration
|
#### Hosting Integration
|
||||||
@@ -2340,7 +2334,7 @@ var loggerFactory = LoggerFactory.Create(builder =>
|
|||||||
// Add Microsoft.Extensions.Logging adapter
|
// Add Microsoft.Extensions.Logging adapter
|
||||||
ILogger<Program> logger = loggerFactory.CreateLogger<Program>();
|
ILogger<Program> logger = loggerFactory.CreateLogger<Program>();
|
||||||
MicrosoftLoggingAdapter adapter = new MicrosoftLoggingAdapter(logger);
|
MicrosoftLoggingAdapter adapter = new MicrosoftLoggingAdapter(logger);
|
||||||
Alligator.AddAdapter(adapter);
|
TelegratorLogging.AddAdapter(adapter);
|
||||||
|
|
||||||
var bot = new TelegratorClient("<BOT_TOKEN>");
|
var bot = new TelegratorClient("<BOT_TOKEN>");
|
||||||
```
|
```
|
||||||
@@ -2359,14 +2353,14 @@ All logging methods support simple message logging:
|
|||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
// In your handlers or aspects
|
// In your handlers or aspects
|
||||||
Alligator.LogInformation("Handler executed");
|
TelegratorLogging.LogInformation("Handler executed");
|
||||||
Alligator.LogError("Something went wrong", exception);
|
TelegratorLogging.LogError("Something went wrong", exception);
|
||||||
Alligator.LogWarning("User exceeded rate limit");
|
TelegratorLogging.LogWarning("User exceeded rate limit");
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Performance Considerations
|
#### Performance Considerations
|
||||||
|
|
||||||
- **Alligator** has minimal overhead with thread-safe adapter management
|
- **TelegratorLogging** has minimal overhead with thread-safe adapter management
|
||||||
- **NullLogger** has zero overhead
|
- **NullLogger** has zero overhead
|
||||||
- **ConsoleLogger** is lightweight for development
|
- **ConsoleLogger** is lightweight for development
|
||||||
- **MicrosoftLoggingAdapter** delegates to the underlying framework
|
- **MicrosoftLoggingAdapter** delegates to the underlying framework
|
||||||
@@ -2576,11 +2570,11 @@ For detailed information about the logging system, see [section 7.5 - Logging Sy
|
|||||||
using Telegrator.Logging;
|
using Telegrator.Logging;
|
||||||
|
|
||||||
// Add console adapter for debugging
|
// Add console adapter for debugging
|
||||||
Alligator.AddConsoleAdapter(LogLevel.Debug, includeTimestamp: true);
|
TelegratorLogging.AddConsoleAdapter(LogLevel.Debug, includeTimestamp: true);
|
||||||
|
|
||||||
// Use logging
|
// Use logging
|
||||||
Alligator.LogInformation("Bot started");
|
TelegratorLogging.LogInformation("Bot started");
|
||||||
Alligator.LogError("Something went wrong", exception);
|
TelegratorLogging.LogError("Something went wrong", exception);
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Common Debugging Steps
|
#### Common Debugging Steps
|
||||||
@@ -2599,9 +2593,9 @@ Alligator.LogError("Something went wrong", exception);
|
|||||||
#### Simple Logging
|
#### Simple Logging
|
||||||
```csharp
|
```csharp
|
||||||
// In your handlers or aspects
|
// In your handlers or aspects
|
||||||
Alligator.LogInformation("Handler executed");
|
TelegratorLogging.LogInformation("Handler executed");
|
||||||
Alligator.LogError("Something went wrong", exception);
|
TelegratorLogging.LogError("Something went wrong", exception);
|
||||||
Alligator.LogWarning("User exceeded rate limit");
|
TelegratorLogging.LogWarning("User exceeded rate limit");
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -2617,4 +2611,10 @@ Alligator.LogWarning("User exceeded rate limit");
|
|||||||
|
|
||||||
> **Feel free to contribute, ask questions, or open issues!**
|
> **Feel free to contribute, ask questions, or open issues!**
|
||||||
|
|
||||||
Сишарпилло Крокодилло
|
В главных ролях :
|
||||||
|
> Сишарпилло Крокодилло,
|
||||||
|
> Дыкий Сишарп,
|
||||||
|
> Шарпенко Михаил Дотнетович
|
||||||
|
|
||||||
|
Кастинг и Тестирование :
|
||||||
|
> не проводилось
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<doc>
|
||||||
|
<assembly>
|
||||||
|
<name>Telegartor.RedisStateStorage</name>
|
||||||
|
</assembly>
|
||||||
|
<members>
|
||||||
|
<member name="T:Telegrator.States.RedisStateStorage">
|
||||||
|
<summary>
|
||||||
|
Provides a Redis-based implementation of the <see cref="T:Telegrator.Core.States.IStateStorage"/> interface.
|
||||||
|
Serializes state objects to JSON format before storing them in the Redis database.
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="M:Telegrator.States.RedisStateStorage.#ctor(StackExchange.Redis.IConnectionMultiplexer)">
|
||||||
|
<summary>
|
||||||
|
Provides a Redis-based implementation of the <see cref="T:Telegrator.Core.States.IStateStorage"/> interface.
|
||||||
|
Serializes state objects to JSON format before storing them in the Redis database.
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="M:Telegrator.States.RedisStateStorage.SetAsync``1(System.String,``0,System.Threading.CancellationToken)">
|
||||||
|
<inheritdoc/>
|
||||||
|
</member>
|
||||||
|
<member name="M:Telegrator.States.RedisStateStorage.GetAsync``1(System.String,System.Threading.CancellationToken)">
|
||||||
|
<inheritdoc/>
|
||||||
|
</member>
|
||||||
|
<member name="M:Telegrator.States.RedisStateStorage.DeleteAsync(System.String,System.Threading.CancellationToken)">
|
||||||
|
<inheritdoc/>
|
||||||
|
</member>
|
||||||
|
</members>
|
||||||
|
</doc>
|
||||||
@@ -28,6 +28,9 @@
|
|||||||
This application's logger
|
This application's logger
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="P:Telegrator.Hosting.Web.TelegramBotWebHost.Properties">
|
||||||
|
<inheritdoc/>
|
||||||
|
</member>
|
||||||
<member name="M:Telegrator.Hosting.Web.TelegramBotWebHost.#ctor(Microsoft.AspNetCore.Builder.WebApplicationBuilder)">
|
<member name="M:Telegrator.Hosting.Web.TelegramBotWebHost.#ctor(Microsoft.AspNetCore.Builder.WebApplicationBuilder)">
|
||||||
<summary>
|
<summary>
|
||||||
Initializes a new instance of the <see cref="T:Microsoft.AspNetCore.Builder.WebApplicationBuilder"/> class.
|
Initializes a new instance of the <see cref="T:Microsoft.AspNetCore.Builder.WebApplicationBuilder"/> class.
|
||||||
@@ -81,9 +84,7 @@
|
|||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="T:Telegrator.Hosting.Web.TelegramBotWebHostBuilder">
|
<member name="T:Telegrator.Hosting.Web.TelegramBotWebHostBuilder">
|
||||||
<summary>
|
<inheritdoc/>
|
||||||
Represents a web hosted telegram bots and services builder that helps manage configuration, logging, lifetime, and more.
|
|
||||||
</summary>
|
|
||||||
</member>
|
</member>
|
||||||
<member name="P:Telegrator.Hosting.Web.TelegramBotWebHostBuilder.Handlers">
|
<member name="P:Telegrator.Hosting.Web.TelegramBotWebHostBuilder.Handlers">
|
||||||
<inheritdoc/>
|
<inheritdoc/>
|
||||||
@@ -100,20 +101,24 @@
|
|||||||
<member name="P:Telegrator.Hosting.Web.TelegramBotWebHostBuilder.Environment">
|
<member name="P:Telegrator.Hosting.Web.TelegramBotWebHostBuilder.Environment">
|
||||||
<inheritdoc/>
|
<inheritdoc/>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Telegrator.Hosting.Web.TelegramBotWebHostBuilder.#ctor(Microsoft.AspNetCore.Builder.WebApplicationBuilder,Microsoft.AspNetCore.Builder.WebApplicationOptions)">
|
<member name="P:Telegrator.Hosting.Web.TelegramBotWebHostBuilder.Properties">
|
||||||
|
<inheritdoc/>
|
||||||
|
</member>
|
||||||
|
<member name="P:Telegrator.Hosting.Web.TelegramBotWebHostBuilder.Metrics">
|
||||||
|
<inheritdoc/>
|
||||||
|
</member>
|
||||||
|
<member name="M:Telegrator.Hosting.Web.TelegramBotWebHostBuilder.#ctor(Microsoft.AspNetCore.Builder.WebApplicationBuilder)">
|
||||||
<summary>
|
<summary>
|
||||||
Initializes a new instance of the <see cref="T:Telegrator.Hosting.Web.TelegramBotWebHostBuilder"/> class.
|
Initializes a new instance of the <see cref="T:Telegrator.Hosting.Web.TelegramBotWebHostBuilder"/> class.
|
||||||
</summary>
|
</summary>
|
||||||
<param name="webApplicationBuilder"></param>
|
<param name="webApplicationBuilder"></param>
|
||||||
<param name="settings"></param>
|
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Telegrator.Hosting.Web.TelegramBotWebHostBuilder.#ctor(Microsoft.AspNetCore.Builder.WebApplicationBuilder,Telegrator.Core.IHandlersCollection,Microsoft.AspNetCore.Builder.WebApplicationOptions)">
|
<member name="M:Telegrator.Hosting.Web.TelegramBotWebHostBuilder.#ctor(Microsoft.AspNetCore.Builder.WebApplicationBuilder,Telegrator.Core.IHandlersCollection)">
|
||||||
<summary>
|
<summary>
|
||||||
Initializes a new instance of the <see cref="T:Telegrator.Hosting.Web.TelegramBotWebHostBuilder"/> class.
|
Initializes a new instance of the <see cref="T:Telegrator.Hosting.Web.TelegramBotWebHostBuilder"/> class.
|
||||||
</summary>
|
</summary>
|
||||||
<param name="webApplicationBuilder"></param>
|
<param name="webApplicationBuilder"></param>
|
||||||
<param name="handlers"></param>
|
<param name="handlers"></param>
|
||||||
<param name="settings"></param>
|
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Telegrator.Hosting.Web.TelegramBotWebHostBuilder.Build">
|
<member name="M:Telegrator.Hosting.Web.TelegramBotWebHostBuilder.Build">
|
||||||
<summary>
|
<summary>
|
||||||
@@ -121,6 +126,9 @@
|
|||||||
</summary>
|
</summary>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Telegrator.Hosting.Web.TelegramBotWebHostBuilder.ConfigureContainer``1(Microsoft.Extensions.DependencyInjection.IServiceProviderFactory{``0},System.Action{``0})">
|
||||||
|
<inheritdoc/>
|
||||||
|
</member>
|
||||||
<member name="T:Telegrator.Hosting.Web.WebhookerOptions">
|
<member name="T:Telegrator.Hosting.Web.WebhookerOptions">
|
||||||
<summary>
|
<summary>
|
||||||
Configuration options for Telegram bot behavior and execution settings.
|
Configuration options for Telegram bot behavior and execution settings.
|
||||||
@@ -155,11 +163,10 @@
|
|||||||
Service for receiving updates for Hosted telegram bots via Webhooks
|
Service for receiving updates for Hosted telegram bots via Webhooks
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Telegrator.Mediation.HostedUpdateWebhooker.#ctor(Microsoft.AspNetCore.Routing.IEndpointRouteBuilder,Telegram.Bot.ITelegramBotClient,Telegrator.Core.IUpdateRouter,Microsoft.Extensions.Options.IOptions{Telegrator.Hosting.Web.WebhookerOptions})">
|
<member name="M:Telegrator.Mediation.HostedUpdateWebhooker.#ctor(Telegram.Bot.ITelegramBotClient,Telegrator.Core.IUpdateRouter,Microsoft.Extensions.Options.IOptions{Telegrator.Hosting.Web.WebhookerOptions})">
|
||||||
<summary>
|
<summary>
|
||||||
Initiallizes new instance of <see cref="T:Telegrator.Mediation.HostedUpdateWebhooker"/>
|
Initiallizes new instance of <see cref="T:Telegrator.Mediation.HostedUpdateWebhooker"/>
|
||||||
</summary>
|
</summary>
|
||||||
<param name="botHost"></param>
|
|
||||||
<param name="botClient"></param>
|
<param name="botClient"></param>
|
||||||
<param name="updateRouter"></param>
|
<param name="updateRouter"></param>
|
||||||
<param name="options"></param>
|
<param name="options"></param>
|
||||||
@@ -171,6 +178,22 @@
|
|||||||
<member name="M:Telegrator.Mediation.HostedUpdateWebhooker.StopAsync(System.Threading.CancellationToken)">
|
<member name="M:Telegrator.Mediation.HostedUpdateWebhooker.StopAsync(System.Threading.CancellationToken)">
|
||||||
<inheritdoc/>
|
<inheritdoc/>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Telegrator.Mediation.HostedUpdateWebhooker.RemapWebhook(Microsoft.AspNetCore.Routing.IEndpointRouteBuilder,System.String,System.Threading.CancellationToken)">
|
||||||
|
<summary>
|
||||||
|
Allows to remap receiving webhook endpoint and map new route to webhost.
|
||||||
|
</summary>
|
||||||
|
<param name="routeBuilder"></param>
|
||||||
|
<param name="webhookUri"></param>
|
||||||
|
<param name="cancellationToken"></param>
|
||||||
|
<returns></returns>
|
||||||
|
<exception cref="T:System.ArgumentException"></exception>
|
||||||
|
</member>
|
||||||
|
<member name="M:Telegrator.Mediation.HostedUpdateWebhooker.MapWebhook(Microsoft.AspNetCore.Routing.IEndpointRouteBuilder)">
|
||||||
|
<summary>
|
||||||
|
Maps bot webhook to application builder
|
||||||
|
</summary>
|
||||||
|
<param name="routeBuilder"></param>
|
||||||
|
</member>
|
||||||
<member name="T:Telegrator.ServicesCollectionExtensions">
|
<member name="T:Telegrator.ServicesCollectionExtensions">
|
||||||
<summary>
|
<summary>
|
||||||
Contains extensions for <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection"/>
|
Contains extensions for <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection"/>
|
||||||
@@ -185,17 +208,44 @@
|
|||||||
<member name="M:Telegrator.ServicesCollectionExtensions.get_Handlers(Microsoft.AspNetCore.Builder.WebApplicationBuilder)">
|
<member name="M:Telegrator.ServicesCollectionExtensions.get_Handlers(Microsoft.AspNetCore.Builder.WebApplicationBuilder)">
|
||||||
<inheritdoc cref="P:Telegrator.ServicesCollectionExtensions.<G>$41F16C2D39AF52899E745C9C9F42FF83.Handlers"/>
|
<inheritdoc cref="P:Telegrator.ServicesCollectionExtensions.<G>$41F16C2D39AF52899E745C9C9F42FF83.Handlers"/>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Telegrator.ServicesCollectionExtensions.AddTelegratorWeb(Microsoft.Extensions.Hosting.IHostApplicationBuilder,Microsoft.AspNetCore.Builder.WebApplicationOptions,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection)">
|
<member name="M:Telegrator.ServicesCollectionExtensions.AddTelegratorWeb(Telegrator.Hosting.ITelegramBotHostBuilder,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection,System.Action{Telegrator.Hosting.ITelegramBotHostBuilder})">
|
||||||
<summary>
|
<summary>
|
||||||
Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
|
Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Telegrator.ServicesCollectionExtensions.UseTelegratorWeb(Microsoft.AspNetCore.Builder.WebApplication)">
|
<member name="M:Telegrator.ServicesCollectionExtensions.AddTelegratorWeb(Microsoft.AspNetCore.Builder.WebApplicationBuilder,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection,System.Action{Telegrator.Hosting.ITelegramBotHostBuilder})">
|
||||||
|
<summary>
|
||||||
|
Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="M:Telegrator.ServicesCollectionExtensions.AddTelegratorWebInternal(Microsoft.Extensions.DependencyInjection.IServiceCollection,Microsoft.Extensions.Configuration.IConfiguration,System.Collections.Generic.IDictionary{System.Object,System.Object},Telegrator.Core.IHandlersCollection@,Telegrator.TelegratorOptions)">
|
||||||
|
<summary>
|
||||||
|
Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="M:Telegrator.ServicesCollectionExtensions.TryFindWebhooker(System.IServiceProvider,Telegrator.Mediation.HostedUpdateWebhooker@)">
|
||||||
|
<summary>
|
||||||
|
Searchs for <see cref="T:Telegrator.Mediation.HostedUpdateWebhooker"/> hosted service inside hosts services
|
||||||
|
</summary>
|
||||||
|
<param name="services"></param>
|
||||||
|
<param name="webhooker"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:Telegrator.ServicesCollectionExtensions.UseTelegratorWeb``1(``0,System.Boolean)">
|
||||||
<summary>
|
<summary>
|
||||||
Replaces the initialization logic from TelegramBotWebHost constructor.
|
Replaces the initialization logic from TelegramBotWebHost constructor.
|
||||||
Initializes the bot and logs handlers on application startup.
|
Initializes the bot and logs handlers on application startup.
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Telegrator.ServicesCollectionExtensions.RemapWebhook``1(``0,System.String)">
|
||||||
|
<summary>
|
||||||
|
Allows to remap receiving webhook endpoint and map new route to webhost.
|
||||||
|
</summary>
|
||||||
|
<param name="app"></param>
|
||||||
|
<param name="webhookUri"></param>
|
||||||
|
<returns></returns>
|
||||||
|
<exception cref="T:System.ArgumentException"></exception>
|
||||||
|
</member>
|
||||||
<member name="M:Telegrator.ServicesCollectionExtensions.AddTelegramWebhook(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
|
<member name="M:Telegrator.ServicesCollectionExtensions.AddTelegramWebhook(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
|
||||||
<summary>
|
<summary>
|
||||||
Registers <see cref="T:Telegram.Bot.ITelegramBotClient"/> service with <see cref="T:Telegrator.Mediation.HostedUpdateWebhooker"/> to receive updates using webhook
|
Registers <see cref="T:Telegram.Bot.ITelegramBotClient"/> service with <see cref="T:Telegrator.Mediation.HostedUpdateWebhooker"/> to receive updates using webhook
|
||||||
|
|||||||
+44
-41
@@ -13,7 +13,7 @@
|
|||||||
<param name="services"></param>
|
<param name="services"></param>
|
||||||
<param name="configuration"></param>
|
<param name="configuration"></param>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Telegrator.Hosting.HostedTelegramBotInfo.#ctor(Telegram.Bot.ITelegramBotClient,System.IServiceProvider,Microsoft.Extensions.Configuration.IConfigurationManager)">
|
<member name="M:Telegrator.Hosting.HostedTelegramBotInfo.#ctor(Telegram.Bot.ITelegramBotClient,System.IServiceProvider,Microsoft.Extensions.Configuration.IConfiguration)">
|
||||||
<summary>
|
<summary>
|
||||||
Implementation of <see cref="T:Telegrator.Core.ITelegramBotInfo"/> that provides bot information.
|
Implementation of <see cref="T:Telegrator.Core.ITelegramBotInfo"/> that provides bot information.
|
||||||
Contains metadata about the Telegram bot including user details and service provider for wider filterring abilities
|
Contains metadata about the Telegram bot including user details and service provider for wider filterring abilities
|
||||||
@@ -37,23 +37,7 @@
|
|||||||
</member>
|
</member>
|
||||||
<member name="T:Telegrator.Hosting.ITelegramBotHostBuilder">
|
<member name="T:Telegrator.Hosting.ITelegramBotHostBuilder">
|
||||||
<summary>
|
<summary>
|
||||||
Interface for building Telegram bot hosts with dependency injection support.
|
Represents a hosted telegram bots and services builder that helps manage configuration, logging, lifetime, and more.
|
||||||
Combines host application building capabilities with handler collection functionality.
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="P:Telegrator.Hosting.ITelegramBotHostBuilder.Configuration">
|
|
||||||
<summary>
|
|
||||||
Gets the set of key/value configuration properties.
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="P:Telegrator.Hosting.ITelegramBotHostBuilder.Logging">
|
|
||||||
<summary>
|
|
||||||
Gets a collection of logging providers for the application to compose. This is useful for adding new logging providers.
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="P:Telegrator.Hosting.ITelegramBotHostBuilder.Services">
|
|
||||||
<summary>
|
|
||||||
Gets a collection of services for the application to compose. This is useful for adding user provided or framework provided services.
|
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="T:Telegrator.Hosting.TelegramBotHost">
|
<member name="T:Telegrator.Hosting.TelegramBotHost">
|
||||||
@@ -114,9 +98,7 @@
|
|||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="T:Telegrator.Hosting.TelegramBotHostBuilder">
|
<member name="T:Telegrator.Hosting.TelegramBotHostBuilder">
|
||||||
<summary>
|
<inheritdoc/>
|
||||||
Represents a hosted telegram bots and services builder that helps manage configuration, logging, lifetime, and more.
|
|
||||||
</summary>
|
|
||||||
</member>
|
</member>
|
||||||
<member name="P:Telegrator.Hosting.TelegramBotHostBuilder.Handlers">
|
<member name="P:Telegrator.Hosting.TelegramBotHostBuilder.Handlers">
|
||||||
<inheritdoc/>
|
<inheritdoc/>
|
||||||
@@ -133,20 +115,24 @@
|
|||||||
<member name="P:Telegrator.Hosting.TelegramBotHostBuilder.Environment">
|
<member name="P:Telegrator.Hosting.TelegramBotHostBuilder.Environment">
|
||||||
<inheritdoc/>
|
<inheritdoc/>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Telegrator.Hosting.TelegramBotHostBuilder.#ctor(Microsoft.Extensions.Hosting.HostApplicationBuilder,Microsoft.Extensions.Hosting.HostApplicationBuilderSettings)">
|
<member name="P:Telegrator.Hosting.TelegramBotHostBuilder.Properties">
|
||||||
|
<inheritdoc/>
|
||||||
|
</member>
|
||||||
|
<member name="P:Telegrator.Hosting.TelegramBotHostBuilder.Metrics">
|
||||||
|
<inheritdoc/>
|
||||||
|
</member>
|
||||||
|
<member name="M:Telegrator.Hosting.TelegramBotHostBuilder.#ctor(Microsoft.Extensions.Hosting.HostApplicationBuilder)">
|
||||||
<summary>
|
<summary>
|
||||||
Initializes a new instance of the <see cref="T:Telegrator.Hosting.TelegramBotHostBuilder"/> class.
|
Initializes a new instance of the <see cref="T:Telegrator.Hosting.TelegramBotHostBuilder"/> class.
|
||||||
</summary>
|
</summary>
|
||||||
<param name="hostApplicationBuilder"></param>
|
<param name="hostApplicationBuilder"></param>
|
||||||
<param name="settings"></param>
|
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Telegrator.Hosting.TelegramBotHostBuilder.#ctor(Microsoft.Extensions.Hosting.HostApplicationBuilder,Telegrator.Core.IHandlersCollection,Microsoft.Extensions.Hosting.HostApplicationBuilderSettings)">
|
<member name="M:Telegrator.Hosting.TelegramBotHostBuilder.#ctor(Microsoft.Extensions.Hosting.HostApplicationBuilder,Telegrator.Core.IHandlersCollection)">
|
||||||
<summary>
|
<summary>
|
||||||
Initializes a new instance of the <see cref="T:Telegrator.Hosting.TelegramBotHostBuilder"/> class.
|
Initializes a new instance of the <see cref="T:Telegrator.Hosting.TelegramBotHostBuilder"/> class.
|
||||||
</summary>
|
</summary>
|
||||||
<param name="hostApplicationBuilder"></param>
|
<param name="hostApplicationBuilder"></param>
|
||||||
<param name="handlers"></param>
|
<param name="handlers"></param>
|
||||||
<param name="settings"></param>
|
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Telegrator.Hosting.TelegramBotHostBuilder.Build">
|
<member name="M:Telegrator.Hosting.TelegramBotHostBuilder.Build">
|
||||||
<summary>
|
<summary>
|
||||||
@@ -154,6 +140,9 @@
|
|||||||
</summary>
|
</summary>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Telegrator.Hosting.TelegramBotHostBuilder.ConfigureContainer``1(Microsoft.Extensions.DependencyInjection.IServiceProviderFactory{``0},System.Action{``0})">
|
||||||
|
<inheritdoc/>
|
||||||
|
</member>
|
||||||
<member name="T:Telegrator.Logging.MicrosoftLoggingAdapter">
|
<member name="T:Telegrator.Logging.MicrosoftLoggingAdapter">
|
||||||
<summary>
|
<summary>
|
||||||
Adapter for Microsoft.Extensions.Logging to work with Telegrator logging system.
|
Adapter for Microsoft.Extensions.Logging to work with Telegrator logging system.
|
||||||
@@ -190,12 +179,6 @@
|
|||||||
<member name="M:Telegrator.Polling.HostedUpdateReceiver.ExecuteAsync(System.Threading.CancellationToken)">
|
<member name="M:Telegrator.Polling.HostedUpdateReceiver.ExecuteAsync(System.Threading.CancellationToken)">
|
||||||
<inheritdoc/>
|
<inheritdoc/>
|
||||||
</member>
|
</member>
|
||||||
<member name="T:Telegrator.Polling.HostUpdateHandlersPool">
|
|
||||||
<inheritdoc/>
|
|
||||||
</member>
|
|
||||||
<member name="M:Telegrator.Polling.HostUpdateHandlersPool.#ctor(Telegrator.Core.IUpdateRouter,Microsoft.Extensions.Options.IOptions{Telegrator.TelegratorOptions})">
|
|
||||||
<inheritdoc/>
|
|
||||||
</member>
|
|
||||||
<member name="T:Telegrator.Polling.HostUpdateRouter">
|
<member name="T:Telegrator.Polling.HostUpdateRouter">
|
||||||
<inheritdoc/>
|
<inheritdoc/>
|
||||||
</member>
|
</member>
|
||||||
@@ -204,7 +187,7 @@
|
|||||||
<see cref="T:Microsoft.Extensions.Logging.ILogger"/> of this router
|
<see cref="T:Microsoft.Extensions.Logging.ILogger"/> of this router
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Telegrator.Polling.HostUpdateRouter.#ctor(Telegrator.Core.IHandlersProvider,Telegrator.Core.IAwaitingProvider,Microsoft.Extensions.Options.IOptions{Telegrator.TelegratorOptions},Telegrator.Core.IUpdateHandlersPool,Telegrator.Core.ITelegramBotInfo,Microsoft.Extensions.Logging.ILogger{Telegrator.Polling.HostUpdateRouter})">
|
<member name="M:Telegrator.Polling.HostUpdateRouter.#ctor(Telegrator.Core.IHandlersProvider,Telegrator.Core.IAwaitingProvider,Telegrator.Core.States.IStateStorage,Microsoft.Extensions.Options.IOptions{Telegrator.TelegratorOptions},Telegrator.Core.ITelegramBotInfo,Microsoft.Extensions.Logging.ILogger{Telegrator.Polling.HostUpdateRouter})">
|
||||||
<inheritdoc/>
|
<inheritdoc/>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Telegrator.Polling.HostUpdateRouter.HandleUpdateAsync(Telegram.Bot.ITelegramBotClient,Telegram.Bot.Types.Update,System.Threading.CancellationToken)">
|
<member name="M:Telegrator.Polling.HostUpdateRouter.HandleUpdateAsync(Telegram.Bot.ITelegramBotClient,Telegram.Bot.Types.Update,System.Threading.CancellationToken)">
|
||||||
@@ -222,7 +205,7 @@
|
|||||||
<member name="T:Telegrator.Providers.HostAwaitingProvider">
|
<member name="T:Telegrator.Providers.HostAwaitingProvider">
|
||||||
<inheritdoc/>
|
<inheritdoc/>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Telegrator.Providers.HostAwaitingProvider.#ctor(Microsoft.Extensions.Options.IOptions{Telegrator.TelegratorOptions},Microsoft.Extensions.Logging.ILogger{Telegrator.Providers.HostAwaitingProvider})">
|
<member name="M:Telegrator.Providers.HostAwaitingProvider.#ctor(Microsoft.Extensions.Options.IOptions{Telegrator.TelegratorOptions})">
|
||||||
<inheritdoc/>
|
<inheritdoc/>
|
||||||
</member>
|
</member>
|
||||||
<member name="T:Telegrator.Providers.HostHandlersCollection">
|
<member name="T:Telegrator.Providers.HostHandlersCollection">
|
||||||
@@ -240,7 +223,7 @@
|
|||||||
<member name="T:Telegrator.Providers.HostHandlersProvider">
|
<member name="T:Telegrator.Providers.HostHandlersProvider">
|
||||||
<inheritdoc/>
|
<inheritdoc/>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Telegrator.Providers.HostHandlersProvider.#ctor(Telegrator.Core.IHandlersCollection,Microsoft.Extensions.Options.IOptions{Telegrator.TelegratorOptions},System.IServiceProvider,Microsoft.Extensions.Logging.ILogger{Telegrator.Providers.HostHandlersProvider})">
|
<member name="M:Telegrator.Providers.HostHandlersProvider.#ctor(Telegrator.Core.IHandlersCollection,Microsoft.Extensions.Options.IOptions{Telegrator.TelegratorOptions},System.IServiceProvider)">
|
||||||
<inheritdoc/>
|
<inheritdoc/>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Telegrator.Providers.HostHandlersProvider.GetHandlerInstance(Telegrator.Core.Descriptors.HandlerDescriptor,System.Threading.CancellationToken)">
|
<member name="M:Telegrator.Providers.HostHandlersProvider.GetHandlerInstance(Telegrator.Core.Descriptors.HandlerDescriptor,System.Threading.CancellationToken)">
|
||||||
@@ -256,17 +239,29 @@
|
|||||||
The key used to store the <see cref="T:Telegrator.Core.IHandlersCollection"/> in the builder properties.
|
The key used to store the <see cref="T:Telegrator.Core.IHandlersCollection"/> in the builder properties.
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Telegrator.HostBuilderExtensions.get_Handlers(Microsoft.Extensions.Hosting.IHostApplicationBuilder)">
|
<member name="M:Telegrator.HostBuilderExtensions.AddTelegrator(Telegrator.Hosting.ITelegramBotHostBuilder,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection,System.Action{Telegrator.Hosting.ITelegramBotHostBuilder})">
|
||||||
<inheritdoc cref="P:Telegrator.HostBuilderExtensions.<G>$605D8CCF64349EA050C790D67C500BD9.Handlers"/>
|
|
||||||
</member>
|
|
||||||
<member name="M:Telegrator.HostBuilderExtensions.AddTelegrator(Microsoft.Extensions.Hosting.IHostApplicationBuilder,Microsoft.Extensions.Hosting.HostApplicationBuilderSettings,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection)">
|
|
||||||
<summary>
|
<summary>
|
||||||
Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
|
Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:Telegrator.HostBuilderExtensions.<G>$605D8CCF64349EA050C790D67C500BD9.Handlers">
|
<member name="M:Telegrator.HostBuilderExtensions.AddTelegrator(Microsoft.Extensions.Hosting.HostApplicationBuilder,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection,System.Action{Telegrator.Hosting.ITelegramBotHostBuilder})">
|
||||||
<summary>
|
<summary>
|
||||||
Gets the <see cref="T:Telegrator.Core.IHandlersCollection"/> from the builder properties.
|
Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="M:Telegrator.HostBuilderExtensions.AddTelegrator(Microsoft.Extensions.Hosting.IHostApplicationBuilder,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection)">
|
||||||
|
<summary>
|
||||||
|
Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="M:Telegrator.HostBuilderExtensions.AddTelegrator(Microsoft.Extensions.Hosting.IHostBuilder,Telegrator.TelegratorOptions,Telegrator.Core.IHandlersCollection)">
|
||||||
|
<summary>
|
||||||
|
Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="M:Telegrator.HostBuilderExtensions.AddTelegratorInternal(Microsoft.Extensions.DependencyInjection.IServiceCollection,Microsoft.Extensions.Configuration.IConfiguration,System.Collections.Generic.IDictionary{System.Object,System.Object},Telegrator.Core.IHandlersCollection@,Telegrator.TelegratorOptions)">
|
||||||
|
<summary>
|
||||||
|
Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
<member name="T:Telegrator.ServicesCollectionExtensions">
|
<member name="T:Telegrator.ServicesCollectionExtensions">
|
||||||
@@ -275,6 +270,14 @@
|
|||||||
Provides method to configure Telegram Bot Host
|
Provides method to configure Telegram Bot Host
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Telegrator.ServicesCollectionExtensions.AddStateStorage``1(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
|
||||||
|
<summary>
|
||||||
|
Registers <see cref="T:Telegrator.Core.States.IStateStorage"/> service
|
||||||
|
</summary>
|
||||||
|
<typeparam name="TStorage"></typeparam>
|
||||||
|
<param name="services"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:Telegrator.ServicesCollectionExtensions.AddTelegramBotHostDefaults(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
|
<member name="M:Telegrator.ServicesCollectionExtensions.AddTelegramBotHostDefaults(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
|
||||||
<summary>
|
<summary>
|
||||||
Registers <see cref="T:Telegrator.Hosting.TelegramBotHost"/> default services
|
Registers <see cref="T:Telegrator.Hosting.TelegramBotHost"/> default services
|
||||||
|
|||||||
+303
-694
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,13 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Telegrator" Version="1.16.2"/>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using Telegrator;
|
||||||
|
|
||||||
|
namespace Telegrator.Examples;
|
||||||
|
|
||||||
|
public class EchoBot
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
var client = new TelegratorClient();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
# Telegrator.RedisStateStorage
|
||||||
|
|
||||||
|
**Telegrator.RedisStateStorage** is an extension for the Telegrator framework that provides Redis powered IStateStorage implementation.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
- .NET standart 2.1 or later
|
||||||
|
- [Telegrator](https://github.com/Rikitav/Telegrator)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```shell
|
||||||
|
dotnet add package Telegrator.RedisStateStorage
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Quick Start Example
|
||||||
|
|
||||||
|
**Program.cs:**
|
||||||
|
```csharp
|
||||||
|
using Telegrator.Hosting;
|
||||||
|
|
||||||
|
// Creating builder
|
||||||
|
TelegramBotHostBuilder builder = TelegramBotHost.CreateBuilder(new HostApplicationBuilderSettings()
|
||||||
|
{
|
||||||
|
Args = args,
|
||||||
|
ApplicationName = "TelegramBotHost example",
|
||||||
|
});
|
||||||
|
|
||||||
|
// Registerring handlers
|
||||||
|
builder.Handlers.CollectHandlersAssemblyWide();
|
||||||
|
|
||||||
|
// Register your services and
|
||||||
|
builder.Services.AddService<IStateStorage, RedisStateStorage>(services =>
|
||||||
|
new RedisStateStorage(ConnectionMultiplexer.Connect("server1:6379, server2:6379")));
|
||||||
|
|
||||||
|
// Building and running application
|
||||||
|
TelegramBotHost telegramBot = builder.Build();
|
||||||
|
telegramBot.SetBotCommands();
|
||||||
|
telegramBot.Run();
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
- [Telegrator Main Docs](https://github.com/Rikitav/Telegrator)
|
||||||
|
- [Getting Started Guide](https://github.com/Rikitav/Telegrator/wiki/Getting-started)
|
||||||
|
- [Annotation Overview](https://github.com/Rikitav/Telegrator/wiki/Annotation-overview)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## License
|
||||||
|
GPLv3
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
using StackExchange.Redis;
|
||||||
|
using System.Text.Json;
|
||||||
|
using Telegrator.Core.States;
|
||||||
|
|
||||||
|
namespace Telegrator.States;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Provides a Redis-based implementation of the <see cref="IStateStorage"/> interface.
|
||||||
|
/// Serializes state objects to JSON format before storing them in the Redis database.
|
||||||
|
/// </summary>
|
||||||
|
public class RedisStateStorage(IConnectionMultiplexer redis) : IStateStorage
|
||||||
|
{
|
||||||
|
private readonly IDatabase _db = redis.GetDatabase();
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public async Task SetAsync<T>(string key, T state, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
string json = JsonSerializer.Serialize(state);
|
||||||
|
await _db.StringSetAsync(key, json);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public async Task<T?> GetAsync<T>(string key, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
RedisValue json = await _db.StringGetAsync(key);
|
||||||
|
string? jsonStr = json;
|
||||||
|
|
||||||
|
if (jsonStr is null)
|
||||||
|
return default;
|
||||||
|
|
||||||
|
return JsonSerializer.Deserialize<T?>(json: jsonStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public async Task DeleteAsync(string key, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
await _db.KeyDeleteAsync(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<LangVersion>latest</LangVersion>
|
||||||
|
<RootNamespace>Telegrator</RootNamespace>
|
||||||
|
<BaseOutputPath>..\..\bin</BaseOutputPath>
|
||||||
|
<DocumentationFile>..\..\docs\$(AssemblyName).xml</DocumentationFile>
|
||||||
|
|
||||||
|
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||||
|
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||||
|
<EnableNETAnalyzers>True</EnableNETAnalyzers>
|
||||||
|
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||||
|
|
||||||
|
<Title>Telegrator.RedisStateStorage</Title>
|
||||||
|
<Version>1.16.6</Version>
|
||||||
|
<Authors>Rikitav Tim4ik</Authors>
|
||||||
|
<Company>Rikitav Tim4ik</Company>
|
||||||
|
<RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl>
|
||||||
|
<PackageTags>telegram;bot;mediator;attributes;aspect;hosting;host;framework;easy;simple;handlers</PackageTags>
|
||||||
|
|
||||||
|
<PackageIcon>telegrator_nuget.png</PackageIcon>
|
||||||
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
|
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Telegrator\Telegrator.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="StackExchange.Redis" Version="2.12.14" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include=".\README.md" Pack="True" PackagePath="\" />
|
||||||
|
<None Include="..\..\LICENSE" Pack="True" PackagePath="\" />
|
||||||
|
<None Include="..\..\resources\telegrator_nuget.png" Pack="True" PackagePath="\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -9,3 +9,4 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
[assembly: SuppressMessage("Style", "IDE0090")]
|
[assembly: SuppressMessage("Style", "IDE0090")]
|
||||||
[assembly: SuppressMessage("Usage", "CA2254")]
|
[assembly: SuppressMessage("Usage", "CA2254")]
|
||||||
[assembly: SuppressMessage("Maintainability", "CA1510")]
|
[assembly: SuppressMessage("Maintainability", "CA1510")]
|
||||||
|
[assembly: SuppressMessage("Style", "IDE0270")]
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ using Microsoft.Extensions.Hosting;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Telegrator.Core;
|
using Telegrator.Core;
|
||||||
|
|
||||||
namespace Telegrator.Hosting.Web
|
namespace Telegrator.Hosting.Web;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a web hosted telegram bot
|
/// Represents a web hosted telegram bot
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -39,11 +39,13 @@ namespace Telegrator.Hosting.Web
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public ILogger<TelegramBotWebHost> Logger => _logger;
|
public ILogger<TelegramBotWebHost> Logger => _logger;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public IDictionary<string, object?> Properties => ((IApplicationBuilder)_innerApp).Properties;
|
||||||
|
|
||||||
// Private interface fields
|
// Private interface fields
|
||||||
IServiceProvider IEndpointRouteBuilder.ServiceProvider => Services;
|
IServiceProvider IEndpointRouteBuilder.ServiceProvider => Services;
|
||||||
IServiceProvider IApplicationBuilder.ApplicationServices { get => Services; set => throw new NotImplementedException(); }
|
IServiceProvider IApplicationBuilder.ApplicationServices { get => Services; set => throw new NotImplementedException(); }
|
||||||
IFeatureCollection IApplicationBuilder.ServerFeatures => ((IApplicationBuilder)_innerApp).ServerFeatures;
|
IFeatureCollection IApplicationBuilder.ServerFeatures => ((IApplicationBuilder)_innerApp).ServerFeatures;
|
||||||
IDictionary<string, object?> IApplicationBuilder.Properties => ((IApplicationBuilder)_innerApp).Properties;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="WebApplicationBuilder"/> class.
|
/// Initializes a new instance of the <see cref="WebApplicationBuilder"/> class.
|
||||||
@@ -53,7 +55,6 @@ namespace Telegrator.Hosting.Web
|
|||||||
{
|
{
|
||||||
// Building proxy application
|
// Building proxy application
|
||||||
_innerApp = webApplicationBuilder.Build();
|
_innerApp = webApplicationBuilder.Build();
|
||||||
_innerApp.UseTelegratorWeb();
|
|
||||||
|
|
||||||
// Reruesting services for this host
|
// Reruesting services for this host
|
||||||
_updateRouter = Services.GetRequiredService<IUpdateRouter>();
|
_updateRouter = Services.GetRequiredService<IUpdateRouter>();
|
||||||
@@ -64,14 +65,12 @@ namespace Telegrator.Hosting.Web
|
|||||||
/// Creates new <see cref="TelegramBotHostBuilder"/> with default services and webhook update receiving scheme
|
/// Creates new <see cref="TelegramBotHostBuilder"/> with default services and webhook update receiving scheme
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static TelegramBotWebHostBuilder CreateBuilder(WebApplicationOptions settings)
|
public static TelegramBotWebHostBuilder CreateBuilder(WebApplicationOptions? settings)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(settings, nameof(settings));
|
ArgumentNullException.ThrowIfNull(settings, nameof(settings));
|
||||||
WebApplicationBuilder innerApp = WebApplication.CreateBuilder(settings);
|
WebApplicationBuilder innerApp = WebApplication.CreateBuilder(settings);
|
||||||
TelegramBotWebHostBuilder builder = new TelegramBotWebHostBuilder(innerApp, settings);
|
TelegramBotWebHostBuilder builder = new TelegramBotWebHostBuilder(innerApp);
|
||||||
|
builder.AddTelegratorWeb();
|
||||||
builder.Services.AddTelegramBotHostDefaults();
|
|
||||||
builder.Services.AddTelegramWebhook();
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,14 +78,12 @@ namespace Telegrator.Hosting.Web
|
|||||||
/// Creates new SLIM <see cref="TelegramBotHostBuilder"/> with default services and webhook update receiving scheme
|
/// Creates new SLIM <see cref="TelegramBotHostBuilder"/> with default services and webhook update receiving scheme
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static TelegramBotWebHostBuilder CreateSlimBuilder(WebApplicationOptions settings)
|
public static TelegramBotWebHostBuilder CreateSlimBuilder(WebApplicationOptions? settings)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(settings, nameof(settings));
|
ArgumentNullException.ThrowIfNull(settings, nameof(settings));
|
||||||
WebApplicationBuilder innerApp = WebApplication.CreateSlimBuilder(settings);
|
WebApplicationBuilder innerApp = WebApplication.CreateSlimBuilder(settings);
|
||||||
TelegramBotWebHostBuilder builder = new TelegramBotWebHostBuilder(innerApp, settings);
|
TelegramBotWebHostBuilder builder = new TelegramBotWebHostBuilder(innerApp);
|
||||||
|
builder.AddTelegratorWeb();
|
||||||
builder.Services.AddTelegramBotHostDefaults();
|
|
||||||
builder.Services.AddTelegramWebhook();
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,11 +91,13 @@ namespace Telegrator.Hosting.Web
|
|||||||
/// Creates new EMPTY <see cref="TelegramBotHostBuilder"/> WITHOUT any services or update receiving schemes
|
/// Creates new EMPTY <see cref="TelegramBotHostBuilder"/> WITHOUT any services or update receiving schemes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static TelegramBotWebHostBuilder CreateEmptyBuilder(WebApplicationOptions settings)
|
public static TelegramBotWebHostBuilder CreateEmptyBuilder(WebApplicationOptions? settings)
|
||||||
{
|
{
|
||||||
ArgumentNullException.ThrowIfNull(settings, nameof(settings));
|
ArgumentNullException.ThrowIfNull(settings, nameof(settings));
|
||||||
WebApplicationBuilder innerApp = WebApplication.CreateEmptyBuilder(settings);
|
WebApplicationBuilder innerApp = WebApplication.CreateEmptyBuilder(settings);
|
||||||
return new TelegramBotWebHostBuilder(innerApp, settings);
|
TelegramBotWebHostBuilder builder = new TelegramBotWebHostBuilder(innerApp);
|
||||||
|
builder.AddTelegratorWeb();
|
||||||
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@@ -158,4 +157,3 @@ namespace Telegrator.Hosting.Web
|
|||||||
_disposed = true;
|
_disposed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,20 +1,18 @@
|
|||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Diagnostics.Metrics;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Telegrator.Core;
|
using Telegrator.Core;
|
||||||
|
|
||||||
#pragma warning disable IDE0001
|
#pragma warning disable IDE0001
|
||||||
namespace Telegrator.Hosting.Web
|
namespace Telegrator.Hosting.Web;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <inheritdoc/>
|
||||||
/// Represents a web hosted telegram bots and services builder that helps manage configuration, logging, lifetime, and more.
|
|
||||||
/// </summary>
|
|
||||||
public class TelegramBotWebHostBuilder : ITelegramBotHostBuilder
|
public class TelegramBotWebHostBuilder : ITelegramBotHostBuilder
|
||||||
{
|
{
|
||||||
private readonly WebApplicationBuilder _innerBuilder;
|
private readonly WebApplicationBuilder _innerBuilder;
|
||||||
private readonly WebApplicationOptions _settings;
|
|
||||||
internal IHandlersCollection _handlers = null!;
|
internal IHandlersCollection _handlers = null!;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@@ -32,17 +30,19 @@ namespace Telegrator.Hosting.Web
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IHostEnvironment Environment => _innerBuilder.Environment;
|
public IHostEnvironment Environment => _innerBuilder.Environment;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public IDictionary<object, object> Properties => ((IHostApplicationBuilder)_innerBuilder).Properties;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public IMetricsBuilder Metrics => _innerBuilder.Metrics;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="TelegramBotWebHostBuilder"/> class.
|
/// Initializes a new instance of the <see cref="TelegramBotWebHostBuilder"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="webApplicationBuilder"></param>
|
/// <param name="webApplicationBuilder"></param>
|
||||||
/// <param name="settings"></param>
|
public TelegramBotWebHostBuilder(WebApplicationBuilder webApplicationBuilder)
|
||||||
public TelegramBotWebHostBuilder(WebApplicationBuilder webApplicationBuilder, WebApplicationOptions settings)
|
|
||||||
{
|
{
|
||||||
_innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder));
|
_innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder));
|
||||||
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
|
|
||||||
|
|
||||||
_innerBuilder.AddTelegratorWeb();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -50,13 +50,10 @@ namespace Telegrator.Hosting.Web
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="webApplicationBuilder"></param>
|
/// <param name="webApplicationBuilder"></param>
|
||||||
/// <param name="handlers"></param>
|
/// <param name="handlers"></param>
|
||||||
/// <param name="settings"></param>
|
public TelegramBotWebHostBuilder(WebApplicationBuilder webApplicationBuilder, IHandlersCollection handlers)
|
||||||
public TelegramBotWebHostBuilder(WebApplicationBuilder webApplicationBuilder, IHandlersCollection handlers, WebApplicationOptions settings)
|
|
||||||
{
|
{
|
||||||
_innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder));
|
_innerBuilder = webApplicationBuilder ?? throw new ArgumentNullException(nameof(webApplicationBuilder));
|
||||||
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
|
_handlers = handlers ?? throw new ArgumentNullException(nameof(handlers));
|
||||||
|
|
||||||
_innerBuilder.AddTelegratorWeb(null, handlers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -66,8 +63,13 @@ namespace Telegrator.Hosting.Web
|
|||||||
public TelegramBotWebHost Build()
|
public TelegramBotWebHost Build()
|
||||||
{
|
{
|
||||||
TelegramBotWebHost host = new TelegramBotWebHost(_innerBuilder);
|
TelegramBotWebHost host = new TelegramBotWebHost(_innerBuilder);
|
||||||
host.UseTelegrator();
|
host.UseTelegratorWeb();
|
||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public void ConfigureContainer<TContainerBuilder>(IServiceProviderFactory<TContainerBuilder> factory, Action<TContainerBuilder>? configure = null) where TContainerBuilder : notnull
|
||||||
|
{
|
||||||
|
((IHostApplicationBuilder)_innerBuilder).ConfigureContainer(factory, configure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
namespace Telegrator.Hosting.Web
|
namespace Telegrator.Hosting.Web;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Configuration options for Telegram bot behavior and execution settings.
|
/// Configuration options for Telegram bot behavior and execution settings.
|
||||||
/// Controls various aspects of bot operation including concurrency, routing, webhook receiving, and execution policies.
|
/// Controls various aspects of bot operation including concurrency, routing, webhook receiving, and execution policies.
|
||||||
@@ -32,4 +32,3 @@ namespace Telegrator.Hosting.Web
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool DropPendingUpdates { get; set; } = false;
|
public bool DropPendingUpdates { get; set; } = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ using Telegram.Bot.Types;
|
|||||||
using Telegrator.Core;
|
using Telegrator.Core;
|
||||||
using Telegrator.Hosting.Web;
|
using Telegrator.Hosting.Web;
|
||||||
|
|
||||||
namespace Telegrator.Mediation
|
namespace Telegrator.Mediation;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Service for receiving updates for Hosted telegram bots via Webhooks
|
/// Service for receiving updates for Hosted telegram bots via Webhooks
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -19,7 +19,6 @@ namespace Telegrator.Mediation
|
|||||||
{
|
{
|
||||||
private const string SecretTokenHeader = "X-Telegram-Bot-Api-Secret-Token";
|
private const string SecretTokenHeader = "X-Telegram-Bot-Api-Secret-Token";
|
||||||
|
|
||||||
private readonly IEndpointRouteBuilder _botHost;
|
|
||||||
private readonly ITelegramBotClient _botClient;
|
private readonly ITelegramBotClient _botClient;
|
||||||
private readonly IUpdateRouter _updateRouter;
|
private readonly IUpdateRouter _updateRouter;
|
||||||
private readonly WebhookerOptions _options;
|
private readonly WebhookerOptions _options;
|
||||||
@@ -27,17 +26,15 @@ namespace Telegrator.Mediation
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initiallizes new instance of <see cref="HostedUpdateWebhooker"/>
|
/// Initiallizes new instance of <see cref="HostedUpdateWebhooker"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="botHost"></param>
|
|
||||||
/// <param name="botClient"></param>
|
/// <param name="botClient"></param>
|
||||||
/// <param name="updateRouter"></param>
|
/// <param name="updateRouter"></param>
|
||||||
/// <param name="options"></param>
|
/// <param name="options"></param>
|
||||||
/// <exception cref="ArgumentNullException"></exception>
|
/// <exception cref="ArgumentNullException"></exception>
|
||||||
public HostedUpdateWebhooker(IEndpointRouteBuilder botHost, ITelegramBotClient botClient, IUpdateRouter updateRouter, IOptions<WebhookerOptions> options)
|
public HostedUpdateWebhooker(ITelegramBotClient botClient, IUpdateRouter updateRouter, IOptions<WebhookerOptions> options)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(options.Value.WebhookUri))
|
if (string.IsNullOrEmpty(options.Value.WebhookUri))
|
||||||
throw new ArgumentNullException(nameof(options), "Option \"WebhookUrl\" must be set to subscribe for update recieving");
|
throw new ArgumentNullException(nameof(options), "Option \"WebhookUrl\" must be set to subscribe for update recieving");
|
||||||
|
|
||||||
_botHost = botHost;
|
|
||||||
_botClient = botClient;
|
_botClient = botClient;
|
||||||
_updateRouter = updateRouter;
|
_updateRouter = updateRouter;
|
||||||
_options = options.Value;
|
_options = options.Value;
|
||||||
@@ -50,11 +47,48 @@ namespace Telegrator.Mediation
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void StartInternal(CancellationToken cancellationToken)
|
/// <inheritdoc/>
|
||||||
|
public Task StopAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
_botClient.DeleteWebhook(_options.DropPendingUpdates, cancellationToken);
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allows to remap receiving webhook endpoint and map new route to webhost.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="routeBuilder"></param>
|
||||||
|
/// <param name="webhookUri"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="ArgumentException"></exception>
|
||||||
|
public async Task RemapWebhook(IEndpointRouteBuilder routeBuilder, string webhookUri, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
if (!Uri.TryCreate(webhookUri, UriKind.Absolute, out Uri? result))
|
||||||
|
throw new ArgumentException("invalid URL");
|
||||||
|
|
||||||
|
_options.WebhookUri = result.ToString();
|
||||||
|
await SetWebhook(cancellationToken);
|
||||||
|
MapWebhook(routeBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Maps bot webhook to application builder
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="routeBuilder"></param>
|
||||||
|
internal void MapWebhook(IEndpointRouteBuilder routeBuilder)
|
||||||
{
|
{
|
||||||
string pattern = new UriBuilder(_options.WebhookUri).Path;
|
string pattern = new UriBuilder(_options.WebhookUri).Path;
|
||||||
_botHost.MapPost(pattern, (Delegate)ReceiveUpdate);
|
routeBuilder.MapPost(pattern, (Delegate)ReceiveUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void StartInternal(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await SetWebhook(cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SetWebhook(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
await _botClient.SetWebhook(
|
await _botClient.SetWebhook(
|
||||||
url: _options.WebhookUri,
|
url: _options.WebhookUri,
|
||||||
maxConnections: _options.MaxConnections,
|
maxConnections: _options.MaxConnections,
|
||||||
@@ -64,13 +98,6 @@ namespace Telegrator.Mediation
|
|||||||
cancellationToken: cancellationToken);
|
cancellationToken: cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public Task StopAsync(CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
_botClient.DeleteWebhook(_options.DropPendingUpdates, cancellationToken);
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<IResult> ReceiveUpdate(HttpContext ctx)
|
private async Task<IResult> ReceiveUpdate(HttpContext ctx)
|
||||||
{
|
{
|
||||||
if (_options.SecretToken != null)
|
if (_options.SecretToken != null)
|
||||||
@@ -94,4 +121,3 @@ namespace Telegrator.Mediation
|
|||||||
return Results.Ok();
|
return Results.Ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Telegrator.Hosting;
|
using Telegrator.Hosting;
|
||||||
using Telegrator.Hosting.Web;
|
using Telegrator.Hosting.Web;
|
||||||
@@ -15,7 +16,8 @@ internal class Program
|
|||||||
ApplicationName = "TelegramBotWebHost example",
|
ApplicationName = "TelegramBotWebHost example",
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.Handlers.CollectHandlersAssemblyWide();
|
builder.Handlers
|
||||||
|
.CollectHandlersAssemblyWide();
|
||||||
|
|
||||||
builder.Build()
|
builder.Build()
|
||||||
.AddLoggingAdapter()
|
.AddLoggingAdapter()
|
||||||
@@ -31,11 +33,12 @@ internal class Program
|
|||||||
ApplicationName = "WebApplication example",
|
ApplicationName = "WebApplication example",
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.AddTelegratorWeb();
|
builder.AddTelegratorWeb(action: builder => builder.Handlers
|
||||||
builder.Handlers.CollectHandlersAssemblyWide();
|
.CollectHandlersAssemblyWide());
|
||||||
|
|
||||||
builder.Build()
|
builder.Build()
|
||||||
.UseTelegratorWeb()
|
.UseTelegratorWeb(dontMap: true)
|
||||||
|
.RemapWebhook("https://awesome-butt-sex.cloudpub.ru/")
|
||||||
.AddLoggingAdapter()
|
.AddLoggingAdapter()
|
||||||
.SetBotCommands()
|
.SetBotCommands()
|
||||||
.Run();
|
.Run();
|
||||||
@@ -43,13 +46,18 @@ internal class Program
|
|||||||
|
|
||||||
public static void TelegramBotHostBuilder_Example(string[] args)
|
public static void TelegramBotHostBuilder_Example(string[] args)
|
||||||
{
|
{
|
||||||
|
ConfigurationManager configuration = new ConfigurationManager();
|
||||||
|
configuration.AddJsonFile("appsettings.json");
|
||||||
|
|
||||||
TelegramBotHostBuilder builder = TelegramBotHost.CreateBuilder(new HostApplicationBuilderSettings()
|
TelegramBotHostBuilder builder = TelegramBotHost.CreateBuilder(new HostApplicationBuilderSettings()
|
||||||
{
|
{
|
||||||
Args = args,
|
Args = args,
|
||||||
ApplicationName = "TelegramBotHost example",
|
ApplicationName = "TelegramBotHost example",
|
||||||
|
Configuration = configuration
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.Handlers.CollectHandlersAssemblyWide();
|
builder.Handlers
|
||||||
|
.CollectHandlersAssemblyWide();
|
||||||
|
|
||||||
builder.Build()
|
builder.Build()
|
||||||
.AddLoggingAdapter()
|
.AddLoggingAdapter()
|
||||||
@@ -65,8 +73,8 @@ internal class Program
|
|||||||
ApplicationName = "Host example",
|
ApplicationName = "Host example",
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.AddTelegrator();
|
builder.AddTelegrator(action: builder => builder.Handlers
|
||||||
builder.Handlers.CollectHandlersAssemblyWide();
|
.CollectHandlersAssemblyWide());
|
||||||
|
|
||||||
builder.Build()
|
builder.Build()
|
||||||
.UseTelegrator()
|
.UseTelegrator()
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||||
|
|
||||||
<Title>Telegrator.Hosting.Web</Title>
|
<Title>Telegrator.Hosting.Web</Title>
|
||||||
<Version>1.16.1</Version>
|
<Version>1.16.9</Version>
|
||||||
<Authors>Rikitav Tim4ik</Authors>
|
<Authors>Rikitav Tim4ik</Authors>
|
||||||
<Company>Rikitav Tim4ik</Company>
|
<Company>Rikitav Tim4ik</Company>
|
||||||
<RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl>
|
<RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl>
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegrator.Core;
|
using Telegrator.Core;
|
||||||
|
using Telegrator.Hosting;
|
||||||
using Telegrator.Hosting.Web;
|
using Telegrator.Hosting.Web;
|
||||||
using Telegrator.Mediation;
|
using Telegrator.Mediation;
|
||||||
using Telegrator.Providers;
|
using Telegrator.Providers;
|
||||||
@@ -24,28 +27,34 @@ namespace Telegrator
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public const string HandlersCollectionPropertyKey = nameof(IHandlersCollection);
|
public const string HandlersCollectionPropertyKey = nameof(IHandlersCollection);
|
||||||
|
|
||||||
extension(WebApplicationBuilder builder)
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the <see cref="IHandlersCollection"/> from the builder properties.
|
/// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IHandlersCollection Handlers
|
public static ITelegramBotHostBuilder AddTelegratorWeb(this ITelegramBotHostBuilder builder, TelegratorOptions? options = null, IHandlersCollection? handlers = null, Action<ITelegramBotHostBuilder>? action = null)
|
||||||
{
|
{
|
||||||
get
|
AddTelegratorWebInternal(builder.Services, builder.Configuration, builder.Properties, ref handlers, options);
|
||||||
{
|
if (builder is TelegramBotWebHostBuilder telegramBotHostBuilder)
|
||||||
return (IHandlersCollection)builder.Host.Properties[HandlersCollectionPropertyKey];
|
telegramBotHostBuilder._handlers = handlers;
|
||||||
}
|
|
||||||
}
|
action?.Invoke(builder);
|
||||||
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
|
/// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static IHostApplicationBuilder AddTelegratorWeb(this IHostApplicationBuilder builder, TelegratorOptions? options = null, IHandlersCollection? handlers = null)
|
public static IHostApplicationBuilder AddTelegratorWeb(this WebApplicationBuilder builder, TelegratorOptions? options = null, IHandlersCollection? handlers = null, Action<ITelegramBotHostBuilder>? action = null)
|
||||||
{
|
{
|
||||||
IServiceCollection services = builder.Services;
|
AddTelegratorWebInternal(builder.Services, builder.Configuration, ((IHostApplicationBuilder)builder).Properties, ref handlers, options);
|
||||||
IConfigurationManager configuration = builder.Configuration;
|
action?.Invoke(new TelegramBotWebHostBuilder(builder, handlers));
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
|
||||||
|
/// </summary>
|
||||||
|
internal static void AddTelegratorWebInternal(IServiceCollection services, IConfiguration configuration, IDictionary<object, object> properties, [NotNull] ref IHandlersCollection? handlers, TelegratorOptions? options = null)
|
||||||
|
{
|
||||||
if (options == null)
|
if (options == null)
|
||||||
{
|
{
|
||||||
options = configuration.GetSection(nameof(TelegratorOptions)).Get<TelegratorOptions>();
|
options = configuration.GetSection(nameof(TelegratorOptions)).Get<TelegratorOptions>();
|
||||||
@@ -70,10 +79,7 @@ namespace Telegrator
|
|||||||
|
|
||||||
handlers ??= new HostHandlersCollection(services, options);
|
handlers ??= new HostHandlersCollection(services, options);
|
||||||
services.AddSingleton(handlers);
|
services.AddSingleton(handlers);
|
||||||
|
properties.Add(HandlersCollectionPropertyKey, handlers);
|
||||||
builder.Properties.Add(HandlersCollectionPropertyKey, handlers);
|
|
||||||
if (builder is TelegramBotWebHostBuilder botHostBuilder)
|
|
||||||
botHostBuilder._handlers = handlers;
|
|
||||||
|
|
||||||
if (!services.Any(srvc => srvc.ImplementationType == typeof(IOptions<WebhookerOptions>)))
|
if (!services.Any(srvc => srvc.ImplementationType == typeof(IOptions<WebhookerOptions>)))
|
||||||
{
|
{
|
||||||
@@ -95,18 +101,32 @@ namespace Telegrator
|
|||||||
|
|
||||||
services.AddTelegramBotHostDefaults();
|
services.AddTelegramBotHostDefaults();
|
||||||
services.AddTelegramWebhook();
|
services.AddTelegramWebhook();
|
||||||
return builder;
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Searchs for <see cref="HostedUpdateWebhooker"/> hosted service inside hosts services
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="services"></param>
|
||||||
|
/// <param name="webhooker"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool TryFindWebhooker(this IServiceProvider services, [NotNullWhen(true)] out HostedUpdateWebhooker? webhooker)
|
||||||
|
{
|
||||||
|
webhooker = services.GetServices<IHostedService>().FirstOrDefault(s => s is HostedUpdateWebhooker) as HostedUpdateWebhooker;
|
||||||
|
return webhooker != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Replaces the initialization logic from TelegramBotWebHost constructor.
|
/// Replaces the initialization logic from TelegramBotWebHost constructor.
|
||||||
/// Initializes the bot and logs handlers on application startup.
|
/// Initializes the bot and logs handlers on application startup.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static WebApplication UseTelegratorWeb(this WebApplication app)
|
public static T UseTelegratorWeb<T>(this T app, bool dontMap = false) where T : IEndpointRouteBuilder, IHost
|
||||||
{
|
{
|
||||||
ITelegramBotInfo info = app.Services.GetRequiredService<ITelegramBotInfo>();
|
if (!app.ServiceProvider.TryFindWebhooker(out HostedUpdateWebhooker? webhooker))
|
||||||
IHandlersCollection handlers = app.Services.GetRequiredService<IHandlersCollection>();
|
throw new InvalidOperationException("No service for type 'Telegrator.Mediation.HostedUpdateWebhooker' has been registered.");
|
||||||
ILoggerFactory loggerFactory = app.Services.GetRequiredService<ILoggerFactory>();
|
|
||||||
|
ITelegramBotInfo info = app.ServiceProvider.GetRequiredService<ITelegramBotInfo>();
|
||||||
|
IHandlersCollection handlers = app.ServiceProvider.GetRequiredService<IHandlersCollection>();
|
||||||
|
ILoggerFactory loggerFactory = app.ServiceProvider.GetRequiredService<ILoggerFactory>();
|
||||||
ILogger logger = loggerFactory.CreateLogger("Telegrator.Hosting.Web.TelegratorHost");
|
ILogger logger = loggerFactory.CreateLogger("Telegrator.Hosting.Web.TelegratorHost");
|
||||||
|
|
||||||
if (logger.IsEnabled(LogLevel.Information))
|
if (logger.IsEnabled(LogLevel.Information))
|
||||||
@@ -116,6 +136,25 @@ namespace Telegrator
|
|||||||
logger.LogHandlers(handlers);
|
logger.LogHandlers(handlers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!dontMap)
|
||||||
|
webhooker.MapWebhook(app);
|
||||||
|
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allows to remap receiving webhook endpoint and map new route to webhost.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="app"></param>
|
||||||
|
/// <param name="webhookUri"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <exception cref="ArgumentException"></exception>
|
||||||
|
public static T RemapWebhook<T>(this T app, string webhookUri) where T : IEndpointRouteBuilder, IHost
|
||||||
|
{
|
||||||
|
if (!app.ServiceProvider.TryFindWebhooker(out HostedUpdateWebhooker? webhooker))
|
||||||
|
throw new InvalidOperationException("No service for type 'Telegrator.Mediation.HostedUpdateWebhooker' has been registered.");
|
||||||
|
|
||||||
|
webhooker.RemapWebhook(app, webhookUri, default).GetAwaiter().GetResult();
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
[assembly: SuppressMessage("Style", "IDE0090")]
|
[assembly: SuppressMessage("Style", "IDE0090")]
|
||||||
[assembly: SuppressMessage("Usage", "CA2254")]
|
[assembly: SuppressMessage("Usage", "CA2254")]
|
||||||
[assembly: SuppressMessage("Maintainability", "CA1510")]
|
[assembly: SuppressMessage("Maintainability", "CA1510")]
|
||||||
|
[assembly: SuppressMessage("Style", "IDE0270")]
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ using Telegram.Bot;
|
|||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegrator.Core;
|
using Telegrator.Core;
|
||||||
|
|
||||||
namespace Telegrator.Hosting
|
namespace Telegrator.Hosting;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implementation of <see cref="ITelegramBotInfo"/> that provides bot information.
|
/// Implementation of <see cref="ITelegramBotInfo"/> that provides bot information.
|
||||||
/// Contains metadata about the Telegram bot including user details and service provider for wider filterring abilities
|
/// Contains metadata about the Telegram bot including user details and service provider for wider filterring abilities
|
||||||
@@ -12,7 +12,7 @@ namespace Telegrator.Hosting
|
|||||||
/// <param name="client"></param>
|
/// <param name="client"></param>
|
||||||
/// <param name="services"></param>
|
/// <param name="services"></param>
|
||||||
/// <param name="configuration"></param>
|
/// <param name="configuration"></param>
|
||||||
public class HostedTelegramBotInfo(ITelegramBotClient client, IServiceProvider services, IConfigurationManager configuration) : ITelegramBotInfo
|
public class HostedTelegramBotInfo(ITelegramBotClient client, IServiceProvider services, IConfiguration configuration) : ITelegramBotInfo
|
||||||
{
|
{
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public User User { get; } = client.GetMe().Result;
|
public User User { get; } = client.GetMe().Result;
|
||||||
@@ -25,6 +25,5 @@ namespace Telegrator.Hosting
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides access to configuration of this Hosted telegram bot
|
/// Provides access to configuration of this Hosted telegram bot
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IConfigurationManager Configuration { get; } = configuration;
|
public IConfiguration Configuration { get; } = configuration;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,12 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Telegrator.Core;
|
using Telegrator.Core;
|
||||||
|
|
||||||
namespace Telegrator.Hosting
|
namespace Telegrator.Hosting;
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Interface for building Telegram bot hosts with dependency injection support.
|
|
||||||
/// Combines host application building capabilities with handler collection functionality.
|
|
||||||
/// </summary>
|
|
||||||
public interface ITelegramBotHostBuilder : ICollectingProvider
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the set of key/value configuration properties.
|
|
||||||
/// </summary>
|
|
||||||
IConfigurationManager Configuration { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a collection of logging providers for the application to compose. This is useful for adding new logging providers.
|
/// Represents a hosted telegram bots and services builder that helps manage configuration, logging, lifetime, and more.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
ILoggingBuilder Logging { get; }
|
public interface ITelegramBotHostBuilder : IHostApplicationBuilder, ICollectingProvider
|
||||||
|
{
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a collection of services for the application to compose. This is useful for adding user provided or framework provided services.
|
|
||||||
/// </summary>
|
|
||||||
IServiceCollection Services { get; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,23 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Telegrator.Core;
|
using Telegrator.Core;
|
||||||
|
|
||||||
namespace Telegrator.Hosting
|
namespace Telegrator.Hosting;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a hosted telegram bot
|
/// Represents a hosted telegram bot
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TelegramBotHost : IHost, ITelegratorBot
|
public class TelegramBotHost : IHost, ITelegratorBot
|
||||||
{
|
{
|
||||||
private readonly IHost _innerHost;
|
private readonly IHost _innerHost;
|
||||||
private readonly IServiceProvider _serviceProvider;
|
|
||||||
private readonly IUpdateRouter _updateRouter;
|
private readonly IUpdateRouter _updateRouter;
|
||||||
private readonly ILogger<TelegramBotHost> _logger;
|
private readonly ILogger<TelegramBotHost> _logger;
|
||||||
|
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IServiceProvider Services => _serviceProvider;
|
public IServiceProvider Services => _innerHost.Services;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IUpdateRouter UpdateRouter => _updateRouter;
|
public IUpdateRouter UpdateRouter => _updateRouter;
|
||||||
@@ -40,8 +38,6 @@ namespace Telegrator.Hosting
|
|||||||
|
|
||||||
// Building proxy hoster
|
// Building proxy hoster
|
||||||
_innerHost = hostApplicationBuilder.Build();
|
_innerHost = hostApplicationBuilder.Build();
|
||||||
_serviceProvider = _innerHost.Services;
|
|
||||||
_innerHost.UseTelegrator();
|
|
||||||
|
|
||||||
// Reruesting services for this host
|
// Reruesting services for this host
|
||||||
_updateRouter = Services.GetRequiredService<IUpdateRouter>();
|
_updateRouter = Services.GetRequiredService<IUpdateRouter>();
|
||||||
@@ -55,10 +51,7 @@ namespace Telegrator.Hosting
|
|||||||
public static TelegramBotHostBuilder CreateBuilder()
|
public static TelegramBotHostBuilder CreateBuilder()
|
||||||
{
|
{
|
||||||
HostApplicationBuilder innerBuilder = new HostApplicationBuilder(settings: null);
|
HostApplicationBuilder innerBuilder = new HostApplicationBuilder(settings: null);
|
||||||
TelegramBotHostBuilder builder = new TelegramBotHostBuilder(innerBuilder, null);
|
TelegramBotHostBuilder builder = new TelegramBotHostBuilder(innerBuilder);
|
||||||
|
|
||||||
builder.Services.AddTelegramBotHostDefaults();
|
|
||||||
builder.Services.AddTelegramReceiver();
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,10 +62,7 @@ namespace Telegrator.Hosting
|
|||||||
public static TelegramBotHostBuilder CreateBuilder(HostApplicationBuilderSettings? settings)
|
public static TelegramBotHostBuilder CreateBuilder(HostApplicationBuilderSettings? settings)
|
||||||
{
|
{
|
||||||
HostApplicationBuilder innerBuilder = new HostApplicationBuilder(settings);
|
HostApplicationBuilder innerBuilder = new HostApplicationBuilder(settings);
|
||||||
TelegramBotHostBuilder builder = new TelegramBotHostBuilder(innerBuilder, settings);
|
TelegramBotHostBuilder builder = new TelegramBotHostBuilder(innerBuilder);
|
||||||
|
|
||||||
builder.Services.AddTelegramBotHostDefaults();
|
|
||||||
builder.Services.AddTelegramReceiver();
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +73,7 @@ namespace Telegrator.Hosting
|
|||||||
public static TelegramBotHostBuilder CreateEmptyBuilder()
|
public static TelegramBotHostBuilder CreateEmptyBuilder()
|
||||||
{
|
{
|
||||||
HostApplicationBuilder innerBuilder = Host.CreateEmptyApplicationBuilder(null);
|
HostApplicationBuilder innerBuilder = Host.CreateEmptyApplicationBuilder(null);
|
||||||
return new TelegramBotHostBuilder(innerBuilder, null);
|
return new TelegramBotHostBuilder(innerBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -92,8 +82,8 @@ namespace Telegrator.Hosting
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static TelegramBotHostBuilder CreateEmptyBuilder(HostApplicationBuilderSettings? settings)
|
public static TelegramBotHostBuilder CreateEmptyBuilder(HostApplicationBuilderSettings? settings)
|
||||||
{
|
{
|
||||||
HostApplicationBuilder innerBuilder = Host.CreateEmptyApplicationBuilder(null);
|
HostApplicationBuilder innerBuilder = Host.CreateEmptyApplicationBuilder(settings);
|
||||||
return new TelegramBotHostBuilder(innerBuilder, settings);
|
return new TelegramBotHostBuilder(innerBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@@ -122,4 +112,3 @@ namespace Telegrator.Hosting
|
|||||||
_disposed = true;
|
_disposed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,20 +1,17 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Diagnostics.Metrics;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Telegrator.Core;
|
using Telegrator.Core;
|
||||||
using Telegrator.Providers;
|
|
||||||
|
|
||||||
#pragma warning disable IDE0001
|
#pragma warning disable IDE0001
|
||||||
namespace Telegrator.Hosting
|
namespace Telegrator.Hosting;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <inheritdoc/>
|
||||||
/// Represents a hosted telegram bots and services builder that helps manage configuration, logging, lifetime, and more.
|
public class TelegramBotHostBuilder : ITelegramBotHostBuilder
|
||||||
/// </summary>
|
|
||||||
public class TelegramBotHostBuilder : ICollectingProvider
|
|
||||||
{
|
{
|
||||||
private readonly HostApplicationBuilder _innerBuilder;
|
private readonly HostApplicationBuilder _innerBuilder;
|
||||||
private readonly HostApplicationBuilderSettings _settings;
|
|
||||||
internal IHandlersCollection _handlers = null!;
|
internal IHandlersCollection _handlers = null!;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@@ -32,18 +29,19 @@ namespace Telegrator.Hosting
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IHostEnvironment Environment => _innerBuilder.Environment;
|
public IHostEnvironment Environment => _innerBuilder.Environment;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public IDictionary<object, object> Properties => ((IHostApplicationBuilder)_innerBuilder).Properties;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public IMetricsBuilder Metrics => _innerBuilder.Metrics;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="TelegramBotHostBuilder"/> class.
|
/// Initializes a new instance of the <see cref="TelegramBotHostBuilder"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="hostApplicationBuilder"></param>
|
/// <param name="hostApplicationBuilder"></param>
|
||||||
/// <param name="settings"></param>
|
public TelegramBotHostBuilder(HostApplicationBuilder hostApplicationBuilder)
|
||||||
public TelegramBotHostBuilder(HostApplicationBuilder hostApplicationBuilder, HostApplicationBuilderSettings? settings = null)
|
|
||||||
{
|
{
|
||||||
_innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder));
|
_innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder));
|
||||||
_settings = settings ?? new HostApplicationBuilderSettings();
|
|
||||||
|
|
||||||
_innerBuilder.AddTelegrator();
|
|
||||||
_innerBuilder.Logging.ClearProviders();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -51,14 +49,10 @@ namespace Telegrator.Hosting
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="hostApplicationBuilder"></param>
|
/// <param name="hostApplicationBuilder"></param>
|
||||||
/// <param name="handlers"></param>
|
/// <param name="handlers"></param>
|
||||||
/// <param name="settings"></param>
|
public TelegramBotHostBuilder(HostApplicationBuilder hostApplicationBuilder, IHandlersCollection handlers)
|
||||||
public TelegramBotHostBuilder(HostApplicationBuilder hostApplicationBuilder, IHandlersCollection handlers, HostApplicationBuilderSettings? settings = null)
|
|
||||||
{
|
{
|
||||||
_innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder));
|
_innerBuilder = hostApplicationBuilder ?? throw new ArgumentNullException(nameof(hostApplicationBuilder));
|
||||||
_settings = settings ?? new HostApplicationBuilderSettings();
|
_handlers = handlers ?? throw new ArgumentNullException(nameof(handlers));
|
||||||
|
|
||||||
_innerBuilder.AddTelegrator(null, handlers);
|
|
||||||
_innerBuilder.Logging.ClearProviders();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -71,5 +65,10 @@ namespace Telegrator.Hosting
|
|||||||
host.UseTelegrator();
|
host.UseTelegrator();
|
||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public void ConfigureContainer<TContainerBuilder>(IServiceProviderFactory<TContainerBuilder> factory, Action<TContainerBuilder>? configure = null) where TContainerBuilder : notnull
|
||||||
|
{
|
||||||
|
_innerBuilder.ConfigureContainer(factory, configure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,18 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
namespace Telegrator.Logging;
|
||||||
|
|
||||||
namespace Telegrator.Logging
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adapter for Microsoft.Extensions.Logging to work with Telegrator logging system.
|
/// Adapter for Microsoft.Extensions.Logging to work with Telegrator logging system.
|
||||||
/// This allows seamless integration with ASP.NET Core logging infrastructure.
|
/// This allows seamless integration with ASP.NET Core logging infrastructure.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MicrosoftLoggingAdapter : ITelegratorLogger
|
public class MicrosoftLoggingAdapter : ITelegratorLogger
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly Microsoft.Extensions.Logging.ILogger _logger;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of MicrosoftLoggingAdapter.
|
/// Initializes a new instance of MicrosoftLoggingAdapter.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="logger">The Microsoft.Extensions.Logging logger instance.</param>
|
/// <param name="logger">The Microsoft.Extensions.Logging logger instance.</param>
|
||||||
public MicrosoftLoggingAdapter(ILogger logger)
|
public MicrosoftLoggingAdapter(Microsoft.Extensions.Logging.ILogger logger)
|
||||||
{
|
{
|
||||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||||
}
|
}
|
||||||
@@ -24,11 +22,11 @@ namespace Telegrator.Logging
|
|||||||
{
|
{
|
||||||
var msLogLevel = level switch
|
var msLogLevel = level switch
|
||||||
{
|
{
|
||||||
Telegrator.Logging.LogLevel.Trace => Microsoft.Extensions.Logging.LogLevel.Trace,
|
LogLevel.Trace => Microsoft.Extensions.Logging.LogLevel.Trace,
|
||||||
Telegrator.Logging.LogLevel.Debug => Microsoft.Extensions.Logging.LogLevel.Debug,
|
LogLevel.Debug => Microsoft.Extensions.Logging.LogLevel.Debug,
|
||||||
Telegrator.Logging.LogLevel.Information => Microsoft.Extensions.Logging.LogLevel.Information,
|
LogLevel.Information => Microsoft.Extensions.Logging.LogLevel.Information,
|
||||||
Telegrator.Logging.LogLevel.Warning => Microsoft.Extensions.Logging.LogLevel.Warning,
|
LogLevel.Warning => Microsoft.Extensions.Logging.LogLevel.Warning,
|
||||||
Telegrator.Logging.LogLevel.Error => Microsoft.Extensions.Logging.LogLevel.Error,
|
LogLevel.Error => Microsoft.Extensions.Logging.LogLevel.Error,
|
||||||
_ => Microsoft.Extensions.Logging.LogLevel.Information
|
_ => Microsoft.Extensions.Logging.LogLevel.Information
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -42,4 +40,3 @@ namespace Telegrator.Logging
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using Microsoft.Extensions.Options;
|
|
||||||
using Telegrator.Core;
|
|
||||||
using Telegrator.Mediation;
|
|
||||||
|
|
||||||
namespace Telegrator.Polling
|
|
||||||
{
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public class HostUpdateHandlersPool(IUpdateRouter router, IOptions<TelegratorOptions> options)
|
|
||||||
: UpdateHandlersPool(router, options.Value, options.Value.GlobalCancellationToken)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,10 +4,11 @@ using Telegram.Bot;
|
|||||||
using Telegram.Bot.Polling;
|
using Telegram.Bot.Polling;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegrator.Core;
|
using Telegrator.Core;
|
||||||
|
using Telegrator.Core.States;
|
||||||
using Telegrator.Mediation;
|
using Telegrator.Mediation;
|
||||||
|
|
||||||
namespace Telegrator.Polling
|
namespace Telegrator.Polling;
|
||||||
{
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public class HostUpdateRouter : UpdateRouter
|
public class HostUpdateRouter : UpdateRouter
|
||||||
{
|
{
|
||||||
@@ -20,10 +21,10 @@ namespace Telegrator.Polling
|
|||||||
public HostUpdateRouter(
|
public HostUpdateRouter(
|
||||||
IHandlersProvider handlersProvider,
|
IHandlersProvider handlersProvider,
|
||||||
IAwaitingProvider awaitingProvider,
|
IAwaitingProvider awaitingProvider,
|
||||||
|
IStateStorage stateStorage,
|
||||||
IOptions<TelegratorOptions> options,
|
IOptions<TelegratorOptions> options,
|
||||||
IUpdateHandlersPool handlersPool,
|
|
||||||
ITelegramBotInfo botInfo,
|
ITelegramBotInfo botInfo,
|
||||||
ILogger<HostUpdateRouter> logger) : base(handlersProvider, awaitingProvider, options.Value, handlersPool, botInfo)
|
ILogger<HostUpdateRouter> logger) : base(handlersProvider, awaitingProvider, stateStorage, options.Value, botInfo)
|
||||||
{
|
{
|
||||||
Logger = logger;
|
Logger = logger;
|
||||||
ExceptionHandler = new DefaultRouterExceptionHandler(HandleException);
|
ExceptionHandler = new DefaultRouterExceptionHandler(HandleException);
|
||||||
@@ -56,4 +57,3 @@ namespace Telegrator.Polling
|
|||||||
Logger.LogError("Exception was thrown during update routing faulted :\n{exception}", exception.ToString());
|
Logger.LogError("Exception was thrown during update routing faulted :\n{exception}", exception.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ using Telegram.Bot.Polling;
|
|||||||
using Telegrator.Core;
|
using Telegrator.Core;
|
||||||
using Telegrator.Mediation;
|
using Telegrator.Mediation;
|
||||||
|
|
||||||
namespace Telegrator.Polling
|
namespace Telegrator.Polling;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Service for receiving updates for Hosted telegram bots
|
/// Service for receiving updates for Hosted telegram bots
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -25,8 +25,10 @@ namespace Telegrator.Polling
|
|||||||
{
|
{
|
||||||
logger.LogInformation("Starting receiving updates via long-polling");
|
logger.LogInformation("Starting receiving updates via long-polling");
|
||||||
_receiverOptions.AllowedUpdates = _updateRouter.HandlersProvider.AllowedTypes.ToArray();
|
_receiverOptions.AllowedUpdates = _updateRouter.HandlersProvider.AllowedTypes.ToArray();
|
||||||
|
|
||||||
|
botClient.DeleteWebhook(options.Value.DropPendingUpdates).Wait();
|
||||||
|
|
||||||
DefaultUpdateReceiver updateReceiver = new DefaultUpdateReceiver(botClient, _receiverOptions);
|
DefaultUpdateReceiver updateReceiver = new DefaultUpdateReceiver(botClient, _receiverOptions);
|
||||||
await updateReceiver.ReceiveAsync(_updateRouter, stoppingToken).ConfigureAwait(false);
|
await updateReceiver.ReceiveAsync(_updateRouter, stoppingToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Options;
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
|
namespace Telegrator.Providers;
|
||||||
|
|
||||||
namespace Telegrator.Providers
|
|
||||||
{
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public class HostAwaitingProvider(IOptions<TelegratorOptions> options, ILogger<HostAwaitingProvider> logger) : AwaitingProvider(options.Value)
|
public class HostAwaitingProvider(IOptions<TelegratorOptions> options) : AwaitingProvider(options.Value)
|
||||||
{
|
{
|
||||||
private readonly ILogger<HostAwaitingProvider> _logger = logger;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
using Telegrator.Core;
|
using Telegrator.Core;
|
||||||
using Telegrator.Core.Descriptors;
|
using Telegrator.Core.Descriptors;
|
||||||
|
|
||||||
namespace Telegrator.Providers
|
namespace Telegrator.Providers;
|
||||||
{
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public class HostHandlersCollection(IServiceCollection hostServiceColletion, TelegratorOptions options) : HandlersCollection(options)
|
public class HostHandlersCollection(IServiceCollection hostServiceColletion, TelegratorOptions options) : HandlersCollection(options)
|
||||||
{
|
{
|
||||||
@@ -59,4 +59,3 @@ namespace Telegrator.Providers
|
|||||||
return base.AddDescriptor(descriptor);
|
return base.AddDescriptor(descriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,27 +1,23 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Telegrator.Core;
|
using Telegrator.Core;
|
||||||
using Telegrator.Core.Descriptors;
|
using Telegrator.Core.Descriptors;
|
||||||
using Telegrator.Core.Handlers;
|
using Telegrator.Core.Handlers;
|
||||||
|
|
||||||
namespace Telegrator.Providers
|
namespace Telegrator.Providers;
|
||||||
{
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public class HostHandlersProvider : HandlersProvider
|
public class HostHandlersProvider : HandlersProvider
|
||||||
{
|
{
|
||||||
private readonly IServiceProvider Services;
|
private readonly IServiceProvider Services;
|
||||||
private readonly ILogger<HostHandlersProvider> Logger;
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public HostHandlersProvider(
|
public HostHandlersProvider(
|
||||||
IHandlersCollection handlers,
|
IHandlersCollection handlers,
|
||||||
IOptions<TelegratorOptions> options,
|
IOptions<TelegratorOptions> options,
|
||||||
IServiceProvider serviceProvider,
|
IServiceProvider serviceProvider) : base(handlers, options.Value)
|
||||||
ILogger<HostHandlersProvider> logger) : base(handlers, options.Value)
|
|
||||||
{
|
{
|
||||||
Services = serviceProvider;
|
Services = serviceProvider;
|
||||||
Logger = logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@@ -42,4 +38,3 @@ namespace Telegrator.Providers
|
|||||||
return updateHandler;
|
return updateHandler;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||||
|
|
||||||
<Title>Telegrator.Hosting</Title>
|
<Title>Telegrator.Hosting</Title>
|
||||||
<Version>1.16.1</Version>
|
<Version>1.16.9</Version>
|
||||||
<Authors>Rikitav Tim4ik</Authors>
|
<Authors>Rikitav Tim4ik</Authors>
|
||||||
<Company>Rikitav Tim4ik</Company>
|
<Company>Rikitav Tim4ik</Company>
|
||||||
<RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl>
|
<RepositoryUrl>https://github.com/Rikitav/Telegrator</RepositoryUrl>
|
||||||
@@ -31,8 +31,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.3" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.7" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.3" />
|
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.7" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
|
|||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Polling;
|
using Telegram.Bot.Polling;
|
||||||
@@ -11,10 +12,12 @@ using Telegram.Bot.Types;
|
|||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
using Telegrator.Core;
|
using Telegrator.Core;
|
||||||
using Telegrator.Core.Descriptors;
|
using Telegrator.Core.Descriptors;
|
||||||
|
using Telegrator.Core.States;
|
||||||
using Telegrator.Hosting;
|
using Telegrator.Hosting;
|
||||||
using Telegrator.Logging;
|
using Telegrator.Logging;
|
||||||
using Telegrator.Polling;
|
using Telegrator.Polling;
|
||||||
using Telegrator.Providers;
|
using Telegrator.Providers;
|
||||||
|
using Telegrator.States;
|
||||||
|
|
||||||
namespace Telegrator;
|
namespace Telegrator;
|
||||||
|
|
||||||
@@ -28,31 +31,52 @@ public static class HostBuilderExtensions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public const string HandlersCollectionPropertyKey = nameof(IHandlersCollection);
|
public const string HandlersCollectionPropertyKey = nameof(IHandlersCollection);
|
||||||
|
|
||||||
extension (IHostApplicationBuilder builder)
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the <see cref="IHandlersCollection"/> from the builder properties.
|
/// Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IHandlersCollection Handlers
|
public static ITelegramBotHostBuilder AddTelegrator(this ITelegramBotHostBuilder builder, TelegratorOptions? options = null, IHandlersCollection? handlers = null, Action<ITelegramBotHostBuilder>? action = null)
|
||||||
{
|
{
|
||||||
get
|
AddTelegratorInternal(builder.Services, builder.Configuration, builder.Properties, ref handlers, options);
|
||||||
{
|
if (builder is TelegramBotHostBuilder telegramBotHostBuilder)
|
||||||
if (builder is TelegramBotHostBuilder botHostBuilder)
|
telegramBotHostBuilder._handlers = handlers;
|
||||||
return botHostBuilder.Handlers;
|
|
||||||
|
|
||||||
return (IHandlersCollection)builder.Properties[HandlersCollectionPropertyKey];
|
action?.Invoke(builder);
|
||||||
}
|
return builder;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Replaces TelegramBotWebHostBuilder. Configures DI, options, and handlers.
|
/// Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
|
||||||
|
/// </summary>
|
||||||
|
public static IHostApplicationBuilder AddTelegrator(this HostApplicationBuilder builder, TelegratorOptions? options = null, IHandlersCollection? handlers = null, Action<ITelegramBotHostBuilder>? action = null)
|
||||||
|
{
|
||||||
|
AddTelegratorInternal(builder.Services, builder.Configuration, ((IHostApplicationBuilder)builder).Properties, ref handlers, options);
|
||||||
|
action?.Invoke(new TelegramBotHostBuilder(builder, handlers));
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static IHostApplicationBuilder AddTelegrator(this IHostApplicationBuilder builder, TelegratorOptions? options = null, IHandlersCollection? handlers = null)
|
public static IHostApplicationBuilder AddTelegrator(this IHostApplicationBuilder builder, TelegratorOptions? options = null, IHandlersCollection? handlers = null)
|
||||||
{
|
{
|
||||||
IServiceCollection services = builder.Services;
|
AddTelegratorInternal(builder.Services, builder.Configuration, builder.Properties, ref handlers, options);
|
||||||
IConfigurationManager configuration = builder.Configuration;
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
|
||||||
|
/// </summary>
|
||||||
|
public static IHostBuilder AddTelegrator(this IHostBuilder builder, TelegratorOptions? options = null, IHandlersCollection? handlers = null)
|
||||||
|
{
|
||||||
|
builder.ConfigureServices((ctx, sp) => AddTelegratorInternal(sp, ctx.Configuration, builder.Properties, ref handlers, options));
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Replaces TelegramBotHostBuilder. Configures DI, options, and handlers.
|
||||||
|
/// </summary>
|
||||||
|
internal static void AddTelegratorInternal(IServiceCollection services, IConfiguration configuration, IDictionary<object, object> properties, [NotNull] ref IHandlersCollection? handlers, TelegratorOptions? options = null)
|
||||||
|
{
|
||||||
if (options == null)
|
if (options == null)
|
||||||
{
|
{
|
||||||
options = configuration.GetSection(nameof(TelegratorOptions)).Get<TelegratorOptions>();
|
options = configuration.GetSection(nameof(TelegratorOptions)).Get<TelegratorOptions>();
|
||||||
@@ -77,10 +101,7 @@ public static class HostBuilderExtensions
|
|||||||
|
|
||||||
handlers ??= new HostHandlersCollection(services, options);
|
handlers ??= new HostHandlersCollection(services, options);
|
||||||
services.AddSingleton(handlers);
|
services.AddSingleton(handlers);
|
||||||
|
properties.Add(HandlersCollectionPropertyKey, handlers);
|
||||||
builder.Properties.Add(HandlersCollectionPropertyKey, handlers);
|
|
||||||
if (builder is TelegramBotHostBuilder botHostBuilder)
|
|
||||||
botHostBuilder._handlers = handlers;
|
|
||||||
|
|
||||||
if (!services.Any(srvc => srvc.ImplementationType == typeof(IOptions<ReceiverOptions>)))
|
if (!services.Any(srvc => srvc.ImplementationType == typeof(IOptions<ReceiverOptions>)))
|
||||||
{
|
{
|
||||||
@@ -100,9 +121,8 @@ public static class HostBuilderExtensions
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
services.AddTelegramReceiver();
|
|
||||||
services.AddTelegramBotHostDefaults();
|
services.AddTelegramBotHostDefaults();
|
||||||
return builder;
|
services.AddTelegramReceiver();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,6 +132,18 @@ public static class HostBuilderExtensions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ServicesCollectionExtensions
|
public static class ServicesCollectionExtensions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Registers <see cref="IStateStorage"/> service
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TStorage"></typeparam>
|
||||||
|
/// <param name="services"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IServiceCollection AddStateStorage<TStorage>(this IServiceCollection services) where TStorage : IStateStorage
|
||||||
|
{
|
||||||
|
services.Replace(new ServiceDescriptor(typeof(IStateStorage), typeof(TStorage), ServiceLifetime.Singleton));
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Registers <see cref="TelegramBotHost"/> default services
|
/// Registers <see cref="TelegramBotHost"/> default services
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -119,12 +151,11 @@ public static class ServicesCollectionExtensions
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IServiceCollection AddTelegramBotHostDefaults(this IServiceCollection services)
|
public static IServiceCollection AddTelegramBotHostDefaults(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddLogging(builder => builder.AddConsole().AddDebug());
|
|
||||||
services.AddSingleton<IUpdateHandlersPool, HostUpdateHandlersPool>();
|
|
||||||
services.AddSingleton<IAwaitingProvider, HostAwaitingProvider>();
|
services.AddSingleton<IAwaitingProvider, HostAwaitingProvider>();
|
||||||
services.AddSingleton<IHandlersProvider, HostHandlersProvider>();
|
services.AddSingleton<IHandlersProvider, HostHandlersProvider>();
|
||||||
services.AddSingleton<IUpdateRouter, HostUpdateRouter>();
|
services.AddSingleton<IUpdateRouter, HostUpdateRouter>();
|
||||||
services.AddSingleton<ITelegramBotInfo, HostedTelegramBotInfo>();
|
services.AddSingleton<ITelegramBotInfo, HostedTelegramBotInfo>();
|
||||||
|
services.AddSingleton<IStateStorage, DefaultStateStorage>();
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ using System.Threading.Tasks;
|
|||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegrator.Handlers;
|
using Telegrator.Handlers;
|
||||||
|
|
||||||
namespace Telegrator.Localized
|
namespace Telegrator.Localized;
|
||||||
{
|
|
||||||
public static class LocalizedMessageHandlerExtensions
|
public static class LocalizedMessageHandlerExtensions
|
||||||
{
|
{
|
||||||
public static async Task<Message> ResponseLocalized(this ILocalizedHandler<Message> localizedHandler, string localizedReplyIdentifier, params IEnumerable<string> formatArgs)
|
public static async Task<Message> ResponseLocalized(this ILocalizedHandler<Message> localizedHandler, string localizedReplyIdentifier, params IEnumerable<string> formatArgs)
|
||||||
@@ -14,4 +14,3 @@ namespace Telegrator.Localized
|
|||||||
return await localizedHandler.Container.Responce(localizedString.Value);
|
return await localizedHandler.Container.Responce(localizedString.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.1</TargetFramework>
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="10.0.2" />
|
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="10.0.7" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ using Telegrator.Attributes;
|
|||||||
using Telegrator.Core.Filters;
|
using Telegrator.Core.Filters;
|
||||||
using Telegrator.Filters;
|
using Telegrator.Filters;
|
||||||
|
|
||||||
namespace Telegrator.Annotations
|
namespace Telegrator.Annotations;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Abstract base attribute for filtering callback-based updates.
|
/// Abstract base attribute for filtering callback-based updates.
|
||||||
/// Supports various message types including regular messages, edited messages, channel posts, and business messages.
|
/// Supports various message types including regular messages, edited messages, channel posts, and business messages.
|
||||||
@@ -41,4 +41,3 @@ namespace Telegrator.Annotations
|
|||||||
public class CallbackInlineIdAttribute(string inlineMessageId)
|
public class CallbackInlineIdAttribute(string inlineMessageId)
|
||||||
: CallbackQueryAttribute(new CallbackInlineIdFilter(inlineMessageId))
|
: CallbackQueryAttribute(new CallbackInlineIdFilter(inlineMessageId))
|
||||||
{ }
|
{ }
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ using Telegram.Bot.Types.Enums;
|
|||||||
using Telegrator.Filters;
|
using Telegrator.Filters;
|
||||||
using Telegrator.Attributes;
|
using Telegrator.Attributes;
|
||||||
|
|
||||||
namespace Telegrator.Annotations
|
namespace Telegrator.Annotations;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attribute for filtering messages based on command aliases.
|
/// Attribute for filtering messages based on command aliases.
|
||||||
/// Allows handlers to respond to multiple command variations using a single attribute.
|
/// Allows handlers to respond to multiple command variations using a single attribute.
|
||||||
@@ -57,4 +57,3 @@ namespace Telegrator.Annotations
|
|||||||
/// <returns>The message from the update, or null if not present.</returns>
|
/// <returns>The message from the update, or null if not present.</returns>
|
||||||
public override Message? GetFilterringTarget(Update update) => update.Message;
|
public override Message? GetFilterringTarget(Update update) => update.Message;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Telegrator.Filters;
|
using Telegrator.Filters;
|
||||||
|
|
||||||
namespace Telegrator.Annotations
|
namespace Telegrator.Annotations;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attribute for filtering messages where a command has arguments count >= <paramref name="count"/>.
|
/// Attribute for filtering messages where a command has arguments count >= <paramref name="count"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -60,4 +60,3 @@ namespace Telegrator.Annotations
|
|||||||
public class ArgumentRegexAttribute(string pattern, RegexOptions options = RegexOptions.None, int index = 0)
|
public class ArgumentRegexAttribute(string pattern, RegexOptions options = RegexOptions.None, int index = 0)
|
||||||
: MessageFilterAttribute(new ArgumentRegexFilter(pattern, options, index: index))
|
: MessageFilterAttribute(new ArgumentRegexFilter(pattern, options, index: index))
|
||||||
{ }
|
{ }
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace Telegrator.Annotations
|
namespace Telegrator.Annotations;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attribute that prevents a class from being automatically collected by the handler collection system.
|
/// Attribute that prevents a class from being automatically collected by the handler collection system.
|
||||||
/// When applied to a class, it will be excluded from domain-wide handler collection operations.
|
/// When applied to a class, it will be excluded from domain-wide handler collection operations.
|
||||||
@@ -9,4 +9,3 @@
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ using Telegrator.Filters;
|
|||||||
using Telegrator.Attributes;
|
using Telegrator.Attributes;
|
||||||
using Telegrator.Core.Filters;
|
using Telegrator.Core.Filters;
|
||||||
|
|
||||||
namespace Telegrator.Annotations
|
namespace Telegrator.Annotations;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Abstract base attribute for filtering updates based on environment conditions.
|
/// Abstract base attribute for filtering updates based on environment conditions.
|
||||||
/// Can process all types of updates and provides environment-specific filtering logic.
|
/// Can process all types of updates and provides environment-specific filtering logic.
|
||||||
@@ -82,4 +82,3 @@ namespace Telegrator.Annotations
|
|||||||
public EnvironmentVariableAttribute(string variable, StringComparison comparison)
|
public EnvironmentVariableAttribute(string variable, StringComparison comparison)
|
||||||
: base(new EnvironmentVariableFilter(variable, comparison)) { }
|
: base(new EnvironmentVariableFilter(variable, comparison)) { }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
using Telegrator.Filters;
|
using Telegrator.Filters;
|
||||||
|
|
||||||
namespace Telegrator.Annotations
|
namespace Telegrator.Annotations;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attribute for filtering messages that contain mentions.
|
/// Attribute for filtering messages that contain mentions.
|
||||||
/// Allows handlers to respond only to messages that mention the bot or specific users.
|
/// Allows handlers to respond only to messages that mention the bot or specific users.
|
||||||
@@ -37,4 +37,3 @@ namespace Telegrator.Annotations
|
|||||||
public MentionedAttribute(string mention, int offset)
|
public MentionedAttribute(string mention, int offset)
|
||||||
: base(new MessageHasEntityFilter(MessageEntityType.Mention, offset, null), new MentionedFilter(mention)) { }
|
: base(new MessageHasEntityFilter(MessageEntityType.Mention, offset, null), new MentionedFilter(mention)) { }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
using Telegrator.Filters;
|
using Telegrator.Filters;
|
||||||
|
|
||||||
namespace Telegrator.Annotations
|
namespace Telegrator.Annotations;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attribute for filtering messages sent in forum chats.
|
/// Attribute for filtering messages sent in forum chats.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -102,4 +102,3 @@ namespace Telegrator.Annotations
|
|||||||
public ChatNameAttribute(string? firstName, string? lastName)
|
public ChatNameAttribute(string? firstName, string? lastName)
|
||||||
: base(new MessageChatNameFilter(firstName, lastName)) { }
|
: base(new MessageChatNameFilter(firstName, lastName)) { }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ using Telegrator.Filters;
|
|||||||
using Telegrator.Attributes;
|
using Telegrator.Attributes;
|
||||||
using Telegrator.Core.Filters;
|
using Telegrator.Core.Filters;
|
||||||
|
|
||||||
namespace Telegrator.Annotations
|
namespace Telegrator.Annotations;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Abstract base attribute for filtering message-based updates.
|
/// Abstract base attribute for filtering message-based updates.
|
||||||
/// Supports various message types including regular messages, edited messages, channel posts, and business messages.
|
/// Supports various message types including regular messages, edited messages, channel posts, and business messages.
|
||||||
@@ -158,4 +158,3 @@ namespace Telegrator.Annotations
|
|||||||
public MessageHasEntityAttribute(MessageEntityType type, int offset, int? length, string content, StringComparison stringComparison = StringComparison.CurrentCulture)
|
public MessageHasEntityAttribute(MessageEntityType type, int offset, int? length, string content, StringComparison stringComparison = StringComparison.CurrentCulture)
|
||||||
: base(new MessageHasEntityFilter(type, offset, length, content, stringComparison)) { }
|
: base(new MessageHasEntityFilter(type, offset, length, content, stringComparison)) { }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Telegrator.Filters;
|
using Telegrator.Filters;
|
||||||
|
|
||||||
namespace Telegrator.Annotations
|
namespace Telegrator.Annotations;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attribute for filtering messages with reply to messages of this bot.
|
/// Attribute for filtering messages with reply to messages of this bot.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -24,4 +24,3 @@ namespace Telegrator.Annotations
|
|||||||
public class FromReplyChainAttribute(int replyDepth = 1)
|
public class FromReplyChainAttribute(int replyDepth = 1)
|
||||||
: MessageFilterAttribute(new FromReplyChainFilter(replyDepth))
|
: MessageFilterAttribute(new FromReplyChainFilter(replyDepth))
|
||||||
{ }
|
{ }
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Telegrator.Filters;
|
using Telegrator.Filters;
|
||||||
|
|
||||||
namespace Telegrator.Annotations
|
namespace Telegrator.Annotations;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attribute for filtering messages based on the sender's username.
|
/// Attribute for filtering messages based on the sender's username.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -89,4 +89,3 @@ namespace Telegrator.Annotations
|
|||||||
public class FromPremiumUserAttribute()
|
public class FromPremiumUserAttribute()
|
||||||
: MessageFilterAttribute(new FromPremiumUserFilter())
|
: MessageFilterAttribute(new FromPremiumUserFilter())
|
||||||
{ }
|
{ }
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Telegrator.Filters;
|
using Telegrator.Filters;
|
||||||
|
|
||||||
namespace Telegrator.Annotations
|
namespace Telegrator.Annotations;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attribute for filtering messages where the text starts with the specified content.
|
/// Attribute for filtering messages where the text starts with the specified content.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -55,4 +55,3 @@ namespace Telegrator.Annotations
|
|||||||
public class TextContainsWordAttribute(string word, StringComparison comparison = StringComparison.InvariantCulture, int startIndex = 0)
|
public class TextContainsWordAttribute(string word, StringComparison comparison = StringComparison.InvariantCulture, int startIndex = 0)
|
||||||
: MessageFilterAttribute(new TextContainsWordFilter(word, comparison, startIndex))
|
: MessageFilterAttribute(new TextContainsWordFilter(word, comparison, startIndex))
|
||||||
{ }
|
{ }
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
namespace Telegrator.Annotations
|
namespace Telegrator.Annotations;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attribute that says if this handler can await some of await types, that is not listed by its handler base.
|
/// Attribute that says if this handler can await some of await types, that is not listed by its handler base.
|
||||||
/// Used for automatic collecting allowed to receiving <see cref="UpdateType"/>'s.
|
/// Used for automatic collecting allowed to receiving <see cref="UpdateType"/>'s.
|
||||||
@@ -24,4 +24,3 @@ namespace Telegrator.Annotations
|
|||||||
public MightAwaitAttribute(params UpdateType[] updateTypes)
|
public MightAwaitAttribute(params UpdateType[] updateTypes)
|
||||||
=> _updateTypes = updateTypes;
|
=> _updateTypes = updateTypes;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using Telegram.Bot.Types;
|
||||||
|
using Telegram.Bot.Types.Enums;
|
||||||
|
using Telegrator.Attributes;
|
||||||
|
using Telegrator.Core.States;
|
||||||
|
using Telegrator.Filters;
|
||||||
|
|
||||||
|
namespace Telegrator.Annotations;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attribute for filtering updates where resolved state matches target value.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TKey"></typeparam>
|
||||||
|
/// <typeparam name="TValue"></typeparam>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
public class StateAttribute<TKey, TValue>(TValue? value) : UpdateFilterAttribute<Update>(new StateKeyFilter<TKey, TValue>(value))
|
||||||
|
where TKey : IStateKeyResolver, new()
|
||||||
|
where TValue : IEquatable<TValue>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The targetting state value.
|
||||||
|
/// </summary>
|
||||||
|
public TValue? Value => value;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override UpdateType[] AllowedTypes => Update.AllTypes;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override Update? GetFilterringTarget(Update update)
|
||||||
|
{
|
||||||
|
return update;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
using Telegrator.StateKeeping;
|
|
||||||
using Telegrator.Attributes;
|
|
||||||
using Telegrator.Core.StateKeeping;
|
|
||||||
|
|
||||||
namespace Telegrator.Annotations.StateKeeping
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Attribute for managing enum-based states in Telegram bot handlers.
|
|
||||||
/// Provides a convenient way to associate enum values with state management functionality.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="TEnum">The enum type to be used for state management.</typeparam>
|
|
||||||
public class EnumStateAttribute<TEnum> : StateKeeperAttribute<long, TEnum, EnumStateKeeper<TEnum>> where TEnum : Enum
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the EnumStateAttribute with a special state and custom key resolver.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="specialState">The special state to be managed.</param>
|
|
||||||
/// <param name="keyResolver">The resolver for extracting keys from updates.</param>
|
|
||||||
public EnumStateAttribute(SpecialState specialState, IStateKeyResolver<long> keyResolver)
|
|
||||||
: base(specialState, keyResolver) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the EnumStateAttribute with a specific enum state and custom key resolver.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="myState">The specific enum state to be managed.</param>
|
|
||||||
/// <param name="keyResolver">The resolver for extracting keys from updates.</param>
|
|
||||||
public EnumStateAttribute(TEnum myState, IStateKeyResolver<long> keyResolver)
|
|
||||||
: base(myState, keyResolver) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the EnumStateAttribute with a special state and default sender ID resolver.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="specialState">The special state to be managed.</param>
|
|
||||||
public EnumStateAttribute(SpecialState specialState)
|
|
||||||
: base(specialState, new SenderIdResolver()) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the EnumStateAttribute with a specific enum state and default sender ID resolver.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="myState">The specific enum state to be managed.</param>
|
|
||||||
public EnumStateAttribute(TEnum myState)
|
|
||||||
: this(myState, new SenderIdResolver()) { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
using Telegrator.StateKeeping;
|
|
||||||
using Telegrator.Attributes;
|
|
||||||
using Telegrator.Core.StateKeeping;
|
|
||||||
|
|
||||||
namespace Telegrator.Annotations.StateKeeping
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Attribute for associating a handler or method with a numeric (integer) state keeper.
|
|
||||||
/// Provides constructors for flexible state and key resolver configuration.
|
|
||||||
/// </summary>
|
|
||||||
public class NumericStateAttribute : StateKeeperAttribute<long, int, NumericStateKeeper>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes the attribute with a special state and a custom key resolver.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="specialState">The special state to associate</param>
|
|
||||||
/// <param name="keyResolver">The key resolver for state keeping</param>
|
|
||||||
public NumericStateAttribute(SpecialState specialState, IStateKeyResolver<long> keyResolver)
|
|
||||||
: base(specialState, keyResolver) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes the attribute with a specific numeric state and a custom key resolver.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="myState">The integer state to associate</param>
|
|
||||||
/// <param name="keyResolver">The key resolver for state keeping</param>
|
|
||||||
public NumericStateAttribute(int myState, IStateKeyResolver<long> keyResolver)
|
|
||||||
: base(myState, keyResolver) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes the attribute with a special state and the default sender ID resolver.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="specialState">The special state to associate</param>
|
|
||||||
public NumericStateAttribute(SpecialState specialState)
|
|
||||||
: base(specialState, new SenderIdResolver()) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes the attribute with a specific numeric state and the default sender ID resolver.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="myState">The integer state to associate</param>
|
|
||||||
public NumericStateAttribute(int myState)
|
|
||||||
: this(myState, new SenderIdResolver()) { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
namespace Telegrator.Annotations.StateKeeping
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents special states for state keeping logic.
|
|
||||||
/// </summary>
|
|
||||||
public enum SpecialState
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// No special state.
|
|
||||||
/// </summary>
|
|
||||||
None,
|
|
||||||
/// <summary>
|
|
||||||
/// Indicates that no state is present.
|
|
||||||
/// </summary>
|
|
||||||
NoState,
|
|
||||||
/// <summary>
|
|
||||||
/// Indicates that any state is acceptable.
|
|
||||||
/// </summary>
|
|
||||||
AnyState
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
using Telegrator.StateKeeping;
|
|
||||||
using Telegrator.Attributes;
|
|
||||||
using Telegrator.Core.StateKeeping;
|
|
||||||
|
|
||||||
namespace Telegrator.Annotations.StateKeeping
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Attribute for associating a handler or method with a string-based state keeper.
|
|
||||||
/// Provides various constructors for flexible state and key resolver configuration.
|
|
||||||
/// </summary>
|
|
||||||
public class StringStateAttribute : StateKeeperAttribute<long, string, StringStateKeeper>
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes the attribute with a special state and a custom key resolver.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="specialState">The special state to associate</param>
|
|
||||||
/// <param name="keyResolver">The key resolver for state keeping</param>
|
|
||||||
public StringStateAttribute(SpecialState specialState, IStateKeyResolver<long> keyResolver)
|
|
||||||
: base(specialState, keyResolver) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes the attribute with a specific state and a custom key resolver.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="myState">The string state to associate</param>
|
|
||||||
/// <param name="keyResolver">The key resolver for state keeping</param>
|
|
||||||
public StringStateAttribute(string myState, IStateKeyResolver<long> keyResolver)
|
|
||||||
: base(myState, keyResolver) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes the attribute with a special state and the default sender ID resolver.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="specialState">The special state to associate</param>
|
|
||||||
public StringStateAttribute(SpecialState specialState)
|
|
||||||
: base(specialState, new SenderIdResolver()) { }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes the attribute with a specific state and the default sender ID resolver.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="myState">The string state to associate</param>
|
|
||||||
public StringStateAttribute(string myState)
|
|
||||||
: base(myState, new SenderIdResolver()) { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
using Telegram.Bot.Types;
|
|
||||||
using Telegram.Bot.Types.Enums;
|
|
||||||
using Telegrator.Filters;
|
|
||||||
|
|
||||||
namespace Telegrator.Annotations.Targetted
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Attribute for filtering message with command "start" in bot's private chats.
|
|
||||||
/// Allows handlers to respond to "welcome" bot commands.
|
|
||||||
/// </summary>
|
|
||||||
public class WelcomeAttribute : MessageFilterAttribute
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Creates new instance of <see cref="WelcomeAttribute"/>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="onlyFirst"></param>
|
|
||||||
public WelcomeAttribute(bool onlyFirst = false) : base(
|
|
||||||
new MessageChatTypeFilter(ChatType.Private),
|
|
||||||
new CommandAlliasFilter("start"),
|
|
||||||
Filter<Message>.If(ctx => !onlyFirst || ctx.Input.Id == 0))
|
|
||||||
{ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using Telegram.Bot.Types;
|
||||||
|
using Telegram.Bot.Types.Enums;
|
||||||
|
using Telegrator.Filters;
|
||||||
|
|
||||||
|
namespace Telegrator.Annotations;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attribute for filtering message with command "start" in bot's private chats.
|
||||||
|
/// Allows handlers to respond to "welcome" bot commands.
|
||||||
|
/// </summary>
|
||||||
|
public class WelcomeAttribute : MessageFilterAttribute
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Creates new instance of <see cref="WelcomeAttribute"/>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="onlyFirst"></param>
|
||||||
|
public WelcomeAttribute(bool onlyFirst = false) : base(
|
||||||
|
new MessageChatTypeFilter(ChatType.Private),
|
||||||
|
new CommandAlliasFilter("start"),
|
||||||
|
Filter<Message>.If(ctx => !onlyFirst || ctx.Input.Id == 0))
|
||||||
|
{ }
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace Telegrator.Aspects
|
namespace Telegrator.Aspects;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attribute that specifies a post-execution processor to be executed after the handler.
|
/// Attribute that specifies a post-execution processor to be executed after the handler.
|
||||||
/// The processor type must implement <see cref="IPostProcessor"/> interface.
|
/// The processor type must implement <see cref="IPostProcessor"/> interface.
|
||||||
@@ -13,4 +13,3 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Type ProcessorType => typeof(T);
|
public Type ProcessorType => typeof(T);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace Telegrator.Aspects
|
namespace Telegrator.Aspects;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attribute that specifies a pre-execution processor to be executed before the handler.
|
/// Attribute that specifies a pre-execution processor to be executed before the handler.
|
||||||
/// The processor type must implement <see cref="IPreProcessor"/> interface.
|
/// The processor type must implement <see cref="IPreProcessor"/> interface.
|
||||||
@@ -13,4 +13,3 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Type ProcessorType => typeof(T);
|
public Type ProcessorType => typeof(T);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Telegrator.Core.Handlers;
|
using Telegrator.Core.Handlers;
|
||||||
|
|
||||||
namespace Telegrator.Aspects
|
namespace Telegrator.Aspects;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interface for post-execution processors that are executed after handler execution.
|
/// Interface for post-execution processors that are executed after handler execution.
|
||||||
/// Implement this interface to add cross-cutting concerns like logging, cleanup, or metrics collection.
|
/// Implement this interface to add cross-cutting concerns like logging, cleanup, or metrics collection.
|
||||||
@@ -16,4 +16,3 @@ namespace Telegrator.Aspects
|
|||||||
/// <returns>A <see cref="Result"/> indicating the final execution result.</returns>
|
/// <returns>A <see cref="Result"/> indicating the final execution result.</returns>
|
||||||
public Task<Result> AfterExecution(IHandlerContainer container, CancellationToken cancellationToken);
|
public Task<Result> AfterExecution(IHandlerContainer container, CancellationToken cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Telegrator.Core.Handlers;
|
using Telegrator.Core.Handlers;
|
||||||
|
|
||||||
namespace Telegrator.Aspects
|
namespace Telegrator.Aspects;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interface for pre-execution processors that are executed before handler execution.
|
/// Interface for pre-execution processors that are executed before handler execution.
|
||||||
/// Implement this interface to add cross-cutting concerns like validation, logging, or authorization.
|
/// Implement this interface to add cross-cutting concerns like validation, logging, or authorization.
|
||||||
@@ -16,4 +16,3 @@ namespace Telegrator.Aspects
|
|||||||
/// <returns>A <see cref="Result"/> indicating whether execution should continue or be stopped.</returns>
|
/// <returns>A <see cref="Result"/> indicating whether execution should continue or be stopped.</returns>
|
||||||
public Task<Result> BeforeExecution(IHandlerContainer container, CancellationToken cancellationToken = default);
|
public Task<Result> BeforeExecution(IHandlerContainer container, CancellationToken cancellationToken = default);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ using Telegram.Bot.Types.Enums;
|
|||||||
using Telegrator.Core.Filters;
|
using Telegrator.Core.Filters;
|
||||||
using Telegrator.Filters;
|
using Telegrator.Filters;
|
||||||
|
|
||||||
namespace Telegrator.Attributes
|
namespace Telegrator.Attributes;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reactive way to implement a new <see cref="UpdateFilterAttribute{T}"/> of type <typeparamref name="T"/>
|
/// Reactive way to implement a new <see cref="UpdateFilterAttribute{T}"/> of type <typeparamref name="T"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -36,4 +36,3 @@ namespace Telegrator.Attributes
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public abstract bool CanPass(FilterExecutionContext<T> context);
|
public abstract bool CanPass(FilterExecutionContext<T> context);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace Telegrator.Attributes
|
namespace Telegrator.Attributes;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Enumeration of filter modifiers that can be applied to update filters.
|
/// Enumeration of filter modifiers that can be applied to update filters.
|
||||||
/// Defines how filters should be combined and applied in filter chains.
|
/// Defines how filters should be combined and applied in filter chains.
|
||||||
@@ -22,4 +22,3 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
Not = 4,
|
Not = 4,
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,86 +0,0 @@
|
|||||||
using Telegram.Bot.Types;
|
|
||||||
using Telegrator.Annotations.StateKeeping;
|
|
||||||
using Telegrator.Core.Attributes;
|
|
||||||
using Telegrator.Core.Filters;
|
|
||||||
using Telegrator.Core.StateKeeping;
|
|
||||||
|
|
||||||
namespace Telegrator.Attributes
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Abstract attribute for associating a handler or method with a state keeper.
|
|
||||||
/// Provides logic for state-based filtering and state management.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="TKey">The type of the key used for state keeping (e.g., chat ID).</typeparam>
|
|
||||||
/// <typeparam name="TState">The type of the state value (e.g., string, int).</typeparam>
|
|
||||||
/// <typeparam name="TKeeper">The type of the state keeper implementation.</typeparam>
|
|
||||||
public abstract class StateKeeperAttribute<TKey, TState, TKeeper> : StateKeeperAttributeBase where TKey : notnull where TState : notnull where TKeeper : StateKeeperBase<TKey, TState>, new()
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
private static readonly TKeeper _shared = new TKeeper();
|
|
||||||
private static readonly Dictionary<TKey, TKeeper> _keyed = [];
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the singleton instance of the state keeper for this attribute type.
|
|
||||||
/// </summary>
|
|
||||||
public static TKeeper Shared { get; } = new TKeeper();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the default state value of this statekeeper.
|
|
||||||
/// </summary>
|
|
||||||
public static TState DefaultState => Shared.DefaultState;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the state value associated with this attribute instance.
|
|
||||||
/// </summary>
|
|
||||||
public TState MyState { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the special state mode for this attribute instance.
|
|
||||||
/// </summary>
|
|
||||||
public SpecialState SpecialState { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes the attribute with a specific state and a custom key resolver.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="myState">The state value to associate</param>
|
|
||||||
/// <param name="keyResolver">The key resolver for state keeping</param>
|
|
||||||
protected StateKeeperAttribute(TState myState, IStateKeyResolver<TKey> keyResolver) : base(typeof(TKeeper))
|
|
||||||
{
|
|
||||||
Shared.KeyResolver = keyResolver;
|
|
||||||
MyState = myState;
|
|
||||||
SpecialState = SpecialState.None;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes the attribute with a special state and a custom key resolver.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="specialState">The special state mode</param>
|
|
||||||
/// <param name="keyResolver">The key resolver for state keeping</param>
|
|
||||||
protected StateKeeperAttribute(SpecialState specialState, IStateKeyResolver<TKey> keyResolver) : base(typeof(TKeeper))
|
|
||||||
{
|
|
||||||
Shared.KeyResolver = keyResolver;
|
|
||||||
MyState = Shared.DefaultState;
|
|
||||||
SpecialState = specialState;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Determines whether the current update context passes the state filter.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context">The filter execution context</param>
|
|
||||||
/// <returns>True if the state matches the filter; otherwise, false.</returns>
|
|
||||||
public override bool CanPass(FilterExecutionContext<Update> context)
|
|
||||||
{
|
|
||||||
if (SpecialState == SpecialState.AnyState)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (!Shared.TryGetState(context.Input, out TState? state))
|
|
||||||
return SpecialState == SpecialState.NoState;
|
|
||||||
|
|
||||||
if (state == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return MyState.Equals(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,8 +3,8 @@ using Telegrator.Core.Attributes;
|
|||||||
using Telegrator.Core.Filters;
|
using Telegrator.Core.Filters;
|
||||||
using Telegrator.Filters;
|
using Telegrator.Filters;
|
||||||
|
|
||||||
namespace Telegrator.Attributes
|
namespace Telegrator.Attributes;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Abstract base attribute for defining update filters for a specific type of update target.
|
/// Abstract base attribute for defining update filters for a specific type of update target.
|
||||||
/// Provides logic for filter composition, modifier processing, and target extraction.
|
/// Provides logic for filter composition, modifier processing, and target extraction.
|
||||||
@@ -82,4 +82,3 @@ namespace Telegrator.Attributes
|
|||||||
/// <returns>The target object to filter, or null if not applicable</returns>
|
/// <returns>The target object to filter, or null if not applicable</returns>
|
||||||
public abstract T? GetFilterringTarget(Update update);
|
public abstract T? GetFilterringTarget(Update update);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
using Telegrator.Core.Attributes;
|
using Telegrator.Core.Attributes;
|
||||||
using Telegrator.Core.Handlers;
|
using Telegrator.Core.Handlers;
|
||||||
|
|
||||||
namespace Telegrator.Attributes
|
namespace Telegrator.Attributes;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Abstract base attribute for marking update handler classes.
|
/// Abstract base attribute for marking update handler classes.
|
||||||
/// Provides a type-safe way to associate handler types with specific update types and importance settings.
|
/// Provides a type-safe way to associate handler types with specific update types and importance settings.
|
||||||
@@ -43,4 +43,3 @@ namespace Telegrator.Attributes
|
|||||||
protected UpdateHandlerAttribute(Type[] types, UpdateType updateType, int importance)
|
protected UpdateHandlerAttribute(Type[] types, UpdateType updateType, int importance)
|
||||||
: base([.. types, typeof(T)], updateType, importance) { }
|
: base([.. types, typeof(T)], updateType, importance) { }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
using Telegram.Bot.Types;
|
|
||||||
using Telegrator.Core.Filters;
|
|
||||||
using Telegrator.Core.Handlers;
|
|
||||||
using Telegrator.Core.StateKeeping;
|
|
||||||
|
|
||||||
namespace Telegrator.Core.Attributes
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Sets the state in which the <see cref="UpdateHandlerBase"/> can be executed
|
|
||||||
/// </summary>
|
|
||||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
|
||||||
public abstract class StateKeeperAttributeBase : Attribute, IFilter<Update>
|
|
||||||
{
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public bool IsCollectible => GetType().HasPublicProperties();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a new instance <see cref="StateKeeperBase{TKey, TState}"/>
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="stateKeeperType"></param>
|
|
||||||
/// <exception cref="ArgumentException"></exception>
|
|
||||||
protected StateKeeperAttributeBase(Type stateKeeperType)
|
|
||||||
{
|
|
||||||
if (!stateKeeperType.IsAssignableToGenericType(typeof(StateKeeperBase<,>)))
|
|
||||||
throw new ArgumentException(stateKeeperType + " is not a StateKeeperBase", nameof(stateKeeperType));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Realizes a <see cref="IFilter{T}"/> for validation of the current <see cref="StateKeeperBase{TKey, TState}"/> in the polling routing
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public abstract bool CanPass(FilterExecutionContext<Update> context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,8 +5,8 @@ using Telegrator.Core.Filters;
|
|||||||
using Telegrator.Core.Handlers;
|
using Telegrator.Core.Handlers;
|
||||||
using Telegrator.Filters;
|
using Telegrator.Filters;
|
||||||
|
|
||||||
namespace Telegrator.Core.Attributes
|
namespace Telegrator.Core.Attributes;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the <see cref="IFilter{T}"/> to <see cref="Update"/> validation for entry into execution of the <see cref="UpdateHandlerBase"/>
|
/// Defines the <see cref="IFilter{T}"/> to <see cref="Update"/> validation for entry into execution of the <see cref="UpdateHandlerBase"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -44,4 +44,3 @@ namespace Telegrator.Core.Attributes
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public abstract bool ProcessModifiers(UpdateFilterAttributeBase? previous);
|
public abstract bool ProcessModifiers(UpdateFilterAttributeBase? previous);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ using Telegrator.Core.Descriptors;
|
|||||||
using Telegrator.Core.Filters;
|
using Telegrator.Core.Filters;
|
||||||
using Telegrator.Core.Handlers;
|
using Telegrator.Core.Handlers;
|
||||||
|
|
||||||
namespace Telegrator.Core.Attributes
|
namespace Telegrator.Core.Attributes;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the <see cref="UpdateType"/>'s and validator (<see cref="IFilter{T}"/>) of the <see cref="Update"/> that <see cref="UpdateHandlerBase"/> will process
|
/// Defines the <see cref="UpdateType"/>'s and validator (<see cref="IFilter{T}"/>) of the <see cref="Update"/> that <see cref="UpdateHandlerBase"/> will process
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -79,4 +79,3 @@ namespace Telegrator.Core.Attributes
|
|||||||
/// <returns>True if the update passes validation; otherwise, false.</returns>
|
/// <returns>True if the update passes validation; otherwise, false.</returns>
|
||||||
public abstract bool CanPass(FilterExecutionContext<Update> context);
|
public abstract bool CanPass(FilterExecutionContext<Update> context);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ using Telegrator.Core.Handlers;
|
|||||||
using Telegrator.Handlers;
|
using Telegrator.Handlers;
|
||||||
using Telegrator.Handlers.Building;
|
using Telegrator.Handlers.Building;
|
||||||
|
|
||||||
namespace Telegrator.Core.Descriptors
|
namespace Telegrator.Core.Descriptors;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Descriptor for creating handlers from methods
|
/// Descriptor for creating handlers from methods
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -24,7 +24,7 @@ namespace Telegrator.Core.Descriptors
|
|||||||
public MethodHandlerDescriptor(AbstractHandlerAction<TUpdate> action) : base(DescriptorType.General, typeof(MethodHandler), true)
|
public MethodHandlerDescriptor(AbstractHandlerAction<TUpdate> action) : base(DescriptorType.General, typeof(MethodHandler), true)
|
||||||
{
|
{
|
||||||
UpdateHandlerAttributeBase handlerAttribute = HandlerInspector.GetHandlerAttribute(action.Method);
|
UpdateHandlerAttributeBase handlerAttribute = HandlerInspector.GetHandlerAttribute(action.Method);
|
||||||
StateKeeperAttributeBase? stateKeeperAttribute = HandlerInspector.GetStateKeeperAttribute(action.Method);
|
IFilter<Update>? stateKeeperAttribute = HandlerInspector.GetStateKeeperAttribute(action.Method);
|
||||||
IFilter<Update>[] filters = HandlerInspector.GetFilterAttributes(action.Method, handlerAttribute.Type).ToArray();
|
IFilter<Update>[] filters = HandlerInspector.GetFilterAttributes(action.Method, handlerAttribute.Type).ToArray();
|
||||||
|
|
||||||
UpdateType = handlerAttribute.Type;
|
UpdateType = handlerAttribute.Type;
|
||||||
@@ -67,4 +67,3 @@ namespace Telegrator.Core.Descriptors
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,9 +2,10 @@
|
|||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegrator.Core.Filters;
|
using Telegrator.Core.Filters;
|
||||||
using Telegrator.Core.Handlers;
|
using Telegrator.Core.Handlers;
|
||||||
|
using Telegrator.Core.States;
|
||||||
|
|
||||||
|
namespace Telegrator.Core.Descriptors;
|
||||||
|
|
||||||
namespace Telegrator.Core.Descriptors
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains information about a described handler, including its context, client, and execution logic.
|
/// Contains information about a described handler, including its context, client, and execution logic.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -27,6 +28,11 @@ namespace Telegrator.Core.Descriptors
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public IAwaitingProvider AwaitingProvider { get; }
|
public IAwaitingProvider AwaitingProvider { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The state storage to handling state machines
|
||||||
|
/// </summary>
|
||||||
|
public IStateStorage StateStorage { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Telegram bot client used for this handler.
|
/// The Telegram bot client used for this handler.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -73,6 +79,7 @@ namespace Telegrator.Core.Descriptors
|
|||||||
/// <param name="fromDescriptor">The descriptor from which this handler was described.</param>
|
/// <param name="fromDescriptor">The descriptor from which this handler was described.</param>
|
||||||
/// <param name="updateRouter">The update router.</param>
|
/// <param name="updateRouter">The update router.</param>
|
||||||
/// <param name="awaitingProvider">The awaiting provider.</param>
|
/// <param name="awaitingProvider">The awaiting provider.</param>
|
||||||
|
/// <param name="stateStorage">The state storage.</param>
|
||||||
/// <param name="client">The Telegram bot client.</param>
|
/// <param name="client">The Telegram bot client.</param>
|
||||||
/// <param name="handlerInstance">The handler instance.</param>
|
/// <param name="handlerInstance">The handler instance.</param>
|
||||||
/// <param name="filterContext">The filter execution context.</param>
|
/// <param name="filterContext">The filter execution context.</param>
|
||||||
@@ -81,6 +88,7 @@ namespace Telegrator.Core.Descriptors
|
|||||||
HandlerDescriptor fromDescriptor,
|
HandlerDescriptor fromDescriptor,
|
||||||
IUpdateRouter updateRouter,
|
IUpdateRouter updateRouter,
|
||||||
IAwaitingProvider awaitingProvider,
|
IAwaitingProvider awaitingProvider,
|
||||||
|
IStateStorage stateStorage,
|
||||||
ITelegramBotClient client,
|
ITelegramBotClient client,
|
||||||
UpdateHandlerBase handlerInstance,
|
UpdateHandlerBase handlerInstance,
|
||||||
FilterExecutionContext<Update> filterContext,
|
FilterExecutionContext<Update> filterContext,
|
||||||
@@ -89,6 +97,7 @@ namespace Telegrator.Core.Descriptors
|
|||||||
From = fromDescriptor;
|
From = fromDescriptor;
|
||||||
UpdateRouter = updateRouter;
|
UpdateRouter = updateRouter;
|
||||||
AwaitingProvider = awaitingProvider;
|
AwaitingProvider = awaitingProvider;
|
||||||
|
StateStorage = stateStorage;
|
||||||
Client = client;
|
Client = client;
|
||||||
HandlerInstance = handlerInstance;
|
HandlerInstance = handlerInstance;
|
||||||
ExtraData = filterContext.Data;
|
ExtraData = filterContext.Data;
|
||||||
@@ -114,7 +123,7 @@ namespace Telegrator.Core.Descriptors
|
|||||||
/// <param name="result">The execution result.</param>
|
/// <param name="result">The execution result.</param>
|
||||||
public void ReportResult(Result? result)
|
public void ReportResult(Result? result)
|
||||||
{
|
{
|
||||||
if (result != null)
|
if (Result != null)
|
||||||
throw new InvalidOperationException("Result already reported");
|
throw new InvalidOperationException("Result already reported");
|
||||||
|
|
||||||
Result = result;
|
Result = result;
|
||||||
@@ -125,4 +134,3 @@ namespace Telegrator.Core.Descriptors
|
|||||||
public override string ToString()
|
public override string ToString()
|
||||||
=> DisplayString ?? From.HandlerType.Name;
|
=> DisplayString ?? From.HandlerType.Name;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using Telegrator.Aspects;
|
using Telegrator.Aspects;
|
||||||
using Telegrator.Core.Handlers;
|
using Telegrator.Core.Handlers;
|
||||||
|
|
||||||
namespace Telegrator.Core.Descriptors
|
namespace Telegrator.Core.Descriptors;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Manages the execution of pre and post-execution aspects for a handler.
|
/// Manages the execution of pre and post-execution aspects for a handler.
|
||||||
/// This class coordinates between self-processing (handler implements interfaces)
|
/// This class coordinates between self-processing (handler implements interfaces)
|
||||||
@@ -77,4 +77,3 @@ namespace Telegrator.Core.Descriptors
|
|||||||
return Result.Ok();
|
return Result.Ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ using Telegrator.Core.Filters;
|
|||||||
using Telegrator.Handlers.Diagnostics;
|
using Telegrator.Handlers.Diagnostics;
|
||||||
using Telegrator.Logging;
|
using Telegrator.Logging;
|
||||||
|
|
||||||
namespace Telegrator.Core.Descriptors
|
namespace Telegrator.Core.Descriptors;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a set of filters for a handler descriptor, including update and state keeper validators.
|
/// Represents a set of filters for a handler descriptor, including update and state keeper validators.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -142,4 +142,3 @@ namespace Telegrator.Core.Descriptors
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Telegrator.Core.Attributes;
|
using Telegrator.Core.Attributes;
|
||||||
|
|
||||||
namespace Telegrator.Core.Descriptors
|
namespace Telegrator.Core.Descriptors;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents an indexer for handler descriptors, containing importance and priority information.
|
/// Represents an indexer for handler descriptors, containing importance and priority information.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -85,4 +85,3 @@ namespace Telegrator.Core.Descriptors
|
|||||||
return string.Format("(Ix: {0,2}, Im: {1,2}, Pr: {2,2})", RouterIndex, Importance, Priority);
|
return string.Format("(Ix: {0,2}, Im: {1,2}, Pr: {2,2})", RouterIndex, Importance, Priority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ using Telegrator.Core.Attributes;
|
|||||||
using Telegrator.Core.Filters;
|
using Telegrator.Core.Filters;
|
||||||
using Telegrator.Core.Handlers;
|
using Telegrator.Core.Handlers;
|
||||||
|
|
||||||
namespace Telegrator.Core.Descriptors
|
namespace Telegrator.Core.Descriptors;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Specifies the type of handler descriptor.
|
/// Specifies the type of handler descriptor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -43,7 +43,6 @@ namespace Telegrator.Core.Descriptors
|
|||||||
public DescriptorType Type
|
public DescriptorType Type
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
private set;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -52,7 +51,6 @@ namespace Telegrator.Core.Descriptors
|
|||||||
public Type HandlerType
|
public Type HandlerType
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
private set;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -164,10 +162,10 @@ namespace Telegrator.Core.Descriptors
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
UpdateHandlerAttributeBase handlerAttribute = HandlerInspector.GetHandlerAttribute(handlerType);
|
UpdateHandlerAttributeBase handlerAttribute = HandlerInspector.GetHandlerAttribute(handlerType);
|
||||||
if (handlerAttribute.ExpectingHandlerType != null && !handlerAttribute.ExpectingHandlerType.Contains(handlerType.BaseType))
|
if (handlerAttribute.ExpectingHandlerType?.Contains(handlerType.BaseType) == false)
|
||||||
throw new ArgumentException(string.Format("This handler attribute cannot be attached to this class. Attribute can be attached on next handlers : {0}", string.Join(", ", handlerAttribute.ExpectingHandlerType.AsEnumerable())));
|
throw new ArgumentException(string.Format("This handler attribute cannot be attached to this class. Attribute can be attached on next handlers : {0}", string.Join(", ", handlerAttribute.ExpectingHandlerType.AsEnumerable())));
|
||||||
|
|
||||||
StateKeeperAttributeBase? stateKeeperAttribute = HandlerInspector.GetStateKeeperAttribute(handlerType);
|
IFilter<Update>? stateKeeperAttribute = HandlerInspector.GetStateKeeperAttribute(handlerType);
|
||||||
IFilter<Update>[] filters = HandlerInspector.GetFilterAttributes(handlerType, handlerAttribute.Type).ToArray();
|
IFilter<Update>[] filters = HandlerInspector.GetFilterAttributes(handlerType, handlerAttribute.Type).ToArray();
|
||||||
|
|
||||||
UpdateType = handlerAttribute.Type;
|
UpdateType = handlerAttribute.Type;
|
||||||
@@ -472,4 +470,3 @@ namespace Telegrator.Core.Descriptors
|
|||||||
public override string ToString()
|
public override string ToString()
|
||||||
=> DisplayString ?? HandlerType.Name;
|
=> DisplayString ?? HandlerType.Name;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
namespace Telegrator.Core.Descriptors
|
namespace Telegrator.Core.Descriptors;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The collection containing the <see cref="HandlerDescriptor"/>'s. Used to route <see cref="Update"/>'s in <see cref="IHandlersProvider"/>
|
/// The collection containing the <see cref="HandlerDescriptor"/>'s. Used to route <see cref="Update"/>'s in <see cref="IHandlersProvider"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -156,4 +156,3 @@ namespace Telegrator.Core.Descriptors
|
|||||||
return _innerCollection.Values.GetEnumerator();
|
return _innerCollection.Values.GetEnumerator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,12 +2,13 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
using Telegrator.Annotations;
|
||||||
using Telegrator.Aspects;
|
using Telegrator.Aspects;
|
||||||
using Telegrator.Core.Attributes;
|
using Telegrator.Core.Attributes;
|
||||||
using Telegrator.Core.Filters;
|
using Telegrator.Core.Filters;
|
||||||
|
|
||||||
namespace Telegrator.Core.Descriptors
|
namespace Telegrator.Core.Descriptors;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides methods for inspecting handler types and retrieving their attributes and filters.
|
/// Provides methods for inspecting handler types and retrieving their attributes and filters.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -42,13 +43,13 @@ namespace Telegrator.Core.Descriptors
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="handlerType">The member info representing the handler type.</param>
|
/// <param name="handlerType">The member info representing the handler type.</param>
|
||||||
/// <returns>The state keeper attribute, or null if not present.</returns>
|
/// <returns>The state keeper attribute, or null if not present.</returns>
|
||||||
public static StateKeeperAttributeBase? GetStateKeeperAttribute(MemberInfo handlerType)
|
public static IFilter<Update>? GetStateKeeperAttribute(MemberInfo handlerType)
|
||||||
{
|
{
|
||||||
// Getting polling handler attribute
|
// Getting polling handler attribute
|
||||||
IEnumerable<StateKeeperAttributeBase> handlerAttrs = handlerType.GetCustomAttributes<StateKeeperAttributeBase>();
|
Attribute stateAttr = handlerType.GetCustomAttribute(typeof(StateAttribute<,>));
|
||||||
|
|
||||||
//
|
//
|
||||||
return handlerAttrs.Any() ? handlerAttrs.Single() : null;
|
return stateAttr as IFilter<Update>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -95,4 +96,3 @@ namespace Telegrator.Core.Descriptors
|
|||||||
return new DescriptorAspectsSet(typedPre, typedPost);
|
return new DescriptorAspectsSet(typedPre, typedPost);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
using Telegrator.Filters;
|
using Telegrator.Filters;
|
||||||
using Telegrator.Logging;
|
using Telegrator.Logging;
|
||||||
|
|
||||||
namespace Telegrator.Core.Filters
|
namespace Telegrator.Core.Filters;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a compiled filter that applies a set of filters to an anonymous target type.
|
/// Represents a compiled filter that applies a set of filters to an anonymous target type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -106,4 +106,3 @@ namespace Telegrator.Core.Filters
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
using Telegrator.Filters;
|
using Telegrator.Filters;
|
||||||
using Telegrator.Logging;
|
using Telegrator.Logging;
|
||||||
|
|
||||||
namespace Telegrator.Core.Filters
|
namespace Telegrator.Core.Filters;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a filter that applies a filter action to an anonymous target type extracted from an update.
|
/// Represents a filter that applies a filter action to an anonymous target type extracted from an update.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -107,4 +107,3 @@ namespace Telegrator.Core.Filters
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using Telegrator.Filters;
|
using Telegrator.Filters;
|
||||||
using Telegrator.Logging;
|
using Telegrator.Logging;
|
||||||
|
|
||||||
namespace Telegrator.Core.Filters
|
namespace Telegrator.Core.Filters;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a filter that composes multiple filters and passes only if all of them pass.
|
/// Represents a filter that composes multiple filters and passes only if all of them pass.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -61,4 +61,3 @@ namespace Telegrator.Core.Filters
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
||||||
namespace Telegrator.Core.Filters
|
namespace Telegrator.Core.Filters;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The list containing filters worked out during Polling to further obtain additional filtering information
|
/// The list containing filters worked out during Polling to further obtain additional filtering information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -83,4 +83,3 @@ namespace Telegrator.Core.Filters
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
IEnumerator IEnumerable.GetEnumerator() => CompletedFilters.GetEnumerator();
|
IEnumerator IEnumerable.GetEnumerator() => CompletedFilters.GetEnumerator();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
namespace Telegrator.Core.Filters
|
namespace Telegrator.Core.Filters;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents the context for filter execution, including update, input, and additional data.
|
/// Represents the context for filter execution, including update, input, and additional data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">The type of the input for the filter.</typeparam>
|
/// <typeparam name="T">The type of the input for the filter.</typeparam>
|
||||||
public class FilterExecutionContext<T> where T : class
|
public class FilterExecutionContext<T> where T : class
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the <see cref="ITelegramBotInfo"/> for the current context.
|
||||||
|
/// </summary>
|
||||||
|
public IUpdateRouter UpdateRouter { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the <see cref="ITelegramBotInfo"/> for the current context.
|
/// Gets the <see cref="ITelegramBotInfo"/> for the current context.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -42,13 +47,15 @@ namespace Telegrator.Core.Filters
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="FilterExecutionContext{T}"/> class with all parameters.
|
/// Initializes a new instance of the <see cref="FilterExecutionContext{T}"/> class with all parameters.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="router">The router, that invoked filter.</param>
|
||||||
/// <param name="botInfo">The bot info.</param>
|
/// <param name="botInfo">The bot info.</param>
|
||||||
/// <param name="update">The update.</param>
|
/// <param name="update">The update.</param>
|
||||||
/// <param name="input">The input object.</param>
|
/// <param name="input">The input object.</param>
|
||||||
/// <param name="data">The additional data dictionary.</param>
|
/// <param name="data">The additional data dictionary.</param>
|
||||||
/// <param name="completedFilters">The list of completed filters.</param>
|
/// <param name="completedFilters">The list of completed filters.</param>
|
||||||
public FilterExecutionContext(ITelegramBotInfo botInfo, Update update, T input, Dictionary<string, object> data, CompletedFiltersList completedFilters)
|
public FilterExecutionContext(IUpdateRouter router, ITelegramBotInfo botInfo, Update update, T input, Dictionary<string, object> data, CompletedFiltersList completedFilters)
|
||||||
{
|
{
|
||||||
|
UpdateRouter = router;
|
||||||
BotInfo = botInfo;
|
BotInfo = botInfo;
|
||||||
Data = data;
|
Data = data;
|
||||||
CompletedFilters = completedFilters;
|
CompletedFilters = completedFilters;
|
||||||
@@ -60,11 +67,12 @@ namespace Telegrator.Core.Filters
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="FilterExecutionContext{T}"/> class with default data and filters.
|
/// Initializes a new instance of the <see cref="FilterExecutionContext{T}"/> class with default data and filters.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="router">The router, that invoked filter.</param>
|
||||||
/// <param name="botInfo">The bot info.</param>
|
/// <param name="botInfo">The bot info.</param>
|
||||||
/// <param name="update">The update.</param>
|
/// <param name="update">The update.</param>
|
||||||
/// <param name="input">The input object.</param>
|
/// <param name="input">The input object.</param>
|
||||||
public FilterExecutionContext(ITelegramBotInfo botInfo, Update update, T input)
|
public FilterExecutionContext(IUpdateRouter router, ITelegramBotInfo botInfo, Update update, T input)
|
||||||
: this(botInfo, update, input, [], []) { }
|
: this(router, botInfo, update, input, [], []) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a child context for a different input type, sharing the same data and completed filters.
|
/// Creates a child context for a different input type, sharing the same data and completed filters.
|
||||||
@@ -73,6 +81,5 @@ namespace Telegrator.Core.Filters
|
|||||||
/// <param name="input">The new input object.</param>
|
/// <param name="input">The new input object.</param>
|
||||||
/// <returns>A new <see cref="FilterExecutionContext{C}"/> instance.</returns>
|
/// <returns>A new <see cref="FilterExecutionContext{C}"/> instance.</returns>
|
||||||
public FilterExecutionContext<C> CreateChild<C>(C input) where C : class
|
public FilterExecutionContext<C> CreateChild<C>(C input) where C : class
|
||||||
=> new FilterExecutionContext<C>(BotInfo, Update, input, Data, CompletedFilters);
|
=> new FilterExecutionContext<C>(UpdateRouter, BotInfo, Update, input, Data, CompletedFilters);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace Telegrator.Core.Filters
|
namespace Telegrator.Core.Filters;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interface for filters that have a name for identification and debugging purposes.
|
/// Interface for filters that have a name for identification and debugging purposes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -36,4 +36,15 @@
|
|||||||
/// <returns>True if the filter passes; otherwise, false.</returns>
|
/// <returns>True if the filter passes; otherwise, false.</returns>
|
||||||
public bool CanPass(FilterExecutionContext<T> info);
|
public bool CanPass(FilterExecutionContext<T> info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a filter that joins multiple filters together.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of the input for the filter.</typeparam>
|
||||||
|
public interface IJoinedFilter<T> : IFilter<T> where T : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the array of joined filters.
|
||||||
|
/// </summary>
|
||||||
|
public IFilter<T>[] Filters { get; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
namespace Telegrator.Core.Filters
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a filter that joins multiple filters together.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">The type of the input for the filter.</typeparam>
|
|
||||||
public interface IJoinedFilter<T> : IFilter<T> where T : class
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the array of joined filters.
|
|
||||||
/// </summary>
|
|
||||||
public IFilter<T>[] Filters { get; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,10 +3,11 @@ using Telegram.Bot.Types;
|
|||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
using Telegrator.Core.Descriptors;
|
using Telegrator.Core.Descriptors;
|
||||||
using Telegrator.Core.Filters;
|
using Telegrator.Core.Filters;
|
||||||
|
using Telegrator.Core.States;
|
||||||
using Telegrator.Handlers;
|
using Telegrator.Handlers;
|
||||||
|
|
||||||
namespace Telegrator.Core.Handlers
|
namespace Telegrator.Core.Handlers;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Abstract handler for Telegram updates of type <typeparamref name="TUpdate"/>.
|
/// Abstract handler for Telegram updates of type <typeparamref name="TUpdate"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -47,6 +48,11 @@ namespace Telegrator.Core.Handlers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected IAwaitingProvider AwaitingProvider => Container.AwaitingProvider;
|
protected IAwaitingProvider AwaitingProvider => Container.AwaitingProvider;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Storage of bot states.
|
||||||
|
/// </summary>
|
||||||
|
protected IStateStorage StateStorage => Container.StateStorage;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance and checks that the update type matches <typeparamref name="TUpdate"/>.
|
/// Initializes a new instance and checks that the update type matches <typeparamref name="TUpdate"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -87,4 +93,3 @@ namespace Telegrator.Core.Handlers
|
|||||||
/// <returns>A task representing the asynchronous operation.</returns>
|
/// <returns>A task representing the asynchronous operation.</returns>
|
||||||
public abstract Task<Result> Execute(IHandlerContainer<TUpdate> container, CancellationToken cancellation);
|
public abstract Task<Result> Execute(IHandlerContainer<TUpdate> container, CancellationToken cancellation);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ using Telegrator.Core.Descriptors;
|
|||||||
using Telegrator.Core.Filters;
|
using Telegrator.Core.Filters;
|
||||||
using Telegrator.Handlers;
|
using Telegrator.Handlers;
|
||||||
|
|
||||||
namespace Telegrator.Core.Handlers
|
namespace Telegrator.Core.Handlers;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Abstract base class for handlers that support branching execution based on different methods.
|
/// Abstract base class for handlers that support branching execution based on different methods.
|
||||||
/// Allows multiple handler methods to be defined in a single class, each with its own filters.
|
/// Allows multiple handler methods to be defined in a single class, each with its own filters.
|
||||||
@@ -162,4 +162,3 @@ namespace Telegrator.Core.Handlers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
using Telegrator.Annotations.StateKeeping;
|
|
||||||
using Telegrator.Core.Descriptors;
|
using Telegrator.Core.Descriptors;
|
||||||
using Telegrator.Core.Filters;
|
using Telegrator.Core.Filters;
|
||||||
using Telegrator.Core.StateKeeping;
|
using Telegrator.Core.States;
|
||||||
|
using Telegrator.Filters;
|
||||||
|
|
||||||
|
namespace Telegrator.Core.Handlers.Building;
|
||||||
|
|
||||||
namespace Telegrator.Core.Handlers.Building
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Base class for building handler descriptors and managing handler filters.
|
/// Base class for building handler descriptors and managing handler filters.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -15,7 +15,7 @@ namespace Telegrator.Core.Handlers.Building
|
|||||||
private static int HandlerServiceKeyIndex = 0;
|
private static int HandlerServiceKeyIndex = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <see cref="IHandlersCollection"/> to ehich new builded handlers is adding
|
/// <see cref="IHandlersCollection"/> to which new builded handlers is adding
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected readonly IHandlersCollection? HandlerCollection = handlerCollection;
|
protected readonly IHandlersCollection? HandlerCollection = handlerCollection;
|
||||||
|
|
||||||
@@ -140,35 +140,15 @@ namespace Telegrator.Core.Handlers.Building
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets a state keeper for the handler using a specific state and key resolver.
|
/// Sets a state keeper for the handler using a specific state and key resolver.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TKey">The type of the key.</typeparam>
|
/// <typeparam name="TKey">The key resolver.</typeparam>
|
||||||
/// <typeparam name="TState">The type of the state.</typeparam>
|
/// <typeparam name="TValue">The state value.</typeparam>
|
||||||
/// <typeparam name="TKeeper">The type of the state keeper.</typeparam>
|
/// <param name="state">The state value.</param>
|
||||||
/// <param name="myState">The state value.</param>
|
|
||||||
/// <param name="keyResolver">The key resolver.</param>
|
|
||||||
/// <returns>The builder instance.</returns>
|
/// <returns>The builder instance.</returns>
|
||||||
public void SetStateKeeper<TKey, TState, TKeeper>(TState myState, IStateKeyResolver<TKey> keyResolver)
|
public void SetState<TKey, TValue>(TValue? state)
|
||||||
where TKey : notnull
|
where TKey : IStateKeyResolver, new()
|
||||||
where TState : IEquatable<TState>
|
where TValue : IEquatable<TValue>
|
||||||
where TKeeper : StateKeeperBase<TKey, TState>, new()
|
|
||||||
{
|
{
|
||||||
StateKeeper = new StateKeepFilter<TKey, TState, TKeeper>(myState, keyResolver);
|
StateKeeper = new StateKeyFilter<TKey, TValue>(state);
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets a state keeper for the handler using a special state and key resolver.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="TKey">The type of the key.</typeparam>
|
|
||||||
/// <typeparam name="TState">The type of the state.</typeparam>
|
|
||||||
/// <typeparam name="TKeeper">The type of the state keeper.</typeparam>
|
|
||||||
/// <param name="specialState">The special state value.</param>
|
|
||||||
/// <param name="keyResolver">The key resolver.</param>
|
|
||||||
/// <returns>The builder instance.</returns>
|
|
||||||
public void SetStateKeeper<TKey, TState, TKeeper>(SpecialState specialState, IStateKeyResolver<TKey> keyResolver)
|
|
||||||
where TKey : notnull
|
|
||||||
where TState : IEquatable<TState>
|
|
||||||
where TKeeper : StateKeeperBase<TKey, TState>, new()
|
|
||||||
{
|
|
||||||
StateKeeper = new StateKeepFilter<TKey, TState, TKeeper>(specialState, keyResolver);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -197,4 +177,3 @@ namespace Telegrator.Core.Handlers.Building
|
|||||||
Filters.Add(compiledPollingFilter);
|
Filters.Add(compiledPollingFilter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Telegrator.Core.StateKeeping;
|
using Telegrator.Core.States;
|
||||||
|
|
||||||
|
namespace Telegrator.Core.Handlers.Building;
|
||||||
|
|
||||||
namespace Telegrator.Core.Handlers.Building
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines a builder for awaiting handler logic for a specific update type.
|
/// Defines a builder for awaiting handler logic for a specific update type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -11,9 +11,8 @@ namespace Telegrator.Core.Handlers.Building
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Awaits an update using the specified key resolver and cancellation token.
|
/// Awaits an update using the specified key resolver and cancellation token.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="keyResolver">The <see cref="IStateKeyResolver{TKey}"/> to resolve the key.</param>
|
/// <param name="keyResolver">The <see cref="IStateKeyResolver"/> to resolve the key.</param>
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns>A <see cref="Task{TUpdate}"/> representing the awaited update.</returns>
|
/// <returns>A <see cref="Task{TUpdate}"/> representing the awaited update.</returns>
|
||||||
public Task<TUpdate> Await(IStateKeyResolver<long> keyResolver, CancellationToken cancellationToken = default);
|
public Task<TUpdate> Await(IStateKeyResolver keyResolver, CancellationToken cancellationToken = default);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegrator.Annotations.StateKeeping;
|
|
||||||
using Telegrator.Core.Filters;
|
using Telegrator.Core.Filters;
|
||||||
using Telegrator.Core.StateKeeping;
|
using Telegrator.Core.States;
|
||||||
|
|
||||||
|
namespace Telegrator.Core.Handlers.Building;
|
||||||
|
|
||||||
namespace Telegrator.Core.Handlers.Building
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines builder actions for configuring handler builders.
|
/// Defines builder actions for configuring handler builders.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -56,30 +55,13 @@ namespace Telegrator.Core.Handlers.Building
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets a state keeper for the handler using a specific state and key resolver.
|
/// Sets a state keeper for the handler using a specific state and key resolver.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TKey">The type of the key.</typeparam>
|
/// <typeparam name="TKey">The key resolver.</typeparam>
|
||||||
/// <typeparam name="TState">The type of the state.</typeparam>
|
/// <typeparam name="TValue">The state value.</typeparam>
|
||||||
/// <typeparam name="TKeeper">The type of the state keeper.</typeparam>
|
/// <param name="state">The state value.</param>
|
||||||
/// <param name="myState">The state value.</param>
|
|
||||||
/// <param name="keyResolver">The key resolver.</param>
|
|
||||||
/// <returns>The builder instance.</returns>
|
/// <returns>The builder instance.</returns>
|
||||||
public void SetStateKeeper<TKey, TState, TKeeper>(TState myState, IStateKeyResolver<TKey> keyResolver)
|
public void SetState<TKey, TValue>(TValue? state)
|
||||||
where TKey : notnull
|
where TKey : IStateKeyResolver, new()
|
||||||
where TState : IEquatable<TState>
|
where TValue : IEquatable<TValue>;
|
||||||
where TKeeper : StateKeeperBase<TKey, TState>, new();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets a state keeper for the handler using a special state and key resolver.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="TKey">The type of the key.</typeparam>
|
|
||||||
/// <typeparam name="TState">The type of the state.</typeparam>
|
|
||||||
/// <typeparam name="TKeeper">The type of the state keeper.</typeparam>
|
|
||||||
/// <param name="specialState">The special state value.</param>
|
|
||||||
/// <param name="keyResolver">The key resolver.</param>
|
|
||||||
/// <returns>The builder instance.</returns>
|
|
||||||
public void SetStateKeeper<TKey, TState, TKeeper>(SpecialState specialState, IStateKeyResolver<TKey> keyResolver)
|
|
||||||
where TKey : notnull
|
|
||||||
where TState : IEquatable<TState>
|
|
||||||
where TKeeper : StateKeeperBase<TKey, TState>, new();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a targeted filter for a specific filter target type.
|
/// Adds a targeted filter for a specific filter target type.
|
||||||
@@ -101,4 +83,3 @@ namespace Telegrator.Core.Handlers.Building
|
|||||||
public void AddTargetedFilters<TFilterTarget>(Func<Update, TFilterTarget?> getFilterringTarget, params IFilter<TFilterTarget>[] filters)
|
public void AddTargetedFilters<TFilterTarget>(Func<Update, TFilterTarget?> getFilterringTarget, params IFilter<TFilterTarget>[] filters)
|
||||||
where TFilterTarget : class;
|
where TFilterTarget : class;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Telegrator.Handlers.Building;
|
using Telegrator.Handlers.Building;
|
||||||
|
|
||||||
namespace Telegrator.Core.Handlers.Building
|
namespace Telegrator.Core.Handlers.Building;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines a builder for regular handler logic for a specific update type.
|
/// Defines a builder for regular handler logic for a specific update type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -14,4 +14,3 @@ namespace Telegrator.Core.Handlers.Building
|
|||||||
/// <param name="executeHandler">The delegate to execute the handler logic.</param>
|
/// <param name="executeHandler">The delegate to execute the handler logic.</param>
|
||||||
public IHandlersCollection Build(AbstractHandlerAction<TUpdate> executeHandler);
|
public IHandlersCollection Build(AbstractHandlerAction<TUpdate> executeHandler);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,80 +0,0 @@
|
|||||||
using Telegram.Bot.Types;
|
|
||||||
using Telegrator.Annotations.StateKeeping;
|
|
||||||
using Telegrator.Core.Filters;
|
|
||||||
using Telegrator.Core.StateKeeping;
|
|
||||||
using Telegrator.Filters;
|
|
||||||
|
|
||||||
namespace Telegrator.Core.Handlers.Building
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Filter for state keeping logic, allowing filtering based on state and special state conditions.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="TKey">The type of the key for state resolution.</typeparam>
|
|
||||||
/// <typeparam name="TState">The type of the state.</typeparam>
|
|
||||||
/// <typeparam name="TKeeper">The type of the state keeper.</typeparam>
|
|
||||||
public class StateKeepFilter<TKey, TState, TKeeper> : Filter<Update>
|
|
||||||
where TKey : notnull
|
|
||||||
where TState : IEquatable<TState>
|
|
||||||
where TKeeper : StateKeeperBase<TKey, TState>, new()
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the state keeper instance.
|
|
||||||
/// </summary>
|
|
||||||
public static TKeeper StateKeeper { get; internal set; } = null!;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the state value for this filter.
|
|
||||||
/// </summary>
|
|
||||||
public TState MyState { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the special state value for this filter.
|
|
||||||
/// </summary>
|
|
||||||
public SpecialState SpecialState { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="StateKeepFilter{TKey, TState, TKeeper}"/> class with a specific state.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="myState">The state value.</param>
|
|
||||||
/// <param name="keyResolver">The key resolver.</param>
|
|
||||||
public StateKeepFilter(TState myState, IStateKeyResolver<TKey> keyResolver)
|
|
||||||
{
|
|
||||||
StateKeeper ??= new TKeeper();
|
|
||||||
StateKeeper.KeyResolver = keyResolver;
|
|
||||||
MyState = myState;
|
|
||||||
SpecialState = SpecialState.None;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="StateKeepFilter{TKey, TState, TKeeper}"/> class with a special state.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="specialState">The special state value.</param>
|
|
||||||
/// <param name="keyResolver">The key resolver.</param>
|
|
||||||
public StateKeepFilter(SpecialState specialState, IStateKeyResolver<TKey> keyResolver)
|
|
||||||
{
|
|
||||||
StateKeeper ??= new TKeeper();
|
|
||||||
StateKeeper.KeyResolver = keyResolver;
|
|
||||||
MyState = StateKeeper.DefaultState;
|
|
||||||
SpecialState = specialState;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Determines whether the filter can pass for the given context based on state logic.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="context">The filter execution context.</param>
|
|
||||||
/// <returns>True if the filter passes; otherwise, false.</returns>
|
|
||||||
public override bool CanPass(FilterExecutionContext<Update> context)
|
|
||||||
{
|
|
||||||
if (SpecialState == SpecialState.AnyState)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (!StateKeeper.TryGetState(context.Input, out TState? state))
|
|
||||||
return SpecialState == SpecialState.NoState;
|
|
||||||
|
|
||||||
if (state == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return MyState.Equals(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegrator.Core.Filters;
|
using Telegrator.Core.Filters;
|
||||||
|
|
||||||
namespace Telegrator.Core.Handlers.Building
|
namespace Telegrator.Core.Handlers.Building;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delegate for validating an update in a filter context.
|
/// Delegate for validating an update in a filter context.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -38,4 +38,3 @@ namespace Telegrator.Core.Handlers.Building
|
|||||||
public bool CanPass(FilterExecutionContext<Update> info)
|
public bool CanPass(FilterExecutionContext<Update> info)
|
||||||
=> UpdateValidateAction.Invoke(info);
|
=> UpdateValidateAction.Invoke(info);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegrator.Core.Filters;
|
using Telegrator.Core.Filters;
|
||||||
|
using Telegrator.Core.States;
|
||||||
|
|
||||||
|
namespace Telegrator.Core.Handlers;
|
||||||
|
|
||||||
namespace Telegrator.Core.Handlers
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents an empty handler container that throws <see cref="NotImplementedException"/> for all members.
|
/// Represents an empty handler container that throws <see cref="NotImplementedException"/> for all members.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -23,5 +24,7 @@ namespace Telegrator.Core.Handlers
|
|||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IAwaitingProvider AwaitingProvider => throw new NotImplementedException();
|
public IAwaitingProvider AwaitingProvider => throw new NotImplementedException();
|
||||||
}
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public IStateStorage StateStorage => throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace Telegrator.Core.Handlers
|
namespace Telegrator.Core.Handlers;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a token that tracks the lifetime of a handler instance.
|
/// Represents a token that tracks the lifetime of a handler instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -24,4 +24,3 @@
|
|||||||
OnLifetimeEnded?.Invoke(this);
|
OnLifetimeEnded?.Invoke(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegrator.Core.Filters;
|
using Telegrator.Core.Filters;
|
||||||
|
using Telegrator.Core.States;
|
||||||
|
|
||||||
|
namespace Telegrator.Core.Handlers;
|
||||||
|
|
||||||
namespace Telegrator.Core.Handlers
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interface for handler containers that provide context and resources for update handlers.
|
/// Interface for handler containers that provide context and resources for update handlers.
|
||||||
/// Contains all necessary information and services that handlers need during execution.
|
/// Contains all necessary information and services that handlers need during execution.
|
||||||
@@ -34,5 +35,9 @@ namespace Telegrator.Core.Handlers
|
|||||||
/// Gets the <see cref="IAwaitingProvider"/> for awaiting operations.
|
/// Gets the <see cref="IAwaitingProvider"/> for awaiting operations.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IAwaitingProvider AwaitingProvider { get; }
|
public IAwaitingProvider AwaitingProvider { get; }
|
||||||
}
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the <see cref="IStateStorage"/> for state managment.
|
||||||
|
/// </summary>
|
||||||
|
public IStateStorage StateStorage { get; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Telegrator.Core.Descriptors;
|
using Telegrator.Core.Descriptors;
|
||||||
|
|
||||||
namespace Telegrator.Core.Handlers
|
namespace Telegrator.Core.Handlers;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Factory interface for creating handler containers.
|
/// Factory interface for creating handler containers.
|
||||||
/// Provides a way to create handler containers with specific providers and handler information.
|
/// Provides a way to create handler containers with specific providers and handler information.
|
||||||
@@ -15,4 +15,3 @@ namespace Telegrator.Core.Handlers
|
|||||||
/// <returns>A new <see cref="IHandlerContainer"/> instance.</returns>
|
/// <returns>A new <see cref="IHandlerContainer"/> instance.</returns>
|
||||||
public IHandlerContainer CreateContainer(DescribedHandlerDescriptor handlerInfo);
|
public IHandlerContainer CreateContainer(DescribedHandlerDescriptor handlerInfo);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ using Telegram.Bot.Types.Enums;
|
|||||||
using Telegrator.Core.Descriptors;
|
using Telegrator.Core.Descriptors;
|
||||||
using Telegrator.Handlers.Diagnostics;
|
using Telegrator.Handlers.Diagnostics;
|
||||||
|
|
||||||
namespace Telegrator.Core.Handlers
|
namespace Telegrator.Core.Handlers;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Base class for update handlers, providing execution and lifetime management for Telegram updates.
|
/// Base class for update handlers, providing execution and lifetime management for Telegram updates.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -125,7 +125,7 @@ namespace Telegrator.Core.Handlers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal IHandlerContainer GetContainer(DescribedHandlerDescriptor handlerInfo)
|
private IHandlerContainer GetContainer(DescribedHandlerDescriptor handlerInfo)
|
||||||
{
|
{
|
||||||
if (this is IHandlerContainerFactory handlerDefainedContainerFactory)
|
if (this is IHandlerContainerFactory handlerDefainedContainerFactory)
|
||||||
return handlerDefainedContainerFactory.CreateContainer(handlerInfo);
|
return handlerDefainedContainerFactory.CreateContainer(handlerInfo);
|
||||||
@@ -179,4 +179,3 @@ namespace Telegrator.Core.Handlers
|
|||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Telegrator.Core.Descriptors;
|
using Telegrator.Core.Descriptors;
|
||||||
|
|
||||||
namespace Telegrator.Core
|
namespace Telegrator.Core;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provider for managing awaiting handlers that can wait for specific update types.
|
/// Provider for managing awaiting handlers that can wait for specific update types.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -14,4 +14,3 @@ namespace Telegrator.Core
|
|||||||
/// <returns>An <see cref="IDisposable"/> that manages the handler's usage lifetime.</returns>
|
/// <returns>An <see cref="IDisposable"/> that manages the handler's usage lifetime.</returns>
|
||||||
public IDisposable UseHandler(HandlerDescriptor handlerDescriptor);
|
public IDisposable UseHandler(HandlerDescriptor handlerDescriptor);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user