diff --git a/db/models.py b/db/models.py index b9eed6a..6bbbc02 100644 --- a/db/models.py +++ b/db/models.py @@ -46,6 +46,9 @@ class User(BaseModel): return self.mastodon_username else: return f"{self.mastodon_username}@{self.mastodon_server}" + + def mastodon_visibility(self): + return 'public' if self.mastodon_post_public else 'direct' def __str__(self): return self.telegram_username diff --git a/mastodon.py b/mastodon.py index 6167d76..b32e742 100644 --- a/mastodon.py +++ b/mastodon.py @@ -1,6 +1,6 @@ import logging -from settings import MASTODON_INSTANCE, MASTODON_ACCESS_TOKEN, MASTODON_VISIBILITY +from settings import MASTODON_INSTANCE, MASTODON_ACCESS_TOKEN API_STATUSES = '/api/v1/statuses' API_STATUS_CONTEXT = '/api/v1/statuses/%(id)s/context' @@ -48,13 +48,15 @@ class Mastodon: return await response.json() - async def statusPost(self, status, in_reply_to_id=None): + async def statusPost(self, status, user, in_reply_to_id=None): + visibility = user.mastodon_visibility() + return await self.post( self.instance, API_STATUSES, data={ 'status': status, - 'visibility': MASTODON_VISIBILITY, + 'visibility': visibility, 'in_reply_to_id': in_reply_to_id }) diff --git a/orders.py b/orders.py index 4cde582..742065b 100644 --- a/orders.py +++ b/orders.py @@ -31,7 +31,7 @@ async def order_mastodon_post(session, orders_pool, orders_str, repeats, due_at, post += f"ATTN - {user.mastodon_attn_list}\n" m = Mastodon(session) - return await m.statusPost(post) + return await m.statusPost(post, user) async def order_telegram_post(session, orders_pool, orders_str, repeats, due_at, m_url, verify_at=None): post = "Here are your orders -\n\n" @@ -139,7 +139,8 @@ async def punishment_mastodon_post(session, orders_pool, punishment_str, reply_i m = Mastodon(session) return await m.statusPost( - post, + post, + user, in_reply_to_id=reply_id ) diff --git a/settings.py b/settings.py index 541a9b0..f784f0c 100644 --- a/settings.py +++ b/settings.py @@ -5,7 +5,6 @@ ENV = os.environ.get('ENV', 'dev') MASTODON_INSTANCE = os.environ.get("MASTODON_INSTANCE") MASTODON_ACCESS_TOKEN = os.environ.get('MASTODON_ACCESS_TOKEN') -MASTODON_VISIBILITY = os.environ.get('MASTODON_VISIBILITY', 'direct') MASTODON_CC_LIST = os.environ.get('MASTODON_CC_LIST', '') MASTODON_OAUTH_SCOPES = os.environ.get('MASTODON_OAUTH_SCOPES', 'profile')