This repository has been archived by the owner on Jun 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
581 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package setu | ||
|
||
import ( | ||
"gorm.io/gorm" | ||
) | ||
|
||
type DB struct { | ||
d *gorm.DB | ||
} | ||
type GroupConfig struct { | ||
GroupID int64 `gorm:"primaryKey"` | ||
R18 bool | ||
Enable bool | ||
} | ||
|
||
func InitDB(db *gorm.DB) DB { | ||
//log.Println(db.AutoMigrate(&GroupConfig{},&setucore.Pic{})) | ||
return DB{d: db} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package setu | ||
|
||
import ( | ||
"OPQBot-QQGroupManager/Core" | ||
"OPQBot-QQGroupManager/setu/pixiv" | ||
"OPQBot-QQGroupManager/setu/setucore" | ||
"fmt" | ||
"github.com/mcoo/OPQBot" | ||
"github.com/mcoo/requests" | ||
"github.com/sirupsen/logrus" | ||
"math/rand" | ||
"strings" | ||
"time" | ||
) | ||
|
||
type Module struct { | ||
} | ||
|
||
var log *logrus.Entry | ||
|
||
func (m *Module) ModuleInfo() Core.ModuleInfo { | ||
return Core.ModuleInfo{ | ||
Name: "Setu姬", | ||
Author: "enjoy", | ||
Description: "思路来源于https://github.com/opq-osc/OPQ-SetuBot 天乐giegie的setu机器人", | ||
Version: 0, | ||
} | ||
} | ||
func (m *Module) ModuleInit(b *Core.Bot, l *logrus.Entry) error { | ||
log = l | ||
InitDB(b.DB) | ||
px := &pixiv.Provider{} | ||
RegisterProvider(px, b) | ||
err := b.AddEvent(OPQBot.EventNameOnGroupMessage, func(qq int64, packet *OPQBot.GroupMsgPack) { | ||
if packet.FromUserID != b.QQ { | ||
cm := strings.Split(packet.Content, " ") | ||
if len(cm) == 2 && cm[0] == "搜图测试" { | ||
pics, err := px.SearchPic(cm[1], false) | ||
rand.Seed(time.Now().UnixNano()) | ||
num := rand.Intn(len(pics)) | ||
res, err := requests.Get(strings.ReplaceAll(pics[num].OriginalPicUrl, "i.pximg.net", "i.pixiv.cat")) | ||
if err != nil { | ||
log.Error(err) | ||
return | ||
} | ||
b.SendGroupPicMsg(packet.FromGroupID, fmt.Sprintf("标题:%s", pics[num].Title), res.Content()) | ||
if err != nil { | ||
log.Error(err) | ||
} | ||
|
||
} | ||
} | ||
}) | ||
if err != nil { | ||
log.Error(err) | ||
} | ||
return nil | ||
} | ||
func init() { | ||
Core.RegisterModule(&Module{}) | ||
} | ||
func RegisterProvider(p setucore.Provider, bot *Core.Bot) { | ||
p.InitProvider(log.WithField("SetuProvider", "Pixiv Core"), bot) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package pixiv | ||
|
||
import "time" | ||
|
||
type ErrResult struct { | ||
HasError bool `json:"has_error"` | ||
Errors struct { | ||
System struct { | ||
Message string `json:"message"` | ||
Code int `json:"code"` | ||
} `json:"system"` | ||
} `json:"errors"` | ||
Error string `json:"error"` | ||
} | ||
|
||
type LoginSuccessResult struct { | ||
AccessToken string `json:"access_token"` | ||
ExpiresIn int `json:"expires_in"` | ||
TokenType string `json:"token_type"` | ||
Scope string `json:"scope"` | ||
RefreshToken string `json:"refresh_token"` | ||
User struct { | ||
ProfileImageUrls struct { | ||
Px16X16 string `json:"px_16x16"` | ||
Px50X50 string `json:"px_50x50"` | ||
Px170X170 string `json:"px_170x170"` | ||
} `json:"profile_image_urls"` | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
Account string `json:"account"` | ||
MailAddress string `json:"mail_address"` | ||
IsPremium bool `json:"is_premium"` | ||
XRestrict int `json:"x_restrict"` | ||
IsMailAuthorized bool `json:"is_mail_authorized"` | ||
RequirePolicyAgreement bool `json:"require_policy_agreement"` | ||
} `json:"user"` | ||
Response struct { | ||
AccessToken string `json:"access_token"` | ||
ExpiresIn int `json:"expires_in"` | ||
TokenType string `json:"token_type"` | ||
Scope string `json:"scope"` | ||
RefreshToken string `json:"refresh_token"` | ||
User struct { | ||
ProfileImageUrls struct { | ||
Px16X16 string `json:"px_16x16"` | ||
Px50X50 string `json:"px_50x50"` | ||
Px170X170 string `json:"px_170x170"` | ||
} `json:"profile_image_urls"` | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
Account string `json:"account"` | ||
MailAddress string `json:"mail_address"` | ||
IsPremium bool `json:"is_premium"` | ||
XRestrict int `json:"x_restrict"` | ||
IsMailAuthorized bool `json:"is_mail_authorized"` | ||
RequirePolicyAgreement bool `json:"require_policy_agreement"` | ||
} `json:"user"` | ||
} `json:"response"` | ||
} | ||
type IllustResult struct { | ||
Illusts []struct { | ||
ID int `json:"id"` | ||
Title string `json:"title"` | ||
Type string `json:"type"` | ||
ImageUrls struct { | ||
SquareMedium string `json:"square_medium"` | ||
Medium string `json:"medium"` | ||
Large string `json:"large"` | ||
} `json:"image_urls"` | ||
Caption string `json:"caption"` | ||
Restrict int `json:"restrict"` | ||
User struct { | ||
ID int `json:"id"` | ||
Name string `json:"name"` | ||
Account string `json:"account"` | ||
ProfileImageUrls struct { | ||
Medium string `json:"medium"` | ||
} `json:"profile_image_urls"` | ||
IsFollowed bool `json:"is_followed"` | ||
} `json:"user"` | ||
Tags []struct { | ||
Name string `json:"name"` | ||
TranslatedName string `json:"translated_name"` | ||
} `json:"tags"` | ||
Tools []string `json:"tools"` | ||
CreateDate time.Time `json:"create_date"` | ||
PageCount int `json:"page_count"` | ||
Width int `json:"width"` | ||
Height int `json:"height"` | ||
SanityLevel int `json:"sanity_level"` | ||
XRestrict int `json:"x_restrict"` | ||
Series interface{} `json:"series"` | ||
MetaSinglePage struct { | ||
OriginalImageURL string `json:"original_image_url"` | ||
} `json:"meta_single_page,omitempty"` | ||
MetaPages []struct { | ||
ImageUrls struct { | ||
Original string `json:"original"` | ||
} `json:"image_urls"` | ||
} `json:"meta_pages"` | ||
TotalView int `json:"total_view"` | ||
TotalBookmarks int `json:"total_bookmarks"` | ||
IsBookmarked bool `json:"is_bookmarked"` | ||
Visible bool `json:"visible"` | ||
IsMuted bool `json:"is_muted"` | ||
} `json:"illusts"` | ||
SearchSpanLimit int `json:"search_span_limit"` | ||
} |
Oops, something went wrong.