Merge branch 'channels_msg_offline' of https://github.com/TehomCD/evennia into TehomCD-channels_msg_offline

This commit is contained in:
Griatch 2017-05-21 07:39:28 +02:00
commit 2f4cbf1d09
2 changed files with 23 additions and 3 deletions

View file

@ -2,7 +2,6 @@
Base typeclass for in-game Channels.
"""
from evennia.typeclasses.models import TypeclassBase
from evennia.comms.models import TempMsg, ChannelDB
from evennia.comms.managers import ChannelManager
@ -239,14 +238,17 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
Args:
msgobj (Msg or TempMsg): Message to distribute.
online (bool): Only send to receivers who are actually online
(not currently used):
Notes:
This is also where logging happens, if enabled.
"""
# get all players or objects connected to this channel and send to them
for entity in self.subscriptions.all():
if online:
subs = self.subscriptions.online()
else:
subs = self.subscriptions.all()
for entity in subs:
# if the entity is muted, we don't send them a message
if entity in self.mutelist:
continue

View file

@ -538,6 +538,24 @@ class SubscriptionHandler(object):
self._recache()
return self._cache
def online(self):
"""
Get all online players from our cache
Returns:
subscribers (list): Subscribers who are online or
are puppeted by an online player.
"""
subs = []
for obj in self.all():
if hasattr(obj, 'player'):
if not obj.player:
continue
obj = obj.player
if not obj.is_connected:
continue
subs.append(obj)
return subs
def clear(self):
"""
Remove all subscribers from channel.