-
Notifications
You must be signed in to change notification settings - Fork 20
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
Conversation
utils/filters.py
Outdated
@@ -20,6 +20,11 @@ def check_chatids_valid(chatids): | |||
return False | |||
return True | |||
|
|||
def check_callback_user(uid,data): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哈哈,这个应该改成一个filter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
房东哥我有点不太明白这个, 您是说把变量命名成filter吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哈哈,这种函数适合写成filter,在python中有一个语法糖可以使用 @ 放在一个函数前做filter。
可以参考这个实现
EnglishHelper/utils/filters.py
Line 4 in fb90cfe
def check_admin_permission(uid): |
这样使用
EnglishHelper/cmdproc/upload.py
Line 39 in fb90cfe
@check_admin_filter |
There was a problem hiding this comment.
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的话似乎没啥用啊, 不知道我这么想对不对。
@@ -0,0 +1,58 @@ | |||
|
There was a problem hiding this comment.
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
|
||
def gen_user_chapter_dict(uid): | ||
stored_data=fetch_user_data(uid) | ||
if stored_data == None: #如果stored_data是空的,就根据chapter_dict重新生成stored_data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果chapter_dict变化了呢?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
添加了一个同步chapter_dict的功能
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
跪求 unit test
fix #11 #12