From 82fad29c17baba358ae6178d7e762fc3314f2c08 Mon Sep 17 00:00:00 2001 From: Adler Neves Date: Wed, 8 Jul 2020 02:32:26 -0300 Subject: [PATCH] Added Telegram token variables --- webproj/bot/urls.py | 6 +++++ webproj/bot/views.py | 28 ++++++++++++++++++++- webproj/fsconfig.py | 11 +++++++- webproj/settings.py | 60 ++++++++++++++++++++++++++++++++++++++++++++ webproj/urls.py | 5 ++++ 5 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 webproj/bot/urls.py diff --git a/webproj/bot/urls.py b/webproj/bot/urls.py new file mode 100644 index 0000000..f7db534 --- /dev/null +++ b/webproj/bot/urls.py @@ -0,0 +1,6 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.SoonView.as_view(), name='home'), +] diff --git a/webproj/bot/views.py b/webproj/bot/views.py index 91ea44a..4e1626f 100644 --- a/webproj/bot/views.py +++ b/webproj/bot/views.py @@ -1,3 +1,29 @@ -from django.shortcuts import render +import datetime +import gzip +import json +import mimetypes +import sys +from pathlib import Path +from typing import Any, Dict, List +from uuid import UUID + +import pytz + +from django.conf import settings +from django.contrib.auth.decorators import login_required +from django.contrib.auth.mixins import LoginRequiredMixin +from django.http import FileResponse, HttpResponse, HttpResponseRedirect +from django.shortcuts import get_object_or_404, redirect, render, resolve_url +from django.urls import reverse +from django.utils.decorators import method_decorator +from django.utils.html import escape +from django.views import View +from django.views.decorators.csrf import csrf_exempt +from django.views.decorators.http import last_modified +from django.views.generic import TemplateView # Create your views here. + + +class SoonView(TemplateView): + template_name = "soon.html" diff --git a/webproj/fsconfig.py b/webproj/fsconfig.py index 8d8d642..475dbd5 100644 --- a/webproj/fsconfig.py +++ b/webproj/fsconfig.py @@ -12,6 +12,7 @@ XTRACFG = os.path.join(server_secrets_DIR, 'extraconfig.py') RGO = os.path.join(server_secrets_DIR, 'REGISTRATION_OPEN.txt') LNGS = os.path.join(BASE_DIR, 'webproj', 'locale') LNGSo = os.path.join(server_secrets_DIR, 'active_languages.html') +TGT = os.path.join(server_secrets_DIR, 'telegram.token') if not os.path.exists(server_secrets_DIR): os.makedirs(server_secrets_DIR) @@ -37,12 +38,16 @@ if not os.path.exists(RGO): if not os.path.exists(STD): with open(STD, 'wt') as f: - f.write('.furmeet.app') + f.write('bot.furmeet.app\n.furmeet.app') if not os.path.exists(STN): with open(STN, 'wt') as f: f.write('FurmeetApp\'s Group Chat Bot') +if not os.path.exists(TGT): + with open(TGT, 'wt') as f: + f.write('') + def isTrue(s: str) -> bool: return s in ['1', 'true', 't', 'True', 'TRUE', 'yes', 'y', 'YES', 'Yes'] @@ -54,6 +59,7 @@ SITE_DOMAIN = None REGISTRATION_OPEN = None SITE_NAME = None LANGUAGES = list() +TELEGRAM_TOKEN = None with open(SKB, 'rb') as f: SECRET_KEY = f.read() @@ -70,6 +76,9 @@ with open(STD, 'rt') as f: with open(STN, 'rt') as f: SITE_NAME = f.read().strip() +with open(TGT, 'rt') as f: + TELEGRAM_TOKEN = f.read().strip() + for language_code in sorted(os.listdir(LNGS)): lc = language_code.lower().replace(' ', '-').replace('_', '-') LANGUAGES.append(( diff --git a/webproj/settings.py b/webproj/settings.py index 98e084a..4bbd040 100644 --- a/webproj/settings.py +++ b/webproj/settings.py @@ -202,4 +202,64 @@ CORS_URLS_REGEX = r'^/api/.*$' # CORS_ORIGIN_REGEX_WHITELIST = [r'^.*$'] CORS_ORIGIN_ALLOW_ALL = True +DJANGO_TELEGRAMBOT = { + + 'MODE': 'WEBHOOK', # (Optional [str]) # The default value is WEBHOOK, + # otherwise you may use 'POLLING' + # NB: if use polling you must provide to run + # a management command that starts a worker + + 'WEBHOOK_SITE': f'https://{fsconfig.SITE_DOMAIN[0]}', + 'WEBHOOK_PREFIX': '/telegram', # (Optional[str]) # If this value is specified, + # a prefix is added to webhook url + + # 'WEBHOOK_CERTIFICATE' : 'cert.pem', # If your site use self-signed + # certificate, must be set with location of your public key + # certificate.(More info at https://core.telegram.org/bots/self-signed ) + + 'BOTS': [ + { + 'TOKEN': fsconfig.TELEGRAM_TOKEN, # Your bot token. + + # 'ALLOWED_UPDATES':(Optional[list[str]]), # List the types of + # updates you want your bot to receive. For example, specify + # ``["message", "edited_channel_post", "callback_query"]`` to + # only receive updates of these types. See ``telegram.Update`` + # for a complete list of available update types. + # Specify an empty list to receive all updates regardless of type + # (default). If not specified, the previous setting will be used. + # Please note that this parameter doesn't affect updates created + # before the call to the setWebhook, so unwanted updates may be + # received for a short period of time. + + # 'TIMEOUT':(Optional[int|float]), # If this value is specified, + # use it as the read timeout from the server + + # 'WEBHOOK_MAX_CONNECTIONS':(Optional[int]), # Maximum allowed number of + # simultaneous HTTPS connections to the webhook for update + # delivery, 1-100. Defaults to 40. Use lower values to limit the + # load on your bot's server, and higher values to increase your + # bot's throughput. + + # 'POLL_INTERVAL' : (Optional[float]), # Time to wait between polling updates from Telegram in + #seconds. Default is 0.0 + + # 'POLL_CLEAN':(Optional[bool]), # Whether to clean any pending updates on Telegram servers before + # actually starting to poll. Default is False. + + # 'POLL_BOOTSTRAP_RETRIES':(Optional[int]), # Whether the bootstrapping phase of the `Updater` + # will retry on failures on the Telegram server. + # | < 0 - retry indefinitely + # | 0 - no retries (default) + # | > 0 - retry up to X times + + # 'POLL_READ_LATENCY':(Optional[float|int]), # Grace time in seconds for receiving the reply from + # server. Will be added to the `timeout` value and used as the read timeout from + # server (Default: 2). + }, + # Other bots here with same structure. + ], +} + + exec('from server_secrets.extraconfig import *') diff --git a/webproj/urls.py b/webproj/urls.py index ea56b5f..0345e6c 100644 --- a/webproj/urls.py +++ b/webproj/urls.py @@ -13,9 +13,14 @@ 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')) """ +import django_telegrambot.urls as telebot_urls from django.contrib import admin from django.urls import path +from .bot import urls as bot_urls + urlpatterns = [ path('admin/', admin.site.urls), + path('', telebot_urls), + path('', bot_urls), ]