Skip to content
This repository was archived by the owner on Apr 27, 2019. It is now read-only.

Commit b44889c

Browse files
committed
Moved extract_name to utility_functions.py
1 parent 745c9ba commit b44889c

2 files changed

Lines changed: 24 additions & 23 deletions

File tree

plugins/admin_commands_plugin/admin_command_plugin.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from base_plugin import SimpleCommandPlugin, BasePlugin
22
from core_plugins.player_manager import permissions, UserLevels
33
from packets import chat_sent
4-
from utility_functions import give_item_to_player
4+
from utility_functions import give_item_to_player, extract_name
55

66

77
class UserCommandPlugin(SimpleCommandPlugin):
@@ -18,25 +18,6 @@ def activate(self):
1818
self.player_manager = self.plugins['player_manager'].player_manager
1919
self.godmode = {}
2020

21-
@staticmethod
22-
def extract_name(l):
23-
name = []
24-
if l[0][0] not in ["'", '"']:
25-
return l[0], l[1:]
26-
name.append(l[0][1:])
27-
terminator = l[0][0]
28-
for idx, s in enumerate(l[1:]):
29-
if s[-1] == terminator:
30-
name.append(s[:-1])
31-
if idx + 2 != len(l):
32-
return " ".join(name), l[idx + 2:]
33-
else:
34-
return " ".join(name), None
35-
else:
36-
name.append(s)
37-
raise ValueError("Final terminator character of <%s> not found" %
38-
terminator)
39-
4021
def who(self, data):
4122
"""Returns all current users on the server. Syntax: /who"""
4223
who = [w.colored_name(self.config.colors) for w in self.player_manager.who()]
@@ -122,7 +103,7 @@ def make_admin(self, player):
122103
@permissions(UserLevels.MODERATOR)
123104
def kick(self, data):
124105
"""Kicks a user from the server. Usage: /kick [username] [reason]"""
125-
name, reason = self.extract_name(data)
106+
name, reason = extract_name(data)
126107
if reason is None:
127108
reason = "no reason given"
128109
info = self.player_manager.whois(name)
@@ -169,7 +150,7 @@ def unban(self, data):
169150
def give_item(self, data):
170151
"""Gives an item to a player. Syntax: /give [target player] [item name] [optional: item count]"""
171152
if len(data) >= 2:
172-
name, item = self.extract_name(data)
153+
name, item = extract_name(data)
173154
target_player = self.player_manager.get_logged_in_by_name(name)
174155
target_protocol = self.protocol.factory.protocols[target_player.protocol]
175156
if target_player is not None:
@@ -225,6 +206,7 @@ def passthrough(self, data):
225206
"""Sets the server to passthrough mode. *This is irreversible without restart.* Syntax: /passthrough"""
226207
self.config.passthrough = True
227208

209+
228210
class MuteManager(BasePlugin):
229211
name = "mute_manager"
230212
def on_chat_sent(self, data):

utility_functions.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,23 @@ def move_ship_to_coords(protocol, sector, x, y, z, planet, satellite):
5656
packets.warp_command_write(t="MOVE_SHIP", sector=sector, x=x, y=y, z=z,
5757
planet=planet,
5858
satellite=satellite, player="".encode('utf-8')))
59-
protocol.client_protocol.transport.write(warp_packet)
59+
protocol.client_protocol.transport.write(warp_packet)
60+
61+
62+
def extract_name(l):
63+
name = []
64+
if l[0][0] not in ["'", '"']:
65+
return l[0], l[1:]
66+
name.append(l[0][1:])
67+
terminator = l[0][0]
68+
for idx, s in enumerate(l[1:]):
69+
if s[-1] == terminator:
70+
name.append(s[:-1])
71+
if idx + 2 != len(l):
72+
return " ".join(name), l[idx + 2:]
73+
else:
74+
return " ".join(name), None
75+
else:
76+
name.append(s)
77+
raise ValueError("Final terminator character of <%s> not found" %
78+
terminator)

0 commit comments

Comments
 (0)