Skip to content

Commit

Permalink
Fix outdated motd_updater code
Browse files Browse the repository at this point in the history
  • Loading branch information
th3-z committed Jul 12, 2019
1 parent d186d1b commit 42c49bf
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions magicked_admin/server/motd_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import requests
from lxml import html

from utils import DEBUG, find_data_file, warning
from utils import DEBUG, find_data_file, warning, debug
from utils.text import millify, trim_string


Expand All @@ -23,7 +23,6 @@ def __init__(self, server, scoreboard_type):

with open(self.motd_path, "w+") as motd_file:
motd_file.write(self.server.web_admin.get_motd())


self.motd = self.load_motd()

Expand Down Expand Up @@ -52,17 +51,26 @@ def load_motd(self):
def render_motd(self, src_motd):
if self.scoreboard_type in ['kills', 'Kills', 'kill', 'Kill']:
scores = self.server.database.top_kills()
elif self.scoreboard_type in ['Dosh','dosh']:
scores = [
{'score': score['kills'], 'username': score['username']}
for score in scores
]
elif self.scoreboard_type in ['Dosh', 'dosh']:
scores = self.server.database.top_dosh()
scores = [
{'score': score['dosh'], 'username': score['username']}
for score in scores
]
else:
warning("Scoreboard_type not recognised '{}' for {}. Options are: dosh, kills"
.format(self.scoreboard_type, self.server.name))
return src_motd

for player in scores:
name = player[0].replace("<", "&lt;")
if not player['username']: continue
name = player['username'].replace("<", "&lt;")
name = trim_string(name, 12)
score = player[1]
score = player['score']

src_motd = src_motd.replace("%PLR", name, 1)
src_motd = src_motd.replace("%SCR", millify(score), 1)
Expand Down

0 comments on commit 42c49bf

Please sign in to comment.