Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Commit

Permalink
v3.3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
JustHumanz committed Mar 22, 2021
1 parent 038af0f commit e655068
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 28 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v3.3.4
- Fix bug on `setup`
- Add color on pixiv image
- Fix livestream conter not running

v3.3.3
- Fix swaped youtube thub and avatar
- Use const for paramater
Expand Down
57 changes: 55 additions & 2 deletions service/fanart/pixiv/pixiv.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package pixiv
import (
"context"
"encoding/json"
"errors"
"io"
"net/http"
"os"
"regexp"
"sort"
"strings"
Expand Down Expand Up @@ -34,6 +38,7 @@ 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")
}
Expand Down Expand Up @@ -92,6 +97,16 @@ 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
Expand Down Expand Up @@ -133,7 +148,7 @@ func CheckPixiv() {
}
var (
tags string
Msg string
Msg = "Pixiv"
)

for i, Channel := range ChannelData {
Expand Down Expand Up @@ -161,6 +176,7 @@ func CheckPixiv() {
SetDescription(TextFix).
SetImage(config.PixivProxy+FixImg).
AddField("User Tags", tags).
SetColor(Color).
SetFooter(Msg, config.PixivIMG).MessageEmbed)
if err != nil {
log.Error(msg, err)
Expand All @@ -176,7 +192,7 @@ func CheckPixiv() {

if i%config.Waiting == 0 && configfile.LowResources {
log.WithFields(log.Fields{
"Func": "Twitter Fanart",
"Func": "Pixiv Fanart",
}).Warn(config.FanartSleep)
time.Sleep(config.FanartSleep)
}
Expand Down Expand Up @@ -247,3 +263,40 @@ func RemoveHtmlTag(in string) string {
}
return in
}

func DownloadImg(u string) (string, error) {
dir := config.TmpDir + engine.RanString()
out, err := os.Create(dir)
if err != nil {
return "", err
}

defer out.Close()
request, err := http.NewRequest(http.MethodGet, u, nil)
if err != nil {
return "", err
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

request.Header.Set("cache-control", "no-cache")
request.Header.Set("User-Agent", network.RandomAgent())
request.Header.Set("Referer", "https://www.pixiv.net")

spaceClient := http.Client{}
resp, err := spaceClient.Do(request.WithContext(ctx))
if err != nil {
return "", err
}

defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return "", errors.New(resp.Status)
}
_, err = io.Copy(out, resp.Body)
if err != nil {
return "", err
}
return dir, nil
}
12 changes: 6 additions & 6 deletions service/frontend/bilibili_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func BiliBiliMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
for _, FindGroupArry := range Payload {
VTuberGroup, err := FindGropName(FindGroupArry)
if err != nil {
Member := FindVtuber(FindGroupArry, 0)
Member := FindVtuber(FindGroupArry)
if Member == (database.Member{}) {
s.ChannelMessageSend(m.ChannelID, "`"+FindGroupArry+"`,Name of Vtuber Group or Vtuber Name was not found")
return
Expand Down Expand Up @@ -78,7 +78,7 @@ func BiliBiliMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
}

for _, LiveData := range LiveBili {
LiveData.AddMember(FindVtuber("", LiveData.Member.ID))
LiveData.AddMember(FindVtuber(LiveData.Member.ID))
FixName := engine.FixName(LiveData.Member.EnName, LiveData.Member.JpName)
diff := time.Now().In(loc).Sub(LiveData.Schedul.In(loc))
view, err := strconv.Atoi(LiveData.Viewers)
Expand Down Expand Up @@ -116,7 +116,7 @@ func BiliBiliMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
for _, FindGroupArry := range Payload {
VTuberGroup, err := FindGropName(FindGroupArry)
if err != nil {
Member := FindVtuber(FindGroupArry, 0)
Member := FindVtuber(FindGroupArry)
if Member == (database.Member{}) {
s.ChannelMessageSend(m.ChannelID, "`"+FindGroupArry+"`,Name of Vtuber Group or Vtuber Name was not found")
return
Expand Down Expand Up @@ -169,7 +169,7 @@ func BiliBiliMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
}

for _, LiveData := range LiveBili {
LiveData.AddMember(FindVtuber("", LiveData.Member.ID))
LiveData.AddMember(FindVtuber(LiveData.Member.ID))
FixName := engine.FixName(LiveData.Member.EnName, LiveData.Member.JpName)
view, err := strconv.Atoi(LiveData.Viewers)
if err != nil {
Expand Down Expand Up @@ -223,7 +223,7 @@ func BiliBiliSpace(s *discordgo.Session, m *discordgo.MessageCreate) {
for _, FindGroupArry := range strings.Split(strings.TrimSpace(Payload), ",") {
VTuberGroup, err := FindGropName(FindGroupArry)
if err != nil {
Member := FindVtuber(FindGroupArry, 0)
Member := FindVtuber(FindGroupArry)
if Member == (database.Member{}) {
s.ChannelMessageSend(m.ChannelID, "`"+FindGroupArry+"`,Name of Vtuber Group or Vtuber Name was not found")
return
Expand Down Expand Up @@ -281,7 +281,7 @@ func BiliBiliSpace(s *discordgo.Session, m *discordgo.MessageCreate) {
}

for _, SpaceData := range SpaceBili {
SpaceData.AddMember(FindVtuber("", SpaceData.Member.ID))
SpaceData.AddMember(FindVtuber(SpaceData.Member.ID))

FixName := engine.FixName(SpaceData.Member.EnName, SpaceData.Member.JpName)
diff := time.Now().In(loc).Sub(SpaceData.Schedul.In(loc))
Expand Down
12 changes: 6 additions & 6 deletions service/frontend/general_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func Tags(s *discordgo.Session, m *discordgo.MessageCreate) {
if VtuberName != "" {
tmp := strings.Split(VtuberName, ",")
for _, Name := range tmp {
Member := FindVtuber(Name, 0)
Member := FindVtuber(Name)
if Member == (database.Member{}) {
VTuberGroup, err := FindGropName(Name)
if err != nil {
Expand Down Expand Up @@ -348,7 +348,7 @@ func Tags(s *discordgo.Session, m *discordgo.MessageCreate) {

tmp := strings.Split(FindInt[1], ",")
for _, Name := range tmp {
Member := FindVtuber(Name, 0)
Member := FindVtuber(Name)
if Member == (database.Member{}) {
VTuberGroup, err := FindGropName(Name)
if err != nil {
Expand Down Expand Up @@ -495,7 +495,7 @@ func Tags(s *discordgo.Session, m *discordgo.MessageCreate) {
if VtuberName != "" {
tmp := strings.Split(VtuberName, ",")
for _, Name := range tmp {
Member := FindVtuber(Name, 0)
Member := FindVtuber(Name)
if Member == (database.Member{}) {
VTuberGroup, err := FindGropName(Name)
if err != nil {
Expand Down Expand Up @@ -665,7 +665,7 @@ func Tags(s *discordgo.Session, m *discordgo.MessageCreate) {
if len(VtuberName[len(VtuberName)-1:]) > 0 {
tmp := strings.Split(VtuberName[len(VtuberName)-1:][0], ",")
for _, Name := range tmp {
Member := FindVtuber(Name, 0)
Member := FindVtuber(Name)
if Member == (database.Member{}) {
VTuberGroup, err := FindGropName(Name)
if err != nil {
Expand Down Expand Up @@ -838,7 +838,7 @@ func Tags(s *discordgo.Session, m *discordgo.MessageCreate) {
tmp := strings.Split(VtuberName[len(VtuberName)-1:][0], ",")

for _, Name := range tmp {
Member := FindVtuber(Name, 0)
Member := FindVtuber(Name)
if Member == (database.Member{}) {
VTuberGroup, err := FindGropName(Name)
if err != nil {
Expand Down Expand Up @@ -1026,7 +1026,7 @@ func Tags(s *discordgo.Session, m *discordgo.MessageCreate) {
if len(VtuberName[len(VtuberName)-2:]) > 0 {
tmp := strings.Split(VtuberName[len(VtuberName)-2:][0], ",")
for _, Name := range tmp {
Member := FindVtuber(Name, 0)
Member := FindVtuber(Name)
if Member == (database.Member{}) {
VTuberGroup, err := FindGropName(Name)
if err != nil {
Expand Down
19 changes: 11 additions & 8 deletions service/frontend/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,21 @@ func Module(s *discordgo.Session, m *discordgo.MessageCreate) {
*/

//FindName Find a valid Vtuber name from message handler
func FindVtuber(MemberName string, ID int64) database.Member {
if ID != 0 {
func FindVtuber(M interface{}) database.Member {
MemberName, str := M.(string)
if str {
for _, Group := range Payload.VtuberData {
for _, Name := range Group.Members {
if Name.ID == ID {
if strings.ToLower(Name.Name) == MemberName || strings.ToLower(Name.JpName) == MemberName || MemberName == strconv.Itoa(int(Name.ID)) {
return Name
}
}
}
} else {
MemberID := M.(int64)
for _, Group := range Payload.VtuberData {
for _, Name := range Group.Members {
if strings.ToLower(Name.Name) == MemberName || strings.ToLower(Name.JpName) == MemberName {
if MemberID == Name.ID {
return Name
}
}
Expand All @@ -215,16 +217,17 @@ func FindVtuber(MemberName string, ID int64) database.Member {

//FindGropName Find a valid Vtuber Group from message handler
func FindGropName(g interface{}) (database.Group, error) {
ID, err := strconv.Atoi(g.(string))
if err != nil {
Grp, str := g.(string)
if str {
for _, Group := range Payload.VtuberData {
if strings.ToLower(Group.GroupName) == strings.ToLower(g.(string)) {
if strings.ToLower(Group.GroupName) == strings.ToLower(Grp) || strconv.Itoa(int(Group.ID)) == Grp {
return Group, nil
}
}
} else {
GrpID := g.(int64)
for _, Group := range Payload.VtuberData {
if Group.ID == int64(ID) {
if Group.ID == GrpID {
return Group, nil
}
}
Expand Down
12 changes: 6 additions & 6 deletions service/frontend/youtube_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func YoutubeMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
for _, GroupNameQuery := range strings.Split(strings.TrimSpace(CommandArray[1]), ",") {
VTuberGroup, err := FindGropName(GroupNameQuery)
if err != nil {
Member := FindVtuber(GroupNameQuery, 0)
Member := FindVtuber(GroupNameQuery)
if Member == (database.Member{}) {
_, err := s.ChannelMessageSend(m.ChannelID, "`"+GroupNameQuery+"`,Name of Vtuber Group or Vtuber Name was not found")
if err != nil {
Expand Down Expand Up @@ -109,7 +109,7 @@ func YoutubeMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
}
if GroupData != nil {
for _, Youtube := range GroupData {
Youtube.AddMember(FindVtuber("", Youtube.Member.ID))
Youtube.AddMember(FindVtuber(Youtube.Member.ID))
FixName := engine.FixName(Youtube.Member.EnName, Youtube.Member.JpName)

loc := engine.Zawarudo(Youtube.Member.Region)
Expand Down Expand Up @@ -173,7 +173,7 @@ func YoutubeMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
for _, GroupName := range FindGroupArry {
VTuberGroup, err := FindGropName(GroupName)
if err != nil {
Member := FindVtuber(GroupName, 0)
Member := FindVtuber(GroupName)
if Member == (database.Member{}) {
_, err := s.ChannelMessageSend(m.ChannelID, "`"+GroupName+"`,Name of Vtuber Group or Vtuber Name was not found")
if err != nil {
Expand Down Expand Up @@ -242,7 +242,7 @@ func YoutubeMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
}
if YoutubeData != nil {
for _, Youtube := range YoutubeData {
Youtube.AddMember(FindVtuber("", Youtube.Member.ID))
Youtube.AddMember(FindVtuber(Youtube.Member.ID))

loc := engine.Zawarudo(Youtube.Member.Region)
duration := durafmt.Parse(time.Now().In(loc).Sub(Youtube.Schedul.In(loc))).LimitFirstN(2)
Expand Down Expand Up @@ -309,7 +309,7 @@ func YoutubeMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
for _, GroupName := range FindGroupArry {
VTuberGroup, err := FindGropName(GroupName)
if err != nil {
Member := FindVtuber(GroupName, 0)
Member := FindVtuber(GroupName)
if Member == (database.Member{}) {
_, err := s.ChannelMessageSend(m.ChannelID, "`"+GroupName+"`,Name of Vtuber Group or Vtuber Name was not found")
if err != nil {
Expand Down Expand Up @@ -386,7 +386,7 @@ func YoutubeMessage(s *discordgo.Session, m *discordgo.MessageCreate) {

if YoutubeData != nil {
for _, Youtube := range YoutubeData {
Youtube.AddMember(FindVtuber("", Youtube.Member.ID))
Youtube.AddMember(FindVtuber(Youtube.Member.ID))

Color, err := engine.GetColor(config.TmpDir, Youtube.Thumb)
if err != nil {
Expand Down

0 comments on commit e655068

Please sign in to comment.