Skip to content

Commit

Permalink
Merge d17907a into 0817f80
Browse files Browse the repository at this point in the history
  • Loading branch information
th3-z committed Sep 27, 2019
2 parents 0817f80 + d17907a commit 7d8ab9a
Show file tree
Hide file tree
Showing 10 changed files with 276 additions and 106 deletions.
57 changes: 36 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ Many commands will look for closest matches to their parameters.
For example '_biotics_' will match '_kf-biotics-lab_' and '_userO_' will match
'_userOne™/@:®_'.

All commands have in-game help text that can be accessed with the `-h` parameter.
All commands have in-game help text that can be accessed with the `-h` flag.

* Example: `!commands -h`

All commands also have the following flags.

* `-q` - Suppresses output
* `-p` - Pads output to hide the username line

Escape sequences as follows are available to format messages.

* `\n` - Newline
Expand Down Expand Up @@ -128,27 +133,33 @@ the `!op` command.
- Available tokens: `%PLR` - username, `%KLL%` - total kills, `%DSH%` -
total dosh
* `!stop_jc` - Stops all join commands
* `!start_wc [wave] <command>` - Start a command that runs on wave `[wave]`
- `[wave`] Can be omitted to have the command run every wave
- `[wave`] Can be negative to count backwards from the boss wave
* `!start_wc [-w <wave>] <command>` - Start a command that runs on wave `<wave>`
- `-w` Wave to run the command on, can be omitted to have the command
run every wave
- `-w` Can be negative to count backwards from the boss wave
- Example: `!start_wc -1 say Welcome to the boss wave`
* `!stop_wc` - Stops all wave commands
* `!start_tc <seconds> <command>` - Start a command that runs every
`<seconds>` seconds
- Example: `!start_tc 600 say Join our Steam group!\n
* `!start_tc [-r, -t <seconds>] <command>` - Start a command that runs after
`<seconds>` seconds
- Option `-r`: Add to have the command run repeatedly
- Option `-t`: Required, the number of seconds before the command runs
- Example: `!start_tc -rt 600 say Join our Steam group!\n
http://steam.group/`
* `!stop_tc` - Stops all timed commands
* `!start_trc <command>` - Start a commands that runs when the trader opens
* `!start_trc [-w <wave>] <command>` - Start a commands that runs when the trader opens
- `-w` Wave to run the command on, can be omitted to have the command
run every wave
- `-w` Can be negative to count backwards from the boss wave
- Example: `!start_trc top_wave_dosh` - Shows who earned the most dosh
this wave when the trader opens
every wave when the trader opens
* `!stop_trc` - Stop all commands that run on trader open
* `!silent` - Toggles suppression of all chat output, commands still have
effect, but the response will not be visible to players
* `!run <script_name>` - Executes a script from the `scripts` folder, more
* `!run <script_name>` - Executes a script from the `conf/scripts` folder, more
information in the scripts section
- Example: `!run example`
* `!marquee <marquee_name>` - Runs a marquee in the chat from the `marquee`
folder, _experimental_
* `!marquee <marquee_name>` - Runs a marquee in the chat from the
`conf/marquee` folder, _experimental_
- Example: `!marquee example`
* `!enforce_dosh` - Kicks all players that have more dosh than the
`dosh_threshold` configuration option
Expand All @@ -157,9 +168,9 @@ the `!op` command.

### MOTD leaderboard

Writing a `server_name.motd` file containing pairs of `%PLR` and `%SCR` and
enabling the `motd_scoreboard` option will put a live leaderboard in the motd
and update it every 5 minutes.
Writing a `conf/server_name.motd` file containing pairs of `%PLR` and `%SCR`
and enabling the `motd_scoreboard` option will put a live leaderboard in the
motd and update it every 5 minutes.

`%SRV_D` and `%SRV_K` will be replaced by the total dosh and kills on the
server respectively.
Expand All @@ -169,10 +180,10 @@ metric on the leaderboard. The options for this are: `dosh` or `kills`.

### Scripts

Writting a `server_name.init` in the root folder with a series of commands
Writting a `server_name.init` in the `conf` folder with a series of commands
will run the commands in sequence when the bot starts on `server_name`.

Additional scripts can be written in the `scripts` folder and ran with the
Additional scripts can be written in the `conf/scripts` folder and ran with the
`!run` command. There is an example already in there that can be ran with
`!run example`.

Expand All @@ -194,7 +205,7 @@ Configuration options
---------------------

Basic setup is done on the first run. However this does not cover all of the
options KF2-MA can offer. Please see the config file, `magicked_admin.conf`,
options KF2-MA can offer. Please see the config file, `conf/magicked_admin.conf`,
for more configuration options as some features are disabled by default.

Each server managed by KF2-MA has a section that looks something like
Expand All @@ -204,7 +215,7 @@ is the name of the server, this can be changed to whatever you want.

### Options

Options can be configured in the config file `magicked_admin.conf`.
Options can be configured in the config file `conf/magicked_admin.conf`.

* `address`
- Web address of the server's webadmin panel. Requires scheme and protocol,
Expand Down Expand Up @@ -236,9 +247,13 @@ Running with docker is easy. Just issue this command:
```
docker run -it -p 1880:1880 --name kf-magicked-admin -v '<host config folder location>':'/magicked_admin/conf' th3-z/kf-magicked-admin
```
You will need to change `<host config folder location>` to wheverever you want to store your config folder. `/mnt/user/appdata/kf-magicked-admin` is a popular choice for systems running Unraid.
You will need to change `<host config folder location>` to wheverever you want
to store your config folder. `/mnt/user/appdata/kf-magicked-admin` is a popular
choice for systems running Unraid.

After this command runs the container will exit out and the logs will tell you to setup the config file. Go to your `conf` folder and set things up then run the container again and you are good to go!
After this command runs the container will exit out and the logs will tell you
to setup the config file. Go to your `conf` folder and set things up then run
the container again and you are good to go!

Running from Python sources
---------------------------
Expand Down
3 changes: 2 additions & 1 deletion magicked_admin/chatbot/command_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def generate_map(self):
'server_dosh': CommandServerDosh(self.server),
'map': CommandGameMap(self.server),
'maps': CommandGameMaps(self.server),
'player_count': CommandPlayerCount(self.server)
'player_count': CommandPlayerCount(self.server),
'scoreboard': CommandScoreboard(self.server)
}

return command_map
23 changes: 14 additions & 9 deletions magicked_admin/chatbot/command_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def event_check(self, server, message):
return True

new_wave = message[1]
if wave or int(new_wave) == wave:
if int(new_wave) == wave:
return True

return False
Expand Down Expand Up @@ -200,21 +200,26 @@ def resolve_command(self, internal_message):


class CommandOnTrader(ScheduledCommand):
def __init__(self, server, command, on_close=False):
def __init__(self, server, command, wave=ALL_WAVES):
ScheduledCommand.__init__(self, server, command)

# TODO: Implemented but un-used
self.on_close = on_close
self.wave = wave

def event_check(self, server, message):
if not message:
return False

args = message.split()

if args[0] == "t_open" and not self.on_close:
return True
elif args[0] == "t_close" and self.on_close:
return True
# Translate negative input to positive, '-1' runs on boss wave
length = server.game.length
wave = (length + 1) + (self.wave + 1) if self.wave < 0 else self.wave

return False
if args[0] == "t_open":

new_wave = int(args[1])
if self.wave != ALL_WAVES and new_wave != wave:
return False
return True
else:
return False
65 changes: 51 additions & 14 deletions magicked_admin/chatbot/commands/event_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ def __init__(self, server, scheduler):
Command.__init__(self, server, admin_only=True, requires_patch=False)
self.scheduler = scheduler

self.help_text = "start_jc help"
self.help_text = "Usage: !start_jc COMMAND\n" \
"\tCOMMAND - Command to run\n" \
"Desc: Runs a command when a player joins the match"
self.parser.add_argument("command", nargs="*")

def execute(self, username, args, user_flags):
Expand All @@ -34,7 +36,8 @@ def __init__(self, server, scheduler):
Command.__init__(self, server, admin_only=True, requires_patch=False)
self.scheduler = scheduler

self.help_text = "stop_jc help"
self.help_text = "Usage: !stop_jc\n" \
"Desc: Stops all join commands"

def execute(self, username, args, user_flags):
args, err = self.parse_args(username, args, user_flags)
Expand All @@ -54,8 +57,12 @@ def __init__(self, server, scheduler):
Command.__init__(self, server, admin_only=True, requires_patch=False)
self.scheduler = scheduler

self.help_text = "start_wc help"
self.parser.add_argument("--wave", "-w", type=int)
self.help_text = "Usage: !start_wc [--wave] COMMAND\n" \
"\t-w --wave - Optional, wave to run on\n" \
"\tCOMMAND - Command to run\n" \
"Desc: Run a command at the start of a wave, wave" \
" can be omitted top run on every wave"
self.parser.add_argument("--wave", "-w")
self.parser.add_argument("command", nargs="*")

def execute(self, username, args, user_flags):
Expand Down Expand Up @@ -93,7 +100,8 @@ def __init__(self, server, scheduler):
Command.__init__(self, server, admin_only=True, requires_patch=False)
self.scheduler = scheduler

self.help_text = "stop_wc help"
self.help_text = "Usage: !stop_wc\n" \
"Desc: Stops all wave commands"

def execute(self, username, args, user_flags):
args, err = self.parse_args(username, args, user_flags)
Expand All @@ -113,8 +121,13 @@ def __init__(self, server, scheduler):
Command.__init__(self, server, admin_only=True, requires_patch=False)
self.scheduler = scheduler

self.help_text = "start_tc help"
self.parser.add_argument("interval")
self.help_text = "Usage: !start_tc [-r -t] COMMAND\n" \
"\tCOMMAND - Command to run\n" \
"\t-r --repeat - Optional, run repeatedly\n" \
"\t-t --time - Seconds before running\n" \
"Desc: Runs a command after some time delay"
self.parser.add_argument("--time", "-t")
self.parser.add_argument("--repeat", "-r", action="store_true")
self.parser.add_argument("command", nargs="*")

def execute(self, username, args, user_flags):
Expand All @@ -124,11 +137,17 @@ def execute(self, username, args, user_flags):
elif args.help:
return self.format_response(self.help_text, args)

if not args.time:
return self.format_response(
"Please specify a time interval, '!start_tc -h' for help",
args
)

try:
interval = float(args.interval)
interval = float(args.time)
except ValueError:
return self.format_response(
"'{}' is not a valid time interval".format(args.interval),
"'{}' is not a valid time interval".format(args.time),
args
)

Expand All @@ -137,8 +156,10 @@ def execute(self, username, args, user_flags):
"Please specify a command to run", args
)

run_once = False if args.repeat else True

command = CommandOnTime(
self.server, " ".join(args.command), interval
self.server, " ".join(args.command), interval, run_once=run_once
)
self.scheduler.schedule_command(command)
return self.format_response("Time interval command started", args)
Expand All @@ -149,7 +170,8 @@ def __init__(self, server, scheduler):
Command.__init__(self, server, admin_only=True, requires_patch=False)
self.scheduler = scheduler

self.help_text = "stop_tc help"
self.help_text = "Usage: !stop_tc\n" \
"Desc: Stops all timed commands"

def execute(self, username, args, user_flags):
args, err = self.parse_args(username, args, user_flags)
Expand All @@ -169,7 +191,12 @@ def __init__(self, server, scheduler):
Command.__init__(self, server, admin_only=True, requires_patch=False)
self.scheduler = scheduler

self.help_text = "start_tc help"
self.help_text = "Usage: !start_trc [--wave] COMMAND\n" \
"\tCOMMAND - Command to run\n" \
"\t-w --wave - Optional, wave to run on\n" \
"Desc: Runs a command when the trader opens, wave" \
" can be omitted to run every time the trader opens"
self.parser.add_argument("--wave", "-w")
self.parser.add_argument("command", nargs="*")

def execute(self, username, args, user_flags):
Expand All @@ -184,8 +211,17 @@ def execute(self, username, args, user_flags):
"Please specify a command to run", args
)

wave = args.wave if args.wave else ALL_WAVES
try:
wave = int(wave)
except ValueError:
return self.format_response(
"'{}' is not a valid wave number".format(args.wave),
args
)

command = CommandOnTrader(
self.server, " ".join(args.command)
self.server, " ".join(args.command), wave=wave
)
self.scheduler.schedule_command(command)
return self.format_response("Trader open command started", args)
Expand All @@ -196,7 +232,8 @@ def __init__(self, server, scheduler):
Command.__init__(self, server, admin_only=True, requires_patch=False)
self.scheduler = scheduler

self.help_text = "stop_wc help"
self.help_text = "Usage: !stop_trc\n" \
"Desc: Stops all trader commands"

def execute(self, username, args, user_flags):
args, err = self.parse_args(username, args, user_flags)
Expand Down
Loading

0 comments on commit 7d8ab9a

Please sign in to comment.