本文整理汇总了Python中utility_functions.extract_name函数的典型用法代码示例。如果您正苦于以下问题:Python extract_name函数的具体用法?Python extract_name怎么用?Python extract_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了extract_name函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: move_ship
def move_ship(self, location):
"""Move your ship to another player or specific coordinates. Syntax: /move_ship [player_name] OR /move_ship [from player] [to player]"""
try:
first_name, rest = extract_name(location)
if rest is None:
self.move_own_ship_to_player(first_name)
else:
self.move_player_ship_to_other(first_name, extract_name(rest)[0])
except ValueError:
self.protocol.send_chat_message(self.move_ship.__doc__)
开发者ID:elmerfud,项目名称:StarryPy,代码行数:10,代码来源:warpy_plugin.py
示例2: nick_set
def nick_set(self, data):
"""
Changes player nickname.
Syntax: /nick_set (name) (new name)
"""
if data:
self.protocol.send_chat_message(self.nick_set.__doc__)
return
try:
first_name, rest = extract_name(data)
# Replace problematic chars in client name
for regex in self.regexes:
first_name = re.sub(regex, "", first_name)
except ValueError:
self.protocol.send_chat_message("Name not recognized. If it has spaces, " "please surround it by quotes!")
return
if not rest:
self.protocol.send_chat_message(self.nick_set.__doc__)
else:
try:
second_name = extract_name(rest)[0]
# Replace problematic chars in client name
for regex in self.regexes:
second_name = re.sub(regex, "", second_name)
except ValueError:
self.protocol.send_chat_message(
"New name not recognized. If it has spaces, " "please surround it by quotes!"
)
return
player = self.player_manager.get_by_name(str(first_name))
player2 = self.player_manager.get_by_name(str(second_name))
org_player = self.player_manager.get_by_org_name(str(first_name))
org_player2 = self.player_manager.get_by_org_name(str(second_name))
if player:
first_uuid = player.uuid
elif org_player:
first_uuid = org_player.uuid
if player2:
second_uuid = player2.uuid
elif org_player2:
second_uuid = org_player2.uuid
if player or org_player:
if (player2 or org_player2) and first_uuid != second_uuid:
self.protocol.send_chat_message("There's already a player by that name.")
else:
old_name = player.colored_name(self.config.colors)
player.name = second_name
self.factory.broadcast(
"{}^green;'s name has been changed to {}".format(old_name, player.colored_name(self.config.colors))
)
开发者ID:8r2y5,项目名称:StarryPy,代码行数:52,代码来源:plugin.py
示例3: move_ship
def move_ship(self, location):
"""Move your ship to another player or specific coordinates. Syntax: /move_ship [player_name] OR /move_ship [from player] [to player]"""
try:
first_name, rest = extract_name(location)
if not rest:
self.move_own_ship_to_player(first_name)
else:
self.move_player_ship_to_other(first_name, extract_name(rest)[0])
except ValueError as e:
self.protocol.send_chat_message(str(e))
self.protocol.send_chat_message(self.move_ship.__doc__)
except AttributeError:
self.protocol.send_chat_message("Couldn't find one or both of the users you specified.")
开发者ID:TinCow,项目名称:StarryPy,代码行数:13,代码来源:warpy_plugin.py
示例4: unprotect
def unprotect(self, data):
"""Removes the protection from the current planet, or removes a registered player.\nSyntax: /unprotect [player]"""
planet = self.protocol.player.planet
on_ship = self.protocol.player.on_ship
if len(data) == 0:
addplayer = self.protocol.player.org_name
first_name_color = self.protocol.player.colored_name(self.config.colors)
else:
addplayer, rest = extract_name(data)
first_name_color = addplayer
first_name = str(addplayer)
if on_ship:
self.protocol.send_chat_message("Can't protect ships (at the moment)")
return
if len(data) == 0:
if planet in self.protected_planets:
del self.player_planets[planet]
self.protected_planets.remove(planet)
self.protocol.send_chat_message("Planet successfully unprotected.")
self.logger.info("Unprotected planet %s", planet)
else:
self.protocol.send_chat_message("Planet is not protected!")
else:
if first_name in self.player_planets[planet]:
self.player_planets[planet].remove(first_name)
self.protocol.send_chat_message("Removed ^yellow;" + first_name_color + "^green; from planet list")
else:
self.protocol.send_chat_message(
"Cannot remove ^yellow;" + first_name_color + "^green; from planet list (not in list)")
self.save()
开发者ID:Azorax,项目名称:StarryPy,代码行数:30,代码来源:planet_protect_plugin.py
示例5: give_item
def give_item(self, data):
"""Gives an item to a player. Syntax: /give [target player] [item name] [optional: item count]"""
if len(data) >= 2:
name, item = extract_name(data)
target_player = self.player_manager.get_logged_in_by_name(name)
target_protocol = self.protocol.factory.protocols[target_player.protocol]
if target_player is not None:
if len(item) > 0:
item_name = item[0]
if len(item) > 1:
item_count = item[1]
else:
item_count = 1
give_item_to_player(target_protocol, item_name, item_count)
target_protocol.send_chat_message(
"%s has given you: %s (count: %s)" % (
self.protocol.player.name, item_name, item_count))
self.protocol.send_chat_message("Sent the item(s).")
self.logger.info("%s gave %s %s (count: %s)", self.protocol.player.name, name, item_name,
item_count)
else:
self.protocol.send_chat_message("You have to give an item name.")
else:
self.protocol.send_chat_message("Couldn't find name: %s" % name)
return False
else:
self.protocol.send_chat_message(self.give_item.__doc__)
开发者ID:elmerfud,项目名称:StarryPy,代码行数:27,代码来源:admin_command_plugin.py
示例6: teleport_to_own_ship
def teleport_to_own_ship(self, data):
"""
Teleports a player to their own ship. If no source player is provided,
we assume you mean yourself.
Syntax: /teleport home [source player]
"""
usage = 'Syntax: /teleport home [source player]'
if not data:
source = self.protocol.player.name
else:
source, rest = extract_name(data)
if not self._validate_player(source):
self.protocol.send_chat_message(usage)
return
source = source.lower()
source_player = self.player_manager.get_logged_in_by_name(source)
if source_player is None:
self.logger.debug('Error: Player %s is not logged in.', source)
self.protocol.send_chat_message(
'Error: Player {} is not logged in.'.format(source)
)
return
source_protocol = self.factory.protocols[source_player.protocol]
teleport_packet = build_packet(
Packets.PLAYER_WARP, player_warp_toalias_write(alias=2)
)
source_protocol.client_protocol.transport.write(teleport_packet)
开发者ID:GermaniumSystem,项目名称:StarryPy,代码行数:30,代码来源:teleport_plugin.py
示例7: teleport_to_player
def teleport_to_player(self, data):
"""Teleports a player to another player's location. If no source player is provided, we assume you mean yourself.\nSyntax: /teleport [player] (destination player) [source player]"""
usage = 'Syntax: /teleport [player] (destination player) [source player]'
if not data:
self.protocol.send_chat_message(self.teleport_to_player.__doc__)
return
destination, rest = extract_name(data)
if not self._validate_player(destination):
self.protocol.send_chat_message(usage)
return
destination = destination.lower()
if not rest:
source = self.protocol.player.name
source = source.lower()
else:
source, rest = extract_name(rest)
if not self._validate_player(source):
self.protocol.send_chat_message(usage)
return
source = source.lower()
if source == destination:
self.logger.debug("Error: player is teleporting to self.")
self.protocol.send_chat_message("Why are you trying to teleport to yourself? That seems illogical, captain.")
return
destination_player = self.player_manager.get_logged_in_by_name(destination)
if destination_player is None:
self.logger.debug("Error: Player %s is not logged in.", destination)
self.protocol.send_chat_message("Error: Player %s is not logged in." % (destination, ))
return
source_player = self.player_manager.get_logged_in_by_name(source)
if source_player is None:
self.logger.debug("Error: Player %s is not logged in.", source)
self.protocol.send_chat_message("Error: Player %s is not logged in." % (source, ))
return
source_protocol = self.factory.protocols[source_player.protocol]
teleport_packet = build_packet(Packets.PLAYER_WARP, player_warp_toplayer_write(uuid=destination_player.uuid))
source_protocol.client_protocol.transport.write(teleport_packet)
self.logger.debug("Teleport command called by %s. Teleporting %s to %s", self.protocol.player.name, source, destination)
self.protocol.send_chat_message("Teleported ^yellow;%s^green; to ^yellow;%s^green;." % (source, destination))
开发者ID:Asmodeyby,项目名称:StarryPy,代码行数:47,代码来源:teleport_plugin.py
示例8: unclaim
def unclaim(self, data):
"""Removes claimed planet, or removes a registered player.\nSyntax: /unclaim [player]"""
try:
my_storage = self.protocol.player.storage
except AttributeError:
return
if not 'claims' in my_storage or int(my_storage['claims']) <= 0:
my_storage['claims'] = 0
self.protocol.player.storage = my_storage
self.protocol.send_chat_message("You have no claimed planets!")
else:
planet = self.protocol.player.planet
on_ship = self.protocol.player.on_ship
#print(self.player_planets[planet].first())
#player_name = self.protocol.player.name
if len(data) == 0:
addplayer = self.protocol.player.org_name
first_name_color = self.protocol.player.colored_name(self.config.colors)
else:
addplayer, rest = extract_name(data)
first_name_color = addplayer
first_name = str(addplayer)
orgplayer = self.protocol.player.org_name
if on_ship:
self.protocol.send_chat_message("Can't claim ships (at the moment)")
return
try:
count = 1
for name in self.player_planets[planet]:
#print(first_name, str(name))
if name != str(orgplayer) and count == 1:
self.protocol.send_chat_message("You can only unclaim planets you've claimed!")
return
if len(data) != 0 and first_name == str(orgplayer):
self.protocol.send_chat_message("Use only /unclaim if you wish to remove protection!")
return
count += 1
except:
pass
if len(data) == 0:
if planet in self.protected_planets:
del self.player_planets[planet]
self.protected_planets.remove(planet)
self.protocol.send_chat_message("Planet successfully unclaimed.")
self.logger.info("Unprotected planet %s", planet)
my_storage['claims'] = int(my_storage['claims']) - 1
self.protocol.player.storage = my_storage
else:
self.protocol.send_chat_message("Planet has not been claimed!")
else:
if first_name in self.player_planets[planet]:
self.player_planets[planet].remove(first_name)
self.protocol.send_chat_message("Removed ^yellow;" + first_name_color + "^green; from planet list")
else:
self.protocol.send_chat_message(
"Cannot remove ^yellow;" + first_name_color + "^green; from planet list (not in list)")
self.save()
开发者ID:Azorax,项目名称:StarryPy,代码行数:59,代码来源:claims_plugin.py
示例9: warp_ship
def warp_ship(self, location):
"""Warps a player ship to another players ship.\nSyntax: /warp_ship [player] (to player)"""
if len(location) == 0:
self.protocol.send_chat_message(self.warp_ship.__doc__)
return
try:
first_name, rest = extract_name(location)
except ValueError as e:
self.protocol.send_chat_message(str(e))
return
if rest is None or len(rest) == 0:
self.move_own_ship_to_player(first_name)
else:
try:
second_name = extract_name(rest)[0]
except ValueError as e:
self.protocol.send_chat_message(str(e))
return
self.move_player_ship_to_other(first_name, second_name)
开发者ID:Asian-Canadian,项目名称:StarryPy,代码行数:19,代码来源:warpy_plugin.py
示例10: warp
def warp(self, name):
"""Warps you to a player's ship (or player to player).\nSyntax: /warp [player] (to player)"""
if len(name) == 0:
self.protocol.send_chat_message(self.warp.__doc__)
return
try:
first_name, rest = extract_name(name)
except ValueError as e:
self.protocol.send_chat_message(str(e))
return
if rest is None or len(rest) == 0:
self.warp_self_to_player([first_name])
else:
try:
second_name = extract_name(rest)[0]
except ValueError as e:
self.protocol.send_chat_message(str(e))
return
self.warp_player_to_player(first_name, second_name)
开发者ID:Asian-Canadian,项目名称:StarryPy,代码行数:19,代码来源:warpy_plugin.py
示例11: warp
def warp(self, name):
"""Warps you to a player's ship, or a player to another player's ship. Syntax: /warp [player name] OR /warp [player 1] [player 2]"""
if len(name) == 0:
self.protocol.send_chat_message(self.warp.__doc__)
return
try:
first_name, rest = extract_name(name)
except ValueError:
self.protocol.send_chat_message(self.warp.__doc__)
return
if rest is None or len(rest)==0:
self.warp_self_to_player([first_name])
else:
try:
second_name = extract_name(rest)[0]
except ValueError:
self.protocol.send_chat_message(self.warp.__doc__)
return
self.warp_player_to_player(first_name, second_name)
开发者ID:elmerfud,项目名称:StarryPy,代码行数:19,代码来源:warpy_plugin.py
示例12: unban_by_name
def unban_by_name(self, data):
name, reason = extract_name(data)
info = self.player_manager.get_by_name(name)
if info:
self.player_manager.unban(info.name)
self.protocol.send_chat_message("Unbanned: %s" % info.colored_name(self.config.colors))
self.logger.warning("%s unbanned: %s", self.protocol.player.name, info.name)
else:
self.protocol.send_chat_message("Couldn't find a user by the name ^yellow;%s^green;." % name)
return False
开发者ID:Asian-Canadian,项目名称:StarryPy,代码行数:10,代码来源:admin_command_plugin.py
示例13: move_ship
def move_ship(self, location):
"""Move a player ship to another player.\nSyntax: /move_ship <to player> OR /move_ship <from player> <to player>"""
if len(location) == 0:
self.protocol.send_chat_message(self.move_ship.__doc__)
return
try:
first_name, rest = extract_name(location)
except ValueError as e:
self.protocol.send_chat_message(str(e))
return
if rest is None or len(rest) == 0:
self.move_own_ship_to_player(first_name)
else:
try:
second_name = extract_name(rest)[0]
except ValueError as e:
self.protocol.send_chat_message(str(e))
return
self.move_player_ship_to_other(first_name, second_name)
开发者ID:mathsteck,项目名称:StarryPy,代码行数:19,代码来源:warpy_plugin.py
示例14: outpost
def outpost(self, name):
"""Warps you (or another player) to the outpost.\nSyntax: /outpost [player]"""
if len(name) == 0:
self.warp_player_to_outpost(self.protocol.player.name)
else:
try:
player_name, rest = extract_name(name)
except ValueError as e:
self.protocol.send_chat_message(str(e))
return
self.warp_player_to_outpost(player_name)
开发者ID:Sperovita,项目名称:StarryPy,代码行数:11,代码来源:warpy_plugin.py
示例15: unmute
def unmute(self, data):
"""Unmute a currently muted player.\nSyntax: /unmute (player)"""
name, garbage = extract_name(data)
player = self.player_manager.get_logged_in_by_name(name)
if player is None:
self.protocol.send_chat_message("Couldn't find a user by the name ^yellow;%s^green;" % name)
return
target_protocol = self.factory.protocols[player.protocol]
player.muted = False
target_protocol.send_chat_message("You have been ^yellow;unmuted^green;.")
self.protocol.send_chat_message(
"%s^green; has been ^yellow;unmuted^green;." % target_protocol.player.colored_name(self.config.colors))
开发者ID:teihoo,项目名称:StarryPy_Teihoo,代码行数:12,代码来源:admin_command_plugin.py
示例16: protect
def protect(self, data):
"""Protects the current planet. Only administrators and allowed players can build on protected planets.\nSyntax: /protect [player]"""
planet = self.protocol.player.planet
on_ship = self.protocol.player.on_ship
if len(data) == 0:
addplayer = self.protocol.player.org_name
first_name_color = self.protocol.player.colored_name(self.config.colors)
else:
self.logger.info("stream: %s" % data)
addplayer = data[0]
try:
addplayer, rest = extract_name(data)
self.logger.info("name: %s" % str(addplayer))
addplayer = self.player_manager.get_by_name(addplayer).org_name
first_name_color = self.player_manager.get_by_org_name(addplayer).colored_name(self.config.colors)
except:
self.protocol.send_chat_message("There's no player named: ^yellow;%s" % str(addplayer))
return
first_name = str(addplayer)
try:
if first_name in self.player_planets[self.protocol.player.planet]:
self.protocol.send_chat_message(
"Player ^yellow;%s^green; is already in planet protect list." % first_name_color)
return
except:
pass
planet = self.protocol.player.planet # reset planet back to current planet
if on_ship:
self.protocol.send_chat_message("Can't protect ships (at the moment)")
return
if planet not in self.protected_planets:
self.protected_planets.append(planet)
self.protocol.send_chat_message("Planet successfully protected.")
self.logger.info("Protected planet %s", planet)
if len(first_name) > 0:
if planet not in self.player_planets:
self.player_planets[planet] = [first_name]
else:
self.player_planets[planet] = self.player_planets[planet] + [first_name]
self.protocol.send_chat_message("Adding ^yellow;%s^green; to planet list" % first_name_color)
else:
if len(first_name) == 0:
self.protocol.send_chat_message("Planet is already protected!")
else:
if planet not in self.player_planets:
self.player_planets[planet] = [first_name]
else:
self.player_planets[planet] = self.player_planets[planet] + [first_name]
self.protocol.send_chat_message("Adding ^yellow;%s^green; to planet list" % first_name_color)
self.save()
开发者ID:Sperovita,项目名称:StarryPy,代码行数:53,代码来源:planet_protect_plugin.py
示例17: backup_drop
def backup_drop(self, data):
"""Remove a planet from backups completely.
Syntax: /backup drop (player name) (planet name)
"""
usage = 'Syntax: /backup drop (player name) (planet name)'
if not data:
self.protocol.send_chat_message(self.backup_drop.__doc__)
return
player_name, planet_name = extract_name(data)
if not self._validate_player(player_name):
self.protocol.send_chat_message(usage)
return
player_name = player_name.lower()
if not planet_name:
self.protocol.send_chat_message(
'A planet nickname must be provided.'
)
self.protocol.send_chat_message(usage)
return
planet_name = planet_name[0]
sql = (
'SELECT planet_coord FROM backups '
'WHERE owner = ? AND planet_name = ?'
)
result = self.db.select(sql, (player_name, planet_name))
if not result:
self.protocol.send_chat_message(
'No planet available based on provided input.'
)
return
planet_coord = result[0]
sql = 'DELETE FROM backups WHERE PLANET_COORD = ?'
self.db.execute(sql, (planet_coord[0], ))
dst_path = os.path.join('.', 'backups', player_name, planet_name)
self._drop_tree(dst_path)
self.protocol.send_chat_message(
'The planet has been removed from backups.'
)
self.logger.info(
'%s removed planet %s from backups for %s.',
self.protocol.player.name, planet_name, player_name
)
开发者ID:GermaniumSystem,项目名称:StarryPy,代码行数:50,代码来源:backups_plugin.py
示例18: unprotect
def unprotect(self, data):
"""
Removes the protection from the current planet, or removes a
registered player.
Syntax: /unprotect [player]
"""
planet = self.protocol.player.planet
on_ship = self.protocol.player.on_ship
if not data:
addplayer = self.protocol.player.org_name
first_name_color = self.protocol.player.colored_name(
self.config.colors
)
else:
addplayer, rest = extract_name(data)
first_name_color = addplayer
first_name = str(addplayer)
if on_ship:
self.protocol.send_chat_message(
'Can\'t protect ships (at the moment)'
)
return
if not data:
if planet in self.protected_planets:
del self.player_planets[planet]
self.protected_planets.remove(planet)
self.protocol.send_chat_message(
'Planet successfully unprotected.'
)
self.logger.info('Unprotected planet %s', planet)
else:
self.protocol.send_chat_message('Planet is not protected!')
else:
if first_name in self.player_planets[planet]:
self.player_planets[planet].remove(first_name)
self.protocol.send_chat_message(
'Removed ^yellow;{}^green; from planet list'.format(
first_name_color
)
)
else:
self.protocol.send_chat_message(
'Cannot remove ^yellow;{}^green; from planet list '
'(not in list)'.format(first_name_color)
)
self.save()
开发者ID:StarryPy,项目名称:StarryPy-Historic,代码行数:48,代码来源:planet_protect_plugin.py
示例19: kick
def kick(self, data):
"""Kicks a user from the server. Usage: /kick [username] [reason]"""
name, reason = extract_name(data)
if reason is None:
reason = "no reason given"
info = self.player_manager.whois(name)
if info and info.logged_in:
tp = self.protocol.factory.protocols[info.protocol]
tp.die()
self.protocol.factory.broadcast("%s kicked %s (reason: %s)" %
(self.protocol.player.name,
info.name,
" ".join(reason)))
self.logger.info("%s kicked %s (reason: %s", self.protocol.player.name, info.name,
" ".join(reason))
return False
开发者ID:elmerfud,项目名称:StarryPy,代码行数:16,代码来源:admin_command_plugin.py
示例20: backup_disable
def backup_disable(self, data):
"""
Stop a planet from backing up (but keep it's history around).
Syntax: /backup disable [planet name]
"""
usage = 'Syntax: /backup disable (player name) (planet name)'
if not data:
self.protocol.send_chat_message(self.backup_disable.__doc__)
return
player_name, planet_name = extract_name(data)
if not self._validate_player(player_name):
self.protocol.send_chat_message(usage)
return
player_name = player_name.lower()
if not planet_name:
self.protocol.send_chat_message(
'A planet nickname must be provided.'
)
self.protocol.send_chat_message(usage)
return
planet_name = planet_name[0]
sql = (
'SELECT planet_coord, active FROM backups '
'WHERE owner = ? AND planet_name = ?'
)
result = self.db.select(sql, (player_name, planet_name))
if not result:
self.protocol.send_chat_message(
'No planet available based on provided input.'
)
return
planet_coord, active = result[0]
if not active:
self.protocol.send_chat_message(
'Planet backups are already disabled.'
)
return
sql = 'UPDATE backups set active = 0 WHERE planet_coord = ?'
_ = self.db.execute(sql, (planet_coord, ))
self.protocol.send_chat_message('Planet backups have been disabled.')
开发者ID:GermaniumSystem,项目名称:StarryPy,代码行数:47,代码来源:backups_plugin.py
注:本文中的utility_functions.extract_name函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论