def msg(self, msgobj, header=None, senders=None, sender_strings=None, persistent=False, online=False, emit=False, external=False): """ Send the given message to all players connected to channel. Note that no permission-checking is done here; it is assumed to have been done before calling this method. The optional keywords are not used if persistent is False. msgobj - a Msg/TempMsg instance or a message string. If one of the former, the remaining keywords will be ignored. If a string, this will either be sent as-is (if persistent=False) or it will be used together with header and senders keywords to create a Msg instance on the fly. senders - an object, player or a list of objects or players. Optional if persistent=False. sender_strings - Name strings of senders. Used for external connections where the sender is not a player or object. When this is defined, external will be assumed. external - Treat this message agnostic of its sender. persistent (default False) - ignored if msgobj is a Msg or TempMsg. If True, a Msg will be created, using header and senders keywords. If False, other keywords will be ignored. online (bool) - If this is set true, only messages people who are online. Otherwise, messages all players connected. This can make things faster, but may not trigger listeners on players that are offline. emit (bool) - Signals to the message formatter that this message is not to be directly associated with a name. """ if senders: senders = make_iter(senders) else: senders = [] if isinstance(msgobj, basestring): # given msgobj is a string msg = msgobj if persistent and self.db.keep_log: msgobj = Msg() msgobj.save() else: # Use TempMsg, so this message is not stored. msgobj = TempMsg() msgobj.header = header msgobj.message = msg msgobj.channels = [self] # add this channel if not msgobj.senders: msgobj.senders = senders msgobj = self.pre_send_message(msgobj) if not msgobj: return False msgobj = self.message_transform(msgobj, emit=emit, sender_strings=sender_strings, external=external) self.distribute_message(msgobj, online=online) self.post_send_message(msgobj) return True
def msg(self, msgobj, header=None, senders=None, sender_strings=None, persistent=False, online=False, emit=False, external=False): """ Send the given message to all players connected to channel. Note that no permission-checking is done here; it is assumed to have been done before calling this method. The optional keywords are not used if persistent is False. Args: msgobj (Msg, TempMsg or str): If a Msg/TempMsg, the remaining keywords will be ignored (since the Msg/TempMsg object already has all the data). If a string, this will either be sent as-is (if persistent=False) or it will be used together with `header` and `senders` keywords to create a Msg instance on the fly. header (str, optional): A header for building the message. senders (Object, Player or list, optional): Optional if persistent=False, used to build senders for the message. sender_strings (list, optional): Name strings of senders. Used for external connections where the sender is not a player or object. When this is defined, external will be assumed. persistent (bool, optional): Ignored if msgobj is a Msg or TempMsg. If True, a Msg will be created, using header and senders keywords. If False, other keywords will be ignored. online (bool, optional) - If this is set true, only messages people who are online. Otherwise, messages all players connected. This can make things faster, but may not trigger listeners on players that are offline. emit (bool, optional) - Signals to the message formatter that this message is not to be directly associated with a name. external (bool, optional): Treat this message as being agnostic of its sender. Returns: success (bool): Returns `True` if message sending was successful, `False` otherwise. """ if senders: senders = make_iter(senders) else: senders = [] if isinstance(msgobj, basestring): # given msgobj is a string msg = msgobj if persistent and self.db.keep_log: msgobj = Msg() msgobj.save() else: # Use TempMsg, so this message is not stored. msgobj = TempMsg() msgobj.header = header msgobj.message = msg msgobj.channels = [self] # add this channel if not msgobj.senders: msgobj.senders = senders msgobj = self.pre_send_message(msgobj) if not msgobj: return False msgobj = self.message_transform(msgobj, emit=emit, sender_strings=sender_strings, external=external) self.distribute_message(msgobj, online=online) self.post_send_message(msgobj) return True