Compare commits
11 Commits
8d83ec1657
...
32cee3f6b5
| Author | SHA1 | Date | |
|---|---|---|---|
| 32cee3f6b5 | |||
| 659f58db38 | |||
| 6dac8a1de2 | |||
| b1aeb64768 | |||
| 88e8a98b76 | |||
| 39d00ac549 | |||
| 11d2a6ef7e | |||
| 1f5b68d095 | |||
| 5f3ff140dd | |||
| 8698fa20c2 | |||
| b426c6caac |
BIN
assets/en/cafe/CAFE_INVITE.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
BIN
assets/en/cafe/CAFE_INVITED.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
BIN
assets/en/cafe/CHECK_MOMOTALK.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
BIN
assets/en/cafe/INVITE_CONFIRM.BUTTON.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
assets/en/cafe/INVITE_CONFIRM.png
Normal file
|
After Width: | Height: | Size: 6.4 KiB |
BIN
assets/en/cafe/INVITE_IN_SECOND.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
assets/en/cafe/INVITE_IN_SECOND_CLOSE.png
Normal file
|
After Width: | Height: | Size: 5.4 KiB |
BIN
assets/en/cafe/INVITE_SUBSTITUTE.BUTTON.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
assets/en/cafe/INVITE_SUBSTITUTE.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
assets/en/cafe/INVITE_SUBSTITUTE_CLOSE.png
Normal file
|
After Width: | Height: | Size: 5.4 KiB |
BIN
assets/en/cafe/MOMOTALK_INVITE.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
assets/en/cafe/MOMOTALK_ITEM.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
assets/en/cafe/OCR_NAME.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
assets/jp/cafe/CAFE_INVITE.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
BIN
assets/jp/cafe/CAFE_INVITED.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
BIN
assets/jp/cafe/CHECK_MOMOTALK.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
BIN
assets/jp/cafe/INVITE_CONFIRM.BUTTON.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
assets/jp/cafe/INVITE_CONFIRM.png
Normal file
|
After Width: | Height: | Size: 6.3 KiB |
BIN
assets/jp/cafe/INVITE_IN_SECOND.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
assets/jp/cafe/INVITE_IN_SECOND_CLOSE.png
Normal file
|
After Width: | Height: | Size: 5.4 KiB |
BIN
assets/jp/cafe/INVITE_SUBSTITUTE.BUTTON.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
assets/jp/cafe/INVITE_SUBSTITUTE.png
Normal file
|
After Width: | Height: | Size: 8.7 KiB |
BIN
assets/jp/cafe/INVITE_SUBSTITUTE_CLOSE.png
Normal file
|
After Width: | Height: | Size: 5.4 KiB |
BIN
assets/jp/cafe/MOMOTALK_INVITE.png
Normal file
|
After Width: | Height: | Size: 5.9 KiB |
BIN
assets/jp/cafe/MOMOTALK_ITEM.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
assets/jp/cafe/OCR_NAME.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
@ -45,6 +45,13 @@
|
||||
"Touch": true,
|
||||
"AutoAdjust": true,
|
||||
"SecondCafe": true
|
||||
},
|
||||
"Invitation": {
|
||||
"Enable": true,
|
||||
"WaitingHour": 0,
|
||||
"Choice": "list_top",
|
||||
"Name": null,
|
||||
"Substitute": false
|
||||
}
|
||||
},
|
||||
"Circle": {
|
||||
|
||||
@ -205,6 +205,38 @@
|
||||
"type": "checkbox",
|
||||
"value": true
|
||||
}
|
||||
},
|
||||
"Invitation": {
|
||||
"Enable": {
|
||||
"type": "checkbox",
|
||||
"value": true
|
||||
},
|
||||
"WaitingHour": {
|
||||
"type": "select",
|
||||
"value": 0,
|
||||
"option": [
|
||||
0,
|
||||
3,
|
||||
6,
|
||||
9
|
||||
]
|
||||
},
|
||||
"Choice": {
|
||||
"type": "select",
|
||||
"value": "list_top",
|
||||
"option": [
|
||||
"list_top",
|
||||
"by_name"
|
||||
]
|
||||
},
|
||||
"Name": {
|
||||
"type": "textarea",
|
||||
"value": null
|
||||
},
|
||||
"Substitute": {
|
||||
"type": "checkbox",
|
||||
"value": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"Circle": {
|
||||
|
||||
@ -80,6 +80,18 @@ Cafe:
|
||||
Touch: true
|
||||
AutoAdjust: true
|
||||
SecondCafe: true
|
||||
Invitation:
|
||||
Enable: true
|
||||
WaitingHour:
|
||||
value: 0
|
||||
option: [ 0, 3, 6, 9 ]
|
||||
Choice:
|
||||
value: list_top
|
||||
option: [ list_top, by_name ]
|
||||
Name:
|
||||
value: null
|
||||
type: textarea
|
||||
Substitute: false
|
||||
|
||||
Bounty:
|
||||
OnError:
|
||||
|
||||
@ -25,6 +25,7 @@ Daily:
|
||||
Cafe:
|
||||
- Scheduler
|
||||
- Cafe
|
||||
- Invitation
|
||||
Circle:
|
||||
- Scheduler
|
||||
Mail:
|
||||
|
||||
@ -45,6 +45,13 @@ class GeneratedConfig:
|
||||
Cafe_AutoAdjust = True
|
||||
Cafe_SecondCafe = True
|
||||
|
||||
# Group `Invitation`
|
||||
Invitation_Enable = True
|
||||
Invitation_WaitingHour = 0 # 0, 3, 6, 9
|
||||
Invitation_Choice = 'list_top' # list_top, by_name
|
||||
Invitation_Name = None
|
||||
Invitation_Substitute = False
|
||||
|
||||
# Group `Bounty`
|
||||
Bounty_OnError = 'skip' # stop, skip
|
||||
|
||||
|
||||
@ -221,6 +221,38 @@
|
||||
"help": "JP server only\nEnable auto switch to second floor and perform interaction"
|
||||
}
|
||||
},
|
||||
"Invitation": {
|
||||
"_info": {
|
||||
"name": "Invitation Settings",
|
||||
"help": ""
|
||||
},
|
||||
"Enable": {
|
||||
"name": "Enable",
|
||||
"help": "Enable cafe invitation"
|
||||
},
|
||||
"WaitingHour": {
|
||||
"name": "Invitation Condition",
|
||||
"help": "Choose whether to invite students based on the remaining time before next cafe refresh\nThis is for obtaining maximum student interation and maximum affection when AFK. Recommended option:\n24*7 AFK:\t\t Choose \"If 9 more hours remaining\"\nNormal usage:\t Choose \"Invite immediately\"",
|
||||
"0": "Invite immediately",
|
||||
"3": "If 3 more hours remaining",
|
||||
"6": "If 6 more hours remaining",
|
||||
"9": "If 9 more hours remaining"
|
||||
},
|
||||
"Choice": {
|
||||
"name": "Choose Inviting Student",
|
||||
"help": "Top first student of list: Invite the student at the top first of the list\nBy name: Invite the student with the name you set below",
|
||||
"list_top": "Top first student of list",
|
||||
"by_name": "By name"
|
||||
},
|
||||
"Name": {
|
||||
"name": "Inviting Student Name",
|
||||
"help": "Fill in the name of the student to be invited. Use in-game text language. Use > to connect multiple students. Example:\nJP: ホシノ(水着) > 御坂美琴 > ユズ\nOVERSEA: Hoshino(Swimsuit) > Yuuka > Kayoko(New Year)"
|
||||
},
|
||||
"Substitute": {
|
||||
"name": "Replace existing student",
|
||||
"help": "Whether to replace the existing student with their alt.\nIf not, try to match the next student"
|
||||
}
|
||||
},
|
||||
"Bounty": {
|
||||
"_info": {
|
||||
"name": "Bounty Settings",
|
||||
|
||||
@ -221,6 +221,38 @@
|
||||
"help": "仅支持日服\n自动切换第二咖啡厅进行互动点击"
|
||||
}
|
||||
},
|
||||
"Invitation": {
|
||||
"_info": {
|
||||
"name": "邀请设置",
|
||||
"help": ""
|
||||
},
|
||||
"Enable": {
|
||||
"name": "启用",
|
||||
"help": "是否启用咖啡厅邀请功能"
|
||||
},
|
||||
"WaitingHour": {
|
||||
"name": "邀请条件",
|
||||
"help": "根据距离下一次咖啡厅刷新的时长,选择是否邀请学生\n此项设立是为了后台挂机最大化收益,使得邀请券能被最大化利用。推荐选项:\n常驻挂机:\t选择“离下次刷新 9 小时以上”\n非常驻挂机:\t选择“不等待刷新,立即邀请”,或根据自己挂机时长选择",
|
||||
"0": "不等待刷新,立即邀请",
|
||||
"3": "离下次刷新 3 小时以上",
|
||||
"6": "离下次刷新 6 小时以上",
|
||||
"9": "离下次刷新 9 小时以上"
|
||||
},
|
||||
"Choice": {
|
||||
"name": "选择邀请学生",
|
||||
"help": "按列表第一个:优先邀请列表中第一个学生,若失败则则尝试下一个\n按名字:优先邀请下方填写学生名的第一个,若失败则尝试下一个",
|
||||
"list_top": "按列表第一个",
|
||||
"by_name": "按名字"
|
||||
},
|
||||
"Name": {
|
||||
"name": "邀请学生名",
|
||||
"help": "填写要邀请的学生的名字,使用游戏内语言填写,多个学生使用 > 连接。例:\n日服:\tホシノ(水着) > 御坂美琴 > ユズ\n国际服:\tHoshino(Swimsuit) > Yuuka > Kayoko(New Year)"
|
||||
},
|
||||
"Substitute": {
|
||||
"name": "是否替换已存在学生",
|
||||
"help": "若咖啡厅已存在所邀请学生的不同服装,选择是否替换该学生\n若不替换,则尝试匹配下一位学生"
|
||||
}
|
||||
},
|
||||
"Bounty": {
|
||||
"_info": {
|
||||
"name": "悬赏通缉设置",
|
||||
|
||||
@ -40,6 +40,40 @@ CAFE_FIRST = ButtonWrapper(
|
||||
button=(82, 152, 136, 175),
|
||||
),
|
||||
)
|
||||
CAFE_INVITE = ButtonWrapper(
|
||||
name='CAFE_INVITE',
|
||||
jp=Button(
|
||||
file='./assets/jp/cafe/CAFE_INVITE.png',
|
||||
area=(816, 635, 845, 655),
|
||||
search=(796, 615, 865, 675),
|
||||
color=(173, 182, 192),
|
||||
button=(816, 635, 845, 655),
|
||||
),
|
||||
en=Button(
|
||||
file='./assets/en/cafe/CAFE_INVITE.png',
|
||||
area=(816, 635, 845, 655),
|
||||
search=(796, 615, 865, 675),
|
||||
color=(173, 182, 192),
|
||||
button=(816, 635, 845, 655),
|
||||
),
|
||||
)
|
||||
CAFE_INVITED = ButtonWrapper(
|
||||
name='CAFE_INVITED',
|
||||
jp=Button(
|
||||
file='./assets/jp/cafe/CAFE_INVITED.png',
|
||||
area=(815, 633, 847, 657),
|
||||
search=(795, 613, 867, 677),
|
||||
color=(144, 144, 146),
|
||||
button=(815, 633, 847, 657),
|
||||
),
|
||||
en=Button(
|
||||
file='./assets/en/cafe/CAFE_INVITED.png',
|
||||
area=(815, 633, 847, 657),
|
||||
search=(795, 613, 867, 677),
|
||||
color=(144, 144, 146),
|
||||
button=(815, 633, 847, 657),
|
||||
),
|
||||
)
|
||||
CAFE_SECOND = ButtonWrapper(
|
||||
name='CAFE_SECOND',
|
||||
jp=Button(
|
||||
@ -91,6 +125,23 @@ CHANGE_CAFE_SELECTED = ButtonWrapper(
|
||||
button=(40, 87, 191, 112),
|
||||
),
|
||||
)
|
||||
CHECK_MOMOTALK = ButtonWrapper(
|
||||
name='CHECK_MOMOTALK',
|
||||
jp=Button(
|
||||
file='./assets/jp/cafe/CHECK_MOMOTALK.png',
|
||||
area=(421, 83, 447, 108),
|
||||
search=(401, 63, 467, 128),
|
||||
color=(253, 203, 212),
|
||||
button=(421, 83, 447, 108),
|
||||
),
|
||||
en=Button(
|
||||
file='./assets/en/cafe/CHECK_MOMOTALK.png',
|
||||
area=(421, 83, 447, 108),
|
||||
search=(401, 63, 467, 128),
|
||||
color=(253, 203, 212),
|
||||
button=(421, 83, 447, 108),
|
||||
),
|
||||
)
|
||||
CHECK_REWARD = ButtonWrapper(
|
||||
name='CHECK_REWARD',
|
||||
jp=Button(
|
||||
@ -186,6 +237,91 @@ INVENTORY = ButtonWrapper(
|
||||
button=(1123, 90, 1165, 130),
|
||||
),
|
||||
)
|
||||
INVITE_CONFIRM = ButtonWrapper(
|
||||
name='INVITE_CONFIRM',
|
||||
jp=Button(
|
||||
file='./assets/jp/cafe/INVITE_CONFIRM.png',
|
||||
area=(609, 147, 671, 178),
|
||||
search=(589, 127, 691, 198),
|
||||
color=(152, 164, 177),
|
||||
button=(665, 471, 870, 533),
|
||||
),
|
||||
en=Button(
|
||||
file='./assets/en/cafe/INVITE_CONFIRM.png',
|
||||
area=(592, 149, 689, 176),
|
||||
search=(572, 129, 709, 196),
|
||||
color=(169, 179, 191),
|
||||
button=(664, 470, 872, 534),
|
||||
),
|
||||
)
|
||||
INVITE_IN_SECOND = ButtonWrapper(
|
||||
name='INVITE_IN_SECOND',
|
||||
jp=Button(
|
||||
file='./assets/jp/cafe/INVITE_IN_SECOND.png',
|
||||
area=(482, 147, 799, 177),
|
||||
search=(462, 127, 819, 197),
|
||||
color=(166, 177, 188),
|
||||
button=(482, 147, 799, 177),
|
||||
),
|
||||
en=Button(
|
||||
file='./assets/en/cafe/INVITE_IN_SECOND.png',
|
||||
area=(482, 147, 799, 177),
|
||||
search=(462, 127, 819, 197),
|
||||
color=(166, 177, 188),
|
||||
button=(482, 147, 799, 177),
|
||||
),
|
||||
)
|
||||
INVITE_IN_SECOND_CLOSE = ButtonWrapper(
|
||||
name='INVITE_IN_SECOND_CLOSE',
|
||||
jp=Button(
|
||||
file='./assets/jp/cafe/INVITE_IN_SECOND_CLOSE.png',
|
||||
area=(874, 150, 900, 176),
|
||||
search=(854, 130, 920, 196),
|
||||
color=(180, 189, 198),
|
||||
button=(874, 150, 900, 176),
|
||||
),
|
||||
en=Button(
|
||||
file='./assets/en/cafe/INVITE_IN_SECOND_CLOSE.png',
|
||||
area=(874, 150, 900, 176),
|
||||
search=(854, 130, 920, 196),
|
||||
color=(180, 189, 198),
|
||||
button=(874, 150, 900, 176),
|
||||
),
|
||||
)
|
||||
INVITE_SUBSTITUTE = ButtonWrapper(
|
||||
name='INVITE_SUBSTITUTE',
|
||||
jp=Button(
|
||||
file='./assets/jp/cafe/INVITE_SUBSTITUTE.png',
|
||||
area=(582, 154, 698, 184),
|
||||
search=(562, 134, 718, 204),
|
||||
color=(154, 166, 179),
|
||||
button=(673, 478, 858, 541),
|
||||
),
|
||||
en=Button(
|
||||
file='./assets/en/cafe/INVITE_SUBSTITUTE.png',
|
||||
area=(506, 157, 775, 186),
|
||||
search=(486, 137, 795, 206),
|
||||
color=(176, 186, 196),
|
||||
button=(673, 477, 857, 542),
|
||||
),
|
||||
)
|
||||
INVITE_SUBSTITUTE_CLOSE = ButtonWrapper(
|
||||
name='INVITE_SUBSTITUTE_CLOSE',
|
||||
jp=Button(
|
||||
file='./assets/jp/cafe/INVITE_SUBSTITUTE_CLOSE.png',
|
||||
area=(867, 158, 893, 184),
|
||||
search=(847, 138, 913, 204),
|
||||
color=(180, 189, 199),
|
||||
button=(867, 158, 893, 184),
|
||||
),
|
||||
en=Button(
|
||||
file='./assets/en/cafe/INVITE_SUBSTITUTE_CLOSE.png',
|
||||
area=(867, 158, 893, 184),
|
||||
search=(847, 138, 913, 204),
|
||||
color=(180, 189, 199),
|
||||
button=(867, 158, 893, 184),
|
||||
),
|
||||
)
|
||||
MOMOTALK_CLOSE = ButtonWrapper(
|
||||
name='MOMOTALK_CLOSE',
|
||||
jp=Button(
|
||||
@ -203,6 +339,40 @@ MOMOTALK_CLOSE = ButtonWrapper(
|
||||
button=(824, 82, 850, 108),
|
||||
),
|
||||
)
|
||||
MOMOTALK_INVITE = ButtonWrapper(
|
||||
name='MOMOTALK_INVITE',
|
||||
jp=Button(
|
||||
file='./assets/jp/cafe/MOMOTALK_INVITE.png',
|
||||
area=(764, 211, 809, 234),
|
||||
search=(744, 191, 829, 254),
|
||||
color=(90, 163, 195),
|
||||
button=(764, 211, 809, 234),
|
||||
),
|
||||
en=Button(
|
||||
file='./assets/en/cafe/MOMOTALK_INVITE.png',
|
||||
area=(755, 210, 817, 233),
|
||||
search=(735, 190, 837, 253),
|
||||
color=(98, 179, 211),
|
||||
button=(755, 210, 817, 233),
|
||||
),
|
||||
)
|
||||
MOMOTALK_ITEM = ButtonWrapper(
|
||||
name='MOMOTALK_ITEM',
|
||||
jp=Button(
|
||||
file='./assets/jp/cafe/MOMOTALK_ITEM.png',
|
||||
area=(489, 193, 864, 259),
|
||||
search=(469, 173, 884, 279),
|
||||
color=(203, 230, 240),
|
||||
button=(489, 193, 864, 259),
|
||||
),
|
||||
en=Button(
|
||||
file='./assets/en/cafe/MOMOTALK_ITEM.png',
|
||||
area=(489, 193, 864, 259),
|
||||
search=(469, 173, 884, 279),
|
||||
color=(203, 230, 240),
|
||||
button=(489, 193, 864, 259),
|
||||
),
|
||||
)
|
||||
OCR_CAFE = ButtonWrapper(
|
||||
name='OCR_CAFE',
|
||||
jp=Button(
|
||||
@ -220,6 +390,23 @@ OCR_CAFE = ButtonWrapper(
|
||||
button=(1105, 639, 1195, 674),
|
||||
),
|
||||
)
|
||||
OCR_NAME = ButtonWrapper(
|
||||
name='OCR_NAME',
|
||||
jp=Button(
|
||||
file='./assets/jp/cafe/OCR_NAME.png',
|
||||
area=(488, 194, 704, 588),
|
||||
search=(468, 174, 724, 608),
|
||||
color=(237, 239, 241),
|
||||
button=(488, 194, 704, 588),
|
||||
),
|
||||
en=Button(
|
||||
file='./assets/en/cafe/OCR_NAME.png',
|
||||
area=(488, 194, 704, 588),
|
||||
search=(468, 174, 724, 608),
|
||||
color=(237, 239, 241),
|
||||
button=(488, 194, 704, 588),
|
||||
),
|
||||
)
|
||||
STUDENT_LIST = ButtonWrapper(
|
||||
name='STUDENT_LIST',
|
||||
jp=Button(
|
||||
|
||||
@ -6,6 +6,7 @@ from module.logger import logger
|
||||
from module.ui.switch import Switch
|
||||
from tasks.base.page import page_cafe
|
||||
from tasks.cafe.assets.assets_cafe import *
|
||||
from tasks.cafe.invitation import handle_invitation
|
||||
from tasks.cafe.ui import CafeUI
|
||||
|
||||
SWITCH_CAFE = Switch('Cafe_switch')
|
||||
@ -22,8 +23,9 @@ class CafeStatus(Enum):
|
||||
OCR = 1
|
||||
REWARD = 2
|
||||
GOT = 3
|
||||
CLICK = 4
|
||||
CHECK = 5
|
||||
INVITATION = 4
|
||||
CLICK = 5
|
||||
CHECK = 6
|
||||
FINISHED = -1
|
||||
|
||||
|
||||
@ -63,6 +65,9 @@ class Cafe(CafeUI):
|
||||
logger.info('Cafe reward have been got')
|
||||
self.appear_then_click(GET_REWARD_CLOSE)
|
||||
if not self.appear(GET_REWARD_CLOSE):
|
||||
return CafeStatus.INVITATION
|
||||
case CafeStatus.INVITATION:
|
||||
if handle_invitation(self):
|
||||
return CafeStatus.CLICK
|
||||
case CafeStatus.CLICK:
|
||||
buttons = self.get_clickable_buttons(offset=(45, 10))
|
||||
|
||||
314
tasks/cafe/invitation.py
Normal file
@ -0,0 +1,314 @@
|
||||
import re
|
||||
from datetime import datetime, timedelta
|
||||
from enum import Enum
|
||||
|
||||
import numpy as np
|
||||
|
||||
from module.base.base import ModuleBase
|
||||
from module.base.timer import Timer
|
||||
from module.base.utils import area_size, area_offset
|
||||
from module.config.utils import get_server_next_update
|
||||
from module.logger import logger
|
||||
from module.ocr.ocr import Ocr
|
||||
from tasks.cafe.assets.assets_cafe import *
|
||||
|
||||
|
||||
class InvitationOcr(Ocr):
|
||||
def after_process(self, result):
|
||||
result = super().after_process(result)
|
||||
result = result.replace('モI', 'モエ')
|
||||
return result
|
||||
|
||||
|
||||
class InvitationStatus(Enum):
|
||||
MOMOTALK = 0
|
||||
OCR = 1
|
||||
SELECT = 2
|
||||
CONFIRM = 3
|
||||
SUBSTITUTE = 4
|
||||
IN_SECOND = 5
|
||||
INVITED = 6
|
||||
FAILED = 7
|
||||
FINISHED = -1
|
||||
|
||||
|
||||
class Invitation:
|
||||
swipe_vector_range = (0.65, 0.85)
|
||||
cafe_update = ["04:00", "16:00"]
|
||||
|
||||
def __init__(self, name: str):
|
||||
self.name = name
|
||||
self.ocr = InvitationOcr(OCR_NAME)
|
||||
self.list = OCR_NAME
|
||||
self.item = MOMOTALK_ITEM
|
||||
self.invite = MOMOTALK_INVITE
|
||||
|
||||
self.target_names = []
|
||||
self.waiting_hour = None
|
||||
self.substitute = None
|
||||
self.choice = None
|
||||
|
||||
self.invited = []
|
||||
self.current_names = []
|
||||
|
||||
def __str__(self):
|
||||
return f'Invitation({self.name})'
|
||||
|
||||
__repr__ = __str__
|
||||
|
||||
def __eq__(self, other):
|
||||
return str(self) == str(other)
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.name)
|
||||
|
||||
def swipe_page(self, main: ModuleBase, vector_range=None, reverse=False):
|
||||
"""
|
||||
Args:
|
||||
main:
|
||||
vector_range (tuple[float, float]):
|
||||
reverse (bool):
|
||||
"""
|
||||
if vector_range is None:
|
||||
vector_range = self.swipe_vector_range
|
||||
vector = np.random.uniform(*vector_range)
|
||||
width, height = area_size(self.list.button)
|
||||
vector = (0, -vector * height)
|
||||
|
||||
if reverse:
|
||||
vector = (-vector[0], -vector[1])
|
||||
name = f'{self.name}_SWIPE'
|
||||
main.device.swipe_vector(vector, self.list.button, name=name)
|
||||
main.device.click_record_remove(name)
|
||||
|
||||
def load_names(self, main: ModuleBase):
|
||||
names = self.ocr.detect_and_ocr(main.device.image)
|
||||
if not names:
|
||||
logger.warning(f'No valid names in {self.ocr.name}')
|
||||
return
|
||||
self.current_names = []
|
||||
for name_ in names:
|
||||
name: str = name_.ocr_text.replace(' ', '')
|
||||
if name.isdigit():
|
||||
continue
|
||||
if name.startswith('('):
|
||||
if not self.current_names:
|
||||
continue
|
||||
n = self.current_names.pop(len(self.current_names) - 1)
|
||||
self.current_names.append((n[0] + name, n[1]))
|
||||
continue
|
||||
self.current_names.append((name, name_.box))
|
||||
|
||||
@property
|
||||
def is_invitation(self) -> bool:
|
||||
return get_server_next_update(self.cafe_update) - datetime.now() > timedelta(hours=self.waiting_hour)
|
||||
|
||||
@property
|
||||
def names(self):
|
||||
return list(map(lambda x: x[0], self.current_names))
|
||||
|
||||
@property
|
||||
def target_name(self):
|
||||
return self.target_names[0] if self.target_names else None
|
||||
|
||||
def on_success(self):
|
||||
logger.info(f'Invited {self.target_name}')
|
||||
self.invited.append(self.target_name)
|
||||
self.target_names.pop(0)
|
||||
|
||||
def on_failed(self):
|
||||
logger.warning(f'Failed to invite {self.target_name}')
|
||||
self.target_names.pop(0)
|
||||
|
||||
def insight_name(self, name: str, main: ModuleBase, skip_first_screenshot=True) -> bool:
|
||||
"""
|
||||
Args:
|
||||
name:
|
||||
main:
|
||||
skip_first_screenshot:
|
||||
"""
|
||||
logger.info(f'Insight name: {name}')
|
||||
last_names: set[str] = set()
|
||||
|
||||
while 1:
|
||||
if skip_first_screenshot:
|
||||
skip_first_screenshot = False
|
||||
else:
|
||||
main.device.screenshot()
|
||||
|
||||
self.load_names(main)
|
||||
|
||||
if name in self.names:
|
||||
return True
|
||||
|
||||
names = self.names
|
||||
if names and last_names == set(names):
|
||||
logger.warning(f'Name not found: {name}')
|
||||
return False
|
||||
last_names = set(names)
|
||||
|
||||
self.swipe_page(main)
|
||||
|
||||
main.wait_until_stable(
|
||||
self.list.button,
|
||||
timer=Timer(0, 0),
|
||||
timeout=Timer(1.5, 5)
|
||||
)
|
||||
|
||||
def select_name_invite(
|
||||
self,
|
||||
main: ModuleBase,
|
||||
name: str = None,
|
||||
insight: bool = True,
|
||||
skip_first_screenshot: bool = True
|
||||
) -> bool:
|
||||
"""
|
||||
Args:
|
||||
main:
|
||||
name:
|
||||
insight:
|
||||
skip_first_screenshot:
|
||||
|
||||
Returns:
|
||||
If success
|
||||
"""
|
||||
if name is None:
|
||||
if not self.target_name:
|
||||
return False
|
||||
name = self.target_name
|
||||
if insight and not self.insight_name(name, main, skip_first_screenshot):
|
||||
return False
|
||||
|
||||
logger.info(f'Select name: {name}')
|
||||
click_interval = Timer(1, 2)
|
||||
load_names_interval = Timer(1, 5)
|
||||
timeout = Timer(10, 10).start()
|
||||
while 1:
|
||||
if skip_first_screenshot:
|
||||
skip_first_screenshot = False
|
||||
else:
|
||||
main.device.screenshot()
|
||||
|
||||
if load_names_interval.reached_and_reset() and not insight:
|
||||
self.load_names(main)
|
||||
|
||||
name_box = next(filter(lambda x: x[0] == name, self.current_names), None)
|
||||
if name_box is None:
|
||||
logger.warning(f'No name {name} in {self.ocr.name}')
|
||||
continue
|
||||
|
||||
search_box = area_offset((0, 0, *area_size(self.item.area)), name_box[1][:2])
|
||||
self.invite.load_search(search_box)
|
||||
click_button = self.invite.match_multi_template(main.device.image)
|
||||
|
||||
if not click_button:
|
||||
logger.warning(f'No clickable {self.invite.name}')
|
||||
continue
|
||||
|
||||
if click_interval.reached_and_reset():
|
||||
main.device.click(click_button[0])
|
||||
return True
|
||||
|
||||
if timeout.reached():
|
||||
logger.warning(f'No clickable {self.invite.name}')
|
||||
return False
|
||||
|
||||
|
||||
invitation = Invitation('CafeInvitation')
|
||||
|
||||
|
||||
def handle_invitation_status(status: InvitationStatus, main: ModuleBase) -> InvitationStatus:
|
||||
match status:
|
||||
case InvitationStatus.MOMOTALK:
|
||||
if not invitation.is_invitation:
|
||||
logger.info('Invitation waiting until next refresh')
|
||||
return InvitationStatus.FINISHED
|
||||
if main.appear(CAFE_INVITED):
|
||||
logger.info('Invitation in cooldown')
|
||||
return InvitationStatus.FINISHED
|
||||
if invitation.choice != 'list_top' and invitation.target_name is None:
|
||||
logger.warning('No student to be invited or all invitations failed')
|
||||
return InvitationStatus.FINISHED
|
||||
if main.appear(CHECK_MOMOTALK):
|
||||
return InvitationStatus.OCR
|
||||
main.appear_then_click(CAFE_INVITE)
|
||||
case InvitationStatus.OCR:
|
||||
if invitation.choice == 'list_top':
|
||||
invitation.load_names(main)
|
||||
invitation.target_names = invitation.names
|
||||
invitation.choice = 'list'
|
||||
if invitation.select_name_invite(main):
|
||||
return InvitationStatus.SELECT
|
||||
return InvitationStatus.FAILED
|
||||
case InvitationStatus.SELECT:
|
||||
if main.appear(INVITE_CONFIRM):
|
||||
return InvitationStatus.CONFIRM
|
||||
if main.config.LANG == 'jp' and main.appear(INVITE_IN_SECOND):
|
||||
return InvitationStatus.IN_SECOND
|
||||
if main.appear(INVITE_SUBSTITUTE):
|
||||
return InvitationStatus.SUBSTITUTE
|
||||
case InvitationStatus.CONFIRM:
|
||||
main.appear_then_click(INVITE_CONFIRM)
|
||||
if not main.appear(INVITE_CONFIRM):
|
||||
invitation.on_success()
|
||||
return InvitationStatus.INVITED
|
||||
case InvitationStatus.IN_SECOND:
|
||||
main.appear_then_click(INVITE_IN_SECOND_CLOSE)
|
||||
return InvitationStatus.FAILED
|
||||
case InvitationStatus.SUBSTITUTE:
|
||||
if not invitation.substitute:
|
||||
main.appear_then_click(INVITE_SUBSTITUTE_CLOSE)
|
||||
return InvitationStatus.FAILED
|
||||
else:
|
||||
main.appear_then_click(INVITE_SUBSTITUTE)
|
||||
if not main.appear(INVITE_SUBSTITUTE):
|
||||
return InvitationStatus.INVITED
|
||||
case InvitationStatus.INVITED:
|
||||
main.appear_then_click(MOMOTALK_CLOSE)
|
||||
if not main.appear(MOMOTALK_CLOSE):
|
||||
return InvitationStatus.FINISHED
|
||||
case InvitationStatus.FAILED:
|
||||
main.appear_then_click(MOMOTALK_CLOSE)
|
||||
if not main.appear(CHECK_MOMOTALK):
|
||||
invitation.on_failed()
|
||||
return InvitationStatus.MOMOTALK
|
||||
case InvitationStatus.FINISHED:
|
||||
pass
|
||||
case _:
|
||||
logger.warning(f'Invalid status: {status}')
|
||||
return status
|
||||
|
||||
|
||||
def handle_invitation(main: ModuleBase):
|
||||
if not main.config.Invitation_Enable:
|
||||
logger.info('Invitation disabled')
|
||||
return True
|
||||
invitation.waiting_hour = main.config.Invitation_WaitingHour
|
||||
invitation.substitute = main.config.Invitation_Substitute
|
||||
if invitation.choice is None:
|
||||
invitation.choice = main.config.Invitation_Choice
|
||||
if invitation.choice == 'by_name' and not invitation.target_names:
|
||||
name = main.config.Invitation_Name
|
||||
if name is None:
|
||||
logger.warning('Choose By Name but Inviting Student Name is blank')
|
||||
return True
|
||||
name = re.sub(r'[ \t\r\n]', '', name)
|
||||
name = re.sub(r'[>﹥›˃ᐳ❯]', '>', name)
|
||||
name = re.sub(r'(', '(', name)
|
||||
name = re.sub(r')', ')', name)
|
||||
invitation.target_names = name.split('>')
|
||||
status = InvitationStatus.MOMOTALK
|
||||
action_timer = Timer(1, 1)
|
||||
loading_timer = Timer(1, 1)
|
||||
while 1:
|
||||
main.device.screenshot()
|
||||
|
||||
if not loading_timer.reached():
|
||||
continue
|
||||
|
||||
if action_timer.reached_and_reset():
|
||||
logger.attr('Status', status)
|
||||
status = handle_invitation_status(status, main)
|
||||
|
||||
if status == InvitationStatus.FINISHED:
|
||||
return True
|
||||