From 624998817b7f6f6f4b491cf8e28d769057080982 Mon Sep 17 00:00:00 2001 From: hkc Date: Sat, 8 Jun 2024 16:32:04 +0300 Subject: [PATCH] Added option to post replies anyways Also reformatting because I forgot --- config.ini | 4 ++++ mastoposter/__init__.py | 1 + mastoposter/__main__.py | 8 +++++++- mastoposter/filters/__init__.py | 1 + mastoposter/filters/base.py | 1 + mastoposter/filters/boost.py | 1 + mastoposter/filters/combined.py | 1 + mastoposter/filters/media.py | 1 + mastoposter/filters/mention.py | 1 + mastoposter/filters/spoiler.py | 1 + mastoposter/filters/text.py | 1 + mastoposter/filters/visibility.py | 1 + mastoposter/integrations/__init__.py | 1 + mastoposter/integrations/base.py | 1 + mastoposter/integrations/discord/__init__.py | 9 ++++++--- mastoposter/integrations/discord/types.py | 1 + mastoposter/integrations/telegram.py | 1 + mastoposter/sources.py | 1 + mastoposter/text/__init__.py | 1 + mastoposter/text/html.py | 1 + mastoposter/types.py | 1 + mastoposter/utils.py | 1 + 22 files changed, 36 insertions(+), 4 deletions(-) diff --git a/config.ini b/config.ini index 8a313b1..f25820e 100644 --- a/config.ini +++ b/config.ini @@ -32,6 +32,10 @@ user = auto # address bar while you have that list open) list = 1 +# Allow replies to be boosted as well +# By default replies will be ignores unless it's a reply to your post +# replies_to_other_accounts_should_not_be_skipped = yes + # Should we automatically reconnect to the streaming socket? # That option exists because it's not really a big deal when crossposter runs # as a service and restarts automatically by the service manager. diff --git a/mastoposter/__init__.py b/mastoposter/__init__.py index 3ac629c..7a68760 100644 --- a/mastoposter/__init__.py +++ b/mastoposter/__init__.py @@ -12,6 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ + from asyncio import gather from configparser import ConfigParser from logging import getLogger diff --git a/mastoposter/__main__.py b/mastoposter/__main__.py index d360fa7..5bc19ac 100644 --- a/mastoposter/__main__.py +++ b/mastoposter/__main__.py @@ -64,6 +64,7 @@ async def listen( source: Callable[..., AsyncGenerator[Status, None]], drains: List[FilteredIntegration], user: str, + replies_to_other_accounts_should_not_be_skipped: bool = False, /, **kwargs, ): @@ -93,7 +94,7 @@ async def listen( if ( status.in_reply_to_account_id is not None and status.in_reply_to_account_id != user - ): + ) and not replies_to_other_accounts_should_not_be_skipped: logger.info( "Skipping post %s because it's a reply to another person", status.uri, @@ -147,6 +148,11 @@ def main(): modules, user_id, url=url, + replies_to_other_accounts_should_not_be_skipped=conf[ + "main" + ].getboolean( + "replies_to_other_accounts_should_not_be_skipped", False + ), reconnect=conf["main"].getboolean("auto_reconnect", False), reconnect_delay=conf["main"].getfloat("reconnect_delay", 1.0), list=conf["main"]["list"], diff --git a/mastoposter/filters/__init__.py b/mastoposter/filters/__init__.py index 0ef8dde..cd7ed1f 100644 --- a/mastoposter/filters/__init__.py +++ b/mastoposter/filters/__init__.py @@ -12,6 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ + from logging import getLogger from typing import List diff --git a/mastoposter/filters/base.py b/mastoposter/filters/base.py index d563847..0e3fa24 100644 --- a/mastoposter/filters/base.py +++ b/mastoposter/filters/base.py @@ -12,6 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ + from abc import ABC, abstractmethod from configparser import ConfigParser, SectionProxy from typing import ClassVar, Dict, NamedTuple, Type diff --git a/mastoposter/filters/boost.py b/mastoposter/filters/boost.py index 7fa494b..d4ed4ec 100644 --- a/mastoposter/filters/boost.py +++ b/mastoposter/filters/boost.py @@ -12,6 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ + from configparser import SectionProxy from fnmatch import fnmatch from typing import List diff --git a/mastoposter/filters/combined.py b/mastoposter/filters/combined.py index 91fedea..fae29fc 100644 --- a/mastoposter/filters/combined.py +++ b/mastoposter/filters/combined.py @@ -12,6 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ + from configparser import ConfigParser, SectionProxy from typing import Callable, ClassVar, Dict, List, Sequence from mastoposter.filters.base import BaseFilter, FilterInstance diff --git a/mastoposter/filters/media.py b/mastoposter/filters/media.py index a0f5b81..a6e0b71 100644 --- a/mastoposter/filters/media.py +++ b/mastoposter/filters/media.py @@ -12,6 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ + from configparser import SectionProxy from typing import Literal, Set from mastoposter.filters.base import BaseFilter diff --git a/mastoposter/filters/mention.py b/mastoposter/filters/mention.py index 70b06a1..08e4d56 100644 --- a/mastoposter/filters/mention.py +++ b/mastoposter/filters/mention.py @@ -12,6 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ + from configparser import SectionProxy from re import Pattern, compile as regexp from typing import ClassVar, Set diff --git a/mastoposter/filters/spoiler.py b/mastoposter/filters/spoiler.py index a600d09..a97c005 100644 --- a/mastoposter/filters/spoiler.py +++ b/mastoposter/filters/spoiler.py @@ -12,6 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ + from configparser import SectionProxy from re import Pattern, compile as regexp from mastoposter.filters.base import BaseFilter diff --git a/mastoposter/filters/text.py b/mastoposter/filters/text.py index 3d202be..f4bc791 100644 --- a/mastoposter/filters/text.py +++ b/mastoposter/filters/text.py @@ -12,6 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ + from configparser import SectionProxy from re import Pattern, compile as regexp from typing import Optional, Set diff --git a/mastoposter/filters/visibility.py b/mastoposter/filters/visibility.py index 9dcfd31..b2a6671 100644 --- a/mastoposter/filters/visibility.py +++ b/mastoposter/filters/visibility.py @@ -12,6 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ + from configparser import SectionProxy from typing import Set from mastoposter.filters.base import BaseFilter diff --git a/mastoposter/integrations/__init__.py b/mastoposter/integrations/__init__.py index eee75de..1964405 100644 --- a/mastoposter/integrations/__init__.py +++ b/mastoposter/integrations/__init__.py @@ -12,6 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ + from typing import List, NamedTuple from mastoposter.filters.base import FilterInstance diff --git a/mastoposter/integrations/base.py b/mastoposter/integrations/base.py index 2b70eba..4637da9 100644 --- a/mastoposter/integrations/base.py +++ b/mastoposter/integrations/base.py @@ -12,6 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ + from abc import ABC, abstractmethod from configparser import SectionProxy from typing import Optional diff --git a/mastoposter/integrations/discord/__init__.py b/mastoposter/integrations/discord/__init__.py index 9572306..cb82064 100644 --- a/mastoposter/integrations/discord/__init__.py +++ b/mastoposter/integrations/discord/__init__.py @@ -12,6 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ + from configparser import SectionProxy from logging import getLogger from typing import List, Optional @@ -51,9 +52,11 @@ class DiscordIntegration(BaseIntegration): "content": content, "username": username, "avatar_url": avatar_url, - "embeds": [embed.asdict() for embed in embeds] - if embeds is not None - else [], + "embeds": ( + [embed.asdict() for embed in embeds] + if embeds is not None + else [] + ), } logger.debug("Executing webhook with %r", json) diff --git a/mastoposter/integrations/discord/types.py b/mastoposter/integrations/discord/types.py index 372b16b..2f92788 100644 --- a/mastoposter/integrations/discord/types.py +++ b/mastoposter/integrations/discord/types.py @@ -12,6 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ + from dataclasses import asdict, dataclass from datetime import datetime from typing import Any, Callable, Dict, List, Optional diff --git a/mastoposter/integrations/telegram.py b/mastoposter/integrations/telegram.py index eb6acab..6706a87 100644 --- a/mastoposter/integrations/telegram.py +++ b/mastoposter/integrations/telegram.py @@ -12,6 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ + from configparser import SectionProxy from dataclasses import dataclass from logging import getLogger diff --git a/mastoposter/sources.py b/mastoposter/sources.py index 749ad4d..9f0a85e 100644 --- a/mastoposter/sources.py +++ b/mastoposter/sources.py @@ -12,6 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ + from asyncio import exceptions, sleep from json import loads from logging import getLogger diff --git a/mastoposter/text/__init__.py b/mastoposter/text/__init__.py index e349396..b545845 100644 --- a/mastoposter/text/__init__.py +++ b/mastoposter/text/__init__.py @@ -12,6 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ + from typing import Callable, Iterable, Literal, Optional from bs4.element import Tag, PageElement diff --git a/mastoposter/text/html.py b/mastoposter/text/html.py index 8446404..386f474 100644 --- a/mastoposter/text/html.py +++ b/mastoposter/text/html.py @@ -12,6 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ + from bs4 import NavigableString from mastoposter.text import ( nodes_process, diff --git a/mastoposter/types.py b/mastoposter/types.py index 4e08038..d446e59 100644 --- a/mastoposter/types.py +++ b/mastoposter/types.py @@ -12,6 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ + from dataclasses import dataclass, field, fields from datetime import datetime from typing import Any, Callable, Optional, List, Literal, TypeVar diff --git a/mastoposter/utils.py b/mastoposter/utils.py index 2ec843a..de76ae0 100644 --- a/mastoposter/utils.py +++ b/mastoposter/utils.py @@ -12,6 +12,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ + from configparser import ConfigParser from logging import getLogger