Compare commits
No commits in common. "master" and "pending-list" have entirely different histories.
master
...
pending-li
34 changed files with 689 additions and 2239 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,5 +1,4 @@
|
|||
/subscribe-bot
|
||||
/test.db
|
||||
/test.db-sqlite
|
||||
/db
|
||||
/config.toml
|
||||
/repos
|
||||
|
|
674
LICENSE
674
LICENSE
|
@ -1,674 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
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>.
|
12
Makefile
12
Makefile
|
@ -1,12 +0,0 @@
|
|||
GIT_COMMIT = $(shell git rev-parse --short HEAD)
|
||||
SOURCES = $(shell find . -type f -and -name "*.go" -or -name "*.html")
|
||||
|
||||
all: subscribe-bot
|
||||
|
||||
subscribe-bot: $(SOURCES)
|
||||
go build -o $@ -ldflags "-X main.GitCommit=$(GIT_COMMIT)"
|
||||
|
||||
checkFmt:
|
||||
[ -z "$$(git ls-files | grep '\.go$$' | xargs gofmt -l)" ] || (exit 1)
|
||||
|
||||
.PHONY: all checkFmt
|
15
README.md
15
README.md
|
@ -4,9 +4,8 @@ subscribe-bot
|
|||
Subscribes to OSU map updates and stores versions for later review.
|
||||
|
||||
Please don't run a separate bot, the official one is `subscribe-bot#8789`. If
|
||||
you want to contribute or test the bot, instructions on how to run it are below.
|
||||
|
||||
Join the [Discord][2]
|
||||
you want to contribute or test the bot, then here are instructions on how to
|
||||
run it:
|
||||
|
||||
How to run
|
||||
----------
|
||||
|
@ -23,19 +22,9 @@ How to run
|
|||
1. Run the executable, passing `-config {path}` in case you want to use a
|
||||
different config file than `config.toml`.
|
||||
|
||||
Architecture
|
||||
------------
|
||||
|
||||
There's several independent services running within:
|
||||
|
||||
- Discord bot, which posts updates to the relevant channels in discord
|
||||
- Web server, which hosts an HTTP server allowing you to view changes
|
||||
- Scraper, which actually polls the OSU API for new updates
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
[GPL3][1]
|
||||
|
||||
[1]: https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||
[2]: https://discord.gg/eqjVG2H
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package discord
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
@ -17,21 +17,18 @@ import (
|
|||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
|
||||
"subscribe-bot/config"
|
||||
"subscribe-bot/db"
|
||||
"subscribe-bot/osuapi"
|
||||
)
|
||||
|
||||
type Bot struct {
|
||||
*discordgo.Session
|
||||
mentionRe *regexp.Regexp
|
||||
db *db.Db
|
||||
api *osuapi.Osuapi
|
||||
config *config.Config
|
||||
db *Db
|
||||
api *Osuapi
|
||||
requests chan int
|
||||
config *Config
|
||||
}
|
||||
|
||||
func NewBot(config *config.Config, db *db.Db, api *osuapi.Osuapi) (bot *Bot, err error) {
|
||||
func NewBot(config *Config, db *Db, requests chan int) (bot *Bot, err error) {
|
||||
s, err := discordgo.New("Bot " + config.BotToken)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -48,17 +45,11 @@ func NewBot(config *config.Config, db *db.Db, api *osuapi.Osuapi) (bot *Bot, err
|
|||
return
|
||||
}
|
||||
|
||||
bot = &Bot{s, re, db, api, config}
|
||||
bot = &Bot{s, re, db, db.api, requests, config}
|
||||
s.AddHandler(bot.errWrap(bot.newMessageHandler))
|
||||
return
|
||||
}
|
||||
|
||||
func (bot *Bot) NotifyError(format string, args ...interface{}) {
|
||||
msg := fmt.Sprintf(format, args...)
|
||||
channel, _ := bot.UserChannelCreate("100443064228646912")
|
||||
bot.ChannelMessageSend(channel.ID, msg)
|
||||
}
|
||||
|
||||
func (bot *Bot) errWrap(fn interface{}) interface{} {
|
||||
val := reflect.ValueOf(fn)
|
||||
origType := reflect.TypeOf(fn)
|
||||
|
@ -72,7 +63,10 @@ func (bot *Bot) errWrap(fn interface{}) interface{} {
|
|||
if len(res) > 0 && !res[0].IsNil() {
|
||||
err := res[0].Interface().(error)
|
||||
if err != nil {
|
||||
bot.NotifyError("error: %s", err)
|
||||
msg := fmt.Sprintf("error: %s", err)
|
||||
channel, _ := bot.UserChannelCreate("100443064228646912")
|
||||
id, _ := bot.ChannelMessageSend(channel.ID, msg)
|
||||
log.Println(id, msg)
|
||||
}
|
||||
}
|
||||
return []reflect.Value{}
|
||||
|
@ -80,7 +74,7 @@ func (bot *Bot) errWrap(fn interface{}) interface{} {
|
|||
return newFunc.Interface()
|
||||
}
|
||||
|
||||
func (bot *Bot) NotifyNewBeatmap(channels []string, newMaps []osuapi.Beatmapset) (err error) {
|
||||
func (bot *Bot) NotifyNewBeatmap(channels []string, newMaps []Beatmapset) (err error) {
|
||||
for _, beatmapSet := range newMaps {
|
||||
var eventTime time.Time
|
||||
eventTime, err = time.Parse(time.RFC3339, beatmapSet.LastUpdated)
|
||||
|
@ -103,7 +97,7 @@ func (bot *Bot) NotifyNewBeatmap(channels []string, newMaps []osuapi.Beatmapset)
|
|||
|
||||
// try to open a repo for this beatmap
|
||||
var repo *git.Repository
|
||||
repoDir := path.Join(bot.config.Repos, strconv.Itoa(beatmapSet.UserID), strconv.Itoa(beatmapSet.ID))
|
||||
repoDir := path.Join(bot.config.Repos, strconv.Itoa(beatmapSet.ID))
|
||||
if _, err := os.Stat(repoDir); os.IsNotExist(err) {
|
||||
os.MkdirAll(repoDir, 0777)
|
||||
}
|
||||
|
@ -155,7 +149,7 @@ func (bot *Bot) NotifyNewBeatmap(channels []string, newMaps []osuapi.Beatmapset)
|
|||
},
|
||||
)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("couldn't create commit for %d: %w", beatmapSet.ID, err)
|
||||
err = fmt.Errorf("couldn't create commit for %s: %w", beatmapSet.ID, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -171,7 +165,7 @@ func (bot *Bot) NotifyNewBeatmap(channels []string, newMaps []osuapi.Beatmapset)
|
|||
err = fmt.Errorf("couldn't retrieve commit parent: %w", err)
|
||||
return
|
||||
} else {
|
||||
patch, err = parent.Patch(commit)
|
||||
patch, err = commit.Patch(parent)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("couldn't retrieve patch: %w", err)
|
||||
return
|
||||
|
@ -179,26 +173,16 @@ func (bot *Bot) NotifyNewBeatmap(channels []string, newMaps []osuapi.Beatmapset)
|
|||
foundPatch = true
|
||||
}
|
||||
|
||||
fmt.Println("saving", beatmapSet)
|
||||
bot.db.SaveBeatmap(db.Beatmapset{
|
||||
ID: beatmapSet.ID,
|
||||
MapperID: beatmapSet.UserID,
|
||||
Artist: beatmapSet.Artist,
|
||||
Title: beatmapSet.Title,
|
||||
LastUpdated: eventTime,
|
||||
})
|
||||
bot.db.GetUser(beatmapSet.UserID)
|
||||
|
||||
embed := &discordgo.MessageEmbed{
|
||||
URL: fmt.Sprintf("%s/map/%d/%d/versions", bot.config.Web.ServedAt, beatmapSet.UserID, beatmapSet.ID),
|
||||
URL: fmt.Sprintf("https://osu.ppy.sh/s/%d", beatmapSet.ID),
|
||||
Title: fmt.Sprintf("Update: %s - %s", beatmapSet.Artist, beatmapSet.Title),
|
||||
Timestamp: eventTime.Format(time.RFC3339),
|
||||
Author: &discordgo.MessageEmbedAuthor{
|
||||
URL: "https://osu.ppy.sh/u/" + strconv.Itoa(beatmapSet.UserID),
|
||||
URL: "https://osu.ppy.sh/u/" + strconv.Itoa(beatmapSet.UserId),
|
||||
Name: beatmapSet.Creator,
|
||||
IconURL: fmt.Sprintf(
|
||||
"https://a.ppy.sh/%d?%d.png",
|
||||
beatmapSet.UserID,
|
||||
beatmapSet.UserId,
|
||||
time.Now().Unix(),
|
||||
),
|
||||
},
|
||||
|
@ -224,6 +208,7 @@ func (bot *Bot) NotifyNewBeatmap(channels []string, newMaps []osuapi.Beatmapset)
|
|||
_, err = bot.ChannelMessageSendEmbed(channelId, embed)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to send to %s: %w", channelId, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -235,7 +220,7 @@ type BeatmapsetDownloaded struct {
|
|||
Path string
|
||||
}
|
||||
|
||||
func (bot *Bot) downloadBeatmapTo(beatmapSet *osuapi.Beatmapset, repo *git.Repository, repoDir string) (err error) {
|
||||
func (bot *Bot) downloadBeatmapTo(beatmapSet *Beatmapset, repo *git.Repository, repoDir string) (err error) {
|
||||
// clear all OSU files
|
||||
files, err := ioutil.ReadDir(repoDir)
|
||||
if err != nil {
|
||||
|
@ -259,7 +244,7 @@ func (bot *Bot) downloadBeatmapTo(beatmapSet *osuapi.Beatmapset, repo *git.Repos
|
|||
return
|
||||
}
|
||||
|
||||
func (bot *Bot) getBeatmapsetInfo(event osuapi.Event) (beatmapSet osuapi.Beatmapset, err error) {
|
||||
func (bot *Bot) getBeatmapsetInfo(event Event) (beatmapSet Beatmapset, err error) {
|
||||
beatmapSetId, err := strconv.Atoi(strings.TrimPrefix(event.Beatmapset.URL, "/s/"))
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -298,7 +283,7 @@ func (bot *Bot) newMessageHandler(s *discordgo.Session, m *discordgo.MessageCrea
|
|||
return
|
||||
}
|
||||
|
||||
var mapper osuapi.User
|
||||
var mapper User
|
||||
mapperName := strings.Join(parts[1:], " ")
|
||||
mapper, err = bot.api.GetUser(mapperName)
|
||||
if err != nil {
|
||||
|
@ -311,16 +296,12 @@ func (bot *Bot) newMessageHandler(s *discordgo.Session, m *discordgo.MessageCrea
|
|||
return
|
||||
}
|
||||
|
||||
// go func() {
|
||||
// time.Sleep(refreshInterval)
|
||||
// bot.requests <- mapperId
|
||||
// }()
|
||||
|
||||
bot.ChannelMessageSend(m.ChannelID, fmt.Sprintf("subscribed to %+v", mapper))
|
||||
|
||||
case "list":
|
||||
mappers := make([]string, 0)
|
||||
bot.db.IterChannelTrackedMappers(m.ChannelID, func(mapper db.User) error {
|
||||
mappers = append(mappers, mapper.Username)
|
||||
return nil
|
||||
})
|
||||
|
||||
bot.ChannelMessageSend(m.ChannelID, "tracking: "+strings.Join(mappers, ", "))
|
||||
}
|
||||
|
||||
return
|
|
@ -1,4 +1,4 @@
|
|||
package config
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -9,25 +9,10 @@ import (
|
|||
)
|
||||
|
||||
type Config struct {
|
||||
Debug bool `toml:"debug,omitempty"`
|
||||
BotToken string `toml:"bot_token"`
|
||||
Repos string `toml:"repos"`
|
||||
DatabasePath string `toml:"db_path"`
|
||||
|
||||
Oauth OauthConfig `toml:"oauth"`
|
||||
Web WebConfig `toml:"web"`
|
||||
}
|
||||
|
||||
type OauthConfig struct {
|
||||
ClientId string `toml:"client_id"`
|
||||
ClientId int `toml:"client_id"`
|
||||
ClientSecret string `toml:"client_secret"`
|
||||
}
|
||||
|
||||
type WebConfig struct {
|
||||
Host string `toml:"host"`
|
||||
Port int `toml:"port"`
|
||||
ServedAt string `toml:"served_at"`
|
||||
SessionSecret string `toml:"session_secret"`
|
||||
Repos string `toml:"repos"`
|
||||
}
|
||||
|
||||
func ReadConfig(path string) (config Config, err error) {
|
240
db.go
Normal file
240
db.go
Normal file
|
@ -0,0 +1,240 @@
|
|||
package main
|
||||
|
||||
// Database is laid out like this:
|
||||
// mapper/<mapper_id>/trackers/<channel_id> -> priority
|
||||
// mapper/<mapper_id>/latestEvent
|
||||
// channel/<channel_id>/tracks/<mapper_id> -> priority
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
bolt "go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
var (
|
||||
LATEST_EVENT = []byte("latestEvent")
|
||||
)
|
||||
|
||||
type Db struct {
|
||||
*bolt.DB
|
||||
api *Osuapi
|
||||
}
|
||||
|
||||
func OpenDb(path string, api *Osuapi) (db *Db, err error) {
|
||||
inner, err := bolt.Open(path, 0666, nil)
|
||||
db = &Db{inner, api}
|
||||
return
|
||||
}
|
||||
|
||||
// Loop over channels that are tracking this specific mapper
|
||||
func (db *Db) IterTrackingChannels(mapperId int, fn func(channelId string) error) (err error) {
|
||||
err = db.DB.View(func(tx *bolt.Tx) error {
|
||||
mapper := getMapper(tx, mapperId)
|
||||
if mapper == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
trackers := mapper.Bucket([]byte("trackers"))
|
||||
if trackers == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
c := trackers.Cursor()
|
||||
for k, _ := c.First(); k != nil; k, _ = c.Next() {
|
||||
channelId := string(k)
|
||||
err := fn(channelId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Loop over tracked mappers
|
||||
func (db *Db) IterTrackedMappers(fn func(userId int) error) (err error) {
|
||||
err = db.DB.View(func(tx *bolt.Tx) error {
|
||||
mappers := tx.Bucket([]byte("mapper"))
|
||||
if mappers == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
c := mappers.Cursor()
|
||||
for k, _ := c.First(); k != nil; k, _ = c.Next() {
|
||||
userId, err := strconv.Atoi(string(k))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = fn(userId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Get a list of channels that are tracking this mapper
|
||||
func (db *Db) GetMapperTrackers(userId int) (trackersList []string) {
|
||||
trackersList = make([]string, 0)
|
||||
db.DB.View(func(tx *bolt.Tx) error {
|
||||
mapper, err := getMapperMut(tx, userId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
trackers := mapper.Bucket([]byte("trackers"))
|
||||
if trackers == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
c := trackers.Cursor()
|
||||
for k, _ := c.First(); k != nil; k, _ = c.Next() {
|
||||
channelId := string(k)
|
||||
trackersList = append(trackersList, channelId)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Update the latest event of a mapper to the given one
|
||||
func (db *Db) UpdateMapperLatestEvent(userId int, eventId int) (err error) {
|
||||
err = db.DB.Update(func(tx *bolt.Tx) error {
|
||||
mapper, err := getMapperMut(tx, userId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = mapper.Put(LATEST_EVENT, []byte(strconv.Itoa(eventId)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Get the latest event ID of this mapper, if they have one
|
||||
func (db *Db) MapperLastEvent(userId int) (has bool, id int) {
|
||||
has = false
|
||||
id = -1
|
||||
db.DB.View(func(tx *bolt.Tx) error {
|
||||
mapper := getMapper(tx, userId)
|
||||
if mapper == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
lastEventId := mapper.Get(LATEST_EVENT)
|
||||
if lastEventId == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
id, err = strconv.Atoi(string(lastEventId))
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
has = true
|
||||
return nil
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Start tracking a new mapper (if they're not already tracked)
|
||||
func (db *Db) ChannelTrackMapper(channelId string, mapperId int, priority int) (err error) {
|
||||
events, err := db.api.GetUserEvents(mapperId, 1, 0)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = db.Batch(func(tx *bolt.Tx) error {
|
||||
{
|
||||
mapper, err := getMapperMut(tx, mapperId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(events) > 0 {
|
||||
latestEventId := strconv.Itoa(events[0].ID)
|
||||
mapper.Put(LATEST_EVENT, []byte(latestEventId))
|
||||
}
|
||||
|
||||
trackers, err := mapper.CreateBucketIfNotExists([]byte("trackers"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = trackers.Put([]byte(channelId), []byte(strconv.Itoa(priority)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
{
|
||||
channels, err := tx.CreateBucketIfNotExists([]byte("channels"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
channel, err := channels.CreateBucketIfNotExists([]byte(channelId))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tracks, err := channel.CreateBucketIfNotExists([]byte("tracks"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tracks.Put([]byte(strconv.Itoa(mapperId)), []byte(strconv.Itoa(priority)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (db *Db) Close() {
|
||||
db.DB.Close()
|
||||
}
|
||||
|
||||
func getMapper(tx *bolt.Tx, userId int) (mapper *bolt.Bucket) {
|
||||
mappers := tx.Bucket([]byte("mapper"))
|
||||
if mappers == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
mapper = mappers.Bucket([]byte(strconv.Itoa(userId)))
|
||||
if mapper == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func getMapperMut(tx *bolt.Tx, userId int) (mapper *bolt.Bucket, err error) {
|
||||
mappers, err := tx.CreateBucketIfNotExists([]byte("mapper"))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
mapper, err = mappers.CreateBucketIfNotExists([]byte(strconv.Itoa(userId)))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package db
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Beatmapset struct {
|
||||
gorm.Model
|
||||
ID int `gorm:"primaryKey"`
|
||||
Artist string
|
||||
Title string
|
||||
MapperID int `gorm:"mapper_id"`
|
||||
Mapper User `gorm:"foreignKey:MapperID"`
|
||||
LastUpdated time.Time `gorm:"last_updated"`
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package db
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
type DiscordChannel struct {
|
||||
gorm.Model
|
||||
ID string `gorm:"primaryKey"`
|
||||
TrackedMappers []User `gorm:"many2many:tracked_mappers"`
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package db
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
type Config struct {
|
||||
gorm.Model
|
||||
Key string `gorm:"key;primaryKey"`
|
||||
Value string `gorm:"value"`
|
||||
}
|
182
db/db.go
182
db/db.go
|
@ -1,182 +0,0 @@
|
|||
package db
|
||||
|
||||
// Database is laid out like this:
|
||||
// mapper/<mapper_id>/trackers/<channel_id> -> priority
|
||||
// mapper/<mapper_id>/latestEvent
|
||||
// channel/<channel_id>/tracks/<mapper_id> -> priority
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/logger"
|
||||
|
||||
"subscribe-bot/config"
|
||||
"subscribe-bot/osuapi"
|
||||
)
|
||||
|
||||
var (
|
||||
LATEST_EVENT = []byte("latestEvent")
|
||||
MAPPERS = []byte("mapper")
|
||||
CHANNELS = []byte("channels")
|
||||
)
|
||||
|
||||
type Db struct {
|
||||
gorm *gorm.DB
|
||||
api *osuapi.Osuapi
|
||||
}
|
||||
|
||||
func OpenDb(cfg config.Config, api *osuapi.Osuapi) (db *Db, err error) {
|
||||
gormConfig := &gorm.Config{}
|
||||
if cfg.Debug {
|
||||
gormConfig.Logger = logger.Default.LogMode(logger.Info)
|
||||
}
|
||||
|
||||
gorm, err := gorm.Open(sqlite.Open(cfg.DatabasePath), gormConfig)
|
||||
if err != nil {
|
||||
panic("failed to connect database")
|
||||
}
|
||||
|
||||
// auto-migrate
|
||||
gorm.AutoMigrate(&Config{})
|
||||
gorm.AutoMigrate(&User{})
|
||||
gorm.AutoMigrate(&Beatmapset{})
|
||||
gorm.AutoMigrate(&DiscordChannel{})
|
||||
|
||||
db = &Db{gorm, api}
|
||||
return
|
||||
}
|
||||
|
||||
func (db *Db) SaveBeatmap(beatmap Beatmapset) {
|
||||
db.gorm.Clauses(clause.OnConflict{UpdateAll: true}).Create(&beatmap)
|
||||
return
|
||||
}
|
||||
|
||||
func (db *Db) IterTrackedBeatmapsets(limit int, fn func(beatmapset Beatmapset) error) (err error) {
|
||||
var beatmapsets []Beatmapset
|
||||
db.gorm.Preload(clause.Associations).Limit(limit).Order("last_updated desc").Find(&beatmapsets)
|
||||
for _, beatmapset := range beatmapsets {
|
||||
fn(beatmapset)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (db *Db) IterTrackedBeatmapsetsBy(mapperId int, fn func(beatmapset Beatmapset) error) (err error) {
|
||||
var beatmapsets []Beatmapset
|
||||
db.gorm.Where("mapper_id = ?", mapperId).Order("last_updated desc").Find(&beatmapsets)
|
||||
for _, beatmapset := range beatmapsets {
|
||||
fn(beatmapset)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Loop over channels that are tracking this specific mapper
|
||||
func (db *Db) IterTrackingChannels(mapperId int, fn func(channel DiscordChannel) error) (err error) {
|
||||
var channels []DiscordChannel
|
||||
db.gorm.Model(&User{ID: mapperId}).Association("TrackingChannels").Find(&channels)
|
||||
for _, channel := range channels {
|
||||
fn(channel)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Loop over tracked mappers for this channel
|
||||
func (db *Db) IterChannelTrackedMappers(channelId string, fn func(user User) error) (err error) {
|
||||
var mappers []User
|
||||
db.gorm.Model(&DiscordChannel{ID: channelId}).Association("TrackedMappers").Find(&mappers)
|
||||
for _, mapper := range mappers {
|
||||
fn(mapper)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Loop over all tracked mappers
|
||||
func (db *Db) IterAllTrackedMappers(fn func(user User) error) (err error) {
|
||||
var mappers []User
|
||||
db.gorm.Find(&mappers)
|
||||
for _, mapper := range mappers {
|
||||
fn(mapper)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (db *Db) UpdateMapperLastEvent(userId int, eventId int) (err error) {
|
||||
if eventId == -1 {
|
||||
var events []osuapi.Event
|
||||
events, err = db.api.GetUserEvents(userId, 1, 0)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "couldn't get user events from API")
|
||||
return
|
||||
}
|
||||
|
||||
if len(events) > 0 {
|
||||
eventId = events[0].ID
|
||||
}
|
||||
}
|
||||
|
||||
db.gorm.Model(&User{}).Where("id = ?", userId).Update("latest_event_id", eventId)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get the latest event ID of this mapper, if they have one
|
||||
func (db *Db) MapperLastEvent(userId int) (has bool, id int) {
|
||||
var user User
|
||||
db.gorm.Select("latest_event_id").First(&user)
|
||||
return true, user.LatestEventID
|
||||
}
|
||||
|
||||
// Start tracking a new mapper (if they're not already tracked)
|
||||
func (db *Db) ChannelTrackMapper(channelId string, mapperId int, priority int) (err error) {
|
||||
err = db.gorm.Model(&DiscordChannel{ID: channelId}).Association("TrackedMappers").Append(db.GetUser(mapperId))
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "could not add tracking for channel "+channelId)
|
||||
return
|
||||
}
|
||||
|
||||
err = db.UpdateMapperLastEvent(mapperId, -1)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "could not update mapper latest event")
|
||||
return
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *Db) Close() {
|
||||
}
|
||||
|
||||
func (db *Db) GetUser(userId int) (user *User, err error) {
|
||||
// TODO: cache user info for some time?
|
||||
|
||||
apiUser, err := db.api.GetUser(strconv.Itoa(userId))
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "could not retrieve user from the API")
|
||||
return
|
||||
}
|
||||
|
||||
user = &User{
|
||||
ID: userId,
|
||||
Username: apiUser.Username,
|
||||
Country: apiUser.CountryCode,
|
||||
}
|
||||
db.gorm.Clauses(clause.OnConflict{UpdateAll: true}).Create(user)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type Stats struct {
|
||||
TotalMaps int64
|
||||
TotalUsers int64
|
||||
}
|
||||
|
||||
func (db *Db) GetStats() (stats Stats) {
|
||||
db.gorm.Model(&Beatmapset{}).Count(&stats.TotalMaps)
|
||||
db.gorm.Model(&Beatmapset{}).Group("mapper_id").Count(&stats.TotalUsers)
|
||||
return
|
||||
}
|
13
db/user.go
13
db/user.go
|
@ -1,13 +0,0 @@
|
|||
package db
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
type User struct {
|
||||
gorm.Model
|
||||
ID int `gorm:"primaryKey"`
|
||||
Username string
|
||||
Country string
|
||||
LatestEventID int `gorm:"latest_event_id"`
|
||||
TrackingChannels []DiscordChannel `gorm:"many2many:tracked_mappers"`
|
||||
TrackedBeatmapsets []Beatmapset `gorm:"foreignKey:MapperID"`
|
||||
}
|
12
go.mod
12
go.mod
|
@ -4,18 +4,8 @@ go 1.14
|
|||
|
||||
require (
|
||||
github.com/BurntSushi/toml v0.3.1
|
||||
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect
|
||||
github.com/bwmarrin/discordgo v0.22.0
|
||||
github.com/dustin/go-humanize v1.0.0
|
||||
github.com/foolin/goview v0.3.0
|
||||
github.com/gin-contrib/static v0.0.0-20200916080430-d45d9a37d28e
|
||||
github.com/gin-gonic/contrib v0.0.0-20201005132743-ca038bbf2944
|
||||
github.com/gin-gonic/gin v1.6.3
|
||||
github.com/go-git/go-git/v5 v5.2.0
|
||||
github.com/gorilla/sessions v1.2.1 // indirect
|
||||
github.com/kofalt/go-memoize v0.0.0-20200917044458-9b55a8d73e1c
|
||||
github.com/pkg/errors v0.8.1
|
||||
go.etcd.io/bbolt v1.3.5
|
||||
golang.org/x/sync v0.0.0-20201008141435-b3e1573b7520
|
||||
gorm.io/driver/sqlite v1.1.4
|
||||
gorm.io/gorm v1.21.12
|
||||
)
|
||||
|
|
137
go.sum
137
go.sum
|
@ -1,80 +1,27 @@
|
|||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
|
||||
github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0=
|
||||
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
|
||||
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs=
|
||||
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
|
||||
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=
|
||||
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
|
||||
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff h1:RmdPFa+slIr4SCBg4st/l/vZWVe9QJKMXGO60Bxbe04=
|
||||
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff/go.mod h1:+RTT1BOk5P97fT2CiHkbFQwkK3mjsFAP6zCYV2aXtjw=
|
||||
github.com/bwmarrin/discordgo v0.22.0 h1:uBxY1HmlVCsW1IuaPjpCGT6A2DBwRn0nvOguQIxDdFM=
|
||||
github.com/bwmarrin/discordgo v0.22.0/go.mod h1:c1WtWUGN6nREDmzIpyTp/iD3VYt4Fpx+bVyfBG7JE+M=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
|
||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
|
||||
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
|
||||
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
|
||||
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
|
||||
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
|
||||
github.com/foolin/goview v0.3.0 h1:q5wKwXKEFb20dMRfYd59uj5qGCo7q4L9eVHHUjmMWrg=
|
||||
github.com/foolin/goview v0.3.0/go.mod h1:OC1VHC4FfpWymhShj8L1Tc3qipFmrmm+luAEdTvkos4=
|
||||
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s=
|
||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||
github.com/gin-contrib/static v0.0.0-20200916080430-d45d9a37d28e h1:8bZpGwoPxkaivQPrAbWl+7zjjUcbFUnYp7yQcx2r2N0=
|
||||
github.com/gin-contrib/static v0.0.0-20200916080430-d45d9a37d28e/go.mod h1:VhW/Ch/3FhimwZb8Oj+qJmdMmoB8r7lmJ5auRjm50oQ=
|
||||
github.com/gin-gonic/contrib v0.0.0-20201005132743-ca038bbf2944 h1:CUXsTZuAAdpQinpKgInZqKTOfn/jkIA9DLnozeybVRQ=
|
||||
github.com/gin-gonic/contrib v0.0.0-20201005132743-ca038bbf2944/go.mod h1:iqneQ2Df3omzIVTkIfn7c1acsVnMGiSLn4XF5Blh3Yg=
|
||||
github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM=
|
||||
github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do=
|
||||
github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
|
||||
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
|
||||
github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
|
||||
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
|
||||
github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
|
||||
github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
|
||||
github.com/go-git/go-billy/v5 v5.0.0 h1:7NQHvd9FVid8VL4qVUMm8XifBK+2xCoZ2lSk0agRrHM=
|
||||
github.com/go-git/go-billy/v5 v5.0.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
|
||||
github.com/go-git/go-git-fixtures/v4 v4.0.2-0.20200613231340-f56387b50c12 h1:PbKy9zOy4aAKrJ5pibIRpVO2BXnK1Tlcg+caKI7Ox5M=
|
||||
github.com/go-git/go-git v1.0.0 h1:YcN9iDGDoXuIw0vHls6rINwV416HYa0EB2X+RBsyYp4=
|
||||
github.com/go-git/go-git v3.2.0+incompatible h1:puJR2KQIDtZm7uQoF5h+BUFHiU2naU4tfwau90nRIoo=
|
||||
github.com/go-git/go-git-fixtures/v4 v4.0.2-0.20200613231340-f56387b50c12/go.mod h1:m+ICp2rF3jDhFgEZ/8yziagdT1C+ZpZcrJjappBCDSw=
|
||||
github.com/go-git/go-git/v5 v5.2.0 h1:YPBLG/3UK1we1ohRkncLjaXWLW+HKp5QNM/jTli2JgI=
|
||||
github.com/go-git/go-git/v5 v5.2.0/go.mod h1:kh02eMX+wdqqxgNMEyq8YgwlIOsDOa9homkUq1PoTMs=
|
||||
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
|
||||
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM=
|
||||
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
|
||||
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
|
||||
github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY=
|
||||
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
|
||||
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
|
||||
github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY=
|
||||
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
|
||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
|
||||
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
|
||||
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8=
|
||||
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
|
||||
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
|
||||
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
|
||||
github.com/gorilla/sessions v1.1.1/go.mod h1:8KCfur6+4Mqcc6S0FEfKuN15Vl5MgXW92AE8ovaJD0w=
|
||||
github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI=
|
||||
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
|
||||
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
|
||||
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
|
||||
|
@ -82,121 +29,49 @@ github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJ
|
|||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
|
||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/jinzhu/now v1.1.2 h1:eVKgfIdy9b6zbWBMgFpfDPoAMifwSZagU9HmEU6zgiI=
|
||||
github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
|
||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY=
|
||||
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
|
||||
github.com/kofalt/go-memoize v0.0.0-20200917044458-9b55a8d73e1c h1:iQm590VHHIeY1j9OFi2qBPgIeDqxz+PmHdDK/fUcN7s=
|
||||
github.com/kofalt/go-memoize v0.0.0-20200917044458-9b55a8d73e1c/go.mod h1:IvB2BCBCdgZFN9ZSgInoUlL1sAu0Xbvqfd7D+qqzTeo=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
|
||||
github.com/labstack/echo/v4 v4.1.6/go.mod h1:kU/7PwzgNxZH4das4XNsSpBSOD09XIF5YEPzjpkGnGE=
|
||||
github.com/labstack/gommon v0.2.9/go.mod h1:E8ZTmW9vw5az5/ZyHWCp0Lw4OH2ecsaBP1C/NKavGG4=
|
||||
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
|
||||
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
|
||||
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
|
||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-sqlite3 v1.14.5 h1:1IdxlwTNazvbKJQSxoJ5/9ECbEeaTTyeU7sEAZ5KKTQ=
|
||||
github.com/mattn/go-sqlite3 v1.14.5/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI=
|
||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E=
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
||||
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
||||
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
|
||||
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
|
||||
github.com/smartystreets/gunit v1.4.2 h1:tyWYZffdPhQPfK5VsMQXfauwnJkqg7Tv5DLuQVYxq3Q=
|
||||
github.com/smartystreets/gunit v1.4.2/go.mod h1:ZjM1ozSIMJlAz/ay4SG8PeKF00ckUp+zMHZXV9/bvak=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
|
||||
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
|
||||
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
|
||||
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
|
||||
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
|
||||
github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
|
||||
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
|
||||
go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
|
||||
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
|
||||
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16 h1:y6ce7gCWtnH+m3dCjzQ1PCuwl28DDIc3VNnvY29DlIA=
|
||||
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM=
|
||||
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190607181551-461777fb6f67/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
|
||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201008141435-b3e1573b7520 h1:Bx6FllMpG4NWDOfhMBz1VR2QYNp/SAOHPIAsaVmxfPo=
|
||||
golang.org/x/sync v0.0.0-20201008141435-b3e1573b7520/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190609082536-301114b31cce/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
|
||||
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190608022120-eacb66d2a7c3/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
|
||||
gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y=
|
||||
gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=
|
||||
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
|
||||
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gorm.io/driver/sqlite v1.1.4 h1:PDzwYE+sI6De2+mxAneV9Xs11+ZyKV6oxD3wDGkaNvM=
|
||||
gorm.io/driver/sqlite v1.1.4/go.mod h1:mJCeTFr7+crvS+TRnWc5Z3UvwxUN1BGBLMrf5LA9DYw=
|
||||
gorm.io/gorm v1.20.7/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
|
||||
gorm.io/gorm v1.21.12 h1:3fQM0Eiz7jcJEhPggHEpoYnsGZqynMzverL77DV40RM=
|
||||
gorm.io/gorm v1.21.12/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
|
||||
|
|
27
main.go
27
main.go
|
@ -6,43 +6,32 @@ import (
|
|||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"subscribe-bot/config"
|
||||
"subscribe-bot/db"
|
||||
"subscribe-bot/discord"
|
||||
"subscribe-bot/osuapi"
|
||||
"subscribe-bot/scrape"
|
||||
"subscribe-bot/web"
|
||||
)
|
||||
|
||||
var exit_chan = make(chan int)
|
||||
|
||||
var GitCommit string
|
||||
|
||||
func main() {
|
||||
configPath := flag.String("config", "config.toml", "Path to the config file (defaults to config.toml)")
|
||||
flag.Parse()
|
||||
|
||||
config, err := config.ReadConfig(*configPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
config, err := ReadConfig(*configPath)
|
||||
|
||||
api := osuapi.New(&config)
|
||||
requests := make(chan int)
|
||||
|
||||
db, err := db.OpenDb(config, api)
|
||||
api := NewOsuapi(&config)
|
||||
|
||||
db, err := OpenDb("db", api)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Println("opened db")
|
||||
|
||||
bot, err := discord.NewBot(&config, db, api)
|
||||
bot, err := NewBot(&config, db, requests)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
go scrape.RunScraper(&config, bot, db, api)
|
||||
go web.RunWeb(&config, api, db, GitCommit)
|
||||
go RunScraper(bot, db, api, requests)
|
||||
|
||||
signal_chan := make(chan os.Signal, 1)
|
||||
signal.Notify(signal_chan,
|
||||
|
@ -71,6 +60,6 @@ func main() {
|
|||
|
||||
db.Close()
|
||||
bot.Close()
|
||||
scrape.Ticker.Stop()
|
||||
ticker.Stop()
|
||||
os.Exit(code)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package osuapi
|
||||
package main
|
||||
|
||||
type User struct {
|
||||
ID int `json:"id"`
|
||||
|
@ -14,7 +14,7 @@ type Beatmapset struct {
|
|||
Title string `json:"title"`
|
||||
TitleUnicode string `json:"title_unicode"`
|
||||
Creator string `json:"creator"`
|
||||
UserID int `json:"user_id"`
|
||||
UserId int `json:"user_id"`
|
||||
|
||||
Covers BeatmapCovers `json:"covers"`
|
||||
Beatmaps []Beatmap `json:"beatmaps,omitempty"`
|
||||
|
@ -41,8 +41,15 @@ type Event struct {
|
|||
ID int `json:"id"`
|
||||
Type string `json:"type"`
|
||||
|
||||
// type: achievement
|
||||
Achievement EventAchievement `json:"achievement,omitempty"`
|
||||
Beatmapset EventBeatmapset `json:"beatmapset,omitempty"`
|
||||
|
||||
// type: beatmapsetApprove
|
||||
// type: beatmapsetDelete
|
||||
// type: beatmapsetRevive
|
||||
// type: beatmapsetUpdate
|
||||
// type: beatmapsetUpload
|
||||
Beatmapset EventBeatmapset `json:"beatmapset,omitempty"`
|
||||
|
||||
User EventUser `json:"user,omitempty"`
|
||||
}
|
||||
|
@ -63,14 +70,3 @@ type EventUser struct {
|
|||
type BeatmapSearch struct {
|
||||
Beatmapsets []Beatmapset `json:"beatmapsets"`
|
||||
}
|
||||
|
||||
type BeatmapsetEvents struct {
|
||||
Events []BeatmapsetEvent `json:"events"`
|
||||
}
|
||||
|
||||
type BeatmapsetEvent struct {
|
||||
ID int `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Beatmapset Beatmapset `json:"beatmapset"`
|
||||
UserID int `json:"user_id"`
|
||||
}
|
230
osuapi.go
Normal file
230
osuapi.go
Normal file
|
@ -0,0 +1,230 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"golang.org/x/sync/semaphore"
|
||||
)
|
||||
|
||||
const BASE_URL = "https://osu.ppy.sh/api/v2"
|
||||
|
||||
type Osuapi struct {
|
||||
httpClient *http.Client
|
||||
lock *semaphore.Weighted
|
||||
token string
|
||||
expires time.Time
|
||||
clientId int
|
||||
clientSecret string
|
||||
}
|
||||
|
||||
func NewOsuapi(config *Config) *Osuapi {
|
||||
client := &http.Client{
|
||||
Timeout: 9 * time.Second,
|
||||
}
|
||||
|
||||
// want to cap at around 1000 requests a minute, OSU cap is 1200
|
||||
lock := semaphore.NewWeighted(1000)
|
||||
return &Osuapi{client, lock, "", time.Now(), config.ClientId, config.ClientSecret}
|
||||
}
|
||||
|
||||
func (api *Osuapi) Token() (token string, err error) {
|
||||
if time.Now().Before(api.expires) {
|
||||
token = api.token
|
||||
return
|
||||
}
|
||||
|
||||
data := fmt.Sprintf(
|
||||
"client_id=%d&client_secret=%s&grant_type=client_credentials&scope=public",
|
||||
api.clientId,
|
||||
api.clientSecret,
|
||||
)
|
||||
|
||||
resp, err := http.Post(
|
||||
"https://osu.ppy.sh/oauth/token",
|
||||
"application/x-www-form-urlencoded",
|
||||
strings.NewReader(data),
|
||||
)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var osuToken OsuToken
|
||||
respBody, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(respBody, &osuToken)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("got new access token", osuToken.AccessToken[:12]+"...")
|
||||
api.token = osuToken.AccessToken
|
||||
api.expires = time.Now().Add(time.Duration(osuToken.ExpiresIn) * time.Second)
|
||||
token = api.token
|
||||
return
|
||||
}
|
||||
|
||||
func (api *Osuapi) Request0(action string, url string) (resp *http.Response, err error) {
|
||||
err = api.lock.Acquire(context.TODO(), 1)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
apiUrl := BASE_URL + url
|
||||
req, err := http.NewRequest(action, apiUrl, nil)
|
||||
|
||||
token, err := api.Token()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
req.Header.Add("Authorization", "Bearer "+token)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err = api.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
var respBody []byte
|
||||
respBody, err = ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = fmt.Errorf("not 200: %s", string(respBody))
|
||||
return
|
||||
}
|
||||
|
||||
// release the lock after 1 minute
|
||||
go func() {
|
||||
time.Sleep(time.Minute)
|
||||
api.lock.Release(1)
|
||||
}()
|
||||
return
|
||||
}
|
||||
|
||||
func (api *Osuapi) Request(action string, url string, result interface{}) (err error) {
|
||||
resp, err := api.Request0(action, url)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(data, result)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (api *Osuapi) DownloadSingleBeatmap(beatmapId int, path string) (err error) {
|
||||
url := fmt.Sprintf("https://osu.ppy.sh/osu/%d", beatmapId)
|
||||
resp, err := api.httpClient.Get(url)
|
||||
|
||||
file, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, 0644)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = io.Copy(file, resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (api *Osuapi) GetBeatmapSet(beatmapSetId int) (beatmapSet Beatmapset, err error) {
|
||||
url := fmt.Sprintf("/beatmapsets/%d", beatmapSetId)
|
||||
err = api.Request("GET", url, &beatmapSet)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (api *Osuapi) BeatmapsetDownload(beatmapSetId int) (path string, err error) {
|
||||
url := fmt.Sprintf("/beatmapsets/%d/download", beatmapSetId)
|
||||
resp, err := api.Request0("GET", url)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
file, err := ioutil.TempFile(os.TempDir(), "beatmapsetDownload")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = io.Copy(file, resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
file.Close()
|
||||
|
||||
path = file.Name()
|
||||
return
|
||||
}
|
||||
|
||||
func (api *Osuapi) GetUser(userId string) (user User, err error) {
|
||||
url := fmt.Sprintf("/users/%s", userId)
|
||||
err = api.Request("GET", url, &user)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (api *Osuapi) GetUserEvents(userId int, limit int, offset int) (events []Event, err error) {
|
||||
url := fmt.Sprintf(
|
||||
"/users/%d/recent_activity?limit=%d&offset=%d",
|
||||
userId,
|
||||
limit,
|
||||
offset,
|
||||
)
|
||||
err = api.Request("GET", url, &events)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (api *Osuapi) SearchBeatmaps(rankStatus string) (beatmapSearch BeatmapSearch, err error) {
|
||||
values := url.Values{}
|
||||
values.Set("s", rankStatus)
|
||||
query := values.Encode()
|
||||
url := "/beatmapsets/search?" + query
|
||||
err = api.Request("GET", url, &beatmapSearch)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type OsuToken struct {
|
||||
TokenType string `json:"token_type"`
|
||||
ExpiresIn int `json:"expires_in"`
|
||||
AccessToken string `json:"access_token"`
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
package osuapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (api *Osuapi) SearchBeatmaps(rankStatus string) (beatmapSearch BeatmapSearch, err error) {
|
||||
values := url.Values{}
|
||||
values.Set("s", rankStatus)
|
||||
query := values.Encode()
|
||||
url := "/beatmapsets/search?" + query
|
||||
err = api.Request("GET", url, &beatmapSearch)
|
||||
if err != nil {
|
||||
errors.Wrap(err, "failed to search beatmaps")
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (api *Osuapi) DownloadSingleBeatmap(beatmapId int, path string) (err error) {
|
||||
url := fmt.Sprintf("https://osu.ppy.sh/osu/%d", beatmapId)
|
||||
resp, err := api.httpClient.Get(url)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "could not fetch beatmap")
|
||||
return
|
||||
}
|
||||
|
||||
file, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, 0644)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "could not open file for downloading beatmap")
|
||||
return
|
||||
}
|
||||
|
||||
_, err = io.Copy(file, resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (api *Osuapi) GetBeatmapSet(beatmapSetId int) (beatmapSet Beatmapset, err error) {
|
||||
url := fmt.Sprintf("/beatmapsets/%d", beatmapSetId)
|
||||
err = api.Request("GET", url, &beatmapSet)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (api *Osuapi) BeatmapsetDownload(beatmapSetId int) (path string, err error) {
|
||||
url := fmt.Sprintf("/beatmapsets/%d/download", beatmapSetId)
|
||||
resp, err := api.Request0("GET", url)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
file, err := ioutil.TempFile(os.TempDir(), "beatmapsetDownload")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = io.Copy(file, resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
file.Close()
|
||||
|
||||
path = file.Name()
|
||||
return
|
||||
}
|
||||
|
||||
type GetBeatmapsetEventsOptions struct {
|
||||
User string
|
||||
Types []string
|
||||
}
|
||||
|
||||
func (api *Osuapi) GetBeatmapsetEvents(opts *GetBeatmapsetEventsOptions) (events []BeatmapsetEvent, err error) {
|
||||
values := url.Values{}
|
||||
values.Set("user", opts.User)
|
||||
query := values.Encode()
|
||||
for _, t := range opts.Types {
|
||||
query += "&types[]=" + t
|
||||
}
|
||||
url := "/beatmapsets/events?" + query
|
||||
fmt.Println("URL IS", url)
|
||||
|
||||
var reply BeatmapsetEvents
|
||||
err = api.Request("GET", url, &reply)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
events = reply.Events
|
||||
return
|
||||
}
|
180
osuapi/osuapi.go
180
osuapi/osuapi.go
|
@ -1,180 +0,0 @@
|
|||
package osuapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/sync/semaphore"
|
||||
|
||||
"subscribe-bot/config"
|
||||
)
|
||||
|
||||
const BASE_URL = "https://osu.ppy.sh/api/v2"
|
||||
|
||||
type Osuapi struct {
|
||||
httpClient *http.Client
|
||||
lock *semaphore.Weighted
|
||||
token string
|
||||
expires time.Time
|
||||
config *config.Config
|
||||
|
||||
tokenLock sync.RWMutex
|
||||
isFetchingToken bool
|
||||
}
|
||||
|
||||
func New(config *config.Config) *Osuapi {
|
||||
client := &http.Client{
|
||||
Timeout: 9 * time.Second,
|
||||
}
|
||||
|
||||
// want to cap at around 1000 requests a minute, OSU cap is 1200
|
||||
lock := semaphore.NewWeighted(1000)
|
||||
|
||||
return &Osuapi{
|
||||
httpClient: client,
|
||||
lock: lock,
|
||||
expires: time.Now(),
|
||||
config: config,
|
||||
}
|
||||
}
|
||||
|
||||
func (api *Osuapi) Token() (token string, err error) {
|
||||
return api.tokenFetch(false)
|
||||
}
|
||||
|
||||
func (api *Osuapi) tokenFetch(force bool) (token string, err error) {
|
||||
if !force {
|
||||
if time.Now().Before(api.expires) {
|
||||
token = api.token
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if api.isFetchingToken {
|
||||
api.tokenLock.RLock()
|
||||
token = api.token
|
||||
api.tokenLock.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
api.tokenLock.Lock()
|
||||
api.isFetchingToken = true
|
||||
|
||||
data := fmt.Sprintf(
|
||||
"client_id=%s&client_secret=%s&grant_type=client_credentials&scope=public",
|
||||
api.config.Oauth.ClientId,
|
||||
api.config.Oauth.ClientSecret,
|
||||
)
|
||||
|
||||
resp, err := http.Post(
|
||||
"https://osu.ppy.sh/oauth/token",
|
||||
"application/x-www-form-urlencoded",
|
||||
strings.NewReader(data),
|
||||
)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "failed to make POST request")
|
||||
return
|
||||
}
|
||||
|
||||
var osuToken OsuToken
|
||||
respBody, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "failed to read response body")
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(respBody, &osuToken)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "failed to unmarshal response body as json")
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("got new access token", osuToken.AccessToken[:12]+"...")
|
||||
api.token = osuToken.AccessToken
|
||||
api.expires = time.Now().Add(time.Duration(osuToken.ExpiresIn) * time.Second)
|
||||
|
||||
token = api.token
|
||||
api.tokenLock.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
func (api *Osuapi) Request0(action string, url string) (resp *http.Response, err error) {
|
||||
err = api.lock.Acquire(context.TODO(), 1)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
apiUrl := BASE_URL + url
|
||||
req, err := http.NewRequest(action, apiUrl, nil)
|
||||
|
||||
token, err := api.Token()
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "failed to fetch token")
|
||||
return
|
||||
}
|
||||
|
||||
req.Header.Add("Authorization", "Bearer "+token)
|
||||
|
||||
resp, err = api.httpClient.Do(req)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "http client failed")
|
||||
return
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
if resp.StatusCode == 401 {
|
||||
// force fetch token again
|
||||
api.tokenFetch(true)
|
||||
log.Println("re-fetched token cus expired")
|
||||
return api.Request0(action, url)
|
||||
}
|
||||
|
||||
var respBody []byte
|
||||
respBody, err = ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = fmt.Errorf("not 200: %s", string(respBody))
|
||||
return
|
||||
}
|
||||
|
||||
// release the lock after 1 minute
|
||||
go func() {
|
||||
time.Sleep(time.Minute)
|
||||
api.lock.Release(1)
|
||||
}()
|
||||
return
|
||||
}
|
||||
|
||||
func (api *Osuapi) Request(action string, url string, result interface{}) (err error) {
|
||||
resp, err := api.Request0(action, url)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "base request failed")
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to read http response body")
|
||||
}
|
||||
|
||||
err = json.Unmarshal(data, result)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to unmarshal http response as json")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type OsuToken struct {
|
||||
TokenType string `json:"token_type"`
|
||||
ExpiresIn int `json:"expires_in"`
|
||||
AccessToken string `json:"access_token"`
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package osuapi
|
||||
|
||||
import "fmt"
|
||||
|
||||
func (api *Osuapi) GetUser(userId string) (user User, err error) {
|
||||
url := fmt.Sprintf("/users/%s", userId)
|
||||
err = api.Request("GET", url, &user)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (api *Osuapi) GetUserEvents(userId int, limit int, offset int) (events []Event, err error) {
|
||||
url := fmt.Sprintf(
|
||||
"/users/%d/recent_activity?limit=%d&offset=%d",
|
||||
userId,
|
||||
limit,
|
||||
offset,
|
||||
)
|
||||
err = api.Request("GET", url, &events)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
161
scrape.go
Normal file
161
scrape.go
Normal file
|
@ -0,0 +1,161 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
refreshInterval = 30 * time.Second
|
||||
ticker = time.NewTicker(refreshInterval)
|
||||
)
|
||||
|
||||
func RunScraper(bot *Bot, db *Db, api *Osuapi, requests chan int) {
|
||||
lastUpdateTime := time.Now()
|
||||
go func() {
|
||||
for ; true; <-ticker.C {
|
||||
// build a list of currently tracked mappers
|
||||
trackedMappers := make(map[int]int)
|
||||
db.IterTrackedMappers(func(userId int) error {
|
||||
trackedMappers[userId] = 1
|
||||
return nil
|
||||
})
|
||||
|
||||
// TODO: is this sorted for sure??
|
||||
pendingSets, err := bot.api.SearchBeatmaps("pending")
|
||||
if err != nil {
|
||||
log.Println("error fetching pending sets", err)
|
||||
}
|
||||
|
||||
allNewMaps := make(map[int][]Beatmapset, 0)
|
||||
var newLastUpdateTime = time.Unix(0, 0)
|
||||
for _, beatmapSet := range pendingSets.Beatmapsets {
|
||||
updatedTime, err := time.Parse(time.RFC3339, beatmapSet.LastUpdated)
|
||||
if err != nil {
|
||||
log.Println("error parsing last updated time", updatedTime)
|
||||
}
|
||||
|
||||
if updatedTime.After(newLastUpdateTime) {
|
||||
// update lastUpdateTime to latest updated map
|
||||
newLastUpdateTime = updatedTime
|
||||
}
|
||||
|
||||
if !updatedTime.After(lastUpdateTime) {
|
||||
break
|
||||
}
|
||||
|
||||
mapperId := beatmapSet.UserId
|
||||
if _, ok := trackedMappers[mapperId]; ok {
|
||||
if _, ok2 := allNewMaps[mapperId]; !ok2 {
|
||||
allNewMaps[mapperId] = make([]Beatmapset, 0)
|
||||
}
|
||||
|
||||
allNewMaps[mapperId] = append(allNewMaps[mapperId], beatmapSet)
|
||||
}
|
||||
}
|
||||
|
||||
if len(allNewMaps) > 0 {
|
||||
for mapperId, newMaps := range allNewMaps {
|
||||
channels := make([]string, 0)
|
||||
db.IterTrackingChannels(mapperId, func(channelId string) error {
|
||||
channels = append(channels, channelId)
|
||||
return nil
|
||||
})
|
||||
|
||||
err := bot.NotifyNewBeatmap(channels, newMaps)
|
||||
if err != nil {
|
||||
log.Println("error notifying new maps:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastUpdateTime = newLastUpdateTime
|
||||
fmt.Print("\a")
|
||||
log.Println("last updated time", lastUpdateTime)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func getNewMaps(db *Db, api *Osuapi, userId int) (newMaps []Event, err error) {
|
||||
// see if there's a last event
|
||||
hasLastEvent, lastEventId := db.MapperLastEvent(userId)
|
||||
newMaps = make([]Event, 0)
|
||||
var (
|
||||
events []Event
|
||||
newLatestEvent = 0
|
||||
updateLatestEvent = false
|
||||
)
|
||||
if hasLastEvent {
|
||||
offset := 0
|
||||
|
||||
loop:
|
||||
for {
|
||||
events, err = api.GetUserEvents(userId, 50, offset)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("couldn't load events for user %d, offset %d: %w", userId, offset, err)
|
||||
return
|
||||
}
|
||||
if len(events) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
for _, event := range events {
|
||||
if event.ID == lastEventId {
|
||||
break loop
|
||||
}
|
||||
|
||||
if event.ID > newLatestEvent {
|
||||
updateLatestEvent = true
|
||||
newLatestEvent = event.ID
|
||||
}
|
||||
|
||||
if event.Type == "beatmapsetUpload" ||
|
||||
event.Type == "beatmapsetRevive" ||
|
||||
event.Type == "beatmapsetUpdate" {
|
||||
newMaps = append(newMaps, event)
|
||||
}
|
||||
}
|
||||
|
||||
offset += len(events)
|
||||
}
|
||||
} else {
|
||||
log.Printf("no last event id found for %d\n", userId)
|
||||
events, err = api.GetUserEvents(userId, 50, 0)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, event := range events {
|
||||
if event.ID > newLatestEvent {
|
||||
updateLatestEvent = true
|
||||
newLatestEvent = event.ID
|
||||
}
|
||||
|
||||
if event.Type == "beatmapsetUpload" ||
|
||||
event.Type == "beatmapsetRevive" ||
|
||||
event.Type == "beatmapsetUpdate" {
|
||||
newMaps = append(newMaps, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: debug
|
||||
// updateLatestEvent = false
|
||||
|
||||
if updateLatestEvent {
|
||||
err = db.UpdateMapperLatestEvent(userId, newLatestEvent)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func startTimers(db *Db, requests chan int) {
|
||||
db.IterTrackedMappers(func(userId int) error {
|
||||
requests <- userId
|
||||
return nil
|
||||
})
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package scrape
|
||||
|
||||
import (
|
||||
"subscribe-bot/osuapi"
|
||||
)
|
||||
|
||||
func (s *Scraper) scrapeNominatedMaps() {
|
||||
events, _ := s.api.GetBeatmapsetEvents(&osuapi.GetBeatmapsetEventsOptions{
|
||||
Types: []string{"nominate", "qualify"},
|
||||
})
|
||||
|
||||
for _, event := range events {
|
||||
(func(_ osuapi.BeatmapsetEvent) {})(event)
|
||||
// fmt.Println(event)
|
||||
}
|
||||
}
|
|
@ -1,145 +0,0 @@
|
|||
package scrape
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"subscribe-bot/db"
|
||||
"subscribe-bot/osuapi"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (s *Scraper) scrapePendingMaps() {
|
||||
// build a list of currently tracked mappers
|
||||
trackedMappers := make(map[int]int)
|
||||
s.db.IterAllTrackedMappers(func(mapper db.User) error {
|
||||
trackedMappers[mapper.ID] = 1
|
||||
return nil
|
||||
})
|
||||
|
||||
// TODO: is this sorted for sure??
|
||||
pendingSets, err := s.api.SearchBeatmaps("pending")
|
||||
if err != nil {
|
||||
log.Println("error fetching pending sets", err)
|
||||
s.bot.NotifyError("failed to fetch pending sets", err)
|
||||
return
|
||||
}
|
||||
|
||||
allNewMaps := make(map[int][]osuapi.Beatmapset, 0)
|
||||
var newLastUpdateTime = time.Unix(0, 0)
|
||||
for _, beatmapSet := range pendingSets.Beatmapsets {
|
||||
updatedTime, err := time.Parse(time.RFC3339, beatmapSet.LastUpdated)
|
||||
if err != nil {
|
||||
log.Println("error parsing last updated time", updatedTime)
|
||||
}
|
||||
|
||||
if updatedTime.After(newLastUpdateTime) {
|
||||
// update lastUpdateTime to latest updated map
|
||||
newLastUpdateTime = updatedTime
|
||||
}
|
||||
|
||||
if !updatedTime.After(lastUpdateTime) {
|
||||
break
|
||||
}
|
||||
|
||||
mapperId := beatmapSet.UserID
|
||||
|
||||
// if _, ok := trackedMappers[mapperId]; ok {
|
||||
if _, ok2 := allNewMaps[mapperId]; !ok2 {
|
||||
allNewMaps[mapperId] = make([]osuapi.Beatmapset, 0)
|
||||
}
|
||||
|
||||
allNewMaps[mapperId] = append(allNewMaps[mapperId], beatmapSet)
|
||||
// }
|
||||
}
|
||||
|
||||
if len(allNewMaps) > 0 {
|
||||
for mapperId, newMaps := range allNewMaps {
|
||||
channels := make([]string, 0)
|
||||
s.db.IterTrackingChannels(mapperId, func(channel db.DiscordChannel) error {
|
||||
channels = append(channels, channel.ID)
|
||||
return nil
|
||||
})
|
||||
|
||||
err := s.bot.NotifyNewBeatmap(channels, newMaps)
|
||||
if err != nil {
|
||||
log.Println("error notifying new maps:", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastUpdateTime = newLastUpdateTime
|
||||
log.Println("last updated time", lastUpdateTime)
|
||||
}
|
||||
|
||||
func getNewMaps(db *db.Db, api *osuapi.Osuapi, userId int) (newMaps []osuapi.Event, err error) {
|
||||
// see if there's a last event
|
||||
hasLastEvent, lastEventId := db.MapperLastEvent(userId)
|
||||
newMaps = make([]osuapi.Event, 0)
|
||||
var (
|
||||
events []osuapi.Event
|
||||
newLatestEvent = 0
|
||||
updateLatestEvent = false
|
||||
)
|
||||
if hasLastEvent {
|
||||
offset := 0
|
||||
|
||||
loop:
|
||||
for {
|
||||
events, err = api.GetUserEvents(userId, 50, offset)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("couldn't load events for user %d, offset %d: %w", userId, offset, err)
|
||||
return
|
||||
}
|
||||
if len(events) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
for _, event := range events {
|
||||
if event.ID == lastEventId {
|
||||
break loop
|
||||
}
|
||||
|
||||
if event.ID > newLatestEvent {
|
||||
updateLatestEvent = true
|
||||
newLatestEvent = event.ID
|
||||
}
|
||||
|
||||
if event.Type == "beatmapsetUpload" ||
|
||||
event.Type == "beatmapsetRevive" ||
|
||||
event.Type == "beatmapsetUpdate" {
|
||||
newMaps = append(newMaps, event)
|
||||
}
|
||||
}
|
||||
|
||||
offset += len(events)
|
||||
}
|
||||
} else {
|
||||
log.Printf("no last event id found for %d\n", userId)
|
||||
events, err = api.GetUserEvents(userId, 50, 0)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for _, event := range events {
|
||||
if event.ID > newLatestEvent {
|
||||
updateLatestEvent = true
|
||||
newLatestEvent = event.ID
|
||||
}
|
||||
|
||||
if event.Type == "beatmapsetUpload" ||
|
||||
event.Type == "beatmapsetRevive" ||
|
||||
event.Type == "beatmapsetUpdate" {
|
||||
newMaps = append(newMaps, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if updateLatestEvent {
|
||||
err = db.UpdateMapperLastEvent(userId, newLatestEvent)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package scrape
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"subscribe-bot/config"
|
||||
"subscribe-bot/db"
|
||||
"subscribe-bot/discord"
|
||||
"subscribe-bot/osuapi"
|
||||
)
|
||||
|
||||
var (
|
||||
refreshInterval = 30 * time.Second
|
||||
lastUpdateTime time.Time
|
||||
Ticker = time.NewTicker(refreshInterval)
|
||||
)
|
||||
|
||||
type Scraper struct {
|
||||
config *config.Config
|
||||
bot *discord.Bot
|
||||
db *db.Db
|
||||
api *osuapi.Osuapi
|
||||
}
|
||||
|
||||
func RunScraper(config *config.Config, bot *discord.Bot, db *db.Db, api *osuapi.Osuapi) {
|
||||
lastUpdateTime = time.Now()
|
||||
|
||||
scraper := Scraper{config, bot, db, api}
|
||||
|
||||
go func() {
|
||||
for ; true; <-Ticker.C {
|
||||
scraper.scrapePendingMaps()
|
||||
scraper.scrapeNominatedMaps()
|
||||
}
|
||||
}()
|
||||
}
|
81
web/auth.go
81
web/auth.go
|
@ -1,81 +0,0 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/contrib/sessions"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func (web *Web) logout(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
session.Delete("access_token")
|
||||
session.Save()
|
||||
|
||||
c.Redirect(http.StatusTemporaryRedirect, "/")
|
||||
}
|
||||
|
||||
func (web *Web) login(c *gin.Context) {
|
||||
url := url.URL{
|
||||
Scheme: "https",
|
||||
Host: "osu.ppy.sh",
|
||||
Path: "/oauth/authorize",
|
||||
}
|
||||
q := url.Query()
|
||||
q.Set("client_id", web.config.Oauth.ClientId)
|
||||
q.Set("redirect_uri", web.config.Web.ServedAt+"/login/callback")
|
||||
q.Set("response_type", "code")
|
||||
q.Set("scope", "identify public")
|
||||
q.Set("state", "urmom")
|
||||
url.RawQuery = q.Encode()
|
||||
fmt.Println("redirecting to", url.String())
|
||||
c.Redirect(http.StatusTemporaryRedirect, url.String())
|
||||
}
|
||||
|
||||
func (web *Web) loginCallback(c *gin.Context) {
|
||||
receivedCode := c.Query("code")
|
||||
|
||||
bodyQuery := url.Values{}
|
||||
bodyQuery.Set("client_id", web.config.Oauth.ClientId)
|
||||
bodyQuery.Set("client_secret", web.config.Oauth.ClientSecret)
|
||||
bodyQuery.Set("code", receivedCode)
|
||||
bodyQuery.Set("grant_type", "authorization_code")
|
||||
bodyQuery.Set("redirect_uri", web.config.Web.ServedAt+"/login/callback")
|
||||
body := strings.NewReader(bodyQuery.Encode())
|
||||
resp, _ := web.hc.Post("https://osu.ppy.sh/oauth/token", "application/x-www-form-urlencoded", body)
|
||||
respBody, _ := ioutil.ReadAll(resp.Body)
|
||||
type OsuToken struct {
|
||||
TokenType string `json:"token_type"`
|
||||
ExpiresIn int `json:"expires_in"`
|
||||
AccessToken string `json:"access_token"`
|
||||
RefreshToken string `json:"refresh_token"`
|
||||
}
|
||||
var token OsuToken
|
||||
_ = json.Unmarshal(respBody, &token)
|
||||
fmt.Println("TOKEN", token)
|
||||
|
||||
session := sessions.Default(c)
|
||||
session.Set("access_token", token.AccessToken)
|
||||
session.Save()
|
||||
|
||||
c.Redirect(http.StatusTemporaryRedirect, "/")
|
||||
}
|
||||
|
||||
func isLoggedIn(c *gin.Context) bool {
|
||||
session := sessions.Default(c)
|
||||
var accessToken string
|
||||
loggedIn := false
|
||||
accessTokenI := session.Get("access_token")
|
||||
if accessTokenI != nil {
|
||||
accessToken = accessTokenI.(string)
|
||||
if len(accessToken) > 0 {
|
||||
loggedIn = true
|
||||
}
|
||||
}
|
||||
return loggedIn
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"subscribe-bot/db"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (web *Web) mapperIndex(c *gin.Context) (err error) {
|
||||
userId := c.Param("userId")
|
||||
mapperId, err := strconv.Atoi(userId)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "id is not an integer")
|
||||
return
|
||||
}
|
||||
|
||||
mapper, err := web.db.GetUser(mapperId)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "failed to get user from mapper-index")
|
||||
return
|
||||
}
|
||||
|
||||
beatmapsets := make([]db.Beatmapset, 0)
|
||||
web.db.IterTrackedBeatmapsetsBy(mapperId, func(beatmapset db.Beatmapset) error {
|
||||
beatmapsets = append(beatmapsets, beatmapset)
|
||||
return nil
|
||||
})
|
||||
|
||||
web.render(c, http.StatusOK, "mapper-index.html", gin.H{
|
||||
"Mapper": mapper,
|
||||
"Beatmapsets": beatmapsets,
|
||||
})
|
||||
|
||||
return
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func (web *Web) errorWrap(fn func(*gin.Context) error) func(*gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
err := fn(c)
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, "error")
|
||||
log.Println("fatal error", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (web *Web) render(c *gin.Context, code int, tmpl string, obj gin.H) {
|
||||
base := gin.H{
|
||||
"IsLoggedIn": isLoggedIn(c),
|
||||
}
|
||||
|
||||
for key, val := range obj {
|
||||
base[key] = val
|
||||
}
|
||||
|
||||
c.HTML(code, tmpl, base)
|
||||
}
|
117
web/repo.go
117
web/repo.go
|
@ -1,117 +0,0 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"path"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
)
|
||||
|
||||
func (web *Web) mapVersions(c *gin.Context) (err error) {
|
||||
userId := c.Param("userId")
|
||||
mapId := c.Param("mapId")
|
||||
|
||||
id, _ := strconv.Atoi(mapId)
|
||||
bs, _ := web.api.GetBeatmapSet(id)
|
||||
|
||||
repoDir := path.Join(web.config.Repos, userId, mapId)
|
||||
repo, _ := git.PlainOpen(repoDir)
|
||||
|
||||
type Revision struct {
|
||||
Date time.Time
|
||||
HumanDate string
|
||||
Summary string
|
||||
Hash string
|
||||
HasParent bool
|
||||
}
|
||||
|
||||
versions := make([]Revision, 0)
|
||||
logIter, _ := repo.Log(&git.LogOptions{})
|
||||
for i := 0; i < 20; i++ {
|
||||
commit, err := logIter.Next()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
|
||||
stats, _ := commit.Stats()
|
||||
_, err = commit.Parent(0)
|
||||
hasParent := !errors.Is(err, object.ErrParentNotFound)
|
||||
|
||||
versions = append(versions, Revision{
|
||||
Date: commit.Author.When,
|
||||
HumanDate: humanize.Time(commit.Author.When),
|
||||
Summary: stats.String(),
|
||||
Hash: commit.Hash.String(),
|
||||
HasParent: hasParent,
|
||||
})
|
||||
}
|
||||
|
||||
web.render(c, http.StatusOK, "map-version.html", gin.H{
|
||||
"Beatmapset": bs,
|
||||
"LoggedIn": isLoggedIn(c),
|
||||
"Versions": versions,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (web *Web) mapPatch(c *gin.Context) (err error) {
|
||||
userId := c.Param("userId")
|
||||
mapId := c.Param("mapId")
|
||||
hash := c.Param("hash")
|
||||
|
||||
repoDir := path.Join(web.config.Repos, userId, mapId)
|
||||
repo, _ := git.PlainOpen(repoDir)
|
||||
|
||||
hashObj := plumbing.NewHash(hash)
|
||||
commit, _ := repo.CommitObject(hashObj)
|
||||
parent, _ := commit.Parent(0)
|
||||
patch, _ := parent.Patch(commit)
|
||||
|
||||
c.String(http.StatusOK, "text/plain", patch.String())
|
||||
return
|
||||
}
|
||||
|
||||
func (web *Web) mapZip(c *gin.Context) (err error) {
|
||||
userId := c.Param("userId")
|
||||
mapId := c.Param("mapId")
|
||||
hash := c.Param("hash")
|
||||
|
||||
repoDir := path.Join(web.config.Repos, userId, mapId)
|
||||
repo, _ := git.PlainOpen(repoDir)
|
||||
|
||||
hashObj := plumbing.NewHash(hash)
|
||||
commit, _ := repo.CommitObject(hashObj)
|
||||
tree, _ := commit.Tree()
|
||||
|
||||
files := tree.Files()
|
||||
|
||||
c.Writer.Header().Set("Content-type", "application/octet-stream")
|
||||
c.Writer.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s-%s.zip", mapId, hash))
|
||||
c.Stream(func(w io.Writer) bool {
|
||||
ar := zip.NewWriter(w)
|
||||
for {
|
||||
file, err := files.Next()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
|
||||
reader, _ := file.Reader()
|
||||
fdest, _ := ar.Create(file.Name)
|
||||
io.Copy(fdest, reader)
|
||||
}
|
||||
ar.Close()
|
||||
|
||||
return false
|
||||
})
|
||||
return
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
:root {
|
||||
--primary-color: #09c;
|
||||
}
|
||||
|
||||
body, html {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
|
||||
.title a {
|
||||
color: black;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.nav-bar {
|
||||
background-color: var(--primary-color);
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.nav-bar a {
|
||||
color: white;
|
||||
padding: 7px;
|
||||
margin: 0px 3px;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--primary-color);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* containers */
|
||||
|
||||
.container {
|
||||
width: 90%;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
@media only screen and (min-width: 33.75em) { /* 540px */
|
||||
.container {
|
||||
width: 80%;
|
||||
}
|
||||
}
|
||||
|
||||
@media only screen and (min-width: 60em) { /* 960px */
|
||||
.container {
|
||||
width: 75%;
|
||||
max-width: 60rem;
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
{{ define "content" }}
|
||||
|
||||
<h3>Stats</h3>
|
||||
|
||||
Currently tracking <b>{{ .TotalMaps }}</b> maps from <b>{{ .TotalUsers }}</b> users.
|
||||
|
||||
<h3>Last 10 Updated Beatmaps</h3>
|
||||
|
||||
<table class="table-auto">
|
||||
<thead>
|
||||
<th>Links</th>
|
||||
<th>Title</th>
|
||||
<th>Mapper</th>
|
||||
<th>Updated</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range .Beatmapsets }}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="https://osu.ppy.sh/s/{{ .ID }}" target="_blank">[osu]</a>
|
||||
<a href="/map/{{ .MapperID }}/{{ .ID }}/versions">[versions]</a>
|
||||
</td>
|
||||
<td>{{ .Artist }} - {{ .Title }}</td>
|
||||
<td>
|
||||
<a href="/map/{{ .MapperID }}">{{ .Mapper.Username }}</a>
|
||||
</td>
|
||||
<td>
|
||||
{{ .LastUpdated | humanize }}
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{{ end }}
|
|
@ -1,36 +0,0 @@
|
|||
{{ define "content" }}
|
||||
|
||||
<h3>versions of {{ .Beatmapset.Artist }} - {{ .Beatmapset.Title }}</h3>
|
||||
|
||||
<p>
|
||||
<a href="https://osu.ppy.sh/s/{{ .Beatmapset.ID }}" target="_blank">Map link</a>
|
||||
·
|
||||
mapped by <a href="https://osu.ppy.sh/u/{{ .Beatmapset.UserID }}" target="_blank">{{ .Beatmapset.Creator }}</a>
|
||||
</p>
|
||||
|
||||
<small>up to the latest 20 revisions, pagination coming later</small>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<th>Date</th>
|
||||
<th>Links</th>
|
||||
<th>Summary</th>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{{ range .Versions }}
|
||||
<tr>
|
||||
<td><span title="{{ .Date }}">{{ .HumanDate }}</span></td>
|
||||
<td>
|
||||
<a href="zip/{{ .Hash }}" target="_blank">[zip]</a>
|
||||
{{ if .HasParent }}
|
||||
<a href="patch/{{ .Hash }}" target="_blank">[patch]</a>
|
||||
{{ end }}
|
||||
</td>
|
||||
<td><pre>{{ .Summary }}</pre></td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{{ end }}
|
|
@ -1,27 +0,0 @@
|
|||
{{ define "content" }}
|
||||
|
||||
<h3>Tracked Maps by <a href="https://osu.ppy.sh/u/{{ .Mapper.ID }}" target="_blank">{{ .Mapper.Username }}</a></h3>
|
||||
|
||||
<table class="table-auto">
|
||||
<thead>
|
||||
<th>Links</th>
|
||||
<th>Title</th>
|
||||
<th>Updated</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{ range .Beatmapsets }}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="https://osu.ppy.sh/s/{{ .ID }}" target="_blank">[osu]</a>
|
||||
<a href="/map/{{ .MapperID }}/{{ .ID }}/versions">[versions]</a>
|
||||
</td>
|
||||
<td>{{ .Artist }} - {{ .Title }}</td>
|
||||
<td>
|
||||
{{ .LastUpdated | humanize }}
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{{ end }}
|
|
@ -1,45 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>subscribe-bot</title>
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<link rel="stylesheet" href="/static/main.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1 class="title">
|
||||
<a href="/">subscribe-bot</a>
|
||||
</h1>
|
||||
|
||||
<small>logging in with your osu account does nothing</small>
|
||||
|
||||
<div class="nav-bar">
|
||||
<a href="/">home</a>
|
||||
|
||||
{{ if .LoggedIn }}
|
||||
<a href="/logout">logout</a>
|
||||
{{ else }}
|
||||
<a href="/login">login</a>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
||||
{{ template "content" . }}
|
||||
|
||||
<footer>
|
||||
<hr />
|
||||
<small>
|
||||
Maintained by <a href="https://osu.ppy.sh/u/2688103" target="_blank">IOException</a>
|
||||
·
|
||||
<a href="https://git.mzhang.io/osu/subscribe-bot" target="_blank">Source code</a>
|
||||
·
|
||||
<a href="https://discord.gg/eqjVG2H" target="_blank">Discord</a>
|
||||
·
|
||||
subscribe-bot v{{ GitCommit }}
|
||||
</small>
|
||||
</footer>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
99
web/web.go
99
web/web.go
|
@ -1,99 +0,0 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/foolin/goview"
|
||||
"github.com/foolin/goview/supports/ginview"
|
||||
"github.com/gin-contrib/static"
|
||||
"github.com/gin-gonic/contrib/sessions"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/kofalt/go-memoize"
|
||||
|
||||
"subscribe-bot/config"
|
||||
"subscribe-bot/db"
|
||||
"subscribe-bot/osuapi"
|
||||
)
|
||||
|
||||
const (
|
||||
USER_KEY = "user"
|
||||
)
|
||||
|
||||
var (
|
||||
cache = memoize.NewMemoizer(90*time.Second, 10*time.Minute)
|
||||
)
|
||||
|
||||
type Web struct {
|
||||
config *config.Config
|
||||
api *osuapi.Osuapi
|
||||
hc *http.Client
|
||||
db *db.Db
|
||||
version string
|
||||
}
|
||||
|
||||
func RunWeb(config *config.Config, api *osuapi.Osuapi, db *db.Db, version string) {
|
||||
hc := &http.Client{
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
|
||||
web := Web{config, api, hc, db, version}
|
||||
web.Run()
|
||||
}
|
||||
|
||||
func (web *Web) Run() {
|
||||
if !web.config.Debug {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
|
||||
r := gin.Default()
|
||||
r.Use(gin.Recovery())
|
||||
r.Use(static.Serve("/static", static.LocalFile("web/static", false)))
|
||||
r.Use(sessions.Sessions("mysession", sessions.NewCookieStore([]byte(web.config.Web.SessionSecret))))
|
||||
|
||||
r.HTMLRender = ginview.New(goview.Config{
|
||||
Root: "web/templates",
|
||||
Master: "master.html",
|
||||
DisableCache: web.config.Debug,
|
||||
Funcs: template.FuncMap{
|
||||
"GitCommit": func() string {
|
||||
return web.version
|
||||
},
|
||||
"humanize": humanize.Time,
|
||||
},
|
||||
})
|
||||
|
||||
r.GET("/logout", web.logout)
|
||||
r.GET("/login", web.login)
|
||||
r.GET("/login/callback", web.loginCallback)
|
||||
|
||||
r.GET("/map/:userId", web.errorWrap(web.mapperIndex))
|
||||
r.GET("/map/:userId/:mapId/versions", web.errorWrap(web.mapVersions))
|
||||
r.GET("/map/:userId/:mapId/patch/:hash", web.errorWrap(web.mapPatch))
|
||||
r.GET("/map/:userId/:mapId/zip/:hash", web.errorWrap(web.mapZip))
|
||||
|
||||
r.GET("/", func(c *gin.Context) {
|
||||
beatmapSets := web.listRepos()
|
||||
stats := web.db.GetStats()
|
||||
web.render(c, http.StatusOK, "index.html", gin.H{
|
||||
"Beatmapsets": beatmapSets,
|
||||
"TotalMaps": stats.TotalMaps,
|
||||
"TotalUsers": stats.TotalUsers,
|
||||
})
|
||||
})
|
||||
|
||||
addr := fmt.Sprintf("%s:%d", web.config.Web.Host, web.config.Web.Port)
|
||||
r.Run(addr)
|
||||
}
|
||||
|
||||
func (web *Web) listRepos() []db.Beatmapset {
|
||||
beatmapSets := make([]db.Beatmapset, 0)
|
||||
web.db.IterTrackedBeatmapsets(10, func(beatmapset db.Beatmapset) error {
|
||||
beatmapSets = append(beatmapSets, beatmapset)
|
||||
return nil
|
||||
})
|
||||
return beatmapSets
|
||||
}
|
Loading…
Reference in a new issue