From 6caebac9462349b5032ceb98248f257c986b9b17 Mon Sep 17 00:00:00 2001 From: justcool393 Date: Tue, 1 Nov 2022 18:46:56 -0500 Subject: [PATCH] actions: move user-only actions to useractions, which gets rid of a circular dependency --- files/helpers/actions.py | 22 ---------------------- files/helpers/casino.py | 2 +- files/helpers/cron.py | 2 +- files/helpers/lottery.py | 2 +- files/helpers/useractions.py | 23 +++++++++++++++++++++++ files/mail/__init__.py | 2 +- files/routes/admin.py | 1 + files/routes/awards.py | 1 + files/routes/hats.py | 2 +- files/routes/settings.py | 1 + 10 files changed, 31 insertions(+), 27 deletions(-) create mode 100644 files/helpers/useractions.py diff --git a/files/helpers/actions.py b/files/helpers/actions.py index b5e2192d0..488188f34 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -1,5 +1,4 @@ from flask import g -from files.classes.badges import Badge from files.helpers.alerts import send_repeatable_notification from files.helpers.const import * from files.helpers.get import * @@ -8,27 +7,6 @@ from files.helpers.slots import execute_slots_command import random from urllib.parse import quote -def badge_grant(user, badge_id, description=None, url=None, notify=True): - assert user != None - if user.has_badge(badge_id): - return - - badge = Badge( - badge_id=int(badge_id), - user_id=user.id, - description=description, - url=url, - ) - - g.db.add(badge) - g.db.flush() - - if notify: - send_repeatable_notification(user.id, - f"@AutoJanny has given you the following profile badge:\n\n" + - f"![]({badge.path})\n\n**{badge.name}**\n\n{badge.badge.description}") - - headers = {'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'} def archiveorg(url): diff --git a/files/helpers/casino.py b/files/helpers/casino.py index fd3f59a61..98388cd8a 100644 --- a/files/helpers/casino.py +++ b/files/helpers/casino.py @@ -1,6 +1,6 @@ from files.__main__ import app, limiter, db_session from files.helpers.wrappers import * -from files.helpers.actions import badge_grant +from files.helpers.useractions import badge_grant from files.helpers.alerts import * from files.helpers.get import * from files.helpers.const import * diff --git a/files/helpers/cron.py b/files/helpers/cron.py index 2dd3a8918..eb0704e61 100644 --- a/files/helpers/cron.py +++ b/files/helpers/cron.py @@ -4,7 +4,7 @@ from files.helpers.const import * from files.helpers.alerts import send_repeatable_notification from files.helpers.roulette import spin_roulette_wheel from files.helpers.get import * -from files.helpers.actions import * +from files.helpers.useractions import * from files.classes import * from files.__main__ import cache diff --git a/files/helpers/lottery.py b/files/helpers/lottery.py index eb8310f8c..19b0b5e19 100644 --- a/files/helpers/lottery.py +++ b/files/helpers/lottery.py @@ -3,7 +3,7 @@ from random import choice from sqlalchemy import * from files.helpers.alerts import * from files.helpers.wrappers import * -from files.helpers.actions import * +from files.helpers.useractions import * from flask import g from .const import * diff --git a/files/helpers/useractions.py b/files/helpers/useractions.py new file mode 100644 index 000000000..e8b3ffb01 --- /dev/null +++ b/files/helpers/useractions.py @@ -0,0 +1,23 @@ +from flask import g +from files.classes.badges import Badge +from files.helpers.alerts import send_repeatable_notification + +def badge_grant(user, badge_id, description=None, url=None, notify=True): + assert user != None + if user.has_badge(badge_id): + return + + badge = Badge( + badge_id=int(badge_id), + user_id=user.id, + description=description, + url=url, + ) + + g.db.add(badge) + g.db.flush() + + if notify: + send_repeatable_notification(user.id, + f"@AutoJanny has given you the following profile badge:\n\n" + + f"![]({badge.path})\n\n**{badge.name}**\n\n{badge.badge.description}") \ No newline at end of file diff --git a/files/mail/__init__.py b/files/mail/__init__.py index 5a15dfdae..54b925662 100644 --- a/files/mail/__init__.py +++ b/files/mail/__init__.py @@ -7,7 +7,7 @@ from files.helpers.security import * from files.helpers.wrappers import * from files.helpers.const import * from files.helpers.get import * -from files.helpers.actions import * +from files.helpers.useractions import * from files.classes import * from files.__main__ import app, limiter diff --git a/files/routes/admin.py b/files/routes/admin.py index 4757cad0f..0ea30e237 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -11,6 +11,7 @@ from files.helpers.get import * from files.helpers.media import * from files.helpers.const import * from files.helpers.actions import * +from files.helpers.useractions import * from files.helpers.cloudflare import * from files.classes import * from flask import * diff --git a/files/routes/awards.py b/files/routes/awards.py index 754d901c4..b6afb2e39 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -5,6 +5,7 @@ from files.helpers.get import * from files.helpers.const import * from files.helpers.regex import * from files.helpers.actions import * +from files.helpers.useractions import * from files.classes.award import * from .front import frontlist from flask import g, request diff --git a/files/routes/hats.py b/files/routes/hats.py index 355df90e3..5f0bfdba2 100644 --- a/files/routes/hats.py +++ b/files/routes/hats.py @@ -3,7 +3,7 @@ from files.classes.hats import * from files.helpers.alerts import * from files.helpers.wrappers import * from files.helpers.const import * -from files.helpers.actions import * +from files.helpers.useractions import * from flask import g @app.get("/hats") diff --git a/files/routes/settings.py b/files/routes/settings.py index 2289f1abb..d0ba13464 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -4,6 +4,7 @@ from files.helpers.sanitize import * from files.helpers.const import * from files.helpers.regex import * from files.helpers.actions import * +from files.helpers.useractions import * from files.helpers.get import * from files.helpers.security import * from files.mail import *