예제 #1
0
 def func(self):
     """
     Create a new message and send it to channel, using
     the already formatted input.
     """
     caller = self.caller
     channelkey, msg = self.args
     if not msg:
         caller.msg("Say what?")
         return
     channel = Channel.objects.get_channel(channelkey)
     if not channel:
         caller.msg("Channel '%s' not found." % channelkey)
         return
     if not channel.has_connection(caller):
         string = "You are not connected to channel '%s'."
         caller.msg(string % channelkey)
         return
     if not channel.access(caller, 'send'):
         string = "You are not permitted to send to channel '%s'."
         caller.msg(string % channelkey)
         return
     msg = "[%s] %s: %s" % (channel.key, caller.name, msg)
     msgobj = create.create_message(caller, msg, channels=[channel])
     channel.msg(msgobj)
예제 #2
0
def send_message(senders,
                 subject,
                 body,
                 receivers,
                 priority=False,
                 silent_receive=False,
                 send_email=False):
    """
    Send a mail message to specified recipients.
    """
    message = create.create_message(senderobj=senders,
                                    message=body,
                                    receivers=receivers,
                                    header=subject)
    successful = []
    status = []
    print "starting"
    for target in receivers:
        try:
            print "Iterated"
            if len(target.db.mail) >= MAX_MESSAGES and not priority:
                print "Max mail!"
                status.append(
                    "Mailbox of %s is full. Could not send message to this player!"
                    % target.name)
                continue
            target.db.mail.append([message, message.date_sent, False])
        except (TypeError, AttributeError):
            target.db.mail = [[message, message.date_sent, False]]
        if not silent_receive:
            target.msg(ALERT % "You have new mail! Check it by typing: mail")
        successful.append(target)
    if EMAIL and send_email:
        send_email_copy(message)
    return successful, status
예제 #3
0
 def func(self):
     """
     Create a new message and send it to channel, using
     the already formatted input.
     """
     caller = self.caller
     channelkey, msg = self.args
     if not msg:
         caller.msg("Say what?")
         return
     channel = ChannelDB.objects.get_channel(channelkey)
     if not channel:
         caller.msg("Channel '%s' not found." % channelkey)
         return
     if not channel.has_connection(caller):
         string = "You are not connected to channel '%s'."
         caller.msg(string % channelkey)
         return
     if not channel.access(caller, 'send'):
         string = "You are not permitted to send to channel '%s'."
         caller.msg(string % channelkey)
         return
     msg = "[%s] %s: %s" % (channel.key, caller.name, msg)
     msgobj = create.create_message(caller, msg, channels=[channel])
     channel.msg(msgobj)
예제 #4
0
파일: utils.py 프로젝트: abbacode/avaloria
    def func(self):
        "Run the test program"
        caller = self.caller
        
        if 'create' in self.switches:
            if self.args:
                chankey = self.args
                try:
                    channel = create.create_channel(chankey)
                except IntegrityError:
                    caller.msg("Channel '%s' already exists." % chankey)
                    return 
            channel.connect_to(caller)
            caller.msg("Created new channel %s" % chankey)
            msgobj = create.create_message(caller.player,
                                           "First post to new channel!")
            channel.msg(msgobj)

            return
        elif 'list' in self.switches:
            msgresults = Msg.objects.get_messages_by_sender(caller)
            string = "\n".join(["%s %s: %s" % (msg.date_sent,
                                               [str(chan.key) for chan in msg.channels.all()],
                                               msg.message)
                                for msg in msgresults])
            caller.msg(string)
            return 
        caller.msg("Usage: @testcom/create channel")
예제 #5
0
def send_message(senders, subject, body, receivers, priority=False, silent_receive=False, send_email=False):
    """
    Send a mail message to specified recipients.
    """
    message = create.create_message(senderobj=senders, message=body,
           receivers=receivers, header=subject)
    successful = []
    status = []
    print "starting"
    for target in receivers:
        try:
            print "Iterated"
            if len(target.db.mail) >= MAX_MESSAGES and not priority:
                print "Max mail!"
                status.append("Mailbox of %s is full. Could not send message to this player!" % target.name)
                continue
            target.db.mail.append([message, message.date_sent, False])
        except (TypeError, AttributeError):
            target.db.mail = [ [message, message.date_sent, False] ]
        if not silent_receive:
            target.msg(ALERT % "You have new mail! Check it by typing: mail")
        successful.append(target)
    if EMAIL and send_email:
        send_email_copy(message)
    return successful, status
예제 #6
0
    def func(self):
        "Destroy objects cleanly."
        caller = self.caller

        if not self.args:
            self.msg("Usage: @cdestroy <channelname>")
            return
        channel = find_channel(caller, self.args)
        if not channel:
            self.msg("Could not find channel %s." % self.args)
            return
        if not channel.access(caller, 'control'):
            self.msg("You are not allowed to do that.")
            return
        channel_key = channel.key
        message = "%s is being destroyed. Make sure to change your aliases." % channel_key
        msgobj = create.create_message(caller, message, channel)
        channel.msg(msgobj)
        channel.delete()
        CHANNELHANDLER.update()
        self.msg("Channel '%s' was destroyed." % channel_key)
예제 #7
0
    def func(self):
        "Destroy objects cleanly."
        caller = self.caller

        if not self.args:
            self.msg("Usage: @cdestroy <channelname>")
            return
        channel = find_channel(caller, self.args)
        if not channel:
            self.msg("Could not find channel %s." % self.args)
            return
        if not channel.access(caller, 'control'):
            self.msg("You are not allowed to do that.")
            return
        channel_key = channel.key
        message = "%s is being destroyed. Make sure to change your aliases." % channel_key
        msgobj = create.create_message(caller, message, channel)
        channel.msg(msgobj)
        channel.delete()
        CHANNELHANDLER.update()
        self.msg("Channel '%s' was destroyed." % channel_key)
예제 #8
0
    def func(self):
        "Implement function using the Msg methods"

        # this is a MuxPlayerCommand, which means caller will be a Player.
        caller = self.caller

        # get the messages we've sent (not to channels)
        pages_we_sent = Msg.objects.get_messages_by_sender(caller,
                                                 exclude_channel_messages=True)
        # get last messages we've got
        pages_we_got = Msg.objects.get_messages_by_receiver(caller)

        if 'last' in self.switches:
            if pages_we_sent:
                recv = ",".join(obj.key for obj in pages_we_sent[-1].receivers)
                self.msg("You last paged {c%s{n:%s" % (recv,
                                                    pages_we_sent[-1].message))
                return
            else:
                self.msg("You haven't paged anyone yet.")
                return

        if not self.args or not self.rhs:
            pages = pages_we_sent + pages_we_got
            pages.sort(lambda x, y: cmp(x.date_sent, y.date_sent))

            number = 5
            if self.args:
                try:
                    number = int(self.args)
                except ValueError:
                    self.msg("Usage: tell [<player> = msg]")
                    return

            if len(pages) > number:
                lastpages = pages[-number:]
            else:
                lastpages = pages
            template = "{w%s{n {c%s{n to {c%s{n: %s"
            lastpages = "\n ".join(template %
                                   (utils.datetime_format(page.date_sent),
                                    ",".join(obj.key for obj in page.senders),
                                    "{n,{c ".join([obj.name for obj in page.receivers]),
                                    page.message) for page in lastpages)

            if lastpages:
                string = "Your latest pages:\n %s" % lastpages
            else:
                string = "You haven't paged anyone yet."
            self.msg(string)
            return

        # We are sending. Build a list of targets

        if not self.lhs:
            # If there are no targets, then set the targets
            # to the last person we paged.
            if pages_we_sent:
                receivers = pages_we_sent[-1].receivers
            else:
                self.msg("Who do you want to page?")
                return
        else:
            receivers = self.lhslist

        recobjs = []
        for receiver in set(receivers):
            if isinstance(receiver, basestring):
                pobj = caller.search(receiver)
            elif hasattr(receiver, 'character'):
                pobj = receiver
            else:
                self.msg("Who do you want to page?")
                return
            if pobj:
                recobjs.append(pobj)
        if not recobjs:
            self.msg("Noone found to page.")
            return

        header = "{wPlayer{n {c%s{n {wpages:{n" % caller.key
        message = self.rhs

        # if message begins with a :, we assume it is a 'page-pose'
        if message.startswith(":"):
            message = "%s %s" % (caller.key, message.strip(':').strip())

        # create the persistent message object
        create.create_message(caller, message,
                              receivers=recobjs)

        # tell the players they got a message.
        received = []
        rstrings = []
        for pobj in recobjs:
            if not pobj.access(caller, 'msg'):
                rstrings.append("You are not allowed to page %s." % pobj)
                continue
            pobj.msg("%s %s" % (header, message))
            if hasattr(pobj, 'sessions') and not pobj.sessions:
                received.append("{C%s{n" % pobj.name)
                rstrings.append("%s is offline. They will see your message if they list their pages later." % received[-1])
            else:
                received.append("{c%s{n" % pobj.name)
        if rstrings:
            self.msg("\n".join(rstrings))
        self.msg("You paged %s with: '%s'." % (", ".join(received), message))
예제 #9
0
    def func(self):
        "Implement function using the Msg methods"

        # this is a MuxPlayerCommand, which means caller will be a Player.
        caller = self.caller

        # get the messages we've sent (not to channels)
        pages_we_sent = Msg.objects.get_messages_by_sender(
            caller, exclude_channel_messages=True)
        # get last messages we've got
        pages_we_got = Msg.objects.get_messages_by_receiver(caller)

        if 'last' in self.switches:
            if pages_we_sent:
                recv = ",".join(obj.key for obj in pages_we_sent[-1].receivers)
                self.msg("You last paged {c%s{n:%s" %
                         (recv, pages_we_sent[-1].message))
                return
            else:
                self.msg("You haven't paged anyone yet.")
                return

        if not self.args or not self.rhs:
            pages = pages_we_sent + pages_we_got
            pages.sort(lambda x, y: cmp(x.date_sent, y.date_sent))

            number = 5
            if self.args:
                try:
                    number = int(self.args)
                except ValueError:
                    self.msg("Usage: tell [<player> = msg]")
                    return

            if len(pages) > number:
                lastpages = pages[-number:]
            else:
                lastpages = pages
            template = "{w%s{n {c%s{n to {c%s{n: %s"
            lastpages = "\n ".join(
                template %
                (utils.datetime_format(page.date_sent), ",".join(
                    obj.key for obj in page.senders),
                 "{n,{c ".join([obj.name
                                for obj in page.receivers]), page.message)
                for page in lastpages)

            if lastpages:
                string = "Your latest pages:\n %s" % lastpages
            else:
                string = "You haven't paged anyone yet."
            self.msg(string)
            return

        # We are sending. Build a list of targets

        if not self.lhs:
            # If there are no targets, then set the targets
            # to the last person we paged.
            if pages_we_sent:
                receivers = pages_we_sent[-1].receivers
            else:
                self.msg("Who do you want to page?")
                return
        else:
            receivers = self.lhslist

        recobjs = []
        for receiver in set(receivers):
            if isinstance(receiver, basestring):
                pobj = caller.search(receiver)
            elif hasattr(receiver, 'character'):
                pobj = receiver
            else:
                self.msg("Who do you want to page?")
                return
            if pobj:
                recobjs.append(pobj)
        if not recobjs:
            self.msg("Noone found to page.")
            return

        header = "{wPlayer{n {c%s{n {wpages:{n" % caller.key
        message = self.rhs

        # if message begins with a :, we assume it is a 'page-pose'
        if message.startswith(":"):
            message = "%s %s" % (caller.key, message.strip(':').strip())

        # create the persistent message object
        create.create_message(caller, message, receivers=recobjs)

        # tell the players they got a message.
        received = []
        rstrings = []
        for pobj in recobjs:
            if not pobj.access(caller, 'msg'):
                rstrings.append("You are not allowed to page %s." % pobj)
                continue
            pobj.msg("%s %s" % (header, message))
            if hasattr(pobj, 'sessions') and not pobj.sessions:
                received.append("{C%s{n" % pobj.name)
                rstrings.append(
                    "%s is offline. They will see your message if they list their pages later."
                    % received[-1])
            else:
                received.append("{c%s{n" % pobj.name)
        if rstrings:
            self.msg("\n".join(rstrings))
        self.msg("You paged %s with: '%s'." % (", ".join(received), message))