2022-06-15 19:33:21 +00:00
|
|
|
from flask import g
|
|
|
|
from files.classes.badges import Badge
|
|
|
|
from files.helpers.alerts import send_repeatable_notification
|
2022-06-06 04:07:38 +00:00
|
|
|
|
2022-06-15 20:08:26 +00:00
|
|
|
def badge_grant(user, badge_id, description=None, url=None):
|
2022-06-15 21:17:31 +00:00
|
|
|
assert user != None
|
2022-06-15 20:29:25 +00:00
|
|
|
if user.has_badge(badge_id):
|
2022-06-15 20:08:26 +00:00
|
|
|
return
|
2022-06-06 04:07:38 +00:00
|
|
|
|
|
|
|
badge = Badge(
|
2022-06-15 20:08:26 +00:00
|
|
|
badge_id=int(badge_id),
|
|
|
|
user_id=user.id,
|
|
|
|
description=description,
|
|
|
|
url=url,
|
2022-06-06 04:07:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
g.db.add(badge)
|
2022-06-15 19:33:21 +00:00
|
|
|
g.db.flush()
|
|
|
|
|
2022-06-15 20:08:26 +00:00
|
|
|
send_repeatable_notification(user.id,
|
|
|
|
f"@AutoJanny has given you the following profile badge:\n\n" +
|
|
|
|
f"![]({badge.path})\n\n{badge.name}")
|