More logging?
This commit is contained in:
parent
1ec78d5f53
commit
95c9a523e0
|
@ -19,12 +19,13 @@ VERIFY_CREDS_TEMPLATE = "https://{instance}/api/v1/accounts/verify_credentials"
|
||||||
logger = getLogger()
|
logger = getLogger()
|
||||||
|
|
||||||
|
|
||||||
def init_logger():
|
def init_logger(loglevel: int = DEBUG):
|
||||||
stdout_handler = StreamHandler(stdout)
|
stdout_handler = StreamHandler(stdout)
|
||||||
stdout_handler.setLevel(DEBUG)
|
stdout_handler.setLevel(DEBUG)
|
||||||
formatter = Formatter("[%(asctime)s][%(levelname)5s:%(name)s] %(message)s")
|
formatter = Formatter("[%(asctime)s][%(levelname)5s:%(name)s] %(message)s")
|
||||||
stdout_handler.setFormatter(formatter)
|
stdout_handler.setFormatter(formatter)
|
||||||
logger.addHandler(stdout_handler)
|
logger.addHandler(stdout_handler)
|
||||||
|
logger.setLevel(loglevel)
|
||||||
|
|
||||||
|
|
||||||
async def listen(
|
async def listen(
|
||||||
|
|
|
@ -15,7 +15,7 @@ logger = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def run_filters(filters: List[FilterInstance], status: Status) -> bool:
|
def run_filters(filters: List[FilterInstance], status: Status) -> bool:
|
||||||
logger.debug("Running filters on %r", status)
|
logger.debug("Running filters on %r", status.id)
|
||||||
|
|
||||||
if not filters:
|
if not filters:
|
||||||
logger.debug("No filters, returning True")
|
logger.debug("No filters, returning True")
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from configparser import SectionProxy
|
from configparser import SectionProxy
|
||||||
|
from logging import getLogger
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
from httpx import AsyncClient
|
from httpx import AsyncClient
|
||||||
from zlib import crc32
|
from zlib import crc32
|
||||||
|
@ -10,6 +11,8 @@ from mastoposter.integrations.discord.types import (
|
||||||
)
|
)
|
||||||
from mastoposter.types import Status
|
from mastoposter.types import Status
|
||||||
|
|
||||||
|
logger = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class DiscordIntegration(BaseIntegration):
|
class DiscordIntegration(BaseIntegration):
|
||||||
def __init__(self, webhook: str):
|
def __init__(self, webhook: str):
|
||||||
|
@ -35,6 +38,9 @@ class DiscordIntegration(BaseIntegration):
|
||||||
if embeds is not None
|
if embeds is not None
|
||||||
else [],
|
else [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.debug("Executing webhook with %r", json)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
await c.post(
|
await c.post(
|
||||||
self.webhook,
|
self.webhook,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from configparser import SectionProxy
|
from configparser import SectionProxy
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from logging import getLogger
|
||||||
from typing import Any, List, Mapping, Optional
|
from typing import Any, List, Mapping, Optional
|
||||||
from httpx import AsyncClient
|
from httpx import AsyncClient
|
||||||
from jinja2 import Template
|
from jinja2 import Template
|
||||||
|
@ -8,6 +9,9 @@ from mastoposter.types import Attachment, Poll, Status
|
||||||
from emoji import emojize
|
from emoji import emojize
|
||||||
|
|
||||||
|
|
||||||
|
logger = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TGResponse:
|
class TGResponse:
|
||||||
ok: bool
|
ok: bool
|
||||||
|
@ -89,6 +93,7 @@ class TelegramIntegration(BaseIntegration):
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _post_plaintext(self, text: str) -> TGResponse:
|
async def _post_plaintext(self, text: str) -> TGResponse:
|
||||||
|
logger.debug("Sending HTML message: %r", text)
|
||||||
return await self._tg_request(
|
return await self._tg_request(
|
||||||
"sendMessage",
|
"sendMessage",
|
||||||
parse_mode="HTML",
|
parse_mode="HTML",
|
||||||
|
@ -101,6 +106,9 @@ class TelegramIntegration(BaseIntegration):
|
||||||
async def _post_media(self, text: str, media: Attachment) -> TGResponse:
|
async def _post_media(self, text: str, media: Attachment) -> TGResponse:
|
||||||
# Just to be safe
|
# Just to be safe
|
||||||
if media.type not in MEDIA_MAPPING:
|
if media.type not in MEDIA_MAPPING:
|
||||||
|
logger.warning(
|
||||||
|
"Media %r has unknown type, falling back to plaintext", media
|
||||||
|
)
|
||||||
return await self._post_plaintext(text)
|
return await self._post_plaintext(text)
|
||||||
|
|
||||||
return await self._tg_request(
|
return await self._tg_request(
|
||||||
|
@ -116,6 +124,7 @@ class TelegramIntegration(BaseIntegration):
|
||||||
async def _post_mediagroup(
|
async def _post_mediagroup(
|
||||||
self, text: str, media: List[Attachment]
|
self, text: str, media: List[Attachment]
|
||||||
) -> TGResponse:
|
) -> TGResponse:
|
||||||
|
logger.debug("Sendind media group: %r (text=%r)", media, text)
|
||||||
media_list: List[dict] = []
|
media_list: List[dict] = []
|
||||||
allowed_medias = {"image", "gifv", "video", "audio", "unknown"}
|
allowed_medias = {"image", "gifv", "video", "audio", "unknown"}
|
||||||
for attachment in media:
|
for attachment in media:
|
||||||
|
@ -149,6 +158,7 @@ class TelegramIntegration(BaseIntegration):
|
||||||
async def _post_poll(
|
async def _post_poll(
|
||||||
self, poll: Poll, reply_to: Optional[str] = None
|
self, poll: Poll, reply_to: Optional[str] = None
|
||||||
) -> TGResponse:
|
) -> TGResponse:
|
||||||
|
logger.debug("Sending poll: %r", poll)
|
||||||
return await self._tg_request(
|
return await self._tg_request(
|
||||||
"sendPoll",
|
"sendPoll",
|
||||||
disable_notification=self.silent,
|
disable_notification=self.silent,
|
||||||
|
@ -198,9 +208,17 @@ class TelegramIntegration(BaseIntegration):
|
||||||
return str.join(",", map(str, ids))
|
return str.join(",", map(str, ids))
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
|
bot_uid, key = self.token.split(":")
|
||||||
return (
|
return (
|
||||||
"<TelegramIntegration "
|
"<TelegramIntegration "
|
||||||
"chat_id={chat!r} "
|
"chat_id={chat!r} "
|
||||||
"template={template!r} "
|
"template={template!r} "
|
||||||
|
"token={bot_uid}:{key} "
|
||||||
"silent={silent!r}>"
|
"silent={silent!r}>"
|
||||||
).format(chat=self.chat_id, silent=self.silent, template=self.template)
|
).format(
|
||||||
|
chat=self.chat_id,
|
||||||
|
silent=self.silent,
|
||||||
|
template=self.template,
|
||||||
|
bot_uid=bot_uid,
|
||||||
|
key=str.join("", ("X" for _ in key)),
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue