当前位置: 首页>>代码示例>>Python>>正文


Python utilities.send_message函数代码示例

本文整理汇总了Python中utilities.send_message函数的典型用法代码示例。如果您正苦于以下问题:Python send_message函数的具体用法?Python send_message怎么用?Python send_message使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了send_message函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_command

    def run_command(self, command, connection, to_parse):
        """
        Evaluate the command passed in, passing along the arguments. Raise
        various errors depending on what might have gone wrong.

        :param command: Command to be executed. Looked up in commands dict.
        :param connection: Connection which is calling the command.
        :param to_parse: Arguments to provide to the command.
        :return: Null.
        :raise: SyntaxWarning on improper syntax usage. NameError when object
                could not be found. ValueError when improper input is provided.
                General Exception error as a last-resort catch-all.
        """
        try:
            yield from self.commands[command](extractor(to_parse),
                                              connection)
        except SyntaxWarning as e:
            self._send_syntax_error(command, e, connection)
        except NameError as e:
            self._send_name_error(e, connection)
        except ValueError as e:
            send_message(connection, str(e))
        except SystemExit as e:
            raise SystemExit
        except:
            self.logger.exception("Unknown exception encountered. Ignoring.",
                                  exc_info=True)
开发者ID:dopeghoti,项目名称:StarryPy3k,代码行数:27,代码来源:command_dispatcher.py

示例2: _readmail

 def _readmail(self, data, connection):
     if connection.player.uuid not in self.storage['mail']:
         self.storage['mail'][connection.player.uuid] = []
     mailbox = self.storage['mail'][connection.player.uuid]
     if data:
         try:
             index = int(data[0]) - 1
             mail = mailbox[index]
             mail.unread = False
             yield from send_message(connection, "From {} on {}: \n{}"
                                     .format(mail.author.alias,
                                             mail.time.strftime("%d %b "
                                                                "%H:%M"),
                                             mail.message))
         except ValueError:
             yield from send_message(connection, "Specify a valid number.")
         except IndexError:
             yield from send_message(connection, "No mail with that "
                                                 "number.")
     else:
         unread_mail = False
         for mail in mailbox:
             if mail.unread:
                 unread_mail = True
                 mail.unread = False
                 yield from send_message(connection, "From {} on {}: \n{}"
                                         .format(mail.author.alias,
                                                 mail.time
                                                 .strftime("%d %b %H:%M"),
                                                 mail.message))
         if not unread_mail:
             yield from send_message(connection, "No unread mail to "
                                                 "display.")
开发者ID:GermaniumSystem,项目名称:StarryPy3k,代码行数:33,代码来源:mail.py

示例3: _sendmail

 def _sendmail(self, data, connection):
     if data:
         target = self.find_player(data[0])
         if not target:
             raise SyntaxWarning("Couldn't find target.")
         if not data[1]:
             raise SyntaxWarning("No message provided.")
         uid = target.uuid
         if uid not in self.storage['mail']:
             self.storage['mail'][uid] = []
         mailbox = self.storage['mail'][uid]
         if len(mailbox) >= self.max_mail:
             yield from send_message(connection, "{}'s mailbox is full!"
                                     .format(target.alias))
         else:
             mail = Mail(" ".join(data[1:]), connection.player)
             mailbox.insert(0, mail)
             yield from send_message(connection, "Mail delivered to {}."
                                     .format(target.alias))
             if target.logged_in:
                 yield from send_message(target.connection, "New mail from "
                                                            "{}!"
                                         .format(connection.player.alias))
     else:
         raise SyntaxWarning("No target provided.")
开发者ID:GermaniumSystem,项目名称:StarryPy3k,代码行数:25,代码来源:mail.py

示例4: _delete_player

    def _delete_player(self, data, connection):
        """
        Removes a player from the player database. By default. you cannot
        remove a logged-in player, so either they need to be removed from
        the server first, or you have to apply the *force operation.

        :param data: The packet containing the command.
        :param connection: The connection from which the packet came.
        :return: Null.
        :raise: NameError if is not available. ValueError if player is
                currently logged in.
        """
        if data[-1] == "*force":
            force = True
            data.pop()
        else:
            force = False
        alias = " ".join(data)
        player = self.get_player_by_alias(alias)
        if player is None:
            raise NameError
        if (not force) and player.logged_in:
            raise ValueError(
                "Can't delete a logged-in player; please kick them first. If "
                "absolutely necessary, append *force to the command.")
        self.players.pop(player.uuid)
        del player
        send_message(connection, "Player {} has been deleted.".format(alias))
开发者ID:ren-kun,项目名称:StarryPy3k,代码行数:28,代码来源:player_manager.py

示例5: _move_ship

    def _move_ship(self, connection):
        """
        Generate packet that moves ship.

        :param connection: Player being moved to spawn.
        :return: Null.
        :raise: NotImplementedError when spawn planet not yet set.
        """
        if "spawn_location" not in self.storage["spawn"]:
            send_message(connection, "Spawn planet not currently set.")
            raise NotImplementedError
        else:
            spawn_location = self.storage["spawn"]["spawn_location"]
            destination = data_parser.FlyShip.build(dict(
                world_x=spawn_location.x,
                world_y=spawn_location.y,
                world_z=spawn_location.z,
                location=dict(
                    type=SystemLocationType.COORDINATE,
                    world_x=spawn_location.x,
                    world_y=spawn_location.y,
                    world_z=spawn_location.z,
                    world_planet=spawn_location.planet,
                    world_satellite=spawn_location.satellite
                )
            ))
            flyship_packet = pparser.build_packet(packets.packets["fly_ship"],
                                                  destination)
            yield from connection.client_raw_write(flyship_packet)
开发者ID:GermaniumSystem,项目名称:StarryPy3k,代码行数:29,代码来源:spawn.py

示例6: _move_ship

    def _move_ship(self, connection, location):
        """
        Generate packet that moves ship.

        :param connection: Player being moved.
        :param location: The intended destination of the player.
        :return: Null.
        :raise: NotImplementedError when POI does not exist.
        """
        if location not in self.storage["pois"]:
            send_message(connection, "That POI does not exist!")
            raise NotImplementedError
        else:
            location = self.storage["pois"][location]
            destination = data_parser.FlyShip.build(dict(
                world_x=location.x,
                world_y=location.y,
                world_z=location.z,
                location=dict(
                    type=SystemLocationType.COORDINATE,
                    world_x=location.x,
                    world_y=location.y,
                    world_z=location.z,
                    world_planet=location.planet,
                    world_satellite=location.satellite
                )
            ))
            flyship_packet = pparser.build_packet(packets.packets["fly_ship"],
                                                  destination)
            yield from connection.client_raw_write(flyship_packet)
开发者ID:GermaniumSystem,项目名称:StarryPy3k,代码行数:30,代码来源:poi.py

示例7: _here

    def _here(self, data, connection):
        """
        Displays all players on the same planet as the user.

        :param data: The packet containing the command.
        :param connection: The connection from which the packet came.
        :return: Null.
        """
        ret_list = []
        location = str(connection.player.location)
        for uid in self.plugins.player_manager.players_online:
            p = self.plugins.player_manager.get_player_by_uuid(uid)
            if str(p.location) == location:
                if connection.player.perm_check(
                        "general_commands.who_clientids"):
                    ret_list.append(
                        "[^red;{}^reset;] {}{}^reset;"
                            .format(p.client_id,
                                    p.chat_prefix,
                                    p.alias))
                else:
                    ret_list.append("{}{}^reset;".format(
                        p.chat_prefix, p.alias))
        send_message(connection,
                     "{} players on planet:\n{}".format(len(ret_list),
                                                        ", ".join(ret_list)))
开发者ID:GermaniumSystem,项目名称:StarryPy3k,代码行数:26,代码来源:general_commands.py

示例8: _nick

    def _nick(self, data, connection):
        """
        Change your name as it is displayed in the chat window.

        :param data: The packet containing the command.
        :param connection: The connection from which the packet came.
        :return: Null.
        """
        if len(data) > 1 and connection.player.perm_check(
                "general_commands.nick_others"):
            target = self.plugins.player_manager.find_player(data[0])
            alias = " ".join(data[1:])
        else:
            alias = " ".join(data)
            target = connection.player
        if len(data) == 0:
            alias = connection.player.name
        conflict = self.plugins.player_manager.get_player_by_alias(alias)
        if conflict and target != conflict:
            raise ValueError("There's already a user by that name.")
        else:
            clean_alias = self.plugins['player_manager'].clean_name(alias)
            if clean_alias is None:
                send_message(connection,
                             "Nickname contains no valid characters.")
                return
            old_alias = target.alias
            target.alias = clean_alias
            broadcast(connection, "{}'s name has been changed to {}".format(
                old_alias, clean_alias))
开发者ID:GermaniumSystem,项目名称:StarryPy3k,代码行数:30,代码来源:general_commands.py

示例9: _protect_ship

    def _protect_ship(self, connection):
        """
        Add protection to a ship.

        :param connection: Connection of player to have ship protected.
        :return: Null.
        """
        yield from asyncio.sleep(.5)
        try:
            if connection.player.location.locationtype() is "ShipWorld":
                ship = connection.player.location
                alias = connection.player.alias
                if ship.player == alias:
                    if not self.planet_protect.check_protection(ship):
                        self.planet_protect. add_protection(ship,
                                                            connection.player)
                        send_message(connection,
                                     "Your ship has been auto-claimed in "
                                     "your name.")
                        if alias not in self.storage["owners"]:
                            self.storage["owners"][alias] = []
                        self.storage["owners"][alias].append(str(ship))
                    if alias not in self.storage["owners"]:
                        self.storage["owners"][alias] = [str(ship)]
                    elif str(ship) not in self.storage["owners"][alias]:
                        self.storage["owners"][alias].append(str(ship))
        except AttributeError:
            pass
开发者ID:dopeghoti,项目名称:StarryPy3k,代码行数:28,代码来源:claims.py

示例10: ban_by_name

 def ban_by_name(self, name, reason, protocol):
     p = self.get_player_by_name(name)
     if p is not None:
         self.ban_by_ip(p.ip, reason, protocol)
     else:
         send_message(protocol,
                      "Couldn't find a player by the name %s" % name)
开发者ID:FrankVenseth10,项目名称:StarryPy3k,代码行数:7,代码来源:player_manager.py

示例11: planetary_broadcast

 def planetary_broadcast(self, player, message):
     for p in self.players.values():
         if p.logged_in and p.location is player.location:
             send_message(p.protocol,
                          message,
                          name=p.name)
     return None
开发者ID:FrankVenseth10,项目名称:StarryPy3k,代码行数:7,代码来源:player_manager.py

示例12: _delmail

 def _delmail(self, data, connection):
     uid = connection.player.uuid
     if uid not in self.storage['mail']:
         self.storage['mail'][uid] = []
     mailbox = self.storage['mail'][uid]
     if data:
         if data[0] == "all":
             self.storage['mail'][uid] = []
             yield from send_message(connection, "Deleted all mail.")
         elif data[0] == "unread":
             for mail in mailbox:
                 if mail.unread:
                     self.storage['mail'][uid].remove(mail)
             yield from send_message(connection, "Deleted all unread mail.")
         elif data[0] == "read":
             for mail in mailbox:
                 if not mail.unread:
                     self.storage['mail'][uid].remove(mail)
             yield from send_message(connection, "Deleted all read mail.")
         else:
             try:
                 index = int(data[0]) - 1
                 self.storage['mail'][uid].pop(index)
                 yield from send_message(connection, "Deleted mail {}."
                                         .format(data[0]))
             except ValueError:
                 raise SyntaxWarning("Argument must be a category or "
                                     "number. Valid categories: \"read\","
                                     " \"unread\", \"all\"")
             except IndexError:
                 yield from send_message(connection, "No message at "
                                                     "that index.")
     else:
         raise SyntaxWarning("No argument provided.")
开发者ID:GermaniumSystem,项目名称:StarryPy3k,代码行数:34,代码来源:mail.py

示例13: _protect_ship

    def _protect_ship(self, connection):
        """
        Add protection to a ship.

        :param connection: Connection of player to have ship protected.
        :return: Null.
        """
        if not hasattr(connection, "player"):
            return
        try:
            if connection.player.location.locationtype() is "ShipWorld":
                ship = connection.player.location
                uuid = connection.player.uuid
                if ship.uuid.decode("utf-8") == uuid:
                    if not self.planet_protect.check_protection(ship):
                        self.planet_protect. add_protection(ship,
                                                            connection.player)
                        send_message(connection,
                                     "Your ship has been auto-claimed in "
                                     "your name.")
                        if uuid not in self.storage["owners"]:
                            self.storage["owners"][uuid] = []
                        self.storage["owners"][uuid].append(str(ship))
                    if uuid not in self.storage["owners"]:
                        self.storage["owners"][uuid] = [str(ship)]
                    elif str(ship) not in self.storage["owners"][uuid]:
                        self.storage["owners"][uuid].append(str(ship))
        except AttributeError:
            pass
开发者ID:GermaniumSystem,项目名称:StarryPy3k,代码行数:29,代码来源:claims.py

示例14: _purge_claims

 def _purge_claims(self, data, connection):
     target = self.plugins.player_manager.find_player(" ".join(data))
     if target.uuid in self.storage['owners']:
         self.storage['owners'][target.uuid] = []
         yield from send_message(connection, "Purged claims of {}"
                                 .format(target.alias))
     else:
         yield from send_message(connection, "Target has no claims.")
开发者ID:GermaniumSystem,项目名称:StarryPy3k,代码行数:8,代码来源:claims.py

示例15: who

 def who(self, data, protocol):
     ret_list = []
     for player in self.plugins['player_manager'].players.values():
         if player.logged_in:
             ret_list.append(player.name)
     send_message(protocol,
                  "%d players online: %s" % (len(ret_list),
                                             ", ".join(ret_list)))
开发者ID:FrankVenseth10,项目名称:StarryPy3k,代码行数:8,代码来源:general_commands.py


注:本文中的utilities.send_message函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。