File Update

indentations
This commit is contained in:
Thomas
2025-10-06 21:16:06 +02:00
parent a184c31cca
commit 655347dbf5
6 changed files with 310 additions and 6 deletions

View File

@@ -1 +1,128 @@
<?php require_once __DIR__.'/guard.php'; require_login(); $db=new PDO('sqlite:'.dirname(__DIR__).'/data/app.db'); $msg=''; if($_SERVER['REQUEST_METHOD']==='POST'){ if(isset($_POST['open'])){ $o1=trim($_POST['opt1']??''); $o2=trim($_POST['opt2']??''); if($o1&&$o2){ $st=$db->prepare('INSERT INTO bets(status,option1,option2,created_ts) VALUES(?,?,?,?)'); $st->execute(['open',$o1,$o2,gmdate('c')]); $msg='Bet åbnet.'; } } if(isset($_POST['close'])){ $db->exec("UPDATE bets SET status='closed', close_ts='".gmdate('c')."' WHERE status='open'"); $msg='Bet lukket.'; } if(isset($_POST['resolve'])){ $win=(int)($_POST['winner']??1); $last=$db->query("SELECT * FROM bets WHERE status='closed' ORDER BY id DESC LIMIT 1")->fetch(PDO::FETCH_ASSOC); if($last){ $st=$db->prepare('SELECT user_login, amount FROM bet_entries WHERE bet_id=? AND option=?'); $st->execute([$last['id'],$win]); $wins=$st->fetchAll(PDO::FETCH_ASSOC); foreach($wins as $w){ $db->prepare('INSERT INTO points(user_login,display_name,points) VALUES(?,?,?) ON CONFLICT(user_login) DO UPDATE SET points=points+excluded.points')->execute([$w['user_login'],$w['user_login'],(int)$w['amount']*2]); } $db->prepare('UPDATE bets SET status="resolved", resolved_option=? WHERE id=?')->execute([$win,$last['id']]); $msg='Bet resolved, vinder: option '.$win; } } } $last=$db->query('SELECT * FROM bets ORDER BY id DESC LIMIT 1')->fetch(PDO::FETCH_ASSOC); $entries=$last?$db->query('SELECT * FROM bet_entries WHERE bet_id='.(int)$last['id'])->fetchAll(PDO::FETCH_ASSOC):[]; ?><!DOCTYPE html><html><head><meta charset="utf-8"><title>Bets</title><link rel="stylesheet" href="style.css"></head><body><div class="wrap"><div class="card"><h2>💸 Bets</h2><p><a class="btn" href="index.php">← Tilbage</a></p><?php if($msg): ?><p class="notice"><?php echo htmlspecialchars($msg); ?></p><?php endif; ?><form method="post" style="margin-bottom:1rem"><label>Option 1<input name="opt1" placeholder="Team A"></label><br><label>Option 2<input name="opt2" placeholder="Team B"></label><br><button class="btn" name="open" value="1">Åbn nyt bet</button> <button class="btn" name="close" value="1">Luk indskud</button> <label>Vinder (1/2)<input name="winner" value="1"></label> <button class="btn" name="resolve" value="1">Afslut & udbetal</button></form><?php if($last): ?><p>Status: <span class="badge"><?php echo htmlspecialchars($last['status']); ?></span> #<?php echo (int)$last['id']; ?> (<?php echo htmlspecialchars($last['option1'].' vs '.$last['option2']); ?>)</p><h3>Indskud</h3><table><tr><th>Bruger</th><th>Beløb</th><th>Option</th></tr><?php foreach($entries as $e){ echo '<tr><td>@'.htmlspecialchars($e['user_login']).'</td><td>'.(int)$e['amount'].'</td><td>'.(int)$e['option'].'</td></tr>'; } ?></table><?php endif; ?></div></div></body></html> <?php
require_once __DIR__ . '/guard.php';
require_login();
$db = new PDO('sqlite:' . dirname(__DIR__) . '/data/app.db');
$msg = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Åbn nyt bet
if (isset($_POST['open'])) {
$o1 = trim($_POST['opt1'] ?? '');
$o2 = trim($_POST['opt2'] ?? '');
if ($o1 && $o2) {
$st = $db->prepare('INSERT INTO bets (status, option1, option2, created_ts) VALUES (?, ?, ?, ?)');
$st->execute(['open', $o1, $o2, gmdate('c')]);
$msg = 'Bet åbnet.';
}
}
// Luk indskud
if (isset($_POST['close'])) {
$db->exec("UPDATE bets SET status='closed', close_ts='" . gmdate('c') . "' WHERE status='open'");
$msg = 'Bet lukket.';
}
// Afslut og udbetal
if (isset($_POST['resolve'])) {
$win = (int)($_POST['winner'] ?? 1);
$win = ($win === 2) ? 2 : 1; // clamp til 1/2
$last = $db->query("SELECT * FROM bets WHERE status='closed' ORDER BY id DESC LIMIT 1")
->fetch(PDO::FETCH_ASSOC);
if ($last) {
// Find vindere
$st = $db->prepare('SELECT user_login, amount FROM bet_entries WHERE bet_id = ? AND option = ?');
$st->execute([$last['id'], $win]);
$wins = $st->fetchAll(PDO::FETCH_ASSOC);
// Udbetal 2x indsats (UPSERT på points-tabellen)
foreach ($wins as $w) {
$db->prepare(
'INSERT INTO points (user_login, display_name, points)
VALUES (?, ?, ?)
ON CONFLICT(user_login) DO UPDATE SET points = points + excluded.points'
)->execute([$w['user_login'], $w['user_login'], (int)$w['amount'] * 2]);
}
// Marker bet som resolved (STRINGSKONSTANT med enkeltanførselstegn)
$db->prepare("UPDATE bets SET status='resolved', resolved_option=? WHERE id=?")
->execute([$win, $last['id']]);
$msg = 'Bet resolved, vinder: option ' . $win;
}
}
}
$last = $db->query('SELECT * FROM bets ORDER BY id DESC LIMIT 1')->fetch(PDO::FETCH_ASSOC);
$entries = $last ? $db->query('SELECT * FROM bet_entries WHERE bet_id=' . (int)$last['id'])->fetchAll(PDO::FETCH_ASSOC) : [];
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Bets</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="wrap">
<div class="card">
<h2>💸 Bets</h2>
<p><a class="btn" href="index.php">← Tilbage</a></p>
<?php if ($msg): ?>
<p class="notice"><?php echo htmlspecialchars($msg); ?></p>
<?php endif; ?>
<form method="post" style="margin-bottom:1rem">
<label>
Option 1
<input name="opt1" placeholder="Team A">
</label>
<br>
<label>
Option 2
<input name="opt2" placeholder="Team B">
</label>
<br>
<button class="btn" name="open" value="1">Åbn nyt bet</button>
<button class="btn" name="close" value="1">Luk indskud</button>
<label>
Vinder (1/2)
<input name="winner" value="1">
</label>
<button class="btn" name="resolve" value="1">Afslut & udbetal</button>
</form>
<?php if ($last): ?>
<p>
Status:
<span class="badge"><?php echo htmlspecialchars($last['status']); ?></span>
#<?php echo (int)$last['id']; ?>
(<?php echo htmlspecialchars($last['option1'] . ' vs ' . $last['option2']); ?>)
</p>
<h3>Indskud</h3>
<table>
<tr>
<th>Bruger</th>
<th>Beløb</th>
<th>Option</th>
</tr>
<?php foreach ($entries as $e): ?>
<tr>
<td>@<?php echo htmlspecialchars($e['user_login']); ?></td>
<td><?php echo (int)$e['amount']; ?></td>
<td><?php echo (int)$e['option']; ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
</div>
</div>
</body>
</html>

View File

@@ -1 +1,131 @@
<?php require_once __DIR__.'/guard.php'; require_login(); $file=__DIR__.'/../data/commands.json'; $out=__DIR__.'/../data/outbox.txt'; $cmds=file_exists($file)?json_decode(file_get_contents($file),true):[]; $editing=''; $editText=''; if($_SERVER['REQUEST_METHOD']==='POST'){ $a=$_POST['action']??''; if($a==='save'){ $name=strtolower(trim($_POST['name']??'')); $text=trim($_POST['text']??''); if($name&&$text){ $cmds[$name]=$text; file_put_contents($file,json_encode($cmds,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE)); } header('Location: commands.php?saved=1'); exit; } if($a==='delete'){ $name=strtolower(trim($_POST['name']??'')); if(isset($cmds[$name])){ unset($cmds[$name]); file_put_contents($file,json_encode($cmds,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE)); } header('Location: commands.php?deleted=1'); exit; } if($a==='edit'){ $editing=strtolower(trim($_POST['name']??'')); $editText=$cmds[$editing]??''; } if($a==='send'){ $name=strtolower(trim($_POST['name']??'')); if(isset($cmds[$name])) file_put_contents($out,$cmds[$name].PHP_EOL,FILE_APPEND); header('Location: commands.php?sent=1'); exit; } } ?><!DOCTYPE html><html><head><meta charset="utf-8"><title>Kommandoer</title><link rel="stylesheet" href="style.css"><script>function confirmDelete(n){return confirm('Slet !'+n+'?')}</script></head><body><div class="wrap"><div class="card"><h2>Bot-kommandoer</h2><p><a class="btn" href="index.php">← Tilbage</a><a class="btn" href="help.php" target="_blank">📖 Hjælp</a></p><form method="post" style="margin-bottom:1rem"><input type="hidden" name="action" value="save"><label>!kommando (uden !) <input name="name" required value="<?php echo htmlspecialchars($editing); ?>"></label><br><label>Svar <textarea name="text" rows="3" required><?php echo htmlspecialchars($editText); ?></textarea></label><br><button class="btn"><?php echo $editing?'Opdater':'Gem'; ?></button></form><table><tr><th>!kommando</th><th>Svar</th><th>Handling</th></tr><?php foreach($cmds as $k=>$v): ?><tr><td><?php echo '!'.htmlspecialchars($k); ?></td><td><?php echo htmlspecialchars($v); ?></td><td><form method="post" style="display:inline"><input type="hidden" name="action" value="edit"><input type="hidden" name="name" value="<?php echo htmlspecialchars($k); ?>"><button class="btn">Redigér</button></form> <form method="post" style="display:inline" onsubmit="return confirmDelete('<?php echo htmlspecialchars($k); ?>')"><input type="hidden" name="action" value="delete"><input type="hidden" name="name" value="<?php echo htmlspecialchars($k); ?>"><button class="btn">Slet</button></form> <form method="post" style="display:inline"><input type="hidden" name="action" value="send"><input type="hidden" name="name" value="<?php echo htmlspecialchars($k); ?>"><button class="btn">Send nu</button></form></td></tr><?php endforeach; ?></table></div></div></body></html> <?php
require_once __DIR__ . '/guard.php';
require_login();
$file = __DIR__ . '/../data/commands.json';
$out = __DIR__ . '/../data/outbox.txt';
$cmds = file_exists($file) ? json_decode(file_get_contents($file), true) : [];
$editing = '';
$editText = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$a = $_POST['action'] ?? '';
if ($a === 'save') {
$name = strtolower(trim($_POST['name'] ?? ''));
$text = trim($_POST['text'] ?? '');
if ($name && $text) {
$cmds[$name] = $text;
file_put_contents($file, json_encode($cmds, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
}
header('Location: commands.php?saved=1');
exit;
}
if ($a === 'delete') {
$name = strtolower(trim($_POST['name'] ?? ''));
if (isset($cmds[$name])) {
unset($cmds[$name]);
file_put_contents($file, json_encode($cmds, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
}
header('Location: commands.php?deleted=1');
exit;
}
if ($a === 'edit') {
$editing = strtolower(trim($_POST['name'] ?? ''));
$editText = $cmds[$editing] ?? '';
}
if ($a === 'send') {
$name = strtolower(trim($_POST['name'] ?? ''));
if (isset($cmds[$name])) {
file_put_contents($out, $cmds[$name] . PHP_EOL, FILE_APPEND);
}
header('Location: commands.php?sent=1');
exit;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Kommandoer</title>
<link rel="stylesheet" href="style.css">
<script>
function confirmDelete(n) {
return confirm('Slet !' + n + '?');
}
</script>
</head>
<body>
<div class="wrap">
<div class="card">
<h2>Bot-kommandoer</h2>
<p>
<a class="btn" href="index.php">← Tilbage</a>
<a class="btn" href="help.php" target="_blank">📖 Hjælp</a>
</p>
<form method="post" style="margin-bottom:1rem">
<input type="hidden" name="action" value="save">
<label>
!kommando (uden !)
<input name="name" required value="<?php echo htmlspecialchars($editing); ?>">
</label>
<br>
<label>
Svar
<textarea name="text" rows="3" required><?php echo htmlspecialchars($editText); ?></textarea>
</label>
<br>
<button class="btn"><?php echo $editing ? 'Opdater' : 'Gem'; ?></button>
</form>
<table>
<tr>
<th>!kommando</th>
<th>Svar</th>
<th>Handling</th>
</tr>
<?php foreach ($cmds as $k => $v): ?>
<tr>
<td><?php echo '!' . htmlspecialchars($k); ?></td>
<td><?php echo htmlspecialchars($v); ?></td>
<td>
<form method="post" style="display:inline">
<input type="hidden" name="action" value="edit">
<input type="hidden" name="name" value="<?php echo htmlspecialchars($k); ?>">
<button class="btn">Redigér</button>
</form>
<form method="post" style="display:inline" onsubmit="return confirmDelete('<?php echo htmlspecialchars($k); ?>')">
<input type="hidden" name="action" value="delete">
<input type="hidden" name="name" value="<?php echo htmlspecialchars($k); ?>">
<button class="btn">Slet</button>
</form>
<form method="post" style="display:inline">
<input type="hidden" name="action" value="send">
<input type="hidden" name="name" value="<?php echo htmlspecialchars($k); ?>">
<button class="btn">Send nu</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
</body>
</html>

View File

@@ -1 +1,33 @@
<?php $base=dirname(__DIR__); $stop=$base.'/data/stop.flag'; $bat=$base.'/start_bot.bat'; $a=$_GET['action']??''; if($a==='start'){ $cmd='cmd /c start "" /min "'.$bat.'"'; if(function_exists('popen'))@pclose(@popen($cmd,'r')); else @shell_exec($cmd.' >NUL 2>&1'); header('Location: index.php'); exit; } if($a==='stop'){ file_put_contents($stop,'1'); header('Location: index.php'); exit; } if($a==='restart'){ file_put_contents($stop,'1'); echo '<meta http-equiv="refresh" content="1; url=control.php?action=start">Genstarter...'; exit; } header('Location: index.php'); <?php
$base = dirname(__DIR__);
$stop = $base . '/data/stop.flag';
$bat = $base . '/start_bot.bat';
$action = $_GET['action'] ?? '';
if ($action === 'start') {
$cmd = 'cmd /c start "" /min "' . $bat . '"';
if (function_exists('popen')) {
@pclose(@popen($cmd, 'r'));
} else {
@shell_exec($cmd . ' >NUL 2>&1');
}
header('Location: index.php');
exit;
}
if ($action === 'stop') {
file_put_contents($stop, '1');
header('Location: index.php');
exit;
}
if ($action === 'restart') {
file_put_contents($stop, '1');
echo '<meta http-equiv="refresh" content="1; url=control.php?action=start">Genstarter...';
exit;
}
header('Location: index.php');

View File

@@ -55,17 +55,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<meta charset="utf-8"> <meta charset="utf-8">
<title>Login Twitch PHP Bot</title> <title>Login Twitch PHP Bot</title>
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
<style>.login-box{max-width:400px;margin:100px auto}</style> <style>.login-box{max-width:400px;margin:1% auto}</style>
</head> </head>
<body> <body>
<div id="bg-image"></div>
<div class="wrap"> <div class="wrap">
<div class="card login-box"> <div class="card login-box">
<h2>🔐 Login</h2> <h2>🔐 Login</h2>
<?php if ($error): ?><p class="notice" style="color:#ff8080"><?php echo htmlspecialchars($error); ?></p><?php endif; ?> <?php if ($error): ?><p class="notice" style="color:#ff8080"><?php echo htmlspecialchars($error); ?></p><?php endif; ?>
<form method="post"> <form method="post">
<label>Brugernavn</label> <label>Brugernavn / Username</label>
<input type="text" name="username" required> <input type="text" name="username" required>
<label>Adgangskode</label> <label>Adgangskode / Password</label>
<input type="password" name="password" required> <input type="password" name="password" required>
<br> <br>
<button class="btn" type="submit">Log ind</button> <button class="btn" type="submit">Log ind</button>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

View File

@@ -133,3 +133,17 @@ td {
.right { .right {
float: right; float: right;
} }
html {
height: 100%;
width: 100%;
}
#bg-image {
height: 100%;
width: 100%;
position: fixed;
background-image: url(logo.png);
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
opacity: 0.3;
}