feat(task): 领取社团奖励(笔记请求)和送礼物

This commit is contained in:
YXHXianYu 2025-03-13 23:55:09 +08:00
parent 179cdfe0ea
commit e0cf155e4c
8 changed files with 137 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

@ -0,0 +1,80 @@
"""领取社团奖励,并尽可能地给其他人送礼物"""
import logging
from math import log
from kotonebot import task, device, image, AdaptiveWait, sleep, ocr
from kotonebot.errors import GameUpdateNeededError
from . import R
from .common import DailyMoneyShopItems, conf
from .actions.loading import loading
from .actions.scenes import at_home, goto_home
from .actions.commu import handle_unread_commu
logger = logging.getLogger(__name__)
@task('领取社团奖励并送礼物')
def club_reward():
"""
领取社团奖励并尽可能地给其他人送礼物
"""
if not conf().club_reward.enabled:
logger.info('"Club reward" is disabled.')
return
if not at_home():
goto_home()
# 进入社团UI
logger.info('Entering club UI')
device.click(image.expect_wait(R.Daily.IconMenu, timeout=5))
device.click(image.expect_wait(R.Daily.IconMenuClub, timeout=5))
sleep(2)
# 如果笔记请求尚未结束,则不进行任何笔记请求有关操作(领取奖励 & 发起新的笔记请求)
# 如果笔记请求已经结束且存在奖励提示学偶UI应该会直接弹出面板那么直接点击关闭按钮即可
if image.find(R.Common.ButtonClose):
device.click()
logger.info('Collected club reward')
# 如果笔记请求已经结束,则发起一轮新的笔记请求;
# 注:下面这个图片要可以区分出笔记请求是否已经结束,不然会发生不幸的事情
if image.find(R.Daily.ButtonClubCollectReward):
logger.info('Starting new note request')
device.click()
sleep(1)
# 找到配置中选择的书籍
if not image.expect_wait(conf().club_reward.selected_note.to_resource(), timeout=5):
logger.error('Failed to select note!')
return
# 点两次书,确保选中
device.click()
sleep(0.5)
device.click()
sleep(0.5)
# 确认键
device.click(image.expect_wait(R.Common.ButtonConfirm, timeout=5))
logger.info('Started new note request')
# 送礼物好友硬币是重要的o(* ̄▽ ̄*)o
logger.info('Sending gifts')
for _ in range(5): # 默认循环5次
# 送礼物
if image.find(R.Daily.ButtonClubSendGift):
device.click()
sleep(0.5)
# 下个人
if image.find(R.Daily.ButtonClubSendGiftNext):
device.click()
sleep(0.5)
else:
# 找不到下个人就break
break
if __name__ == '__main__':
import logging
logging.basicConfig(level=logging.INFO, format='[%(asctime)s] [%(levelname)s] [%(name)s] [%(funcName)s] [%(lineno)d] %(message)s')
logger.setLevel(logging.DEBUG)
club_reward()

View File

@ -199,6 +199,16 @@ class DailyMoneyShopItems(IntEnum):
def all(cls) -> list[tuple[str, 'DailyMoneyShopItems']]:
"""获取所有枚举值及其对应的UI显示文本"""
return [(cls.to_ui_text(item), item) for item in cls]
@classmethod
def _is_note(cls, item: 'DailyMoneyShopItems') -> bool:
"""判断是否为笔记"""
return 'Note' in item.name and not item.name.startswith('Note') and not item.name.endswith('Note')
@classmethod
def note_items(cls) -> list[tuple[str, 'DailyMoneyShopItems']]:
"""获取所有枚举值及其对应的UI显示文本"""
return [(cls.to_ui_text(item), item) for item in cls if cls._is_note(item)]
def to_resource(self):
from . import R
@ -413,6 +423,13 @@ class MissionRewardConfig(ConfigBaseModel):
enabled: bool = False
"""是否启用领取任务奖励"""
class ClubRewardConfig(ConfigBaseModel):
enabled: bool = False
"""是否启用领取社团奖励"""
selected_note: DailyMoneyShopItems = DailyMoneyShopItems.AnomalyNoteVisual
"""想在社团奖励中获取到的笔记"""
class TraceConfig(ConfigBaseModel):
recommend_card_detection: bool = False
"""跟踪推荐卡检测"""
@ -452,6 +469,9 @@ class BaseConfig(ConfigBaseModel):
mission_reward: MissionRewardConfig = MissionRewardConfig()
"""领取任务奖励配置"""
club_reward: ClubRewardConfig = ClubRewardConfig()
"""领取社团奖励配置"""
trace: TraceConfig = TraceConfig()
"""跟踪配置"""

View File

@ -14,7 +14,7 @@ import gradio as gr
from kotonebot.backend.context import task_registry, ContextStackVars
from kotonebot.config.manager import load_config, save_config
from kotonebot.tasks.common import (
BaseConfig, APShopItems, PurchaseConfig, ActivityFundsConfig,
BaseConfig, APShopItems, ClubRewardConfig, PurchaseConfig, ActivityFundsConfig,
PresentsConfig, AssignmentConfig, ContestConfig, ProduceConfig,
MissionRewardConfig, PIdol, DailyMoneyShopItems, ProduceAction,
RecommendCardDetectionMode, TraceConfig, StartGameConfig
@ -262,6 +262,10 @@ class KotoneBotUI:
actions_order: List[str],
recommend_card_detection_mode: str,
mission_reward_enabled: bool,
# club reward
club_reward_enabled: bool,
selected_note: DailyMoneyShopItems,
# start game
start_game_enabled: bool,
start_through_kuyo: bool,
game_package_name: str,
@ -329,6 +333,10 @@ class KotoneBotUI:
mission_reward=MissionRewardConfig(
enabled=mission_reward_enabled
),
club_reward=ClubRewardConfig(
enabled=club_reward_enabled,
selected_note=selected_note
),
start_game=StartGameConfig(
enabled=start_game_enabled,
start_through_kuyo=start_through_kuyo,
@ -683,6 +691,30 @@ class KotoneBotUI:
outputs=[memory_sets_group]
)
return produce_enabled, produce_mode, produce_count, produce_idols, memory_sets, auto_set_memory, auto_set_support, use_pt_boost, use_note_boost, follow_producer, self_study_lesson, prefer_lesson_ap, actions_order, recommend_card_detection_mode
def _create_club_reward_settings(self) -> Tuple[gr.Checkbox, gr.Dropdown]:
with gr.Column():
gr.Markdown("### 社团奖励设置")
club_reward_enabled = gr.Checkbox(
label="启用社团奖励",
value=self.current_config.options.club_reward.enabled,
info=ClubRewardConfig.model_fields['enabled'].description
)
with gr.Group(visible=self.current_config.options.club_reward.enabled) as club_reward_group:
selected_note = gr.Dropdown(
choices=list(DailyMoneyShopItems.note_items()),
value=self.current_config.options.club_reward.selected_note,
label="想在社团奖励中获取到的笔记",
interactive=True,
info=ClubRewardConfig.model_fields['selected_note'].description
)
club_reward_enabled.change(
fn=lambda x: gr.Group(visible=x),
inputs=[club_reward_enabled],
outputs=[club_reward_group]
)
return club_reward_enabled, selected_note
def _create_start_game_settings(self) -> Tuple[gr.Checkbox, gr.Checkbox, gr.Textbox, gr.Textbox]:
with gr.Column():
@ -802,6 +834,9 @@ class KotoneBotUI:
info=MissionRewardConfig.model_fields['enabled'].description
)
# 社团奖励设置
club_reward_settings = self._create_club_reward_settings()
# 跟踪设置
with gr.Column():
gr.Markdown("### 跟踪设置")
@ -831,6 +866,7 @@ class KotoneBotUI:
*contest_settings,
*produce_settings,
mission_reward,
*club_reward_settings,
*start_game_settings
]