Skip to content

Commit

Permalink
Merge 97d0254 into f3e8f43
Browse files Browse the repository at this point in the history
  • Loading branch information
th3-z committed Oct 6, 2019
2 parents f3e8f43 + 97d0254 commit 5553427
Show file tree
Hide file tree
Showing 18 changed files with 180 additions and 131 deletions.
8 changes: 6 additions & 2 deletions magicked_admin/chatbot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
INIT_TEMPLATE = '''
import gettext

_ = gettext.gettext

INIT_TEMPLATE = _('''
; The contents of this file will be ran in sequence on the server it is named
; after when the program starts. Lines starting with ; will be ignored. There
; is no need to prefix commands with ! in this file.
Expand All @@ -7,4 +11,4 @@
; silent
; start_wc -w 1 Welcome to wave 1
; silent
'''
''')
7 changes: 5 additions & 2 deletions magicked_admin/chatbot/chatbot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from os import path
import gettext

from chatbot import INIT_TEMPLATE
from chatbot.command_map import CommandMap
Expand All @@ -8,6 +9,8 @@
from web_admin.constants import *
from utils import warning

_ = gettext.gettext


class Chatbot(ChatListener):

Expand All @@ -16,7 +19,7 @@ def __init__(self, server, name=None):
if name:
self.name = name
else:
self.name = "Unnamed"
self.name = _("Unnamed")

self.chat = server.web_admin.chat
self.chat.add_listener(self)
Expand Down Expand Up @@ -54,7 +57,7 @@ def command_handler(self, username, args, user_flags):
self.chat.submit_message(response)

def execute_script(self, filename):
debug("Executing script: " + path.basename(filename))
debug(_("Executing script: ") + path.basename(filename))

with open(filename) as script:
for line in script:
Expand Down
90 changes: 47 additions & 43 deletions magicked_admin/chatbot/command_map.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import gettext

from chatbot.commands.event_commands import *
from chatbot.commands.info_commands import *
from chatbot.commands.player_commands import *
from chatbot.commands.server_commands import *

_ = gettext.gettext

# Internal command definitions
COMMAND_NEW_WAVE = "new_wave" # Params: wave number
COMMAND_NEW_GAME = "new_game"
Expand All @@ -22,51 +26,51 @@ def generate_map(self):

command_map = {
# Operator commands
'start_jc': CommandStartJoinCommand(self.server, scheduler),
'stop_jc': CommandStopJoinCommands(self.server, scheduler),
'start_wc': CommandStartWaveCommand(self.server, scheduler),
'stop_wc': CommandStopWaveCommands(self.server, scheduler),
'start_tc': CommandStartTimeCommand(self.server, scheduler),
'stop_tc': CommandStopTimeCommands(self.server, scheduler),
'start_trc': CommandStartTraderCommand(self.server, scheduler),
'stop_trc': CommandStopTraderCommands(self.server, scheduler),
'enforce_dosh': CommandEnforceDosh(self.server),
'say': CommandSay(self.server),
'restart': CommandRestart(self.server),
'load_map': CommandLoadMap(self.server),
'password': CommandPassword(self.server),
'silent': CommandSilent(self.server, self.chatbot),
'run': CommandRun(self.server, self.chatbot),
'length': CommandLength(self.server),
'difficulty': CommandDifficulty(self.server),
'game_mode': CommandGameMode(self.server),
'players': CommandPlayers(self.server),
'kick': CommandKick(self.server),
'ban': CommandBan(self.server),
'op': CommandOp(self.server),
'deop': CommandDeop(self.server),
'marquee': CommandMarquee(self.server, self.chatbot),
_('start_jc'): CommandStartJoinCommand(self.server, scheduler),
_('stop_jc'): CommandStopJoinCommands(self.server, scheduler),
_('start_wc'): CommandStartWaveCommand(self.server, scheduler),
_('stop_wc'): CommandStopWaveCommands(self.server, scheduler),
_('start_tc'): CommandStartTimeCommand(self.server, scheduler),
_('stop_tc'): CommandStopTimeCommands(self.server, scheduler),
_('start_trc'): CommandStartTraderCommand(self.server, scheduler),
_('stop_trc'): CommandStopTraderCommands(self.server, scheduler),
_('enforce_dosh'): CommandEnforceDosh(self.server),
_('say'): CommandSay(self.server),
_('restart'): CommandRestart(self.server),
_('load_map'): CommandLoadMap(self.server),
_('password'): CommandPassword(self.server),
_('silent'): CommandSilent(self.server, self.chatbot),
_('run'): CommandRun(self.server, self.chatbot),
_('length'): CommandLength(self.server),
_('difficulty'): CommandDifficulty(self.server),
_('game_mode'): CommandGameMode(self.server),
_('players'): CommandPlayers(self.server),
_('kick'): CommandKick(self.server),
_('ban'): CommandBan(self.server),
_('op'): CommandOp(self.server),
_('deop'): CommandDeop(self.server),
_('marquee'): CommandMarquee(self.server, self.chatbot),

# Player commands
'commands': CommandCommands(self.server),
'record_wave': CommandHighWave(self.server),
'game': CommandGame(self.server),
'kills': CommandKills(self.server),
'dosh': CommandDosh(self.server),
'top_kills': CommandTopKills(self.server),
'top_dosh': CommandTopDosh(self.server),
'top_time': CommandTopTime(self.server),
'top_wave_kills': CommandTopWaveKills(self.server),
'top_wave_dosh': CommandTopWaveDosh(self.server),
'stats': CommandStats(self.server),
'game_time': CommandGameTime(self.server),
'server_kills': CommandServerKills(self.server),
'server_dosh': CommandServerDosh(self.server),
'map': CommandGameMap(self.server),
'maps': CommandGameMaps(self.server),
'player_count': CommandPlayerCount(self.server),
'scoreboard': CommandScoreboard(self.server),
'sb': CommandScoreboard(self.server)
_('commands'): CommandCommands(self.server),
_('record_wave'): CommandHighWave(self.server),
_('game'): CommandGame(self.server),
_('kills'): CommandKills(self.server),
_('dosh'): CommandDosh(self.server),
_('top_kills'): CommandTopKills(self.server),
_('top_dosh'): CommandTopDosh(self.server),
_('top_time'): CommandTopTime(self.server),
_('top_wave_kills'): CommandTopWaveKills(self.server),
_('top_wave_dosh'): CommandTopWaveDosh(self.server),
_('stats'): CommandStats(self.server),
_('game_time'): CommandGameTime(self.server),
_('server_kills'): CommandServerKills(self.server),
_('server_dosh'): CommandServerDosh(self.server),
_('map'): CommandGameMap(self.server),
_('maps'): CommandGameMaps(self.server),
_('player_count'): CommandPlayerCount(self.server),
_('scoreboard'): CommandScoreboard(self.server),
_('sb'): CommandScoreboard(self.server)
}

return command_map
11 changes: 6 additions & 5 deletions magicked_admin/chatbot/command_scheduler.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import threading
import time
import gettext

from chatbot.commands.command import Command
from utils import warning
from web_admin.chat import ChatListener
from web_admin.constants import *

_ = gettext.gettext
ALL_WAVES = 999


Expand Down Expand Up @@ -50,11 +52,10 @@ def unschedule_commands(self, command_type):
stopped += 1

if stopped:
message = "Stopped {} command".format(stopped)
message += "s" if stopped > 1 else ""
message = _("Stopped {} command(s)").format(stopped)
return message
else:
return "None running"
return _("None running")

def receive_message(self, username, message, user_flags):
"""
Expand Down Expand Up @@ -102,8 +103,8 @@ def __init__(self, server, command, run_once=False, poll=False):

def execute(self, username, args, user_flags):
warning(
"Scheduled command ({}) ran directly by {}, please use "
"CommandScheduler".format(
_("Scheduled command ({}) ran directly by {}, please use "
"CommandScheduler").format(
" ".join(args),
username
)
Expand Down
24 changes: 13 additions & 11 deletions magicked_admin/chatbot/commands/command.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
from argparse import ArgumentError
import gettext

from chatbot.commands.argument_parser import ArgumentParser
from utils import debug, BANNER_URL
from utils.text import pad_output
from web_admin.constants import *

_ = gettext.gettext


class Command:
def __init__(self, server, admin_only=True, requires_patch=False):
self.server = server
self.admin_only = admin_only
self.requires_patch = requires_patch

not_auth_message = "You're not authorised to use that command"
not_auth_message = _("You're not authorised to use that command")
self.not_auth_message = pad_output(not_auth_message)

not_supported_message = "This action isn't supported without Killing" \
" Floor 2 Magicked Administrator's server" \
" side patch! Please review the " \
"documentation at '{}' for guidance."\
.format(BANNER_URL)
not_supported_message = _(
"This action isn't supported without Killing Floor 2 Magicked "
"Administrator's server side patch! Please review the "
"documentation at '{}' for guidance."
).format(BANNER_URL)
self.not_supported_message = pad_output(not_supported_message)

self.help_text = "The help text for this command hasn't been written!"
self.currency_symbol = "$"
# TODO: implement
self.language = "en_GB.lang"
self.help_text = _("The help text for this command hasn't been "
"written!")
self.currency_symbol = _("$")

self.parser = ArgumentParser(add_help=False)
self.parser.add_argument(
Expand All @@ -51,7 +53,7 @@ def authorise(self, username, user_flags):
authorised = (not self.admin_only) or op or internal or admin

if not authorised:
debug("Auth failure, username: {}, user flags: {:b}".format(
debug(_("Auth failure, username: {}, user flags: {:b}").format(
username, user_flags
))

Expand Down
4 changes: 3 additions & 1 deletion magicked_admin/database/database.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import sqlite3
from os import path
from threading import Lock
import gettext

from utils import find_data_file, info

_ = gettext.gettext
lock = Lock()


Expand All @@ -24,7 +26,7 @@ def __init__(self, name):
self.cur = self.conn.cursor()

def build_schema(self):
info("Building new database...")
info(_("Building new database..."))

conn = sqlite3.connect(self.sqlite_db_file)
cur = conn.cursor()
Expand Down
13 changes: 8 additions & 5 deletions magicked_admin/magicked_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
from utils import banner, die, find_data_file, info, warning
from utils.net import phone_home
from utils.text import str_to_bool
import gettext

_ = gettext.gettext

init()

parser = argparse.ArgumentParser(
description='Killing Floor 2 Magicked Administrator'
description=_('Killing Floor 2 Magicked Administrator')
)
parser.add_argument('-s', '--skip_setup', action='store_true',
help='Skips the guided setup process')
help=_('Skips the guided setup process'))
args = parser.parse_args()

banner()
Expand Down Expand Up @@ -87,7 +90,7 @@ def run(self):

Chatbot(server, settings.setting(server_name, "username"))

info("Initialisation complete!\n")
info(_("Initialisation complete!\n"))

while True:
command = input()
Expand All @@ -97,7 +100,7 @@ def run(self):
def terminate(self, signal, frame):
if self.sigint_count > 1:
print() # \n
warning("Closing immediately!")
warning(_("Closing immediately!"))
os._exit(0)
return

Expand All @@ -106,7 +109,7 @@ def terminate(self, signal, frame):
return

print() # \n
info("Program interrupted, saving data...")
info(_("Program interrupted, saving data..."))

for server in self.servers:
server.close()
Expand Down
17 changes: 12 additions & 5 deletions magicked_admin/server/game.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import web_admin as api
from web_admin.constants import *
import gettext

_ = gettext.gettext


class Game:
Expand All @@ -23,7 +26,7 @@ def __init__(self, game_map, game_type):
self.password_enabled = False

def __str__(self):
return "Mode: {}\nMap: {}\nDifficulty: {}\nWave {}/{}".format(
return _("Mode: {}\nMap: {}\nDifficulty: {}\nWave {}/{}").format(
GAME_TYPE_DISPLAY[self.game_type],
self.game_map.name,
DIFF_DISPLAY[self.difficulty],
Expand Down Expand Up @@ -63,7 +66,11 @@ def reset_stats(self):
self.votes = 0

def __str__(self):
return ("Title: {}\nPlays survival: {}\nPlays survival_vs: {}\n"
"Plays endless: {}\nPlays weekly: {}") \
.format(self.title, self.plays_survival, self.plays_survival_vs,
self.plays_endless, self.plays_weekly)
map_str = _("Title: {}\nPlays survival: {}\nPlays survival_vs: {}\n"
"Plays endless: {}\nPlays weekly: {}").format(
self.title, self.plays_survival,
self.plays_survival_vs, self.plays_endless,
self.plays_weekly
)

return map_str
10 changes: 6 additions & 4 deletions magicked_admin/server/game_tracker.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import threading
import time

import gettext
from colorama import init
from termcolor import colored

from utils import BANNER_URL, warning
from web_admin.constants import *


_ = gettext.gettext
init()


Expand Down Expand Up @@ -51,9 +53,9 @@ def __is_new_game(game_now, game_before):
if game_now.wave is None:
# Initial mode change
if game_before.game_type != game_now.game_type:
message = ("Game type ({}) support not installed, please "
"patch your webadmin to correct this! Guidance is "
"available at: {}")
message = (_("Game type ({}) support not installed, please "
"patch your webadmin to correct this! Guidance is"
" available at: {}"))
warning(message.format(
game_now.game_type, colored(BANNER_URL, 'magenta')
))
Expand Down
Loading

0 comments on commit 5553427

Please sign in to comment.