mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-13 12:19:54 +01:00
Compare commits
22 Commits
3efd003424
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17a754b918 | ||
|
|
730f91e74e | ||
|
|
dbd34abea1 | ||
|
|
beed95eed9 | ||
|
|
074a4a88f0 | ||
|
|
fa765859e4 | ||
|
|
1f59f13bfc | ||
|
|
92660df667 | ||
|
|
db4ca8e4cf | ||
|
|
13b2335ae8 | ||
|
|
1bb8536334 | ||
|
|
6a2e573828 | ||
|
|
7185544e03 | ||
|
|
7fe4181c72 | ||
|
|
3771b1d2c4 | ||
|
|
d54ed135e3 | ||
|
|
ec6ed3cc63 | ||
|
|
2e5b45a699 | ||
|
|
10a563bb23 | ||
|
|
ecba4d68e6 | ||
|
|
1a075e79ff | ||
|
|
12c69818ce |
@@ -295,3 +295,8 @@ _[]Appointment_ (POST/DELETE)
|
||||
}
|
||||
]
|
||||
```
|
||||
### User data
|
||||
| Method | Route | Description | Response | Parameter | Header | POST-Body |
|
||||
| - | - | - | - | - | - | - |
|
||||
| GET | /api/userdata/{user}/{key} | User data holen | | {user} = MAL username; {key} = Key der data | X-HUSO-AUTH | Plaintext(binary) data |
|
||||
| PUT | /api/userdata/{user}/{key} | User data setzen | Plaintext(binary) data | {user} = MAL username; {key} = Key der data | X-HUSO-AUTH | |
|
||||
|
||||
3
build.sh
3
build.sh
@@ -1,3 +1,4 @@
|
||||
#!/bin/bash
|
||||
date=$(date '+%Y-%m-%dT%H:%M:%S')
|
||||
go build -ldflags "-X main.buildTime=$date"
|
||||
commit=$(git log -1 --pretty=format:'%h %B')
|
||||
go build -ldflags "-X 'main.buildTime=$date' -X 'main.buildCommit=$commit'"
|
||||
|
||||
18
go.mod
18
go.mod
@@ -1,30 +1,30 @@
|
||||
module github.com/ultrasn0w/huso
|
||||
|
||||
go 1.18
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/allegro/bigcache/v3 v3.0.2
|
||||
github.com/bwmarrin/discordgo v0.25.0
|
||||
github.com/fasthttp/router v1.4.10
|
||||
github.com/bwmarrin/discordgo v0.26.0
|
||||
github.com/fasthttp/router v1.4.11
|
||||
github.com/go-sql-driver/mysql v1.6.0
|
||||
github.com/gookit/color v1.5.1
|
||||
github.com/valyala/fasthttp v1.38.0
|
||||
github.com/klauspost/compress v1.15.9
|
||||
github.com/valyala/fasthttp v1.39.0
|
||||
github.com/valyala/quicktemplate v1.7.0
|
||||
github.com/xujiajun/nutsdb v0.9.0
|
||||
golang.org/x/time v0.0.0-20220609170525-579cf78fd858
|
||||
github.com/xujiajun/nutsdb v0.10.0
|
||||
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.0.4 // indirect
|
||||
github.com/bwmarrin/snowflake v0.3.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/klauspost/compress v1.15.8 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
|
||||
github.com/xujiajun/mmap-go v1.0.1 // indirect
|
||||
github.com/xujiajun/utils v0.0.0-20190123093513-8bf096c4f53b // indirect
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
|
||||
golang.org/x/crypto v0.0.0-20220824171710-5757bc0c5503 // indirect
|
||||
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24 // indirect
|
||||
)
|
||||
|
||||
32
go.sum
32
go.sum
@@ -4,15 +4,15 @@ github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu
|
||||
github.com/andybalholm/brotli v1.0.3/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
|
||||
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/bwmarrin/discordgo v0.25.0 h1:NXhdfHRNxtwso6FPdzW2i3uBvvU7UIQTghmV2T4nqAs=
|
||||
github.com/bwmarrin/discordgo v0.25.0/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
|
||||
github.com/bwmarrin/discordgo v0.26.0 h1:/AdFmxHXSHInYAZ7K0O3VEIXlVjGpztk/nuCr9o+JCs=
|
||||
github.com/bwmarrin/discordgo v0.26.0/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
|
||||
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
|
||||
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
|
||||
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/fasthttp/router v1.4.10 h1:C8z6K1pTqhLjSv97/qCY9tZiiPT8JuFwDoO9E2HJFWQ=
|
||||
github.com/fasthttp/router v1.4.10/go.mod h1:FGSUOg9SQ/tU864SfD23kG/HwfD0akXqOqhTQ27gTFQ=
|
||||
github.com/fasthttp/router v1.4.11 h1:99BvgVxeS2oOZBHnKr/okpdPq1jkn8WvYA2trh/71LY=
|
||||
github.com/fasthttp/router v1.4.11/go.mod h1:luEEYkGBSAmYyPaMeIUGNgqY+FdHHYDOK9Kivaw7aNo=
|
||||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
|
||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
@@ -25,8 +25,8 @@ github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
|
||||
github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
|
||||
github.com/klauspost/compress v1.13.5/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
||||
github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
||||
github.com/klauspost/compress v1.15.8 h1:JahtItbkWjf2jzm/T+qgMxkP9EMHsqEUA6vCMGmXvhA=
|
||||
github.com/klauspost/compress v1.15.8/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
|
||||
github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY=
|
||||
github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
@@ -40,9 +40,9 @@ github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1F
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.30.0/go.mod h1:2rsYD01CKFrjjsvFxx75KlEUNpWNBY9JWD3K/7o2Cus=
|
||||
github.com/valyala/fasthttp v1.37.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
|
||||
github.com/valyala/fasthttp v1.38.0 h1:yTjSSNjuDi2PPvXY2836bIwLmiTS2T4T9p1coQshpco=
|
||||
github.com/valyala/fasthttp v1.38.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
|
||||
github.com/valyala/fasthttp v1.39.0 h1:lW8mGeM7yydOqZKmwyMTaz/PH/A+CLgtmmcjv+OORfU=
|
||||
github.com/valyala/fasthttp v1.39.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
|
||||
github.com/valyala/quicktemplate v1.7.0 h1:LUPTJmlVcb46OOUY3IeD9DojFpAVbsG+5WFTcjMJzCM=
|
||||
github.com/valyala/quicktemplate v1.7.0/go.mod h1:sqKJnoaOF88V07vkO+9FL8fb9uZg/VPSJnLYn+LmLk8=
|
||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||
@@ -51,15 +51,15 @@ github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1z
|
||||
github.com/xujiajun/gorouter v1.2.0/go.mod h1:yJrIta+bTNpBM/2UT8hLOaEAFckO+m/qmR3luMIQygM=
|
||||
github.com/xujiajun/mmap-go v1.0.1 h1:7Se7ss1fLPPRW+ePgqGpCkfGIZzJV6JPq9Wq9iv/WHc=
|
||||
github.com/xujiajun/mmap-go v1.0.1/go.mod h1:CNN6Sw4SL69Sui00p0zEzcZKbt+5HtEnYUsc6BKKRMg=
|
||||
github.com/xujiajun/nutsdb v0.9.0 h1:vy8rjDp0Sk/SnTAqg61i+G4NIN/3tBKSdZ6rIyKYVIo=
|
||||
github.com/xujiajun/nutsdb v0.9.0/go.mod h1:8ZdTTF0cEQO+wN940htfHYKswFql2iB6Osckx+GmOoU=
|
||||
github.com/xujiajun/nutsdb v0.10.0 h1:kSxd7MyZiAVQM2I79FK74WneGI+uaHsUdak8dbjzKJc=
|
||||
github.com/xujiajun/nutsdb v0.10.0/go.mod h1:8ZdTTF0cEQO+wN940htfHYKswFql2iB6Osckx+GmOoU=
|
||||
github.com/xujiajun/utils v0.0.0-20190123093513-8bf096c4f53b h1:jKG9OiL4T4xQN3IUrhUpc1tG+HfDXppkgVcrAiiaI/0=
|
||||
github.com/xujiajun/utils v0.0.0-20190123093513-8bf096c4f53b/go.mod h1:AZd87GYJlUzl82Yab2kTjx1EyXSQCAfZDhpTo1SQC4k=
|
||||
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
||||
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220824171710-5757bc0c5503 h1:vJ2V3lFLg+bBhgroYuRfyN583UzVveQmIXjc8T/y3to=
|
||||
golang.org/x/crypto v0.0.0-20220824171710-5757bc0c5503/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
@@ -73,15 +73,15 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220405210540-1e041c57c461/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24 h1:TyKJRhyo17yWxOMCTHKWrc5rddHORMlnZ/j57umaUd8=
|
||||
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 h1:Dpdu/EMxGMFgq0CeYMh4fazTD2vtlZRYE7wyynxJb9U=
|
||||
golang.org/x/time v0.0.0-20220609170525-579cf78fd858/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 h1:ftMN5LMiBFjbzleLqtoBZk7KdJwhuybIU+FckUHgoyQ=
|
||||
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
19
huso.go
19
huso.go
@@ -20,7 +20,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
husoVersion = "1.3"
|
||||
husoVersion = "1.7.1"
|
||||
registerSecret = "綾波レイ"
|
||||
seasonStrJikan = "seasons/"
|
||||
userApiJikan = "users/"
|
||||
@@ -37,6 +37,7 @@ const (
|
||||
bucketMedia = "media"
|
||||
bucketAppoint = "appoint"
|
||||
bucketChat = "chat"
|
||||
bucketStash = "stash"
|
||||
AppointSplit = "§"
|
||||
chatLength = 10101
|
||||
)
|
||||
@@ -50,6 +51,9 @@ var (
|
||||
mmDbServer = flag.String("mmDbServer", "hanami.family:3306", "MovieManager db server")
|
||||
mmDbUser = flag.String("mmDbUser", "yui", "MovieManager db user")
|
||||
discordToken = flag.String("discordToken", "OTk4MTk3MTMzNjE2MzUzMzUw.GKPdLt.zaMvvlikffjBxJO-Qx69A5nQNQxtA-FmkH2yTA", "Discord bot auth token")
|
||||
discordChannel = flag.String("discordChannel", "998277590609559632", "Discord bot channel id")
|
||||
husoWebAnimeUri = flag.String("husoWebAnimeUri", "https://anime.hanami.family/anime/", "HusoWeb Anime base URL")
|
||||
husoWebUserUri = flag.String("husoWebUserUri", "https://anime.hanami.family/user/", "HusoWeb User base URL")
|
||||
animeCache *bigcache.BigCache
|
||||
seasoncache *bigcache.BigCache
|
||||
userCache *bigcache.BigCache
|
||||
@@ -62,6 +66,8 @@ var (
|
||||
jikanLimiter *rate.Limiter
|
||||
logOut *RingBuf
|
||||
buildTime string
|
||||
buildCommit string
|
||||
lastAnnounce *SomewhatThreadSafeTime
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -71,10 +77,12 @@ func main() {
|
||||
sc := make(chan os.Signal, 1)
|
||||
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
||||
|
||||
logOut = NewRingBuf(10101)
|
||||
logOut = NewRingBuf(101010)
|
||||
|
||||
color.Notice.Printf("huso %s built on %s with %s\n", husoVersion, buildTime, runtime.Version())
|
||||
color.Notice.Printf("Last git commit: %s\n", buildCommit)
|
||||
logOut.WriteLine(fmt.Sprintf("🎉 huso %s built on %s with %s", husoVersion, buildTime, runtime.Version()))
|
||||
logOut.WriteLine(fmt.Sprintf("🪄 Last git commit: %s", buildCommit))
|
||||
|
||||
jikanLimiter = rate.NewLimiter(rate.Every(time.Second+(time.Millisecond*420)), 1)
|
||||
|
||||
@@ -100,7 +108,7 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer searchCache.Close()
|
||||
animeListCache, err = bigcache.NewBigCache(bigcache.DefaultConfig(42 * time.Minute))
|
||||
animeListCache, err = bigcache.NewBigCache(bigcache.DefaultConfig(15 * time.Minute))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -119,6 +127,10 @@ func main() {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
lastAnnounce = &SomewhatThreadSafeTime{
|
||||
stamp: time.Now().Add(-1 * time.Hour),
|
||||
}
|
||||
|
||||
color.Infoln("NutsDB connected")
|
||||
logOut.WriteLine("🗃️ NutsDB connected")
|
||||
|
||||
@@ -160,6 +172,7 @@ func main() {
|
||||
}
|
||||
|
||||
Arbeit()
|
||||
BissleArbeit()
|
||||
LangeArbeit()
|
||||
|
||||
go Arbeiten()
|
||||
|
||||
31
klotz.go
31
klotz.go
@@ -1,6 +1,9 @@
|
||||
package main
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type AnimeUser struct {
|
||||
Anime int64 `json:"anime"`
|
||||
@@ -55,9 +58,10 @@ type AnimeStudio struct {
|
||||
}
|
||||
|
||||
type Appointment struct {
|
||||
Anime int64 `json:"anime"`
|
||||
Time time.Time `json:"date"`
|
||||
Users []string `json:"users"`
|
||||
Anime int64 `json:"anime"`
|
||||
Time time.Time `json:"date"`
|
||||
Users []string `json:"users"`
|
||||
Announced bool `json:"announced"`
|
||||
}
|
||||
|
||||
type WatchUser struct {
|
||||
@@ -67,13 +71,6 @@ type WatchUser struct {
|
||||
Updated time.Time `json:"updated"`
|
||||
}
|
||||
|
||||
type UserData struct {
|
||||
Username string `json:"username"`
|
||||
MalID int64 `json:"malId"`
|
||||
DiscordID int64 `json:"discordId"`
|
||||
Secret string `json:"secret"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
MalID int64 `json:"id"`
|
||||
Username string `json:"username"`
|
||||
@@ -86,6 +83,13 @@ type User struct {
|
||||
Joined time.Time `json:"joined"`
|
||||
}
|
||||
|
||||
type UserData struct {
|
||||
Username string `json:"username"`
|
||||
MalID int64 `json:"malId"`
|
||||
DiscordID int64 `json:"discordId"`
|
||||
Secret string `json:"secret"`
|
||||
}
|
||||
|
||||
type RegisterData struct {
|
||||
Username string `json:"username"`
|
||||
MalID int64 `json:"malId"`
|
||||
@@ -327,3 +331,8 @@ type MovieChart struct {
|
||||
AvgScore float64 `json:"avgScore"`
|
||||
UserCount int `json:"userCount"`
|
||||
}
|
||||
|
||||
type SomewhatThreadSafeTime struct {
|
||||
sync.Mutex
|
||||
stamp time.Time
|
||||
}
|
||||
|
||||
99
knecht.go
99
knecht.go
@@ -8,6 +8,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/gookit/color"
|
||||
"github.com/valyala/fasthttp"
|
||||
@@ -18,19 +19,29 @@ func SearchAnimeData(query string) ([]Anime, []byte, error) {
|
||||
data, err := searchCache.Get(query)
|
||||
if err != nil {
|
||||
err = nil
|
||||
dataMal, err := GetDataMal(searchApiMal + query + "&fields=id,title,main_picture,alternative_titles,start_date,end_date,synopsis,mean,rank,popularity,num_list_users,num_scoring_users,nsfw,media_type,status,genres,my_list_status,num_episodes,start_season,broadcast,source,average_episode_duration,rating,studios&limit=100")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
var animeList AnimeListMal
|
||||
animes = make([]Anime, 0)
|
||||
err = json.Unmarshal(dataMal, &animeList)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
parseId, err := strconv.ParseInt(query, 10, 64)
|
||||
if err == nil && parseId > 0 {
|
||||
anime, err := SearchAnime(parseId)
|
||||
if err == nil {
|
||||
animes = append(animes, *anime)
|
||||
}
|
||||
}
|
||||
// convert to anime
|
||||
for _, a := range animeList.Data {
|
||||
animes = append(animes, MalConvert(&a.Node))
|
||||
err = nil
|
||||
if utf8.RuneCountInString(query) > 2 {
|
||||
dataMal, err := GetDataMal(searchApiMal + query + "&fields=id,title,main_picture,alternative_titles,start_date,end_date,synopsis,mean,rank,popularity,num_list_users,num_scoring_users,nsfw,media_type,status,genres,my_list_status,num_episodes,start_season,broadcast,source,average_episode_duration,rating,studios&limit=100")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
var animeList AnimeListMal
|
||||
err = json.Unmarshal(dataMal, &animeList)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
// convert to anime
|
||||
for _, a := range animeList.Data {
|
||||
animes = append(animes, MalConvert(&a.Node))
|
||||
}
|
||||
}
|
||||
data, err = json.Marshal(animes)
|
||||
if err != nil {
|
||||
@@ -87,51 +98,57 @@ func GetUserAnimeListData(username, status string) (*AnimeListMal, []byte, error
|
||||
return &list, data, err
|
||||
}
|
||||
|
||||
func GetUserData(username string) (*User, []byte, error) {
|
||||
func GetUser(username string) (*User, []byte, error) {
|
||||
var user User
|
||||
data, err := userCache.Get(username)
|
||||
if err != nil {
|
||||
err = nil
|
||||
dataJikan, err := GetDataJikan(userApiJikan + username)
|
||||
userp, data, err := GetUserData(username)
|
||||
if err != nil {
|
||||
return userp, data, err
|
||||
}
|
||||
userCache.Set(username, data)
|
||||
return userp, data, err
|
||||
} else {
|
||||
err = json.Unmarshal(data, &user)
|
||||
}
|
||||
|
||||
return &user, data, err
|
||||
}
|
||||
|
||||
func GetUserData(username string) (*User, []byte, error) {
|
||||
dataJikan, err := GetDataJikan(userApiJikan + username)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if strings.Contains(string(dataJikan), "BadResponseException") {
|
||||
return nil, nil, fmt.Errorf("user not found: %s", username)
|
||||
}
|
||||
var userJikan UserJikan
|
||||
err = json.Unmarshal(dataJikan, &userJikan)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
// workaround number #2 bcs jikan kekw
|
||||
if userJikan.Data.MalID == 0 {
|
||||
dataJikan, err = GetDataJikan(userApiJikan + username)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if strings.Contains(string(dataJikan), "BadResponseException") {
|
||||
return nil, nil, fmt.Errorf("user not found: %s", username)
|
||||
}
|
||||
var userJikan UserJikan
|
||||
err = json.Unmarshal(dataJikan, &userJikan)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
// workaround number #2 bcs jikan kekw
|
||||
if userJikan.Data.MalID == 0 {
|
||||
dataJikan, err = GetDataJikan(userApiJikan + username)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if strings.Contains(string(dataJikan), "BadResponseException") {
|
||||
return nil, nil, fmt.Errorf("user not found: %s", username)
|
||||
}
|
||||
err = json.Unmarshal(dataJikan, &userJikan)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
if userJikan.Data.MalID == 0 {
|
||||
return nil, nil, fmt.Errorf("user returned empty object: %s", username)
|
||||
}
|
||||
// convert to user
|
||||
user = UserConvert(&userJikan)
|
||||
data, err = json.Marshal(&user)
|
||||
if err != nil {
|
||||
return &user, data, err
|
||||
}
|
||||
userCache.Set(username, data)
|
||||
} else {
|
||||
err = json.Unmarshal(data, &user)
|
||||
}
|
||||
|
||||
if userJikan.Data.MalID == 0 {
|
||||
return nil, nil, fmt.Errorf("user returned empty object: %s", username)
|
||||
}
|
||||
// convert to user
|
||||
user := UserConvert(&userJikan)
|
||||
data, err := json.Marshal(&user)
|
||||
return &user, data, err
|
||||
}
|
||||
|
||||
|
||||
97
labersack.go
97
labersack.go
@@ -3,23 +3,110 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/gookit/color"
|
||||
)
|
||||
|
||||
func SendAppointBroadcast(creator string, app *Appointment) {
|
||||
if app != nil && discc != nil {
|
||||
watchData, err := GetAnimeWatchFromDb(app.Anime)
|
||||
if err != nil {
|
||||
color.Errorln(err.Error())
|
||||
return
|
||||
}
|
||||
anime, err := SearchAnime(app.Anime)
|
||||
if err != nil {
|
||||
color.Errorln(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var msgStart strings.Builder
|
||||
for _, u := range app.Users {
|
||||
uData, err := ReadUser(u)
|
||||
for _, u := range watchData.Users {
|
||||
uData, err := ReadUser(u.Username)
|
||||
if err != nil || uData.DiscordID == 0 {
|
||||
continue
|
||||
}
|
||||
msgStart.WriteString(fmt.Sprintf("<@%d> ", uData.DiscordID))
|
||||
msgStart.WriteString(fmt.Sprintf("<@%d>", uData.DiscordID))
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("📺 %s%s created appointment for %d at <t:%d:F>", msgStart.String(), creator, app.Anime, app.Time.Unix())
|
||||
_, err := discc.ChannelMessageSend("998277590609559632", msg)
|
||||
msgs := fmt.Sprintf("🗓️ New appointment for [%s](%s%d) at\n<t:%d:F>\n<t:%d:R>", anime.Title, *husoWebAnimeUri, app.Anime, app.Time.Unix(), app.Time.Unix())
|
||||
msge := discordgo.MessageEmbed{
|
||||
Description: msgs,
|
||||
URL: fmt.Sprintf("%s%d", *husoWebAnimeUri, app.Anime),
|
||||
Thumbnail: &discordgo.MessageEmbedThumbnail{URL: anime.ImageLargeURL},
|
||||
Color: 7187428,
|
||||
Footer: &discordgo.MessageEmbedFooter{
|
||||
Text: "huso " + husoVersion,
|
||||
},
|
||||
}
|
||||
|
||||
user, _, err := GetUser(creator)
|
||||
if err == nil {
|
||||
msge.Author = &discordgo.MessageEmbedAuthor{
|
||||
Name: user.Username,
|
||||
IconURL: user.ImageURL,
|
||||
URL: fmt.Sprintf("%s%s", *husoWebUserUri, creator),
|
||||
}
|
||||
}
|
||||
|
||||
msgc := discordgo.MessageSend{
|
||||
Content: msgStart.String(),
|
||||
Embeds: []*discordgo.MessageEmbed{&msge},
|
||||
}
|
||||
_, err = discc.ChannelMessageSendComplex(*discordChannel, &msgc)
|
||||
|
||||
if err != nil {
|
||||
color.Errorln(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func AnnounceBomb(animeId, meetingUnix int64, timer time.Duration) {
|
||||
time.Sleep(timer)
|
||||
AnnounceAppointmentSoon(animeId, meetingUnix)
|
||||
}
|
||||
|
||||
func AnnounceAppointmentSoon(animeId, meetingUnix int64) {
|
||||
if animeId != 0 && discc != nil {
|
||||
watchData, err := GetAnimeWatchFromDb(animeId)
|
||||
if err != nil {
|
||||
color.Errorln(err.Error())
|
||||
return
|
||||
}
|
||||
anime, err := SearchAnime(animeId)
|
||||
if err != nil {
|
||||
color.Errorln(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var msgStart strings.Builder
|
||||
for _, u := range watchData.Users {
|
||||
uData, err := ReadUser(u.Username)
|
||||
if err != nil || uData.DiscordID == 0 {
|
||||
continue
|
||||
}
|
||||
msgStart.WriteString(fmt.Sprintf("<@%d>", uData.DiscordID))
|
||||
}
|
||||
|
||||
msgs := fmt.Sprintf("⏰ Appointment starting <t:%d:R>!\n[%s](%s%d) at\n<t:%d:F>", meetingUnix, anime.Title, *husoWebAnimeUri, animeId, meetingUnix)
|
||||
msge := discordgo.MessageEmbed{
|
||||
Description: msgs,
|
||||
URL: fmt.Sprintf("%s%d", *husoWebAnimeUri, animeId),
|
||||
Thumbnail: &discordgo.MessageEmbedThumbnail{URL: anime.ImageLargeURL},
|
||||
Color: 7187428,
|
||||
Footer: &discordgo.MessageEmbedFooter{
|
||||
Text: "huso " + husoVersion,
|
||||
},
|
||||
}
|
||||
|
||||
msgc := discordgo.MessageSend{
|
||||
Content: msgStart.String(),
|
||||
Embeds: []*discordgo.MessageEmbed{&msge},
|
||||
}
|
||||
_, err = discc.ChannelMessageSendComplex(*discordChannel, &msgc)
|
||||
|
||||
if err != nil {
|
||||
color.Errorln(err.Error())
|
||||
}
|
||||
|
||||
7
nuss.go
7
nuss.go
@@ -432,9 +432,10 @@ func ReadAppointments() ([]Appointment, error) {
|
||||
return err
|
||||
}
|
||||
appointment := Appointment{
|
||||
Anime: animeId,
|
||||
Time: date,
|
||||
Users: appointmentUsers,
|
||||
Anime: animeId,
|
||||
Time: date,
|
||||
Users: appointmentUsers,
|
||||
Announced: false,
|
||||
}
|
||||
appoints = append(appoints, appointment)
|
||||
}
|
||||
|
||||
221
ober.go
221
ober.go
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -14,6 +15,13 @@ import (
|
||||
"github.com/xujiajun/nutsdb"
|
||||
)
|
||||
|
||||
const (
|
||||
xHusoAuth = "X-HUSO-AUTH"
|
||||
htmlContentType = "text/html; charset=utf-8"
|
||||
jsonContentType = "application/json; charset=utf-8"
|
||||
textContentType = "text/plain; charset=utf-8"
|
||||
)
|
||||
|
||||
func RunWebserv() {
|
||||
r := router.New()
|
||||
r.GET("/", Headers(Start))
|
||||
@@ -28,6 +36,7 @@ func RunWebserv() {
|
||||
r.GET("/api/chat/{id}", Headers(ChatGet))
|
||||
r.GET("/api/log", Headers(LogGet))
|
||||
r.GET("/api/user/{user?}", Headers(UserGet))
|
||||
r.GET("/api/userdata/{user}/{data}", Headers(UserStashGet))
|
||||
r.GET("/api/watch/{user?}", Headers(WatchGet))
|
||||
r.GET("/api/watchext/{user?}", Headers(WatchExtendedGet))
|
||||
r.POST("/api/appointment/{user}", Headers(AppointmentPost))
|
||||
@@ -35,6 +44,7 @@ func RunWebserv() {
|
||||
r.POST("/api/register", Headers(Register))
|
||||
r.POST("/api/watch/{user}", Headers(WatchPost))
|
||||
r.PATCH("/api/register", Headers(RegisterUpdate))
|
||||
r.PUT("/api/userdata/{user}/{data}", Headers(UserStashPut))
|
||||
r.DELETE("/api/appointment/{user}", Headers(AppointmentDelete))
|
||||
r.DELETE("/api/register", Headers(UnRegister))
|
||||
r.DELETE("/api/watch/{user}", Headers(WatchDelete))
|
||||
@@ -60,12 +70,12 @@ func Start(ctx *fasthttp.RequestCtx) {
|
||||
|
||||
WriteIndex(ctx, season, oracles, charts, logOut.String())
|
||||
|
||||
ctx.SetContentType("text/html; charset=utf-8")
|
||||
ctx.SetContentType(htmlContentType)
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
}
|
||||
|
||||
func AuthTest(ctx *fasthttp.RequestCtx) {
|
||||
auth := ctx.Request.Header.Peek("X-HUSO-AUTH")
|
||||
auth := ctx.Request.Header.Peek(xHusoAuth)
|
||||
if ctx.UserValue("user") == nil || auth == nil || string(auth) == "" {
|
||||
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
||||
return
|
||||
@@ -85,15 +95,7 @@ func Season(ctx *fasthttp.RequestCtx) {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = writeResponseBody(ctx, data)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
setResponseJson(ctx, data)
|
||||
}
|
||||
|
||||
func SeasonNext(ctx *fasthttp.RequestCtx) {
|
||||
@@ -102,15 +104,7 @@ func SeasonNext(ctx *fasthttp.RequestCtx) {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = writeResponseBody(ctx, data)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
setResponseJson(ctx, data)
|
||||
}
|
||||
|
||||
func SeasonNextNext(ctx *fasthttp.RequestCtx) {
|
||||
@@ -119,15 +113,7 @@ func SeasonNextNext(ctx *fasthttp.RequestCtx) {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = writeResponseBody(ctx, data)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
setResponseJson(ctx, data)
|
||||
}
|
||||
|
||||
func SeasonLast(ctx *fasthttp.RequestCtx) {
|
||||
@@ -136,15 +122,7 @@ func SeasonLast(ctx *fasthttp.RequestCtx) {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = writeResponseBody(ctx, data)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
setResponseJson(ctx, data)
|
||||
}
|
||||
|
||||
func AnimeGet(ctx *fasthttp.RequestCtx) {
|
||||
@@ -171,14 +149,7 @@ func AnimeGet(ctx *fasthttp.RequestCtx) {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
_, err = ctx.Write(bytes)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
setResponseJson(ctx, bytes)
|
||||
}
|
||||
|
||||
func AnimeSearchGet(ctx *fasthttp.RequestCtx) {
|
||||
@@ -193,14 +164,7 @@ func AnimeSearchGet(ctx *fasthttp.RequestCtx) {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
_, err = ctx.Write(bytes)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
setResponseJson(ctx, bytes)
|
||||
}
|
||||
|
||||
func AppointmentGet(ctx *fasthttp.RequestCtx) {
|
||||
@@ -220,14 +184,7 @@ func AppointmentGet(ctx *fasthttp.RequestCtx) {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
_, err = ctx.Write(bytes)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
setResponseJson(ctx, bytes)
|
||||
}
|
||||
|
||||
func ChatGet(ctx *fasthttp.RequestCtx) {
|
||||
@@ -266,7 +223,7 @@ func ChatGet(ctx *fasthttp.RequestCtx) {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
ctx.SetContentType("text/plain; charset=utf-8")
|
||||
ctx.SetContentType(textContentType)
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
}
|
||||
|
||||
@@ -276,7 +233,7 @@ func LogGet(ctx *fasthttp.RequestCtx) {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
ctx.SetContentType("text/plain; charset=utf-8")
|
||||
ctx.SetContentType(textContentType)
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
}
|
||||
|
||||
@@ -285,7 +242,7 @@ func UserGet(ctx *fasthttp.RequestCtx) {
|
||||
users := make([]User, 0)
|
||||
if usrVal != nil {
|
||||
// get specific user
|
||||
user, _, err := GetUserData(fmt.Sprintf("%s", usrVal))
|
||||
user, _, err := GetUser(fmt.Sprintf("%s", usrVal))
|
||||
if err != nil {
|
||||
ctx.WriteString(err.Error())
|
||||
ctx.SetStatusCode(fasthttp.StatusNotFound)
|
||||
@@ -303,7 +260,7 @@ func UserGet(ctx *fasthttp.RequestCtx) {
|
||||
regUsers = make([]UserData, 0)
|
||||
}
|
||||
for _, u := range regUsers {
|
||||
user, _, err := GetUserData(u.Username)
|
||||
user, _, err := GetUser(u.Username)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
@@ -317,14 +274,11 @@ func UserGet(ctx *fasthttp.RequestCtx) {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
_, err = ctx.Write(bytes)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
setResponseJson(ctx, bytes)
|
||||
}
|
||||
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
func UserStashGet(ctx *fasthttp.RequestCtx) {
|
||||
processUserStashReq(ctx, false)
|
||||
}
|
||||
|
||||
func WatchGet(ctx *fasthttp.RequestCtx) {
|
||||
@@ -339,14 +293,7 @@ func WatchGet(ctx *fasthttp.RequestCtx) {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
_, err = ctx.Write(bytes)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
setResponseJson(ctx, bytes)
|
||||
}
|
||||
|
||||
func WatchExtendedGet(ctx *fasthttp.RequestCtx) {
|
||||
@@ -382,14 +329,7 @@ func WatchExtendedGet(ctx *fasthttp.RequestCtx) {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
_, err = ctx.Write(bytes)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
setResponseJson(ctx, bytes)
|
||||
}
|
||||
|
||||
func Register(ctx *fasthttp.RequestCtx) {
|
||||
@@ -424,7 +364,7 @@ func Register(ctx *fasthttp.RequestCtx) {
|
||||
return
|
||||
}
|
||||
// check user legit
|
||||
userData, _, err := GetUserData(register.Username)
|
||||
userData, _, err := GetUser(register.Username)
|
||||
if err != nil {
|
||||
ctx.WriteString(err.Error())
|
||||
ctx.SetStatusCode(fasthttp.StatusExpectationFailed)
|
||||
@@ -457,13 +397,11 @@ func Register(ctx *fasthttp.RequestCtx) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetBody(body)
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
setResponseJson(ctx, body)
|
||||
}
|
||||
|
||||
func RegisterUpdate(ctx *fasthttp.RequestCtx) {
|
||||
auth := ctx.Request.Header.Peek("X-HUSO-AUTH")
|
||||
auth := ctx.Request.Header.Peek(xHusoAuth)
|
||||
if auth == nil || string(auth) == "" || !strings.Contains(string(ctx.Request.Header.ContentType()), "application/json") {
|
||||
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
||||
return
|
||||
@@ -526,9 +464,7 @@ func RegisterUpdate(ctx *fasthttp.RequestCtx) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetBody(body)
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
setResponseJson(ctx, body)
|
||||
}
|
||||
|
||||
func AppointmentPost(ctx *fasthttp.RequestCtx) {
|
||||
@@ -536,7 +472,7 @@ func AppointmentPost(ctx *fasthttp.RequestCtx) {
|
||||
}
|
||||
|
||||
func ChatPost(ctx *fasthttp.RequestCtx) {
|
||||
auth := ctx.Request.Header.Peek("X-HUSO-AUTH")
|
||||
auth := ctx.Request.Header.Peek(xHusoAuth)
|
||||
if ctx.UserValue("id") == nil || ctx.UserValue("user") == nil || auth == nil || string(auth) == "" || !strings.Contains(string(ctx.Request.Header.ContentType()), "text/plain") {
|
||||
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
||||
return
|
||||
@@ -577,7 +513,7 @@ func ChatPost(ctx *fasthttp.RequestCtx) {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
ctx.SetContentType("text/plain; charset=utf-8")
|
||||
ctx.SetContentType(textContentType)
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
}
|
||||
|
||||
@@ -585,12 +521,16 @@ func WatchPost(ctx *fasthttp.RequestCtx) {
|
||||
processUpdateReq(ctx, true)
|
||||
}
|
||||
|
||||
func UserStashPut(ctx *fasthttp.RequestCtx) {
|
||||
processUserStashReq(ctx, true)
|
||||
}
|
||||
|
||||
func AppointmentDelete(ctx *fasthttp.RequestCtx) {
|
||||
processUpdateAppointmentReq(ctx, false)
|
||||
}
|
||||
|
||||
func UnRegister(ctx *fasthttp.RequestCtx) {
|
||||
auth := ctx.Request.Header.Peek("X-HUSO-AUTH")
|
||||
auth := ctx.Request.Header.Peek(xHusoAuth)
|
||||
if auth == nil || string(auth) == "" || !strings.Contains(string(ctx.Request.Header.ContentType()), "application/json") {
|
||||
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
||||
return
|
||||
@@ -641,9 +581,7 @@ func UnRegister(ctx *fasthttp.RequestCtx) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetBody(body)
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
setResponseJson(ctx, body)
|
||||
}
|
||||
|
||||
func WatchDelete(ctx *fasthttp.RequestCtx) {
|
||||
@@ -706,11 +644,17 @@ func watchGetLogic(ctx *fasthttp.RequestCtx) ([]AnimeUser, error) {
|
||||
}
|
||||
animesUsers = filteredAnimes
|
||||
}
|
||||
|
||||
sort.Slice(animesUsers, func(i, j int) bool { return animesUsers[i].Anime < animesUsers[j].Anime })
|
||||
sort.SliceStable(animesUsers, func(i, j int) bool {
|
||||
return AverageEpPerUser(animesUsers[i].Users) > AverageEpPerUser(animesUsers[j].Users)
|
||||
})
|
||||
|
||||
return animesUsers, err
|
||||
}
|
||||
|
||||
func processUpdateReq(ctx *fasthttp.RequestCtx, update bool) {
|
||||
auth := ctx.Request.Header.Peek("X-HUSO-AUTH")
|
||||
auth := ctx.Request.Header.Peek(xHusoAuth)
|
||||
if ctx.UserValue("user") == nil || auth == nil || string(auth) == "" || !strings.Contains(string(ctx.Request.Header.ContentType()), "application/json") {
|
||||
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
||||
return
|
||||
@@ -778,16 +722,11 @@ func processUpdateReq(ctx *fasthttp.RequestCtx, update bool) {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
err = writeResponseBody(ctx, data)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
setResponseJson(ctx, data)
|
||||
}
|
||||
|
||||
func processUpdateAppointmentReq(ctx *fasthttp.RequestCtx, update bool) {
|
||||
auth := ctx.Request.Header.Peek("X-HUSO-AUTH")
|
||||
auth := ctx.Request.Header.Peek(xHusoAuth)
|
||||
if ctx.UserValue("user") == nil || auth == nil || string(auth) == "" || !strings.Contains(string(ctx.Request.Header.ContentType()), "application/json") {
|
||||
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
||||
return
|
||||
@@ -867,22 +806,58 @@ func processUpdateAppointmentReq(ctx *fasthttp.RequestCtx, update bool) {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
err = writeResponseBody(ctx, data)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
setResponseJson(ctx, data)
|
||||
}
|
||||
|
||||
func writeResponseBody(ctx *fasthttp.RequestCtx, bytes []byte) error {
|
||||
_, err := ctx.Write(bytes)
|
||||
if err != nil {
|
||||
return err
|
||||
func processUserStashReq(ctx *fasthttp.RequestCtx, update bool) {
|
||||
auth := ctx.Request.Header.Peek(xHusoAuth)
|
||||
dataPath := fmt.Sprintf("%s", ctx.UserValue("data"))
|
||||
if auth == nil || string(auth) == "" || dataPath == "" {
|
||||
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
|
||||
username := fmt.Sprintf("%s", ctx.UserValue("user"))
|
||||
legit, _ := GheddoAuth(username, string(auth))
|
||||
if !legit {
|
||||
ctx.SetStatusCode(fasthttp.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
if update {
|
||||
compressed, err := CompressZstd(ctx.PostBody())
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
err = DbSave(bucketStash, fmt.Sprintf("%s.%s", username, dataPath), compressed)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetStatusCode(fasthttp.StatusAccepted)
|
||||
} else {
|
||||
compressed, err := DbRead(bucketStash, []byte(fmt.Sprintf("%s.%s", username, dataPath)))
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
decompressed, err := DecompressZstd(compressed)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetBody(decompressed)
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
}
|
||||
}
|
||||
|
||||
func setResponseJson(ctx *fasthttp.RequestCtx, bytes []byte) {
|
||||
ctx.SetBody(bytes)
|
||||
ctx.SetContentType(jsonContentType)
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
return err
|
||||
}
|
||||
|
||||
func addErrorToCtx(ctx *fasthttp.RequestCtx, err error) {
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func Arbeiten() {
|
||||
for range time.Tick(time.Hour) {
|
||||
for range time.Tick(10 * time.Minute) {
|
||||
Arbeit()
|
||||
}
|
||||
}
|
||||
@@ -27,8 +27,11 @@ func Arbeit() {
|
||||
}
|
||||
} else {
|
||||
cleared := 0
|
||||
lastAnnounce.Lock()
|
||||
defer lastAnnounce.Unlock()
|
||||
newCheckDate := time.Now()
|
||||
for _, a := range appoints {
|
||||
if a.Time.Before(time.Now().Add(time.Hour * 22)) {
|
||||
if a.Time.Add(22 * time.Hour).Before(newCheckDate) {
|
||||
// appointment expired
|
||||
keyBytes := Int64AndDateToBytes(a.Anime, a.Time)
|
||||
err = DbDelete(bucketAppoint, string(keyBytes))
|
||||
@@ -38,8 +41,14 @@ func Arbeit() {
|
||||
} else {
|
||||
cleared++
|
||||
}
|
||||
} else {
|
||||
if lastAnnounce.stamp.Add(time.Hour).Before(a.Time) && newCheckDate.Add(time.Hour).After(a.Time) {
|
||||
// This has not happened and is happening soon
|
||||
go AnnounceBomb(a.Anime, a.Time.Unix(), time.Until(a.Time.Add(-25*time.Minute)))
|
||||
}
|
||||
}
|
||||
}
|
||||
lastAnnounce.stamp = newCheckDate
|
||||
if cleared > 0 {
|
||||
color.Infof("Cleared %d expired appointments\n", cleared)
|
||||
logOut.WriteLine(fmt.Sprintf("♻️ Cleared %d expired appointments", cleared))
|
||||
@@ -55,8 +64,13 @@ func Arbeit() {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ACTUALLY STUPID ENOUGH TO FIX A LOT OF PROBLEMS
|
||||
animeListCache.Reset()
|
||||
|
||||
color.Infoln("Animelisten abfragen...")
|
||||
logOut.WriteLine("📜 Animelisten abfragen...")
|
||||
//logOut.WriteLine("📜 Animelisten abfragen...")
|
||||
|
||||
count := 0
|
||||
// iterate anime
|
||||
for _, a := range animesUsers {
|
||||
@@ -108,8 +122,11 @@ func Arbeit() {
|
||||
count++
|
||||
}
|
||||
}
|
||||
color.Infof("%d Sachen aktualisiert\n", count)
|
||||
logOut.WriteLine(fmt.Sprintf("📜 %d Sachen aktualisiert", count))
|
||||
|
||||
if count > 0 {
|
||||
color.Infof("%d Sachen aktualisiert\n", count)
|
||||
logOut.WriteLine(fmt.Sprintf("📜 %d Sachen aktualisiert", count))
|
||||
}
|
||||
}
|
||||
|
||||
func BissleArbeiten() {
|
||||
@@ -130,7 +147,7 @@ func BissleArbeit() {
|
||||
}
|
||||
} else {
|
||||
for _, u := range regUsers {
|
||||
_, _, err = GetUserData(u.Username)
|
||||
err = refreshUser(u.Username)
|
||||
if err != nil {
|
||||
color.Errorln(err.Error())
|
||||
logOut.WriteError(err)
|
||||
@@ -234,14 +251,21 @@ func refreshAnime(animeId int64) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
animeCache.Set(key, data)
|
||||
return nil
|
||||
return animeCache.Set(key, data)
|
||||
}
|
||||
|
||||
func refreshSeason(season string) error {
|
||||
_, bytes, err := GetSeasonDataAll(season)
|
||||
if err == nil {
|
||||
err = seasoncache.Set(season, bytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
return seasoncache.Set(season, bytes)
|
||||
}
|
||||
|
||||
func refreshUser(username string) error {
|
||||
_, data, err := GetUserData(username)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return userCache.Set(username, data)
|
||||
}
|
||||
|
||||
44
rechner.go
44
rechner.go
@@ -1,12 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha512"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/klauspost/compress/zstd"
|
||||
)
|
||||
|
||||
func Sauce(malid int64, username string) string {
|
||||
@@ -43,3 +47,43 @@ func BytesToInt64AndDate(bytes []byte) (int64, time.Time, error) {
|
||||
func Int64AndDateToBytes(num int64, appoint time.Time) []byte {
|
||||
return []byte(fmt.Sprintf("%d%s%s", num, AppointSplit, appoint.Format(time.RFC3339)))
|
||||
}
|
||||
|
||||
func CompressZstd(src []byte) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
encoder, err := zstd.NewWriter(&buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reader := bytes.NewReader(src)
|
||||
_, err = io.Copy(encoder, reader)
|
||||
if err != nil {
|
||||
encoder.Close()
|
||||
return nil, err
|
||||
}
|
||||
err = encoder.Close()
|
||||
return buf.Bytes(), err
|
||||
}
|
||||
|
||||
func DecompressZstd(src []byte) ([]byte, error) {
|
||||
reader := bytes.NewReader(src)
|
||||
decoder, err := zstd.NewReader(reader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer decoder.Close()
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err = io.Copy(&buf, decoder)
|
||||
return buf.Bytes(), err
|
||||
}
|
||||
|
||||
func AverageEpPerUser(users []WatchUser) float64 {
|
||||
if len(users) == 0 {
|
||||
return 0.0
|
||||
}
|
||||
res := 0.0
|
||||
for _, u := range users {
|
||||
res += float64(u.Progress)
|
||||
}
|
||||
return res / float64(len(users))
|
||||
}
|
||||
|
||||
13
schaffer.go
13
schaffer.go
@@ -253,6 +253,19 @@ func AddToChat(old, new, user string) string {
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func GetAnimeWatchFromDb(animeId int64) (*AnimeUser, error) {
|
||||
dbAnime, err := ReadAnimeUsers()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, a := range dbAnime {
|
||||
if a.Anime == animeId {
|
||||
return &a, err
|
||||
}
|
||||
}
|
||||
return nil, errors.New("anime not found")
|
||||
}
|
||||
|
||||
func CheckAnimeExistInDb(animeId int64) (bool, error) {
|
||||
dbAnime, err := ReadAnimeUsers()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user