mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-16 02:49:52 +01:00
Compare commits
12 Commits
7185544e03
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17a754b918 | ||
|
|
730f91e74e | ||
|
|
dbd34abea1 | ||
|
|
beed95eed9 | ||
|
|
074a4a88f0 | ||
|
|
fa765859e4 | ||
|
|
1f59f13bfc | ||
|
|
92660df667 | ||
|
|
db4ca8e4cf | ||
|
|
13b2335ae8 | ||
|
|
1bb8536334 | ||
|
|
6a2e573828 |
12
go.mod
12
go.mod
@@ -1,17 +1,17 @@
|
||||
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/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/klauspost/compress v1.15.9
|
||||
github.com/valyala/fasthttp v1.38.0
|
||||
github.com/valyala/fasthttp v1.39.0
|
||||
github.com/valyala/quicktemplate v1.7.0
|
||||
github.com/xujiajun/nutsdb v0.9.0
|
||||
github.com/xujiajun/nutsdb v0.10.0
|
||||
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9
|
||||
)
|
||||
|
||||
@@ -25,6 +25,6 @@ require (
|
||||
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-20220722155217-630584e8d5aa // indirect
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
|
||||
golang.org/x/crypto v0.0.0-20220824171710-5757bc0c5503 // indirect
|
||||
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24 // indirect
|
||||
)
|
||||
|
||||
19
go.sum
19
go.sum
@@ -4,8 +4,8 @@ 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=
|
||||
@@ -40,8 +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.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=
|
||||
@@ -50,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-20220722155217-630584e8d5aa h1:zuSxTR4o9y82ebqCUJYNGJbGPo6sKVl54f/TVDObg1c=
|
||||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/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=
|
||||
@@ -72,8 +73,8 @@ 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-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/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=
|
||||
|
||||
14
huso.go
14
huso.go
@@ -20,7 +20,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
husoVersion = "1.5"
|
||||
husoVersion = "1.7.1"
|
||||
registerSecret = "綾波レイ"
|
||||
seasonStrJikan = "seasons/"
|
||||
userApiJikan = "users/"
|
||||
@@ -51,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
|
||||
@@ -64,6 +67,7 @@ var (
|
||||
logOut *RingBuf
|
||||
buildTime string
|
||||
buildCommit string
|
||||
lastAnnounce *SomewhatThreadSafeTime
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -73,7 +77,7 @@ 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)
|
||||
@@ -104,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)
|
||||
}
|
||||
@@ -123,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")
|
||||
|
||||
|
||||
17
klotz.go
17
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 {
|
||||
@@ -327,3 +331,8 @@ type MovieChart struct {
|
||||
AvgScore float64 `json:"avgScore"`
|
||||
UserCount int `json:"userCount"`
|
||||
}
|
||||
|
||||
type SomewhatThreadSafeTime struct {
|
||||
sync.Mutex
|
||||
stamp time.Time
|
||||
}
|
||||
|
||||
33
knecht.go
33
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 {
|
||||
|
||||
28
labersack.go
28
labersack.go
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/gookit/color"
|
||||
@@ -30,10 +31,10 @@ func SendAppointBroadcast(creator string, app *Appointment) {
|
||||
msgStart.WriteString(fmt.Sprintf("<@%d>", uData.DiscordID))
|
||||
}
|
||||
|
||||
msgs := fmt.Sprintf("🗓️ New appointment for [%s](https://anime.hanami.family/anime/%d) at\n<t:%d:F>\n<t:%d:R>", anime.Title, app.Anime, app.Time.Unix(), app.Time.Unix())
|
||||
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("https://anime.hanami.family/anime/%d", app.Anime),
|
||||
URL: fmt.Sprintf("%s%d", *husoWebAnimeUri, app.Anime),
|
||||
Thumbnail: &discordgo.MessageEmbedThumbnail{URL: anime.ImageLargeURL},
|
||||
Color: 7187428,
|
||||
Footer: &discordgo.MessageEmbedFooter{
|
||||
@@ -46,7 +47,7 @@ func SendAppointBroadcast(creator string, app *Appointment) {
|
||||
msge.Author = &discordgo.MessageEmbedAuthor{
|
||||
Name: user.Username,
|
||||
IconURL: user.ImageURL,
|
||||
URL: fmt.Sprintf("https://anime.hanami.family/user/%s", creator),
|
||||
URL: fmt.Sprintf("%s%s", *husoWebUserUri, creator),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +55,7 @@ func SendAppointBroadcast(creator string, app *Appointment) {
|
||||
Content: msgStart.String(),
|
||||
Embeds: []*discordgo.MessageEmbed{&msge},
|
||||
}
|
||||
_, err = discc.ChannelMessageSendComplex("998277590609559632", &msgc)
|
||||
_, err = discc.ChannelMessageSendComplex(*discordChannel, &msgc)
|
||||
|
||||
if err != nil {
|
||||
color.Errorln(err.Error())
|
||||
@@ -62,14 +63,19 @@ func SendAppointBroadcast(creator string, app *Appointment) {
|
||||
}
|
||||
}
|
||||
|
||||
func AnnounceAppointmentSoon(app *Appointment) {
|
||||
if app != nil && discc != nil {
|
||||
watchData, err := GetAnimeWatchFromDb(app.Anime)
|
||||
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(app.Anime)
|
||||
anime, err := SearchAnime(animeId)
|
||||
if err != nil {
|
||||
color.Errorln(err.Error())
|
||||
return
|
||||
@@ -84,10 +90,10 @@ func AnnounceAppointmentSoon(app *Appointment) {
|
||||
msgStart.WriteString(fmt.Sprintf("<@%d>", uData.DiscordID))
|
||||
}
|
||||
|
||||
msgs := fmt.Sprintf("⏰ Appointment starting <t:%d:R>!\n[%s](https://anime.hanami.family/anime/%d) at\n<t:%d:F>", app.Time.Unix(), anime.Title, app.Anime, app.Time.Unix())
|
||||
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("https://anime.hanami.family/anime/%d", app.Anime),
|
||||
URL: fmt.Sprintf("%s%d", *husoWebAnimeUri, animeId),
|
||||
Thumbnail: &discordgo.MessageEmbedThumbnail{URL: anime.ImageLargeURL},
|
||||
Color: 7187428,
|
||||
Footer: &discordgo.MessageEmbedFooter{
|
||||
@@ -99,7 +105,7 @@ func AnnounceAppointmentSoon(app *Appointment) {
|
||||
Content: msgStart.String(),
|
||||
Embeds: []*discordgo.MessageEmbed{&msge},
|
||||
}
|
||||
_, err = discc.ChannelMessageSendComplex("998277590609559632", &msgc)
|
||||
_, 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)
|
||||
}
|
||||
|
||||
166
ober.go
166
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))
|
||||
@@ -62,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
|
||||
@@ -87,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) {
|
||||
@@ -104,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) {
|
||||
@@ -121,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) {
|
||||
@@ -138,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) {
|
||||
@@ -173,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) {
|
||||
@@ -195,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) {
|
||||
@@ -222,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) {
|
||||
@@ -268,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)
|
||||
}
|
||||
|
||||
@@ -278,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)
|
||||
}
|
||||
|
||||
@@ -319,14 +274,7 @@ func UserGet(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 UserStashGet(ctx *fasthttp.RequestCtx) {
|
||||
@@ -345,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) {
|
||||
@@ -388,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) {
|
||||
@@ -463,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
|
||||
@@ -532,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) {
|
||||
@@ -542,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
|
||||
@@ -583,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)
|
||||
}
|
||||
|
||||
@@ -600,7 +530,7 @@ func AppointmentDelete(ctx *fasthttp.RequestCtx) {
|
||||
}
|
||||
|
||||
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
|
||||
@@ -651,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) {
|
||||
@@ -716,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
|
||||
@@ -788,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
|
||||
@@ -877,16 +806,11 @@ 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 processUserStashReq(ctx *fasthttp.RequestCtx, update bool) {
|
||||
auth := ctx.Request.Header.Peek("X-HUSO-AUTH")
|
||||
auth := ctx.Request.Header.Peek(xHusoAuth)
|
||||
dataPath := fmt.Sprintf("%s", ctx.UserValue("data"))
|
||||
if auth == nil || string(auth) == "" || dataPath == "" {
|
||||
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
||||
@@ -930,14 +854,10 @@ func processUserStashReq(ctx *fasthttp.RequestCtx, update bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func writeResponseBody(ctx *fasthttp.RequestCtx, bytes []byte) error {
|
||||
_, err := ctx.Write(bytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
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(29 * time.Minute) {
|
||||
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.Add(22 * time.Hour).Before(time.Now()) {
|
||||
if a.Time.Add(22 * time.Hour).Before(newCheckDate) {
|
||||
// appointment expired
|
||||
keyBytes := Int64AndDateToBytes(a.Anime, a.Time)
|
||||
err = DbDelete(bucketAppoint, string(keyBytes))
|
||||
@@ -38,11 +41,14 @@ func Arbeit() {
|
||||
} else {
|
||||
cleared++
|
||||
}
|
||||
} else if time.Now().Add(4*time.Minute).Before(a.Time) && time.Now().Add(33*time.Minute).After(a.Time) {
|
||||
// This has not happened and is happening soon
|
||||
AnnounceAppointmentSoon(&a)
|
||||
} 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))
|
||||
@@ -58,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 {
|
||||
@@ -111,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() {
|
||||
|
||||
11
rechner.go
11
rechner.go
@@ -76,3 +76,14 @@ func DecompressZstd(src []byte) ([]byte, error) {
|
||||
_, 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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user