Skip to content

Commit

Permalink
Add admin_only kwarg
Browse files Browse the repository at this point in the history
  • Loading branch information
godwhoa committed Dec 11, 2017
1 parent 3e7ef41 commit 168c185
Show file tree
Hide file tree
Showing 26 changed files with 105 additions and 169 deletions.
139 changes: 48 additions & 91 deletions piqueserver/commands.py

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions piqueserver/scripts/afk.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def afk(connection, player):
elapsed = prettify_timespan(reactor.seconds() - player.last_activity, True)
return S_AFK_CHECK.format(player=player.name, time=elapsed)

@admin
@command('kickafk')
@command('kickafk', admin_only=True)
def kick_afk(connection, minutes, amount=None):
protocol = connection.protocol
minutes = int(minutes)
Expand Down
3 changes: 1 addition & 2 deletions piqueserver/scripts/aimbot2.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ def accuracy_player(player, name_info=True):
rifle_percent, smg_percent, shotgun_percent)
return s

@admin
@command()
@command(admin_only=True)
def hackinfo(connection, name):
player = get_player(connection.protocol, name)
return hackinfo_player(player)
Expand Down
3 changes: 1 addition & 2 deletions piqueserver/scripts/airstrike2.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def airstrike(connection, *args):
remaining=kills_left)

# debug
@admin
@command('givestrike')
@command('givestrike', admin_only=True)
def give_strike(connection, player=None):
protocol = connection.protocol
if player is not None:
Expand Down
3 changes: 1 addition & 2 deletions piqueserver/scripts/arena.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@
MAX_ROUND_TIME_TEXT = str(MAX_ROUND_TIME) + ' seconds'


@admin
@command()
@command(admin_only=True)
def coord(connection):
connection.get_coord = True
return 'Spade a block to get its coordinate.'
Expand Down
6 changes: 2 additions & 4 deletions piqueserver/scripts/badmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,15 @@ def aimbot_match(player, msg):
return (not aimbot_pattern.match(msg) is None)


@admin
@command()
@command(admin_only=True)
def badmin(connection, var=None):
if var == None:
return ("@Badmin (r%s): Language Filter(LF) [%s], Blank Votekick Blocker(BV) "
"[%s], Grief Votekick Protection(GV) [%s], Aimbot Votekick Protection(AV) [%s]"
% (BADMIN_VERSION, LANGUAGE_FILTER_ENABLED, BLANK_VOTEKICK_ENABLED,
SCORE_GRIEF_ENABLED, SCORE_AIMBOT_ENABLED))

@admin
@command()
@command(admin_only=True)
def investigate(connection, player):
player = get_player(connection.protocol, player)
score = score_grief(connection, player)
Expand Down
3 changes: 1 addition & 2 deletions piqueserver/scripts/daycycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
S_SPEED_SET = 'Day cycle speed changed to {multiplier}'
S_STOPPED = 'Day cycle stopped'

@admin
@command('dayspeed')
@command('dayspeed', admin_only=True)
def day_speed(connection, value=None):
if value is None:
return S_SPEED.format(multiplier=connection.protocol.time_multiplier)
Expand Down
3 changes: 1 addition & 2 deletions piqueserver/scripts/demolitionman.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
DEMOLITION_ENABLED_AT_ROUND_START = False


@admin
@command()
@command(admin_only=True)
def toggledemo(connection):
connection.protocol.demolitionEnabled = not connection.protocol.demolitionEnabled
message = 'Demolition is now disabled'
Expand Down
3 changes: 1 addition & 2 deletions piqueserver/scripts/disco.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
# Time is in seconds
DISCO_ON_GAME_END_DURATION = 10.0

@admin
@command('disco')
@command('disco', admin_only=True)
def toggle_disco(connection):
connection.protocol.toggle_disco(True)

Expand Down
3 changes: 1 addition & 2 deletions piqueserver/scripts/grownade.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ def load_models(expression):
failed.append(filename)
return models, loaded, failed

@admin
@command('model')
@command('model', admin_only=True)
def model_grenades(connection, expression=None):
protocol = connection.protocol
if connection not in protocol.players:
Expand Down
3 changes: 1 addition & 2 deletions piqueserver/scripts/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ def clear(connection):
return S_CLEARED


@admin
@command('togglemarkers')
@command('togglemarkers', admin_only=True)
def toggle_markers(connection, player=None):
protocol = connection.protocol
if player is not None:
Expand Down
15 changes: 5 additions & 10 deletions piqueserver/scripts/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,29 @@
from piqueserver.commands import command, admin


@admin
@command('timer')
@command('timer', admin_only=True)
def start_timer(connection, end):
return connection.protocol.start_timer(int(end) * 60)


@admin
@command('stoptimer')
@command('stoptimer', admin_only=True)
def stop_timer(connection, end):
return connection.protocol.stop_timer()


@admin
@command('startrecord')
@command('startrecord', admin_only=True)
def start_record(connection):
connection.protocol.start_record()
return 'Recording started.'


@admin
@command('stoprecord')
@command('stoprecord', admin_only=True)
def stop_record(connection):
connection.protocol.stop_record()
return 'Recording stopped.'


@admin
@command('saverecord')
@command('saverecord', admin_only=True)
def save_record(connection, value):
if not connection.protocol.save_record(value):
return 'No record file available.'
Expand Down
3 changes: 1 addition & 2 deletions piqueserver/scripts/minefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ def parseField(ext):
return None


@admin
@command()
@command(admin_only=True)
def minedebug(connection):
proto = connection.protocol
proto.minefield_debug = not proto.minefield_debug
Expand Down
3 changes: 1 addition & 2 deletions piqueserver/scripts/nospadingwalls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from pyspades.server import *
from piqueserver.commands import command

@admin
@command('togglewallspading','tws')
@command('togglewallspading','tws', admin_only=True)
def togglewallspading(self):
self.protocol.is_fluffy = not self.protocol.is_fluffy
if not self.protocol.is_fluffy:
Expand Down
3 changes: 1 addition & 2 deletions piqueserver/scripts/paint.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

PAINT_RAY_LENGTH = 32.0

@admin
@command()
@command(admin_only=True)
def paint(connection, player=None):
protocol = connection.protocol
if player is not None:
Expand Down
3 changes: 1 addition & 2 deletions piqueserver/scripts/passreload.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import os.path


@admin
@command()
@command(admin_only=True)
def reloadconfig(connection):
new_config = {}
try:
Expand Down
18 changes: 6 additions & 12 deletions piqueserver/scripts/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,24 +363,21 @@ def flatten(iterables):
return chain.from_iterable(iterables)


@admin
@command()
@command(admin_only=True)
def save(connection):
connection.protocol.dump_platform_json()
return S_SAVED


@admin
@command()
@command(admin_only=True)
def reach(connection):
if connection not in connection.protocol.players:
raise ValueError()
long = connection.reach == ACTION_RAY_LENGTH_LONG
connection.reach = ACTION_RAY_LENGTH if long else ACTION_RAY_LENGTH_LONG
return S_REACH if not long else S_NO_REACH

@admin
@command('platform', 'p')
@command('platform', 'p', admin_only=True)
def platform_command(connection, *args):
protocol = connection.protocol
if connection not in protocol.players:
Expand Down Expand Up @@ -440,8 +437,7 @@ def platform_command(connection, *args):
player.states.exit()
player.states.enter(NewPlatformState())

@admin
@command('button', 'b')
@command('button', 'b', admin_only=True)
def button_command(connection, *args):
protocol = connection.protocol
if connection not in protocol.players:
Expand Down Expand Up @@ -505,8 +501,7 @@ def button_command(connection, *args):
player.states.exit()
player.states.enter(NewButtonState())

@admin
@command('action', 'ac')
@command('action', 'ac', admin_only=True)
def action_command(connection, *args):
protocol = connection.protocol
if connection not in protocol.players:
Expand Down Expand Up @@ -624,8 +619,7 @@ def action_command(connection, *args):
except IndexError:
return usage

@admin
@command('trigger', 't')
@command('trigger', 't', admin_only=True)
def trigger_command(connection, *args):
protocol = connection.protocol
if connection not in protocol.players:
Expand Down
3 changes: 1 addition & 2 deletions piqueserver/scripts/protect.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from pyspades.common import coordinates


@admin
@command()
@command(admin_only=True)
def protect(connection, value=None):
protocol = connection.protocol
if value is None:
Expand Down
6 changes: 2 additions & 4 deletions piqueserver/scripts/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,12 @@ def reset_intel(protocol, team):
protocol.send_chat("The %s intel has been reset." % team.name)


@admin
@command()
@command(admin_only=True)
def resetblueintel(connection):
reset_intel(connection.protocol, connection.protocol.blue_team)


@admin
@command()
@command(admin_only=True)
def resetgreenintel(connection):
reset_intel(connection.protocol, connection.protocol.green_team)

Expand Down
3 changes: 1 addition & 2 deletions piqueserver/scripts/rapid.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
RAPID_INTERVAL = 0.08
RAPID_BLOCK_DELAY = 0.26

@admin
@command('rapid')
@command('rapid', admin_only=True)
def toggle_rapid(connection, player=None):
protocol = connection.protocol
if player is not None:
Expand Down
9 changes: 3 additions & 6 deletions piqueserver/scripts/rollback.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@

NON_SURFACE_COLOR = (0, 0, 0)

@admin
@command()
@command(admin_only=True)
def rollmap(connection, mapname=None, value=None):
start_x, start_y, end_x, end_y = 0, 0, 512, 512
if value is not None:
Expand All @@ -38,13 +37,11 @@ def rollmap(connection, mapname=None, value=None):
return connection.protocol.start_rollback(connection, mapname,
start_x, start_y, end_x, end_y)

@admin
@command()
@command(admin_only=True)
def rollback(connection, value=None):
return rollmap(connection, value=value)

@admin
@command()
@command(admin_only=True)
def rollbackcancel(connection):
return connection.protocol.cancel_rollback(connection)

Expand Down
9 changes: 3 additions & 6 deletions piqueserver/scripts/runningman.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
S_FLAG_CAPTURED = 'The intel capture has unlinked everyone in the {team} team!'


@admin
@command('runningman')
@command('runningman', admin_only=True)
def running_man(connection):
protocol = connection.protocol
protocol.running_man = not protocol.running_man
Expand All @@ -54,17 +53,15 @@ def running_man(connection):
protocol.send_chat(message, irc=True)


@admin
@command()
@command(admin_only=True)
def relink(connection):
if not connection.protocol.running_man:
return S_NOT_ENABLED
connection.protocol.drop_all_links()
connection.protocol.send_chat(S_UNLINK_ALL, irc=True)


@admin
@command()
@command(admin_only=True)
def unlink(connection, player=None):
protocol = connection.protocol
if not protocol.running_man:
Expand Down
3 changes: 1 addition & 2 deletions piqueserver/scripts/timedmute.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from scheduler import Scheduler
from piqueserver.commands import command, admin, get_player, join_arguments

@admin
@command('tm')
@command('tm', admin_only=True)
def timed_mute(connection, *args):
protocol = connection.protocol

Expand Down
3 changes: 1 addition & 2 deletions piqueserver/scripts/trusted.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
S_CANT_VOTEKICK = "{player} is trusted and can't be votekicked"
S_RESULT_TRUSTED = 'Trusted user'

@admin
@command()
@command(admin_only=True)
def trust(connection, player):
player = get_player(connection.protocol, player)
player.on_user_login('trusted', False)
Expand Down
3 changes: 1 addition & 2 deletions piqueserver/scripts/votekick.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ def vote_yes(connection):
votekick.vote(player)


@command('tvk')
@admin
@command('tvk', admin_only=True)
def togglevotekick(connection, *args):
protocol = connection.protocol
if len(args) == 0:
Expand Down
18 changes: 18 additions & 0 deletions tests/piqueserver/test_commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from piqueserver.commands import command
import unittest


class TestCommandDecorator(unittest.TestCase):
def test_admin_only(self):
@command(admin_only=True)
def test():
pass
want = set()
want.add('admin')
self.assertEqual(test.user_types, want)

def test_command_name(self):
@command()
def test():
pass
self.assertEqual(test.command_name, 'test')

0 comments on commit 168c185

Please sign in to comment.