當前位置: 首頁>>代碼示例>>Python>>正文


Python channelhandler.CHANNELHANDLER類代碼示例

本文整理匯總了Python中evennia.comms.channelhandler.CHANNELHANDLER的典型用法代碼示例。如果您正苦於以下問題:Python CHANNELHANDLER類的具體用法?Python CHANNELHANDLER怎麽用?Python CHANNELHANDLER使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了CHANNELHANDLER類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: func

    def func(self):
        "Implement the command"

        caller = self.caller

        if not self.args:
            self.msg("Usage @ccreate <channelname>[;alias;alias..] = description")
            return

        description = ""

        if self.rhs:
            description = self.rhs
        lhs = self.lhs
        channame = lhs
        aliases = None
        if ';' in lhs:
            channame, aliases = lhs.split(';', 1)
            aliases = [alias.strip().lower() for alias in aliases.split(';')]
        channel = ChannelDB.objects.channel_search(channame)
        if channel:
            self.msg("A channel with that name already exists.")
            return
        # Create and set the channel up
        lockstring = "send:all();listen:all();control:id(%s)" % caller.id
        new_chan = create.create_channel(channame.strip(),
                                         aliases,
                                         description,
                                         locks=lockstring)
        new_chan.connect(caller)
        CHANNELHANDLER.update()
        self.msg("Created channel %s and connected to it." % new_chan.key)
開發者ID:ergodicbreak,項目名稱:evennia,代碼行數:32,代碼來源:comms.py

示例2: delete

 def delete(self):
     """
     Deletes channel while also cleaning up channelhandler
     """
     self.attributes.clear()
     self.aliases.clear()
     super(DefaultChannel, self).delete()
     from evennia.comms.channelhandler import CHANNELHANDLER
     CHANNELHANDLER.update()
開發者ID:Antraeus,項目名稱:evennia,代碼行數:9,代碼來源:comms.py

示例3: _get_channel_cmdset

 def _get_channel_cmdset(player_or_obj):
     """
     Helper-method; Get channel-cmdsets
     """
     # Create cmdset for all player's available channels
     try:
         channel_cmdset = yield CHANNELHANDLER.get_cmdset(player_or_obj)
         returnValue([channel_cmdset])
     except Exception:
         _msg_err(caller, _ERROR_CMDSETS)
         raise ErrorReported
開發者ID:ghh0000,項目名稱:evennia,代碼行數:11,代碼來源:cmdhandler.py

示例4: func

    def func(self):
        """implement the function"""

        if not self.args or not self.rhs:
            string = "Usage: @cboot[/quiet] <channel> = <account> [:reason]"
            self.msg(string)
            return

        channel = find_channel(self.caller, self.lhs)
        if not channel:
            return
        reason = ""
        if ":" in self.rhs:
            accountname, reason = self.rhs.rsplit(":", 1)
            searchstring = accountname.lstrip('*')
        else:
            searchstring = self.rhs.lstrip('*')
        account = self.caller.search(searchstring, account=True)
        if not account:
            return
        if reason:
            reason = " (reason: %s)" % reason
        if not channel.access(self.caller, "control"):
            string = "You don't control this channel."
            self.msg(string)
            return
        if not channel.subscriptions.has(account):
            string = "Account %s is not connected to channel %s." % (account.key, channel.key)
            self.msg(string)
            return
        if "quiet" not in self.switches:
            string = "%s boots %s from channel.%s" % (self.caller, account.key, reason)
            channel.msg(string)
        # find all account's nicks linked to this channel and delete them
        for nick in [nick for nick in
                     account.character.nicks.get(category="channel") or []
                     if nick.value[3].lower() == channel.key]:
            nick.delete()
        # disconnect account
        channel.disconnect(account)
        CHANNELHANDLER.update()
開發者ID:Henddher,項目名稱:evennia,代碼行數:41,代碼來源:comms.py

示例5: _get_channel_cmdsets

 def _get_channel_cmdsets(player, player_cmdset):
     "Channel-cmdsets"
     # Create cmdset for all player's available channels
     try:
         channel_cmdset = None
         if not player_cmdset.no_channels:
             channel_cmdset = yield CHANNELHANDLER.get_cmdset(player)
         returnValue(channel_cmdset)
     except Exception:
         logger.log_trace()
         _msg_err(caller, _ERROR_CMDSETS)
         raise ErrorReported
開發者ID:Antraeus,項目名稱:evennia,代碼行數:12,代碼來源:cmdhandler.py

示例6: func


#.........這裏部分代碼省略.........
        elif 'desc' in self.switches:
            if not self.rhs:
                self.msg("Usage: %s/desc <channel> = <description>" % self.cmdstring)
                return
            channel = find_channel(caller, self.lhs)
            if not channel:
                self.msg("Channel '%s' not found." % self.lhs)
                return
            if not channel.access(caller, 'control'):  # check permissions
                self.msg("You cannot describe this channel.")
                return
            channel.db.desc = self.rhs  # set the description
            channel.save()
            self.msg("Description of channel '%s' set to '%s'." % (channel.key, self.rhs))
        elif 'all' in self.switches:
            if not args:
                caller.execute_cmd("@channels")
                self.msg("Usage: %s/all on || off || who || clear" % self.cmdstring)
                return
            if args == "on":  # get names of all channels available to listen to and activate them all
                channels = [chan for chan in ChannelDB.objects.get_all_channels()
                            if chan.access(caller, 'listen')]
                for channel in channels:
                    caller.execute_cmd("@command/join %s" % channel.key)
            elif args == 'off':
                # get names all subscribed channels and disconnect from them all
                channels = ChannelDB.objects.get_subscriptions(caller)
                for channel in channels:
                    caller.execute_cmd("@command/part %s" % channel.key)
            elif args == 'who':
                # run a who, listing the subscribers on visible channels.
                string = "\n|CChannel subscriptions|n"
                channels = [chan for chan in ChannelDB.objects.get_all_channels()
                            if chan.access(caller, 'listen')]
                if not channels:
                    string += "No channels."
                for channel in channels:
                    if not channel.access(self.caller, "control"):
                        continue
                    string += "\n|w%s:|n\n" % channel.key
                    subs = channel.db_subscriptions.all()
                    if subs:
                        string += "  " + ", ".join([account.key for account in subs])
                    else:
                        string += "  <None>"
                self.msg(string.strip())
            else:
                # wrong input
                self.msg("Usage: %s/all on | off | who | clear" % self.cmdstring)
        elif 'remove' in self.switches or 'quiet' in self.switches:
            if not self.args or not self.rhs:
                switch = 'remove' if 'remove' in self.switches else 'quiet'
                string = "Usage: %s/%s <channel> = <account> [:reason]" % (self.cmdstring, switch)
                self.msg(string)
                return
            channel = find_channel(self.caller, self.lhs)
            if not channel:
                return
            reason = ''
            if ":" in self.rhs:
                account_name, reason = self.rhs.rsplit(":", 1)
                search_string = account_name.lstrip('*')
            else:
                search_string = self.rhs.lstrip('*')
            account = self.caller.search(search_string, account=True)
            if not account:
                return
            if reason:
                reason = " (reason: %s)" % reason
            if not channel.access(self.caller, "control"):
                string = "You don't control this channel."
                self.msg(string)
                return
            if account not in channel.db_subscriptions.all():
                string = "Account %s is not connected to channel %s." % (account.key, channel.key)
                self.msg(string)
                return
            if 'quiet' not in self.switches:
                string = "%s boots %s from channel.%s" % (self.caller, account.key, reason)
                channel.msg(string)
            # find all account's nicks linked to this channel and delete them
            for nick in [nick for nick in
                         account.character.nicks.get(category="channel") or []
                         if nick.db_real.lower() == channel.key]:
                nick.delete()
            channel.disconnect(account)  # disconnect account
            CHANNELHANDLER.update()
        else:  # just display the subscribed channels with no extra info
            com_table = evtable.EvTable("|wchannel|n", "|wmy aliases|n",
                                        "|wdescription|n", align="l", maxwidth=_DEFAULT_WIDTH)
            for chan in subs:
                c_lower = chan.key.lower()
                nicks = caller.nicks.get(category="channel", return_obj=True)
                com_table.add_row(*["%s%s" % (chan.key, chan.aliases.all() and
                                    "(%s)" % ",".join(chan.aliases.all()) or ""),
                                    "%s" % ",".join(nick.db_key for nick in make_iter(nicks)
                                                    if nick and nick.strvalue.lower() == c_lower),
                                    chan.db.desc])
            caller.msg("\n|wChannel subscriptions|n (use |[email protected]/list|n to list all, " +
                       "|w/join|n |w/part|n to join or part):|n\n%s" % com_table)
開發者ID:Pinacolada64,項目名稱:NOW,代碼行數:101,代碼來源:channel.py


注:本文中的evennia.comms.channelhandler.CHANNELHANDLER類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。