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

Commit

Permalink
新增订阅up主和番剧保留用户id字段,用户艾特用户
Browse files Browse the repository at this point in the history
  • Loading branch information
bypanghu committed Jun 1, 2021
1 parent cbd91ea commit 4793d53
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 74 deletions.
28 changes: 18 additions & 10 deletions Bili/bili.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,14 @@ type SearchResult struct {
type Up struct {
Name string
Created int64
UserId int64
Groups []int64
}
type Fanju struct {
Title string
Id int64
Groups []int64
UserId int64
}

type BiliResult struct {
Expand Down Expand Up @@ -559,7 +561,7 @@ func (m *Manager) UnSubscribeFanju(groupId int64, mid int64) (e error) {
// return
//}

func (m *Manager) SubscribeFanjuByKeyword(groupId int64, keyword string) (u BiliFanjuResult, e error) {
func (m *Manager) SubscribeFanjuByKeyword(groupId int64, keyword string , userId int64) (u BiliFanjuResult, e error) {
if groupId == 0 {
e = errors.New("默认群禁止订阅!")
return
Expand All @@ -568,10 +570,10 @@ func (m *Manager) SubscribeFanjuByKeyword(groupId int64, keyword string) (u Bili
if e != nil {
return
}
u, e = m.SubscribeFanjuByMid(groupId, mediaId)
u, e = m.SubscribeFanjuByMid(groupId, mediaId,userId)
return
}
func (m *Manager) SubscribeUpByMid(groupId int64, mid int64) (u UpInfoResult, e error) {
func (m *Manager) SubscribeUpByMid(groupId int64, mid int64 , userId int64) (u UpInfoResult, e error) {
if groupId == 0 {
e = errors.New("默认群禁止订阅!")
return
Expand Down Expand Up @@ -613,14 +615,14 @@ func (m *Manager) SubscribeUpByMid(groupId int64, mid int64) (u UpInfoResult, e
if v.BiliUps == nil {
v.BiliUps = map[int64]Config.Up{}
}
v.BiliUps[mid] = Config.Up{Name: u.Data.Card.Name, Created: up.Created}
v.BiliUps[mid] = Config.Up{Name: u.Data.Card.Name, Created: up.Created , UserId : userId}
Config.CoreConfig.GroupConfig[groupId] = v
} else {
if v.BiliUps == nil {
v.BiliUps = map[int64]Config.Up{}
}
v = Config.CoreConfig.DefaultGroupConfig
v.BiliUps[mid] = Config.Up{Name: u.Data.Card.Name, Created: up.Created}
v.BiliUps[mid] = Config.Up{Name: u.Data.Card.Name, Created: up.Created , UserId : userId}
Config.CoreConfig.GroupConfig[groupId] = v
}
Config.Save()
Expand All @@ -631,14 +633,14 @@ func (m *Manager) SubscribeUpByMid(groupId int64, mid int64) (u UpInfoResult, e
if v.BiliUps == nil {
v.BiliUps = map[int64]Config.Up{}
}
v.BiliUps[mid] = Config.Up{Name: u.Data.Card.Name, Created: 0}
v.BiliUps[mid] = Config.Up{Name: u.Data.Card.Name, Created: 0 ,UserId: userId}
Config.CoreConfig.GroupConfig[groupId] = v
} else {
if v.BiliUps == nil {
v.BiliUps = map[int64]Config.Up{}
}
v = Config.CoreConfig.DefaultGroupConfig
v.BiliUps[mid] = Config.Up{Name: u.Data.Card.Name, Created: 0}
v.BiliUps[mid] = Config.Up{Name: u.Data.Card.Name, Created: 0 ,UserId: userId}
Config.CoreConfig.GroupConfig[groupId] = v
}
Config.Save()
Expand All @@ -647,7 +649,7 @@ func (m *Manager) SubscribeUpByMid(groupId int64, mid int64) (u UpInfoResult, e
}
return
}
func (m *Manager) SubscribeFanjuByMid(groupId int64, mediaId int64) (u BiliFanjuResult, e error) {
func (m *Manager) SubscribeFanjuByMid(groupId int64, mediaId int64 , userId int64) (u BiliFanjuResult, e error) {
if groupId == 0 {
e = errors.New("默认群禁止订阅!")
return
Expand Down Expand Up @@ -692,6 +694,7 @@ func (m *Manager) SubscribeFanjuByMid(groupId int64, mediaId int64) (u BiliFanju
v.Fanjus[mediaId] = Config.Fanju{
Title: u.Result.Media.Title,
Id: fj.Id,
UserId: userId,
}
Config.CoreConfig.GroupConfig[groupId] = v
} else {
Expand All @@ -702,6 +705,7 @@ func (m *Manager) SubscribeFanjuByMid(groupId int64, mediaId int64) (u BiliFanju
v.Fanjus[mediaId] = Config.Fanju{
Title: u.Result.Media.Title,
Id: fj.Id,
UserId: userId,
}
Config.CoreConfig.GroupConfig[groupId] = v
}
Expand All @@ -716,6 +720,7 @@ func (m *Manager) SubscribeFanjuByMid(groupId int64, mediaId int64) (u BiliFanju
v.Fanjus[mediaId] = Config.Fanju{
Title: u.Result.Media.Title,
Id: 0,
UserId: userId,
}
Config.CoreConfig.GroupConfig[groupId] = v
} else {
Expand All @@ -726,6 +731,7 @@ func (m *Manager) SubscribeFanjuByMid(groupId int64, mediaId int64) (u BiliFanju
v.Fanjus[mediaId] = Config.Fanju{
Title: u.Result.Media.Title,
Id: 0,
UserId: userId,
}
Config.CoreConfig.GroupConfig[groupId] = v
}
Expand Down Expand Up @@ -766,21 +772,23 @@ func (m *Manager) SearchFanju(keyword string) (mid int64, err error) {
}
return
}
func (m *Manager) GetUpGroupsByMid(mid int64) (upName string, g []int64) {
func (m *Manager) GetUpGroupsByMid(mid int64) (upName string, g []int64 , userId int64) {
m.upsMapLock.RLock()
defer m.upsMapLock.RUnlock()
if v, ok := m.ups[mid]; ok {
g = v.Groups
upName = v.Name
userId = v.UserId
}
return
}
func (m *Manager) GetFanjuGroupsByMid(mid int64) (title string, g []int64) {
func (m *Manager) GetFanjuGroupsByMid(mid int64) (title string, g []int64 , userId int64) {
m.fanjuMapLock.RLock()
defer m.fanjuMapLock.RUnlock()
if v, ok := m.fanjus[mid]; ok {
g = v.Groups
title = v.Title
userId = v.UserId
}
return
}
2 changes: 2 additions & 0 deletions Config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ type GroupConfig struct {
type Up struct {
Name string
Created int64
UserId int64
}
type Fanju struct {
Title string
Id int64
UserId int64
}

var (
Expand Down
Binary file added OPQBot-QQGroupManager
Binary file not shown.
56 changes: 0 additions & 56 deletions config.yaml.example

This file was deleted.

32 changes: 24 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,27 +68,43 @@ func main() {
c.AddJob(-1, "Bili", "*/5 * * * *", func() {
update, fanju := bi.ScanUpdate()
for _, v := range update {
upName, gs := bi.GetUpGroupsByMid(v.Mid)
upName, gs ,userId := bi.GetUpGroupsByMid(v.Mid)
for _, g := range gs {
if v1, ok := Config.CoreConfig.GroupConfig[g]; ok {
if !v1.Bili {
break
}
}
res, _ := requests.Get(v.Pic)
b.SendGroupPicMsg(g, fmt.Sprintf("UP主%s更新了\n%s\n%s", upName, v.Title, v.Description), res.Content())
b.Send(OPQBot.SendMsgPack{
SendToType: OPQBot.SendToTypeGroup,
ToUserUid: g,
Content: OPQBot.SendTypePicMsgByBase64Content{
Content: OPQBot.MacroAt([]int64{userId}) + fmt.Sprintf("您订阅的UP主%s更新了\n%s\n%s", upName, v.Title, v.Description),
Base64: base64.StdEncoding.EncodeToString(res.Content()),
Flash: false,
},
})
}
}
for _, v := range fanju {
title, gs := bi.GetFanjuGroupsByMid(v.Result.Media.MediaID)
title, gs ,userId:= bi.GetFanjuGroupsByMid(v.Result.Media.MediaID)
for _, g := range gs {
if v1, ok := Config.CoreConfig.GroupConfig[g]; ok {
if !v1.Bili {
break
}
}
res, _ := requests.Get(v.Result.Media.Cover)
b.SendGroupPicMsg(g, fmt.Sprintf("番剧%s更新了\n%s", title, v.Result.Media.NewEp.IndexShow), res.Content())
b.Send(OPQBot.SendMsgPack{
SendToType: OPQBot.SendToTypeGroup,
ToUserUid: g,
Content: OPQBot.SendTypePicMsgByBase64Content{
Content: OPQBot.MacroAt([]int64{userId}) + fmt.Sprintf("您订阅的番剧%s更新了\n%s", title, v.Result.Media.NewEp.IndexShow),
Base64: base64.StdEncoding.EncodeToString(res.Content()),
Flash: false,
},
})
}
}
})
Expand Down Expand Up @@ -340,7 +356,7 @@ func main() {
}
if v1, ok := v.(map[int]int64); ok {
if v2, ok := v1[id]; ok {
u, err := bi.SubscribeUpByMid(packet.FromGroupID, v2)
u, err := bi.SubscribeUpByMid(packet.FromGroupID, v2 ,packet.FromUserID)
if err != nil {
b.SendGroupTextMsg(packet.FromGroupID, err.Error())
err = s.Delete("biliUps")
Expand Down Expand Up @@ -445,7 +461,7 @@ func main() {
b.SendGroupTextMsg(packet.FromGroupID, fmt.Sprintf("====输入序号选择UP====\n%s", strings.Join(resultStr, "\n")))
return
}
u, err := bi.SubscribeUpByMid(packet.FromGroupID, mid)
u, err := bi.SubscribeUpByMid(packet.FromGroupID, mid , packet.FromUserID)
if err != nil {
b.SendGroupTextMsg(packet.FromGroupID, err.Error())
return
Expand Down Expand Up @@ -491,7 +507,7 @@ func main() {
}
mid, err := strconv.ParseInt(cm[1], 10, 64)
if err != nil {
u, err := bi.SubscribeFanjuByKeyword(packet.FromGroupID, cm[1])
u, err := bi.SubscribeFanjuByKeyword(packet.FromGroupID, cm[1],packet.FromUserID)
if err != nil {
b.SendGroupTextMsg(packet.FromGroupID, err.Error())
return
Expand All @@ -500,7 +516,7 @@ func main() {
b.SendGroupPicMsg(packet.FromGroupID, "成功订阅番剧"+u.Result.Media.Title, r.Content())
return
}
u, err := bi.SubscribeFanjuByMid(packet.FromGroupID, mid)
u, err := bi.SubscribeFanjuByMid(packet.FromGroupID, mid,packet.FromUserID)
if err != nil {
b.SendGroupTextMsg(packet.FromGroupID, err.Error())
return
Expand Down

0 comments on commit 4793d53

Please sign in to comment.