Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mrogaski committed Aug 13, 2016
2 parents 43ffecd + 84dd344 commit 4cc6b33
Show file tree
Hide file tree
Showing 19 changed files with 844 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ coverage.xml
# Django stuff:
*.log
local_settings.py
pep8.txt

# Flask stuff:
instance/
Expand Down Expand Up @@ -87,3 +88,7 @@ ENV/

# Rope project settings
.ropeproject

# PyDev
.project
.pydevproject
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: python
python:
- "2.7"
- "3.4"
- "3.5"
env:
- DJANGO=1.9
- DJANGO=1.10
install:
- pip install -q Django==$DJANGO --use-mirrors
- pip install -q -e . --use-mirrors
script:
- python setup.py test
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include LICENSE
include README.rst
recursive-include docs *
2 changes: 0 additions & 2 deletions README.md

This file was deleted.

37 changes: 37 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
===================
django-discord-bind
===================

This is a simple Django app that allows users to bind their Discord accounts
to their Django accounts and join a partner Discord server using the OAuth2
functionality of the Discord API.

Quick start
-----------

1. Add "discord_bind" to your INSTALLED_APPS setting like this::

INSTALLED_APPS = [
...
'discord_bind',
]

2. Include the polls URLconf in your project urls.py like this::

url(r'^discord/', include('discord_bind.urls')),

3. Run `python manage.py migrate` to create the discord_bind models.

4. Start the development server and visit http://127.0.0.1:8000/admin/
to add a Discord invite code (you'll need the Admin app enabled).

5. Visit https://discordapp.com/developers/applications/me to create
an application. Add http://127.0.0.1:8000/discord/cb as a redirect URI.

6. Add the Client ID and Secret values to the project settings.py file::

DISCORD_CLIENT_ID = 212763200357720576
DISCORD_CLIENT_SECRET = MfpBbcX2Ga3boNhoQoBTdHNUS2B1xX8f

5. Visit http://127.0.0.1:8000/discord/ to bind your Discord account and
auto-accept the invite code.
26 changes: 26 additions & 0 deletions discord_bind/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
The MIT License (MIT)
Copyright (c) 2016, Mark Rogaski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
default_app_config = 'discord_bind.apps.DiscordBindConfig'
107 changes: 107 additions & 0 deletions discord_bind/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
"""
The MIT License (MIT)
Copyright (c) 2016, Mark Rogaski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
import requests

from django.contrib import admin
from .models import DiscordUser, DiscordInvite

from discord_bind.app_settings import BASE_URI

@admin.register(DiscordUser)
class DiscordUserAdmin(admin.ModelAdmin):
list_display = ('user',
'uid',
'username',
'discriminator',
'email')
list_display_links = ('uid',)
fieldsets = (
(None, {
'fields': ('user',),
}),
('Discord Account', {
'fields': ('uid', ('username', 'discriminator'), 'email', 'avatar'),
}),
('OAuth2', {
'classes': ('collapse',),
'fields': ('access_token', 'refresh_token', 'scope', 'expiry'),
}),
)
readonly_fields = ('user',
'uid',
'access_token',
'refresh_token',
'scope',
'expiry')
search_fields = ['user__username',
'user__email',
'username',
'discriminator',
'uid',
'email']

@admin.register(DiscordInvite)
class DiscordInviteAdmin(admin.ModelAdmin):
list_display = ('code',
'active',
'description',
'guild_name',
'channel_name',
'channel_type')
list_display_links = ('code',)
fieldsets = (
(None, {
'fields': (('code', 'active'), 'description', 'groups'),
}),
('Discord Guild', {
'fields': ('guild_name', 'guild_id', 'guild_icon'),
}),
('Discord Channel', {
'fields': ('channel_name', 'channel_id', 'channel_type'),
}),
)
readonly_fields = ('guild_name',
'guild_id',
'guild_icon',
'channel_name',
'channel_id',
'channel_type')
filter_horizontal = ('groups',)
actions = ['update_context']

def update_context(self, request, queryset):
""" Pull invite details from Discord """
update = 0
delete = 0
invites = queryset.all()
for invite in invites:
if invite.update_context():
update += 1
else:
invite.delete()
delete += 1
self.message_user(request, '%d updated, %d deleted' % (update, delete))
update_context.short_description = 'Update invite context'
51 changes: 51 additions & 0 deletions discord_bind/app_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""
The MIT License (MIT)
Copyright (c) 2016, Mark Rogaski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
from __future__ import unicode_literals

from django.conf import settings


# API service endpoints
BASE_URI = getattr(settings, 'DISCORD_BASE_URI',
'https://discordapp.com/api')
AUTHZ_URI = getattr(settings, 'DISCORD_AUTHZ_URI',
BASE_URI + '/oauth2/authorize')
TOKEN_URI = getattr(settings, 'DISCORD_TOKEN_URI',
BASE_URI + '/oauth2/token')

# OAuth2 application credentials
CLIENT_ID = getattr(settings, 'DISCORD_CLIENT_ID', '')
CLIENT_SECRET = getattr(settings, 'DISCORD_CLIENT_SECRET', '')

# OAuth2 scope
AUTHZ_SCOPE = (
['email', 'guilds.join'] if getattr(settings, 'DISCORD_EMAIL_SCOPE', True)
else ['identity', 'guilds.join'])

# Return URI
INVITE_URI = getattr(settings, 'DISCORD_INVITE_URI',
'https://discordapp.com/channels/@me')
RETURN_URI = getattr(settings, 'DISCORD_RETURN_URI', '/')
30 changes: 30 additions & 0 deletions discord_bind/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
The MIT License (MIT)
Copyright (c) 2016, Mark Rogaski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
from django.apps import AppConfig


class DiscordBindConfig(AppConfig):
name = 'discord_bind'
52 changes: 52 additions & 0 deletions discord_bind/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-08-12 04:43
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('auth', '0008_alter_user_username_max_length'),
]

operations = [
migrations.CreateModel(
name='DiscordInvite',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.CharField(max_length=32, unique=True)),
('active', models.BooleanField(default=False)),
('description', models.CharField(blank=True, max_length=256)),
('guild_name', models.CharField(blank=True, max_length=64)),
('guild_id', models.CharField(blank=True, max_length=20)),
('guild_icon', models.CharField(blank=True, max_length=32)),
('channel_name', models.CharField(blank=True, max_length=64)),
('channel_id', models.CharField(blank=True, max_length=20)),
('channel_type', models.CharField(blank=True, choices=[('text', 'text'), ('voice', 'voice')], max_length=5)),
('groups', models.ManyToManyField(blank=True, related_name='discord_invites', to='auth.Group')),
],
),
migrations.CreateModel(
name='DiscordUser',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('uid', models.CharField(max_length=20, unique=True)),
('username', models.CharField(max_length=254)),
('discriminator', models.CharField(max_length=4)),
('avatar', models.CharField(blank=True, max_length=32)),
('email', models.EmailField(blank=True, max_length=254)),
('access_token', models.CharField(blank=True, max_length=32)),
('refresh_token', models.CharField(blank=True, max_length=32)),
('scope', models.CharField(blank=True, max_length=256)),
('expiry', models.DateTimeField(null=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
Empty file.
Loading

0 comments on commit 4cc6b33

Please sign in to comment.