Compare commits

..

5 Commits

Author SHA1 Message Date
Flatlogic Bot
48fb3678a0 v6 2026-02-17 16:19:48 +00:00
Flatlogic Bot
e22abc064b vvvt 2026-02-17 15:58:54 +00:00
Flatlogic Bot
24e2560989 Autosave: 20260217-155238 2026-02-17 15:52:38 +00:00
Flatlogic Bot
c342af73fb Jjk 2026-02-17 14:52:07 +00:00
Flatlogic Bot
9f44967a26 Autosave: 20260217-143154 2026-02-17 14:31:54 +00:00
15 changed files with 2071 additions and 138 deletions

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

@ -0,0 +1,101 @@
body {
background-color: #fafafa;
color: #1a1a1a;
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
font-size: 0.9rem;
line-height: 1.5;
}
.container {
max-width: 900px;
}
.card {
background-color: #ffffff;
border: 1px solid #e0e0e0;
border-radius: 4px;
box-shadow: none;
margin-bottom: 2rem;
}
.card-header {
background-color: #ffffff;
border-bottom: 1px solid #e0e0e0;
padding: 1rem 1.5rem;
font-weight: 700;
text-transform: uppercase;
font-size: 0.75rem;
letter-spacing: 0.05em;
color: #666;
}
.card-body {
padding: 1.5rem;
}
.btn-primary {
background-color: #000;
border-color: #000;
border-radius: 4px;
padding: 0.5rem 1.25rem;
font-weight: 600;
font-size: 0.8rem;
}
.btn-primary:hover {
background-color: #333;
border-color: #333;
}
.status-badge {
display: inline-flex;
align-items: center;
padding: 0.25rem 0.5rem;
border-radius: 4px;
font-size: 0.75rem;
font-weight: 600;
}
.status-online {
background-color: #e6f4ea;
color: #1e8e3e;
}
.status-offline {
background-color: #fce8e6;
color: #d93025;
}
pre {
background-color: #f1f1f1;
padding: 1rem;
border-radius: 4px;
font-size: 0.8rem;
color: #333;
}
.form-control {
border-radius: 4px;
border: 1px solid #e0e0e0;
padding: 0.6rem;
}
.form-control:focus {
border-color: #000;
box-shadow: none;
}
h1, h2, h3 {
font-weight: 700;
letter-spacing: -0.02em;
}
.nav-link {
color: #666;
font-weight: 500;
}
.nav-link.active {
color: #000 !important;
font-weight: 700;
}

157
bot.log Normal file
View File

@ -0,0 +1,157 @@
Keep-Alive server is running on port 8080
Sodium encryption is ready
Logged in as AsepXiaoQin#6954!
Bot Status: Online
Uncaught exception: Error: Cannot utilize the DAVE protocol as the @snazzah/davey package has not been installed.
- Use the generateDependencyReport() function for more information.
at new DAVESession (/home/ubuntu/executor/workspace/node_modules/@discordjs/voice/dist/index.js:746:13)
at Networking.createDaveSession (/home/ubuntu/executor/workspace/node_modules/@discordjs/voice/dist/index.js:1467:21)
at Networking.onWsPacket (/home/ubuntu/executor/workspace/node_modules/@discordjs/voice/dist/index.js:1602:20)
at VoiceWebSocket.emit (node:events:530:35)
at VoiceWebSocket.onMessage (/home/ubuntu/executor/workspace/node_modules/@discordjs/voice/dist/index.js:1239:10)
at VoiceWebSocket.ws.onmessage (/home/ubuntu/executor/workspace/node_modules/@discordjs/voice/dist/index.js:1182:39)
at callListener (/home/ubuntu/executor/workspace/node_modules/ws/lib/event-target.js:290:14)
at WebSocket.onMessage (/home/ubuntu/executor/workspace/node_modules/ws/lib/event-target.js:209:9)
at WebSocket.emit (node:events:518:28)
at Receiver.receiverOnMessage (/home/ubuntu/executor/workspace/node_modules/ws/lib/websocket.js:1225:20)
Bot Status: Playing
Bot Status: Playing
Bot Status: Playing
Uncaught exception: Error: spawn /home/ubuntu/executor/workspace/node_modules/ffmpeg-static/ffmpeg ENOENT
at ChildProcess._handle.onexit (node:internal/child_process:285:19)
at onErrorNT (node:internal/child_process:483:16)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn /home/ubuntu/executor/workspace/node_modules/ffmpeg-static/ffmpeg',
path: '/home/ubuntu/executor/workspace/node_modules/ffmpeg-static/ffmpeg',
spawnargs: [
'-i',
'/home/ubuntu/executor/workspace/sahur.mp3',
'-analyzeduration',
'0',
'-loglevel',
'0',
'-acodec',
'libopus',
'-f',
'opus',
'-ar',
'48000',
'-ac',
'2',
'pipe:1'
]
}
Uncaught exception: Error: Cannot utilize the DAVE protocol as the @snazzah/davey package has not been installed.
- Use the generateDependencyReport() function for more information.
at new DAVESession (/home/ubuntu/executor/workspace/node_modules/@discordjs/voice/dist/index.js:746:13)
at Networking.createDaveSession (/home/ubuntu/executor/workspace/node_modules/@discordjs/voice/dist/index.js:1467:21)
at Networking.onWsPacket (/home/ubuntu/executor/workspace/node_modules/@discordjs/voice/dist/index.js:1602:20)
at VoiceWebSocket.emit (node:events:530:35)
at VoiceWebSocket.onMessage (/home/ubuntu/executor/workspace/node_modules/@discordjs/voice/dist/index.js:1239:10)
at VoiceWebSocket.ws.onmessage (/home/ubuntu/executor/workspace/node_modules/@discordjs/voice/dist/index.js:1182:39)
at callListener (/home/ubuntu/executor/workspace/node_modules/ws/lib/event-target.js:290:14)
at WebSocket.onMessage (/home/ubuntu/executor/workspace/node_modules/ws/lib/event-target.js:209:9)
at WebSocket.emit (node:events:518:28)
at Receiver.receiverOnMessage (/home/ubuntu/executor/workspace/node_modules/ws/lib/websocket.js:1225:20)
Bot Status: Playing
Uncaught exception: Error: spawn /home/ubuntu/executor/workspace/node_modules/ffmpeg-static/ffmpeg ENOENT
at ChildProcess._handle.onexit (node:internal/child_process:285:19)
at onErrorNT (node:internal/child_process:483:16)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn /home/ubuntu/executor/workspace/node_modules/ffmpeg-static/ffmpeg',
path: '/home/ubuntu/executor/workspace/node_modules/ffmpeg-static/ffmpeg',
spawnargs: [
'-i',
'/home/ubuntu/executor/workspace/sahur.mp3',
'-analyzeduration',
'0',
'-loglevel',
'0',
'-acodec',
'libopus',
'-f',
'opus',
'-ar',
'48000',
'-ac',
'2',
'pipe:1'
]
}
Bot Status: Playing
Uncaught exception: Error: spawn /home/ubuntu/executor/workspace/node_modules/ffmpeg-static/ffmpeg ENOENT
at ChildProcess._handle.onexit (node:internal/child_process:285:19)
at onErrorNT (node:internal/child_process:483:16)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn /home/ubuntu/executor/workspace/node_modules/ffmpeg-static/ffmpeg',
path: '/home/ubuntu/executor/workspace/node_modules/ffmpeg-static/ffmpeg',
spawnargs: [
'-i',
'/home/ubuntu/executor/workspace/sahur.mp3',
'-analyzeduration',
'0',
'-loglevel',
'0',
'-acodec',
'libopus',
'-f',
'opus',
'-ar',
'48000',
'-ac',
'2',
'pipe:1'
]
}
Uncaught exception: Error: Cannot utilize the DAVE protocol as the @snazzah/davey package has not been installed.
- Use the generateDependencyReport() function for more information.
at new DAVESession (/home/ubuntu/executor/workspace/node_modules/@discordjs/voice/dist/index.js:746:13)
at Networking.createDaveSession (/home/ubuntu/executor/workspace/node_modules/@discordjs/voice/dist/index.js:1467:21)
at Networking.onWsPacket (/home/ubuntu/executor/workspace/node_modules/@discordjs/voice/dist/index.js:1602:20)
at VoiceWebSocket.emit (node:events:530:35)
at VoiceWebSocket.onMessage (/home/ubuntu/executor/workspace/node_modules/@discordjs/voice/dist/index.js:1239:10)
at VoiceWebSocket.ws.onmessage (/home/ubuntu/executor/workspace/node_modules/@discordjs/voice/dist/index.js:1182:39)
at callListener (/home/ubuntu/executor/workspace/node_modules/ws/lib/event-target.js:290:14)
at WebSocket.onMessage (/home/ubuntu/executor/workspace/node_modules/ws/lib/event-target.js:209:9)
at WebSocket.emit (node:events:518:28)
at Receiver.receiverOnMessage (/home/ubuntu/executor/workspace/node_modules/ws/lib/websocket.js:1225:20)
Bot Status: Playing
Uncaught exception: Error: spawn /home/ubuntu/executor/workspace/node_modules/ffmpeg-static/ffmpeg ENOENT
at ChildProcess._handle.onexit (node:internal/child_process:285:19)
at onErrorNT (node:internal/child_process:483:16)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn /home/ubuntu/executor/workspace/node_modules/ffmpeg-static/ffmpeg',
path: '/home/ubuntu/executor/workspace/node_modules/ffmpeg-static/ffmpeg',
spawnargs: [
'-i',
'/home/ubuntu/executor/workspace/sahur.mp3',
'-analyzeduration',
'0',
'-loglevel',
'0',
'-acodec',
'libopus',
'-f',
'opus',
'-ar',
'48000',
'-ac',
'2',
'pipe:1'
]
}
[Deploy] 2026-02-17 16:19:33
Started refreshing 2 application (/) commands.
Successfully reloaded 2 application (/) commands.

28
bot_control.php Normal file
View File

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
function isBotRunning(): bool {
$output = [];
exec("ps aux | grep 'node index.js' | grep -v grep", $output);
return !empty($output);
}
if (isset($_GET['action'])) {
if ($_GET['action'] === 'start') {
if (!isBotRunning()) {
// Run in background
exec("nohup node index.js > bot.log 2>&1 &");
sleep(1); // Give it a second to start
}
} elseif ($_GET['action'] === 'stop') {
// Find PID and kill
$output = [];
exec("ps aux | grep 'node index.js' | grep -v grep | awk '{print $2}'", $output);
foreach ($output as $pid) {
exec("kill $pid");
}
sleep(1);
}
header("Location: index.php");
exit;
}

4
config.json Normal file
View File

@ -0,0 +1,4 @@
{
"DISCORD_TOKEN": "MTQ3MTkwOTE5Mzg4Njg1OTI5NA.GN4TSo.GJ2qwdMUfFHHvJb0EUzSplAAdeHCCXwJy2K128",
"DISCORD_CLIENT_ID": "1471909193886859294"
}

View File

@ -0,0 +1,6 @@
CREATE TABLE IF NOT EXISTS settings (
setting_key VARCHAR(50) PRIMARY KEY,
setting_value TEXT
);
INSERT IGNORE INTO settings (setting_key, setting_value) VALUES ('discord_token', ''), ('application_id', '');

52
deploy.js Normal file
View File

@ -0,0 +1,52 @@
const { REST, Routes, SlashCommandBuilder } = require('discord.js');
const fs = require('fs');
const path = require('path');
// Load config
let TOKEN, CLIENT_ID;
try {
const configPath = path.join(__dirname, 'config.json');
if (fs.existsSync(configPath)) {
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
TOKEN = config.DISCORD_TOKEN;
CLIENT_ID = config.DISCORD_CLIENT_ID;
} else {
TOKEN = process.env.DISCORD_TOKEN;
CLIENT_ID = process.env.DISCORD_CLIENT_ID;
}
} catch (err) {
console.error('ERROR: config.json is invalid or error reading it.');
process.exit(1);
}
if (!TOKEN || !CLIENT_ID) {
console.error('ERROR: DISCORD_TOKEN or DISCORD_CLIENT_ID is missing in config.json.');
process.exit(1);
}
const commands = [
new SlashCommandBuilder()
.setName('join')
.setDescription('Masuk ke Voice Channel kamu'),
new SlashCommandBuilder()
.setName('sahur')
.setDescription('Masuk ke Voice Channel dan putar alarm sahur'),
].map(command => command.toJSON());
const rest = new REST({ version: '10' }).setToken(TOKEN);
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
const data = await rest.put(
Routes.applicationCommands(CLIENT_ID),
{ body: commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
process.exit(1);
}
})();

17
deploy_commands.php Normal file
View File

@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
// Run the deploy command
$output = [];
$return_var = 0;
exec("node deploy.js 2>&1", $output, $return_var);
$log = implode("\n", $output);
file_put_contents('bot.log', "[Deploy] " . date('Y-m-d H:i:s') . "\n" . $log . "\n\n", FILE_APPEND);
if ($return_var === 0) {
header("Location: index.php?deploy_success=1");
} else {
header("Location: index.php?deploy_error=1");
}
exit;

17
healthz.php Normal file
View File

@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
function isBotRunning(): bool {
$output = [];
exec("ps aux | grep 'node index.js' | grep -v grep", $output);
return !empty($output);
}
if (isBotRunning()) {
http_response_code(200);
echo "Bot is ONLINE";
} else {
// Optionally try to restart it? No, just report status
http_response_code(503);
echo "Bot is OFFLINE";
}

140
index.js Normal file
View File

@ -0,0 +1,140 @@
const ffmpeg = require('ffmpeg-static');
const { generateDependencyReport } = require('@discordjs/voice');
console.log(generateDependencyReport());
// --- ENCRYPTION & AUDIO CONFIG ---
// Wajib di baris paling atas agar enkripsi Discord terdeteksi dengan benar
process.env.FFMPEG_PATH = ffmpeg;
require('libsodium-wrappers');
// --- KEEP ALIVE ---
// Membuat server sederhana agar bot merespons ping dari sistem
// Port 8080 digunakan untuk internal health check
http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('Bot is Online and Healthy');
res.end();
}).listen(8080, '0.0.0.0', () => {
console.log('Keep-Alive server is running on port 8080');
});
// --- ERROR HANDLING ---
// Mencegah bot mati jika terjadi error yang tidak terduga
process.on('unhandledRejection', error => {
console.error('Unhandled promise rejection:', error);
});
process.on('uncaughtException', error => {
console.error('Uncaught exception:', error);
});
const {
Client,
GatewayIntentBits
} = require('discord.js');
const {
joinVoiceChannel,
createAudioPlayer,
createAudioResource,
AudioPlayerStatus,
VoiceConnectionStatus,
getVoiceConnection
} = require('@discordjs/voice');
// --- CONFIGURATION ---
let TOKEN, CLIENT_ID;
try {
const config = require('./config.json');
TOKEN = config.DISCORD_TOKEN;
CLIENT_ID = config.DISCORD_CLIENT_ID;
} catch (err) {
console.warn('Warning: config.json not found. Using environment variables if available.');
TOKEN = process.env.DISCORD_TOKEN;
CLIENT_ID = process.env.DISCORD_CLIENT_ID;
}
if (!TOKEN) {
console.error('ERROR: DISCORD_TOKEN is missing. Please set it in the dashboard.');
}
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
]
});
// Helper function to join voice
function connectToVoice(interaction) {
return joinVoiceChannel({
channelId: interaction.member.voice.channel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
selfDeaf: true,
selfMute: false,
});
}
client.on('clientReady', () => {
console.log(`Logged in as ${client.user.tag}!`);
console.log('Bot Status: Online');
});
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;
const { commandName } = interaction;
if (commandName === 'join') {
await interaction.deferReply();
try {
connectToVoice(interaction);
await interaction.editReply('Berhasil masuk ke Voice Channel!');
} catch (error) {
await interaction.editReply({ content: error.message, ephemeral: true });
}
}
if (commandName === 'sahur') {
await interaction.deferReply();
try {
let connection = getVoiceConnection(interaction.guild.id);
if (!connection) {
connection = connectToVoice(interaction);
}
const player = createAudioPlayer();
const resource = createAudioResource(path.join(process.cwd(), 'sahur.mp3'));
connection.subscribe(player);
player.play(resource);
console.log('Bot Status: Playing');
await interaction.editReply('🔊 Sedang memutar alarm sahur!');
player.on(AudioPlayerStatus.Idle, () => {
console.log('Bot Status: Finished playing (Idle)');
});
player.on('error', e => {
console.error('ERROR_AUDIO:', e.message);
interaction.followUp({ content: 'Terjadi kesalahan saat memutar audio.', ephemeral: true });
});
} catch (error) {
console.error('ERROR:', error);
await interaction.editReply(error.message || 'Gagal memutar audio.');
}
}
});
if (TOKEN) {
client.login(TOKEN).catch(err => {
console.error('Login failed:', err.message);
});
} else {
console.log('Bot Status: Waiting for token setup...');
}

303
index.php
View File

@ -1,150 +1,177 @@
<?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';
// Fetch settings
$settings = [];
try {
$stmt = db()->query("SELECT * FROM settings");
while ($row = $stmt->fetch()) {
$settings[$row['setting_key']] = $row['setting_value'];
}
} catch (Exception $e) {
// Table might not exist yet or other error
}
$discordToken = $settings['discord_token'] ?? '';
$applicationId = $settings['application_id'] ?? '';
// Helper function to check if bot is running (simplified)
function isBotRunning(): bool {
$output = [];
exec("ps aux | grep 'node index.js' | grep -v grep", $output);
return !empty($output);
}
// Project info
$projectName = $_SERVER['PROJECT_NAME'] ?? 'Sahur Alarm Bot';
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Discord voice bot for sahur alarms.';
$phpVersion = PHP_VERSION;
$now = date('Y-m-d H:i:s');
?>
<!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; ?>
<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>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?= htmlspecialchars($projectName) ?> - Control Panel</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/css/custom.css?v=<?= time() ?>" rel="stylesheet">
<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;500;600;700&display=swap" rel="stylesheet">
</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>
<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>
<nav class="navbar navbar-expand-lg navbar-light bg-white border-bottom mb-4">
<div class="container">
<a class="navbar-brand" href="#"><?= htmlspecialchars($projectName) ?></a>
<div class="ms-auto d-flex align-items-center">
<span class="status-badge <?= isBotRunning() ? 'status-online' : 'status-offline' ?> me-3">
<?= isBotRunning() ? '● ONLINE' : '○ OFFLINE' ?>
</span>
<?php if (isBotRunning()): ?>
<a href="bot_control.php?action=stop" class="btn btn-danger btn-sm">Stop Bot</a>
<?php else: ?>
<a href="bot_control.php?action=start" class="btn btn-success btn-sm">Start Bot</a>
<?php endif; ?>
</div>
</div>
</main>
<footer>
Page updated: <?= htmlspecialchars($now) ?> (UTC)
</footer>
</nav>
<div class="container">
<div class="row">
<div class="col-md-8">
<div class="card">
<div class="card-header">System Overview</div>
<div class="card-body">
<h3>Welcome to your Sahur Bot Panel</h3>
<p class="text-muted"><?= htmlspecialchars($projectDescription) ?></p>
<hr>
<h5>Bot Source Code (index.js)</h5>
<p>The bot is built using Node.js and discord.js v14. It handles the <code>/join</code> and <code>/sahur</code> commands, joins your voice channel, and plays the alarm.</p>
<div class="alert alert-light border">
<strong>Quick Start:</strong>
<ol class="mb-0 mt-2">
<li>Masukkan <strong>Application ID</strong> dan <strong>Bot Token</strong> di panel kanan, lalu klik <strong>Save</strong>.</li>
<li>Klik <strong>Deploy Slash Commands</strong> agar perintah <code>/join</code> dan <code>/sahur</code> muncul di Discord.</li>
<li>Klik <strong>Start Bot</strong> untuk mengaktifkan bot.</li>
</ol>
</div>
</div>
</div>
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<span>Logs & Activity</span>
<button class="btn btn-link btn-sm p-0 text-decoration-none" onclick="location.reload()">Refresh</button>
</div>
<div class="card-body">
<pre id="bot-logs" style="max-height: 300px; overflow-y: auto; background: #1e1e1e; color: #d4d4d4; padding: 15px; border-radius: 4px; font-family: 'Courier New', monospace; font-size: 0.85rem;"><?php
if (file_exists('bot.log')) {
$logs = file_get_contents('bot.log');
echo htmlspecialchars($logs ?: '[Empty logs]');
} else {
echo '[System] No logs found. Start the bot to generate logs.';
}
?></pre>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-header">Audio Management</div>
<div class="card-body">
<p class="small text-muted">Upload your <code>sahur.mp3</code> file here. Ensure it is named exactly <code>sahur.mp3</code>.</p>
<form action="upload_audio.php" method="post" enctype="multipart/form-data">
<div class="mb-3">
<input class="form-control" type="file" name="audio_file" accept=".mp3" required>
</div>
<button type="submit" class="btn btn-primary w-100">Upload MP3</button>
</form>
<?php if (file_exists('sahur.mp3')): ?>
<div class="mt-3 p-2 border rounded bg-light d-flex align-items-center">
<span class="me-2">🔊</span>
<span class="small">sahur.mp3 (<?= round(filesize('sahur.mp3') / 1024 / 1024, 2) ?> MB)</span>
</div>
<?php else: ?>
<div class="mt-3 p-2 border rounded bg-light text-danger small">
⚠️ sahur.mp3 not found.
</div>
<?php endif; ?>
</div>
</div>
<div class="card">
<div class="card-header">Bot Configuration</div>
<div class="card-body">
<p class="small text-muted">To link your bot, you need to provide credentials from the Discord Developer Portal.</p>
<?php if (isset($_GET['success'])): ?>
<div class="alert alert-success py-1 small">Settings saved!</div>
<?php endif; ?>
<?php if (isset($_GET['deploy_success'])): ?>
<div class="alert alert-success py-1 small">Slash commands deployed!</div>
<?php endif; ?>
<?php if (isset($_GET['deploy_error'])): ?>
<div class="alert alert-danger py-1 small">Error deploying commands. Check logs.</div>
<?php endif; ?>
<?php if (isset($_GET['error'])): ?>
<div class="alert alert-danger py-1 small">Error saving settings.</div>
<?php endif; ?>
<form action="save_settings.php" method="post">
<div class="mb-3">
<label class="form-label small fw-bold">Application ID</label>
<input type="text" name="application_id" class="form-control form-control-sm" placeholder="Paste ID here" value="<?= htmlspecialchars($applicationId) ?>">
</div>
<div class="mb-3">
<label class="form-label small fw-bold">Bot Token</label>
<input type="password" name="discord_token" class="form-control form-control-sm" placeholder="Paste Token here" value="<?= htmlspecialchars($discordToken) ?>">
</div>
<button type="submit" class="btn btn-primary btn-sm w-100 mb-2">Save Configuration</button>
</form>
<hr>
<label class="form-label small fw-bold">Command Deployment</label>
<p class="x-small text-muted" style="font-size: 0.7rem;">Click this if slash commands (<code>/sahur</code>) are not showing up in Discord.</p>
<a href="deploy_commands.php" class="btn btn-outline-secondary btn-sm w-100">Deploy Slash Commands</a>
<p class="text-center x-small mt-3 text-muted" style="font-size: 0.7rem;">Config is saved to the database and <code>config.json</code>.</p>
</div>
</div>
</div>
</div>
</div>
<footer class="text-center py-4 text-muted border-top bg-white mt-5">
<div class="container">
<p class="mb-0 small">&copy; <?= date('Y') ?> <?= htmlspecialchars($projectName) ?>. Built with LAMP + Node.js.</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

1311
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

20
package.json Normal file
View File

@ -0,0 +1,20 @@
{
"name": "sahur-alarm-bot",
"version": "1.0.0",
"description": "Discord Sahur Alarm Bot",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"@discordjs/opus": "0.9.0",
"@discordjs/voice": "0.16.1",
"@snazzah/davey": "^0.1.9",
"discord.js": "^14.14.1",
"ffmpeg-static": "5.1.0",
"libsodium-wrappers": "^0.8.2",
"opusscript": "^0.0.8",
"sodium-native": "^5.0.10",
"tweetnacl": "^1.0.3"
}
}

BIN
sahur.mp3 Normal file

Binary file not shown.

29
save_settings.php Normal file
View File

@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
require_once __DIR__ . '/db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$token = $_POST['discord_token'] ?? '';
$app_id = $_POST['application_id'] ?? '';
try {
$stmt = db()->prepare("UPDATE settings SET setting_value = ? WHERE setting_key = 'discord_token'");
$stmt->execute([$token]);
$stmt = db()->prepare("UPDATE settings SET setting_value = ? WHERE setting_key = 'application_id'");
$stmt->execute([$app_id]);
// Generate config.json for the Node.js bot
$config = [
'DISCORD_TOKEN' => $token,
'DISCORD_CLIENT_ID' => $app_id
];
file_put_contents(__DIR__ . '/config.json', json_encode($config, JSON_PRETTY_PRINT));
header('Location: index.php?success=1');
exit;
} catch (Exception $e) {
header('Location: index.php?error=' . urlencode($e->getMessage()));
exit;
}
}

24
upload_audio.php Normal file
View File

@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['audio_file'])) {
$file = $_FILES['audio_file'];
// Validate file type
$ext = pathinfo($file['name'], PATHINFO_EXTENSION);
if (strtolower($ext) !== 'mp3') {
die("Only MP3 files are allowed.");
}
// Move to sahur.mp3
$destination = __DIR__ . '/sahur.mp3';
if (move_uploaded_file($file['tmp_name'], $destination)) {
header("Location: index.php?upload=success");
exit;
} else {
die("Failed to move uploaded file.");
}
} else {
header("Location: index.php");
exit;
}