Ajout de booking pour des One on One avec son coach,
Demande par discord au coach pour confirmer la rencontre Ajout de message automatisé discord pour avertir des nouveaux match et rappel 24h a l'avance
This commit is contained in:
+71
-27
@@ -102,6 +102,7 @@ def edit_user(user_id):
|
||||
|
||||
selected_games = request.form.getlist('games')
|
||||
discord_username = request.form.get('discord_username', '').strip()
|
||||
discord_user_id = request.form.get('discord_user_id', '').strip()
|
||||
league_os_profile = request.form.get('league_os_profile', '').strip()
|
||||
|
||||
user.full_name = full_name
|
||||
@@ -111,6 +112,7 @@ def edit_user(user_id):
|
||||
user.is_active_account = is_active
|
||||
user.games = ','.join(selected_games) if selected_games else None
|
||||
user.discord_username = discord_username or None
|
||||
user.discord_user_id = discord_user_id or None
|
||||
user.league_os_profile = league_os_profile or None
|
||||
|
||||
# Update gamertags using shared function
|
||||
@@ -241,6 +243,7 @@ def edit_profile():
|
||||
|
||||
selected_games = request.form.getlist('games')
|
||||
discord_username = request.form.get('discord_username', '').strip()
|
||||
discord_user_id = request.form.get('discord_user_id', '').strip()
|
||||
league_os_profile = request.form.get('league_os_profile', '').strip()
|
||||
|
||||
if email != current_user.email and User.query.filter_by(email=email).first():
|
||||
@@ -252,6 +255,7 @@ def edit_profile():
|
||||
current_user.phone = phone
|
||||
current_user.games = ','.join(selected_games) if selected_games else None
|
||||
current_user.discord_username = discord_username or None
|
||||
current_user.discord_user_id = discord_user_id or None
|
||||
current_user.league_os_profile = league_os_profile or None
|
||||
|
||||
# Update gamertags using shared function
|
||||
@@ -726,8 +730,11 @@ def download_signed_contract(contract_id):
|
||||
DISCORD_WEBHOOK_URL = os.environ.get('DISCORD_WEBHOOK_URL', '')
|
||||
|
||||
|
||||
def send_discord_notification(player_name, points, date_str, start_time_str, end_time_str, team_name, coach_name, coach_discord):
|
||||
"""Send a Discord webhook notification for a One on One request.
|
||||
def send_discord_notification(player_name, points, date_str, start_time_str, end_time_str, team_name, coach_name, coach_discord, coach_discord_id, request_id=None):
|
||||
"""Send a Discord notification for a One on One request.
|
||||
|
||||
Sends a DM to the coach via Discord bot if their Discord User ID is configured,
|
||||
otherwise falls back to webhook notification.
|
||||
|
||||
Args:
|
||||
player_name: Name of the player making the request.
|
||||
@@ -738,32 +745,67 @@ def send_discord_notification(player_name, points, date_str, start_time_str, end
|
||||
team_name: Name of the player's team.
|
||||
coach_name: Name of the coach.
|
||||
coach_discord: Coach's Discord username.
|
||||
coach_discord_id: Coach's Discord User ID (for DMs).
|
||||
"""
|
||||
if not DISCORD_WEBHOOK_URL:
|
||||
return # No webhook configured, skip notification
|
||||
|
||||
embed = {
|
||||
"embeds": [{
|
||||
"title": "One on One Request",
|
||||
"color": 3447003, # Blue color
|
||||
"fields": [
|
||||
{"name": "Player", "value": player_name, "inline": True},
|
||||
{"name": "Team", "value": team_name or "Unknown Team", "inline": True},
|
||||
{"name": "Date", "value": date_str, "inline": True},
|
||||
{"name": "Time", "value": f"{start_time_str} - {end_time_str}", "inline": True},
|
||||
{"name": "Discussion Points", "value": points or "No specific points provided", "inline": False}
|
||||
],
|
||||
"footer": {
|
||||
"text": f"Coach: {coach_name}" + (f" (Discord: {coach_discord})" if coach_discord else "")
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
||||
try:
|
||||
requests.post(DISCORD_WEBHOOK_URL, json=embed, timeout=5)
|
||||
except Exception:
|
||||
pass # Silently fail if webhook doesn't work
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Try to send DM via Discord bot first (requires coach's Discord User ID)
|
||||
if coach_discord_id:
|
||||
try:
|
||||
from discord_bot import send_one_on_one_dm
|
||||
send_one_on_one_dm(
|
||||
coach_name=coach_name,
|
||||
coach_discord_id=coach_discord_id,
|
||||
player_name=player_name,
|
||||
team_name=team_name,
|
||||
date_str=date_str,
|
||||
start_time=start_time_str,
|
||||
end_time=end_time_str,
|
||||
points=points,
|
||||
request_id=request_id
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to send Discord DM: {e}")
|
||||
|
||||
# Also send to webhook as backup/fallback
|
||||
if DISCORD_WEBHOOK_URL:
|
||||
try:
|
||||
from discord_bot import send_one_on_one_dm
|
||||
|
||||
# Try to send DM to webhook URL if it's a user ID
|
||||
if DISCORD_WEBHOOK_URL.isdigit() and not coach_discord_id:
|
||||
send_one_on_one_dm(
|
||||
coach_name=coach_name,
|
||||
coach_discord_id=DISCORD_WEBHOOK_URL,
|
||||
player_name=player_name,
|
||||
team_name=team_name,
|
||||
date_str=date_str,
|
||||
start_time=start_time_str,
|
||||
end_time=end_time_str,
|
||||
points=points
|
||||
)
|
||||
elif not DISCORD_WEBHOOK_URL.isdigit():
|
||||
# Legacy webhook URL - send traditional webhook embed
|
||||
embed = {
|
||||
"embeds": [{
|
||||
"title": "One on One Request",
|
||||
"color": 3447003,
|
||||
"fields": [
|
||||
{"name": "Player", "value": player_name, "inline": True},
|
||||
{"name": "Team", "value": team_name or "Unknown Team", "inline": True},
|
||||
{"name": "Date", "value": date_str, "inline": True},
|
||||
{"name": "Time", "value": f"{start_time_str} - {end_time_str}", "inline": True},
|
||||
{"name": "Discussion Points", "value": points or "No specific points provided", "inline": False}
|
||||
],
|
||||
"footer": {
|
||||
"text": f"Coach: {coach_name}" + (f" (Discord: {coach_discord})" if coach_discord else "")
|
||||
}
|
||||
}]
|
||||
}
|
||||
requests.post(DISCORD_WEBHOOK_URL, json=embed, timeout=5)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to send Discord notification: {e}")
|
||||
|
||||
@users_bp.route('/one-on-one', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@@ -858,7 +900,9 @@ def one_on_one():
|
||||
end_time_str=end_time_str,
|
||||
team_name=org_team.name if org_team else None,
|
||||
coach_name=coach.full_name,
|
||||
coach_discord=coach.discord_username
|
||||
coach_discord=coach.discord_username,
|
||||
coach_discord_id=coach.discord_user_id,
|
||||
request_id=request_obj.id
|
||||
)
|
||||
|
||||
flash('One on One request sent to your coach!', 'success')
|
||||
|
||||
Reference in New Issue
Block a user