Compare commits
1 commit
master
...
feature/pi
Author | SHA1 | Date | |
---|---|---|---|
![]() |
428f42abea |
active_bots
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
from bot import Bot
|
from bot import Bot
|
||||||
import logging
|
import logging
|
||||||
import mastodon
|
from mastodon import Mastodon
|
||||||
import re
|
import re
|
||||||
from report import Report
|
from report import Report
|
||||||
|
|
||||||
|
@ -19,14 +19,14 @@ class MastodonBot(Bot):
|
||||||
"""
|
"""
|
||||||
mentions = []
|
mentions = []
|
||||||
try:
|
try:
|
||||||
m = mastodon.Mastodon(*user.get_masto_credentials())
|
m = Mastodon(*user.get_masto_credentials())
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# logger.error("No Mastodon Credentials in database.", exc_info=True)
|
# logger.error("No Mastodon Credentials in database.", exc_info=True)
|
||||||
return mentions
|
return mentions
|
||||||
try:
|
try:
|
||||||
notifications = m.notifications()
|
notifications = m.notifications()
|
||||||
except mastodon.MastodonServerError:
|
except Exception:
|
||||||
logger.error("Unknown Mastodon API Error: 502")
|
logger.error("Unknown Mastodon API Error.", exc_info=True)
|
||||||
return mentions
|
return mentions
|
||||||
for status in notifications:
|
for status in notifications:
|
||||||
if (status['type'] == 'mention' and
|
if (status['type'] == 'mention' and
|
||||||
|
@ -54,7 +54,7 @@ class MastodonBot(Bot):
|
||||||
|
|
||||||
def post(self, user, report):
|
def post(self, user, report):
|
||||||
try:
|
try:
|
||||||
m = mastodon.Mastodon(*user.get_masto_credentials())
|
m = Mastodon(*user.get_masto_credentials())
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return # no mastodon account for this user.
|
return # no mastodon account for this user.
|
||||||
if report.source == self:
|
if report.source == self:
|
||||||
|
|
|
@ -32,12 +32,6 @@ class TelegramBot(Bot):
|
||||||
logger.error("Unknown Telegram error code: " + str(update))
|
logger.error("Unknown Telegram error code: " + str(update))
|
||||||
return reports
|
return reports
|
||||||
user.save_seen_tg(update.update_id)
|
user.save_seen_tg(update.update_id)
|
||||||
if update.message.photo:
|
|
||||||
tb.send_message(
|
|
||||||
update.message.sender.id,
|
|
||||||
"Sending Photos is not supported for privacy reasons. Can "
|
|
||||||
"you describe it as text instead?")
|
|
||||||
continue
|
|
||||||
if update.message.text.lower() == "/start":
|
if update.message.text.lower() == "/start":
|
||||||
user.add_telegram_subscribers(update.message.sender.id)
|
user.add_telegram_subscribers(update.message.sender.id)
|
||||||
tb.send_message(
|
tb.send_message(
|
||||||
|
@ -56,6 +50,9 @@ class TelegramBot(Bot):
|
||||||
"Send reports here to share them with other users. "
|
"Send reports here to share them with other users. "
|
||||||
"Use /start and /stop to get reports or not.")
|
"Use /start and /stop to get reports or not.")
|
||||||
# TODO: /help message should be set in frontend
|
# TODO: /help message should be set in frontend
|
||||||
|
elif update.message.text.lower() == "/ping":
|
||||||
|
tb.send_message(
|
||||||
|
update.message.sender.id, "pong")
|
||||||
else:
|
else:
|
||||||
# set report.author to "" to avoid mailbot crash
|
# set report.author to "" to avoid mailbot crash
|
||||||
sender_name = update.message.sender.username
|
sender_name = update.message.sender.username
|
||||||
|
|
|
@ -73,7 +73,7 @@ class TwitterBot(Bot):
|
||||||
def post(self, user, report):
|
def post(self, user, report):
|
||||||
try:
|
try:
|
||||||
api = self.get_api(user)
|
api = self.get_api(user)
|
||||||
except TypeError:
|
except IndexError:
|
||||||
return # no twitter account for this user.
|
return # no twitter account for this user.
|
||||||
try:
|
try:
|
||||||
if report.source == self:
|
if report.source == self:
|
||||||
|
|
Loading…
Reference in a new issue