Beispiel #1
0
    def func(self):
        """
        Create a new message and send it to channel, using
        the already formatted input.
        """
        channelkey, msg = self.args
        caller = self.caller
        if not msg:
            self.msg(_("Say what?"))
            return
        channel = ChannelDB.objects.get_channel(channelkey)

        if not channel:
            self.msg(_("Channel '%s' not found.") % channelkey)
            return
        if not channel.has_connection(caller):
            string = _("You are not connected to channel '%s'.")
            self.msg(string % channelkey)
            return
        if not channel.access(caller, 'send'):
            string = _("You are not permitted to send to channel '%s'.")
            self.msg(string % channelkey)
            return
        if self.history_start is not None:
            # Try to view history
            log_file = channel.attributes.get("log_file", default="channel_%s.log" % channel.key)
            send_msg = lambda lines: self.msg("".join(line.split("[-]", 1)[1]
                                                    if "[-]" in line else line for line in lines))
            tail_log_file(log_file, self.history_start, 20, callback=send_msg)
        else:
            channel.msg(msg, senders=self.caller, online=True)
Beispiel #2
0
    def func(self):
        """
        Create a new message and send it to channel, using
        the already formatted input.
        """
        channelkey, msg = self.args
        caller = self.caller
        if not msg:
            self.msg(_("Say what?"))
            return
        channel = ChannelDB.objects.get_channel(channelkey)

        if not channel:
            self.msg(_("Channel '%s' not found.") % channelkey)
            return
        if not channel.has_connection(caller):
            string = _("You are not connected to channel '%s'.")
            self.msg(string % channelkey)
            return
        if not channel.access(caller, 'send'):
            string = _("You are not permitted to send to channel '%s'.")
            self.msg(string % channelkey)
            return
        if self.history_start is not None:
            # Try to view history
            log_file = channel.attributes.get("log_file",
                                              default="channel_%s.log" %
                                              channel.key)
            send_msg = lambda lines: self.msg("".join(
                line.split("[-]", 1)[1] if "[-]" in line else line
                for line in lines))
            tail_log_file(log_file, self.history_start, 20, callback=send_msg)
        else:
            channel.msg(msg, senders=self.caller, online=True)
Beispiel #3
0
    def func(self):
        """
        Create a new message and send it to channel, using
        the already formatted input.
        """
        global _CHANNELDB
        if not _CHANNELDB:
            from evennia.comms.models import ChannelDB as _CHANNELDB

        channelkey, msg = self.args
        caller = self.caller
        if not msg:
            self.msg(_("Say what?"))
            return
        channel = _CHANNELDB.objects.get_channel(channelkey)

        if not channel:
            self.msg(_("Channel '%s' not found.") % channelkey)
            return
        if not channel.has_connection(caller):
            string = _("You are not connected to channel '%s'.")
            self.msg(string % channelkey)
            return
        if not channel.access(caller, 'send'):
            string = _("You are not permitted to send to channel '%s'.")
            self.msg(string % channelkey)
            return
        if msg == "on":
            caller = caller if not hasattr(caller, 'player') else caller.player
            unmuted = channel.unmute(caller)
            if unmuted:
                self.msg("You start listening to %s." % channel)
                return
            self.msg("You were already listening to %s." % channel)
            return
        if msg == "off":
            caller = caller if not hasattr(caller, 'player') else caller.player
            muted = channel.mute(caller)
            if muted:
                self.msg("You stop listening to %s." % channel)
                return
            self.msg("You were already not listening to %s." % channel)
            return
        if self.history_start is not None:
            # Try to view history
            log_file = channel.attributes.get("log_file",
                                              default="channel_%s.log" %
                                              channel.key)
            send_msg = lambda lines: self.msg("".join(
                line.split("[-]", 1)[1] if "[-]" in line else line
                for line in lines))
            tail_log_file(log_file, self.history_start, 20, callback=send_msg)
        else:
            caller = caller if not hasattr(caller, 'player') else caller.player
            if caller in channel.mutelist:
                self.msg("You currently have %s muted." % channel)
                return
            channel.msg(msg, senders=self.caller, online=True)
Beispiel #4
0
    def func(self):
        """
        Create a new message and send it to channel, using
        the already formatted input.
        """
        global _CHANNELDB
        if not _CHANNELDB:
            from evennia.comms.models import ChannelDB as _CHANNELDB

        channelkey, msg = self.args
        caller = self.caller
        if not msg:
            self.msg(_("Say what?"))
            return
        channel = _CHANNELDB.objects.get_channel(channelkey)

        if not channel:
            self.msg(_("Channel '%s' not found.") % channelkey)
            return
        if not channel.has_connection(caller):
            string = _("You are not connected to channel '%s'.")
            self.msg(string % channelkey)
            return
        if not channel.access(caller, 'send'):
            string = _("You are not permitted to send to channel '%s'.")
            self.msg(string % channelkey)
            return
        if msg == "on":
            caller = caller if not hasattr(caller, 'account') else caller.account
            unmuted = channel.unmute(caller)
            if unmuted:
                self.msg("You start listening to %s." % channel)
                return
            self.msg("You were already listening to %s." % channel)
            return
        if msg == "off":
            caller = caller if not hasattr(caller, 'account') else caller.account
            muted = channel.mute(caller)
            if muted:
                self.msg("You stop listening to %s." % channel)
                return
            self.msg("You were already not listening to %s." % channel)
            return
        if self.history_start is not None:
            # Try to view history
            log_file = channel.attributes.get("log_file", default="channel_%s.log" % channel.key)

            def send_msg(lines): return self.msg("".join(line.split("[-]", 1)[1]
                                                         if "[-]" in line else line for line in lines))
            tail_log_file(log_file, self.history_start, 20, callback=send_msg)
        else:
            caller = caller if not hasattr(caller, 'account') else caller.account
            if caller in channel.mutelist:
                self.msg("You currently have %s muted." % channel)
                return
            channel.msg(msg, senders=self.caller, online=True)
Beispiel #5
0
    def get_context_data(self, **kwargs):
        """
        Django hook; before we can display the channel logs, we need to recall
        the logfile and read its lines.

        Returns:
            context (dict): Django context object

        """
        # Get the parent context object, necessary first step
        context = super(ChannelDetailView, self).get_context_data(**kwargs)

        # Get the filename this Channel is recording to
        filename = self.object.attributes.get("log_file",
                                              default="channel_%s.log" %
                                              self.object.key)

        # Split log entries so we can filter by time
        bucket = []
        for log in (x.strip()
                    for x in tail_log_file(filename, 0, self.max_num_lines)):
            if not log:
                continue
            time, msg = log.split(" [-] ")
            time_key = time.split(":")[0]

            bucket.append({"key": time_key, "timestamp": time, "message": msg})

        # Add the processed entries to the context
        context["object_list"] = bucket

        # Get a list of unique timestamps by hour and sort them
        context["object_filters"] = sorted(set([x["key"] for x in bucket]))

        return context
Beispiel #6
0
    def func(self):
        """Main function for this command."""
        filename = self.args.strip()
        if "." not in filename:
            filename += ".log"

        path = os.path.join("server/logs", filename)
        now = datetime.datetime.now()
        if not os.path.exists(path) or not os.path.isfile(path):
            self.msg("The {} log file doesn't exist.".format(filename))
        else:
            lines = tail_log_file(filename, 0, 20)
            render = []
            for line in lines:
                line = line.decode("utf-8")
                if line.count(" ") >= 2:
                    date, time, message = line.split(" ", 2)
                    try:
                        entry = datetime.datetime.strptime(date + " " + time, "%Y-%m-%d %H:%M:%S,%f")
                    except ValueError:
                        continue
                    else:
                        seconds = round((now - entry).total_seconds())
                        format = time_format(seconds, 1)
                        render.append("{:>4}: {}".format(format, message))

            if render:
                self.msg("\n".join(render))
            else:
                self.msg("|rNo message could be found in this log file.|n")
Beispiel #7
0
    def func(self):
        """
        Create a new message and send it to channel, using
        the already formatted input.
        """
        channelkey, msg = self.args
        caller = self.caller
        player = caller.player_ob
        if not msg:
            self.msg("Say what?")
            return
        channel = ChannelDB.objects.get_channel(channelkey)

        if not channel:
            self.msg("Channel '%s' not found." % channelkey)
            return
        if msg == "on":
            if player:
                caller = player
            temp_mute = caller.db.temp_mute_list or []
            if channel in temp_mute:
                temp_mute.remove(channel)
            if channel.unmute(caller):
                self.msg("You unmute channel %s." % channel)
                return
            caller.execute_cmd("addcom %s" % channelkey)
            return
        if not channel.has_connection(caller):
            string = "You are not connected to channel '%s'."
            self.msg(string % channelkey)
            return
        if not channel.access(caller, 'send'):
            string = "You are not permitted to send to channel '%s'."
            self.msg(string % channelkey)
            return
        if "%r" in msg or "{/" in msg or "|/" in msg:
            caller.msg("Channel messages may not contain newline characters.")
            return
        if len(msg) > self.max_length and not caller.check_permstring(
                "helpers"):
            self.msg(
                "Channel messages may not exceed %d characters in length." %
                self.max_length)
            return
        if msg == "who" or msg == "?" or msg == "all" or msg == "list":
            if caller.check_permstring("builders"):
                wholist = channel.complete_wholist
            else:
                wholist = channel.wholist
            self.msg("{w%s:{n\n %s" % (channel, wholist))
            return
        if msg == 'last' or msg.startswith("last "):
            msglist = msg.split()
            # check if it wasn't just a message starting with 'last'
            # eg: 'last week we blah blah'
            if len(msglist) == 1 or (len(msglist) == 2
                                     and msglist[1].isdigit()):
                self.num_messages = 20
                if len(msglist) == 2:
                    self.num_messages = int(msglist[1])
                self.display_history = True
        if self.display_history:
            log_file = channel.attributes.get("log_file",
                                              default="channel_%s.log" %
                                              channel.key)

            def send_msg(lines):
                msgs = "".join(line for line in lines)
                arx_more.msg(caller, msgs, justify_kwargs=False)

            if self.num_messages > 200:
                self.num_messages = 200
            self.msg("{wChannel history for %s:{n" % self.key)
            tail_log_file(log_file, 0, self.num_messages, callback=send_msg)
            return
        if msg == "off" or msg == "mute":
            if player:
                caller = player
            if msg == "mute":
                channel.temp_mute(caller)
                return
            muted = channel.mute(caller)
            if muted:
                caller.msg("You stop listening to channel '%s'." % channel.key)
            else:
                caller.msg("You already muted channel '%s'." % channel.key)
            return
        if player in channel.mutelist or caller in channel.mutelist:
            self.msg("You have that channel muted.")
            return
        channel.msg(msg,
                    senders=caller.db.char_ob or caller,
                    keep_log=True,
                    online=True)
Beispiel #8
0
    def func(self):
        """
        Create a new message and send it to channel, using
        the already formatted input.
        """
        channelkey, msg = self.args
        caller = self.caller
        channel = ChannelDB.objects.get_channel(channelkey)
        admin_switches = ("destroy", "emit", "lock", "locks", "desc", "kick")

        # Check that the channel exist
        if not channel:
            self.msg(_("Channel '%s' not found.") % channelkey)
            return

        # Check that the caller is connected
        if not channel.has_connection(caller):
            string = _("You are not connected to channel '%s'.")
            self.msg(string % channelkey)
            return

        # Check that the caller has send access
        if not channel.access(caller, 'send'):
            string = _("You are not permitted to send to channel '%s'.")
            self.msg(string % channelkey)
            return

        # Get the list of connected to this channel
        puppets = [session.puppet for session in SESSION_HANDLER.values() \
                if session.puppet]
        connected = [
            obj for obj in channel.subscriptions.all() if obj in puppets
        ]

        # Handle the various switches
        if self.switch == "me":
            if not msg:
                self.msg("What do you want to do on this channel?")
            else:
                msg = "{} {}".format(caller.key, msg)
                channel.msg(msg, online=True)
        elif self.switch == "who":
            keys = [obj.key for obj in connected]
            keys.sort()
            string = "Connected to the {} channel:".format(channel.key)
            string += ", ".join(keys) if keys else "(no one)"
            string += "."
            self.msg(string)
        elif channel.access(caller,
                            'control') and self.switch in admin_switches:
            if self.switch == "destroy":
                confirm = yield (
                    "Are you sure you want to delete the channel {}? (Y?N)".
                    format(channel.key))
                if confirm.lower() in ("y", "yes"):
                    channel.msg("Destroying the channel.")
                    channel.delete()
                    CHANNELHANDLER.update()
                    self.msg("The channel was destroyed.")
                else:
                    self.msg("Operation cancelled, do not destroy.")
            elif self.switch == "emit":
                if not msg:
                    self.msg("What do you want to say on this channel?")
                else:
                    channel.msg(msg, online=True)
            elif self.switch in ("lock", "locks"):
                if msg:
                    try:
                        channel.locks.add(msg)
                    except LockException as err:
                        self.msg(err)
                        return
                    else:
                        self.msg("Channel permissions were edited.")

                string = "Current locks on {}:\n  {}".format(
                    channel.key, channel.locks)
                self.msg(string)
            elif self.switch == "desc":
                if msg:
                    channel.db.desc = msg
                    self.msg("Channel description was updated.")

                self.msg("Description of the {} channel: {}".format(
                    channel.key, channel.db.desc))
            elif self.switch == "kick":
                if not msg:
                    self.msg("Who do you want to kick from this channel?")
                else:
                    to_kick = caller.search(msg, candidates=connected)
                    if to_kick is None:
                        return

                    channel.disconnect(to_kick)
                    channel.msg("{} has been kicked from the channel.".format(
                        to_kick.key))
                    to_kick.msg(
                        "You have been kicked from the {} channel.".format(
                            channel.key))
        elif self.history_start is not None:
            # Try to view history
            log_file = channel.attributes.get("log_file",
                                              default="channel_%s.log" %
                                              channel.key)
            send_msg = lambda lines: self.msg("".join(
                line.split("[-]", 1)[1] if "[-]" in line else line
                for line in lines))
            tail_log_file(log_file, self.history_start, 20, callback=send_msg)
        elif self.switch:
            self.msg("{}: Invalid switch {}.".format(channel.key, self.switch))
        elif not msg:
            self.msg(_("Say what?"))
            return
        else:
            if caller in channel.mutelist:
                self.msg("You currently have %s muted." % channel)
                return
            channel.msg(msg, senders=self.caller, online=True)
Beispiel #9
0
class ChannelCommand(Command):
    """
    {channelkey} channel

    {channeldesc}

    Syntaxe :
      {lower_channelkey} <message>
      {lower_channelkey}/history [début]
      {lower_channelkey}/me <message>
      {lower_channelkey}/who

    Switch :
      history : Voit les 20 derniers messages du canal, soit depuis la fin soit
                depuis le nombre précisé en paramètre.
      me : Fait une action dans ce canal.
      who : Affiche la liste des connectés au canal.

    Exemple :
      {lower_channelkey} Bonjour !
      {lower_channelkey}/history
      {lower_channelkey}/history 30
      {lower_channelkey}/me sourit.
      {lower_channelkey}/who
    """
    # ^note that channeldesc and lower_channelkey will be filled
    # automatically by ChannelHandler

    # this flag is what identifies this cmd as a channel cmd
    # and branches off to the system send-to-channel command
    # (which is customizable by admin)
    is_channel = True
    key = "general"
    help_category = "Channel Names"
    obj = None
    arg_regex = ""

    def parse(self):
        """
        Simple parser
        """
        # cmdhandler sends channame:msg here.
        channelname, msg = self.args.split(":", 1)
        self.history_start = None
        self.switch = None
        if msg.startswith("/"):
            try:
                switch, msg = msg[1:].split(" ", 1)
            except ValueError:
                switch = msg[1:]
                msg = ""

            self.switch = switch.lower().strip()

        # If /history
        if self.switch == "history":
            try:
                self.history_start = int(msg) if msg else 0
            except ValueError:
                # if no valid number was given, ignore it
                pass

        self.args = (channelname.strip(), msg.strip())

    def func(self):
        """
        Create a new message and send it to channel, using
        the already formatted input.
        """
        channelkey, msg = self.args
        caller = self.caller
        channel = ChannelDB.objects.get_channel(channelkey)
        admin_switches = ("destroy", "emit", "lock", "locks", "desc", "kick")

        # Check that the channel exist
        if not channel:
            self.msg(_("Channel '%s' not found.") % channelkey)
            return

        # Check that the caller is connected
        if not channel.has_connection(caller):
            string = _("You are not connected to channel '%s'.")
            self.msg(string % channelkey)
            return

        # Check that the caller has send access
        if not channel.access(caller, 'send'):
            string = _("You are not permitted to send to channel '%s'.")
            self.msg(string % channelkey)
            return

        # Get the list of connected to this channel
        connected = [
            obj for obj in channel.subscriptions.all()
            if getattr(obj, "is_connected", False)
        ]

        # Handle the various switches
        if self.switch == "me":
            if not msg:
                self.msg("Quelle action voulez-vous faire dans ce canal ?")
            else:
                msg = "{} {}".format(caller.key, msg)
                channel.msg(msg, online=True)
        elif self.switch == "who":
            keys = [obj.username for obj in connected]
            keys.sort()
            string = "Connectés au canal {} : ".format(channel.key)
            string += ", ".join(keys) if keys else "(no one)"
            string += "."
            self.msg(string)
        elif channel.access(caller,
                            'control') and self.switch in admin_switches:
            if self.switch == "destroy":
                confirm = yield (
                    "Are you sure you want to delete the channel {}? (Y?N)".
                    format(channel.key))
                if confirm.lower() in ("y", "yes"):
                    channel.msg("Destroying the channel.")
                    channel.delete()
                    CHANNELHANDLER.update()
                    self.msg("The channel was destroyed.")
                else:
                    self.msg("Operation cancelled, do not destroy.")
            elif self.switch == "emit":
                if not msg:
                    self.msg("What do you want to say on this channel?")
                else:
                    channel.msg(msg, online=True)
            elif self.switch in ("lock", "locks"):
                if msg:
                    try:
                        channel.locks.add(msg)
                    except LockException, err:
                        self.msg(err)
                        return
                    else:
                        self.msg("Channel permissions were edited.")

                string = "Current locks on {}:\n  {}".format(
                    channel.key, channel.locks)
                self.msg(string)
            elif self.switch == "desc":
                if msg:
                    channel.db.desc = msg
                    self.msg("Channel description was updated.")

                self.msg("Description of the {} channel: {}".format(
                    channel.key, channel.db.desc))
            elif self.switch == "kick":
                if not msg:
                    self.msg("Who do you want to kick from this channel?")
                else:
                    to_kick = caller.search(msg, candidates=connected)
                    if to_kick is None:
                        return

                    channel.disconnect(to_kick)
                    channel.msg("{} has been kicked from the channel.".format(
                        to_kick.key))
                    to_kick.msg(
                        "You have been kicked from the {} channel.".format(
                            channel.key))
        elif self.history_start is not None:
            # Try to view history
            log_file = channel.attributes.get("log_file",
                                              default="channel_%s.log" %
                                              channel.key)
            send_msg = lambda lines: self.msg("".join(
                line.split("[-]", 1)[1] if "[-]" in line else line
                for line in lines))
            tail_log_file(log_file, self.history_start, 20, callback=send_msg)