mirror of
https://github.com/evennia/evennia.git
synced 2026-04-03 06:27:17 +02:00
The help entry database structure has changed! You have to resync or purge your database or your will get problems! New features: * Help entry access now fully controlled by evennia permissions * Categories for each help entry * All entries are created dynamically, with a See also: footer calculated after the current state of the database. * Indexes and topic list calculated on the fly (alphabetically/after category) * Added auto-help help entries for all default commands. * Only shows commands _actually implemented_ - MUX help db moved into 'MUX' category which is not shown by default. * More powerful auto-help markup - supports categories and permissions (and inheritance). * Global on/off switch for auto-help, when entering production * Auto_help_override switch for selectively activating auto-help when developing new commands (like the old system). * Refactored State help system; no more risk of overwriting global help entries. * State help now defers to main help db when no match found; makes system more transparent. * State help entries also support categories/permissions (state categories are not used much though). Other updates: * Added more commands to the batch processor * Many bug-fixes. /Griatch
59 lines
2.3 KiB
Python
59 lines
2.3 KiB
Python
"""
|
|
Custom manager for HelpEntry objects.
|
|
"""
|
|
from django.db import models
|
|
|
|
class HelpEntryManager(models.Manager):
|
|
"""
|
|
This implements different ways to search for help entries.
|
|
"""
|
|
def find_topicmatch(self, pobject, topicstr, exact=False):
|
|
"""
|
|
Searches for matching topics based on player's input.
|
|
"""
|
|
if topicstr.isdigit():
|
|
return self.filter(id=topicstr)
|
|
t_query = self.filter(topicname__iexact=topicstr)
|
|
if not t_query and not exact:
|
|
t_query = self.filter(topicname__istartswith=topicstr)
|
|
# check permissions
|
|
t_query = [topic for topic in t_query if topic.can_view(pobject)]
|
|
return t_query
|
|
|
|
def find_topicsuggestions(self, pobject, topicstr):
|
|
"""
|
|
Do a fuzzy match, preferably within the category of the
|
|
current topic.
|
|
"""
|
|
basetopic = self.filter(topicname__iexact=topicstr)
|
|
if not basetopic:
|
|
# this topic does not exist; just reply partial
|
|
# matches to the string
|
|
topics = self.filter(topicname__icontains=topicstr)
|
|
return [topic for topic in topics if topic.can_view(pobject)]
|
|
|
|
# we know that the topic exists, try to find similar ones within
|
|
# its category.
|
|
basetopic = basetopic[0]
|
|
category = basetopic.category
|
|
topics = []
|
|
|
|
#remove the @
|
|
crop = topicstr.lstrip('@')
|
|
|
|
# first we filter for matches with the full name
|
|
topics = self.filter(category__iexact=category).filter(topicname__icontains=crop)
|
|
if len(crop) > 4:
|
|
# next search with a cropped version of the command.
|
|
ttemp = self.filter(category__iexact=category).filter(topicname__icontains=crop[:4])
|
|
ttemp = [topic for topic in ttemp if topic not in topics]
|
|
topics = list(topics) + list(ttemp)
|
|
# we need to clean away the given help entry.
|
|
return [topic for topic in topics if topic.topicname.lower() != topicstr.lower()]
|
|
|
|
def find_topics_with_category(self, pobject, category):
|
|
"""
|
|
Search topics having a particular category
|
|
"""
|
|
t_query = self.filter(category__iexact=category)
|
|
return [topic for topic in t_query if topic.can_view(pobject)]
|