Compare commits
No commits in common. "7eba92016e4e75244281689d0a9a0f2cbdd5ba60" and "08d9de8784dfcf2668ce11afd7538c171fb96d29" have entirely different histories.
7eba92016e
...
08d9de8784
43
t0sig.py
43
t0sig.py
|
@ -1,13 +1,6 @@
|
||||||
import os
|
|
||||||
import logging
|
|
||||||
logging.basicConfig(
|
|
||||||
format='[%(asctime)s] %(levelname)s %(module)s/%(funcName)s - %(message)s',
|
|
||||||
level=logging.DEBUG if os.environ.get('DEBUG') else logging.INFO)
|
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import requests
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
from telethon import TelegramClient, events
|
from telethon import TelegramClient, events
|
||||||
|
@ -19,20 +12,11 @@ TANNER = 79316791
|
||||||
|
|
||||||
messages = {}
|
messages = {}
|
||||||
|
|
||||||
def controller_message(message):
|
|
||||||
payload = dict(misc=message)
|
|
||||||
r = requests.post('https://tbot.tannercollin.com/message', data=payload, timeout=10)
|
|
||||||
if r.status_code == 200:
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
logging.exception('Unable to communicate with controller! Message: ' + message)
|
|
||||||
return False
|
|
||||||
|
|
||||||
@bot.on(events.NewMessage(incoming=True))
|
@bot.on(events.NewMessage(incoming=True))
|
||||||
async def new_message(event):
|
async def new_message(event):
|
||||||
text = event.raw_text
|
text = event.raw_text
|
||||||
sender = event.sender_id
|
sender = event.sender_id
|
||||||
logging.info('{} {}'.format(sender, text))
|
print(sender, text)
|
||||||
|
|
||||||
if sender != TANNER:
|
if sender != TANNER:
|
||||||
return
|
return
|
||||||
|
@ -46,17 +30,12 @@ async def new_message(event):
|
||||||
await event.reply('Message ID not found. Did the bot restart?')
|
await event.reply('Message ID not found. Did the bot restart?')
|
||||||
return
|
return
|
||||||
|
|
||||||
entry = '------------------------------------------------------------\n\n{} - {}'.format(data['date'], data['name'])
|
entry = '--------------------------\n\n{} - {}'.format(data['date'], data['name'])
|
||||||
|
|
||||||
website = data['website']
|
website = data['website']
|
||||||
if website:
|
if website:
|
||||||
prefixes = ['http://', 'https://', 'gemini://', 'gopher://']
|
if not website.startswith('http://') and not website.startswith('https://'):
|
||||||
for prefix in prefixes:
|
|
||||||
if website.startswith(prefix):
|
|
||||||
break
|
|
||||||
else: # for loop
|
|
||||||
website = 'http://' + website
|
website = 'http://' + website
|
||||||
|
|
||||||
entry += ' (<a href="{0}" target="_blank" rel="noreferrer noopener">{0}</a>)'.format(website)
|
entry += ' (<a href="{0}" target="_blank" rel="noreferrer noopener">{0}</a>)'.format(website)
|
||||||
|
|
||||||
entry += '\n\n{}\n\n'.format(data['message'])
|
entry += '\n\n{}\n\n'.format(data['message'])
|
||||||
|
@ -65,14 +44,14 @@ async def new_message(event):
|
||||||
f.write(entry)
|
f.write(entry)
|
||||||
|
|
||||||
await event.reply('Entry added to t0.vc/g')
|
await event.reply('Entry added to t0.vc/g')
|
||||||
logging.info('Added: {}'.format(data))
|
print('Added', data)
|
||||||
|
|
||||||
|
|
||||||
async def submit(request):
|
async def submit(request):
|
||||||
data = dict(await request.post())
|
data = dict(await request.post())
|
||||||
data['date'] = str(datetime.today().date())
|
data['date'] = str(datetime.today().date())
|
||||||
mid = str(uuid4()).split('-')[0]
|
mid = str(uuid4()).split('-')[0]
|
||||||
logging.info('{} {}'.format(mid, data))
|
print(mid, data)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
name = data['name']
|
name = data['name']
|
||||||
|
@ -91,15 +70,9 @@ async def submit(request):
|
||||||
if len(message) > 1000:
|
if len(message) > 1000:
|
||||||
raise web.HTTPBadRequest(reason='Message is too long.')
|
raise web.HTTPBadRequest(reason='Message is too long.')
|
||||||
|
|
||||||
if 'sex' not in message and 'porn' not in message:
|
report = 'Name: {}\n\nWebsite: {}\n\nMessage: {}\n\n/allow_{}'
|
||||||
report = 'Name: {}\n\nWebsite: {}\n\nMessage: {}\n\n/allow_{}'
|
await bot.send_message(TANNER, message=report.format(name, website, message, mid))
|
||||||
try:
|
messages[mid] = data
|
||||||
await bot.send_message(TANNER, message=report.format(name, website, message, mid))
|
|
||||||
except:
|
|
||||||
logging.error('Problem sending bot message.')
|
|
||||||
controller_message('t0sig: problem sending bot message!')
|
|
||||||
exit()
|
|
||||||
messages[mid] = data
|
|
||||||
|
|
||||||
with open('data/messages.log', 'a') as f:
|
with open('data/messages.log', 'a') as f:
|
||||||
f.write(json.dumps(data)+'\n')
|
f.write(json.dumps(data)+'\n')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user