├── .github
└── workflows
│ ├── build.yml
│ └── lint.yml
├── .gitignore
├── .golangci.yml
├── CHANGELOG.md
├── LICENSE
├── Makefile
├── cmd
└── bot
│ ├── channels.go
│ ├── commands.go
│ ├── common.go
│ ├── events.go
│ ├── main.go
│ ├── subevent.go
│ └── subevent_test.go
├── go.mod
├── go.sum
├── internal
├── api
│ ├── routes.go
│ └── server.go
├── bot
│ ├── channel.go
│ ├── command.go
│ ├── types.go
│ └── utils.go
├── commands
│ ├── bot.go
│ ├── events.go
│ ├── game.go
│ ├── help.go
│ ├── islive.go
│ ├── migrate_channels.go
│ ├── migrate_subscriptions.go
│ ├── notifyme.go
│ ├── ping.go
│ ├── removeme.go
│ ├── subscribed.go
│ └── title.go
├── common
│ └── common.go
├── config
│ ├── config.go
│ └── model.go
├── eventsub
│ ├── eventsub.go
│ ├── model.go
│ └── routes.go
├── helixclient
│ ├── access_token.go
│ └── client.go
├── mongo
│ ├── connection.go
│ └── types.go
└── supinicapi
│ └── client.go
└── pkg
└── utils
├── slice.go
├── string.go
└── time.go
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 |
3 | on:
4 | push:
5 | branches: [ master ]
6 | pull_request:
7 |
8 | jobs:
9 | build:
10 | name: Build
11 | runs-on: ${{ matrix.os }}
12 |
13 | strategy:
14 | matrix:
15 | go: [1.16, 1.17]
16 | os: [ubuntu-latest]
17 |
18 | steps:
19 | - name: Set up Go
20 | uses: actions/setup-go@v2.1.4
21 | with:
22 | go-version: ${{ matrix.go }}
23 |
24 | - name: Check out into the Go module directory
25 | uses: actions/checkout@v2.3.4
26 |
27 | - name: Get dependencies
28 | run: go get -v -t -d ./...
29 |
30 | - name: Build
31 | run: go build -ldflags="-s -w" -v -o ../../build/tcb
32 | working-directory: cmd/bot
33 |
34 | - name: Test
35 | run: go test -v ./...
36 |
37 | - name: Upload artifact
38 | uses: actions/upload-artifact@v2
39 | with:
40 | name: tcb-${{ matrix.go }}-${{ matrix.os }}
41 | path: build/tcb
42 |
--------------------------------------------------------------------------------
/.github/workflows/lint.yml:
--------------------------------------------------------------------------------
1 | name: Lint
2 |
3 | on:
4 | push:
5 | branches: [ master ]
6 | pull_request:
7 |
8 | jobs:
9 | lint:
10 | name: Lint
11 | runs-on: ubuntu-latest
12 |
13 | strategy:
14 | matrix:
15 | go: [1.16, 1.17]
16 |
17 | steps:
18 | #- name: Set up Go
19 | #uses: actions/setup-go@v2.1.4
20 | #with:
21 | #go-version: ${{ matrix.go }}
22 |
23 | - name: Check out into the Go module directory
24 | uses: actions/checkout@v2.3.4
25 |
26 | - name: Lint the code (reviewdog)
27 | uses: reviewdog/action-golangci-lint@v2.0.1
28 | with:
29 | fail_on_error: true
30 | go_version: ${{ matrix.go }}
31 | filter_mode: nofilter
32 | #- name: Lint the code
33 | #uses: golangci/golangci-lint-action@v2.5.2
34 | #with:
35 | #version: v1.29
36 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | cmd/bot/bot
2 | *.test
3 | config.yaml
4 |
--------------------------------------------------------------------------------
/.golangci.yml:
--------------------------------------------------------------------------------
1 | linters-settings:
2 | govet:
3 | check-shadowing: true
4 | golint:
5 | min-confidence: 0
6 | gocyclo:
7 | min-complexity: 25
8 | maligned:
9 | suggest-new: true
10 | goconst:
11 | min-len: 2
12 | min-occurrences: 4
13 | gocognit:
14 | min-complexity: 60
15 | gocritic:
16 | enabled-tags:
17 | - diagnostic
18 | - experimental
19 | - opinionated
20 | - performance
21 | - style
22 | disabled-checks:
23 | - unnamedResult
24 | - commentedOutCode
25 | - exitAfterDefer # TODO: Investigate re-enabling this one
26 | - filepathJoin # Disabled due to FPs in config package
27 | - appendCombine # After a longer thought I decided I don't like this, makes code less readable
28 | funlen:
29 | lines: 200
30 | statements: 50
31 |
32 | linters:
33 | disable-all: true
34 | enable:
35 | - bodyclose
36 | - deadcode
37 | - depguard
38 | - dogsled
39 | # - dupl
40 | - errcheck
41 | - funlen
42 | - goconst
43 | - gocritic
44 | # - gocyclo # same as with gocognit
45 | - gofmt
46 | - goimports
47 | - golint
48 | - gosec
49 | - gosimple
50 | - govet
51 | - ineffassign
52 | - interfacer
53 | # - lll
54 | # - misspell
55 | - scopelint
56 | - staticcheck
57 | - structcheck
58 | - stylecheck
59 | - typecheck
60 | - unconvert
61 | - unparam
62 | # - unused
63 | - varcheck
64 | - whitespace
65 | # - gocognit # CBA to keep satisfying this check with the enormous !notifyme's code
66 | # - godox
67 | # - maligned
68 | - prealloc
69 |
70 | # don't enable:
71 | # - gochecknoglobals
72 | # - nakedret
73 | # - gochecknoinits
74 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | ## Unversioned
4 |
5 | ## 2.0-rc2
6 |
7 | - Minor: Reimplemented channel MOTDs. (#10)
8 | - Minor: Added a way to subscribe to all events at once with `!notifyme all`.
9 | - Minor: List all available events in `!notifyme` command.
10 | - Minor: Reimplemented respecting of disabled command.
11 | - Minor: Make periodic requests to supinic's API to signal bot being alive. (#6)
12 | - Bugfix: Corrected response in `!bot` command.
13 | - Bugfix: Make checks for subscription values case-insensitive again.
14 | - Dev: Use millisecond precision in logs.
15 | - Dev: Added licese. (#7)
16 | - Dev: Cleaned up code for API routes.
17 |
18 |
19 | ## 2.0-rc1
20 |
21 | - Initial release.
22 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU AFFERO GENERAL PUBLIC LICENSE
2 | Version 3, 19 November 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU Affero General Public License is a free, copyleft license for
11 | software and other kinds of works, specifically designed to ensure
12 | cooperation with the community in the case of network server software.
13 |
14 | The licenses for most software and other practical works are designed
15 | to take away your freedom to share and change the works. By contrast,
16 | our General Public Licenses are intended to guarantee your freedom to
17 | share and change all versions of a program--to make sure it remains free
18 | software for all its users.
19 |
20 | When we speak of free software, we are referring to freedom, not
21 | price. Our General Public Licenses are designed to make sure that you
22 | have the freedom to distribute copies of free software (and charge for
23 | them if you wish), that you receive source code or can get it if you
24 | want it, that you can change the software or use pieces of it in new
25 | free programs, and that you know you can do these things.
26 |
27 | Developers that use our General Public Licenses protect your rights
28 | with two steps: (1) assert copyright on the software, and (2) offer
29 | you this License which gives you legal permission to copy, distribute
30 | and/or modify the software.
31 |
32 | A secondary benefit of defending all users' freedom is that
33 | improvements made in alternate versions of the program, if they
34 | receive widespread use, become available for other developers to
35 | incorporate. Many developers of free software are heartened and
36 | encouraged by the resulting cooperation. However, in the case of
37 | software used on network servers, this result may fail to come about.
38 | The GNU General Public License permits making a modified version and
39 | letting the public access it on a server without ever releasing its
40 | source code to the public.
41 |
42 | The GNU Affero General Public License is designed specifically to
43 | ensure that, in such cases, the modified source code becomes available
44 | to the community. It requires the operator of a network server to
45 | provide the source code of the modified version running there to the
46 | users of that server. Therefore, public use of a modified version, on
47 | a publicly accessible server, gives the public access to the source
48 | code of the modified version.
49 |
50 | An older license, called the Affero General Public License and
51 | published by Affero, was designed to accomplish similar goals. This is
52 | a different license, not a version of the Affero GPL, but Affero has
53 | released a new version of the Affero GPL which permits relicensing under
54 | this license.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | TERMS AND CONDITIONS
60 |
61 | 0. Definitions.
62 |
63 | "This License" refers to version 3 of the GNU Affero General Public License.
64 |
65 | "Copyright" also means copyright-like laws that apply to other kinds of
66 | works, such as semiconductor masks.
67 |
68 | "The Program" refers to any copyrightable work licensed under this
69 | License. Each licensee is addressed as "you". "Licensees" and
70 | "recipients" may be individuals or organizations.
71 |
72 | To "modify" a work means to copy from or adapt all or part of the work
73 | in a fashion requiring copyright permission, other than the making of an
74 | exact copy. The resulting work is called a "modified version" of the
75 | earlier work or a work "based on" the earlier work.
76 |
77 | A "covered work" means either the unmodified Program or a work based
78 | on the Program.
79 |
80 | To "propagate" a work means to do anything with it that, without
81 | permission, would make you directly or secondarily liable for
82 | infringement under applicable copyright law, except executing it on a
83 | computer or modifying a private copy. Propagation includes copying,
84 | distribution (with or without modification), making available to the
85 | public, and in some countries other activities as well.
86 |
87 | To "convey" a work means any kind of propagation that enables other
88 | parties to make or receive copies. Mere interaction with a user through
89 | a computer network, with no transfer of a copy, is not conveying.
90 |
91 | An interactive user interface displays "Appropriate Legal Notices"
92 | to the extent that it includes a convenient and prominently visible
93 | feature that (1) displays an appropriate copyright notice, and (2)
94 | tells the user that there is no warranty for the work (except to the
95 | extent that warranties are provided), that licensees may convey the
96 | work under this License, and how to view a copy of this License. If
97 | the interface presents a list of user commands or options, such as a
98 | menu, a prominent item in the list meets this criterion.
99 |
100 | 1. Source Code.
101 |
102 | The "source code" for a work means the preferred form of the work
103 | for making modifications to it. "Object code" means any non-source
104 | form of a work.
105 |
106 | A "Standard Interface" means an interface that either is an official
107 | standard defined by a recognized standards body, or, in the case of
108 | interfaces specified for a particular programming language, one that
109 | is widely used among developers working in that language.
110 |
111 | The "System Libraries" of an executable work include anything, other
112 | than the work as a whole, that (a) is included in the normal form of
113 | packaging a Major Component, but which is not part of that Major
114 | Component, and (b) serves only to enable use of the work with that
115 | Major Component, or to implement a Standard Interface for which an
116 | implementation is available to the public in source code form. A
117 | "Major Component", in this context, means a major essential component
118 | (kernel, window system, and so on) of the specific operating system
119 | (if any) on which the executable work runs, or a compiler used to
120 | produce the work, or an object code interpreter used to run it.
121 |
122 | The "Corresponding Source" for a work in object code form means all
123 | the source code needed to generate, install, and (for an executable
124 | work) run the object code and to modify the work, including scripts to
125 | control those activities. However, it does not include the work's
126 | System Libraries, or general-purpose tools or generally available free
127 | programs which are used unmodified in performing those activities but
128 | which are not part of the work. For example, Corresponding Source
129 | includes interface definition files associated with source files for
130 | the work, and the source code for shared libraries and dynamically
131 | linked subprograms that the work is specifically designed to require,
132 | such as by intimate data communication or control flow between those
133 | subprograms and other parts of the work.
134 |
135 | The Corresponding Source need not include anything that users
136 | can regenerate automatically from other parts of the Corresponding
137 | Source.
138 |
139 | The Corresponding Source for a work in source code form is that
140 | same work.
141 |
142 | 2. Basic Permissions.
143 |
144 | All rights granted under this License are granted for the term of
145 | copyright on the Program, and are irrevocable provided the stated
146 | conditions are met. This License explicitly affirms your unlimited
147 | permission to run the unmodified Program. The output from running a
148 | covered work is covered by this License only if the output, given its
149 | content, constitutes a covered work. This License acknowledges your
150 | rights of fair use or other equivalent, as provided by copyright law.
151 |
152 | You may make, run and propagate covered works that you do not
153 | convey, without conditions so long as your license otherwise remains
154 | in force. You may convey covered works to others for the sole purpose
155 | of having them make modifications exclusively for you, or provide you
156 | with facilities for running those works, provided that you comply with
157 | the terms of this License in conveying all material for which you do
158 | not control copyright. Those thus making or running the covered works
159 | for you must do so exclusively on your behalf, under your direction
160 | and control, on terms that prohibit them from making any copies of
161 | your copyrighted material outside their relationship with you.
162 |
163 | Conveying under any other circumstances is permitted solely under
164 | the conditions stated below. Sublicensing is not allowed; section 10
165 | makes it unnecessary.
166 |
167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168 |
169 | No covered work shall be deemed part of an effective technological
170 | measure under any applicable law fulfilling obligations under article
171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172 | similar laws prohibiting or restricting circumvention of such
173 | measures.
174 |
175 | When you convey a covered work, you waive any legal power to forbid
176 | circumvention of technological measures to the extent such circumvention
177 | is effected by exercising rights under this License with respect to
178 | the covered work, and you disclaim any intention to limit operation or
179 | modification of the work as a means of enforcing, against the work's
180 | users, your or third parties' legal rights to forbid circumvention of
181 | technological measures.
182 |
183 | 4. Conveying Verbatim Copies.
184 |
185 | You may convey verbatim copies of the Program's source code as you
186 | receive it, in any medium, provided that you conspicuously and
187 | appropriately publish on each copy an appropriate copyright notice;
188 | keep intact all notices stating that this License and any
189 | non-permissive terms added in accord with section 7 apply to the code;
190 | keep intact all notices of the absence of any warranty; and give all
191 | recipients a copy of this License along with the Program.
192 |
193 | You may charge any price or no price for each copy that you convey,
194 | and you may offer support or warranty protection for a fee.
195 |
196 | 5. Conveying Modified Source Versions.
197 |
198 | You may convey a work based on the Program, or the modifications to
199 | produce it from the Program, in the form of source code under the
200 | terms of section 4, provided that you also meet all of these conditions:
201 |
202 | a) The work must carry prominent notices stating that you modified
203 | it, and giving a relevant date.
204 |
205 | b) The work must carry prominent notices stating that it is
206 | released under this License and any conditions added under section
207 | 7. This requirement modifies the requirement in section 4 to
208 | "keep intact all notices".
209 |
210 | c) You must license the entire work, as a whole, under this
211 | License to anyone who comes into possession of a copy. This
212 | License will therefore apply, along with any applicable section 7
213 | additional terms, to the whole of the work, and all its parts,
214 | regardless of how they are packaged. This License gives no
215 | permission to license the work in any other way, but it does not
216 | invalidate such permission if you have separately received it.
217 |
218 | d) If the work has interactive user interfaces, each must display
219 | Appropriate Legal Notices; however, if the Program has interactive
220 | interfaces that do not display Appropriate Legal Notices, your
221 | work need not make them do so.
222 |
223 | A compilation of a covered work with other separate and independent
224 | works, which are not by their nature extensions of the covered work,
225 | and which are not combined with it such as to form a larger program,
226 | in or on a volume of a storage or distribution medium, is called an
227 | "aggregate" if the compilation and its resulting copyright are not
228 | used to limit the access or legal rights of the compilation's users
229 | beyond what the individual works permit. Inclusion of a covered work
230 | in an aggregate does not cause this License to apply to the other
231 | parts of the aggregate.
232 |
233 | 6. Conveying Non-Source Forms.
234 |
235 | You may convey a covered work in object code form under the terms
236 | of sections 4 and 5, provided that you also convey the
237 | machine-readable Corresponding Source under the terms of this License,
238 | in one of these ways:
239 |
240 | a) Convey the object code in, or embodied in, a physical product
241 | (including a physical distribution medium), accompanied by the
242 | Corresponding Source fixed on a durable physical medium
243 | customarily used for software interchange.
244 |
245 | b) Convey the object code in, or embodied in, a physical product
246 | (including a physical distribution medium), accompanied by a
247 | written offer, valid for at least three years and valid for as
248 | long as you offer spare parts or customer support for that product
249 | model, to give anyone who possesses the object code either (1) a
250 | copy of the Corresponding Source for all the software in the
251 | product that is covered by this License, on a durable physical
252 | medium customarily used for software interchange, for a price no
253 | more than your reasonable cost of physically performing this
254 | conveying of source, or (2) access to copy the
255 | Corresponding Source from a network server at no charge.
256 |
257 | c) Convey individual copies of the object code with a copy of the
258 | written offer to provide the Corresponding Source. This
259 | alternative is allowed only occasionally and noncommercially, and
260 | only if you received the object code with such an offer, in accord
261 | with subsection 6b.
262 |
263 | d) Convey the object code by offering access from a designated
264 | place (gratis or for a charge), and offer equivalent access to the
265 | Corresponding Source in the same way through the same place at no
266 | further charge. You need not require recipients to copy the
267 | Corresponding Source along with the object code. If the place to
268 | copy the object code is a network server, the Corresponding Source
269 | may be on a different server (operated by you or a third party)
270 | that supports equivalent copying facilities, provided you maintain
271 | clear directions next to the object code saying where to find the
272 | Corresponding Source. Regardless of what server hosts the
273 | Corresponding Source, you remain obligated to ensure that it is
274 | available for as long as needed to satisfy these requirements.
275 |
276 | e) Convey the object code using peer-to-peer transmission, provided
277 | you inform other peers where the object code and Corresponding
278 | Source of the work are being offered to the general public at no
279 | charge under subsection 6d.
280 |
281 | A separable portion of the object code, whose source code is excluded
282 | from the Corresponding Source as a System Library, need not be
283 | included in conveying the object code work.
284 |
285 | A "User Product" is either (1) a "consumer product", which means any
286 | tangible personal property which is normally used for personal, family,
287 | or household purposes, or (2) anything designed or sold for incorporation
288 | into a dwelling. In determining whether a product is a consumer product,
289 | doubtful cases shall be resolved in favor of coverage. For a particular
290 | product received by a particular user, "normally used" refers to a
291 | typical or common use of that class of product, regardless of the status
292 | of the particular user or of the way in which the particular user
293 | actually uses, or expects or is expected to use, the product. A product
294 | is a consumer product regardless of whether the product has substantial
295 | commercial, industrial or non-consumer uses, unless such uses represent
296 | the only significant mode of use of the product.
297 |
298 | "Installation Information" for a User Product means any methods,
299 | procedures, authorization keys, or other information required to install
300 | and execute modified versions of a covered work in that User Product from
301 | a modified version of its Corresponding Source. The information must
302 | suffice to ensure that the continued functioning of the modified object
303 | code is in no case prevented or interfered with solely because
304 | modification has been made.
305 |
306 | If you convey an object code work under this section in, or with, or
307 | specifically for use in, a User Product, and the conveying occurs as
308 | part of a transaction in which the right of possession and use of the
309 | User Product is transferred to the recipient in perpetuity or for a
310 | fixed term (regardless of how the transaction is characterized), the
311 | Corresponding Source conveyed under this section must be accompanied
312 | by the Installation Information. But this requirement does not apply
313 | if neither you nor any third party retains the ability to install
314 | modified object code on the User Product (for example, the work has
315 | been installed in ROM).
316 |
317 | The requirement to provide Installation Information does not include a
318 | requirement to continue to provide support service, warranty, or updates
319 | for a work that has been modified or installed by the recipient, or for
320 | the User Product in which it has been modified or installed. Access to a
321 | network may be denied when the modification itself materially and
322 | adversely affects the operation of the network or violates the rules and
323 | protocols for communication across the network.
324 |
325 | Corresponding Source conveyed, and Installation Information provided,
326 | in accord with this section must be in a format that is publicly
327 | documented (and with an implementation available to the public in
328 | source code form), and must require no special password or key for
329 | unpacking, reading or copying.
330 |
331 | 7. Additional Terms.
332 |
333 | "Additional permissions" are terms that supplement the terms of this
334 | License by making exceptions from one or more of its conditions.
335 | Additional permissions that are applicable to the entire Program shall
336 | be treated as though they were included in this License, to the extent
337 | that they are valid under applicable law. If additional permissions
338 | apply only to part of the Program, that part may be used separately
339 | under those permissions, but the entire Program remains governed by
340 | this License without regard to the additional permissions.
341 |
342 | When you convey a copy of a covered work, you may at your option
343 | remove any additional permissions from that copy, or from any part of
344 | it. (Additional permissions may be written to require their own
345 | removal in certain cases when you modify the work.) You may place
346 | additional permissions on material, added by you to a covered work,
347 | for which you have or can give appropriate copyright permission.
348 |
349 | Notwithstanding any other provision of this License, for material you
350 | add to a covered work, you may (if authorized by the copyright holders of
351 | that material) supplement the terms of this License with terms:
352 |
353 | a) Disclaiming warranty or limiting liability differently from the
354 | terms of sections 15 and 16 of this License; or
355 |
356 | b) Requiring preservation of specified reasonable legal notices or
357 | author attributions in that material or in the Appropriate Legal
358 | Notices displayed by works containing it; or
359 |
360 | c) Prohibiting misrepresentation of the origin of that material, or
361 | requiring that modified versions of such material be marked in
362 | reasonable ways as different from the original version; or
363 |
364 | d) Limiting the use for publicity purposes of names of licensors or
365 | authors of the material; or
366 |
367 | e) Declining to grant rights under trademark law for use of some
368 | trade names, trademarks, or service marks; or
369 |
370 | f) Requiring indemnification of licensors and authors of that
371 | material by anyone who conveys the material (or modified versions of
372 | it) with contractual assumptions of liability to the recipient, for
373 | any liability that these contractual assumptions directly impose on
374 | those licensors and authors.
375 |
376 | All other non-permissive additional terms are considered "further
377 | restrictions" within the meaning of section 10. If the Program as you
378 | received it, or any part of it, contains a notice stating that it is
379 | governed by this License along with a term that is a further
380 | restriction, you may remove that term. If a license document contains
381 | a further restriction but permits relicensing or conveying under this
382 | License, you may add to a covered work material governed by the terms
383 | of that license document, provided that the further restriction does
384 | not survive such relicensing or conveying.
385 |
386 | If you add terms to a covered work in accord with this section, you
387 | must place, in the relevant source files, a statement of the
388 | additional terms that apply to those files, or a notice indicating
389 | where to find the applicable terms.
390 |
391 | Additional terms, permissive or non-permissive, may be stated in the
392 | form of a separately written license, or stated as exceptions;
393 | the above requirements apply either way.
394 |
395 | 8. Termination.
396 |
397 | You may not propagate or modify a covered work except as expressly
398 | provided under this License. Any attempt otherwise to propagate or
399 | modify it is void, and will automatically terminate your rights under
400 | this License (including any patent licenses granted under the third
401 | paragraph of section 11).
402 |
403 | However, if you cease all violation of this License, then your
404 | license from a particular copyright holder is reinstated (a)
405 | provisionally, unless and until the copyright holder explicitly and
406 | finally terminates your license, and (b) permanently, if the copyright
407 | holder fails to notify you of the violation by some reasonable means
408 | prior to 60 days after the cessation.
409 |
410 | Moreover, your license from a particular copyright holder is
411 | reinstated permanently if the copyright holder notifies you of the
412 | violation by some reasonable means, this is the first time you have
413 | received notice of violation of this License (for any work) from that
414 | copyright holder, and you cure the violation prior to 30 days after
415 | your receipt of the notice.
416 |
417 | Termination of your rights under this section does not terminate the
418 | licenses of parties who have received copies or rights from you under
419 | this License. If your rights have been terminated and not permanently
420 | reinstated, you do not qualify to receive new licenses for the same
421 | material under section 10.
422 |
423 | 9. Acceptance Not Required for Having Copies.
424 |
425 | You are not required to accept this License in order to receive or
426 | run a copy of the Program. Ancillary propagation of a covered work
427 | occurring solely as a consequence of using peer-to-peer transmission
428 | to receive a copy likewise does not require acceptance. However,
429 | nothing other than this License grants you permission to propagate or
430 | modify any covered work. These actions infringe copyright if you do
431 | not accept this License. Therefore, by modifying or propagating a
432 | covered work, you indicate your acceptance of this License to do so.
433 |
434 | 10. Automatic Licensing of Downstream Recipients.
435 |
436 | Each time you convey a covered work, the recipient automatically
437 | receives a license from the original licensors, to run, modify and
438 | propagate that work, subject to this License. You are not responsible
439 | for enforcing compliance by third parties with this License.
440 |
441 | An "entity transaction" is a transaction transferring control of an
442 | organization, or substantially all assets of one, or subdividing an
443 | organization, or merging organizations. If propagation of a covered
444 | work results from an entity transaction, each party to that
445 | transaction who receives a copy of the work also receives whatever
446 | licenses to the work the party's predecessor in interest had or could
447 | give under the previous paragraph, plus a right to possession of the
448 | Corresponding Source of the work from the predecessor in interest, if
449 | the predecessor has it or can get it with reasonable efforts.
450 |
451 | You may not impose any further restrictions on the exercise of the
452 | rights granted or affirmed under this License. For example, you may
453 | not impose a license fee, royalty, or other charge for exercise of
454 | rights granted under this License, and you may not initiate litigation
455 | (including a cross-claim or counterclaim in a lawsuit) alleging that
456 | any patent claim is infringed by making, using, selling, offering for
457 | sale, or importing the Program or any portion of it.
458 |
459 | 11. Patents.
460 |
461 | A "contributor" is a copyright holder who authorizes use under this
462 | License of the Program or a work on which the Program is based. The
463 | work thus licensed is called the contributor's "contributor version".
464 |
465 | A contributor's "essential patent claims" are all patent claims
466 | owned or controlled by the contributor, whether already acquired or
467 | hereafter acquired, that would be infringed by some manner, permitted
468 | by this License, of making, using, or selling its contributor version,
469 | but do not include claims that would be infringed only as a
470 | consequence of further modification of the contributor version. For
471 | purposes of this definition, "control" includes the right to grant
472 | patent sublicenses in a manner consistent with the requirements of
473 | this License.
474 |
475 | Each contributor grants you a non-exclusive, worldwide, royalty-free
476 | patent license under the contributor's essential patent claims, to
477 | make, use, sell, offer for sale, import and otherwise run, modify and
478 | propagate the contents of its contributor version.
479 |
480 | In the following three paragraphs, a "patent license" is any express
481 | agreement or commitment, however denominated, not to enforce a patent
482 | (such as an express permission to practice a patent or covenant not to
483 | sue for patent infringement). To "grant" such a patent license to a
484 | party means to make such an agreement or commitment not to enforce a
485 | patent against the party.
486 |
487 | If you convey a covered work, knowingly relying on a patent license,
488 | and the Corresponding Source of the work is not available for anyone
489 | to copy, free of charge and under the terms of this License, through a
490 | publicly available network server or other readily accessible means,
491 | then you must either (1) cause the Corresponding Source to be so
492 | available, or (2) arrange to deprive yourself of the benefit of the
493 | patent license for this particular work, or (3) arrange, in a manner
494 | consistent with the requirements of this License, to extend the patent
495 | license to downstream recipients. "Knowingly relying" means you have
496 | actual knowledge that, but for the patent license, your conveying the
497 | covered work in a country, or your recipient's use of the covered work
498 | in a country, would infringe one or more identifiable patents in that
499 | country that you have reason to believe are valid.
500 |
501 | If, pursuant to or in connection with a single transaction or
502 | arrangement, you convey, or propagate by procuring conveyance of, a
503 | covered work, and grant a patent license to some of the parties
504 | receiving the covered work authorizing them to use, propagate, modify
505 | or convey a specific copy of the covered work, then the patent license
506 | you grant is automatically extended to all recipients of the covered
507 | work and works based on it.
508 |
509 | A patent license is "discriminatory" if it does not include within
510 | the scope of its coverage, prohibits the exercise of, or is
511 | conditioned on the non-exercise of one or more of the rights that are
512 | specifically granted under this License. You may not convey a covered
513 | work if you are a party to an arrangement with a third party that is
514 | in the business of distributing software, under which you make payment
515 | to the third party based on the extent of your activity of conveying
516 | the work, and under which the third party grants, to any of the
517 | parties who would receive the covered work from you, a discriminatory
518 | patent license (a) in connection with copies of the covered work
519 | conveyed by you (or copies made from those copies), or (b) primarily
520 | for and in connection with specific products or compilations that
521 | contain the covered work, unless you entered into that arrangement,
522 | or that patent license was granted, prior to 28 March 2007.
523 |
524 | Nothing in this License shall be construed as excluding or limiting
525 | any implied license or other defenses to infringement that may
526 | otherwise be available to you under applicable patent law.
527 |
528 | 12. No Surrender of Others' Freedom.
529 |
530 | If conditions are imposed on you (whether by court order, agreement or
531 | otherwise) that contradict the conditions of this License, they do not
532 | excuse you from the conditions of this License. If you cannot convey a
533 | covered work so as to satisfy simultaneously your obligations under this
534 | License and any other pertinent obligations, then as a consequence you may
535 | not convey it at all. For example, if you agree to terms that obligate you
536 | to collect a royalty for further conveying from those to whom you convey
537 | the Program, the only way you could satisfy both those terms and this
538 | License would be to refrain entirely from conveying the Program.
539 |
540 | 13. Remote Network Interaction; Use with the GNU General Public License.
541 |
542 | Notwithstanding any other provision of this License, if you modify the
543 | Program, your modified version must prominently offer all users
544 | interacting with it remotely through a computer network (if your version
545 | supports such interaction) an opportunity to receive the Corresponding
546 | Source of your version by providing access to the Corresponding Source
547 | from a network server at no charge, through some standard or customary
548 | means of facilitating copying of software. This Corresponding Source
549 | shall include the Corresponding Source for any work covered by version 3
550 | of the GNU General Public License that is incorporated pursuant to the
551 | following paragraph.
552 |
553 | Notwithstanding any other provision of this License, you have
554 | permission to link or combine any covered work with a work licensed
555 | under version 3 of the GNU General Public License into a single
556 | combined work, and to convey the resulting work. The terms of this
557 | License will continue to apply to the part which is the covered work,
558 | but the work with which it is combined will remain governed by version
559 | 3 of the GNU General Public License.
560 |
561 | 14. Revised Versions of this License.
562 |
563 | The Free Software Foundation may publish revised and/or new versions of
564 | the GNU Affero General Public License from time to time. Such new versions
565 | will be similar in spirit to the present version, but may differ in detail to
566 | address new problems or concerns.
567 |
568 | Each version is given a distinguishing version number. If the
569 | Program specifies that a certain numbered version of the GNU Affero General
570 | Public License "or any later version" applies to it, you have the
571 | option of following the terms and conditions either of that numbered
572 | version or of any later version published by the Free Software
573 | Foundation. If the Program does not specify a version number of the
574 | GNU Affero General Public License, you may choose any version ever published
575 | by the Free Software Foundation.
576 |
577 | If the Program specifies that a proxy can decide which future
578 | versions of the GNU Affero General Public License can be used, that proxy's
579 | public statement of acceptance of a version permanently authorizes you
580 | to choose that version for the Program.
581 |
582 | Later license versions may give you additional or different
583 | permissions. However, no additional obligations are imposed on any
584 | author or copyright holder as a result of your choosing to follow a
585 | later version.
586 |
587 | 15. Disclaimer of Warranty.
588 |
589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597 |
598 | 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608 | SUCH DAMAGES.
609 |
610 | 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
620 |
621 | How to Apply These Terms to Your New Programs
622 |
623 | If you develop a new program, and you want it to be of the greatest
624 | possible use to the public, the best way to achieve this is to make it
625 | free software which everyone can redistribute and change under these terms.
626 |
627 | To do so, attach the following notices to the program. It is safest
628 | to attach them to the start of each source file to most effectively
629 | state the exclusion of warranty; and each file should have at least
630 | the "copyright" line and a pointer to where the full notice is found.
631 |
632 |
633 | Copyright (C)
634 |
635 | This program is free software: you can redistribute it and/or modify
636 | it under the terms of the GNU Affero General Public License as published
637 | by the Free Software Foundation, either version 3 of the License, or
638 | (at your option) any later version.
639 |
640 | This program is distributed in the hope that it will be useful,
641 | but WITHOUT ANY WARRANTY; without even the implied warranty of
642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643 | GNU Affero General Public License for more details.
644 |
645 | You should have received a copy of the GNU Affero General Public License
646 | along with this program. If not, see .
647 |
648 | Also add information on how to contact you by electronic and paper mail.
649 |
650 | If your software can interact with users remotely through a computer
651 | network, you should also make sure that it provides a way for users to
652 | get its source. For example, if your program is a web application, its
653 | interface could display a "Source" link that leads users to an archive
654 | of the code. There are many ways you could offer source, and different
655 | solutions will be better for different programs; see section 13 for the
656 | specific requirements.
657 |
658 | You should also get your employer (if you work as a programmer) or school,
659 | if any, to sign a "copyright disclaimer" for the program, if necessary.
660 | For more information on this, and how to apply and follow the GNU AGPL, see
661 | .
662 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | lint:
2 | @golangci-lint run
3 |
4 | # BuildTime time when the binary was built
5 | # BuildVersion version of the bot itself, as described by most recent git tag
6 | # BuildHash short Git commit hash
7 | # BuildBranch Git branch
8 | build:
9 | @cd cmd/bot && go build -ldflags " \
10 | -X \"main.buildTime=$$(date +%Y-%m-%dT%H:%M:%S%:z)\" \
11 | -X \"main.buildVersion=$$(git describe --abbrev=0 2>/dev/null || echo -n)\" \
12 | -X \"main.buildHash=$$(git rev-parse --short HEAD)\" \
13 | -X \"main.buildBranch=$$(git rev-parse --abbrev-ref HEAD)\" \
14 | " \
15 | "${@:2}"
16 |
17 | check: lint
18 |
--------------------------------------------------------------------------------
/cmd/bot/channels.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "context"
5 | "log"
6 | "time"
7 |
8 | "github.com/gempir/go-twitch-irc/v3"
9 | "github.com/nicklaw5/helix/v2"
10 | "github.com/zneix/tcb2/internal/bot"
11 | "github.com/zneix/tcb2/internal/eventsub"
12 | "github.com/zneix/tcb2/internal/mongo"
13 | "github.com/zneix/tcb2/pkg/utils"
14 | "go.mongodb.org/mongo-driver/bson"
15 | )
16 |
17 | // loadChannels fetches configured channels from the database, sets default values and message queue for each of them
18 | func loadChannels(bgctx context.Context, mongoConn *mongo.Connection, twitchIRC *twitch.Client) map[string]*bot.Channel {
19 | channels := make(map[string]*bot.Channel)
20 |
21 | ctx, cancel := context.WithTimeout(bgctx, 10*time.Second)
22 | defer cancel()
23 |
24 | // Query all channels from the database, excluding inactive channels
25 | cur, err := mongoConn.Collection(mongo.CollectionNameChannels).Find(ctx, bson.M{
26 | "mode": &bson.M{
27 | "$ne": int(bot.ChannelModeInactive),
28 | },
29 | })
30 | if err != nil {
31 | log.Fatalln("[Mongo] Error querying channels:", err)
32 | return channels
33 | }
34 |
35 | for cur.Next(ctx) {
36 | // Deserialize channel data
37 | var channel bot.Channel
38 | err := cur.Decode(&channel)
39 | if err != nil {
40 | log.Println("[Mongo] Malformed channel document:", err)
41 | continue
42 | }
43 |
44 | // Initialize default values
45 | channel.QueueChannel = make(chan *bot.QueueMessage)
46 | go channel.StartMessageQueue(twitchIRC)
47 |
48 | channels[channel.ID] = &channel
49 | }
50 |
51 | if err := cur.Err(); err != nil {
52 | log.Println("[Mongo] Last cursor error while loading channels wasn't nil:", err)
53 | }
54 |
55 | return channels
56 | }
57 |
58 | var channelSubscriptions = []eventsub.ChannelSubscription{
59 | {
60 | Type: "channel.update",
61 | Version: "1",
62 | },
63 | {
64 | Type: "stream.online",
65 | Version: "1",
66 | },
67 | {
68 | Type: "stream.offline",
69 | Version: "1",
70 | },
71 | }
72 |
73 | // joinChannels performs startup actions for all the channels that are already loaded
74 | func joinChannels(tcb *bot.Bot) {
75 | // Fetch channel information for all channels (in bulks of 100)
76 | channelIDs := make([]string, 0, len(tcb.Channels))
77 | for k := range tcb.Channels {
78 | channelIDs = append(channelIDs, k)
79 | }
80 |
81 | channelIDChunks := utils.ChunkStringSlice(channelIDs, 100)
82 |
83 | for _, chunk := range channelIDChunks {
84 | go handleChannelsChunk(tcb, chunk)
85 | }
86 | }
87 |
88 | // handleChannelsChunk performs startup actions for channels with IDs from chunk
89 | func handleChannelsChunk(tcb *bot.Bot, chunk []string) {
90 | // Fetch Title & Game for all loaded channels
91 | respC, err := tcb.Helix.GetChannelInformation(&helix.GetChannelInformationParams{
92 | BroadcasterIDs: chunk,
93 | })
94 | if err != nil {
95 | log.Printf("Failed to query channel chunk %s; channels: %v", err, chunk)
96 | return
97 | }
98 |
99 | for _, respChannel := range respC.Data.Channels {
100 | channel := tcb.Channels[respChannel.BroadcasterID]
101 |
102 | // Set the ID in map translating login names back to IDs
103 | tcb.Logins[channel.Login] = channel.ID
104 |
105 | // Assign fetched properties to the channels
106 | channel.CurrentGame = respChannel.GameName
107 | channel.CurrentTitle = respChannel.Title
108 |
109 | // JOIN the channel
110 | tcb.TwitchIRC.Join(channel.Login)
111 |
112 | // Create all EventSub subscriptions parallelly
113 | for _, subscription := range channelSubscriptions {
114 | go func(sub eventsub.ChannelSubscription) {
115 | sub.ChannelID = channel.ID
116 | err = tcb.EventSub.CreateChannelSubscription(tcb.Helix, &sub)
117 | if err != nil {
118 | log.Println("[EventSub] Failed to create a subscription: " + err.Error())
119 | }
120 | }(subscription)
121 | }
122 | }
123 |
124 | // Fetch live status to check which channels out of loaded ones are live
125 | respS, err := tcb.Helix.GetStreams(&helix.StreamsParams{
126 | First: 100,
127 | UserIDs: chunk,
128 | })
129 | if err != nil {
130 | log.Printf("Failed to query stream chunk %s; channels: %v", err, chunk)
131 | return
132 | }
133 |
134 | for i := range respS.Data.Streams {
135 | respStream := &respS.Data.Streams[i]
136 | channel := tcb.Channels[respStream.UserID]
137 |
138 | log.Printf("[Helix:GetStreams] %s %s\n", respStream.Type, channel)
139 | if respStream.Type == "live" {
140 | channel.IsLive = true
141 | }
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/cmd/bot/commands.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "github.com/zneix/tcb2/internal/bot"
5 | "github.com/zneix/tcb2/internal/commands"
6 | )
7 |
8 | func registerCommands(tcb *bot.Bot) {
9 | tcb.Commands.RegisterCommand(commands.Ping(tcb))
10 | tcb.Commands.RegisterCommand(commands.Bot(tcb))
11 | tcb.Commands.RegisterCommand(commands.Game(tcb))
12 | tcb.Commands.RegisterCommand(commands.Title(tcb))
13 | tcb.Commands.RegisterCommand(commands.IsLive(tcb))
14 | tcb.Commands.RegisterCommand(commands.Events(tcb))
15 | tcb.Commands.RegisterCommand(commands.Help(tcb))
16 | tcb.Commands.RegisterCommand(commands.Subscribed(tcb))
17 | tcb.Commands.RegisterCommand(commands.NotifyMe(tcb))
18 | tcb.Commands.RegisterCommand(commands.RemoveMe(tcb))
19 |
20 | // Migration commands, admin use only
21 | // tcb.Commands.RegisterCommand(commands.MigrateChannels(tcb))
22 | // tcb.Commands.RegisterCommand(commands.MigrateSubscriptions(tcb))
23 | }
24 |
--------------------------------------------------------------------------------
/cmd/bot/common.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "github.com/zneix/tcb2/internal/common"
4 |
5 | var (
6 | buildTime string
7 | buildVersion string = "dev"
8 | buildHash string
9 | buildBranch string
10 | )
11 |
12 | // Initialized values in the singleton common package
13 | func init() {
14 | common.BuildTime = buildTime
15 | common.BuildVersion = buildVersion
16 | common.BuildHash = buildHash
17 | common.BuildBranch = buildBranch
18 | }
19 |
--------------------------------------------------------------------------------
/cmd/bot/events.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 | "strings"
6 | "time"
7 | "unicode/utf8"
8 |
9 | "github.com/gempir/go-twitch-irc/v3"
10 | "github.com/nicklaw5/helix/v2"
11 | "github.com/zneix/tcb2/internal/bot"
12 | )
13 |
14 | func registerEvents(tcb *bot.Bot) {
15 | // Twitch IRC events
16 |
17 | // Authenticated with IRC
18 | tcb.TwitchIRC.OnConnect(func() {
19 | log.Println("[TwitchIRC] connected")
20 | joinChannels(tcb)
21 | })
22 |
23 | // PRIVMSG
24 | tcb.TwitchIRC.OnPrivateMessage(func(message twitch.PrivateMessage) {
25 | // Early out in case message does not start with command prefix - meaning it's not a command
26 | if !strings.HasPrefix(message.Message, tcb.Commands.Prefix) {
27 | // Handle non-commands
28 | return
29 | }
30 |
31 | // Parse command name and arguments
32 | args := strings.Fields(message.Message)
33 | commandName := strings.ToLower(args[0][utf8.RuneCountInString(tcb.Commands.Prefix):])
34 | args = args[1:]
35 |
36 | // Try to find the command by its name and/or aliases
37 | command, exists := tcb.Commands.GetCommand(commandName)
38 | if !exists {
39 | return
40 | }
41 |
42 | // Skip command execution if it's disabled in the target channel
43 | channel := tcb.Channels[message.RoomID]
44 | for _, disabledCmdName := range channel.DisabledCommands {
45 | if commandName == disabledCmdName {
46 | return
47 | }
48 | }
49 |
50 | // TODO: [Permissions] Check if user is allowed to execute the command
51 |
52 | // Check if channel or user is on cooldown
53 | if time.Since(command.LastExecutionChannel[message.RoomID]) < command.CooldownChannel || time.Since(command.LastExecutionUser[message.User.ID]) < command.CooldownUser {
54 | return
55 | }
56 |
57 | // Execute the command
58 | go command.Run(message, args)
59 |
60 | // Apply cooldown if user's permissions don't allow to skip it
61 | // TODO: [Permissions] Don't apply user cooldowns to users that are allowed to skip it
62 | command.LastExecutionChannel[message.RoomID] = time.Now()
63 | command.LastExecutionUser[message.User.ID] = time.Now()
64 | })
65 |
66 | // USERSTATE
67 | tcb.TwitchIRC.OnUserStateMessage(func(message twitch.UserStateMessage) {
68 | channelID, ok := tcb.Logins[message.Channel]
69 | if !ok {
70 | // tcb.Logins map didn't have current channel's ID
71 | // Note: this should realistically never occur though, but early exit to prevent panic
72 | return
73 | }
74 |
75 | channel := tcb.Channels[channelID]
76 |
77 | // Check if Channel.Mode changed by comparing bot's state
78 | newMode := bot.ChannelModeNormal
79 |
80 | // Bot will always have elevated permissions in its own chat, saving some time with the early-out
81 | if channel.Login == tcb.Self.Login {
82 | return
83 | }
84 |
85 | userType, ok := message.Tags["user-type"]
86 | switch {
87 | case !ok:
88 | log.Println("[TwitchIRC:USERSTATE] user-type tag was not found in the IRC message, either no capabilities or Twitch removed this tag xd")
89 |
90 | case userType == "mod":
91 | newMode = bot.ChannelModeModerator
92 |
93 | default:
94 | // Since user-type does not care about VIP status, we need to check badges
95 | for key := range message.User.Badges {
96 | if key == "vip" || key == "moderator" {
97 | newMode = bot.ChannelModeModerator
98 | break
99 | }
100 | }
101 | }
102 |
103 | // Update ChannelMode in the current channel if it differs
104 | if newMode != channel.Mode {
105 | err := channel.ChangeMode(tcb.Mongo, newMode)
106 | if err != nil {
107 | log.Printf("Failed to change mode in %s: %s\n", channel, err)
108 | }
109 | }
110 | })
111 |
112 | // NOTICE
113 | tcb.TwitchIRC.OnNoticeMessage(func(message twitch.NoticeMessage) {
114 | channelID, ok := tcb.Logins[message.Channel]
115 | if !ok {
116 | // tcb.Logins map didn't have current channel's ID
117 | // Note: this should realistically never occur though, but early exit to prevent panic
118 | return
119 | }
120 | channel := tcb.Channels[channelID]
121 |
122 | log.Printf("[TwitchIRC:NOTICE] %s in %s\n", message.MsgID, channel)
123 |
124 | switch message.MsgID {
125 | case "msg_banned", "msg_channel_suspended":
126 | err := channel.ChangeMode(tcb.Mongo, bot.ChannelModeInactive)
127 | if err != nil {
128 | log.Printf("Failed to change mode in %s: %s\n", channel, err)
129 | }
130 | default:
131 | }
132 | })
133 |
134 | // Twitch EventSub events
135 |
136 | // channel.update
137 | tcb.EventSub.OnChannelUpdateEvent(func(event helix.EventSubChannelUpdateEvent) {
138 | log.Printf("[EventSub:channel.update] %# v\n", event)
139 | channel, ok := tcb.Channels[event.BroadcasterUserID]
140 | if !ok {
141 | return
142 | }
143 |
144 | // Announce game change
145 | if event.CategoryName != channel.CurrentGame {
146 | channel.CurrentGame = event.CategoryName
147 | go subEventTrigger(&bot.SubEventMessage{
148 | Bot: tcb,
149 | ChannelID: event.BroadcasterUserID,
150 | Type: bot.SubEventTypeGame,
151 | })
152 | }
153 | // Announce title change
154 | if event.Title != channel.CurrentTitle {
155 | channel.CurrentTitle = event.Title
156 | go subEventTrigger(&bot.SubEventMessage{
157 | Bot: tcb,
158 | ChannelID: event.BroadcasterUserID,
159 | Type: bot.SubEventTypeTitle,
160 | })
161 | }
162 | })
163 |
164 | // stream.online
165 | tcb.EventSub.OnStreamOnlineEvent(func(event helix.EventSubStreamOnlineEvent) {
166 | log.Printf("[EventSub:stream.online] %# v\n", event)
167 | channel, ok := tcb.Channels[event.BroadcasterUserID]
168 | if !ok {
169 | return
170 | }
171 |
172 | if channel.IsLive {
173 | log.Printf("[EventSub] Received stream.online, but %s seems to be already live!", channel)
174 | return
175 | }
176 |
177 | channel.IsLive = true
178 | // Announce channel going live
179 | go subEventTrigger(&bot.SubEventMessage{
180 | Bot: tcb,
181 | ChannelID: event.BroadcasterUserID,
182 | Type: bot.SubEventTypeLive,
183 | })
184 | })
185 |
186 | // stream.offline
187 | tcb.EventSub.OnStreamOfflineEvent(func(event helix.EventSubStreamOfflineEvent) {
188 | log.Printf("[EventSub:stream.offline] %# v\n", event)
189 | channel, ok := tcb.Channels[event.BroadcasterUserID]
190 | if !ok {
191 | return
192 | }
193 |
194 | if !channel.IsLive {
195 | log.Printf("[EventSub] Received stream.offline, but %s seems to be already offline!", channel)
196 | return
197 | }
198 |
199 | channel.IsLive = false
200 | // Announce channel going offline
201 | go subEventTrigger(&bot.SubEventMessage{
202 | Bot: tcb,
203 | ChannelID: event.BroadcasterUserID,
204 | Type: bot.SubEventTypeOffline,
205 | })
206 | })
207 | }
208 |
--------------------------------------------------------------------------------
/cmd/bot/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "context"
5 | "log"
6 | "time"
7 |
8 | "github.com/gempir/go-twitch-irc/v3"
9 | "github.com/zneix/tcb2/internal/api"
10 | "github.com/zneix/tcb2/internal/bot"
11 | "github.com/zneix/tcb2/internal/common"
12 | "github.com/zneix/tcb2/internal/config"
13 | "github.com/zneix/tcb2/internal/eventsub"
14 | "github.com/zneix/tcb2/internal/helixclient"
15 | "github.com/zneix/tcb2/internal/mongo"
16 | "github.com/zneix/tcb2/internal/supinicapi"
17 | )
18 |
19 | func init() {
20 | log.SetFlags(log.Flags() | log.Lmicroseconds)
21 | }
22 |
23 | func main() {
24 | log.Printf("Starting titlechange_bot %s", common.Version())
25 |
26 | cfg := config.New()
27 | ctx := context.Background()
28 |
29 | mongoConnection := mongo.NewMongoConnection(ctx, cfg)
30 | mongoConnection.Connect(ctx)
31 |
32 | twitchIRC := twitch.NewClient(cfg.TwitchLogin, "oauth:"+cfg.TwitchOAuth)
33 | twitchIRC.SetJoinRateLimiter(twitch.CreateVerifiedRateLimiter())
34 |
35 | helixClient, err := helixclient.New(cfg)
36 | if err != nil {
37 | log.Fatalln("[Helix] Error while initializing client:", err)
38 | }
39 |
40 | apiServer := api.New(cfg)
41 |
42 | esub := eventsub.New(cfg, apiServer)
43 |
44 | self := &bot.Self{
45 | Login: cfg.TwitchLogin,
46 | OAuth: cfg.TwitchOAuth,
47 | }
48 |
49 | tcb := &bot.Bot{
50 | TwitchIRC: twitchIRC,
51 | Mongo: mongoConnection,
52 | Helix: helixClient,
53 | EventSub: esub,
54 | Logins: make(map[string]string),
55 | Channels: loadChannels(ctx, mongoConnection, twitchIRC),
56 | Commands: bot.NewCommandController(cfg.CommandPrefix),
57 | Self: self,
58 | StartTime: time.Now(),
59 | }
60 |
61 | // Register actions that require bot.Bot object initialized already
62 | registerEvents(tcb)
63 | registerCommands(tcb)
64 |
65 | // TODO: Manage goroutines below and (currently blocking) Connect() with sync.WaitGroup
66 | // Listen on the API instance
67 | go apiServer.Listen()
68 |
69 | // Ping Supinic's API periodically to signal that bot is alive
70 | supinic := supinicapi.New(cfg.SupinicAPIKey)
71 | go supinic.UpdateAliveStatus()
72 |
73 | err = tcb.TwitchIRC.Connect()
74 | if err != nil {
75 | log.Fatalln(err)
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/cmd/bot/subevent.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "context"
5 | "errors"
6 | "fmt"
7 | "log"
8 | "strings"
9 | "unicode/utf8"
10 |
11 | "github.com/zneix/tcb2/internal/bot"
12 | "github.com/zneix/tcb2/internal/mongo"
13 | "github.com/zneix/tcb2/pkg/utils"
14 | "go.mongodb.org/mongo-driver/bson"
15 | mongodb "go.mongodb.org/mongo-driver/mongo"
16 | )
17 |
18 | // subEventTrigger will fetch relevant subscriptions and prepare ping messages, then attempt sending them in the channel where the event has occured
19 | func subEventTrigger(msg *bot.SubEventMessage) {
20 | channel := msg.Bot.Channels[msg.ChannelID]
21 | ctx := context.TODO()
22 |
23 | if channel.IsLive && channel.EventsOnlyOffline && msg.Type != bot.SubEventTypeLive {
24 | log.Printf("[SubEvent] Skipped announcing %s in %s because channel is live\n", msg.Type, channel)
25 | return
26 | }
27 |
28 | curSubs, err := msg.Bot.Mongo.CollectionSubs(msg.ChannelID).Find(ctx, bson.M{
29 | "event": msg.Type,
30 | })
31 | if err != nil {
32 | log.Println("[Mongo] Failed querying events:", err)
33 | return
34 | }
35 |
36 | subs := make([]*bot.SubEventSubscription, 0) // XXX: Test if this won't panic
37 |
38 | // value is either new title or new game depending of the event
39 | var value string
40 | switch msg.Type {
41 | case bot.SubEventTypeGame:
42 | value = channel.CurrentGame
43 | case bot.SubEventTypeTitle:
44 | value = channel.CurrentTitle
45 | }
46 |
47 | valueLower := strings.ToLower(value)
48 |
49 | // Fetch all relevant subscriptions
50 | for curSubs.Next(ctx) {
51 | // Deserialized sub data
52 | sub := new(bot.SubEventSubscription)
53 | err := curSubs.Decode(&sub)
54 | if err != nil {
55 | log.Println("[Mongo] Malformed subscription document:", err)
56 | continue
57 | }
58 |
59 | // Ignore subscriptions based on the value (if its present)
60 | if msg.Type == bot.SubEventTypeGame || msg.Type == bot.SubEventTypeTitle {
61 | if sub.Value != "" && !strings.Contains(valueLower, strings.ToLower(sub.Value)) {
62 | continue
63 | }
64 | }
65 | subs = append(subs, sub)
66 | }
67 |
68 | if len(subs) == 0 {
69 | log.Printf("[SubEvent] No relevant subscriptions for %v in %s\n", msg.Type, channel)
70 | return
71 | }
72 |
73 | messagePrefix := createMessagePrefix(channel.Events[msg.Type], value, channel.Login)
74 |
75 | // Prepare ping messages
76 | msgsToSend := []string{messagePrefix}
77 | for i := 0; i < len(subs); {
78 | sub := subs[i]
79 | newMsg := fmt.Sprintf("%s %s", msgsToSend[len(msgsToSend)-1], sub.UserLogin)
80 |
81 | // Adding user to the message would exceed limit in the target channel
82 | // We also want to re-run this iteration by decreasing i
83 | if utf8.RuneCountInString(newMsg) > channel.MessageLengthMax() {
84 | // We can't append any username to a message that is just our messagePrefix
85 | // Loop has to be broken or otherwise it'll run forever
86 | if msgsToSend[len(msgsToSend)-1] == messagePrefix {
87 | log.Printf("[SubEvent] messagePrefix might be too long (%d) in %s: %# v\n", utf8.RuneCountInString(messagePrefix), channel, messagePrefix)
88 | break
89 | }
90 | msgsToSend = append(msgsToSend, messagePrefix)
91 | continue
92 | }
93 | // Otherwise it's good to append the username to message with pings
94 | msgsToSend[len(msgsToSend)-1] = newMsg
95 | i++
96 | }
97 |
98 | // Send messages to the target channel
99 | // TODO: Pajbot API (?)
100 | for i, v := range msgsToSend {
101 | log.Printf("[SubEvent] Announcing %s in %s; %d/%d(%d/%d chars)\n", msg.Type, channel, i+1, len(msgsToSend), utf8.RuneCountInString(v), channel.MessageLengthMax())
102 | channel.Send(v)
103 | }
104 |
105 | // Fetch and send channel's MOTD
106 | handleMOTD(msg)
107 | }
108 |
109 | // createMessagePrefix constructs ping message's "prefix", which will be the beginning of every ping message
110 | func createMessagePrefix(format, value, login string) string {
111 | // Limit the length of a title / game in case it's too long, Twitch's limit is 140 anyway
112 | prefixReplacer := strings.NewReplacer(
113 | "{value}", utils.LimitString(value, 100),
114 | "{login}", login,
115 | )
116 | return ".me " + prefixReplacer.Replace(format)
117 | }
118 |
119 | // handleMOTD queries MOTD for the channel where event occurred and sends it if exists
120 | func handleMOTD(msg *bot.SubEventMessage) {
121 | // By design, it is only sent on live event
122 | if msg.Type != bot.SubEventTypeLive {
123 | return
124 | }
125 |
126 | res := msg.Bot.Mongo.Collection(mongo.CollectionNameMOTDs).FindOne(context.TODO(), bson.M{
127 | "channel_id": msg.ChannelID,
128 | })
129 | if err := res.Err(); err != nil {
130 | // Ignoring ErrNoDocuments, since it's not really an error (plus it is returned quite often)
131 | if !errors.Is(err, mongodb.ErrNoDocuments) {
132 | log.Printf("[Mongo] Failed querying MOTD for %s: %s\n", msg.ChannelID, err)
133 | }
134 | return
135 | }
136 |
137 | // Deserialized MOTD data
138 | motd := new(bot.SubEventMOTD)
139 | err := res.Decode(&motd)
140 | if err != nil {
141 | log.Printf("[Mongo] Malformed MOTD document for %s: %s\n", msg.ChannelID, err)
142 | return
143 | }
144 |
145 | // Send the MOTD to the channel
146 | channel := msg.Bot.Channels[msg.ChannelID]
147 | log.Printf("[SubEvent] Sending channel MOTD to %s (%d/%d chars)\n", channel, utf8.RuneCountInString(motd.Message), channel.MessageLengthMax())
148 | // Channel.Send handles empty messages for us already, in case motd.Message would be empty
149 | channel.Send(motd.Message)
150 | }
151 |
--------------------------------------------------------------------------------
/cmd/bot/subevent_test.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "testing"
4 |
5 | func TestPlaceholderReplacement(t *testing.T) {
6 | var testCases = []struct {
7 | format string
8 | value string
9 | login string
10 | expectedOutput string
11 | }{
12 | {
13 | "NEW GAME 👉 {value} 👉 foo bar baz",
14 | "Artifact",
15 | "forsen",
16 | ".me NEW GAME 👉 Artifact 👉 foo bar baz",
17 | },
18 | {
19 | "KKool GuitarTime {login} has gone live KKool GuitarTime",
20 | "Just Stalling",
21 | "forsen",
22 | ".me KKool GuitarTime forsen has gone live KKool GuitarTime",
23 | },
24 | {
25 | "KKool GuitarTime {login} has gone live KKool GuitarTime",
26 | "Just Stalling",
27 | "{value}",
28 | ".me KKool GuitarTime {value} has gone live KKool GuitarTime",
29 | },
30 | {
31 | "NEW GAME 👉 {value} foo",
32 | "this game has {login} in name",
33 | "zneix",
34 | ".me NEW GAME 👉 this game has {login} in name foo",
35 | },
36 | }
37 |
38 | for _, test := range testCases {
39 | if output := createMessagePrefix(test.format, test.value, test.login); output != test.expectedOutput {
40 | t.Errorf("Expected %q, but resulted in %q", test.expectedOutput, output)
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/zneix/tcb2
2 |
3 | go 1.18
4 |
5 | require (
6 | github.com/gempir/go-twitch-irc/v3 v3.0.0
7 | github.com/go-chi/chi/v5 v5.0.7
8 | github.com/nicklaw5/helix/v2 v2.4.0
9 | github.com/spf13/pflag v1.0.5
10 | github.com/spf13/viper v1.11.0
11 | go.mongodb.org/mongo-driver v1.9.0
12 | )
13 |
14 | require (
15 | github.com/fsnotify/fsnotify v1.5.1 // indirect
16 | github.com/go-stack/stack v1.8.1 // indirect
17 | github.com/golang-jwt/jwt/v4 v4.4.1 // indirect
18 | github.com/golang/snappy v0.0.4 // indirect
19 | github.com/hashicorp/hcl v1.0.0 // indirect
20 | github.com/klauspost/compress v1.15.1 // indirect
21 | github.com/magiconair/properties v1.8.6 // indirect
22 | github.com/mitchellh/mapstructure v1.4.3 // indirect
23 | github.com/pelletier/go-toml v1.9.4 // indirect
24 | github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect
25 | github.com/pkg/errors v0.9.1 // indirect
26 | github.com/spf13/afero v1.8.2 // indirect
27 | github.com/spf13/cast v1.4.1 // indirect
28 | github.com/spf13/jwalterweatherman v1.1.0 // indirect
29 | github.com/subosito/gotenv v1.2.0 // indirect
30 | github.com/xdg-go/pbkdf2 v1.0.0 // indirect
31 | github.com/xdg-go/scram v1.1.1 // indirect
32 | github.com/xdg-go/stringprep v1.0.3 // indirect
33 | github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
34 | golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
35 | golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
36 | golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
37 | golang.org/x/text v0.3.7 // indirect
38 | gopkg.in/ini.v1 v1.66.4 // indirect
39 | gopkg.in/yaml.v2 v2.4.0 // indirect
40 | gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
41 | )
42 |
--------------------------------------------------------------------------------
/go.sum:
--------------------------------------------------------------------------------
1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
2 | cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
3 | cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
4 | cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU=
5 | cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY=
6 | cloud.google.com/go v0.44.3/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY=
7 | cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc=
8 | cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0=
9 | cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To=
10 | cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4=
11 | cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M=
12 | cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc=
13 | cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk=
14 | cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs=
15 | cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc=
16 | cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY=
17 | cloud.google.com/go v0.72.0/go.mod h1:M+5Vjvlc2wnp6tjzE102Dw08nGShTscUx2nZMufOKPI=
18 | cloud.google.com/go v0.74.0/go.mod h1:VV1xSbzvo+9QJOxLDaJfTjx5e+MePCpCWwvftOeQmWk=
19 | cloud.google.com/go v0.75.0/go.mod h1:VGuuCn7PG0dwsd5XPVm2Mm3wlh3EL55/79EKB6hlPTY=
20 | cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
21 | cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE=
22 | cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc=
23 | cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg=
24 | cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc=
25 | cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ=
26 | cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
27 | cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk=
28 | cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
29 | cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw=
30 | cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA=
31 | cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU=
32 | cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
33 | cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos=
34 | cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk=
35 | cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
36 | cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
37 | cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
38 | dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
39 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
40 | github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
41 | github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
42 | github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
43 | github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
44 | github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
45 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
46 | github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
47 | github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
48 | github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
49 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
50 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
51 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
52 | github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
53 | github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
54 | github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
55 | github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
56 | github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
57 | github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
58 | github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI=
59 | github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
60 | github.com/gempir/go-twitch-irc/v3 v3.0.0 h1:e34R+9BdKy+qrO/wN+FCt+BUtyn38gCnJuKWscIKbl4=
61 | github.com/gempir/go-twitch-irc/v3 v3.0.0/go.mod h1:/W9KZIiyizVecp4PEb7kc4AlIyXKiCmvlXrzlpPUytU=
62 | github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8=
63 | github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
64 | github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
65 | github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
66 | github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
67 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
68 | github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
69 | github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
70 | github.com/golang-jwt/jwt/v4 v4.4.1 h1:pC5DB52sCeK48Wlb9oPcdhnjkz1TKt1D/P7WKJ0kUcQ=
71 | github.com/golang-jwt/jwt/v4 v4.4.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
72 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
73 | github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
74 | github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
75 | github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
76 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
77 | github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
78 | github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
79 | github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
80 | github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
81 | github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
82 | github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
83 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
84 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
85 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
86 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
87 | github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
88 | github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
89 | github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
90 | github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
91 | github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
92 | github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
93 | github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
94 | github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
95 | github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
96 | github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
97 | github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
98 | github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
99 | github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
100 | github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
101 | github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
102 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
103 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
104 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
105 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
106 | github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
107 | github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
108 | github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
109 | github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
110 | github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
111 | github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
112 | github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
113 | github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
114 | github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
115 | github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
116 | github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
117 | github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
118 | github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
119 | github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
120 | github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
121 | github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
122 | github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
123 | github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
124 | github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
125 | github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
126 | github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
127 | github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
128 | github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
129 | github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
130 | github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
131 | github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
132 | github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
133 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
134 | github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
135 | github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
136 | github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
137 | github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
138 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
139 | github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
140 | github.com/klauspost/compress v1.15.1 h1:y9FcTHGyrebwfP0ZZqFiaxTaiDnUrGkJkI+f583BL1A=
141 | github.com/klauspost/compress v1.15.1/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
142 | github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
143 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
144 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
145 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
146 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
147 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
148 | github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
149 | github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
150 | github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs=
151 | github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
152 | github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
153 | github.com/nicklaw5/helix/v2 v2.4.0 h1:ZvqCKVqza1eJYyqgTRrZ/xjDq0w/EQVFNkN067Utls0=
154 | github.com/nicklaw5/helix/v2 v2.4.0/go.mod h1:0ONzvVi1cH+k3a7EDIFNNqxfW0podhf+CqlmFvuexq8=
155 | github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM=
156 | github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
157 | github.com/pelletier/go-toml/v2 v2.0.0-beta.8 h1:dy81yyLYJDwMTifq24Oi/IslOslRrDSb3jwDggjz3Z0=
158 | github.com/pelletier/go-toml/v2 v2.0.0-beta.8/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo=
159 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
160 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
161 | github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
162 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
163 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
164 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
165 | github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
166 | github.com/spf13/afero v1.8.2 h1:xehSyVa0YnHWsJ49JFljMpg1HX19V6NDZ1fkm1Xznbo=
167 | github.com/spf13/afero v1.8.2/go.mod h1:CtAatgMJh6bJEIs48Ay/FOnkljP3WeGUG0MC1RfAqwo=
168 | github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA=
169 | github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
170 | github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
171 | github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
172 | github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
173 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
174 | github.com/spf13/viper v1.11.0 h1:7OX/1FS6n7jHD1zGrZTM7WtY13ZELRyosK4k93oPr44=
175 | github.com/spf13/viper v1.11.0/go.mod h1:djo0X/bA5+tYVoCn+C7cAYJGcVn/qYLFTG8gdUsX7Zk=
176 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
177 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
178 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
179 | github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
180 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
181 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
182 | github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
183 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
184 | github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
185 | github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
186 | github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
187 | github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
188 | github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
189 | github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
190 | github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs=
191 | github.com/xdg-go/scram v1.1.1 h1:VOMT+81stJgXW3CpHyqHN3AXDYIMsx56mEFrB37Mb/E=
192 | github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=
193 | github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM=
194 | github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs=
195 | github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
196 | github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
197 | github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqToslyjUt3VOPF4J7aK/3MPcK7xp3PDk=
198 | github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4=
199 | github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
200 | github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
201 | github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
202 | github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
203 | go.mongodb.org/mongo-driver v1.9.0 h1:f3aLGJvQmBl8d9S40IL+jEyBC6hfLPbJjv9t5hEM9ck=
204 | go.mongodb.org/mongo-driver v1.9.0/go.mod h1:0sQWfOeY63QTntERDJJ/0SuKK0T1uVSgKCuAROlKEPY=
205 | go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
206 | go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
207 | go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
208 | go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
209 | go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
210 | go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
211 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
212 | golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
213 | golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
214 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
215 | golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
216 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
217 | golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
218 | golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
219 | golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
220 | golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrbV5NY0liEs/Jg2pv5f+bBA=
221 | golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
222 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
223 | golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
224 | golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
225 | golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek=
226 | golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
227 | golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
228 | golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
229 | golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
230 | golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
231 | golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
232 | golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
233 | golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
234 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
235 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
236 | golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
237 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
238 | golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
239 | golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
240 | golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
241 | golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs=
242 | golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
243 | golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
244 | golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
245 | golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
246 | golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
247 | golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
248 | golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
249 | golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
250 | golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
251 | golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
252 | golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
253 | golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
254 | golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
255 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
256 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
257 | golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
258 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
259 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
260 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
261 | golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
262 | golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
263 | golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
264 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
265 | golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
266 | golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
267 | golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
268 | golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
269 | golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
270 | golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
271 | golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
272 | golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
273 | golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
274 | golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
275 | golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
276 | golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
277 | golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
278 | golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
279 | golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
280 | golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
281 | golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
282 | golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
283 | golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
284 | golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
285 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
286 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
287 | golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
288 | golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
289 | golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
290 | golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
291 | golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
292 | golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
293 | golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
294 | golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
295 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
296 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
297 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
298 | golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
299 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
300 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
301 | golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
302 | golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
303 | golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
304 | golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
305 | golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
306 | golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
307 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
308 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
309 | golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
310 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
311 | golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
312 | golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
313 | golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
314 | golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
315 | golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
316 | golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
317 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
318 | golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
319 | golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
320 | golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
321 | golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
322 | golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
323 | golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
324 | golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
325 | golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
326 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
327 | golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
328 | golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
329 | golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
330 | golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
331 | golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
332 | golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
333 | golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
334 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
335 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
336 | golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
337 | golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
338 | golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
339 | golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
340 | golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
341 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
342 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
343 | golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
344 | golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
345 | golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
346 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
347 | golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
348 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
349 | golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
350 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
351 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
352 | golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
353 | golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
354 | golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
355 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
356 | golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
357 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
358 | golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
359 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
360 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
361 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
362 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
363 | golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
364 | golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
365 | golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
366 | golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
367 | golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
368 | golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
369 | golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
370 | golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
371 | golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
372 | golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
373 | golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
374 | golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
375 | golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
376 | golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
377 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
378 | golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
379 | golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
380 | golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
381 | golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
382 | golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
383 | golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
384 | golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
385 | golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
386 | golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
387 | golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
388 | golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
389 | golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
390 | golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
391 | golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
392 | golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
393 | golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
394 | golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
395 | golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
396 | golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
397 | golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
398 | golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
399 | golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
400 | golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE=
401 | golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
402 | golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
403 | golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
404 | golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
405 | golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
406 | golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
407 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
408 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
409 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
410 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
411 | golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f h1:GGU+dLjvlC3qDwqYgL6UgRmHXhOOgns0bZu2Ty5mm6U=
412 | google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
413 | google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
414 | google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
415 | google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
416 | google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
417 | google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
418 | google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
419 | google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
420 | google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
421 | google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
422 | google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
423 | google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
424 | google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE=
425 | google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE=
426 | google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM=
427 | google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc=
428 | google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg=
429 | google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE=
430 | google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8=
431 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
432 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
433 | google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
434 | google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
435 | google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
436 | google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
437 | google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
438 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
439 | google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
440 | google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
441 | google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
442 | google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
443 | google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
444 | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
445 | google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8=
446 | google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
447 | google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
448 | google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
449 | google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
450 | google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
451 | google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
452 | google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA=
453 | google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
454 | google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
455 | google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
456 | google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
457 | google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
458 | google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
459 | google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
460 | google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
461 | google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U=
462 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
463 | google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA=
464 | google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
465 | google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
466 | google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
467 | google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
468 | google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
469 | google.golang.org/genproto v0.0.0-20201201144952-b05cb90ed32e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
470 | google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
471 | google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
472 | google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
473 | google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
474 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
475 | google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
476 | google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
477 | google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
478 | google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
479 | google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
480 | google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
481 | google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
482 | google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60=
483 | google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
484 | google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
485 | google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
486 | google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
487 | google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
488 | google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8=
489 | google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
490 | google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
491 | google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
492 | google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
493 | google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
494 | google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
495 | google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
496 | google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
497 | google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
498 | google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
499 | google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
500 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
501 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
502 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
503 | gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
504 | gopkg.in/ini.v1 v1.66.4 h1:SsAcf+mM7mRZo2nJNGt8mZCjG8ZRaNGMURJw7BsIST4=
505 | gopkg.in/ini.v1 v1.66.4/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
506 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
507 | gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
508 | gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
509 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
510 | gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
511 | gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
512 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
513 | honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
514 | honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
515 | honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
516 | honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
517 | honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
518 | honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
519 | rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
520 | rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
521 | rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
522 |
--------------------------------------------------------------------------------
/internal/api/routes.go:
--------------------------------------------------------------------------------
1 | package api
2 |
3 | import (
4 | "fmt"
5 | "net/http"
6 | "runtime"
7 |
8 | "github.com/zneix/tcb2/pkg/utils"
9 | )
10 |
11 | // routeIndex handles GET /
12 | func (server *Server) routeIndex(w http.ResponseWriter, r *http.Request) {
13 | w.Header().Set("Content-Type", "text/plain")
14 | _, _ = w.Write([]byte("This is the public titlechange_bot's API, most of the endpoints however are (and will be) undocumented ThreeLetterAPI TeaTime\nMore information on the GitHub repo: https://github.com/zneix/tcb2\n"))
15 | }
16 |
17 | // routeHealth handles GET /health
18 | func (server *Server) routeHealth(w http.ResponseWriter, r *http.Request) {
19 | var m runtime.MemStats
20 | runtime.ReadMemStats(&m)
21 |
22 | memory := fmt.Sprintf("Alloc=%v MiB, TotalAlloc=%v MiB, Sys=%v MiB, NumGC=%v",
23 | m.Alloc/1024/1024,
24 | m.TotalAlloc/1024/1024,
25 | m.Sys/1024/1024,
26 | m.NumGC)
27 |
28 | // _, _ = w.Write([]byte(fmt.Sprintf("API Uptime: %s\nMemory: %s\n", utils.TimeSince(server.startTime), memory)))
29 | fmt.Fprintf(w, "API Uptime: %s\nMemory: %s\n", utils.TimeSince(server.startTime), memory)
30 | }
31 |
32 | func registerMainRoutes(server *Server) {
33 | server.Router.Get("/", server.routeIndex)
34 | server.Router.Get("/health", server.routeHealth)
35 | }
36 |
--------------------------------------------------------------------------------
/internal/api/server.go:
--------------------------------------------------------------------------------
1 | package api
2 |
3 | import (
4 | "log"
5 | "net/http"
6 | "net/url"
7 | "time"
8 |
9 | "github.com/go-chi/chi/v5"
10 | "github.com/go-chi/chi/v5/middleware"
11 | "github.com/zneix/tcb2/internal/config"
12 | )
13 |
14 | type Server struct {
15 | // Router ...
16 | Router *chi.Mux
17 |
18 | // BaseURL ...
19 | BaseURL string
20 |
21 | // bindAddress on which the HTTP server will listen on
22 | bindAddress string
23 |
24 | // listenPrefix ...
25 | listenPrefix string
26 |
27 | startTime time.Time
28 | }
29 |
30 | // mountRouter tries to figure out listenPrefix from server.BaseURL
31 | func mountRouter(server *Server) *chi.Mux {
32 | if server.BaseURL == "" {
33 | return server.Router
34 | }
35 |
36 | u, err := url.Parse(server.BaseURL)
37 | if err != nil {
38 | log.Fatalln("[API] Error mounting router: ", err)
39 | }
40 | if u.Scheme != "http" && u.Scheme != "https" {
41 | log.Fatalln("[API] Scheme must be included in Base URL")
42 | }
43 |
44 | if u.Path != "" {
45 | server.listenPrefix = u.Path
46 | }
47 | ur := chi.NewRouter()
48 | ur.Mount(server.listenPrefix, server.Router)
49 | server.Router = ur
50 |
51 | return ur
52 | }
53 |
54 | // Listen starts to listen on configured bindAddress (blocking)
55 | func (server *Server) Listen() {
56 | srv := &http.Server{
57 | Handler: mountRouter(server),
58 | Addr: server.bindAddress,
59 | WriteTimeout: 15 * time.Second,
60 | ReadTimeout: 15 * time.Second,
61 | }
62 |
63 | log.Printf("[API] Listening on %q (Prefix=%s, BaseURL=%s)\n", server.bindAddress, server.listenPrefix, server.BaseURL)
64 | log.Fatal(srv.ListenAndServe())
65 | }
66 |
67 | func New(cfg *config.TCBConfig) *Server {
68 | router := chi.NewRouter()
69 |
70 | // Strip trailing slashes from API requests
71 | router.Use(middleware.StripSlashes)
72 |
73 | server := &Server{
74 | Router: router,
75 | BaseURL: cfg.BaseURL,
76 | bindAddress: cfg.BindAddress,
77 | listenPrefix: "/",
78 | startTime: time.Now(),
79 | }
80 |
81 | // Handle routes
82 | registerMainRoutes(server)
83 |
84 | return server
85 | }
86 |
--------------------------------------------------------------------------------
/internal/bot/channel.go:
--------------------------------------------------------------------------------
1 | package bot
2 |
3 | import (
4 | "context"
5 | "fmt"
6 | "log"
7 | "time"
8 |
9 | "github.com/gempir/go-twitch-irc/v3"
10 | "github.com/zneix/tcb2/internal/mongo"
11 | "github.com/zneix/tcb2/pkg/utils"
12 | "go.mongodb.org/mongo-driver/bson"
13 | )
14 |
15 | type Channel struct {
16 | ID string `bson:"id"`
17 | Login string `bson:"login"`
18 |
19 | DisabledCommands []string `bson:"disabled_commands"`
20 | Events map[SubEventType]string `bson:"events"`
21 | PajbotAPI *PajbotAPI `bson:"pajbot_api"`
22 | MessageLengthLimit int `bson:"message_length_limit"`
23 | WhisperCommands bool `bson:"whisper_commands"`
24 | EventsOnlyOffline bool `bson:"events_only_offline"`
25 | Mode ChannelMode `bson:"mode"`
26 |
27 | CurrentTitle string `bson:"-"`
28 | CurrentGame string `bson:"-"`
29 | IsLive bool `bson:"-"`
30 | LastMsg string `bson:"-"`
31 | QueueChannel chan *QueueMessage `bson:"-"`
32 | }
33 |
34 | func (channel *Channel) String() string {
35 | return fmt.Sprintf("#%s(%s)", channel.Login, channel.ID)
36 | }
37 |
38 | func (channel *Channel) StartMessageQueue(twitchIRC *twitch.Client) {
39 | // log.Println("Starting message queue for", channel)
40 | defer log.Println("[Channel] Message queue suddenly quit(?) for", channel)
41 |
42 | for message := range channel.QueueChannel {
43 | // Actually send the message to the chat
44 | twitchIRC.Say(channel.Login, message.Message)
45 |
46 | // Update last sent message
47 | channel.LastMsg = message.Message
48 |
49 | // Wait for the cooldown
50 | time.Sleep(channel.Mode.MessageRatelimit())
51 | }
52 | }
53 |
54 | // Sends a message to the channel while taking care of ratelimits
55 | func (channel *Channel) Send(message string) {
56 | // Don't attempt to send an empty message
57 | if message == "" {
58 | return
59 | }
60 |
61 | // TODO: Restrict usage of some commands, e.g. .ban, .timeout, .clear
62 |
63 | // limitting message length to not get it dropped
64 | message = utils.LimitString(message, channel.MessageLengthMax())
65 |
66 | // Append magic character at the end of the message if it's a duplicate
67 | if channel.LastMsg == message {
68 | message += " \U000E0000"
69 | }
70 |
71 | // Send message object to the message queue sending messages in ratelimit
72 | channel.QueueChannel <- &QueueMessage{
73 | Message: message,
74 | }
75 | }
76 |
77 | // Sendf formats according to a format specifier and runs channel.Send with the resulting string
78 | func (channel *Channel) Sendf(format string, a ...interface{}) {
79 | channel.Send(fmt.Sprintf(format, a...))
80 | }
81 |
82 | func (channel *Channel) MessageLengthMax() int {
83 | if channel.MessageLengthLimit > 0 {
84 | return channel.MessageLengthLimit
85 | }
86 |
87 | if channel.Mode == ChannelModeModerator {
88 | // Leaving 2 characters for the magic character
89 | return 498
90 | }
91 | // TODO: Investigate the actual limit for "pleb" modes (?)
92 | // mm2pl: maybe it's something like max of count(CHAR) / len(msg) for each unique character used in a message
93 | // mm2pl: or maybe it's some kind of GOW average
94 | // mm2pl: max((msg.count(ch) / len(msg) for ch in set(msg))) seems like a good approximation
95 | // For now I'm lazy and just gonna hardcode some reasonable value in here
96 | return 468
97 | }
98 |
99 | func (channel *Channel) ChangeMode(mongoConn *mongo.Connection, newMode ChannelMode) (err error) {
100 | log.Printf("[Mongo] Changing mode in %s from %v to %v", channel, channel.Mode, newMode)
101 | channel.Mode = newMode
102 |
103 | // Update mode in the database as well
104 | _, err = mongoConn.Collection(mongo.CollectionNameChannels).UpdateOne(context.TODO(), bson.M{
105 | "id": channel.ID,
106 | }, bson.M{
107 | "$set": bson.M{
108 | "mode": newMode,
109 | },
110 | })
111 |
112 | if err != nil {
113 | log.Printf("[Mongo] Error updating ChannelMode for %s: %s\n", channel, err)
114 | }
115 | return
116 | }
117 |
--------------------------------------------------------------------------------
/internal/bot/command.go:
--------------------------------------------------------------------------------
1 | package bot
2 |
3 | import (
4 | "strings"
5 | "time"
6 |
7 | "github.com/gempir/go-twitch-irc/v3"
8 | )
9 |
10 | type Command struct {
11 | Name string
12 | Aliases []string
13 | Description string
14 | Usage string
15 | Run func(msg twitch.PrivateMessage, args []string)
16 |
17 | CooldownChannel time.Duration
18 | CooldownUser time.Duration
19 |
20 | // TODO: Perhaps cooldown logic should be stored in Bot / redis (?)
21 | LastExecutionChannel map[string]time.Time
22 | LastExecutionUser map[string]time.Time
23 | }
24 |
25 | func (c *Command) String() string {
26 | str := c.Name
27 | if c.Usage != "" {
28 | str += " " + c.Usage
29 | }
30 | return str
31 | }
32 |
33 | type CommandController struct {
34 | Commands map[string]*Command
35 | aliases map[string]string
36 | Prefix string
37 | }
38 |
39 | func (c *CommandController) GetCommand(alias string) (*Command, bool) {
40 | name, ok := c.aliases[strings.ToLower(alias)]
41 | if !ok {
42 | return nil, false
43 | }
44 |
45 | cmd, ok := c.Commands[name]
46 | return cmd, ok
47 | }
48 |
49 | func (c *CommandController) RegisterCommand(cmd *Command) {
50 | cmd.LastExecutionChannel = make(map[string]time.Time)
51 | cmd.LastExecutionUser = make(map[string]time.Time)
52 |
53 | c.Commands[cmd.Name] = cmd
54 |
55 | c.aliases[cmd.Name] = cmd.Name
56 | for _, alias := range cmd.Aliases {
57 | c.aliases[alias] = cmd.Name
58 | }
59 | }
60 |
61 | func NewCommandController(prefix string) *CommandController {
62 | return &CommandController{
63 | Commands: make(map[string]*Command),
64 | aliases: make(map[string]string),
65 | Prefix: prefix,
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/internal/bot/types.go:
--------------------------------------------------------------------------------
1 | package bot
2 |
3 | import (
4 | "fmt"
5 | "time"
6 |
7 | "github.com/gempir/go-twitch-irc/v3"
8 | "github.com/nicklaw5/helix/v2"
9 | "github.com/zneix/tcb2/internal/eventsub"
10 | "github.com/zneix/tcb2/internal/mongo"
11 | )
12 |
13 | // types
14 | // TODO: Restructure this and split types to their separate types
15 |
16 | // Self contains properties related to bot's user account
17 | type Self struct {
18 | Login string
19 | OAuth string
20 | }
21 |
22 | type Bot struct {
23 | TwitchIRC *twitch.Client
24 | Mongo *mongo.Connection
25 | Helix *helix.Client
26 | EventSub *eventsub.EventSub
27 |
28 | Logins map[string]string
29 | Channels map[string]*Channel
30 | Commands *CommandController
31 |
32 | Self *Self
33 | StartTime time.Time
34 | }
35 |
36 | type PajbotAPI struct {
37 | Mode PajbotAPIMode `bson:"mode"`
38 | Domain string `bson:"domain"`
39 | }
40 |
41 | // SubEventMOTD if present for a channel with the corresponding ChannelID, should be posted right after announcing channel going live
42 | // It could be useful to remind streamer to tweet or announce going live on Discord
43 | type SubEventMOTD struct {
44 | ChannelID string `bson:"channel_id"`
45 | Message string `bson:"message"`
46 | }
47 |
48 | type SubEventSubscription struct {
49 | UserLogin string `bson:"user_login"`
50 | UserID string `bson:"user_id"`
51 | Event SubEventType `bson:"event"`
52 | Value string `bson:"value"`
53 | }
54 |
55 | type SubEventMessage struct {
56 | Bot *Bot
57 | ChannelID string
58 | Type SubEventType
59 | }
60 |
61 | type QueueMessage struct {
62 | Message string
63 | }
64 |
65 | // enums
66 |
67 | //
68 | // ChannelMode indicates the bot's state in a Channel
69 | type ChannelMode int
70 |
71 | const (
72 | // ChannelModeNormal default ChannelMode with regular ratelimits
73 | ChannelModeNormal ChannelMode = iota
74 | // ChannelModeInactive bot has been disabled in that chat
75 | ChannelModeInactive
76 | // ChannelModeModerator bot has elevated ratelimits with moderation permissions
77 | ChannelModeModerator
78 | // ChannelModeVIP bot has elevated ratelimits without moderation permissions
79 | // Note: we don't need this, but maybe it can be useful in the future
80 | // ChannelModeVIP
81 |
82 | // ChannelModeEnumBoundary marks the end of enumeration
83 | ChannelModeEnumBoundary
84 | )
85 |
86 | // MessageRatelimit the minimum time.Duration that must pass between sending messages in the Channel
87 | func (mode ChannelMode) MessageRatelimit() time.Duration {
88 | if mode == ChannelModeModerator {
89 | return 100 * time.Millisecond
90 | }
91 | // 1200ms is minimum, but 1650ms prevents exceeding global limits
92 | return 1650 * time.Millisecond
93 | }
94 |
95 | //
96 | // PajbotAPIMode indicates bot's behavior regarding banphrase checks in channels that have pajbot API configured
97 | type PajbotAPIMode int
98 |
99 | const (
100 | // PajbotAPIModeDisabled even if the Domain link is set, API will be totally ignored
101 | PajbotAPIModeDisabled PajbotAPIMode = iota
102 | // PajbotAPIModeEnabled will attempt to sanitize potentially harmful message content
103 | PajbotAPIModeEnabled
104 | )
105 |
106 | //
107 | // SubEventType defines event to which users can subscribe
108 | type SubEventType int
109 |
110 | const (
111 | // SubEventTypeGame game (category) has been updated
112 | // Received in EventSub's "channel.update"
113 | SubEventTypeGame SubEventType = iota
114 | // SubEventTypeTitle title has been updated
115 | // Received in EventSub's "channel.update"
116 | SubEventTypeTitle
117 | // SubEventTypeLive channel has gone live
118 | // Received in EventSub's "stream.online"
119 | SubEventTypeLive
120 | // EventLive channel has gone offline
121 | // Received in EventSub's "stream.offline"
122 | SubEventTypeOffline
123 | // SubEventTypePartnered broadcaster has become partnered
124 | // This is deprecated and is kept in case legacy subscriptions with this value are found
125 | SubEventTypePartnered
126 |
127 | // SubEventTypeInvalid represents an invalid event type that was passed to ParseChannelEvent
128 | SubEventTypeInvalid
129 | )
130 |
131 | func (e SubEventType) String() string {
132 | switch e {
133 | case SubEventTypeGame:
134 | return "game"
135 | case SubEventTypeTitle:
136 | return "title"
137 | case SubEventTypeLive:
138 | return "live"
139 | case SubEventTypeOffline:
140 | return "offline"
141 | case SubEventTypePartnered:
142 | return "partnered"
143 | default:
144 | return fmt.Sprintf("invalid(%d)", int(e))
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/internal/bot/utils.go:
--------------------------------------------------------------------------------
1 | package bot
2 |
3 | // ParseSubEventType attempts to convert value to a ChannelEvent event
4 | func ParseSubEventType(value string) (valid bool, event SubEventType) {
5 | switch value {
6 | case "game":
7 | return true, SubEventTypeGame
8 | case "title":
9 | return true, SubEventTypeTitle
10 | case "live":
11 | return true, SubEventTypeLive
12 | case "offline":
13 | return true, SubEventTypeOffline
14 | // case "partnered":
15 | // return true, SubEventTypePartnered
16 | default:
17 | return false, SubEventTypeInvalid
18 | }
19 | }
20 |
21 | // SubEventDescriptions slice with all currently supported events, indexed by the values of SubEventType
22 | // allowing to cast the index of a string in the slice to a corresponding SubEventType value
23 | var SubEventDescriptions = []string{
24 | "game changes", // SubEventTypeGame
25 | "title changes", // SubEventTypeTitle
26 | "streamer goes live", // SubEventTypeLive
27 | "streamer goes offline", // SubEventTypeOffline
28 | }
29 |
--------------------------------------------------------------------------------
/internal/commands/bot.go:
--------------------------------------------------------------------------------
1 | package commands
2 |
3 | import (
4 | "time"
5 |
6 | "github.com/gempir/go-twitch-irc/v3"
7 | "github.com/zneix/tcb2/internal/bot"
8 | )
9 |
10 | func Bot(tcb *bot.Bot) *bot.Command {
11 | return &bot.Command{
12 | Name: "bot",
13 | Aliases: []string{"tcb", "about", "titlechangebot", "titlechange_bot"},
14 | Description: "Returns basic information about the bot",
15 | Usage: "",
16 | CooldownChannel: 3 * time.Second,
17 | CooldownUser: 5 * time.Second,
18 | Run: func(msg twitch.PrivateMessage, args []string) {
19 | channel := tcb.Channels[msg.RoomID]
20 | channel.Sendf("@%s, I am a bot created by zneix. I can notify you when the channel goes live or the title changes. Try %shelp for a list of commands. pajaDank", msg.User.Name, tcb.Commands.Prefix)
21 | },
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/internal/commands/events.go:
--------------------------------------------------------------------------------
1 | package commands
2 |
3 | import (
4 | "fmt"
5 | "strings"
6 | "time"
7 |
8 | "github.com/gempir/go-twitch-irc/v3"
9 | "github.com/zneix/tcb2/internal/bot"
10 | )
11 |
12 | func Events(tcb *bot.Bot) *bot.Command {
13 | return &bot.Command{
14 | Name: "events",
15 | Aliases: []string{"tcbevents"},
16 | Description: "Shows available events you can subscribe to with a brief description",
17 | Usage: "",
18 | CooldownChannel: 3 * time.Second,
19 | CooldownUser: 5 * time.Second,
20 | Run: func(msg twitch.PrivateMessage, args []string) {
21 | channel := tcb.Channels[msg.RoomID]
22 |
23 | eventStrings := []string{}
24 | for i, desc := range bot.SubEventDescriptions {
25 | eventStrings = append(eventStrings, fmt.Sprintf("%s (%s)", bot.SubEventType(i), desc))
26 | }
27 |
28 | channel.Sendf("@%s, available events: %s. Use \"%snotifyme [optional value]\" to subscribe to an event!", msg.User.Name, strings.Join(eventStrings, ", "), tcb.Commands.Prefix)
29 | },
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/internal/commands/game.go:
--------------------------------------------------------------------------------
1 | package commands
2 |
3 | import (
4 | "time"
5 |
6 | "github.com/gempir/go-twitch-irc/v3"
7 | "github.com/zneix/tcb2/internal/bot"
8 | )
9 |
10 | func Game(tcb *bot.Bot) *bot.Command {
11 | return &bot.Command{
12 | Name: "game",
13 | Aliases: []string{"currentgame"},
14 | Description: "Returns current game",
15 | Usage: "",
16 | CooldownChannel: 3 * time.Second,
17 | CooldownUser: 5 * time.Second,
18 | Run: func(msg twitch.PrivateMessage, args []string) {
19 | channel := tcb.Channels[msg.RoomID]
20 | channel.Sendf("@%s, current game: %s", msg.User.Name, channel.CurrentGame)
21 | },
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/internal/commands/help.go:
--------------------------------------------------------------------------------
1 | package commands
2 |
3 | import (
4 | "strings"
5 | "time"
6 |
7 | "github.com/gempir/go-twitch-irc/v3"
8 | "github.com/zneix/tcb2/internal/bot"
9 | )
10 |
11 | func Help(tcb *bot.Bot) *bot.Command {
12 | return &bot.Command{
13 | Name: "help",
14 | Aliases: []string{
15 | "tcbhelp",
16 | "tcb_help",
17 | "titlechangebothelp",
18 | "titlechange_bothelp",
19 | "titlechangebot_help",
20 | "titlechange_bot_help",
21 | },
22 | Description: "Posts a short list of commands or details about specified command",
23 | Usage: "[command]",
24 | CooldownChannel: 100 * time.Millisecond,
25 | CooldownUser: 2 * time.Second,
26 | Run: func(msg twitch.PrivateMessage, args []string) {
27 | channel := tcb.Channels[msg.RoomID]
28 | // Generic help
29 | if len(args) < 1 {
30 | cmdStrings := make([]string, 0, len(tcb.Commands.Commands))
31 |
32 | for _, cmd := range tcb.Commands.Commands {
33 | cmdStrings = append(cmdStrings, tcb.Commands.Prefix+cmd.String())
34 | }
35 |
36 | channel.Sendf("@%s, available commands: %s", msg.User.Name, strings.Join(cmdStrings, ", "))
37 | return
38 | }
39 |
40 | // Dynamic help
41 | cmd, exists := tcb.Commands.GetCommand(args[0])
42 | if !exists {
43 | channel.Sendf("@%s, provided command is either hidden or doesn't exist BrokeBack", msg.User.Name)
44 | return
45 | }
46 | description := strings.ReplaceAll(cmd.Description, "{prefix}", tcb.Commands.Prefix)
47 | channel.Sendf("@%s, %s%s (%s cooldown): %s", msg.User.Name, tcb.Commands.Prefix, cmd, cmd.CooldownUser, description)
48 | },
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/internal/commands/islive.go:
--------------------------------------------------------------------------------
1 | package commands
2 |
3 | import (
4 | "time"
5 |
6 | "github.com/gempir/go-twitch-irc/v3"
7 | "github.com/zneix/tcb2/internal/bot"
8 | )
9 |
10 | func IsLive(tcb *bot.Bot) *bot.Command {
11 | return &bot.Command{
12 | Name: "islive",
13 | Aliases: []string{"tcbislive"},
14 | Description: "Shows you if the channel is live or not",
15 | Usage: "",
16 | CooldownChannel: 3 * time.Second,
17 | CooldownUser: 5 * time.Second,
18 | Run: func(msg twitch.PrivateMessage, args []string) {
19 | channel := tcb.Channels[msg.RoomID]
20 |
21 | var isLive = channel.IsLive
22 | if len(args) >= 1 {
23 | targetID, ok := tcb.Logins[args[0]]
24 | if !ok {
25 | channel.Send("I don't track the status of the target channel")
26 | return
27 | }
28 | isLive = tcb.Channels[targetID].IsLive
29 | }
30 | var message string
31 | if isLive {
32 | message = "Target channel is live KKona GuitarTime"
33 | } else {
34 | message = "Target channel is offline FeelsBadMan TeaTime"
35 | }
36 | channel.Send(message)
37 | },
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/internal/commands/migrate_channels.go:
--------------------------------------------------------------------------------
1 | package commands
2 |
3 | import (
4 | "time"
5 |
6 | "github.com/gempir/go-twitch-irc/v3"
7 | "github.com/zneix/tcb2/internal/bot"
8 | )
9 |
10 | func MigrateChannels(tcb *bot.Bot) *bot.Command {
11 | return &bot.Command{
12 | Name: "migrate_channels",
13 | Aliases: []string{},
14 | Description: "Migration command, admin use only",
15 | Usage: "",
16 | CooldownChannel: 3 * time.Second,
17 | CooldownUser: 5 * time.Second,
18 | Run: func(msg twitch.PrivateMessage, args []string) {
19 | if msg.User.Name != "zneix" {
20 | return
21 | }
22 |
23 | // channel := tcb.Channels[msg.RoomID]
24 | },
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/internal/commands/migrate_subscriptions.go:
--------------------------------------------------------------------------------
1 | package commands
2 |
3 | import (
4 | "context"
5 | "log"
6 | "time"
7 |
8 | "github.com/gempir/go-twitch-irc/v3"
9 | "github.com/nicklaw5/helix/v2"
10 | "github.com/zneix/tcb2/internal/bot"
11 | "github.com/zneix/tcb2/internal/mongo"
12 | "go.mongodb.org/mongo-driver/bson"
13 | )
14 |
15 | type SubEventSubscriptionOld struct {
16 | Channel string `bson:"channel"`
17 | User string `bson:"user"`
18 | Event string `bson:"event"`
19 | Value string `bson:"requiredValue"`
20 | }
21 |
22 | func MigrateSubscriptions(tcb *bot.Bot) *bot.Command {
23 | return &bot.Command{
24 | Name: "migrate_subscriptions",
25 | Aliases: []string{},
26 | Description: "Migration command, admin use only",
27 | Usage: "",
28 | CooldownChannel: 3 * time.Second,
29 | CooldownUser: 5 * time.Second,
30 | Run: func(msg twitch.PrivateMessage, args []string) {
31 | if msg.User.Name != "zneix" {
32 | return
33 | }
34 |
35 | channel := tcb.Channels[msg.RoomID]
36 |
37 | // Helix username cache: User Login -> User ID
38 | xd := make(map[string]string)
39 | errCount := 0
40 |
41 | // Iterate over all channels and perform migrations for these
42 | channel.Sendf("Attempting to migrate subscriptions for %d channels", len(tcb.Channels))
43 | for _, c := range tcb.Channels {
44 | channel.Sendf("Migrating subscriptions for %s", c)
45 |
46 | cur, err := tcb.Mongo.Collection(mongo.CollectionNameOldSubscriptions).Find(context.Background(), bson.M{
47 | "channel": c.Login,
48 | })
49 | if err != nil {
50 | errCount++
51 | log.Printf("[Mongo] Error querying old subscriptions for %s: %s\n", c, err)
52 | channel.Sendf("Failed to migrate subscriptions for %s: %s", c, err)
53 | continue
54 | }
55 |
56 | for cur.Next(context.TODO()) {
57 | // Deserialize old subscription data
58 | var subOld *SubEventSubscriptionOld
59 | err = cur.Decode(&subOld)
60 | if err != nil {
61 | errCount++
62 | log.Println("[Mongo] Malformed old subscription document: " + err.Error())
63 | continue
64 | }
65 |
66 | userID, ok := xd[subOld.User]
67 | if !ok {
68 | // When the userID wasn't found in cache, query helix for it
69 | log.Printf("[Helix] Querying %s\n", subOld.User)
70 | res, err := tcb.Helix.GetUsers(&helix.UsersParams{
71 | Logins: []string{subOld.User},
72 | })
73 | if err != nil {
74 | errCount++
75 | log.Printf("[Helix] Failed to query user %s: %s\n", subOld.User, err)
76 | channel.Sendf("Failed to query user %s: %s", subOld.User, err)
77 | continue
78 | }
79 |
80 | if len(res.Data.Users) != 1 {
81 | log.Printf("User %s is banned\n", subOld.User)
82 | userID = "banned"
83 | } else {
84 | userID = res.Data.Users[0].ID
85 | }
86 | xd[subOld.User] = userID
87 | }
88 |
89 | valid, event := bot.ParseSubEventType(subOld.Event)
90 | if !valid {
91 | errCount++
92 | log.Printf("Invalid event on old subscription: %# v\n", subOld)
93 | continue
94 | }
95 | subNew := &bot.SubEventSubscription{
96 | UserLogin: subOld.User,
97 | UserID: userID,
98 | Event: event,
99 | Value: subOld.Value,
100 | }
101 | resIns, err := tcb.Mongo.CollectionSubs(c.ID).InsertOne(context.TODO(), *subNew)
102 | if err != nil {
103 | errCount++
104 | log.Printf("[Mongo] Error inserting new subscription %s; %# v\n", err, subNew)
105 | continue
106 | }
107 | log.Printf("[Mongo] Inserted new subscription %# v; ID: %v\n", subNew, resIns.InsertedID)
108 | }
109 | }
110 | channel.Sendf("Finished migrating subscriptions for all %d channels KKona encountered %d errors @zneix", len(tcb.Channels), errCount)
111 | },
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/internal/commands/notifyme.go:
--------------------------------------------------------------------------------
1 | package commands
2 |
3 | import (
4 | "context"
5 | "fmt"
6 | "log"
7 | "strings"
8 | "time"
9 |
10 | "github.com/gempir/go-twitch-irc/v3"
11 | "github.com/zneix/tcb2/internal/bot"
12 | "go.mongodb.org/mongo-driver/bson"
13 | "go.mongodb.org/mongo-driver/mongo"
14 | )
15 |
16 | func NotifyMe(tcb *bot.Bot) *bot.Command {
17 | return &bot.Command{
18 | Name: "notifyme",
19 | Aliases: []string{"tcbnotifyme"},
20 | Description: "Subscribe to an event. Optional value can be only used with title and game events. For list of available events use: \"{prefix}events\". You can use \"{prefix}notifyme all\" to subscribe to all events at once!",
21 | Usage: " [optional value]",
22 | CooldownChannel: 100 * time.Millisecond,
23 | CooldownUser: 3 * time.Second,
24 | Run: func(msg twitch.PrivateMessage, args []string) {
25 | channel := tcb.Channels[msg.RoomID]
26 | ctx := context.TODO()
27 |
28 | eventStrings := make([]string, 0, len(bot.SubEventDescriptions))
29 | for i, desc := range bot.SubEventDescriptions {
30 | eventStrings = append(eventStrings, fmt.Sprintf("%s (%s)", bot.SubEventType(i), desc))
31 | }
32 | availableEvents := strings.Join(eventStrings, ", ")
33 |
34 | // No arguments, return an error message
35 | if len(args) < 1 {
36 | channel.Sendf("@%s, you must specify an event to subscribe to. Available events: %s", msg.User.Name, availableEvents)
37 | return
38 | }
39 |
40 | // Special case - subscribe to all the events
41 | if strings.EqualFold(args[0], "all") {
42 | // Unsubscribe the user from any events that they could've been subscribed to before
43 | resDel, err := tcb.Mongo.CollectionSubs(msg.RoomID).DeleteMany(ctx, bson.M{
44 | "user_id": msg.User.ID,
45 | })
46 | if err != nil {
47 | log.Println("[Mongo] Failed deleting subscriptions:", err)
48 | channel.Sendf("@%s, internal server error occured while trying to delete your old subscriptions monkaS @zneix", msg.User.Name)
49 | return
50 | }
51 | log.Printf("[Mongo] Deleted %d subscription(s) for %# v(%s) in %s", resDel.DeletedCount, msg.User.Name, msg.User.ID, channel)
52 |
53 | // Now add subscriptions to all supported events
54 | allEvents := make([]interface{}, 0, len(bot.SubEventDescriptions))
55 | for subEventIndex := range bot.SubEventDescriptions {
56 | allEvents = append(allEvents, &bot.SubEventSubscription{
57 | UserLogin: msg.User.Name,
58 | UserID: msg.User.ID,
59 | Event: bot.SubEventType(subEventIndex),
60 | Value: "",
61 | })
62 | }
63 | resIns, err := tcb.Mongo.CollectionSubs(msg.RoomID).InsertMany(ctx, allEvents)
64 | if err != nil {
65 | log.Println("[Mongo] Failed adding new subscriptions for all events:", err)
66 | channel.Sendf("@%s, internal server error occured while trying to add your new subscriptions monkaS @zneix", msg.User.Name)
67 | return
68 | }
69 | log.Printf("[Mongo] Added %d subscriptions for %# v(%s) in %s, ID: %v", len(resIns.InsertedIDs), msg.User.Name, msg.User.ID, channel, resIns.InsertedIDs)
70 |
71 | // Inform the user about actions taken
72 | channel.Sendf("@%s, I will now ping you for all events in this channel: %s", msg.User.Name, availableEvents)
73 | return
74 | }
75 |
76 | // Parse sub event type passed as the first argument
77 | valid, event := bot.ParseSubEventType(strings.ToLower(args[0]))
78 | if !valid {
79 | channel.Sendf("@%s, given event name is not valid. Available events: %s", msg.User.Name, availableEvents)
80 | return
81 | }
82 |
83 | // Determine the optional value
84 | value := strings.Join(args[1:], " ")
85 | if event != bot.SubEventTypeGame && event != bot.SubEventTypeTitle {
86 | value = ""
87 | }
88 |
89 | // Find user's subscriptions in this chat for the specified event
90 | cur, err := tcb.Mongo.CollectionSubs(msg.RoomID).Find(ctx, bson.M{
91 | "user_id": msg.User.ID,
92 | "event": event,
93 | })
94 | if err != nil {
95 | log.Println("[Mongo] Failed querying subscription:", err)
96 | return
97 | }
98 |
99 | hasThisSub := false
100 | hasThisSubAllValues := false
101 | hasThisSubWithThisValue := false
102 | var deletedSubCount int
103 |
104 | // Deserialize subscription data
105 | for cur.Next(ctx) {
106 | var sub *bot.SubEventSubscription
107 | err = cur.Decode(&sub)
108 | if err != nil {
109 | log.Println("[Mongo] Malformed subscription document:", err)
110 | continue
111 | }
112 |
113 | if sub.Event != event {
114 | continue
115 | }
116 |
117 | hasThisSub = true
118 | if sub.Value == "" {
119 | hasThisSubAllValues = true
120 | }
121 | if strings.EqualFold(sub.Value, value) {
122 | hasThisSubWithThisValue = true
123 | }
124 | }
125 |
126 | // User already has a subscription with the exact value
127 | // inform them about it and how can they unsubscribe
128 | if hasThisSubWithThisValue {
129 | reply := fmt.Sprintf("@%s, you already have a subscription to the event %s", msg.User.Name, event)
130 | if len(value) > 0 {
131 | reply += " with the provided value FeelsDankMan .."
132 | }
133 |
134 | channel.Sendf("%s. If you want to unsubscribe, use: %sremoveme %s", reply, tcb.Commands.Prefix, event)
135 | return
136 | }
137 |
138 | // User has a subscription for this event for all values
139 | if hasThisSubAllValues && len(value) > 0 {
140 | channel.Sendf("@%s, you already have a subscription for event %s that matches all values. If you want to be pinged only on specific values, use \"%sremoveme %s\" first before running this command again", msg.User.Name, event, tcb.Commands.Prefix, event)
141 | return
142 | }
143 |
144 | // User has subscription(s) for this event, but requests a subscription for all values
145 | // We want to delete all other subscriptions for this event for this user first
146 | if hasThisSub && len(value) < 1 {
147 | var res *mongo.DeleteResult
148 | res, err = tcb.Mongo.CollectionSubs(msg.RoomID).DeleteMany(ctx, bson.M{
149 | "user_id": msg.User.ID,
150 | "event": event,
151 | })
152 | if err != nil {
153 | log.Println("[Mongo] Failed deleting subscriptions:", err)
154 | channel.Sendf("@%s, internal server error occured while trying to delete your old subscriptions monkaS @zneix", msg.User.Name)
155 | return
156 | }
157 | deletedSubCount = int(res.DeletedCount)
158 | log.Printf("[Mongo] Deleted %d subscription(s) for %# v(%s) in %s", res.DeletedCount, msg.User.Name, msg.User.ID, channel)
159 | }
160 |
161 | // Add requested subscription
162 | res, err := tcb.Mongo.CollectionSubs(msg.RoomID).InsertOne(ctx, bot.SubEventSubscription{
163 | UserID: msg.User.ID,
164 | UserLogin: msg.User.Name,
165 | Event: event,
166 | Value: value,
167 | })
168 | if err != nil {
169 | log.Println("[Mongo] Failed adding new subscription:", err)
170 | channel.Sendf("@%s, internal server error occured while trying to add your new subscription monkaS @zneix", msg.User.Name)
171 | return
172 | }
173 | log.Printf("[Mongo] Added 1 subscription for %s(%s) in %s, ID: %v", msg.User.Name, msg.User.ID, channel, res.InsertedID)
174 |
175 | var givenValue string
176 | if len(value) > 0 {
177 | givenValue = fmt.Sprintf(", but only when the %s contains provided value", event)
178 | }
179 | reply := fmt.Sprintf("@%s, I will now ping you when the %s%s!", msg.User.Name, bot.SubEventDescriptions[event], givenValue)
180 | if hasThisSub && len(value) < 1 {
181 | // We had to remove all other subscriptions for this event and add a new one
182 | reply += fmt.Sprintf(" You previously had %d subscription(s) for this event that were set to only match specific values. These subscriptions have been removed and you will now be notified regardless of the value SeemsGood", deletedSubCount)
183 | }
184 |
185 | // Return the final message to the user
186 | channel.Send(reply)
187 | },
188 | }
189 | }
190 |
--------------------------------------------------------------------------------
/internal/commands/ping.go:
--------------------------------------------------------------------------------
1 | package commands
2 |
3 | import (
4 | "time"
5 |
6 | "github.com/gempir/go-twitch-irc/v3"
7 | "github.com/zneix/tcb2/internal/bot"
8 | "github.com/zneix/tcb2/internal/common"
9 | )
10 |
11 | func Ping(tcb *bot.Bot) *bot.Command {
12 | return &bot.Command{
13 | Name: "ping",
14 | Aliases: []string{"tcbping"},
15 | Description: "Pings the bot to see if it's online",
16 | Usage: "",
17 | CooldownChannel: 1 * time.Second,
18 | CooldownUser: 2 * time.Second,
19 | Run: func(msg twitch.PrivateMessage, args []string) {
20 | channel := tcb.Channels[msg.RoomID]
21 | channel.Sendf("@%s, reporting for duty MrDestructoid PowerUpR 🔔 %s", msg.User.Name, common.Version())
22 | },
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/internal/commands/removeme.go:
--------------------------------------------------------------------------------
1 | package commands
2 |
3 | import (
4 | "context"
5 | "fmt"
6 | "log"
7 | "strings"
8 | "time"
9 |
10 | "github.com/gempir/go-twitch-irc/v3"
11 | "github.com/zneix/tcb2/internal/bot"
12 | "go.mongodb.org/mongo-driver/bson"
13 | )
14 |
15 | func RemoveMe(tcb *bot.Bot) *bot.Command {
16 | return &bot.Command{
17 | Name: "removeme",
18 | Aliases: []string{"tcbremoveme"},
19 | Description: "Subscribe to an event. Optional value can be only used with title and game events. For list of available events use: {prefix}events",
20 | Usage: " [optional value]",
21 | CooldownChannel: 100 * time.Millisecond,
22 | CooldownUser: 3 * time.Second,
23 | Run: func(msg twitch.PrivateMessage, args []string) {
24 | channel := tcb.Channels[msg.RoomID]
25 |
26 | // Parts of responses used commonly across the command
27 | checkAllEvents := fmt.Sprintf("Check all events you've subscribed to with: %ssubscribed", tcb.Commands.Prefix)
28 |
29 | // No arguments, return an error message
30 | if len(args) < 1 {
31 | channel.Sendf("@%s, you must specify an event to unsubscribe from. %s", msg.User.Name, checkAllEvents)
32 | return
33 | }
34 |
35 | // Parse sub event type passed as the first argument
36 | valid, event := bot.ParseSubEventType(strings.ToLower(args[0]))
37 | if !valid {
38 | channel.Sendf("@%s, given event name is not valid. %s", msg.User.Name, checkAllEvents)
39 | return
40 | }
41 |
42 | // Determine the optional value
43 | value := strings.Join(args[1:], " ")
44 | if event != bot.SubEventTypeGame && event != bot.SubEventTypeTitle {
45 | value = ""
46 | }
47 |
48 | // If value is empty, remove the user from all subscriptions to this event
49 | removeQuery := bson.M{
50 | "user_id": msg.User.ID,
51 | "event": event,
52 | }
53 | // Otherwise, only remove subscriptions that match that value (case sensitive)
54 | if value != "" {
55 | removeQuery["value"] = value
56 | }
57 | res, err := tcb.Mongo.CollectionSubs(msg.RoomID).DeleteMany(context.TODO(), removeQuery)
58 | if err != nil {
59 | log.Println("[Mongo] Failed deleting subscriptions: " + err.Error())
60 | channel.Sendf("@%s, internal server error occured while trying to delete your subscriptions monkaS @zneix", msg.User.Name)
61 | return
62 | }
63 | log.Printf("[Mongo] Deleted %d subscription(s) for %# v(%s) in %s", res.DeletedCount, msg.User.Name, msg.User.ID, channel)
64 |
65 | if res.DeletedCount == 0 {
66 | if len(value) > 0 {
67 | // Didn't match the value
68 | channel.Sendf("@%s, you are not subscribed to the event %s with provided value FeelsDankMan %s", msg.User.Name, event, checkAllEvents)
69 | } else {
70 | // User wasn't subscribed to this event
71 | channel.Sendf("@%s, you are not subscribed to the event %s. %s", msg.User.Name, event, checkAllEvents)
72 | }
73 | return
74 | }
75 |
76 | reply := fmt.Sprintf("@%s, successfully removed %d subscription(s) to event %s", msg.User.Name, res.DeletedCount, event)
77 | if len(value) > 0 {
78 | reply += ", but only for the provided value"
79 | }
80 | channel.Sendf(reply)
81 | },
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/internal/commands/subscribed.go:
--------------------------------------------------------------------------------
1 | package commands
2 |
3 | import (
4 | "context"
5 | "fmt"
6 | "log"
7 | "strings"
8 | "time"
9 |
10 | "github.com/gempir/go-twitch-irc/v3"
11 | "github.com/zneix/tcb2/internal/bot"
12 | "go.mongodb.org/mongo-driver/bson"
13 | )
14 |
15 | func Subscribed(tcb *bot.Bot) *bot.Command {
16 | return &bot.Command{
17 | Name: "subscribed",
18 | Aliases: []string{"tcbsubscribed"},
19 | Description: "Shows you list of events you're subscribed to",
20 | Usage: "",
21 | CooldownChannel: 100 * time.Millisecond,
22 | CooldownUser: 5 * time.Second,
23 | Run: func(msg twitch.PrivateMessage, args []string) {
24 | channel := tcb.Channels[msg.RoomID]
25 |
26 | // Find all user's subscriptions in this chat
27 | // TODO: Consider adding a way to check your subscriptions in other / all chats
28 | cur, err := tcb.Mongo.CollectionSubs(msg.RoomID).Find(context.TODO(), bson.M{
29 | "user_id": msg.User.ID,
30 | })
31 | if err != nil {
32 | log.Printf("[Mongo] Failed querying events: %s\n", err)
33 | return
34 | }
35 |
36 | // subMap contains indexes of subscriptions in the subs slice
37 | subMap := make(map[bot.SubEventType][]int)
38 | subs := []*bot.SubEventSubscription{}
39 |
40 | // Fetch all relevant subscriptions
41 | for cur.Next(context.TODO()) {
42 | // Deserialize sub data
43 | var sub *bot.SubEventSubscription
44 | err := cur.Decode(&sub)
45 | if err != nil {
46 | log.Println("[Mongo] Malformed subscription document: " + err.Error())
47 | continue
48 | }
49 | subs = append(subs, sub)
50 | subMap[sub.Event] = append(subMap[sub.Event], len(subs)-1)
51 | }
52 |
53 | // User isn't subscribed to anything, tell them how can they do that
54 | if len(subs) == 0 {
55 | // @zneix, You are not subscribed to any events. Use !notifyme [optional value] to subscribe. Valid events are: game, live, offline, title
56 | eventStrings := []string{}
57 | for i, desc := range bot.SubEventDescriptions {
58 | eventStrings = append(eventStrings, fmt.Sprintf("%s (%s)", bot.SubEventType(i), desc))
59 | }
60 | channel.Sendf("@%s, you are not subscribed to any events. Use %snotifyme to subscribe to an event. Valid events: %s", msg.User.Name, tcb.Commands.Prefix, strings.Join(eventStrings, ", "))
61 | return
62 | }
63 |
64 | // Inform the user about their subscriptions
65 | parts := []string{}
66 | for k, v := range subMap {
67 | values := []string{}
68 | for _, subIndex := range v {
69 | if subs[subIndex].Value != "" {
70 | values = append(values, fmt.Sprintf("%q", subs[subIndex].Value))
71 | }
72 | }
73 | if len(values) == 0 {
74 | parts = append(parts, k.String())
75 | } else {
76 | parts = append(parts, fmt.Sprintf("%s (only for values: %s)", k, strings.Join(values, ", ")))
77 | }
78 | }
79 | channel.Sendf("@%s, you have %d subscription(s) to %d event(s): %s", msg.User.Name, len(subs), len(subMap), strings.Join(parts, ", "))
80 | },
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/internal/commands/title.go:
--------------------------------------------------------------------------------
1 | package commands
2 |
3 | import (
4 | "time"
5 |
6 | "github.com/gempir/go-twitch-irc/v3"
7 | "github.com/zneix/tcb2/internal/bot"
8 | )
9 |
10 | func Title(tcb *bot.Bot) *bot.Command {
11 | return &bot.Command{
12 | Name: "title",
13 | Aliases: []string{"currenttitle"},
14 | Description: "Returns current title",
15 | Usage: "",
16 | CooldownChannel: 3 * time.Second,
17 | CooldownUser: 5 * time.Second,
18 | Run: func(msg twitch.PrivateMessage, args []string) {
19 | channel := tcb.Channels[msg.RoomID]
20 | channel.Sendf("@%s, current title: %s", msg.User.Name, channel.CurrentTitle)
21 | },
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/internal/common/common.go:
--------------------------------------------------------------------------------
1 | // common is a Singleton package that contains values filled in while building with Makefile
2 | // values are initialized at the application startup and can be shared across all packages
3 | package common
4 |
5 | import "fmt"
6 |
7 | var (
8 | // Values filled in with ./build.sh (ldflags)
9 |
10 | // BuildTime time when the binary was built
11 | BuildTime string
12 |
13 | // BuildVersion version of the bot itself, as described by most recent git tag
14 | BuildVersion string
15 |
16 | // BuildHash short Git commit hash
17 | BuildHash string
18 |
19 | // BuildBranch Git branch
20 | BuildBranch string
21 | )
22 |
23 | func Version() string {
24 | return fmt.Sprintf("%s %s@%s", BuildVersion, BuildBranch, BuildHash)
25 | }
26 |
--------------------------------------------------------------------------------
/internal/config/config.go:
--------------------------------------------------------------------------------
1 | package config
2 |
3 | import (
4 | "errors"
5 | "fmt"
6 | "os"
7 | "path/filepath"
8 | "runtime"
9 | "strings"
10 |
11 | "github.com/spf13/pflag"
12 | "github.com/spf13/viper"
13 | )
14 |
15 | const (
16 | appName = "tcb2"
17 | configName = "config"
18 | )
19 |
20 | // readFromPath reads the config values from the given path (i.e. path/${configName}.yaml) and returns its values as a map.
21 | // This allows us to use mergeConfig cleanly
22 | func readFromPath(path string) (values map[string]interface{}, err error) {
23 | v := viper.New()
24 | v.SetConfigName(configName)
25 | v.SetConfigType("yaml")
26 | v.AddConfigPath(path)
27 |
28 | if err = v.ReadInConfig(); err != nil {
29 | notFoundError := &viper.ConfigFileNotFoundError{}
30 | if errors.As(err, notFoundError) {
31 | err = nil
32 | return
33 | }
34 | return
35 | }
36 |
37 | _ = v.Unmarshal(&values)
38 |
39 | return
40 | }
41 |
42 | // mergeConfig uses viper.MergeConfigMap to read config values in the unix
43 | // standard, so you start furthest down with reading the system config file,
44 | // merge those values into the main config map, then read the home directory
45 | // config files, and merge any set values from there, and lastly the config
46 | // file in the cwd and merge those in. If a value is not set in the cwd config
47 | // file, but one is set in the system config file then the system config file
48 | // value will be used
49 | func mergeConfig(v *viper.Viper, configPaths []string) {
50 | for _, configPath := range configPaths {
51 | configMap, err := readFromPath(configPath)
52 | if err != nil {
53 | fmt.Printf("Error reading config file from %s.yaml: %s\n", filepath.Join(configPath, configName), err)
54 | return
55 | }
56 | _ = v.MergeConfigMap(configMap)
57 | }
58 | }
59 |
60 | func init() {
61 | // Define command-line flags and default values
62 |
63 | // Bot
64 | pflag.String("command-prefix", "!", "Command prefix to which bot will respond to")
65 |
66 | // Misc
67 | pflag.String("supinic-api-key", "", `titlechange_bot's key to the Supinic's API, in the format: "SupibotID:APIKey" without quotation marks`)
68 |
69 | // API
70 | pflag.StringP("base-url", "b", "", "Base URL of the API to which clients will make their requests. Useful if the API is proxied through reverse proxy like nginx. Value needs to contain full URL with protocol scheme, e.g. https://braize.pajlada.com/chatterino")
71 | pflag.StringP("bind-address", "l", ":2558", "Address to which API will bind and start listening on")
72 |
73 | // Twitch
74 | pflag.String("twitch-login", "titlechange_bot", "Twitch login of the account on which bot will Log in to Twitch IRC")
75 | pflag.String("twitch-oauth", "", `OAuth token of the account on which bot will Log in to IRC. Should not have the "oauth:" part in the beginning.`)
76 | pflag.String("twitch-client-id", "", "Twitch Client ID")
77 | pflag.String("twitch-client-secret", "", "Twitch Client secret")
78 | pflag.String("twitch-eventsub-secret", "", "Twitch EventSub secret used to create subscriptions and verify incoming notifications. Must be between 10 and 100 characters long")
79 |
80 | // Mongo 🥭
81 | pflag.String("mongo-username", "", "Username for the MongoDB user")
82 | pflag.String("mongo-password", "", "Password for the MongoDB user")
83 | pflag.String("mongo-port", "27017", "Port to which connection will try to connect. Note that you can only connect to localhost due to security concerns (use ssh port tunneling while testing/developing)")
84 | pflag.String("mongo-database-name", "tcb2", "Name of the database that should be used by the bot")
85 | pflag.String("mongo-auth-db", "admin", "Name of the authentication database, used as AuthSource while creating a new mongo.Connection. This should usually be left unchanged")
86 |
87 | pflag.Parse()
88 | }
89 |
90 | func New() (cfg *TCBConfig) {
91 | v := viper.New()
92 |
93 | _ = v.BindPFlags(pflag.CommandLine)
94 |
95 | // figure out XDG_DATA_CONFIG to be compliant with the standard
96 | xdgConfigHome, exists := os.LookupEnv("XDG_CONFIG_HOME")
97 | if !exists || xdgConfigHome == "" {
98 | // on Windows, we use appdata since that's the closest equivalent
99 | if runtime.GOOS == "windows" {
100 | xdgConfigHome = "$APPDATA"
101 | } else {
102 | xdgConfigHome = filepath.Join("$HOME", ".config")
103 | }
104 | }
105 |
106 | // config paths to read from, in order of least importance
107 | var configPaths []string
108 | if runtime.GOOS != "windows" {
109 | configPaths = append(configPaths, filepath.Join("/etc", appName))
110 | }
111 | configPaths = append(configPaths, filepath.Join(xdgConfigHome, appName))
112 | configPaths = append(configPaths, ".")
113 |
114 | mergeConfig(v, configPaths)
115 |
116 | // Environment
117 | v.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
118 | v.SetEnvPrefix(appName)
119 | v.AutomaticEnv()
120 |
121 | _ = v.UnmarshalExact(&cfg)
122 |
123 | // fmt.Printf("%# v\n", cfg) // uncomment for debugging purposes
124 | return
125 | }
126 |
--------------------------------------------------------------------------------
/internal/config/model.go:
--------------------------------------------------------------------------------
1 | package config
2 |
3 | type TCBConfig struct {
4 | // Bot
5 |
6 | CommandPrefix string `mapstructure:"command-prefix"`
7 |
8 | // Misc
9 |
10 | SupinicAPIKey string `mapstructure:"supinic-api-key"`
11 |
12 | // API
13 |
14 | BaseURL string `mapstructure:"base-url"`
15 | BindAddress string `mapstructure:"bind-address"`
16 |
17 | // Twitch
18 |
19 | TwitchLogin string `mapstructure:"twitch-login"`
20 | TwitchOAuth string `mapstructure:"twitch-oauth"`
21 | TwitchClientID string `mapstructure:"twitch-client-id"`
22 | TwitchClientSecret string `mapstructure:"twitch-client-secret"`
23 | TwitchEventSubSecret string `mapstructure:"twitch-eventsub-secret"`
24 |
25 | // Mongo 🥭
26 |
27 | MongoUsername string `mapstructure:"mongo-username"`
28 | MongoPassword string `mapstructure:"mongo-password"`
29 | MongoPort string `mapstructure:"mongo-port"`
30 | MongoDatabaseName string `mapstructure:"mongo-database-name"`
31 | MongoAuthDB string `mapstructure:"mongo-auth-db"`
32 | }
33 |
--------------------------------------------------------------------------------
/internal/eventsub/eventsub.go:
--------------------------------------------------------------------------------
1 | package eventsub
2 |
3 | import (
4 | "encoding/json"
5 | "log"
6 | "strings"
7 |
8 | "github.com/nicklaw5/helix/v2"
9 | "github.com/zneix/tcb2/internal/api"
10 | "github.com/zneix/tcb2/internal/config"
11 | )
12 |
13 | func (esub *EventSub) CreateChannelSubscription(helixClient *helix.Client, subscription *ChannelSubscription) error {
14 | _, err := helixClient.CreateEventSubSubscription(&helix.EventSubSubscription{
15 | Type: subscription.Type,
16 | Version: subscription.Version,
17 | Condition: helix.EventSubCondition{
18 | BroadcasterUserID: subscription.ChannelID,
19 | },
20 | Transport: helix.EventSubTransport{
21 | Method: "webhook",
22 | Callback: esub.callbackURL,
23 | Secret: esub.secret,
24 | },
25 | })
26 | if err != nil {
27 | return err
28 | }
29 |
30 | // log.Printf("[EventSub] Create subscription response for %s: %# v\n", subscription, resp.Data)
31 |
32 | // TODO: Properly handle pending status
33 | // subscriptionsPending = append(subscriptionsPending, sub.ID)
34 |
35 | return nil
36 | }
37 |
38 | func (esub *EventSub) handleIncomingNotification(notification *eventSubNotification) {
39 | switch notification.Subscription.Type {
40 | case helix.EventSubTypeChannelUpdate:
41 | // channel.update
42 | var event helix.EventSubChannelUpdateEvent
43 | err := json.Unmarshal(notification.Event, &event)
44 | if err != nil {
45 | log.Printf("[EventSub] Failed to unmarshal notification event: %s, data: %s\n", err, string(notification.Event))
46 | return
47 | }
48 | if esub.onChannelUpdateEvent != nil {
49 | esub.onChannelUpdateEvent(event)
50 | }
51 |
52 | case helix.EventSubTypeStreamOnline:
53 | // stream.online
54 | var event helix.EventSubStreamOnlineEvent
55 | err := json.Unmarshal(notification.Event, &event)
56 | if err != nil {
57 | log.Printf("[EventSub] Failed to unmarshal notification event: %s, data: %s\n", err, string(notification.Event))
58 | return
59 | }
60 | if esub.onStreamOnlineEvent != nil {
61 | esub.onStreamOnlineEvent(event)
62 | }
63 |
64 | case helix.EventSubTypeStreamOffline:
65 | // stream.offline
66 | var event helix.EventSubStreamOfflineEvent
67 | err := json.Unmarshal(notification.Event, &event)
68 | if err != nil {
69 | log.Printf("[EventSub] Failed to unmarshal notification event: %s, data: %s\n", err, string(notification.Event))
70 | return
71 | }
72 | if esub.onStreamOfflineEvent != nil {
73 | esub.onStreamOfflineEvent(event)
74 | }
75 |
76 | default:
77 | log.Printf("[EventSub] Received unhandled notification: %# v\n", notification)
78 | }
79 | }
80 |
81 | // OnChannelUpdateEvent attach callback to channel.update event
82 | func (esub *EventSub) OnChannelUpdateEvent(callback func(event helix.EventSubChannelUpdateEvent)) {
83 | esub.onChannelUpdateEvent = callback
84 | }
85 |
86 | // OnStreamOnlineEvent attach callback to stream.online event
87 | func (esub *EventSub) OnStreamOnlineEvent(callback func(event helix.EventSubStreamOnlineEvent)) {
88 | esub.onStreamOnlineEvent = callback
89 | }
90 |
91 | // OnStreamOfflineEvent attach callback to stream.offline event
92 | func (esub *EventSub) OnStreamOfflineEvent(callback func(event helix.EventSubStreamOfflineEvent)) {
93 | esub.onStreamOfflineEvent = callback
94 | }
95 |
96 | func New(cfg *config.TCBConfig, apiServer *api.Server) *EventSub {
97 | eventsub := &EventSub{
98 | secret: cfg.TwitchEventSubSecret,
99 | callbackURL: strings.TrimSuffix(apiServer.BaseURL, "/") + "/eventsub/callback",
100 | }
101 |
102 | eventsub.registerAPIRoutes(apiServer)
103 |
104 | return eventsub
105 | }
106 |
--------------------------------------------------------------------------------
/internal/eventsub/model.go:
--------------------------------------------------------------------------------
1 | package eventsub
2 |
3 | import (
4 | "encoding/json"
5 | "fmt"
6 |
7 | "github.com/nicklaw5/helix/v2"
8 | )
9 |
10 | type eventSubNotification struct {
11 | Subscription helix.EventSubSubscription `json:"subscription"`
12 | Challenge string `json:"challenge"`
13 | Event json.RawMessage `json:"event"`
14 | }
15 |
16 | type ChannelSubscription struct {
17 | Type string
18 | Version string
19 | ChannelID string
20 | }
21 |
22 | func (subscription *ChannelSubscription) String() string {
23 | return fmt.Sprintf("%s-%s@%s", subscription.Type, subscription.Version, subscription.ChannelID)
24 | }
25 |
26 | type EventSub struct {
27 | secret string
28 | callbackURL string
29 | onChannelUpdateEvent func(event helix.EventSubChannelUpdateEvent)
30 | onStreamOnlineEvent func(event helix.EventSubStreamOnlineEvent)
31 | onStreamOfflineEvent func(event helix.EventSubStreamOfflineEvent)
32 | }
33 |
--------------------------------------------------------------------------------
/internal/eventsub/routes.go:
--------------------------------------------------------------------------------
1 | package eventsub
2 |
3 | import (
4 | "encoding/json"
5 | "io"
6 | "log"
7 | "net/http"
8 |
9 | "github.com/nicklaw5/helix/v2"
10 | "github.com/zneix/tcb2/internal/api"
11 | )
12 |
13 | // routeIndex handles GET /eventsub
14 | func (esub *EventSub) routeIndex(w http.ResponseWriter, r *http.Request) {
15 | w.Header().Set("Content-Type", "text/plain")
16 | _, _ = w.Write([]byte("EventSub route index PauseManShit\n"))
17 | }
18 |
19 | // routeCallback handles POST /eventsub/callback
20 | func (esub *EventSub) routeCallback(w http.ResponseWriter, r *http.Request) {
21 | body, err := io.ReadAll(r.Body)
22 | if err != nil {
23 | log.Println("[EventSub] Error reading request body in eventSubCallback:", err)
24 | w.WriteHeader(http.StatusInternalServerError)
25 | return
26 | }
27 | defer r.Body.Close()
28 |
29 | // First of all, check if the message really came from Twitch by verifying the signature
30 | if !helix.VerifyEventSubNotification(esub.secret, r.Header, string(body)) {
31 | log.Println("[EventSub] Received a notification, but the signature was invalid")
32 | w.WriteHeader(http.StatusForbidden)
33 | return
34 | }
35 |
36 | // Read data sent in the request
37 | var notification eventSubNotification
38 | err = json.Unmarshal(body, ¬ification)
39 | if err != nil {
40 | log.Printf("[EventSub] Failed to unmarshal incoming message: %s, request body: %s\n", err, string(body))
41 | w.WriteHeader(http.StatusInternalServerError)
42 | return
43 | }
44 |
45 | // If a challenge is specified in request, respond to it
46 | if notification.Challenge != "" {
47 | w.Header().Set("Content-Type", "text/plain")
48 | _, _ = w.Write([]byte(notification.Challenge))
49 | return
50 | }
51 |
52 | // XXX: This order of these two functions seems awfully wrong, but in stream-online-while-already-live cases it /could/ prevent panics(?)
53 | w.WriteHeader(http.StatusOK)
54 | esub.handleIncomingNotification(¬ification)
55 | }
56 |
57 | func (esub *EventSub) registerAPIRoutes(server *api.Server) {
58 | server.Router.Get("/eventsub", esub.routeIndex)
59 | server.Router.Post("/eventsub/callback", esub.routeCallback)
60 | }
61 |
--------------------------------------------------------------------------------
/internal/helixclient/access_token.go:
--------------------------------------------------------------------------------
1 | package helixclient
2 |
3 | import (
4 | "log"
5 | "time"
6 |
7 | "github.com/nicklaw5/helix/v2"
8 | )
9 |
10 | // initAppAccessToken requests and sets app access token to the provided helix.Client
11 | // and initializes a ticker running every 24 Hours which re-requests and sets app access token
12 | func initAppAccessToken(client *helix.Client, tokenFetched chan struct{}) {
13 | response, err := client.RequestAppAccessToken([]string{})
14 |
15 | if err != nil {
16 | log.Fatalln("[Helix] Error requesting app access token:", err)
17 | }
18 |
19 | log.Printf("[Helix] Requested access token, status: %d, expires in: %d", response.StatusCode, response.Data.ExpiresIn)
20 | client.SetAppAccessToken(response.Data.AccessToken)
21 | close(tokenFetched)
22 |
23 | // Initialize the ticker
24 | ticker := time.NewTicker(24 * time.Hour)
25 |
26 | for range ticker.C {
27 | response, err := client.RequestAppAccessToken([]string{})
28 | if err != nil {
29 | log.Printf("[Helix] Failed to re-request app access token from ticker, status: %d, err: %s", response.StatusCode, err)
30 | continue
31 | }
32 | log.Printf("[Helix] Re-requested access token from ticker, status: %d, expires in: %d", response.StatusCode, response.Data.ExpiresIn)
33 |
34 | client.SetAppAccessToken(response.Data.AccessToken)
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/internal/helixclient/client.go:
--------------------------------------------------------------------------------
1 | package helixclient
2 |
3 | import (
4 | "errors"
5 |
6 | "github.com/nicklaw5/helix/v2"
7 | "github.com/zneix/tcb2/internal/config"
8 | )
9 |
10 | // New returns a helix.Client that has requested an AppAccessToken and will keep it refreshed every 24h
11 | func New(cfg *config.TCBConfig) (*helix.Client, error) {
12 | if cfg.TwitchClientID == "" {
13 | return nil, errors.New("twitch Client ID is missing, can't make Helix requests")
14 | }
15 | if cfg.TwitchClientSecret == "" {
16 | return nil, errors.New("twitch Client Secret is missing, can't make Helix requests")
17 | }
18 |
19 | client, err := helix.NewClient(&helix.Options{
20 | ClientID: cfg.TwitchClientID,
21 | ClientSecret: cfg.TwitchClientSecret,
22 | })
23 | if err != nil {
24 | return nil, err
25 | }
26 |
27 | // Initialize methods responsible for refreshing access token
28 | waitForFirstAppAccessToken := make(chan struct{})
29 | go initAppAccessToken(client, waitForFirstAppAccessToken)
30 | <-waitForFirstAppAccessToken
31 |
32 | return client, nil
33 | }
34 |
--------------------------------------------------------------------------------
/internal/mongo/connection.go:
--------------------------------------------------------------------------------
1 | package mongo
2 |
3 | import (
4 | "context"
5 | "fmt"
6 | "log"
7 | "time"
8 |
9 | "github.com/zneix/tcb2/internal/config"
10 | "go.mongodb.org/mongo-driver/mongo"
11 | "go.mongodb.org/mongo-driver/mongo/options"
12 | )
13 |
14 | // NewMongoConnection creates a new instance of mongo.Connection. Keep in mind that Connect() has to be called before using it
15 | func NewMongoConnection(bgctx context.Context, cfg *config.TCBConfig) *Connection {
16 | // Prepare mongo client's options
17 | uri := fmt.Sprintf("mongodb://%s:%s", "localhost", cfg.MongoPort)
18 | credentials := options.Credential{
19 | AuthSource: cfg.MongoAuthDB,
20 | Username: cfg.MongoUsername,
21 | Password: cfg.MongoPassword,
22 | }
23 | clientOptions := options.Client().ApplyURI(uri).SetAuth(credentials)
24 |
25 | // Actually connect to the database and test connection with a ping
26 | client, err := mongo.NewClient(clientOptions)
27 |
28 | if err != nil {
29 | log.Fatalf("[Mongo] Failed to create a new client: %s\n", err)
30 | }
31 |
32 | return &Connection{
33 | client: client,
34 | databaseName: cfg.MongoDatabaseName,
35 | }
36 | }
37 |
38 | func (conn Connection) Connect(bgctx context.Context) {
39 | ctx, cancel := context.WithTimeout(bgctx, 10*time.Second)
40 | defer cancel()
41 |
42 | err := conn.client.Connect(ctx)
43 | if err != nil {
44 | log.Fatalln("[Mongo] Error connecting:", err)
45 | }
46 |
47 | err = conn.client.Ping(ctx, nil)
48 | if err != nil {
49 | log.Fatalln("[Mongo] Error while executing the ping:", err)
50 | }
51 | log.Println("[Mongo] connected")
52 | }
53 |
54 | func (conn Connection) Disconnect(bgctx context.Context) {
55 | ctx, cancel := context.WithTimeout(bgctx, 10*time.Second)
56 | defer cancel()
57 |
58 | err := conn.client.Disconnect(ctx)
59 | if err != nil {
60 | log.Println("[Mongo] Error while disconnecting:", err)
61 | }
62 | log.Println("[Mongo] disconnected")
63 | }
64 |
65 | // Collection returns a collection with given name from the bot's main database specified in the config
66 | func (conn *Connection) Collection(name CollectionName) *mongo.Collection {
67 | return conn.client.Database(conn.databaseName).Collection(string(name))
68 | }
69 |
70 | // CollectionSubs returns a collection that stores user's subscriptions to SubEvent events
71 | func (conn *Connection) CollectionSubs(channelID string) *mongo.Collection {
72 | return conn.client.Database(conn.databaseName + "-subscriptions").Collection(channelID)
73 | }
74 |
--------------------------------------------------------------------------------
/internal/mongo/types.go:
--------------------------------------------------------------------------------
1 | package mongo
2 |
3 | import "go.mongodb.org/mongo-driver/mongo"
4 |
5 | type Connection struct {
6 | client *mongo.Client
7 | databaseName string
8 | }
9 |
10 | type CollectionName string
11 |
12 | const (
13 | CollectionNameChannels = CollectionName("channels")
14 | CollectionNameMOTDs = CollectionName("motds")
15 |
16 | // Migration collections
17 | // CollectionNameChannels = CollectionName("new-channels") // Temporary coll with new channels
18 | CollectionNameOldSubscriptions = CollectionName("old-subscriptions") // Coll where old subscriptions should be imported
19 |
20 | // TODO: Add handling for the (admin) users in the "users" collection
21 | // CollectionNameUsers = CollectionName("users")
22 | )
23 |
--------------------------------------------------------------------------------
/internal/supinicapi/client.go:
--------------------------------------------------------------------------------
1 | package supinicapi
2 |
3 | import (
4 | "log"
5 | "net/http"
6 | "time"
7 | )
8 |
9 | // Client represents a Supinic's API wrapper
10 | type Client struct {
11 | apiKey string
12 | httpClient *http.Client
13 | }
14 |
15 | // New creates a new Client instance, requires a
16 | func New(supinicAPIKey string) *Client {
17 | return &Client{
18 | apiKey: supinicAPIKey,
19 | httpClient: &http.Client{},
20 | }
21 | }
22 |
23 | // requestAliveStatus check documentation at https://supinic.com/api/#api-Bot_Program-UpdateBotActivity
24 | func (c *Client) requestAliveStatus() {
25 | req, err := http.NewRequest("PUT", "https://supinic.com/api/bot-program/bot/active", http.NoBody)
26 | if err != nil {
27 | log.Println("[SupinicAPI] Error creating API request:", err)
28 | return
29 | }
30 | req.Header.Set("Authorization", "Basic "+c.apiKey)
31 |
32 | res, err := c.httpClient.Do(req)
33 | if err != nil {
34 | log.Println("[SupinicAPI] Failed to update alive status:", err)
35 | return
36 | }
37 | defer res.Body.Close()
38 |
39 | log.Println("[SupinicAPI] Pinged alive endpoint, status:", res.StatusCode)
40 | }
41 |
42 | // TODO: make use of context.Context here
43 | // UpdateAliveStatus starts routine updating alive status on Supinic's API right away and every 15 minutes
44 | func (c *Client) UpdateAliveStatus() {
45 | if c.apiKey == "" {
46 | log.Println("[SupinicAPI] API key is empty, won't make API requests")
47 | return
48 | }
49 |
50 | c.requestAliveStatus()
51 |
52 | // Make the API request every 15 minutes
53 | ticker := time.NewTicker(15 * time.Minute)
54 |
55 | for range ticker.C {
56 | c.requestAliveStatus()
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/pkg/utils/slice.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | // ChunkStringSlice takes 1 big slice of strings and splits it into
4 | // smaller chunks with the maximum amount of strings specified by chunkSize
5 | func ChunkStringSlice(slice []string, chunkSize int) (chunks [][]string) {
6 | for i := 0; i < len(slice); i += chunkSize {
7 | end := i + chunkSize
8 |
9 | // necessary check to avoid slicing beyond slice capacity
10 | if end > len(slice) {
11 | end = len(slice)
12 | }
13 |
14 | chunks = append(chunks, slice[i:end])
15 | }
16 |
17 | return
18 | }
19 |
--------------------------------------------------------------------------------
/pkg/utils/string.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import "unicode/utf8"
4 |
5 | // LimitString makes sure that a is not bigger than limit or as long as limit with the appended Unicode that looks like three dots
6 | func LimitString(a string, limit int) string {
7 | if utf8.RuneCountInString(a) > limit {
8 | return a[0:limit-1] + "…"
9 | }
10 | return a
11 | }
12 |
--------------------------------------------------------------------------------
/pkg/utils/time.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import (
4 | "fmt"
5 | "math"
6 | "sort"
7 | "strings"
8 | "time"
9 | )
10 |
11 | type relTimeMagnitude struct {
12 | D time.Duration
13 | Name string
14 | DivBy time.Duration
15 | ModBy time.Duration
16 | }
17 |
18 | const (
19 | Day = time.Hour * 24
20 | Week = Day * 7
21 | Month = Day * 30
22 | Year = Month * 12
23 | )
24 |
25 | var magnitudes = []relTimeMagnitude{
26 | {time.Minute, "second", time.Second, 60},
27 | {time.Hour, "minute", time.Minute, 60},
28 | {Day, "hour", time.Hour, 24},
29 | {Week, "day", Day, 7},
30 | {Month, "week", Week, 7},
31 | {Year, "month", Month, 12},
32 | {math.MaxInt64, "year", Year, -1},
33 | }
34 |
35 | func CustomDurationString(diff time.Duration, numParts int, glue string) string {
36 | if diff < time.Second {
37 | return "now"
38 | }
39 |
40 | n := sort.Search(len(magnitudes), func(i int) bool {
41 | return magnitudes[i].D > diff
42 | })
43 |
44 | if n >= len(magnitudes) {
45 | n--
46 | }
47 |
48 | var parts []string
49 |
50 | partIndex := 0
51 | for i := 0; partIndex < numParts && n-i >= 0; i++ {
52 | mag := magnitudes[n-i]
53 |
54 | value := diff
55 | if mag.DivBy != -1 {
56 | value /= mag.DivBy
57 | }
58 | if mag.ModBy != -1 {
59 | value %= mag.ModBy
60 | }
61 | if value > 0 {
62 | part := fmt.Sprintf("%d %s", value, mag.Name)
63 | if value > 1 {
64 | part += "s"
65 | }
66 |
67 | diff -= value * mag.DivBy
68 |
69 | parts = append(parts, part)
70 | partIndex++
71 | }
72 | }
73 |
74 | return strings.Join(parts, glue)
75 | }
76 |
77 | func TimeSince(t2 time.Time) string {
78 | // t1 := time.Now()
79 | // return CustomRelTime(t1, t2, 2, " ")
80 | return CustomDurationString(time.Since(t2), 3, " ")
81 | }
82 |
--------------------------------------------------------------------------------