Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持了浏览图片字典和自定义用户/m和/mm的单词选择范围 #77

Closed
wants to merge 13 commits into from

Conversation

lben1216
Copy link
Collaborator

@lben1216 lben1216 commented Dec 13, 2021

fix #11 #12

@hdcola hdcola changed the title fix #11 #12 支持了浏览图片字典和自定义用户/m和/mm的单词选择范围 Dec 16, 2021
utils/filters.py Outdated
@@ -20,6 +20,11 @@ def check_chatids_valid(chatids):
return False
return True

def check_callback_user(uid,data):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哈哈,这个应该改成一个filter

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

房东哥我有点不太明白这个, 您是说把变量命名成filter吗?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哈哈,这种函数适合写成filter,在python中有一个语法糖可以使用 @ 放在一个函数前做filter。

可以参考这个实现

def check_admin_permission(uid):

这样使用

@check_admin_filter

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原来是这样,我大概明白了。 我试着把这个check_user改成filter, 但是发现不太适合,因为这个function是在用户点完之后才会触发, 如果用filter的话似乎没啥用啊, 不知道我这么想对不对。

utils/fileproc.py Outdated Show resolved Hide resolved
cmdproc/spell_picword_cmd.py Outdated Show resolved Hide resolved
@@ -0,0 +1,58 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哈哈,这是一个module,但是叫dict似乎不太对 :)

dict/user_chapter_dict.py Outdated Show resolved Hide resolved

def gen_user_chapter_dict(uid):
stored_data=fetch_user_data(uid)
if stored_data == None: #如果stored_data是空的,就根据chapter_dict重新生成stored_data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果chapter_dict变化了呢?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

添加了一个同步chapter_dict的功能

dict/user_chapter_dict.py Show resolved Hide resolved
Comment on lines +12 to +49
def gen_chapter_list(user_id): #更新章节列表和按钮
menu_keyboard= []
chapter_preview_msg = "Chapter List\n\n"
count = 1
for key,value in chapter_dict.items():
menu_keyboard.append([
InlineKeyboardButton(text=f"Chapter {count}: {key}", callback_data=f"preview-chapter-topic:{key}:{user_id}")
])
count += 1

menu_keyboard.append([
InlineKeyboardButton(text=f"Finish",callback_data=f"preview-chapter-finish:{user_id}")
])
return chapter_preview_msg,menu_keyboard

def gen_topic_list(chapter_id,user_id):
topic_list = list(chapter_dict[chapter_id].keys()) #获取数据库中的所有topic列表
chap_num = list(chapter_dict.keys()).index(chapter_id) #获取用户选取的topic
if chap_num == 0:
prev_chap = "None"
if chap_num == len(list(chapter_dict.keys())) - 1:
next_chap = "None"
if chap_num > 0:
prev_chap = list(chapter_dict.keys())[chap_num - 1]
if chap_num < len(list(chapter_dict.keys())) - 1:
next_chap = list(chapter_dict.keys())[chap_num + 1]
topic_preview_msg = f"Topic List\nChapter Name:{chapter_id}\n\n"
topic_menu_keyboard = []
count = 1
for topic in topic_list:
topic_preview_msg += f"{count} {topic}\n"
count += 1
topic_menu_keyboard.append([
InlineKeyboardButton(text=f"Prev",callback_data=f"preview-topic-page:{prev_chap}:{user_id}"),
InlineKeyboardButton(text=f"Back to Chapter List",callback_data=f"preview-topic-back:{chap_num}:{user_id}"),
InlineKeyboardButton(text=f"Next",callback_data=f"preview-topic-page:{next_chap}:{user_id}")
])
return topic_preview_msg,topic_menu_keyboard
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

跪求 unit test

dict/user_chapter_dict.py Outdated Show resolved Hide resolved
@hdcola hdcola deleted the branch HDCodePractice:hddev May 4, 2022 20:36
@hdcola hdcola closed this May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants