From 0ded60ef1b0a43c72adb2aa9a13fcaa868b8f7a7 Mon Sep 17 00:00:00 2001 From: JustHumanz Date: Thu, 25 Mar 2021 21:18:43 +0700 Subject: [PATCH 1/7] Add pixiv in art> command --- pkg/database/fanart.go | 101 ++++++++++++++++++++++++++++++++++------- 1 file changed, 85 insertions(+), 16 deletions(-) diff --git a/pkg/database/fanart.go b/pkg/database/fanart.go index 31a38a1c..b60fe39a 100644 --- a/pkg/database/fanart.go +++ b/pkg/database/fanart.go @@ -20,7 +20,7 @@ func GetFanart(GroupID, MemberID int64) (*DataFanart, error) { err error ) - Twitter := func(State string) error { + Twitter := func() error { rows, err = DB.Query(`SELECT Twitter.* FROM Vtuber.Twitter Inner Join Vtuber.VtuberMember on VtuberMember.id = Twitter.VtuberMember_id Inner Join Vtuber.VtuberGroup on VtuberGroup.id = VtuberMember.VtuberGroup_id where (VtuberGroup.id=? OR VtuberMember.id=?) ORDER by RAND() LIMIT 1`, GroupID, MemberID) if err != nil { return err @@ -35,10 +35,10 @@ func GetFanart(GroupID, MemberID int64) (*DataFanart, error) { return err } } - Data.State = State + Data.State = "Twitter" return nil } - Tbilibili := func(State string) error { + Tbilibili := func() error { rows, err = DB.Query(`SELECT TBiliBili.* FROM Vtuber.TBiliBili Inner Join Vtuber.VtuberMember on VtuberMember.id = TBiliBili.VtuberMember_id Inner Join Vtuber.VtuberGroup on VtuberGroup.id = VtuberMember.VtuberGroup_id where (VtuberGroup.id=? OR VtuberMember.id=?) ORDER by RAND() LIMIT 1`, GroupID, MemberID) if err != nil { return err @@ -53,26 +53,95 @@ func GetFanart(GroupID, MemberID int64) (*DataFanart, error) { return err } } - Data.State = State + Data.State = "TBiliBili" return nil } - if gacha() { - err := Twitter("Twitter") - if err != nil { - return nil, err - } - } else { - err := Tbilibili("TBiliBili") + Pixiv := func() error { + rows, err = DB.Query(`SELECT Pixiv.* FROM Vtuber.Pixiv Inner Join Vtuber.VtuberMember on VtuberMember.id = Pixiv.VtuberMember_id Inner Join Vtuber.VtuberGroup on VtuberGroup.id = VtuberMember.VtuberGroup_id where (VtuberGroup.id=? OR VtuberMember.id=?) ORDER by RAND() LIMIT 1`, GroupID, MemberID) if err != nil { - return nil, err + return err + } else if err == sql.ErrNoRows { + return errors.New("Vtuber don't have any fanart") } - if Data.ID == 0 { - log.Warn("Tbilibili nill") - err := Twitter("Twitter") + defer rows.Close() + for rows.Next() { + err = rows.Scan(&Data.ID, &Data.PermanentURL, &Data.Author, &PhotoTmp, &Data.Text, &Data.PixivID, &Data.Member.ID) if err != nil { - return nil, err + return err + } + } + Data.State = "Pixiv" + return nil + } + + if gacha() { + if gacha() { + if gacha() { + err := Pixiv() + if err != nil { + return nil, err + } + } else { + err := Tbilibili() + if err != nil { + log.Error(err) + err := Pixiv() + if err != nil { + return nil, err + } + } + } + } else { + if gacha() { + err := Twitter() + if err != nil { + return nil, err + } + } else { + err := Tbilibili() + if err != nil { + log.Error(err) + err := Twitter() + if err != nil { + return nil, err + } + } + } + } + } else { + if gacha() { + if gacha() { + err := Pixiv() + if err != nil { + return nil, err + } + } else { + err := Tbilibili() + if err != nil { + log.Error(err) + err := Pixiv() + if err != nil { + return nil, err + } + } + } + } else { + if gacha() { + err := Twitter() + if err != nil { + return nil, err + } + } else { + err := Tbilibili() + if err != nil { + log.Error(err) + err := Twitter() + if err != nil { + return nil, err + } + } } } } From e487a0c2c3b5dd92387d74f4d5b5af4a34a74830 Mon Sep 17 00:00:00 2001 From: JustHumanz Date: Thu, 25 Mar 2021 21:19:32 +0700 Subject: [PATCH 2/7] Add pixiv in art> command --- pkg/database/fanart.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/database/fanart.go b/pkg/database/fanart.go index b60fe39a..b9266570 100644 --- a/pkg/database/fanart.go +++ b/pkg/database/fanart.go @@ -25,7 +25,7 @@ func GetFanart(GroupID, MemberID int64) (*DataFanart, error) { if err != nil { return err } else if err == sql.ErrNoRows { - return errors.New("Vtuber don't have any fanart") + return errors.New("Vtuber don't have any fanart in Twitter") } defer rows.Close() @@ -43,7 +43,7 @@ func GetFanart(GroupID, MemberID int64) (*DataFanart, error) { if err != nil { return err } else if err == sql.ErrNoRows { - return errors.New("Vtuber don't have any fanart") + return errors.New("Vtuber don't have any fanart BiliBili") } defer rows.Close() @@ -62,7 +62,7 @@ func GetFanart(GroupID, MemberID int64) (*DataFanart, error) { if err != nil { return err } else if err == sql.ErrNoRows { - return errors.New("Vtuber don't have any fanart") + return errors.New("Vtuber don't have any fanart Pixiv") } defer rows.Close() From 56c53002ed5c09240ec0bf2a4568e503c62c0e0c Mon Sep 17 00:00:00 2001 From: JustHumanz Date: Thu, 25 Mar 2021 22:11:02 +0700 Subject: [PATCH 3/7] Rework fanart send notif --- pkg/database/struct.go | 2 + service/fanart/bilibili/bilibili.go | 100 +++++++-------- service/fanart/lewd/lewd.go | 38 ++---- service/fanart/notif/notif.go | 95 +++++++++++++++ service/fanart/pixiv/pixiv.go | 72 ++--------- service/fanart/twitter/notif.go | 181 ---------------------------- service/fanart/twitter/scraper.go | 6 +- service/fanart/twitter/twitter.go | 16 ++- 8 files changed, 185 insertions(+), 325 deletions(-) create mode 100644 service/fanart/notif/notif.go delete mode 100755 service/fanart/twitter/notif.go diff --git a/pkg/database/struct.go b/pkg/database/struct.go index c2f0a2af..385f4f18 100755 --- a/pkg/database/struct.go +++ b/pkg/database/struct.go @@ -12,6 +12,7 @@ type DataFanart struct { Member Member PermanentURL string Author string + AuthorAvatar string Photos []string Videos string Text string @@ -19,6 +20,7 @@ type DataFanart struct { Dynamic_id string TweetID string PixivID string + Lewd bool State string } diff --git a/service/fanart/bilibili/bilibili.go b/service/fanart/bilibili/bilibili.go index 7c6d85de..e8d3f792 100755 --- a/service/fanart/bilibili/bilibili.go +++ b/service/fanart/bilibili/bilibili.go @@ -1,12 +1,8 @@ package bilibili import ( - "context" "encoding/json" "net/url" - "strconv" - "strings" - "time" "github.com/bwmarrin/discordgo" "github.com/robfig/cron/v3" @@ -16,6 +12,7 @@ import ( database "github.com/JustHumanz/Go-Simp/pkg/database" "github.com/JustHumanz/Go-Simp/pkg/engine" network "github.com/JustHumanz/Go-Simp/pkg/network" + "github.com/JustHumanz/Go-Simp/service/fanart/notif" ) //Public variable @@ -64,6 +61,7 @@ func Start(a *discordgo.Session, b *cron.Cron, c database.VtubersPayload, d conf TBiliData := database.DataFanart{ PermanentURL: "https://t.bilibili.com/" + v.Desc.DynamicIDStr + "?tab=2", Author: v.Desc.UserProfile.Info.Uname, + AuthorAvatar: v.Desc.UserProfile.Info.Face, Likes: v.Desc.Like, Photos: img, Dynamic_id: v.Desc.DynamicIDStr, @@ -76,66 +74,70 @@ func Start(a *discordgo.Session, b *cron.Cron, c database.VtubersPayload, d conf log.Error(err) } if New { - GroupData := Group.RemoveNillIconURL() - ChannelData, err := database.ChannelTag(TBiliData.Member.ID, 1, config.Default, TBiliData.Member.Region) - if err != nil { - log.Error(err) - } - Color, err := engine.GetColor(config.TmpDir, TBiliData.Photos[0]) if err != nil { log.Error(err) } - tags := "" - for i, Channel := range ChannelData { - Channel.SetMember(TBiliData.Member) - ctx := context.Background() - UserTagsList, err := Channel.GetUserList(ctx) + + notif.SendNude(TBiliData, Group, Bot, Color) + /* + GroupData := Group.RemoveNillIconURL() + ChannelData, err := database.ChannelTag(TBiliData.Member.ID, 1, config.Default, TBiliData.Member.Region) if err != nil { log.Error(err) - break - } - if UserTagsList != nil { - tags = strings.Join(UserTagsList, " ") - } else { - tags = "_" } - if tags == "_" && Group.GroupName == config.Indie && !Channel.IndieNotif { - //do nothing,like my life - } else { - tmp, err := Bot.ChannelMessageSendEmbed(Channel.ChannelID, engine.NewEmbed(). - SetAuthor(strings.Title(GroupData.GroupName), GroupData.IconURL). - SetTitle(TBiliData.Author). - SetURL(TBiliData.PermanentURL). - SetThumbnail(v.Desc.UserProfile.Info.Face). - SetDescription(TBiliData.Text). - SetImage(TBiliData.Photos[0]). - AddField("User Tags", tags). - SetFooter("1/"+strconv.Itoa(len(TBiliData.Photos))+" photos", config.BiliBiliIMG). - InlineAllFields(). - SetColor(Color).MessageEmbed) + tags := "" + for i, Channel := range ChannelData { + Channel.SetMember(TBiliData.Member) + ctx := context.Background() + UserTagsList, err := Channel.GetUserList(ctx) if err != nil { - log.Error(tmp, err.Error()) - err = Channel.DelChannel(err.Error()) + log.Error(err) + break + } + if UserTagsList != nil { + tags = strings.Join(UserTagsList, " ") + } else { + tags = "_" + } + + if tags == "_" && Group.GroupName == config.Indie && !Channel.IndieNotif { + //do nothing,like my life + } else { + tmp, err := Bot.ChannelMessageSendEmbed(Channel.ChannelID, engine.NewEmbed(). + SetAuthor(strings.Title(GroupData.GroupName), GroupData.IconURL). + SetTitle(TBiliData.Author). + SetURL(TBiliData.PermanentURL). + SetThumbnail(v.Desc.UserProfile.Info.Face). + SetDescription(TBiliData.Text). + SetImage(TBiliData.Photos[0]). + AddField("User Tags", tags). + SetFooter("1/"+strconv.Itoa(len(TBiliData.Photos))+" photos", config.BiliBiliIMG). + InlineAllFields(). + SetColor(Color).MessageEmbed) + if err != nil { + log.Error(tmp, err.Error()) + err = Channel.DelChannel(err.Error()) + if err != nil { + log.Error(err) + } + } + err = engine.Reacting(map[string]string{ + "ChannelID": Channel.ChannelID, + }, Bot) if err != nil { log.Error(err) } } - err = engine.Reacting(map[string]string{ - "ChannelID": Channel.ChannelID, - }, Bot) - if err != nil { - log.Error(err) + if i%config.Waiting == 0 && config.GoSimpConf.LowResources { + log.WithFields(log.Fields{ + "Func": "BiliBili Fanart", + }).Warn(config.FanartSleep) + time.Sleep(config.FanartSleep) } } - if i%config.Waiting == 0 && config.GoSimpConf.LowResources { - log.WithFields(log.Fields{ - "Func": "BiliBili Fanart", - }).Warn(config.FanartSleep) - time.Sleep(config.FanartSleep) - } - } + */ } } } diff --git a/service/fanart/lewd/lewd.go b/service/fanart/lewd/lewd.go index 9cf25b62..4b9053f6 100644 --- a/service/fanart/lewd/lewd.go +++ b/service/fanart/lewd/lewd.go @@ -12,6 +12,7 @@ import ( "github.com/JustHumanz/Go-Simp/pkg/database" "github.com/JustHumanz/Go-Simp/pkg/engine" "github.com/JustHumanz/Go-Simp/pkg/network" + "github.com/JustHumanz/Go-Simp/service/fanart/notif" "github.com/bwmarrin/discordgo" "github.com/robfig/cron/v3" log "github.com/sirupsen/logrus" @@ -48,32 +49,7 @@ func Start(a *discordgo.Session, b *cron.Cron, c database.VtubersPayload, d conf }).Info("Check lewd pic") var ( - DanPayload []Danbooru - SendFanart = func(FanArt database.DataFanart, AuthorImg string, Color int) { - Group := Group.RemoveNillIconURL() - ChannelData, err := database.ChannelTag(Member.ID, 0, config.LewdChannel, Member.Region) - if err != nil { - log.Error(err) - } - icon := config.TwitterIMG - if FanArt.State == config.PixivArt { - icon = config.PixivIMG - } - - for _, Channel := range ChannelData { - Msg, err := Bot.ChannelMessageSendEmbed(Channel.ChannelID, engine.NewEmbed(). - SetAuthor(strings.Title(Group.GroupName), Group.IconURL). - SetTitle(FanArt.Author). - SetURL(FanArt.PermanentURL). - SetThumbnail(AuthorImg). - SetDescription(FanArt.Text). - SetImage(FanArt.Photos[0]). - SetColor(Color).SetFooter("1/"+strconv.Itoa(len(FanArt.Photos)), icon).MessageEmbed) - if err != nil { - log.Error(err, Msg) - } - } - } + DanPayload []Danbooru TwitterHandler = func(ID []string) error { TweetRes, err := config.Scraper.GetTweet(ID[len(ID)-1]) if err != nil { @@ -87,12 +63,14 @@ func Start(a *discordgo.Session, b *cron.Cron, c database.VtubersPayload, d conf FanArtData := database.DataFanart{ PermanentURL: TweetRes.PermanentURL, Author: TweetRes.Username, + AuthorAvatar: engine.GetAuthorAvatar(TweetRes.Username), Photos: TweetRes.Photos, Videos: Video, Text: TweetRes.Text, TweetID: TweetRes.ID, Member: Member, State: config.TwitterArt, + Lewd: true, } err = database.AddLewd(FanArtData) if err != nil { @@ -101,10 +79,11 @@ func Start(a *discordgo.Session, b *cron.Cron, c database.VtubersPayload, d conf Color, err := engine.GetColor(config.TmpDir, TweetRes.Photos[0]) if err != nil { - return err + log.Error(err) } - SendFanart(FanArtData, engine.GetAuthorAvatar(TweetRes.Username), Color) + notif.SendNude(FanArtData, Group, Bot, Color) + return nil } ) @@ -190,6 +169,7 @@ func Start(a *discordgo.Session, b *cron.Cron, c database.VtubersPayload, d conf FanArtData := database.DataFanart{ PermanentURL: "https://www.pixiv.net/en/artworks/" + strconv.Itoa(Dan.PixivID), Author: UserBody["name"].(string), + AuthorAvatar: config.PixivProxy + UserBody["imageBig"].(string), Photos: []string{FixImg}, Text: Body["title"].(string), PixivID: strconv.Itoa(Dan.PixivID), @@ -206,7 +186,7 @@ func Start(a *discordgo.Session, b *cron.Cron, c database.VtubersPayload, d conf log.Error(err) } - SendFanart(FanArtData, config.PixivProxy+UserBody["imageBig"].(string), Color) + notif.SendNude(FanArtData, Group, Bot, Color) } } else if Dan.IsTwitter() { if database.IsLewdNew("Twitter", Dan.Source) { diff --git a/service/fanart/notif/notif.go b/service/fanart/notif/notif.go new file mode 100644 index 00000000..03386409 --- /dev/null +++ b/service/fanart/notif/notif.go @@ -0,0 +1,95 @@ +package notif + +import ( + "context" + "strings" + "time" + + "github.com/JustHumanz/Go-Simp/pkg/config" + "github.com/JustHumanz/Go-Simp/pkg/database" + "github.com/JustHumanz/Go-Simp/pkg/engine" + "github.com/bwmarrin/discordgo" + log "github.com/sirupsen/logrus" +) + +func SendNude(Art database.DataFanart, Group database.Group, Bot *discordgo.Session, Color int) { + Group.RemoveNillIconURL() + for _, Member := range Group.Members { + if Art.Member.ID == Member.ID { + var ( + ChannelData []database.DiscordChannel + err1 error + ) + if Art.Lewd { + ChannelData, err1 = database.ChannelTag(Member.ID, 1, config.LewdChannel, Member.Region) + if err1 != nil { + log.Error(err1) + } + } else { + ChannelData, err1 = database.ChannelTag(Member.ID, 1, config.Default, Member.Region) + if err1 != nil { + log.Error(err1) + } + } + + icon := "" + if Art.State == config.PixivArt { + icon = config.PixivIMG + } else if Art.State == config.TwitterArt { + icon = config.TwitterIMG + } else { + icon = config.BiliBiliIMG + } + + tags := "" + for i, Channel := range ChannelData { + Channel.SetMember(Member) + UserTagsList, err := Channel.GetUserList(context.Background()) + if err != nil { + log.Error(err) + break + } + if UserTagsList != nil { + tags = strings.Join(UserTagsList, " ") + } else { + tags = "_" + } + + if tags == "_" && Group.GroupName == config.Indie && !Channel.IndieNotif { + //do nothing,like my life + } else { + tmp, err := Bot.ChannelMessageSendEmbed(Channel.ChannelID, engine.NewEmbed(). + SetAuthor(strings.Title(Group.GroupName), Group.IconURL). + SetTitle(Art.Author). + SetURL(Art.PermanentURL). + SetThumbnail(Art.AuthorAvatar). + SetDescription(Art.Text). + SetImage(Art.Photos...). + AddField("User Tags", tags). + SetFooter(Art.State, icon). + InlineAllFields(). + SetColor(Color).MessageEmbed) + if err != nil { + log.Error(tmp, err.Error()) + err = Channel.DelChannel(err.Error()) + if err != nil { + log.Error(err) + } + } + err = engine.Reacting(map[string]string{ + "ChannelID": Channel.ChannelID, + }, Bot) + if err != nil { + log.Error(err) + } + } + if i%config.Waiting == 0 && config.GoSimpConf.LowResources { + log.WithFields(log.Fields{ + "Func": Art.State + "Fanart", + }).Warn(config.FanartSleep) + time.Sleep(config.FanartSleep) + } + } + } + } +} diff --git a/service/fanart/pixiv/pixiv.go b/service/fanart/pixiv/pixiv.go index 2ee41b95..879183fd 100644 --- a/service/fanart/pixiv/pixiv.go +++ b/service/fanart/pixiv/pixiv.go @@ -17,6 +17,7 @@ import ( "github.com/JustHumanz/Go-Simp/pkg/database" "github.com/JustHumanz/Go-Simp/pkg/engine" "github.com/JustHumanz/Go-Simp/pkg/network" + "github.com/JustHumanz/Go-Simp/service/fanart/notif" "github.com/bwmarrin/discordgo" "github.com/robfig/cron/v3" log "github.com/sirupsen/logrus" @@ -97,16 +98,6 @@ func CheckPixiv() { Img := Body["urls"].(map[string]interface{}) FixImg := Img["original"].(string) - path, err := DownloadImg(Img["mini"].(string)) - if err != nil { - log.Error(err) - } - - Color, err := engine.GetColor("", path) - if err != nil { - return err - } - usrbyte, err := network.Curl(config.PixivUserEnd+Tags["authorId"].(string), nil) if err != nil { return err @@ -129,74 +120,29 @@ func CheckPixiv() { FixFanArt := database.DataFanart{ PermanentURL: BaseURL + v2["id"].(string), Author: v2["userName"].(string), + AuthorAvatar: config.PixivProxy + UserBody["imageBig"].(string), Photos: []string{FixImg}, Text: TextFix, PixivID: v2["id"].(string), Member: Member, } - AuthorProfile := config.PixivProxy + UserBody["imageBig"].(string) new, err := FixFanArt.CheckPixivFanArt() if err != nil { return err } if new { - url := BaseURL + v2["id"].(string) - ChannelData, err := database.ChannelTag(Member.ID, 1, config.Default, Member.Region) + path, err := DownloadImg(Img["mini"].(string)) if err != nil { - return err + log.Error(err) } - var ( - tags string - Msg = "Pixiv" - ) - - for i, Channel := range ChannelData { - Channel.SetMember(Member) - ctx := context.Background() - UserTagsList, err := Channel.GetUserList(ctx) - if err != nil { - return err - } - - if UserTagsList != nil { - tags = strings.Join(UserTagsList, " ") - } else { - tags = "_" - } - - if tags == "_" && Group.GroupName == config.Indie && !Channel.IndieNotif { - //do nothing,like my life - } else { - msg, err := Bot.ChannelMessageSendEmbed(Channel.ChannelID, engine.NewEmbed(). - SetAuthor(strings.Title(Group.GroupName), Group.IconURL). - SetTitle(FixFanArt.Author). - SetURL(url). - SetThumbnail(AuthorProfile). - SetDescription(TextFix). - SetImage(config.PixivProxy+FixImg). - AddField("User Tags", tags). - SetColor(Color). - SetFooter(Msg, config.PixivIMG).MessageEmbed) - if err != nil { - log.Error(msg, err) - err = Channel.DelChannel(err.Error()) - if err != nil { - return err - } - } - engine.Reacting(map[string]string{ - "ChannelID": Channel.ChannelID, - }, Bot) - } - if i%config.Waiting == 0 && configfile.LowResources { - log.WithFields(log.Fields{ - "Func": "Pixiv Fanart", - }).Warn(config.FanartSleep) - time.Sleep(config.FanartSleep) - } + Color, err := engine.GetColor("", path) + if err != nil { + return err } + + notif.SendNude(FixFanArt, Group, Bot, Color) } } if i == 10 { diff --git a/service/fanart/twitter/notif.go b/service/fanart/twitter/notif.go deleted file mode 100755 index fefcd109..00000000 --- a/service/fanart/twitter/notif.go +++ /dev/null @@ -1,181 +0,0 @@ -package twitter - -import ( - "context" - "regexp" - "strconv" - "strings" - "time" - - config "github.com/JustHumanz/Go-Simp/pkg/config" - "github.com/JustHumanz/Go-Simp/pkg/database" - engine "github.com/JustHumanz/Go-Simp/pkg/engine" - log "github.com/sirupsen/logrus" -) - -func SendFanart(Data []database.DataFanart, DataGroup database.Group) { - Group := DataGroup.RemoveNillIconURL() - for _, MemberFanart := range Data { - url := MemberFanart.PermanentURL - ChannelData, err := database.ChannelTag(MemberFanart.Member.ID, 1, config.Default, MemberFanart.Member.Region) - if err != nil { - log.Error(err) - } - var ( - tags string - Media string - Msg string - ) - - if MemberFanart.Videos != "" { - Media = MemberFanart.Videos - Msg = "1/1 Videos" - } else if len(MemberFanart.Photos) > 0 { - Media = MemberFanart.Photos[0] - Msg = "1/" + strconv.Itoa(len(MemberFanart.Photos)) + " Photos" - } else { - Media = config.NotFound - Msg = "Photos/Video oversize,check original post" - } - - Color, err := engine.GetColor(config.TmpDir, Media) - if err != nil { - log.Error(err) - } - - for i, Channel := range ChannelData { - Channel.SetMember(MemberFanart.Member) - ctx := context.Background() - UserTagsList, err := Channel.GetUserList(ctx) - if err != nil { - log.Error(err) - break - } - - if UserTagsList != nil { - tags = strings.Join(UserTagsList, " ") - } else { - tags = "_" - } - - if tags == "_" && Group.GroupName == config.Indie && !Channel.IndieNotif { - //do nothing,like my life - } else { - msg, err := Bot.ChannelMessageSendEmbed(Channel.ChannelID, engine.NewEmbed(). - SetAuthor(strings.Title(Group.GroupName), Group.IconURL). - SetTitle("@"+MemberFanart.Author). - SetURL(url). - SetThumbnail(engine.GetAuthorAvatar(MemberFanart.Author)). - SetDescription(RemoveTwitterShortLink(MemberFanart.Text)). - SetImage(Media). - AddField("User Tags", tags). - SetColor(Color). - SetFooter(Msg, config.TwitterIMG).MessageEmbed) - if err != nil { - log.Error(msg, err) - err = Channel.DelChannel(err.Error()) - if err != nil { - log.Error(err) - } - } - engine.Reacting(map[string]string{ - "ChannelID": Channel.ChannelID, - }, Bot) - } - - if i%config.Waiting == 0 && configfile.LowResources { - log.WithFields(log.Fields{ - "Func": "Twitter Fanart", - }).Warn(config.FanartSleep) - time.Sleep(config.FanartSleep) - } - } - } -} - -/* -//SendNude Send to Discord channel -func (Data *TwitterFanart) SendNude() { - for _, Fanart := range Data.Fanart { - url := Fanart.PermanentURL - ID, DiscordChannelID := database.ChannelTag(Data.Member.ID, 1, "") - Bot := runner.Bot - wg := new(sync.WaitGroup) - for i := 0; i < len(DiscordChannelID); i++ { - wg.Add(1) - go func(DiscordChannel string, ID int, Data *TwitterFanart, wg *sync.WaitGroup) { - defer wg.Done() - ChannelState := database.DiscordChannel{ - ChannelID: DiscordChannel, - VtuberGroupID: Data.Group.ID, - } - UserTagsList := database.GetUserList(ID, Data.Member.ID) - - var ( - tags string - GroupIcon string - Media string - Msg string - ) - - if len(Fanart.Videos) > 0 { - Media = Fanart.Videos[0].Preview - Msg = "1/1 Videos" - } else if len(Fanart.Photos) > 0 { - Media = Fanart.Photos[0] - Msg = "1/" + strconv.Itoa(len(Fanart.Photos)) + " Photos" - } else { - Media = config.NotFound - Msg = "Photos/Video oversize,check original post" - } - - Color, err := engine.GetColor("/tmp/tw", Media) - if err != nil { - log.Error(err) - } - - if match, _ := regexp.MatchString("404.jpg", Data.Group.IconURL); match { - GroupIcon = "" - } else { - GroupIcon = Data.Group.IconURL - } - if UserTagsList != nil { - tags = strings.Join(UserTagsList, " ") - } else { - tags = "_" - } - if tags == "_" && Data.Group.GroupName == "Independen" { - //do nothing,like my life - } else { - msg, err := Bot.ChannelMessageSendEmbed(DiscordChannel, engine.NewEmbed(). - SetAuthor(strings.Title(Data.Group.GroupName), GroupIcon). - SetTitle("@"+Fanart.Username). - SetURL(url). - SetThumbnail(engine.GetAuthorAvatar(Fanart.Username)). - SetDescription(RemoveTwitterShortLink(Fanart.Text)). - SetImage(Media). - AddField("User Tags", tags). - SetColor(Color). - SetFooter(Msg, config.TwitterIMG).MessageEmbed) - if err != nil { - log.Error(msg, err) - err = ChannelState.DelChannel(err.Error()) - if err != nil { - log.Error(err) - } - } - engine.Reacting(map[string]string{ - "ChannelID": DiscordChannel, - }, Bot) - } - }(DiscordChannelID[i], ID[i], Data, wg) - } - wg.Wait() - } -} - -*/ -//RemoveTwitterShortLink remove twitter shotlink -func RemoveTwitterShortLink(text string) string { - return regexp.MustCompile(`(?m)^(.*?)https:\/\/t.co\/.+`).ReplaceAllString(text, "${1}$2") -} diff --git a/service/fanart/twitter/scraper.go b/service/fanart/twitter/scraper.go index 3d571478..8ebec95c 100755 --- a/service/fanart/twitter/scraper.go +++ b/service/fanart/twitter/scraper.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/JustHumanz/Go-Simp/pkg/database" + engine "github.com/JustHumanz/Go-Simp/pkg/engine" twitterscraper "github.com/n0madic/twitter-scraper" log "github.com/sirupsen/logrus" ) @@ -30,9 +31,10 @@ func CreatePayload(Group database.Group, Scraper *twitterscraper.Scraper, Limit if strings.ToLower("#"+TweetHashtag) == strings.ToLower(MemberHashtag.TwitterHashtags) && !tweet.IsQuoted && !tweet.IsReply && MemberHashtag.Name != "Kaichou" && len(tweet.Photos) > 0 { TweetArt := database.DataFanart{ PermanentURL: tweet.PermanentURL, - Author: tweet.Username, + Author: "@" + tweet.Username, + AuthorAvatar: engine.GetAuthorAvatar(tweet.Username), TweetID: tweet.ID, - Text: tweet.Text, + Text: RemoveTwitterShortLink(tweet.Text), Photos: tweet.Photos, Likes: tweet.Likes, Member: MemberHashtag, diff --git a/service/fanart/twitter/twitter.go b/service/fanart/twitter/twitter.go index 40865889..e1256ee6 100755 --- a/service/fanart/twitter/twitter.go +++ b/service/fanart/twitter/twitter.go @@ -1,10 +1,13 @@ package twitter import ( + "regexp" "sync" config "github.com/JustHumanz/Go-Simp/pkg/config" "github.com/JustHumanz/Go-Simp/pkg/database" + engine "github.com/JustHumanz/Go-Simp/pkg/engine" + "github.com/JustHumanz/Go-Simp/service/fanart/notif" "github.com/bwmarrin/discordgo" "github.com/robfig/cron/v3" log "github.com/sirupsen/logrus" @@ -39,9 +42,20 @@ func CheckNew() { "Group": Group.GroupName, }).Error(err) } else { - SendFanart(Fanarts, Group) + for _, Art := range Fanarts { + Color, err := engine.GetColor(config.TmpDir, Art.Photos[0]) + if err != nil { + log.Error(err) + } + notif.SendNude(Art, Group, Bot, Color) + } } }(GroupData, wg) } wg.Wait() } + +//RemoveTwitterShortLink remove twitter shotlink +func RemoveTwitterShortLink(text string) string { + return regexp.MustCompile(`(?m)^(.*?)https:\/\/t.co\/.+`).ReplaceAllString(text, "${1}$2") +} From be9ce9148c7f2dcc30a75a2c085180f251c2b2d1 Mon Sep 17 00:00:00 2001 From: JustHumanz Date: Thu, 25 Mar 2021 22:38:50 +0700 Subject: [PATCH 4/7] Add state in fanart & add cronjob to renew payload --- pkg/config/config.go | 5 ++- service/fanart/bilibili/bilibili.go | 61 +---------------------------- service/fanart/lewd/lewd.go | 2 +- service/fanart/pixiv/pixiv.go | 4 +- service/fanart/runner.go | 1 + service/fanart/twitter/scraper.go | 2 + service/rest-api/main.go | 35 ++++++++++------- service/subscriber/runner.go | 1 + 8 files changed, 33 insertions(+), 78 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 26ab798c..9db320fe 100755 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -119,8 +119,9 @@ const ( UnknownStatus = "unknown" //Fanart - TwitterArt = "twitter" - PixivArt = "pixiv" + TwitterArt = "twitter" + PixivArt = "pixiv" + BiliBiliArt = "bilibili" ) //ConfigFile config file struct for config.toml diff --git a/service/fanart/bilibili/bilibili.go b/service/fanart/bilibili/bilibili.go index e8d3f792..d75d218f 100755 --- a/service/fanart/bilibili/bilibili.go +++ b/service/fanart/bilibili/bilibili.go @@ -67,6 +67,7 @@ func Start(a *discordgo.Session, b *cron.Cron, c database.VtubersPayload, d conf Dynamic_id: v.Desc.DynamicIDStr, Text: STB.Item.Description, Member: Member, + State: config.BiliBiliArt, } New, err := TBiliData.CheckTBiliBiliFanArt() @@ -80,64 +81,6 @@ func Start(a *discordgo.Session, b *cron.Cron, c database.VtubersPayload, d conf } notif.SendNude(TBiliData, Group, Bot, Color) - /* - GroupData := Group.RemoveNillIconURL() - ChannelData, err := database.ChannelTag(TBiliData.Member.ID, 1, config.Default, TBiliData.Member.Region) - if err != nil { - log.Error(err) - } - - tags := "" - for i, Channel := range ChannelData { - Channel.SetMember(TBiliData.Member) - ctx := context.Background() - UserTagsList, err := Channel.GetUserList(ctx) - if err != nil { - log.Error(err) - break - } - if UserTagsList != nil { - tags = strings.Join(UserTagsList, " ") - } else { - tags = "_" - } - - if tags == "_" && Group.GroupName == config.Indie && !Channel.IndieNotif { - //do nothing,like my life - } else { - tmp, err := Bot.ChannelMessageSendEmbed(Channel.ChannelID, engine.NewEmbed(). - SetAuthor(strings.Title(GroupData.GroupName), GroupData.IconURL). - SetTitle(TBiliData.Author). - SetURL(TBiliData.PermanentURL). - SetThumbnail(v.Desc.UserProfile.Info.Face). - SetDescription(TBiliData.Text). - SetImage(TBiliData.Photos[0]). - AddField("User Tags", tags). - SetFooter("1/"+strconv.Itoa(len(TBiliData.Photos))+" photos", config.BiliBiliIMG). - InlineAllFields(). - SetColor(Color).MessageEmbed) - if err != nil { - log.Error(tmp, err.Error()) - err = Channel.DelChannel(err.Error()) - if err != nil { - log.Error(err) - } - } - err = engine.Reacting(map[string]string{ - "ChannelID": Channel.ChannelID, - }, Bot) - if err != nil { - log.Error(err) - } - } - if i%config.Waiting == 0 && config.GoSimpConf.LowResources { - log.WithFields(log.Fields{ - "Func": "BiliBili Fanart", - }).Warn(config.FanartSleep) - time.Sleep(config.FanartSleep) - } - } - */ } } } @@ -146,5 +89,5 @@ func Start(a *discordgo.Session, b *cron.Cron, c database.VtubersPayload, d conf } } }) - log.Info("Enable bilibili fanart module") + log.Info("Enable Bilibili fanart module") } diff --git a/service/fanart/lewd/lewd.go b/service/fanart/lewd/lewd.go index 4b9053f6..3718cd2e 100644 --- a/service/fanart/lewd/lewd.go +++ b/service/fanart/lewd/lewd.go @@ -30,7 +30,7 @@ func Start(a *discordgo.Session, b *cron.Cron, c database.VtubersPayload, d conf Bot = a VtubersData = c configfile = d - log.Info("Enable lewd fanart module") + log.Info("Enable Lewd fanart module") b.AddFunc(config.DanbooruFanart, func() { log.Info("Start Checking Danbooru lewd") for _, Group := range VtubersData.VtuberData { diff --git a/service/fanart/pixiv/pixiv.go b/service/fanart/pixiv/pixiv.go index 879183fd..492fa0f7 100644 --- a/service/fanart/pixiv/pixiv.go +++ b/service/fanart/pixiv/pixiv.go @@ -39,7 +39,6 @@ func Start(a *discordgo.Session, b *cron.Cron, c database.VtubersPayload, d conf Bot = a VtubersData = c configfile = d - CheckPixiv() b.AddFunc(config.PixivFanart, CheckPixiv) log.Info("Enable Pixiv fanart module") } @@ -125,6 +124,7 @@ func CheckPixiv() { Text: TextFix, PixivID: v2["id"].(string), Member: Member, + State: config.PixivArt, } new, err := FixFanArt.CheckPixivFanArt() @@ -141,7 +141,7 @@ func CheckPixiv() { if err != nil { return err } - + FixFanArt.Photos[0] = config.PixivProxy + FixImg notif.SendNude(FixFanArt, Group, Bot, Color) } } diff --git a/service/fanart/runner.go b/service/fanart/runner.go index 9e92dc9a..32456a4e 100755 --- a/service/fanart/runner.go +++ b/service/fanart/runner.go @@ -71,6 +71,7 @@ func main() { c := cron.New() c.Start() + c.AddFunc(config.CheckPayload, RequestPay) if *Twitter { twitter.Start(Bot, c, Payload, configfile) diff --git a/service/fanart/twitter/scraper.go b/service/fanart/twitter/scraper.go index 8ebec95c..2e229648 100755 --- a/service/fanart/twitter/scraper.go +++ b/service/fanart/twitter/scraper.go @@ -5,6 +5,7 @@ import ( "errors" "strings" + "github.com/JustHumanz/Go-Simp/pkg/config" "github.com/JustHumanz/Go-Simp/pkg/database" engine "github.com/JustHumanz/Go-Simp/pkg/engine" twitterscraper "github.com/n0madic/twitter-scraper" @@ -38,6 +39,7 @@ func CreatePayload(Group database.Group, Scraper *twitterscraper.Scraper, Limit Photos: tweet.Photos, Likes: tweet.Likes, Member: MemberHashtag, + State: config.TwitterArt, } if tweet.Videos != nil { TweetArt.Videos = tweet.Videos[0].Preview diff --git a/service/rest-api/main.go b/service/rest-api/main.go index de56cb71..1f40175d 100755 --- a/service/rest-api/main.go +++ b/service/rest-api/main.go @@ -12,6 +12,7 @@ import ( "github.com/JustHumanz/Go-Simp/pkg/database" "github.com/JustHumanz/Go-Simp/pkg/network" pilot "github.com/JustHumanz/Go-Simp/service/pilot/grpc" + "github.com/robfig/cron/v3" "github.com/gorilla/mux" log "github.com/sirupsen/logrus" @@ -29,24 +30,30 @@ func init() { configfile config.ConfigFile ) - res, err := gRCPconn.ReqData(context.Background(), &pilot.ServiceMessage{ - Message: "Send me nude", - Service: "Rest_API", - }) - if err != nil { - log.Fatalf("Error when request payload: %s", err) - } - err = json.Unmarshal(res.ConfigFile, &configfile) - if err != nil { - log.Panic(err) - } + RequestPayload := func() { + res, err := gRCPconn.ReqData(context.Background(), &pilot.ServiceMessage{ + Message: "Send me nude", + Service: "Rest_API", + }) + if err != nil { + log.Fatalf("Error when request payload: %s", err) + } + err = json.Unmarshal(res.ConfigFile, &configfile) + if err != nil { + log.Panic(err) + } - err = json.Unmarshal(res.VtuberPayload, &Payload) - if err != nil { - log.Panic(err) + err = json.Unmarshal(res.VtuberPayload, &Payload) + if err != nil { + log.Panic(err) + } } + RequestPayload() configfile.InitConf() + c := cron.New() + c.Start() + c.AddFunc(config.CheckPayload, RequestPayload) database.Start(configfile) go pilot.RunHeartBeat(gRCPconn, "Rest_API") } diff --git a/service/subscriber/runner.go b/service/subscriber/runner.go index 6008b079..a151a7b1 100755 --- a/service/subscriber/runner.go +++ b/service/subscriber/runner.go @@ -73,6 +73,7 @@ func main() { c := cron.New() c.Start() + c.AddFunc(config.CheckPayload, RequestPay) if *Youtube { c.AddFunc(config.YoutubeSubscriber, CheckYoutube) From d215b1f93ba13888c7271f02af744d25f8eef9ec Mon Sep 17 00:00:00 2001 From: JustHumanz Date: Fri, 26 Mar 2021 01:43:21 +0700 Subject: [PATCH 5/7] Fix fanbase in yt command --- service/frontend/youtube_handler.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/service/frontend/youtube_handler.go b/service/frontend/youtube_handler.go index 8efd048b..63b12009 100755 --- a/service/frontend/youtube_handler.go +++ b/service/frontend/youtube_handler.go @@ -201,6 +201,10 @@ func YoutubeMessage(s *discordgo.Session, m *discordgo.MessageCreate) { } } + if Member.Fanbase != "" { + FanBase = Member.Fanbase + } + view, err := strconv.Atoi(Youtube.Viewers) if err != nil { log.Error(err) From da3ae60da85a19052f29e561cfd796e5fddeb899 Mon Sep 17 00:00:00 2001 From: JustHumanz Date: Sat, 27 Mar 2021 05:56:02 +0700 Subject: [PATCH 6/7] Add group in fanart state & remove danbooru --- pkg/config/config.go | 1 + pkg/database/fanart.go | 258 ++++++++++++++------ pkg/database/struct.go | 23 -- service/fanart/Dockerfile | 2 +- service/fanart/bilibili/bilibili.go | 3 +- service/fanart/lewd/lewd.go | 213 ----------------- service/fanart/lewd/struct.go | 88 ------- service/fanart/notif/notif.go | 12 +- service/fanart/pixiv/pixiv.go | 359 +++++++++++++++++++--------- service/fanart/pixiv/pixivlewd.go | 88 +++++++ service/fanart/runner.go | 11 +- service/fanart/twitter/scraper.go | 75 +++++- service/fanart/twitter/twitter.go | 12 +- 13 files changed, 612 insertions(+), 533 deletions(-) delete mode 100644 service/fanart/lewd/lewd.go delete mode 100644 service/fanart/lewd/struct.go create mode 100644 service/fanart/pixiv/pixivlewd.go diff --git a/pkg/config/config.go b/pkg/config/config.go index 9db320fe..5244806c 100755 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -64,6 +64,7 @@ const ( BiliBiliFanart = "@every 0h6m0s" DanbooruFanart = "@every 0h4m0s" PixivFanart = "@every 0h15m0s" + PixivFanartLewd = "@every 0h20m0s" BiliBiliLive = "@every 0h7m0s" BiliBiliSpace = "@every 0h13m0s" Twitch = "@every 0h7m0s" diff --git a/pkg/database/fanart.go b/pkg/database/fanart.go index b9266570..f68945a4 100644 --- a/pkg/database/fanart.go +++ b/pkg/database/fanart.go @@ -180,28 +180,6 @@ func (Data DataFanart) DeleteFanart(e string) error { } } -func IsLewdNew(s, ID string) bool { - var id int - if s == "Pixiv" { - err := DB.QueryRow(`SELECT id FROM Lewd WHERE PixivID=?`, ID).Scan(&id) - if err == sql.ErrNoRows { - log.WithFields(log.Fields{ - "State": "Pixiv", - }).Info("New Lewd Fanart") - return true - } - } else { - Twitter := strings.Split(ID, "/") - err := DB.QueryRow(`SELECT id FROM Lewd WHERE TweetID=?`, Twitter[len(Twitter)-1]).Scan(&id) - if err == sql.ErrNoRows { - log.WithFields(log.Fields{ - "State": "Twitter", - }).Info("New Lewd Fanart") - return true - } - } - return false -} func AddLewd(Data DataFanart) error { stmt, err := DB.Prepare(`INSERT INTO Lewd (PermanentURL,Author,Photos,Videos,Text,TweetID,PixivID,VtuberMember_id) values(?,?,?,?,?,?,?,?)`) if err != nil { @@ -223,46 +201,68 @@ func AddLewd(Data DataFanart) error { //CheckMemberFanart Check if `that` was a new fanart func (FanArt DataFanart) CheckTweetFanArt() (bool, error) { - var ( - id int - ) - err := DB.QueryRow(`SELECT id FROM Twitter WHERE TweetID=?`, FanArt.TweetID).Scan(&id) - if err == sql.ErrNoRows { - log.WithFields(log.Fields{ - "Name": FanArt.Member.EnName, - "Hashtag": FanArt.Member.TwitterHashtags, - }).Info("New Fanart") - - stmt, err := DB.Prepare(`INSERT INTO Twitter (PermanentURL,Author,Likes,Photos,Videos,Text,TweetID,VtuberMember_id) values(?,?,?,?,?,?,?,?)`) - if err != nil { - return false, err - } - defer stmt.Close() - - res, err := stmt.Exec(FanArt.PermanentURL, FanArt.Author, FanArt.Likes, strings.Join(FanArt.Photos, "\n"), FanArt.Videos, FanArt.Text, FanArt.TweetID, FanArt.Member.ID) - if err != nil { - return false, err - } - - _, err = res.LastInsertId() - if err != nil { - return false, err + if FanArt.Lewd { + var ( + id int + ) + err := DB.QueryRow(`SELECT id FROM Lewd WHERE TweetID=?`, FanArt.TweetID).Scan(&id) + if err == sql.ErrNoRows { + log.WithFields(log.Fields{ + "Name": FanArt.Member.EnName, + "Hashtag": FanArt.Member.TwitterHashtags, + "Lewd": FanArt.Lewd, + "URL": FanArt.PermanentURL, + }).Info("New Fanart") + err = AddLewd(FanArt) + if err != nil { + return false, err + } + return true, nil } - return true, nil - } else if err != nil { - return false, err } else { - if !config.GoSimpConf.LowResources { - //update like + var ( + id int + ) + err := DB.QueryRow(`SELECT id FROM Twitter WHERE TweetID=?`, FanArt.TweetID).Scan(&id) + if err == sql.ErrNoRows { log.WithFields(log.Fields{ "Name": FanArt.Member.EnName, "Hashtag": FanArt.Member.TwitterHashtags, - "Likes": FanArt.Likes, - }).Info("Update like") - _, err := DB.Exec(`Update Twitter set Likes=? Where id=? `, FanArt.Likes, id) + "Lewd": FanArt.Lewd, + "URL": FanArt.PermanentURL, + }).Info("New Fanart") + + stmt, err := DB.Prepare(`INSERT INTO Twitter (PermanentURL,Author,Likes,Photos,Videos,Text,TweetID,VtuberMember_id) values(?,?,?,?,?,?,?,?)`) + if err != nil { + return false, err + } + defer stmt.Close() + + res, err := stmt.Exec(FanArt.PermanentURL, FanArt.Author, FanArt.Likes, strings.Join(FanArt.Photos, "\n"), FanArt.Videos, FanArt.Text, FanArt.TweetID, FanArt.Member.ID) if err != nil { return false, err } + + _, err = res.LastInsertId() + if err != nil { + return false, err + } + return true, nil + } else if err != nil { + return false, err + } else { + if !config.GoSimpConf.LowResources { + //update like + log.WithFields(log.Fields{ + "Name": FanArt.Member.EnName, + "Hashtag": FanArt.Member.TwitterHashtags, + "Likes": FanArt.Likes, + }).Info("Update like") + _, err := DB.Exec(`Update Twitter set Likes=? Where id=? `, FanArt.Likes, id) + if err != nil { + return false, err + } + } } } return false, nil @@ -301,33 +301,141 @@ func (FanArt DataFanart) CheckTBiliBiliFanArt() (bool, error) { } func (FanArt DataFanart) CheckPixivFanArt() (bool, error) { - var tmp int64 - row := DB.QueryRow("SELECT id FROM Vtuber.Pixiv where PixivID=?", FanArt.PixivID) - err := row.Scan(&tmp) - if err == sql.ErrNoRows { - log.WithFields(log.Fields{ - "Vtuber": FanArt.Member.EnName, - "Img": FanArt.Photos, - }).Info("New Fanart") - stmt, err := DB.Prepare(`INSERT INTO Pixiv (PermanentURL,Author,Photos,Text,PixivID,VtuberMember_id) values(?,?,?,?,?,?)`) - if err != nil { + if FanArt.Lewd { + var tmp int64 + row := DB.QueryRow("SELECT id FROM Vtuber.Lewd where PixivID=?", FanArt.PixivID) + err := row.Scan(&tmp) + if err == sql.ErrNoRows { + log.WithFields(log.Fields{ + "Vtuber": FanArt.Member.EnName, + "Img": FanArt.Photos, + "URL": FanArt.PermanentURL, + }).Info("New Lewd Fanart") + err = AddLewd(FanArt) + if err != nil { + return false, err + } + return true, nil + } else if err != nil { return false, err + } else { + return false, errors.New(FanArt.Member.Name + " Still same") } - defer stmt.Close() + } else { + var tmp int64 + row := DB.QueryRow("SELECT id FROM Vtuber.Pixiv where PixivID=?", FanArt.PixivID) + err := row.Scan(&tmp) + if err == sql.ErrNoRows { + log.WithFields(log.Fields{ + "Vtuber": FanArt.Member.EnName, + "Img": FanArt.Photos, + "URL": FanArt.PermanentURL, + }).Info("New Fanart") + stmt, err := DB.Prepare(`INSERT INTO Pixiv (PermanentURL,Author,Photos,Text,PixivID,VtuberMember_id) values(?,?,?,?,?,?)`) + if err != nil { + return false, err + } + defer stmt.Close() - res, err := stmt.Exec(FanArt.PermanentURL, FanArt.Author, strings.Join(FanArt.Photos, "\n"), FanArt.Text, FanArt.PixivID, FanArt.Member.ID) - if err != nil { - return false, err - } + res, err := stmt.Exec(FanArt.PermanentURL, FanArt.Author, strings.Join(FanArt.Photos, "\n"), FanArt.Text, FanArt.PixivID, FanArt.Member.ID) + if err != nil { + return false, err + } - _, err = res.LastInsertId() - if err != nil { + _, err = res.LastInsertId() + if err != nil { + return false, err + } + return true, nil + + } else if err != nil { return false, err + } else { + return false, errors.New(FanArt.Member.Name + " Still same") } - return true, nil - } else if err != nil { - return false, err } - return false, nil +} + +//DataFanart fanart struct +type DataFanart struct { + ID int64 + Member Member + Group Group + PermanentURL string + Author string + AuthorAvatar string + Photos []string + Videos string + Text string + Likes int + Dynamic_id string + TweetID string + PixivID string + Lewd bool + State string +} + +func (Data *DataFanart) AddMember(new Member) *DataFanart { + Data.Member = new + return Data +} + +func (Data *DataFanart) AddGroup(new Group) *DataFanart { + Data.Group = new + return Data +} + +func (Data *DataFanart) AddPermanentURL(new string) *DataFanart { + Data.PermanentURL = new + return Data +} + +func (Data *DataFanart) AddAuthor(new string) *DataFanart { + Data.Author = new + return Data +} + +func (Data *DataFanart) AddAuthorAvatar(new string) *DataFanart { + Data.AuthorAvatar = new + return Data +} + +func (Data *DataFanart) AddPhotos(new []string) *DataFanart { + Data.Photos = new + return Data +} + +func (Data *DataFanart) AddVideos(new string) *DataFanart { + Data.Videos = new + return Data +} + +func (Data *DataFanart) AddText(new string) *DataFanart { + Data.Text = new + return Data +} + +func (Data *DataFanart) AddDynamicID(new string) *DataFanart { + Data.Dynamic_id = new + return Data +} + +func (Data *DataFanart) AddTweetID(new string) *DataFanart { + Data.TweetID = new + return Data +} + +func (Data *DataFanart) AddPixivID(new string) *DataFanart { + Data.PixivID = new + return Data +} + +func (Data *DataFanart) SetLewd(new bool) *DataFanart { + Data.Lewd = new + return Data +} +func (Data *DataFanart) SetState(new string) *DataFanart { + Data.State = new + return Data } diff --git a/pkg/database/struct.go b/pkg/database/struct.go index 385f4f18..1c09e693 100755 --- a/pkg/database/struct.go +++ b/pkg/database/struct.go @@ -6,29 +6,6 @@ import ( "time" ) -//DataFanart fanart struct -type DataFanart struct { - ID int64 - Member Member - PermanentURL string - Author string - AuthorAvatar string - Photos []string - Videos string - Text string - Likes int - Dynamic_id string - TweetID string - PixivID string - Lewd bool - State string -} - -func (Data *DataFanart) AddMember(new Member) *DataFanart { - Data.Member = new - return Data -} - //Group group struct type Group struct { ID int64 diff --git a/service/fanart/Dockerfile b/service/fanart/Dockerfile index 8a4b899c..13f1bcac 100755 --- a/service/fanart/Dockerfile +++ b/service/fanart/Dockerfile @@ -1,4 +1,4 @@ FROM go-simp WORKDIR /app/Go-Simp/service/fanart/ RUN go build -o fanart -CMD ["./fanart","-TwitterFanart","-BiliBiliFanart","-DanbooruLewd","-PixivFanArt"] \ No newline at end of file +CMD ["./fanart","-TwitterFanart","-BiliBiliFanart","-LewdFanart","-PixivFanArt"] \ No newline at end of file diff --git a/service/fanart/bilibili/bilibili.go b/service/fanart/bilibili/bilibili.go index d75d218f..9442df66 100755 --- a/service/fanart/bilibili/bilibili.go +++ b/service/fanart/bilibili/bilibili.go @@ -67,6 +67,7 @@ func Start(a *discordgo.Session, b *cron.Cron, c database.VtubersPayload, d conf Dynamic_id: v.Desc.DynamicIDStr, Text: STB.Item.Description, Member: Member, + Group: Group, State: config.BiliBiliArt, } @@ -80,7 +81,7 @@ func Start(a *discordgo.Session, b *cron.Cron, c database.VtubersPayload, d conf log.Error(err) } - notif.SendNude(TBiliData, Group, Bot, Color) + notif.SendNude(TBiliData, Bot, Color) } } } diff --git a/service/fanart/lewd/lewd.go b/service/fanart/lewd/lewd.go deleted file mode 100644 index 3718cd2e..00000000 --- a/service/fanart/lewd/lewd.go +++ /dev/null @@ -1,213 +0,0 @@ -package lewd - -import ( - "context" - "encoding/json" - "strconv" - "strings" - "sync" - "time" - - "github.com/JustHumanz/Go-Simp/pkg/config" - "github.com/JustHumanz/Go-Simp/pkg/database" - "github.com/JustHumanz/Go-Simp/pkg/engine" - "github.com/JustHumanz/Go-Simp/pkg/network" - "github.com/JustHumanz/Go-Simp/service/fanart/notif" - "github.com/bwmarrin/discordgo" - "github.com/robfig/cron/v3" - log "github.com/sirupsen/logrus" -) - -//Public variable -var ( - Bot *discordgo.Session - VtubersData database.VtubersPayload - configfile config.ConfigFile -) - -//Start start twitter module -func Start(a *discordgo.Session, b *cron.Cron, c database.VtubersPayload, d config.ConfigFile) { - Bot = a - VtubersData = c - configfile = d - log.Info("Enable Lewd fanart module") - b.AddFunc(config.DanbooruFanart, func() { - log.Info("Start Checking Danbooru lewd") - for _, Group := range VtubersData.VtuberData { - wg := new(sync.WaitGroup) - for i, Mem := range Group.Members { - wg.Add(1) - if i%10 == 0 { - time.Sleep(5 * time.Second) - } - go func(Member database.Member, w *sync.WaitGroup) { - defer w.Done() - log.WithFields(log.Fields{ - "Group": Group.GroupName, - "Vtubers": Member.Name, - "Site": "Danbooru", - }).Info("Check lewd pic") - - var ( - DanPayload []Danbooru - TwitterHandler = func(ID []string) error { - TweetRes, err := config.Scraper.GetTweet(ID[len(ID)-1]) - if err != nil { - return err - } - var Video string - if TweetRes.Videos != nil { - Video = TweetRes.Videos[0].URL - } - - FanArtData := database.DataFanart{ - PermanentURL: TweetRes.PermanentURL, - Author: TweetRes.Username, - AuthorAvatar: engine.GetAuthorAvatar(TweetRes.Username), - Photos: TweetRes.Photos, - Videos: Video, - Text: TweetRes.Text, - TweetID: TweetRes.ID, - Member: Member, - State: config.TwitterArt, - Lewd: true, - } - err = database.AddLewd(FanArtData) - if err != nil { - return err - } - - Color, err := engine.GetColor(config.TmpDir, TweetRes.Photos[0]) - if err != nil { - log.Error(err) - } - - notif.SendNude(FanArtData, Group, Bot, Color) - - return nil - } - ) - - if Member.TwitterLewd != "" { - log.WithFields(log.Fields{ - "Group": Group.GroupName, - "Vtubers": Member.Name, - "Site": "Twitter", - }).Info("Check lewd pic") - - for tweet := range config.Scraper.SearchTweets(context.Background(), Member.TwitterLewd+" AND -filter:replies -filter:retweets -filter:quote filter:media OR filter:link", 20) { - if len(tweet.Photos) > 0 && !tweet.IsQuoted && !tweet.IsReply { - if database.IsLewdNew("Twitter", tweet.PermanentURL) { - log.WithFields(log.Fields{ - "Group": Group.GroupName, - "Vtubers": Member.Name, - "TweetURL": tweet.PermanentURL, - }).Info("New Lewd pic from Twitter") - TweetID := strings.Split(tweet.PermanentURL, "/") - err := TwitterHandler(TweetID) - if err != nil { - log.Error(err) - } - } - } - } - } - - databyte, err := network.Curl(config.DanbooruEndPoint+strings.Replace(Member.EnName, " ", "_", -1)+"&limit=10", nil) - if err != nil { - log.Error(err) - } - - err = json.Unmarshal(databyte, &DanPayload) - if err != nil { - log.Error(err) - } - - for _, Dan := range DanPayload { - if Dan.CheckLewd() && Dan.IsBadID() { - if Dan.ParentID == nil { - if Dan.IsPixiv() { - if database.IsLewdNew("Pixiv", strconv.Itoa(Dan.PixivID)) { - log.WithFields(log.Fields{ - "Group": Group.GroupName, - "Vtubers": Member.Name, - "DanbooruID": Dan.ID, - }).Info("New Lewd pic from Pixiv") - - var ( - Illusts map[string]interface{} - User map[string]interface{} - ) - illusbyte, err := network.Curl(config.PixivIllustsEnd+strconv.Itoa(Dan.PixivID), nil) - if err != nil { - log.Error(err) - break - } - - err = json.Unmarshal(illusbyte, &Illusts) - if err != nil { - log.Error(err) - } - - Body := Illusts["body"].(map[string]interface{}) - Tags := Body["tags"].(map[string]interface{}) - Img := Body["urls"].(map[string]interface{}) - FixImg := config.PixivProxy + Img["original"].(string) - MiniImg := config.PixivProxy + Img["mini"].(string) - - usrbyte, err := network.Curl(config.PixivUserEnd+Tags["authorId"].(string), nil) - if err != nil { - log.Error(err) - } - - err = json.Unmarshal(usrbyte, &User) - if err != nil { - log.Error(err) - } - - UserBody := User["body"].(map[string]interface{}) - FanArtData := database.DataFanart{ - PermanentURL: "https://www.pixiv.net/en/artworks/" + strconv.Itoa(Dan.PixivID), - Author: UserBody["name"].(string), - AuthorAvatar: config.PixivProxy + UserBody["imageBig"].(string), - Photos: []string{FixImg}, - Text: Body["title"].(string), - PixivID: strconv.Itoa(Dan.PixivID), - Member: Member, - State: config.TwitterArt, - } - err = database.AddLewd(FanArtData) - if err != nil { - log.Error(err) - } - - Color, err := engine.GetColor(config.TmpDir, MiniImg) - if err != nil { - log.Error(err) - } - - notif.SendNude(FanArtData, Group, Bot, Color) - } - } else if Dan.IsTwitter() { - if database.IsLewdNew("Twitter", Dan.Source) { - log.WithFields(log.Fields{ - "Group": Group.GroupName, - "Vtubers": Member.Name, - "DanbooruID": Dan.ID, - }).Info("New Lewd pic from Twitter") - TweetID := strings.Split(Dan.Source, "/") - err := TwitterHandler(TweetID) - if err != nil { - log.Error(err) - } - } - } - } - } - } - }(Mem, wg) - } - wg.Wait() - } - }) -} diff --git a/service/fanart/lewd/struct.go b/service/fanart/lewd/struct.go deleted file mode 100644 index d65831af..00000000 --- a/service/fanart/lewd/struct.go +++ /dev/null @@ -1,88 +0,0 @@ -package lewd - -import ( - "regexp" - "strings" -) - -//Danbooru struct -type Danbooru struct { - ID int `json:"id,omitempty"` - CreatedAt string `json:"created_at"` - UploaderID int `json:"uploader_id"` - Score int `json:"score"` - Source string `json:"source"` - Md5 string `json:"md5,omitempty"` - LastCommentBumpedAt interface{} `json:"last_comment_bumped_at"` - Rating string `json:"rating"` - ImageWidth int `json:"image_width"` - ImageHeight int `json:"image_height"` - TagString string `json:"tag_string"` - IsNoteLocked bool `json:"is_note_locked"` - FavCount int `json:"fav_count"` - FileExt string `json:"file_ext,omitempty"` - LastNotedAt interface{} `json:"last_noted_at"` - IsRatingLocked bool `json:"is_rating_locked"` - ParentID interface{} `json:"parent_id"` - HasChildren bool `json:"has_children"` - ApproverID interface{} `json:"approver_id"` - TagCountGeneral int `json:"tag_count_general"` - TagCountArtist int `json:"tag_count_artist"` - TagCountCharacter int `json:"tag_count_character"` - TagCountCopyright int `json:"tag_count_copyright"` - FileSize int `json:"file_size"` - IsStatusLocked bool `json:"is_status_locked"` - PoolString string `json:"pool_string"` - UpScore int `json:"up_score"` - DownScore int `json:"down_score"` - IsPending bool `json:"is_pending"` - IsFlagged bool `json:"is_flagged"` - IsDeleted bool `json:"is_deleted"` - TagCount int `json:"tag_count"` - UpdatedAt string `json:"updated_at"` - IsBanned bool `json:"is_banned"` - PixivID int `json:"pixiv_id"` - LastCommentedAt interface{} `json:"last_commented_at"` - HasActiveChildren bool `json:"has_active_children"` - BitFlags int `json:"bit_flags"` - TagCountMeta int `json:"tag_count_meta"` - HasLarge bool `json:"has_large"` - HasVisibleChildren bool `json:"has_visible_children"` - TagStringGeneral string `json:"tag_string_general"` - TagStringCharacter string `json:"tag_string_character"` - TagStringCopyright string `json:"tag_string_copyright"` - TagStringArtist string `json:"tag_string_artist"` - TagStringMeta string `json:"tag_string_meta"` - FileURL string `json:"file_url,omitempty"` - LargeFileURL string `json:"large_file_url,omitempty"` - PreviewFileURL string `json:"preview_file_url,omitempty"` -} - -func (Data Danbooru) CheckLewd() bool { - safebutcrott, _ := regexp.MatchString("(swimsuits|lingerie|pantyshot)", Data.TagString) - if Data.Rating == "e" || Data.Rating == "q" || safebutcrott { - return true - } - return false -} - -func (Data Danbooru) IsPixiv() bool { - if Data.PixivID != 0 { - return true - } - return false -} - -func (Data Danbooru) IsTwitter() bool { - if strings.HasPrefix(Data.Source, "https://twitter.com") { - return true - } - return false -} - -func (Data Danbooru) IsBadID() bool { - if match, _ := regexp.MatchString("(bad_id|bad_pixiv_id)", Data.TagStringMeta); match { - return true - } - return false -} diff --git a/service/fanart/notif/notif.go b/service/fanart/notif/notif.go index 03386409..5f39b9a1 100644 --- a/service/fanart/notif/notif.go +++ b/service/fanart/notif/notif.go @@ -12,9 +12,9 @@ import ( log "github.com/sirupsen/logrus" ) -func SendNude(Art database.DataFanart, Group database.Group, Bot *discordgo.Session, Color int) { - Group.RemoveNillIconURL() - for _, Member := range Group.Members { +func SendNude(Art database.DataFanart, Bot *discordgo.Session, Color int) { + Art.Group.RemoveNillIconURL() + for _, Member := range Art.Group.Members { if Art.Member.ID == Member.ID { var ( ChannelData []database.DiscordChannel @@ -55,11 +55,11 @@ func SendNude(Art database.DataFanart, Group database.Group, Bot *discordgo.Sess tags = "_" } - if tags == "_" && Group.GroupName == config.Indie && !Channel.IndieNotif { + if tags == "_" && Art.Group.GroupName == config.Indie && !Channel.IndieNotif { //do nothing,like my life } else { tmp, err := Bot.ChannelMessageSendEmbed(Channel.ChannelID, engine.NewEmbed(). - SetAuthor(strings.Title(Group.GroupName), Group.IconURL). + SetAuthor(strings.Title(Art.Group.GroupName), Art.Group.IconURL). SetTitle(Art.Author). SetURL(Art.PermanentURL). SetThumbnail(Art.AuthorAvatar). @@ -85,7 +85,7 @@ func SendNude(Art database.DataFanart, Group database.Group, Bot *discordgo.Sess } if i%config.Waiting == 0 && config.GoSimpConf.LowResources { log.WithFields(log.Fields{ - "Func": Art.State + "Fanart", + "State": Art.State + " Fanart", }).Warn(config.FanartSleep) time.Sleep(config.FanartSleep) } diff --git a/service/fanart/pixiv/pixiv.go b/service/fanart/pixiv/pixiv.go index 492fa0f7..e7f0c535 100644 --- a/service/fanart/pixiv/pixiv.go +++ b/service/fanart/pixiv/pixiv.go @@ -5,7 +5,9 @@ import ( "encoding/json" "errors" "io" + "io/ioutil" "net/http" + "net/url" "os" "regexp" "sort" @@ -28,161 +30,300 @@ var ( Bot *discordgo.Session VtubersData database.VtubersPayload configfile config.ConfigFile + lewd bool ) const ( BaseURL = "https://www.pixiv.net/en/artworks/" + Limit = 20 ) //Start start twitter module -func Start(a *discordgo.Session, b *cron.Cron, c database.VtubersPayload, d config.ConfigFile) { +func Start(a *discordgo.Session, b *cron.Cron, c database.VtubersPayload, d config.ConfigFile, e bool) { Bot = a VtubersData = c configfile = d + lewd = e b.AddFunc(config.PixivFanart, CheckPixiv) - log.Info("Enable Pixiv fanart module") + if lewd { + b.AddFunc(config.PixivFanartLewd, CheckPixivLewd) + log.Info("Enable Pixiv lewd fanart module") + } else { + log.Info("Enable Pixiv fanart module") + } } //CheckNew Check new fanart func CheckPixiv() { - wg := new(sync.WaitGroup) - for _, GroupData := range VtubersData.VtuberData { - wg.Add(1) - go func(Group database.Group, wg *sync.WaitGroup) { - defer wg.Done() - for _, Member := range Group.Members { - Pixiv := func(Payload string) error { - var Art PixivArtworks + for _, Group := range VtubersData.VtuberData { + var wg sync.WaitGroup + for i, Member := range Group.Members { + wg.Add(1) + go func(wg *sync.WaitGroup, Member database.Member) { + defer wg.Done() + FixFanArt := &database.DataFanart{ + Member: Member, + Group: Group, + Lewd: false, + } + if Member.JpName != "" { log.WithFields(log.Fields{ - "Member": Member.EnName, + "Member": Member.JpName, "Group": Group.GroupName, + "Lewd": false, }).Info("Start curl pixiv") - body, err := network.Curl(Payload, nil) + URLJP := GetPixivURL(url.QueryEscape(Member.JpName)) + err := Pixiv(URLJP, FixFanArt, false) + if err != nil { + log.Error(err) + } + } + + if Member.EnName == Member.Name { + if Member.EnName != "" { + log.WithFields(log.Fields{ + "Member": Member.EnName, + "Group": Group.GroupName, + "Lewd": false, + }).Info("Start curl pixiv") + URLEN := GetPixivURL(url.QueryEscape(Member.EnName)) + err := Pixiv(URLEN, FixFanArt, false) + if err != nil { + log.Error(err) + } + + } + } else { + if Member.EnName != "" { + log.WithFields(log.Fields{ + "Member": Member.EnName, + "Group": Group.GroupName, + "Lewd": false, + }).Info("Start curl pixiv") + URLEN := GetPixivURL(url.QueryEscape(Member.EnName)) + err := Pixiv(URLEN, FixFanArt, false) + if err != nil { + log.Error(err) + } + + } + if Member.Name != "" { + log.WithFields(log.Fields{ + "Member": Member.Name, + "Group": Group.GroupName, + "Lewd": false, + }).Info("Start curl pixiv") + URL := GetPixivURL(url.QueryEscape(Member.Name)) + err := Pixiv(URL, FixFanArt, false) + if err != nil { + log.Error(err) + } + } + } + + }(&wg, Member) + + if i%4 == 0 { + wg.Wait() + } + + } + wg.Wait() + } +} + +func Pixiv(p string, FixFanArt *database.DataFanart, l bool) error { + var Art PixivArtworks + req, err := http.NewRequest("GET", p, nil) + if err != nil { + return err + } + req.Header.Set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0") + req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8") + req.Header.Set("Accept-Language", "en-US,en;q=0.5") + req.Header.Set("Dnt", "1") + req.Header.Set("Upgrade-Insecure-Requests", "1") + req.Header.Set("Connection", "keep-alive") + req.Header.Set("Cookie", "PHPSESSID=32023760_0wwmcnvQ2lWuBNdNyJ2foJc6F28UL5xf") + req.Header.Set("Cache-Control", "max-age=0") + req.Header.Set("Te", "Trailers") + + response, err := http.DefaultClient.Do(req) + if err != nil { + return err + } + defer response.Body.Close() + + if response.StatusCode != http.StatusOK { + log.WithFields(log.Fields{ + "Status": response.StatusCode, + "Reason": response.Status, + }).Error("Status code not daijobu") + return errors.New(response.Status) + } + + body, err := ioutil.ReadAll(response.Body) + if err != nil { + return err + + } + + err = json.Unmarshal(body, &Art) + if err != nil { + return err + } + + if Art.Body.Illustmanga.Data != nil { + for i, v := range Art.Body.Illustmanga.Data { + v2 := v.(map[string]interface{}) + IsVtuber := false + + for _, tag := range v2["tags"].([]interface{}) { + Tag := strings.ToLower(tag.(string)) + match, _ := regexp.MatchString("(youtube|vtuber|"+strings.ToLower(FixFanArt.Group.GroupName)+")", Tag) + if match { + IsVtuber = true + } + } + + var ( + Illusts map[string]interface{} + User map[string]interface{} + TextFix string + ) + + if IsVtuber { + if v2["xRestrict"].(float64) == 0 && !l { + illusbyte, err := network.Curl(config.PixivIllustsEnd+v2["id"].(string), nil) if err != nil { return err } - err = json.Unmarshal(body, &Art) + + err = json.Unmarshal(illusbyte, &Illusts) if err != nil { return err } - IsVtuber := false - for _, tag := range Art.Body.Relatedtags { - if strings.ToLower(tag.(string)) == strings.ToLower(Group.GroupName) { - IsVtuber = true - } + + Body := Illusts["body"].(map[string]interface{}) + Tags := Body["tags"].(map[string]interface{}) + Img := Body["urls"].(map[string]interface{}) + FixImg := Img["original"].(string) + + usrbyte, err := network.Curl(config.PixivUserEnd+Tags["authorId"].(string), nil) + if err != nil { + return err } - if Art.Body.Illustmanga.Data != nil && IsVtuber { - for i, v := range Art.Body.Illustmanga.Data { - var ( - v2 = v.(map[string]interface{}) - Illusts map[string]interface{} - User map[string]interface{} - TextFix string - ) - - if v2["xRestrict"].(float64) == 0 { - illusbyte, err := network.Curl(config.PixivIllustsEnd+v2["id"].(string), nil) - if err != nil { - return err - } - - err = json.Unmarshal(illusbyte, &Illusts) - if err != nil { - return err - } - - Body := Illusts["body"].(map[string]interface{}) - Tags := Body["tags"].(map[string]interface{}) - Img := Body["urls"].(map[string]interface{}) - FixImg := Img["original"].(string) - - usrbyte, err := network.Curl(config.PixivUserEnd+Tags["authorId"].(string), nil) - if err != nil { - return err - } - - err = json.Unmarshal(usrbyte, &User) - if err != nil { - return err - } - - UserBody := User["body"].(map[string]interface{}) - - Desc := RemoveHtmlTag(Body["description"].(string)) - if match, _ := regexp.MatchString("http://twitter.com", Desc); match { - TextFix = ClearTwitterURL(Desc) - } else { - TextFix = "**" + Body["title"].(string) + "**\n" + Desc - } - - FixFanArt := database.DataFanart{ - PermanentURL: BaseURL + v2["id"].(string), - Author: v2["userName"].(string), - AuthorAvatar: config.PixivProxy + UserBody["imageBig"].(string), - Photos: []string{FixImg}, - Text: TextFix, - PixivID: v2["id"].(string), - Member: Member, - State: config.PixivArt, - } - - new, err := FixFanArt.CheckPixivFanArt() - if err != nil { - return err - } - if new { - path, err := DownloadImg(Img["mini"].(string)) - if err != nil { - log.Error(err) - } - - Color, err := engine.GetColor("", path) - if err != nil { - return err - } - FixFanArt.Photos[0] = config.PixivProxy + FixImg - notif.SendNude(FixFanArt, Group, Bot, Color) - } - } - if i == 10 { - break - } - } + err = json.Unmarshal(usrbyte, &User) + if err != nil { + return err } - return nil - } - if Member.Region == "JP" { - URL := GetPixivURL(strings.Replace(Member.JpName, " ", "_", -1)) - err := Pixiv(URL) + + UserBody := User["body"].(map[string]interface{}) + + Desc := RemoveHtmlTag(Body["description"].(string)) + if match, _ := regexp.MatchString("http://twitter.com", Desc); match { + TextFix = ClearTwitterURL(Desc) + } else { + TextFix = "**" + Body["title"].(string) + "**\n" + Desc + } + + FixFanArt.AddAuthor(v2["userName"].(string)).AddPermanentURL(BaseURL + v2["id"].(string)). + AddAuthorAvatar(config.PixivProxy + UserBody["imageBig"].(string)).AddPhotos([]string{FixImg}). + AddText(TextFix).AddPixivID(v2["id"].(string)).SetState(config.PixivArt) + + new, err := FixFanArt.CheckPixivFanArt() if err != nil { - log.Error(err) + return err } - } else { - if Member.EnName != "" { - URL := GetPixivURL(strings.Replace(Member.EnName, " ", "_", -1)) - err := Pixiv(URL) + + if new { + path, err := DownloadImg(Img["mini"].(string)) if err != nil { log.Error(err) } + + Color, err := engine.GetColor("", path) + if err != nil { + return err + } + FixFanArt.Photos[0] = config.PixivProxy + FixImg + notif.SendNude(*FixFanArt, Bot, Color) + } + } else if l && v2["xRestrict"].(float64) == 1 { + illusbyte, err := network.Curl(config.PixivIllustsEnd+v2["id"].(string), nil) + if err != nil { + return err + } + + err = json.Unmarshal(illusbyte, &Illusts) + if err != nil { + return err + } + + Body := Illusts["body"].(map[string]interface{}) + Tags := Body["tags"].(map[string]interface{}) + Img := Body["urls"].(map[string]interface{}) + FixImg := Img["original"].(string) + + usrbyte, err := network.Curl(config.PixivUserEnd+Tags["authorId"].(string), nil) + if err != nil { + return err + } + + err = json.Unmarshal(usrbyte, &User) + if err != nil { + return err + } + + UserBody := User["body"].(map[string]interface{}) + + Desc := RemoveHtmlTag(Body["description"].(string)) + if match, _ := regexp.MatchString("http://twitter.com", Desc); match { + TextFix = ClearTwitterURL(Desc) } else { - URL := GetPixivURL(strings.Replace(Member.Name, " ", "_", -1)) - err := Pixiv(URL) + TextFix = "**" + Body["title"].(string) + "**\n" + Desc + } + + FixFanArt.AddAuthor(v2["userName"].(string)).AddPermanentURL(BaseURL + v2["id"].(string)). + AddAuthorAvatar(config.PixivProxy + UserBody["imageBig"].(string)).AddPhotos([]string{FixImg}). + AddText(TextFix).AddPixivID(v2["id"].(string)).SetState(config.PixivArt) + + new, err := FixFanArt.CheckPixivFanArt() + if err != nil { + return err + } + if new { + path, err := DownloadImg(Img["mini"].(string)) if err != nil { log.Error(err) } + + Color, err := engine.GetColor("", path) + if err != nil { + return err + } + FixFanArt.Photos[0] = config.PixivProxy + FixImg + notif.SendNude(*FixFanArt, Bot, Color) } } + if i == Limit { + break + } } - }(GroupData, wg) + } } - wg.Wait() + return nil } func GetPixivURL(str string) string { return "https://www.pixiv.net/ajax/search/artworks/" + str + "?word=" + str + "&order=date_d&mode=all&p=1&s_mode=s_tag_full&type=all&lang=en" } +func GetPixivLewdURL(str string) string { + return "https://www.pixiv.net/ajax/search/artworks/" + str + "?word=" + str + "&order=date_d&mode=r18&p=1&s_mode=s_tag_full&type=all&lang=en" +} + func ClearTwitterURL(str1 string) string { re := regexp.MustCompile(`(https\:\/\/twitter\.com\/.*)\<`) submatchall := re.FindStringSubmatch(str1) diff --git a/service/fanart/pixiv/pixivlewd.go b/service/fanart/pixiv/pixivlewd.go new file mode 100644 index 00000000..2b91b0d4 --- /dev/null +++ b/service/fanart/pixiv/pixivlewd.go @@ -0,0 +1,88 @@ +package pixiv + +import ( + "net/url" + "sync" + + "github.com/JustHumanz/Go-Simp/pkg/database" + log "github.com/sirupsen/logrus" +) + +func CheckPixivLewd() { + for _, Group := range VtubersData.VtuberData { + var wg sync.WaitGroup + for i, Member := range Group.Members { + wg.Add(1) + go func(wg *sync.WaitGroup, Member database.Member) { + defer wg.Done() + FixFanArt := &database.DataFanart{ + Member: Member, + Group: Group, + Lewd: true, + } + if Member.JpName != "" { + log.WithFields(log.Fields{ + "Member": Member.JpName, + "Group": Group.GroupName, + "Lewd": true, + }).Info("Start curl lewd pixiv") + URLJP := GetPixivLewdURL(url.QueryEscape(Member.JpName)) + err := Pixiv(URLJP, FixFanArt, true) + if err != nil { + log.Error(err) + } + } + + if Member.EnName == Member.Name { + if Member.EnName != "" { + log.WithFields(log.Fields{ + "Member": Member.EnName, + "Group": Group.GroupName, + "Lewd": true, + }).Info("Start curl lewd pixiv") + URLEN := GetPixivLewdURL(url.QueryEscape(Member.EnName)) + err := Pixiv(URLEN, FixFanArt, true) + if err != nil { + log.Error(err) + } + + } + } else { + if Member.EnName != "" { + log.WithFields(log.Fields{ + "Member": Member.EnName, + "Group": Group.GroupName, + "Lewd": true, + }).Info("Start curl lewd pixiv") + URLEN := GetPixivLewdURL(url.QueryEscape(Member.EnName)) + err := Pixiv(URLEN, FixFanArt, true) + if err != nil { + log.Error(err) + } + + } + if Member.Name != "" { + log.WithFields(log.Fields{ + "Member": Member.Name, + "Group": Group.GroupName, + "Lewd": true, + }).Info("Start curl lewd pixiv") + URL := GetPixivLewdURL(url.QueryEscape(Member.Name)) + err := Pixiv(URL, FixFanArt, true) + if err != nil { + log.Error(err) + } + } + + } + + }(&wg, Member) + + if i%4 == 0 { + wg.Wait() + } + + } + wg.Wait() + } +} diff --git a/service/fanart/runner.go b/service/fanart/runner.go index 32456a4e..3cbe1786 100755 --- a/service/fanart/runner.go +++ b/service/fanart/runner.go @@ -12,7 +12,6 @@ import ( "github.com/JustHumanz/Go-Simp/pkg/database" "github.com/JustHumanz/Go-Simp/pkg/network" "github.com/JustHumanz/Go-Simp/service/fanart/bilibili" - "github.com/JustHumanz/Go-Simp/service/fanart/lewd" "github.com/JustHumanz/Go-Simp/service/fanart/pixiv" "github.com/JustHumanz/Go-Simp/service/fanart/twitter" pilot "github.com/JustHumanz/Go-Simp/service/pilot/grpc" @@ -27,7 +26,7 @@ func init() { func main() { Twitter := flag.Bool("TwitterFanart", false, "Enable twitter fanart module") BiliBili := flag.Bool("BiliBiliFanart", false, "Enable bilibili fanart module") - Danbooru := flag.Bool("DanbooruLewd", false, "Enable Danbooru lewd fanart module") + Lewd := flag.Bool("LewdFanart", false, "Enable lewd fanart module") Pixiv := flag.Bool("PixivFanArt", false, "Enable Pixiv fanart module") flag.Parse() @@ -74,19 +73,15 @@ func main() { c.AddFunc(config.CheckPayload, RequestPay) if *Twitter { - twitter.Start(Bot, c, Payload, configfile) + twitter.Start(Bot, c, Payload, configfile, *Lewd) } if *BiliBili { bilibili.Start(Bot, c, Payload, configfile) } - if *Danbooru { - lewd.Start(Bot, c, Payload, configfile) - } - if *Pixiv { - pixiv.Start(Bot, c, Payload, configfile) + pixiv.Start(Bot, c, Payload, configfile, *Lewd) } _, err = gRCPconn.ModuleList(context.Background(), &pilot.ModuleData{ diff --git a/service/fanart/twitter/scraper.go b/service/fanart/twitter/scraper.go index 2e229648..f0cb1903 100755 --- a/service/fanart/twitter/scraper.go +++ b/service/fanart/twitter/scraper.go @@ -14,14 +14,15 @@ import ( func CreatePayload(Group database.Group, Scraper *twitterscraper.Scraper, Limit int) ([]database.DataFanart, error) { var ( - Hashtags []string - Fanarts []database.DataFanart + Hashtags []string + LewdHashtags []string + Fanarts []database.DataFanart ) - CurlTwitter := func(Hashtags []string, GroupData database.Group) { + CurlTwitter := func(Hashtags []string) { log.WithFields(log.Fields{ "Hashtag": strings.Join(Hashtags, " OR "), - "Group": GroupData.GroupName, + "Group": Group.GroupName, }).Info("Start curl twitter") for tweet := range Scraper.SearchTweets(context.Background(), "("+strings.ReplaceAll(strings.Join(Hashtags, " OR "), " ", "")+") AND (-filter:replies -filter:retweets -filter:quote) AND (filter:media OR filter:link)", Limit) { if tweet.Error != nil { @@ -39,6 +40,7 @@ func CreatePayload(Group database.Group, Scraper *twitterscraper.Scraper, Limit Photos: tweet.Photos, Likes: tweet.Likes, Member: MemberHashtag, + Group: Group, State: config.TwitterArt, } if tweet.Videos != nil { @@ -59,23 +61,84 @@ func CreatePayload(Group database.Group, Scraper *twitterscraper.Scraper, Limit } } + CurlTwitterLewd := func(Hashtags []string) { + log.WithFields(log.Fields{ + "Hashtag": strings.Join(Hashtags, " OR "), + "Group": Group.GroupName, + }).Info("Start curl twitter") + for tweet := range Scraper.SearchTweets(context.Background(), "("+strings.ReplaceAll(strings.Join(Hashtags, " OR "), " ", "")+") AND (-filter:replies -filter:retweets -filter:quote) AND (filter:media OR filter:link)", Limit) { + if tweet.Error != nil { + log.Error(tweet.Error) + } + for _, MemberHashtag := range Group.Members { + for _, TweetHashtag := range tweet.Hashtags { + if strings.ToLower("#"+TweetHashtag) == strings.ToLower(MemberHashtag.TwitterLewd) && !tweet.IsQuoted && !tweet.IsReply && len(tweet.Photos) > 0 { + TweetArt := database.DataFanart{ + PermanentURL: tweet.PermanentURL, + Author: "@" + tweet.Username, + AuthorAvatar: engine.GetAuthorAvatar(tweet.Username), + TweetID: tweet.ID, + Text: RemoveTwitterShortLink(tweet.Text), + Photos: tweet.Photos, + Likes: tweet.Likes, + Member: MemberHashtag, + Group: Group, + State: config.TwitterArt, + Lewd: true, + } + + if tweet.Videos != nil { + TweetArt.Videos = tweet.Videos[0].Preview + } + + New, err := TweetArt.CheckTweetFanArt() + if err != nil { + log.Error(err) + } + + if New { + Fanarts = append(Fanarts, TweetArt) + } + } + } + } + } + } + if len(Group.Members) > 7 { for i, Member := range Group.Members { if Member.TwitterHashtags != "" { Hashtags = append(Hashtags, Member.TwitterHashtags) if (i%5 == 0) || (i == len(Group.Members)-1) { - CurlTwitter(Hashtags, Group) + CurlTwitter(Hashtags) Hashtags = nil } } + + if lewd && Member.TwitterLewd != "" { + LewdHashtags = append(LewdHashtags, Member.TwitterLewd) + if (i%5 == 0) || (i == len(Group.Members)-1) { + CurlTwitterLewd(LewdHashtags) + LewdHashtags = nil + } + } } } else { for _, Member := range Group.Members { if Member.TwitterHashtags != "" { Hashtags = append(Hashtags, Member.TwitterHashtags) } + + if lewd && Member.TwitterLewd != "" { + LewdHashtags = append(LewdHashtags, Member.TwitterLewd) + } + } + + CurlTwitter(Hashtags) + + if lewd { + CurlTwitterLewd(LewdHashtags) } - CurlTwitter(Hashtags, Group) } if len(Fanarts) > 0 { diff --git a/service/fanart/twitter/twitter.go b/service/fanart/twitter/twitter.go index e1256ee6..2f2bcc3d 100755 --- a/service/fanart/twitter/twitter.go +++ b/service/fanart/twitter/twitter.go @@ -18,15 +18,21 @@ var ( Bot *discordgo.Session VtubersData database.VtubersPayload configfile config.ConfigFile + lewd bool ) //Start start twitter module -func Start(a *discordgo.Session, b *cron.Cron, c database.VtubersPayload, d config.ConfigFile) { +func Start(a *discordgo.Session, b *cron.Cron, c database.VtubersPayload, d config.ConfigFile, e bool) { Bot = a VtubersData = c configfile = d + lewd = e b.AddFunc(config.TwitterFanart, CheckNew) - log.Info("Enable Twitter fanart module") + if lewd { + log.Info("Enable Twitter lewd fanart module") + } else { + log.Info("Enable Twitter fanart module") + } } //CheckNew Check new fanart @@ -47,7 +53,7 @@ func CheckNew() { if err != nil { log.Error(err) } - notif.SendNude(Art, Group, Bot, Color) + notif.SendNude(Art, Bot, Color) } } }(GroupData, wg) From e917ac8e4352fea15a3e5081fc3c51f33423f9d3 Mon Sep 17 00:00:00 2001 From: JustHumanz Date: Sat, 27 Mar 2021 18:16:26 +0700 Subject: [PATCH 7/7] Add lewd command --- pkg/config/config.go | 2 + pkg/database/fanart.go | 39 ++++++++- service/fanart/pixiv/pixiv.go | 4 +- service/fanart/twitter/scraper.go | 8 +- service/frontend/general_handler.go | 118 +++++++++++++++++++++++++++- service/frontend/runner.go | 2 +- 6 files changed, 163 insertions(+), 10 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 5244806c..5269684c 100755 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -129,6 +129,7 @@ const ( type ConfigFile struct { Discord string `toml:"Discord"` BiliSess string `toml:"BiliSess"` + PixivSession string `toml:"PixivSess"` SauceAPI string `toml:"SauceAPI"` InviteLog string `toml:"InviteLog"` PilotReporting string `toml:"PilotReporting"` @@ -163,6 +164,7 @@ type ConfigFile struct { Youtube string `toml:"Youtube"` Bilibili string `toml:"Bilibili"` General string `toml:"General"` + Lewd string `toml:"Lewd"` } `toml:"BotPrefix"` Emoji struct { Fanart []string `toml:"Fanart"` diff --git a/pkg/database/fanart.go b/pkg/database/fanart.go index f68945a4..a02aef4f 100644 --- a/pkg/database/fanart.go +++ b/pkg/database/fanart.go @@ -35,7 +35,7 @@ func GetFanart(GroupID, MemberID int64) (*DataFanart, error) { return err } } - Data.State = "Twitter" + Data.State = config.TwitterArt return nil } Tbilibili := func() error { @@ -53,7 +53,7 @@ func GetFanart(GroupID, MemberID int64) (*DataFanart, error) { return err } } - Data.State = "TBiliBili" + Data.State = config.BiliBiliArt return nil } @@ -72,7 +72,7 @@ func GetFanart(GroupID, MemberID int64) (*DataFanart, error) { return err } } - Data.State = "Pixiv" + Data.State = config.PixivArt return nil } @@ -152,6 +152,39 @@ func GetFanart(GroupID, MemberID int64) (*DataFanart, error) { } +//GetFanart Get Member fanart URL from TBiliBili and Twitter +func GetLewd(GroupID, MemberID int64) (*DataFanart, error) { + var ( + Data DataFanart + PhotoTmp sql.NullString + Video sql.NullString + ) + + rows, err := DB.Query(`SELECT Lewd.* FROM Vtuber.Lewd Inner Join Vtuber.VtuberMember on VtuberMember.id = Lewd.VtuberMember_id Inner Join Vtuber.VtuberGroup on VtuberGroup.id = VtuberMember.VtuberGroup_id where (VtuberGroup.id=? OR VtuberMember.id=?) ORDER by RAND() LIMIT 1`, GroupID, MemberID) + if err != nil { + return nil, err + } else if err == sql.ErrNoRows { + return nil, errors.New("Vtuber don't have any fanart in Twitter") + } + + defer rows.Close() + for rows.Next() { + err = rows.Scan(&Data.ID, &Data.PermanentURL, &Data.Author, &PhotoTmp, &Video, &Data.Text, &Data.TweetID, &Data.PixivID, &Data.Member.ID) + if err != nil { + return nil, err + } + } + if Data.PixivID != "" { + Data.State = config.PixivArt + } else { + Data.State = config.TwitterArt + } + Data.Photos = strings.Fields(PhotoTmp.String) + Data.Videos = Video.String + return &Data, nil + +} + //DeleteFanart Delete fanart when get 404 error status func (Data DataFanart) DeleteFanart(e string) error { if notfound, _ := regexp.MatchString("404", e); notfound { diff --git a/service/fanart/pixiv/pixiv.go b/service/fanart/pixiv/pixiv.go index e7f0c535..aac8361a 100644 --- a/service/fanart/pixiv/pixiv.go +++ b/service/fanart/pixiv/pixiv.go @@ -35,7 +35,7 @@ var ( const ( BaseURL = "https://www.pixiv.net/en/artworks/" - Limit = 20 + Limit = 10 ) //Start start twitter module @@ -144,7 +144,7 @@ func Pixiv(p string, FixFanArt *database.DataFanart, l bool) error { req.Header.Set("Dnt", "1") req.Header.Set("Upgrade-Insecure-Requests", "1") req.Header.Set("Connection", "keep-alive") - req.Header.Set("Cookie", "PHPSESSID=32023760_0wwmcnvQ2lWuBNdNyJ2foJc6F28UL5xf") + req.Header.Set("Cookie", "PHPSESSID="+config.GoSimpConf.PixivSession) req.Header.Set("Cache-Control", "max-age=0") req.Header.Set("Te", "Trailers") diff --git a/service/fanart/twitter/scraper.go b/service/fanart/twitter/scraper.go index f0cb1903..b3893374 100755 --- a/service/fanart/twitter/scraper.go +++ b/service/fanart/twitter/scraper.go @@ -23,6 +23,7 @@ func CreatePayload(Group database.Group, Scraper *twitterscraper.Scraper, Limit log.WithFields(log.Fields{ "Hashtag": strings.Join(Hashtags, " OR "), "Group": Group.GroupName, + "Lewd": false, }).Info("Start curl twitter") for tweet := range Scraper.SearchTweets(context.Background(), "("+strings.ReplaceAll(strings.Join(Hashtags, " OR "), " ", "")+") AND (-filter:replies -filter:retweets -filter:quote) AND (filter:media OR filter:link)", Limit) { if tweet.Error != nil { @@ -33,7 +34,7 @@ func CreatePayload(Group database.Group, Scraper *twitterscraper.Scraper, Limit if strings.ToLower("#"+TweetHashtag) == strings.ToLower(MemberHashtag.TwitterHashtags) && !tweet.IsQuoted && !tweet.IsReply && MemberHashtag.Name != "Kaichou" && len(tweet.Photos) > 0 { TweetArt := database.DataFanart{ PermanentURL: tweet.PermanentURL, - Author: "@" + tweet.Username, + Author: tweet.Username, AuthorAvatar: engine.GetAuthorAvatar(tweet.Username), TweetID: tweet.ID, Text: RemoveTwitterShortLink(tweet.Text), @@ -65,6 +66,7 @@ func CreatePayload(Group database.Group, Scraper *twitterscraper.Scraper, Limit log.WithFields(log.Fields{ "Hashtag": strings.Join(Hashtags, " OR "), "Group": Group.GroupName, + "Lewd": true, }).Info("Start curl twitter") for tweet := range Scraper.SearchTweets(context.Background(), "("+strings.ReplaceAll(strings.Join(Hashtags, " OR "), " ", "")+") AND (-filter:replies -filter:retweets -filter:quote) AND (filter:media OR filter:link)", Limit) { if tweet.Error != nil { @@ -75,7 +77,7 @@ func CreatePayload(Group database.Group, Scraper *twitterscraper.Scraper, Limit if strings.ToLower("#"+TweetHashtag) == strings.ToLower(MemberHashtag.TwitterLewd) && !tweet.IsQuoted && !tweet.IsReply && len(tweet.Photos) > 0 { TweetArt := database.DataFanart{ PermanentURL: tweet.PermanentURL, - Author: "@" + tweet.Username, + Author: tweet.Username, AuthorAvatar: engine.GetAuthorAvatar(tweet.Username), TweetID: tweet.ID, Text: RemoveTwitterShortLink(tweet.Text), @@ -136,7 +138,7 @@ func CreatePayload(Group database.Group, Scraper *twitterscraper.Scraper, Limit CurlTwitter(Hashtags) - if lewd { + if lewd && LewdHashtags != nil { CurlTwitterLewd(LewdHashtags) } } diff --git a/service/frontend/general_handler.go b/service/frontend/general_handler.go index b08c8a62..3a6fea8e 100755 --- a/service/frontend/general_handler.go +++ b/service/frontend/general_handler.go @@ -36,7 +36,7 @@ func Fanart(s *discordgo.Session, m *discordgo.MessageCreate) { log.Error(err) } - if Data.State == "TBiliBili" { + if Data.State == config.BiliBiliArt { body, errcurl := network.CoolerCurl("https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/get_dynamic_detail?dynamic_id="+Data.Dynamic_id, nil) if errcurl != nil { log.Error(errcurl) @@ -133,6 +133,122 @@ func Fanart(s *discordgo.Session, m *discordgo.MessageCreate) { } } +func Lewd(s *discordgo.Session, m *discordgo.MessageCreate) { + m.Content = strings.ToLower(m.Content) + Prefix := config.GoSimpConf.BotPrefix.Lewd + var ( + Member bool + Group bool + Pic = config.NotFound + Msg string + embed *discordgo.MessageEmbed + ) + + if strings.HasPrefix(m.Content, Prefix) { + SendNude := func(Data *database.DataFanart) bool { + Color, err := engine.GetColor(config.TmpDir, m.Author.AvatarURL("128")) + if err != nil { + log.Error(err) + } + + if Data.State == config.PixivArt { + embed = engine.NewEmbed(). + SetAuthor(m.Author.Username, m.Author.AvatarURL("128")). + SetTitle(Data.Author). + SetDescription(RemovePic(Data.Text)). + SetURL(Data.PermanentURL). + SetImage(config.PixivProxy+Pic). + SetColor(Color). + InlineAllFields(). + SetFooter(Msg, config.PixivIMG).MessageEmbed + } else { + embed = engine.NewEmbed(). + SetAuthor(m.Author.Username, m.Author.AvatarURL("128")). + SetTitle(Data.Author). + SetThumbnail(engine.GetAuthorAvatar(Data.Author)). + SetDescription(RemovePic(Data.Text)). + SetURL(Data.PermanentURL). + SetImage(Pic). + SetColor(Color). + InlineAllFields(). + SetFooter(Msg, config.TwitterIMG).MessageEmbed + } + msg, err := s.ChannelMessageSendEmbed(m.ChannelID, embed) + if err != nil { + log.Error(err, msg) + } + err = engine.Reacting(map[string]string{ + "ChannelID": m.ChannelID, + "Content": m.Content, + "Prefix": Prefix, + }, s) + if err != nil { + log.Error(err) + } + return true + } + for _, GroupData := range Payload.VtuberData { + if m.Content == strings.ToLower(Prefix+GroupData.GroupName) { + FanArtData, err := database.GetLewd(GroupData.ID, 0) + if err != nil { + log.Error(err) + s.ChannelMessageSend(m.ChannelID, "Opps,something goes worng,like dev life\n"+err.Error()) + return + } + + if FanArtData.Videos != "" { + Msg = "Video type,check original post" + Pic = config.NotFound + } else if len(FanArtData.Photos) > 0 { + Pic = FanArtData.Photos[0] + Msg = "1/" + strconv.Itoa(len(FanArtData.Photos)) + " Photos" + } + + for _, v := range GroupData.Members { + if v.ID == FanArtData.Member.ID { + FanArtData.AddMember(v) + break + } + } + + Group = SendNude(FanArtData) + break + } + + for _, MemberData := range GroupData.Members { + if m.Content == strings.ToLower(Prefix+MemberData.Name) || m.Content == strings.ToLower(Prefix+MemberData.JpName) { + FanArtData, err := database.GetLewd(0, MemberData.ID) + if err != nil { + log.Error(err) + s.ChannelMessageSend(m.ChannelID, "Opps,something goes worng,like dev life\n"+err.Error()) + return + } + + if FanArtData.Videos != "" { + Msg = "Video type,check original post" + Pic = config.NotFound + } else if len(FanArtData.Photos) > 0 { + Msg = "1/" + strconv.Itoa(len(FanArtData.Photos)) + " Photos" + Pic = FanArtData.Photos[0] + } + + FanArtData.AddMember(MemberData) + Member = SendNude(FanArtData) + break + } + } + } + + if Member || Group { + return + } + + if !Group && !Member { + s.ChannelMessageSend(m.ChannelID, "`"+m.Content[len(Prefix):]+"` was invalid name") + } + } +} + //Tags command message handler func Tags(s *discordgo.Session, m *discordgo.MessageCreate) { Prefix := configfile.BotPrefix.General diff --git a/service/frontend/runner.go b/service/frontend/runner.go index 3d88d537..c4f9898c 100755 --- a/service/frontend/runner.go +++ b/service/frontend/runner.go @@ -145,7 +145,7 @@ func main() { Bot.AddHandler(BiliBiliSpace) Bot.AddHandler(YoutubeMessage) Bot.AddHandler(SubsMessage) - //Bot.AddHandler(Module) + Bot.AddHandler(Lewd) Bot.AddHandler(RegisterFunc) Bot.AddHandler(Answer) c.Stop()