加入托福词汇内容,
This commit is contained in:
@@ -13,7 +13,8 @@ from plugins.stats_collector.decorators import plugin_stats_decorator
|
|||||||
from robot_cmd.robot_command import Feature, PermissionStatus, GroupBotManager
|
from robot_cmd.robot_command import Feature, PermissionStatus, GroupBotManager
|
||||||
from db.sign_in import SignInDB
|
from db.sign_in import SignInDB
|
||||||
from db.sign_in_redis import SignInRedisDB
|
from db.sign_in_redis import SignInRedisDB
|
||||||
|
import random
|
||||||
|
import os
|
||||||
|
|
||||||
class MessageSignPlugin(MessagePluginInterface):
|
class MessageSignPlugin(MessagePluginInterface):
|
||||||
"""签到插件"""
|
"""签到插件"""
|
||||||
@@ -49,6 +50,10 @@ class MessageSignPlugin(MessagePluginInterface):
|
|||||||
self.timezone = 'Asia/Shanghai'
|
self.timezone = 'Asia/Shanghai'
|
||||||
self.sign_in_db = None
|
self.sign_in_db = None
|
||||||
self.sign_in_redis = None
|
self.sign_in_redis = None
|
||||||
|
# 添加词汇表文件路径和词汇列表
|
||||||
|
self.vocab_file_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
|
||||||
|
"resource", "6 托福-乱序.txt")
|
||||||
|
self.vocab_list = []
|
||||||
|
|
||||||
def initialize(self, context: Dict[str, Any]) -> bool:
|
def initialize(self, context: Dict[str, Any]) -> bool:
|
||||||
"""初始化插件"""
|
"""初始化插件"""
|
||||||
@@ -85,9 +90,31 @@ class MessageSignPlugin(MessagePluginInterface):
|
|||||||
self.last_reset_date = datetime.now(tz=pytz.timezone(self.timezone)).date()
|
self.last_reset_date = datetime.now(tz=pytz.timezone(self.timezone)).date()
|
||||||
self.sign_in_redis.save_last_reset_date(self.last_reset_date)
|
self.sign_in_redis.save_last_reset_date(self.last_reset_date)
|
||||||
|
|
||||||
self.LOG.info(f"[{self.name}] 插件初始化完成,指令:{self._commands}")
|
# 加载词汇表
|
||||||
|
self.load_vocabulary()
|
||||||
|
|
||||||
|
self.LOG.info(f"[{self.name}] 插件初始化完成,指令:{self._commands},已加载 {len(self.vocab_list)} 个词汇")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def load_vocabulary(self):
|
||||||
|
"""加载词汇表到内存"""
|
||||||
|
try:
|
||||||
|
if os.path.exists(self.vocab_file_path):
|
||||||
|
with open(self.vocab_file_path, 'r', encoding='utf-8') as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
self.vocab_list = [line.strip() for line in lines if line.strip()]
|
||||||
|
self.LOG.info(f"成功加载词汇表,共 {len(self.vocab_list)} 个单词")
|
||||||
|
else:
|
||||||
|
self.LOG.error(f"词汇表文件不存在: {self.vocab_file_path}")
|
||||||
|
except Exception as e:
|
||||||
|
self.LOG.error(f"加载词汇表出错: {e}")
|
||||||
|
|
||||||
|
def get_random_vocabulary(self) -> str:
|
||||||
|
"""从内存中获取随机词汇"""
|
||||||
|
if not self.vocab_list:
|
||||||
|
return "词汇表为空"
|
||||||
|
return random.choice(self.vocab_list)
|
||||||
|
|
||||||
def start(self) -> bool:
|
def start(self) -> bool:
|
||||||
"""启动插件"""
|
"""启动插件"""
|
||||||
self.LOG.info(f"[{self.name}] 插件已启动")
|
self.LOG.info(f"[{self.name}] 插件已启动")
|
||||||
@@ -192,6 +219,8 @@ class MessageSignPlugin(MessagePluginInterface):
|
|||||||
points_to_add, current_time, streak
|
points_to_add, current_time, streak
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 在签到成功后添加每日词汇
|
||||||
|
# 在输出信息中添加每日词汇
|
||||||
output = f"签到成功,加[{points_to_add}]分,第[{today_signin_rank}]个!"
|
output = f"签到成功,加[{points_to_add}]分,第[{today_signin_rank}]个!"
|
||||||
|
|
||||||
if streak_broken and old_streak > 0: # 只有在真的断签且之前有签到记录时才显示
|
if streak_broken and old_streak > 0: # 只有在真的断签且之前有签到记录时才显示
|
||||||
@@ -199,6 +228,10 @@ class MessageSignPlugin(MessagePluginInterface):
|
|||||||
elif streak > 1:
|
elif streak > 1:
|
||||||
output += f"连签 {streak} 天!"
|
output += f"连签 {streak} 天!"
|
||||||
|
|
||||||
|
# 从内存中获取随机词汇
|
||||||
|
daily_vocab = self.get_random_vocabulary()
|
||||||
|
output += f"\n今日词汇:{daily_vocab}"
|
||||||
|
|
||||||
self.message_util.send_text_msg(output, (roomid if roomid else sender), sender)
|
self.message_util.send_text_msg(output, (roomid if roomid else sender), sender)
|
||||||
return True, "签到成功"
|
return True, "签到成功"
|
||||||
|
|
||||||
|
|||||||
13477
resource/6 托福-乱序.txt
Normal file
13477
resource/6 托福-乱序.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user