Add the new functions submodule, superseding utilities.py

All of the new functions handle and return User instances. Not used yet, but will be needed when converting roles.
This commit is contained in:
Vgr E. Barry 2017-01-17 13:46:40 -05:00
parent accba42ea2
commit 8c2124fb6a

40
src/functions.py Normal file
View File

@ -0,0 +1,40 @@
from src.messages import messages
from src import settings as var
from src import users
__all__ = ["get_players", "get_target"]
def get_players(roles=None):
if roles is None:
roles = var.ROLES
players = set()
for x in roles:
if x in var.TEMPLATE_RESTRICTIONS:
continue
for p in var.ROLES.get(x, ()):
players.add(p)
return [p for p in var.ALL_PLAYERS if p.nick in players]
def get_target(var, wrapper, message, *, allow_self=False, allow_bot=False):
if not message:
wrapper.pm(messages["not_enough_parameters"])
return
players = get_players()
if not allow_self and wrapper.source in players:
players.remove(wrapper.source)
if allow_bot:
players.append(users.Bot)
match, count = users.complete_match(message, players)
if match is None:
if not count and users.lower(wrapper.source.nick).startswith(users.lower(message)):
return wrapper.source
wrapper.pm(messages["not_playing"].format(message))
return
return match