zhenxun_bot/plugins/word_bank/_data_source.py

49 lines
1.5 KiB
Python
Raw Normal View History

2021-11-23 21:44:59 +08:00
from .model import WordBank
from typing import Union
class WordBankBuilder:
def __init__(self, user_id: int, group_id: int, problem: str):
self._data = {
"user_id": user_id,
"group_id": group_id,
"problem": problem
}
def set_placeholder(self, id_: int, placeholder: Union[str, int]):
"""
设置占位符
:param id_: 站位id
:param placeholder: 占位符内容
"""
if self._data.get("placeholder") is None:
self._data["placeholder"] = []
self._data["placeholder"].append((id_, placeholder))
def set_answer(self, answer: str):
"""
设置回答
:param answer: 回答
"""
self._data["answer"] = answer
2022-04-05 22:15:47 +08:00
async def save(self,search_type):
2021-11-23 21:44:59 +08:00
user_id = self._data["user_id"]
group_id = self._data["group_id"]
problem = self._data["problem"]
answer = self._data["answer"]
placeholder = self._data.get("placeholder")
2022-04-05 22:15:47 +08:00
return await WordBank.add_problem_answer(user_id, group_id, search_type,problem, answer, placeholder)
2021-11-23 21:44:59 +08:00
2022-04-01 23:54:40 +08:00
async def update(self, index):
user_id = self._data["user_id"]
group_id = self._data["group_id"]
problem = self._data["problem"]
answer = self._data["answer"]
placeholder = self._data.get("placeholder")
return await WordBank.update_problem_answer(user_id, group_id, problem, answer, index, placeholder)
2021-11-23 21:44:59 +08:00
def __str__(self):
return str(self._data)