Use user mastodon settings
This commit is contained in:
parent
a5ffbec8d4
commit
6140cca5bf
3 changed files with 25 additions and 14 deletions
|
|
@ -1,5 +1,5 @@
|
|||
from peewee import *
|
||||
from settings import SQLITE_DB
|
||||
from settings import SQLITE_DB, MASTODON_INSTANCE
|
||||
|
||||
database = SqliteDatabase(SQLITE_DB)
|
||||
|
||||
|
|
@ -33,6 +33,12 @@ class User(BaseModel):
|
|||
mastodon_attn_list = TextField(null=True)
|
||||
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:
|
||||
table_name = 'user'
|
||||
|
||||
|
|
|
|||
30
orders.py
30
orders.py
|
|
@ -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 mastodon import Mastodon
|
||||
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
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
async def order_mastodon_post(session, orders_pool, orders_str, repeats, due_at):
|
||||
# TODO: Get user's mastodon username
|
||||
post = "Here are today's orders for @%s -\n\n" % MASTODON_USERNAME
|
||||
user = orders_pool.user
|
||||
|
||||
post = "Here are today's orders for @%s -\n\n" % user.mastodon_account()
|
||||
post += orders_str + "\n\n"
|
||||
if repeats > 1:
|
||||
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"
|
||||
|
||||
if user.mastodon_attn_list:
|
||||
post += f"ATTN - {user.mastodon_attn_list}\n"
|
||||
|
||||
if ENV == 'dev':
|
||||
post += "⚠️ DEV"
|
||||
else:
|
||||
post += "CC - @chicagogear @s10boi"
|
||||
|
||||
m = Mastodon(session)
|
||||
return await m.statusPost(post)
|
||||
|
|
@ -90,14 +93,17 @@ async def order_issue(orders_pool):
|
|||
orders_str
|
||||
)
|
||||
|
||||
async def punishment_mastodon_post(session, punishment_str, reply_id=None):
|
||||
# TODO: Get user's mastodon username
|
||||
post = "@%s has failed to post proof of compliance. Here is the punishment -\n\n" % MASTODON_USERNAME
|
||||
async def punishment_mastodon_post(session, orders_pool, punishment_str, reply_id=None):
|
||||
user = orders_pool.user
|
||||
|
||||
post = "@%s has failed to post proof of compliance. Here is the punishment -\n\n" % user.mastodon_account()
|
||||
post += punishment_str + "\n\n"
|
||||
|
||||
if user.mastodon_attn_list:
|
||||
post += f"ATTN - {user.mastodon_attn_list}\n"
|
||||
|
||||
if ENV == 'dev':
|
||||
post += "⚠️ DEV"
|
||||
else:
|
||||
post += "CC - @chicagogear @s10boi"
|
||||
|
||||
m = Mastodon(session)
|
||||
return await m.statusPost(
|
||||
|
|
@ -128,6 +134,7 @@ async def punishment_issue(session, order_status):
|
|||
|
||||
punishment_status = await punishment_mastodon_post(
|
||||
session,
|
||||
punishment_pool,
|
||||
punishment_str,
|
||||
order_status.mastodon_id,
|
||||
)
|
||||
|
|
@ -166,8 +173,7 @@ async def order_check(order_status_id):
|
|||
for d in context['descendants']:
|
||||
if (
|
||||
d['in_reply_to_id'] == order_status.mastodon_id and
|
||||
# TODO: Get mastodon username
|
||||
d['account']['username'] == MASTODON_USERNAME and
|
||||
d['account']['username'] == order_status.user.mastodon_account() and
|
||||
len(d['media_attachments']) > 0
|
||||
):
|
||||
confirmed_at = d['created_at']
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ ORDER_TIME = os.environ.get('ORDER_TIME', '9:00')
|
|||
ORDER_TIMEOUT = datetime.timedelta(
|
||||
hours=os.environ.get('ORDER_TIMEOUT', 3)
|
||||
)
|
||||
MASTODON_USERNAME = os.environ.get('MASTODON_USERNAME')
|
||||
|
||||
MASTODON_INSTANCE = os.environ.get("MASTODON_INSTANCE")
|
||||
MASTODON_ACCESS_TOKEN = os.environ.get('MASTODON_ACCESS_TOKEN')
|
||||
|
|
|
|||
Loading…
Reference in a new issue