Auto commit: 2026-02-19T00:22:46.855Z
This commit is contained in:
parent
3ce02134e3
commit
020ba95f1c
@ -51,6 +51,12 @@ if ($method === 'POST') {
|
||||
if ($requester !== 'Anónimo') {
|
||||
require_once __DIR__ . '/../includes/points_helper.php';
|
||||
awardPoints($requester, 25);
|
||||
|
||||
if ($source === 'whatsapp') {
|
||||
announceWhatsAppRequest($requester, $artist, $song);
|
||||
} else {
|
||||
announceSongRequest($requester, $artist, $song);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if this user is now the #1 listener of the week
|
||||
|
||||
@ -36,6 +36,25 @@ function awardPoints($username, $pointsToAdd) {
|
||||
return $newPoints;
|
||||
}
|
||||
|
||||
function getNextLevelInfo($username) {
|
||||
$db = db();
|
||||
$stmt = $db->prepare("SELECT points FROM fans WHERE name = ?");
|
||||
$stmt->execute([$username]);
|
||||
$points = $stmt->fetchColumn() ?: 0;
|
||||
|
||||
$milestones = [100, 500, 1000, 2500, 5000, 10000];
|
||||
foreach ($milestones as $level => $threshold) {
|
||||
if ($points < $threshold) {
|
||||
return [
|
||||
'next_level' => $level + 1,
|
||||
'points_needed' => $threshold - $points,
|
||||
'current_points' => $points
|
||||
];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function announceLevelUp($username, $level, $points) {
|
||||
$db = db();
|
||||
$messages = [
|
||||
@ -53,3 +72,57 @@ function announceLevelUp($username, $level, $points) {
|
||||
$db->prepare("INSERT INTO messages (username, ip_address, message, type) VALUES (?, ?, ?, ?)")
|
||||
->execute(['Lili Bot 🤖', $ip, $message, 'text']);
|
||||
}
|
||||
|
||||
function announceWhatsAppRequest($username, $artist, $song) {
|
||||
$db = db();
|
||||
$nextLevel = getNextLevelInfo($username);
|
||||
|
||||
$levelMsg = "";
|
||||
if ($nextLevel) {
|
||||
$needed = $nextLevel['points_needed'];
|
||||
$lvl = $nextLevel['next_level'];
|
||||
$levelMsg = " 🚀 ¡Solo te faltan **$needed** puntos para el **Nivel $lvl**!";
|
||||
}
|
||||
|
||||
$messages = [
|
||||
"📱 ¡Nueva petición por WhatsApp! **$username** acaba de pedir **$artist - $song**. ¡Marchando! 🤖🎶$levelMsg",
|
||||
"✨ ¡Suena el WhatsApp! **$username** quiere escuchar **$artist - $song**. ¡Enseguida la ponemos! 🤖📡$levelMsg",
|
||||
"🎧 **$username** nos escribe por WhatsApp para pedir **$artist - $song**. ¡Petición concedida! 🤖🔥$levelMsg",
|
||||
"🚀 ¡Petición relámpago! **$username** ha pedido **$artist - $song** vía WhatsApp. ¡Disfrútala! 🤖✨$levelMsg"
|
||||
];
|
||||
|
||||
$message = $messages[array_rand($messages)];
|
||||
|
||||
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'] ?? $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1';
|
||||
$ip = explode(',', $ip)[0];
|
||||
|
||||
$db->prepare("INSERT INTO messages (username, ip_address, message, type) VALUES (?, ?, ?, ?)")
|
||||
->execute(['Lili Bot 🤖', $ip, $message, 'text']);
|
||||
}
|
||||
|
||||
function announceSongRequest($username, $artist, $song) {
|
||||
$db = db();
|
||||
$nextLevel = getNextLevelInfo($username);
|
||||
|
||||
$levelMsg = "";
|
||||
if ($nextLevel) {
|
||||
$needed = $nextLevel['points_needed'];
|
||||
$lvl = $nextLevel['next_level'];
|
||||
$levelMsg = " 🚀 ¡Estás a **$needed** puntos del **Nivel $lvl**!";
|
||||
}
|
||||
|
||||
$messages = [
|
||||
"🎵 **$username** ha pedido **$artist - $song**. ¡Gran elección! 🤖✨$levelMsg",
|
||||
"🎶 ¡Suena una petición de **$username**! **$artist - $song**. ¡A disfrutar! 🤖🔥$levelMsg",
|
||||
"🎸 **$username** quiere escuchar **$artist - $song**. ¡Marchando! 🤖🚀$levelMsg",
|
||||
"🎧 ¡Nueva canción pedida por **$username**: **$artist - $song**! 🤖🌟$levelMsg"
|
||||
];
|
||||
|
||||
$message = $messages[array_rand($messages)];
|
||||
|
||||
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'] ?? $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1';
|
||||
$ip = explode(',', $ip)[0];
|
||||
|
||||
$db->prepare("INSERT INTO messages (username, ip_address, message, type) VALUES (?, ?, ?, ?)")
|
||||
->execute(['Lili Bot 🤖', $ip, $message, 'text']);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user