Skip to content

Commit

Permalink
听语音猜干员
Browse files Browse the repository at this point in the history
  • Loading branch information
IJNKAWAKAZE committed Jul 16, 2024
1 parent 5605c8c commit 11e8406
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
1 change: 1 addition & 0 deletions arknights.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ sticker:
api:
user_agent: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Mobile Safari/537.36 EdgA/118.0.2088.66
wiki: https://prts.wiki/w/
voice_data: https://torappu.prts.wiki/assets/audio/
enemy: https://prts.wiki/index.php?title=%E6%95%8C%E4%BA%BA%E4%B8%80%E8%A7%88%2F%E6%95%B0%E6%8D%AE&action=raw
item: https://backend.yituliu.cn/item/value?expCoefficient=0.625
stage_result: https://backend.yituliu.cn/stage/result?expCoefficient=0.625
Expand Down
50 changes: 44 additions & 6 deletions src/plugins/system/quiz_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import (
"arknights_bot/utils"
"crypto/rand"
"fmt"
"github.com/PuerkitoBio/goquery"
tgbotapi "github.com/ijnkawakaze/telegram-bot-api"
"github.com/spf13/viper"
"log"
"math/big"
"net/http"
"strings"
)

// QuizHandle 云玩家检测
Expand Down Expand Up @@ -97,6 +101,7 @@ func QuizHandle(update tgbotapi.Update) error {
correct := options[r.Int64()]

sendPhoto := tgbotapi.NewPhoto(chatId, tgbotapi.FileBytes{Bytes: utils.GetImg(correct.ThumbURL)})
pollText := "请选择上图干员的正确名字"
if param == "h" {
pic := utils.ImgConvert(correct.ThumbURL)
if pic == nil {
Expand All @@ -111,13 +116,46 @@ func QuizHandle(update tgbotapi.Update) error {
}
sendPhoto = tgbotapi.NewPhoto(chatId, tgbotapi.FileBytes{Bytes: pic})
}
photo, err := bot.Arknights.Send(sendPhoto)
if err != nil {
log.Printf("发送图片失败:%s,原因:%s", correct.ThumbURL, err.Error())
return nil
if param == "v" {
var voiceList []string
resp, err := http.Get(viper.GetString("api.wiki") + correct.Name + "/语音记录")
if err != nil {
return err
}
doc, err := goquery.NewDocumentFromReader(resp.Body)
if err != nil {
return err
}
d := doc.Find("#voice-data-root")
voiceKey, _ := d.Attr("data-voice-key")
voiceBase, _ := d.Attr("data-voice-base")
voiceType := "voice/"
if strings.Contains(voiceBase, "中文-普通话") {
voiceType = "voice_cn/"
}
doc.Find(".voice-data-item").Each(func(i int, selection *goquery.Selection) {
voiceIndex, _ := selection.Attr("data-voice-index")
voiceList = append(voiceList, voiceIndex)
})
vr, _ := rand.Int(rand.Reader, big.NewInt(int64(len(voiceList))))
voiceUrl := tgbotapi.FileURL(viper.GetString("api.voice_data") + voiceType + voiceKey + "/cn_" + fmt.Sprintf("%03s", voiceList[vr.Int64()]) + ".mp3")
sendVoice := tgbotapi.NewVoice(chatId, voiceUrl)
v, err := bot.Arknights.Send(sendVoice)
if err != nil {
log.Printf("发送语音失败:%s,原因:%s", voiceUrl, err.Error())
return nil
}
messagecleaner.AddDelQueue(chatId, v.MessageID, 300)
pollText = "听语音选择干员的正确名字"
} else {
photo, err := bot.Arknights.Send(sendPhoto)
if err != nil {
log.Printf("发送图片失败:%s,原因:%s", correct.ThumbURL, err.Error())
return nil
}
messagecleaner.AddDelQueue(chatId, photo.MessageID, 300)
}
messagecleaner.AddDelQueue(chatId, photo.MessageID, 300)
poll := tgbotapi.NewPoll(chatId, "请选择上图干员的正确名字")
poll := tgbotapi.NewPoll(chatId, pollText)
poll.IsAnonymous = false
poll.Type = "quiz"
poll.CorrectOptionID = r.Int64()
Expand Down

0 comments on commit 11e8406

Please sign in to comment.