Use user mastodon settings

This commit is contained in:
Johnny Gear 2026-03-05 19:48:04 -06:00
parent a5ffbec8d4
commit 6140cca5bf
3 changed files with 25 additions and 14 deletions

View file

@ -1,5 +1,5 @@
from peewee import * from peewee import *
from settings import SQLITE_DB from settings import SQLITE_DB, MASTODON_INSTANCE
database = SqliteDatabase(SQLITE_DB) database = SqliteDatabase(SQLITE_DB)
@ -33,6 +33,12 @@ class User(BaseModel):
mastodon_attn_list = TextField(null=True) mastodon_attn_list = TextField(null=True)
mastodon_post_public = BooleanField(null=True, default=False) mastodon_post_public = BooleanField(null=True, default=False)
def mastodon_account(self):
if self.mastodon_server.name == MASTODON_INSTANCE:
return f"@{self.mastodon_username}"
else:
return f"@{self.mastodon_username}@{self.mastodon_server}"
class Meta: class Meta:
table_name = 'user' table_name = 'user'

View file

@ -7,22 +7,25 @@ from generate import generate_order, generate_punishment
from db.queries import order_status_by_id, order_status_put, order_status_confirm from db.queries import order_status_by_id, order_status_put, order_status_confirm
from mastodon import Mastodon from mastodon import Mastodon
from telegram.telegram import Telegram from telegram.telegram import Telegram
from settings import MASTODON_USERNAME, ORDER_TIMEOUT, ENV from settings import ORDER_TIMEOUT, ENV, MASTODON_INSTANCE
from util import timezone from util import timezone
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
async def order_mastodon_post(session, orders_pool, orders_str, repeats, due_at): async def order_mastodon_post(session, orders_pool, orders_str, repeats, due_at):
# TODO: Get user's mastodon username user = orders_pool.user
post = "Here are today's orders for @%s -\n\n" % MASTODON_USERNAME
post = "Here are today's orders for @%s -\n\n" % user.mastodon_account()
post += orders_str + "\n\n" post += orders_str + "\n\n"
if repeats > 1: if repeats > 1:
post += f"These are the same orders from the last {repeats} days\n\n" post += f"These are the same orders from the last {repeats} days\n\n"
post += "Proof of compliance is due by " + due_at.strftime("%I:%M %p") + "\n\n" post += "Proof of compliance is due by " + due_at.strftime("%I:%M %p") + "\n\n"
if user.mastodon_attn_list:
post += f"ATTN - {user.mastodon_attn_list}\n"
if ENV == 'dev': if ENV == 'dev':
post += "⚠️ DEV" post += "⚠️ DEV"
else:
post += "CC - @chicagogear @s10boi"
m = Mastodon(session) m = Mastodon(session)
return await m.statusPost(post) return await m.statusPost(post)
@ -90,14 +93,17 @@ async def order_issue(orders_pool):
orders_str orders_str
) )
async def punishment_mastodon_post(session, punishment_str, reply_id=None): async def punishment_mastodon_post(session, orders_pool, punishment_str, reply_id=None):
# TODO: Get user's mastodon username user = orders_pool.user
post = "@%s has failed to post proof of compliance. Here is the punishment -\n\n" % MASTODON_USERNAME
post = "@%s has failed to post proof of compliance. Here is the punishment -\n\n" % user.mastodon_account()
post += punishment_str + "\n\n" post += punishment_str + "\n\n"
if user.mastodon_attn_list:
post += f"ATTN - {user.mastodon_attn_list}\n"
if ENV == 'dev': if ENV == 'dev':
post += "⚠️ DEV" post += "⚠️ DEV"
else:
post += "CC - @chicagogear @s10boi"
m = Mastodon(session) m = Mastodon(session)
return await m.statusPost( return await m.statusPost(
@ -128,6 +134,7 @@ async def punishment_issue(session, order_status):
punishment_status = await punishment_mastodon_post( punishment_status = await punishment_mastodon_post(
session, session,
punishment_pool,
punishment_str, punishment_str,
order_status.mastodon_id, order_status.mastodon_id,
) )
@ -166,8 +173,7 @@ async def order_check(order_status_id):
for d in context['descendants']: for d in context['descendants']:
if ( if (
d['in_reply_to_id'] == order_status.mastodon_id and d['in_reply_to_id'] == order_status.mastodon_id and
# TODO: Get mastodon username d['account']['username'] == order_status.user.mastodon_account() and
d['account']['username'] == MASTODON_USERNAME and
len(d['media_attachments']) > 0 len(d['media_attachments']) > 0
): ):
confirmed_at = d['created_at'] confirmed_at = d['created_at']

View file

@ -7,7 +7,6 @@ ORDER_TIME = os.environ.get('ORDER_TIME', '9:00')
ORDER_TIMEOUT = datetime.timedelta( ORDER_TIMEOUT = datetime.timedelta(
hours=os.environ.get('ORDER_TIMEOUT', 3) hours=os.environ.get('ORDER_TIMEOUT', 3)
) )
MASTODON_USERNAME = os.environ.get('MASTODON_USERNAME')
MASTODON_INSTANCE = os.environ.get("MASTODON_INSTANCE") MASTODON_INSTANCE = os.environ.get("MASTODON_INSTANCE")
MASTODON_ACCESS_TOKEN = os.environ.get('MASTODON_ACCESS_TOKEN') MASTODON_ACCESS_TOKEN = os.environ.get('MASTODON_ACCESS_TOKEN')