Send controller message on error, change hr line

master
Tanner Collin 2 years ago
parent b420720a2c
commit 7eba92016e
  1. 21
      t0sig.py

@ -7,6 +7,7 @@ logging.basicConfig(
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
@ -18,6 +19,15 @@ 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
@ -36,7 +46,7 @@ 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:
@ -81,9 +91,14 @@ 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 name not in ['Devinwex']: 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:
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 messages[mid] = data
with open('data/messages.log', 'a') as f: with open('data/messages.log', 'a') as f:

Loading…
Cancel
Save