Finish prototype

This commit is contained in:
Tanner Collin 2021-02-18 03:00:50 +00:00
parent 741b580532
commit 930595d0d3
4 changed files with 94 additions and 0 deletions

56
blueocean.py Normal file
View File

@ -0,0 +1,56 @@
import asyncio
import logging
import settings
import time
import validators
from aiohttp import web
from telethon import TelegramClient, events
TANNER = 79316791
bot = TelegramClient('bot', settings.API_ID, settings.API_HASH).start(bot_token=settings.API_TOKEN)
routes = web.RouteTableDef()
logging.basicConfig(level=logging.INFO)
data = ''
data_time = 0
@bot.on(events.NewMessage)
async def echo_all(event):
global data, data_time
if not event.raw_text:
await event.reply('no')
logging.info('No text found')
return
logging.info('Message: ' + event.raw_text)
if event.sender.id != TANNER:
await event.reply('no')
logging.info('Message not from Tanner')
return
data = event.raw_text
data_time = time.time()
await event.reply('ok')
@routes.get('/')
async def index(request):
if 'bot' in request.headers.get('User-Agent', '').lower():
raise web.HTTPForbidden()
if time.time() - data_time > 3600:
logging.info('Time expired, showing green ocean water')
return web.FileResponse(path='greenoceanwater.jpg', status=200)
if validators.domain(data):
raise web.HTTPFound('http://' + data)
elif validators.url(data):
raise web.HTTPFound(data)
else:
return web.Response(text=data)
app = web.Application()
app.add_routes(routes)
web.run_app(app)

BIN
greenoceanwater.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 KiB

35
requirements.txt Normal file
View File

@ -0,0 +1,35 @@
aiohttp==3.7.3
appdirs==1.4.3
async-timeout==3.0.1
attrs==20.3.0
CacheControl==0.12.6
certifi==2019.11.28
chardet==3.0.4
colorama==0.4.3
contextlib2==0.6.0
decorator==4.4.2
distlib==0.3.0
distro==1.4.0
html5lib==1.0.1
idna==2.8
ipaddr==2.2.0
lockfile==0.12.2
msgpack==0.6.2
multidict==5.1.0
packaging==20.3
pep517==0.8.2
progress==1.5
pyaes==1.6.1
pyasn1==0.4.8
pyparsing==2.4.6
pytoml==0.1.21
requests==2.22.0
retrying==1.3.3
rsa==4.7.1
six==1.14.0
Telethon==1.19.5
typing-extensions==3.7.4.3
urllib3==1.25.8
validators==0.18.2
webencodings==0.5.1
yarl==1.6.3

3
settings.py.example Normal file
View File

@ -0,0 +1,3 @@
API_ID = 0
API_HASH = ''
API_TOKEN = ''