Add support for server MOTDs

This commit is contained in:
Trever Fischer
2012-02-27 11:53:06 -05:00
parent a45a3845da
commit aa15f4d797
4 changed files with 38 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
from piston.handler import AnonymousBaseHandler
from profiles.models import MinecraftProfile
from profiles.models import MinecraftProfile, Quote
from minecraft.models import MOTD
from django.http import HttpResponse
class WhitelistHandler(AnonymousBaseHandler):
@@ -14,3 +15,16 @@ class WhitelistHandler(AnonymousBaseHandler):
if profile.user.is_active:
return HttpResponse(status=204)
return HttpResponse(status=404)
class MOTDHandler(AnonymousBaseHandler):
allowed_methods = ('GET',)
def read(self, request, username):
motd = "No MOTD configured!"
motdList = MOTD.objects.all()
if len(motdList) > 0:
motd = motdList[0].text
quote = Quote.objects.order_by('?')
if len(quote) > 0:
motd += "\n"+quote.text
return {"motd":motd.split('\n')}