Skip to content

Commit

Permalink
Merge pull request Ikaros-521#551 from Ikaros-521/owner
Browse files Browse the repository at this point in the history
完成 答谢板块 随机文案的开关功能
  • Loading branch information
Ikaros-521 authored Jan 4, 2024
2 parents 7d9056a + bb1f8bc commit a0c0ecf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
33 changes: 29 additions & 4 deletions utils/my_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import traceback
import importlib
import pyautogui
import copy

from .config import Config
from .common import Common
Expand Down Expand Up @@ -61,6 +62,11 @@ class My_handle(metaclass=SingletonMeta):
}
}

# 答谢板块文案数据临时存储
thanks_entrance_copy = []
thanks_gift_copy = []
thanks_follow_copy = []

def __init__(self, config_path):
logging.info("初始化My_handle...")

Expand Down Expand Up @@ -1681,8 +1687,14 @@ def gift_handle(self, data):
if data["total_price"] < My_handle.config.get("thanks")["lowest_price"]:
return

resp_content = random.choice(My_handle.config.get("thanks", "gift_copy")).format(username=data["username"], gift_name=data["gift_name"])

if My_handle.config.get("thanks", "gift_random"):
resp_content = random.choice(My_handle.config.get("thanks", "gift_copy")).format(username=data["username"], gift_name=data["gift_name"])
else:
# 类变量list中是否有数据,没有就拷贝下数据再顺序取出首个数据
if len(My_handle.thanks_gift_copy) == 0:
My_handle.thanks_gift_copy = copy.copy(My_handle.config.get("thanks", "gift_copy"))
resp_content = My_handle.thanks_gift_copy.pop(0).format(username=data["username"], gift_name=data["gift_name"])

message = {
"type": "gift",
"tts_type": My_handle.config.get("audio_synthesis_type"),
Expand Down Expand Up @@ -1728,7 +1740,13 @@ def entrance_handle(self, data):
if False == My_handle.config.get("thanks")["entrance_enable"]:
return

resp_content = random.choice(My_handle.config.get("thanks", "entrance_copy")).format(username=data["username"])
if My_handle.config.get("thanks", "entrance_random"):
resp_content = random.choice(My_handle.config.get("thanks", "entrance_copy")).format(username=data["username"])
else:
# 类变量list中是否有数据,没有就拷贝下数据再顺序取出首个数据
if len(My_handle.thanks_entrance_copy) == 0:
My_handle.thanks_entrance_copy = copy.copy(My_handle.config.get("thanks", "entrance_copy"))
resp_content = My_handle.thanks_entrance_copy.pop(0).format(username=data["username"])

message = {
"type": "entrance",
Expand Down Expand Up @@ -1764,7 +1782,14 @@ def follow_handle(self, data):
if False == My_handle.config.get("thanks")["follow_enable"]:
return

resp_content = random.choice(My_handle.config.get("thanks", "follow_copy")).format(username=data["username"])
if My_handle.config.get("thanks", "follow_random"):
resp_content = random.choice(My_handle.config.get("thanks", "follow_copy")).format(username=data["username"])
else:
# 类变量list中是否有数据,没有就拷贝下数据再顺序取出首个数据
if len(My_handle.thanks_follow_copy) == 0:
My_handle.thanks_follow_copy = copy.copy(My_handle.config.get("thanks", "follow_copy"))
resp_content = My_handle.thanks_follow_copy.pop(0).format(username=data["username"])


message = {
"type": "follow",
Expand Down
8 changes: 4 additions & 4 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1442,18 +1442,18 @@ def common_textarea_handle(content):
input_filter_schedule_forget_reserve_num = ui.input(label='定时保留数', placeholder='保留最新收到的数据的数量', value=config.get("filter", "schedule_forget_reserve_num")).style("width:200px;")
with ui.card().style(card_css):
ui.label('答谢')
with ui.grid(columns=2):
with ui.row():
input_thanks_username_max_len = ui.input(label='用户名最大长度', value=config.get("thanks", "username_max_len"), placeholder='需要保留的用户名的最大长度,超出部分将被丢弃').style("width:100px;")
with ui.grid(columns=3):
with ui.row():
switch_thanks_entrance_enable = ui.switch('启用入场欢迎', value=config.get("thanks", "entrance_enable")).style(switch_internal_css)
switch_thanks_entrance_random = ui.switch('随机选取', value=config.get("thanks", "entrance_random")).style(switch_internal_css)
textarea_thanks_entrance_copy = ui.textarea(label='入场文案', value=textarea_data_change(config.get("thanks", "entrance_copy")), placeholder='用户进入直播间的相关文案,请勿动 {username},此字符串用于替换用户名').style("width:500px;")
with ui.grid(columns=4):
with ui.row():
switch_thanks_gift_enable = ui.switch('启用礼物答谢', value=config.get("thanks", "gift_enable")).style(switch_internal_css)
switch_thanks_gift_random = ui.switch('随机选取', value=config.get("thanks", "gift_random")).style(switch_internal_css)
textarea_thanks_gift_copy = ui.textarea(label='礼物文案', value=textarea_data_change(config.get("thanks", "gift_copy")), placeholder='用户赠送礼物的相关文案,请勿动 {username} 和 {gift_name},此字符串用于替换用户名和礼物名').style("width:500px;")
input_thanks_lowest_price = ui.input(label='最低答谢礼物价格', value=config.get("thanks", "lowest_price"), placeholder='设置最低答谢礼物的价格(元),低于这个设置的礼物不会触发答谢').style("width:100px;")
with ui.grid(columns=3):
with ui.row():
switch_thanks_follow_enable = ui.switch('启用关注答谢', value=config.get("thanks", "follow_enable")).style(switch_internal_css)
switch_thanks_follow_random = ui.switch('随机选取', value=config.get("thanks", "follow_random")).style(switch_internal_css)
textarea_thanks_follow_copy = ui.textarea(label='关注文案', value=textarea_data_change(config.get("thanks", "follow_copy")), placeholder='用户关注时的相关文案,请勿动 {username},此字符串用于替换用户名').style("width:500px;")
Expand Down

0 comments on commit a0c0ecf

Please sign in to comment.