This commit is contained in:
Flatlogic Bot 2026-02-16 02:59:27 +00:00
parent 04bb805022
commit 184c4889b4
8 changed files with 355 additions and 133 deletions

27
api/save_settings.php Normal file
View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
require_once __DIR__ . '/../db/config.php';
header('Content-Type: application/json');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['success' => false, 'error' => 'Invalid method']);
exit;
}
$data = [
'discord_token' => $_POST['discord_token'] ?? '',
'voice_channel_id' => $_POST['voice_channel_id'] ?? '',
'sahur_time' => $_POST['sahur_time'] ?? '03:30',
];
try {
$db = db();
foreach ($data as $key => $value) {
$stmt = $db->prepare('INSERT INTO bot_settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = ?');
$stmt->execute([$key, $value, $value]);
}
echo json_encode(['success' => true]);
} catch (PDOException $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}

0
assets/audio/sahur.mp3 Normal file
View File

126
assets/css/custom.css Normal file
View File

@ -0,0 +1,126 @@
:root {
--primary: #10b981;
--primary-hover: #059669;
--bg: #f8fafc;
--surface: #ffffff;
--text: #1e293b;
--text-muted: #64748b;
--border: #e2e8f0;
--radius: 4px;
}
body {
background-color: var(--bg);
color: var(--text);
font-family: 'Inter', system-ui, -apple-system, sans-serif;
line-height: 1.5;
margin: 0;
}
.container {
max-width: 800px;
margin: 40px auto;
padding: 0 20px;
}
.card {
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 24px;
margin-bottom: 24px;
}
.card-title {
font-size: 1.25rem;
font-weight: 600;
margin: 0 0 16px 0;
display: flex;
align-items: center;
gap: 8px;
}
.form-group {
margin-bottom: 16px;
}
.form-label {
display: block;
font-size: 0.875rem;
font-weight: 500;
margin-bottom: 4px;
color: var(--text-muted);
}
.form-control {
width: 100%;
padding: 8px 12px;
border: 1px solid var(--border);
border-radius: var(--radius);
font-size: 0.875rem;
transition: border-color 0.2s;
box-sizing: border-box;
}
.form-control:focus {
outline: none;
border-color: var(--primary);
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 8px 16px;
border-radius: var(--radius);
font-size: 0.875rem;
font-weight: 500;
cursor: pointer;
transition: all 0.2s;
border: 1px solid transparent;
}
.btn-primary {
background: var(--primary);
color: white;
}
.btn-primary:hover {
background: var(--primary-hover);
}
.badge {
display: inline-flex;
padding: 2px 8px;
font-size: 0.75rem;
font-weight: 600;
border-radius: 9999px;
text-transform: uppercase;
}
.badge-disconnected {
background: #fee2e2;
color: #991b1b;
}
.badge-connected {
background: #dcfce7;
color: #166534;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 32px;
}
.header h1 {
font-size: 1.5rem;
margin: 0;
}
.audio-player {
width: 100%;
margin-top: 8px;
}

54
assets/js/main.js Normal file
View File

@ -0,0 +1,54 @@
document.addEventListener('DOMContentLoaded', () => {
const configForm = document.getElementById('config-form');
const testAudioBtn = document.getElementById('test-audio-btn');
const audioPlayer = document.querySelector('.audio-player');
if (configForm) {
configForm.addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(configForm);
const submitBtn = configForm.querySelector('button[type="submit"]');
const originalBtnText = submitBtn.textContent;
submitBtn.disabled = true;
submitBtn.textContent = 'Saving...';
try {
const response = await fetch('api/save_settings.php', {
method: 'POST',
body: formData
});
const result = await response.json();
if (result.success) {
alert('Settings saved successfully!');
} else {
alert('Error: ' + result.error);
}
} catch (error) {
alert('Network error while saving settings.');
} finally {
submitBtn.disabled = false;
submitBtn.textContent = originalBtnText;
}
});
}
if (testAudioBtn && audioPlayer) {
testAudioBtn.addEventListener('click', () => {
if (audioPlayer.paused) {
audioPlayer.play();
testAudioBtn.textContent = 'Pause';
} else {
audioPlayer.pause();
testAudioBtn.textContent = 'Test Play Locally';
}
});
audioPlayer.addEventListener('ended', () => {
testAudioBtn.textContent = 'Test Play Locally';
});
}
});

50
bot/index.js Normal file
View File

@ -0,0 +1,50 @@
const { Client, GatewayIntentBits, Collection } = require('discord.js');
const { joinVoiceChannel, createAudioPlayer, createAudioResource, AudioPlayerStatus } = require('@discordjs/voice');
const { CronJob } = require('cron');
const path = require('path');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences
]
});
// Settings from DB or Env
const VC_ID = process.env.VC_ID || '1457687430189682781';
const AUDIO_PATH = path.join(__dirname, '../assets/audio/sahur.mp3');
client.once('ready', () => {
console.log('Bot is ready!');
// Sahur Alarm: 03:30 Asia/Jakarta
new CronJob('30 03 * * *', async () => {
const guild = client.guilds.cache.first(); // Simplified for single server
const channel = guild.channels.cache.get(VC_ID);
if (channel) {
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: guild.id,
adapterCreator: guild.voiceAdapterCreator,
});
const player = createAudioPlayer();
const resource = createAudioResource(AUDIO_PATH);
player.play(resource);
connection.subscribe(player);
player.on(AudioPlayerStatus.Idle, () => {
connection.destroy();
});
}
}, null, true, 'Asia/Jakarta');
});
client.login(process.env.DISCORD_TOKEN);

13
bot/package.json Normal file
View File

@ -0,0 +1,13 @@
{
"name": "sahur-bot",
"version": "1.0.0",
"description": "Discord Sahur Bot",
"main": "index.js",
"dependencies": {
"discord.js": "^14.11.0",
"cron": "^2.3.1",
"@discordjs/voice": "^0.16.0",
"libsodium-wrappers": "^0.7.10",
"ffmpeg-static": "^5.1.0"
}
}

View File

@ -0,0 +1,5 @@
CREATE TABLE IF NOT EXISTS bot_settings (
setting_key VARCHAR(255) PRIMARY KEY,
setting_value TEXT,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

213
index.php
View File

@ -1,150 +1,97 @@
<?php
declare(strict_types=1);
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
@date_default_timezone_set('UTC');
require_once __DIR__ . '/db/config.php';
$phpVersion = PHP_VERSION;
$now = date('Y-m-d H:i:s');
// Fetch settings
$settings = [];
try {
$stmt = db()->query("SELECT setting_key, setting_value FROM bot_settings");
while ($row = $stmt->fetch()) {
$settings[$row['setting_key']] = $row['setting_value'];
}
} catch (PDOException $e) {
// Table might not exist yet or other DB error
}
$discordToken = $settings['discord_token'] ?? '';
$voiceChannelId = $settings['voice_channel_id'] ?? '1457687430189682781';
$sahurTime = $settings['sahur_time'] ?? '03:30';
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Discord Bot for Sahur Alarm and Music';
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>New Style</title>
<?php
// Read project preview data from environment
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
?>
<?php if ($projectDescription): ?>
<!-- Meta description -->
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
<!-- Open Graph meta tags -->
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<!-- Twitter meta tags -->
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<?php endif; ?>
<?php if ($projectImageUrl): ?>
<!-- Open Graph image -->
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<!-- Twitter image -->
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<?php endif; ?>
<title>Sahur Bot Command Center</title>
<meta name="description" content="<?= htmlspecialchars($projectDescription) ?>" />
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-color-start: #6a11cb;
--bg-color-end: #2575fc;
--text-color: #ffffff;
--card-bg-color: rgba(255, 255, 255, 0.01);
--card-border-color: rgba(255, 255, 255, 0.1);
}
body {
margin: 0;
font-family: 'Inter', sans-serif;
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
color: var(--text-color);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
text-align: center;
overflow: hidden;
position: relative;
}
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
animation: bg-pan 20s linear infinite;
z-index: -1;
}
@keyframes bg-pan {
0% { background-position: 0% 0%; }
100% { background-position: 100% 100%; }
}
main {
padding: 2rem;
}
.card {
background: var(--card-bg-color);
border: 1px solid var(--card-border-color);
border-radius: 16px;
padding: 2rem;
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
}
.loader {
margin: 1.25rem auto 1.25rem;
width: 48px;
height: 48px;
border: 3px solid rgba(255, 255, 255, 0.25);
border-top-color: #fff;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.hint {
opacity: 0.9;
}
.sr-only {
position: absolute;
width: 1px; height: 1px;
padding: 0; margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap; border: 0;
}
h1 {
font-size: 3rem;
font-weight: 700;
margin: 0 0 1rem;
letter-spacing: -1px;
}
p {
margin: 0.5rem 0;
font-size: 1.1rem;
}
code {
background: rgba(0,0,0,0.2);
padding: 2px 6px;
border-radius: 4px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
footer {
position: absolute;
bottom: 1rem;
font-size: 0.8rem;
opacity: 0.7;
}
</style>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?= time() ?>">
</head>
<body>
<main>
<div class="card">
<h1>Analyzing your requirements and generating your website…</h1>
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
<span class="sr-only">Loading…</span>
<div class="container">
<header class="header">
<div>
<h1>Sahur Bot</h1>
<p style="margin:0; color:var(--text-muted); font-size: 0.875rem;">Command Center</p>
</div>
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
<p class="hint">This page will update automatically as the plan is implemented.</p>
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
<div id="bot-status">
<span class="badge badge-disconnected">Offline</span>
</div>
</header>
<div class="card">
<h2 class="card-title">Bot Configuration</h2>
<form id="config-form">
<div class="form-group">
<label class="form-label" for="discord_token">Discord Bot Token</label>
<input type="password" id="discord_token" name="discord_token" class="form-control" placeholder="MTAx..." value="<?= htmlspecialchars($discordToken) ?>">
<small style="color:var(--text-muted); font-size: 0.75rem;">Never share your token with anyone.</small>
</div>
<div class="form-group">
<label class="form-label" for="voice_channel_id">Voice Channel ID</label>
<input type="text" id="voice_channel_id" name="voice_channel_id" class="form-control" placeholder="1457..." value="<?= htmlspecialchars($voiceChannelId) ?>">
</div>
<div class="form-group">
<label class="form-label" for="sahur_time">Alarm Time (WIB)</label>
<input type="time" id="sahur_time" name="sahur_time" class="form-control" value="<?= htmlspecialchars($sahurTime) ?>">
</div>
<button type="submit" class="btn btn-primary">Save Settings</button>
</form>
</div>
</main>
<footer>
Page updated: <?= htmlspecialchars($now) ?> (UTC)
</footer>
<div class="card">
<h2 class="card-title">Sound Preview</h2>
<p style="color:var(--text-muted); font-size: 0.875rem; margin-bottom: 12px;">This sound will be played in the voice channel at <?= htmlspecialchars($sahurTime) ?> WIB.</p>
<audio controls class="audio-player">
<source src="assets/audio/sahur.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<div style="margin-top: 16px;">
<button id="test-audio-btn" class="btn" style="border: 1px solid var(--border);">Test Play Locally</button>
</div>
</div>
<div class="card">
<h2 class="card-title">Bot Code Status</h2>
<p style="color:var(--text-muted); font-size: 0.875rem;">The <code>discord.js v14</code> bot skeleton has been generated in the <code>/bot</code> directory.</p>
<div style="background: #f1f5f9; padding: 12px; border-radius: var(--radius); font-family: monospace; font-size: 0.75rem; color: #334155; margin-top: 8px;">
# To start the bot:<br>
cd bot<br>
npm install<br>
DISCORD_TOKEN="your_token" node index.js
</div>
</div>
<footer style="margin-top: 48px; text-align: center; color: var(--text-muted); font-size: 0.75rem;">
&copy; <?= date('Y') ?> Sahur Bot &bull; Powered by Flatlogic LAMP
</footer>
</div>
<script src="assets/js/main.js?v=<?= time() ?>"></script>
</body>
</html>