|
@@ -23,6 +23,14 @@ SOURCE_GIVEAWAY_REFUND = "giveaway_refund"
|
|
|
SOURCE_GIVEAWAY_PARTICIPATION = "giveaway_participation"
|
|
SOURCE_GIVEAWAY_PARTICIPATION = "giveaway_participation"
|
|
|
SOURCE_GIVEAWAY_WINNER = "giveaway_winner"
|
|
SOURCE_GIVEAWAY_WINNER = "giveaway_winner"
|
|
|
|
|
|
|
|
|
|
+DEFAULT_CHECKIN_SUCCESS_MESSAGE = (
|
|
|
|
|
+ "签到成功:+{points} 积分,当前余额:{balance}。"
|
|
|
|
|
+)
|
|
|
|
|
+DEFAULT_CHECKIN_ALREADY_MESSAGE = (
|
|
|
|
|
+ "你今天已经签到过了,当前余额:{balance}。"
|
|
|
|
|
+)
|
|
|
|
|
+CHECKIN_MESSAGE_MAX_LENGTH = 500
|
|
|
|
|
+
|
|
|
POINT_SOURCES = {
|
|
POINT_SOURCES = {
|
|
|
SOURCE_CHECKIN,
|
|
SOURCE_CHECKIN,
|
|
|
SOURCE_ACTIVITY,
|
|
SOURCE_ACTIVITY,
|
|
@@ -40,6 +48,8 @@ DEFAULT_POINT_RULES: dict[str, Any] = {
|
|
|
"checkin_enabled": True,
|
|
"checkin_enabled": True,
|
|
|
"checkin_button_enabled": False,
|
|
"checkin_button_enabled": False,
|
|
|
"checkin_points": 10,
|
|
"checkin_points": 10,
|
|
|
|
|
+ "checkin_success_message": DEFAULT_CHECKIN_SUCCESS_MESSAGE,
|
|
|
|
|
+ "checkin_already_message": DEFAULT_CHECKIN_ALREADY_MESSAGE,
|
|
|
"activity_enabled": True,
|
|
"activity_enabled": True,
|
|
|
"activity_points": 1,
|
|
"activity_points": 1,
|
|
|
"activity_cooldown_seconds": 300,
|
|
"activity_cooldown_seconds": 300,
|
|
@@ -126,6 +136,13 @@ def _safe_bool(value: Any, default: bool) -> bool:
|
|
|
return default
|
|
return default
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def _safe_text(value: Any, default: str, maximum: int) -> str:
|
|
|
|
|
+ text = str(value or "").strip()
|
|
|
|
|
+ if not text:
|
|
|
|
|
+ return default
|
|
|
|
|
+ return text[:maximum]
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def normalize_point_rules(raw: dict[str, Any] | None) -> dict[str, Any]:
|
|
def normalize_point_rules(raw: dict[str, Any] | None) -> dict[str, Any]:
|
|
|
rules = dict(DEFAULT_POINT_RULES)
|
|
rules = dict(DEFAULT_POINT_RULES)
|
|
|
if raw:
|
|
if raw:
|
|
@@ -147,6 +164,16 @@ def normalize_point_rules(raw: dict[str, Any] | None) -> dict[str, Any]:
|
|
|
timezone_name = "Asia/Shanghai"
|
|
timezone_name = "Asia/Shanghai"
|
|
|
rules["timezone"] = timezone_name
|
|
rules["timezone"] = timezone_name
|
|
|
rules["checkin_points"] = _safe_int(rules["checkin_points"], 10, 0, 100000)
|
|
rules["checkin_points"] = _safe_int(rules["checkin_points"], 10, 0, 100000)
|
|
|
|
|
+ rules["checkin_success_message"] = _safe_text(
|
|
|
|
|
+ rules["checkin_success_message"],
|
|
|
|
|
+ DEFAULT_CHECKIN_SUCCESS_MESSAGE,
|
|
|
|
|
+ CHECKIN_MESSAGE_MAX_LENGTH,
|
|
|
|
|
+ )
|
|
|
|
|
+ rules["checkin_already_message"] = _safe_text(
|
|
|
|
|
+ rules["checkin_already_message"],
|
|
|
|
|
+ DEFAULT_CHECKIN_ALREADY_MESSAGE,
|
|
|
|
|
+ CHECKIN_MESSAGE_MAX_LENGTH,
|
|
|
|
|
+ )
|
|
|
rules["activity_points"] = _safe_int(rules["activity_points"], 1, 0, 100000)
|
|
rules["activity_points"] = _safe_int(rules["activity_points"], 1, 0, 100000)
|
|
|
rules["activity_cooldown_seconds"] = _safe_int(
|
|
rules["activity_cooldown_seconds"] = _safe_int(
|
|
|
rules["activity_cooldown_seconds"], 300, 10, 86400
|
|
rules["activity_cooldown_seconds"], 300, 10, 86400
|