@@ -25,6 +25,24 @@ class FileCommand(commands.Cog):
25
25
def __init__ (self , bot ):
26
26
self .bot = bot
27
27
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
28
46
29
47
async def get_files_list (self , branches = ("data" , "assets" )):
30
48
async with ClientSession (headers = GITHUB_HEADERS ) as session :
@@ -95,24 +113,6 @@ async def update_versions_hashes(self, newer_version=None):
95
113
@app_commands .describe (path = "Путь/название интересующего файла" )
96
114
97
115
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
116
116
is_image = False
117
117
if version == "latest" :
118
118
current_files = files
@@ -129,7 +129,7 @@ def search_files(query, files):
129
129
versions_hashes ["assets" ][version_for_mongo ]
130
130
))
131
131
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 )
133
133
path = all_results [0 ]
134
134
#
135
135
path_tree = ""
@@ -197,5 +197,5 @@ async def file_autocomplete(self, ctx: discord.Interaction, curr: str) -> List[a
197
197
current_files = files
198
198
return [
199
199
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 )
201
201
][:25 ]
0 commit comments