Compare commits

..

2 Commits

2 changed files with 22 additions and 3 deletions

View File

@ -2,6 +2,8 @@ from django.urls import path
from . import views
urlpatterns = [
path('bot/discord', views.discord_bot, name='discord_bot'),
path('bot/discord', views.bot_discord_rank, name='bot_discord_rank'), # legacy, to remove when new bot is deployed
path('bot/discord/rank', views.bot_discord_rank, name='bot_discord_rank'), # use this
path('bot/discord/campus', views.bot_discord_campus, name='bot_discord_campus'),
path('events/<str:event_slug>', views.events_data, name='events_data'),
]

View File

@ -7,8 +7,7 @@ from django.shortcuts import get_object_or_404
# Create your views here.
def discord_bot(request):
def bot_discord_rank(request):
if request.method != 'GET':
return JsonResponse({'error':'bad request'})
@ -28,6 +27,24 @@ def discord_bot(request):
return JsonResponse(data)
def bot_discord_campus(request):
if request.method != 'GET':
return JsonResponse({'error':'bad request'})
token = request.GET.get('token')
auth_token = os.getenv('BOT_TOKEN')
if (token != auth_token or not auth_token):
return JsonResponse({'error':'not authorized'})
all_users = UserProfileInfo.objects.select_related().order_by('-score', 'last_submission_date', 'user__username')
data = {}
for user in all_users:
if user.discord_id:
data[user.discord_id] = user.campus
return JsonResponse(data)
def events_data(request, event_slug):
if request.method != 'GET':
return JsonResponse({'error':'bad request'})