Sfoglia il codice sorgente

begin to integrate webgui

Double-Vee 3 anni fa
parent
commit
0ad043b788

+ 6 - 1
.gitignore

@@ -1,11 +1,16 @@
 # Virtual environment
 /bin/
 /lib/
+/share/
 /lib64
 /pyvenv.cfg
 
 # Python
 __pycache__/
 
+# Django
+db.sqlite3
+**/migrations/*.py
+
 # Configuration
-local_settings.py
+local_settings.py

+ 13 - 8
README.md

@@ -2,13 +2,18 @@
 A Discord robot for the Angels Discord written in Python.
 
 ## Requirements
-1. Clone the git repository
-1. Change into the repo directory
-1. `virtualenv --python=python3 .` || `python3 -m venv .`
-1. `source bin/activate`
-1. `pip3 install -r requirements.txt`
+* Python3
+* PostgreSQL
+* Web server gateway interface like uWSGI or Gunicorn
+
+## Installation
+1. Clone the git repository: `git clone ` ...
+1. Change into the repo directory: `cd ` ...
+1. Create virtual environment: `python3 -m venv .`
+1. Activate virutal environment: `source bin/activate`
+1. Install required packages: `pip3 install -r requirements.txt`
 
 ## Run
-1. Change into the repo directory
-1. `source bin/activate`
-1. `python3 rotbot.py`
+1. Activate virutal environment: `source bin/activate`
+1. Change into the bot directory: `cd bot`
+1. `python rotbot.py`

+ 2 - 5
bot/events/general.py

@@ -1,4 +1,4 @@
-import discord, asyncpg, random
+import logging, discord, asyncpg, random
 from discord.ext import commands
 from query.guild import update_guild
 
@@ -14,10 +14,7 @@ class General(commands.Cog):
 
 	@commands.Cog.listener()
 	async def on_ready(self):
-		print('Logged in as')
-		print(self.bot.user.name)
-		print(self.bot.user.id)
-		print('------')
+		logging.info("Logged in as %s - %i", self.bot.user.name, self.bot.user.id)
 
 	@commands.Cog.listener()
 	async def on_guild_join(self, guild: discord.Guild):

+ 1 - 1
bot/local_settings_example.py

@@ -5,7 +5,7 @@ LOG_LEVEL = logging.INFO	# Options: CRITICAL, ERROR, WARNING, INFO, and DEBUG
 
 DATABASE_NAME = ""
 DATABASE_USER = ""
-DATABASE_HOST = ""
+DATABASE_HOST = "127.0.0.1"
 DATABASE_PASSWORD = ""
 
 DISCORD_TOKEN = ""

+ 1 - 0
requirements.txt

@@ -1,2 +1,3 @@
 discord.py==1.7.3
 asyncpg==0.26.0
+Django==4.1

+ 0 - 0
webgui/config/__init__.py


+ 3 - 0
webgui/config/admin.py

@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.

+ 6 - 0
webgui/config/apps.py

@@ -0,0 +1,6 @@
+from django.apps import AppConfig
+
+
+class ConfigConfig(AppConfig):
+    default_auto_field = 'django.db.models.BigAutoField'
+    name = 'config'

+ 13 - 0
webgui/config/models.py

@@ -0,0 +1,13 @@
+from django.db import models
+
+# Create your models here.
+class ChannelSettings(models.Model):
+    # channel = models.AutoField(
+    #     #max_length = 11,   # 'max_length' is ignored when used with AutoField.
+    #     primary_key = True,
+    # )
+
+    class Meta:
+        managed = False
+        db_table = "channel_settings"
+        #verbose_name_plural = "accounts"

+ 3 - 0
webgui/config/tests.py

@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.

+ 3 - 0
webgui/config/views.py

@@ -0,0 +1,3 @@
+from django.shortcuts import render
+
+# Create your views here.

+ 22 - 0
webgui/manage.py

@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+"""Django's command-line utility for administrative tasks."""
+import os
+import sys
+
+
+def main():
+    """Run administrative tasks."""
+    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'webgui.settings')
+    try:
+        from django.core.management import execute_from_command_line
+    except ImportError as exc:
+        raise ImportError(
+            "Couldn't import Django. Are you sure it's installed and "
+            "available on your PYTHONPATH environment variable? Did you "
+            "forget to activate a virtual environment?"
+        ) from exc
+    execute_from_command_line(sys.argv)
+
+
+if __name__ == '__main__':
+    main()

+ 0 - 0
webgui/webgui/__init__.py


+ 16 - 0
webgui/webgui/asgi.py

@@ -0,0 +1,16 @@
+"""
+ASGI config for webgui project.
+
+It exposes the ASGI callable as a module-level variable named ``application``.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/
+"""
+
+import os
+
+from django.core.asgi import get_asgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'webgui.settings')
+
+application = get_asgi_application()

+ 26 - 0
webgui/webgui/local_settings_example.py

@@ -0,0 +1,26 @@
+# Rename this file to local_settings.py
+#
+
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = ""
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = False
+
+ALLOWED_HOSTS = ["*"]
+
+# Database
+# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.postgresql',
+        'NAME': '',
+        'USER': '',
+        'PASSWORD': '',
+        'HOST': '127.0.0.1',
+        'PORT': '5432',
+    }
+}
+
+APPLICATION_NAME = "Iris Pseudácorus Mallard"
+DISCORD_LINK = "https://discord.gg/kDMv6W89VU"

+ 113 - 0
webgui/webgui/settings.py

@@ -0,0 +1,113 @@
+"""
+Django settings for webgui project.
+
+Generated by 'django-admin startproject' using Django 4.1.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/4.1/topics/settings/
+
+For the full list of settings and their values, see
+https://docs.djangoproject.com/en/4.1/ref/settings/
+"""
+
+from pathlib import Path
+
+# Build paths inside the project like this: BASE_DIR / 'subdir'.
+BASE_DIR = Path(__file__).resolve().parent.parent
+
+# Store environment dependant settings in local_settings.py, which is untracked by git.
+try:
+    from .local_settings import *
+except ImportError:
+    pass
+
+
+# Quick-start development settings - unsuitable for production
+# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
+
+# Application definition
+
+INSTALLED_APPS = [
+    # Djange default
+    'django.contrib.admin',
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.messages',
+    'django.contrib.staticfiles',
+
+    # Project apps
+    'config.apps.ConfigConfig',
+]
+
+MIDDLEWARE = [
+    'django.middleware.security.SecurityMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.middleware.common.CommonMiddleware',
+    'django.middleware.csrf.CsrfViewMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.contrib.messages.middleware.MessageMiddleware',
+    'django.middleware.clickjacking.XFrameOptionsMiddleware',
+]
+
+ROOT_URLCONF = 'webgui.urls'
+
+TEMPLATES = [
+    {
+        'BACKEND': 'django.template.backends.django.DjangoTemplates',
+        'DIRS': [],
+        'APP_DIRS': True,
+        'OPTIONS': {
+            'context_processors': [
+                'django.template.context_processors.debug',
+                'django.template.context_processors.request',
+                'django.contrib.auth.context_processors.auth',
+                'django.contrib.messages.context_processors.messages',
+            ],
+        },
+    },
+]
+
+WSGI_APPLICATION = 'webgui.wsgi.application'
+
+
+# Password validation
+# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
+
+AUTH_PASSWORD_VALIDATORS = [
+    {
+        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
+    },
+    {
+        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
+    },
+    {
+        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
+    },
+    {
+        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
+    },
+]
+
+
+# Internationalization
+# https://docs.djangoproject.com/en/4.1/topics/i18n/
+
+LANGUAGE_CODE = 'en-us'
+
+TIME_ZONE = 'UTC'
+
+USE_I18N = True
+
+USE_TZ = True
+
+
+# Static files (CSS, JavaScript, Images)
+# https://docs.djangoproject.com/en/4.1/howto/static-files/
+
+STATIC_URL = 'static/'
+
+# Default primary key field type
+# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
+
+DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

+ 21 - 0
webgui/webgui/urls.py

@@ -0,0 +1,21 @@
+"""webgui URL Configuration
+
+The `urlpatterns` list routes URLs to views. For more information please see:
+    https://docs.djangoproject.com/en/4.1/topics/http/urls/
+Examples:
+Function views
+    1. Add an import:  from my_app import views
+    2. Add a URL to urlpatterns:  path('', views.home, name='home')
+Class-based views
+    1. Add an import:  from other_app.views import Home
+    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
+Including another URLconf
+    1. Import the include() function: from django.urls import include, path
+    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
+"""
+from django.contrib import admin
+from django.urls import path
+
+urlpatterns = [
+    path('admin/', admin.site.urls),
+]

+ 16 - 0
webgui/webgui/wsgi.py

@@ -0,0 +1,16 @@
+"""
+WSGI config for webgui project.
+
+It exposes the WSGI callable as a module-level variable named ``application``.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/
+"""
+
+import os
+
+from django.core.wsgi import get_wsgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'webgui.settings')
+
+application = get_wsgi_application()