@@ -25,6 +25,24 @@ class FileCommand(commands.Cog):
2525 def __init__ (self , bot ):
2626 self .bot = bot
2727 self .update_files_list .start ()
28+
29+ def search_files (self , query , files ):
30+ matches = [file for file in files if query in file ]
31+ if not matches :
32+ matches = []
33+ for file in files :
34+ match_count = 0
35+ query_items_backwards = query .split ("/" )[::- 1 ]
36+ query_size = len (query_items_backwards )
37+ for i in query_items_backwards :
38+ for j in file .split ("/" )[::- 1 ]:
39+ if distance (i , j ) <= min (len (i )/ 3 , 2.7 ):
40+ match_count += 1
41+ break
42+ if match_count >= query_size :
43+ matches .append (file )
44+ break
45+ return matches
2846
2947 async def get_files_list (self , branches = ("data" , "assets" )):
3048 async with ClientSession (headers = GITHUB_HEADERS ) as session :
@@ -95,24 +113,6 @@ async def update_versions_hashes(self, newer_version=None):
95113 @app_commands .describe (path = "Путь/название интересующего файла" )
96114
97115 async def file (self , ctx , path : str , version : str = "latest" ):
98- def search_files (query , files ):
99- matches = []
100- for file in files :
101- if query in file :
102- matches .append (file )
103- else :
104- match_count = 0
105- query_items_backwards = query .split ("/" )[::- 1 ]
106- query_size = len (query_items_backwards )
107- for i in query_items_backwards :
108- for j in file .split ("/" )[::- 1 ]:
109- if distance (i , j ) <= len (i )/ 3 :
110- match_count += 1
111- break
112- if match_count >= query_size :
113- matches .append (file )
114- break
115- return matches
116116 is_image = False
117117 if version == "latest" :
118118 current_files = files
@@ -129,7 +129,7 @@ def search_files(query, files):
129129 versions_hashes ["assets" ][version_for_mongo ]
130130 ))
131131 versions_pathes .insert_one ({"_id" : version_for_mongo , "_" : current_files })
132- all_results = search_files (path , current_files )
132+ all_results = self . search_files (path , current_files )
133133 path = all_results [0 ]
134134 #
135135 path_tree = ""
@@ -197,5 +197,5 @@ async def file_autocomplete(self, ctx: discord.Interaction, curr: str) -> List[a
197197 current_files = files
198198 return [
199199 app_commands .Choice (name = file [- 100 :], value = file [- 100 :])
200- for file in current_files if curr in file
200+ for file in self . search_files ( curr , current_files )
201201 ][:25 ]
0 commit comments