Skip to content

Commit

Permalink
fix find meme name
Browse files Browse the repository at this point in the history
  • Loading branch information
MeetWq committed Sep 8, 2024
1 parent e9379e7 commit 894e5e9
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions nonebot_plugin_memes/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,32 +161,26 @@ def __dump(self):

def __refresh_names(self):
self.__meme_names = {}

def add(key: str, meme: Meme):
key = key.lower()
if key not in self.__meme_names:
self.__meme_names[key] = []
self.__meme_names[key].append(meme)

for meme in self.__meme_dict.values():
add(meme.key, meme)
names = set()
names.add(meme.key.lower())
for keyword in meme.keywords:
add(keyword, meme)
names.add(keyword.lower())
for shortcut in meme.shortcuts:
add(shortcut.humanized or shortcut.key, meme)
names.add((shortcut.humanized or shortcut.key).lower())
for name in names:
if name not in self.__meme_names:
self.__meme_names[name] = []
self.__meme_names[name].append(meme)

def __refresh_tags(self):
self.__meme_tags = {}

def add(tag: str, meme: Meme):
tag = tag.lower()
if tag not in self.__meme_tags:
self.__meme_tags[tag] = []
self.__meme_tags[tag].append(meme)

for meme in self.__meme_dict.values():
for tag in meme.tags:
add(tag, meme)
tag = tag.lower()
if tag not in self.__meme_tags:
self.__meme_tags[tag] = []
self.__meme_tags[tag].append(meme)


meme_manager = MemeManager()

0 comments on commit 894e5e9

Please sign in to comment.