-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.php
More file actions
772 lines (667 loc) · 25.2 KB
/
commands.php
File metadata and controls
772 lines (667 loc) · 25.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bot Komutları - SebastianBot</title>
<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;800&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link rel="stylesheet" href="style.css">
<style>
.commands-layout {
flex: 1;
padding: 24px;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 24px;
}
.cmd-form-card {
background-color: var(--card-bg);
border-radius: 16px;
border: 1px solid var(--border-color);
padding: 24px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.cmd-form-card h3 {
font-size: 18px;
font-weight: 700;
margin-bottom: 20px;
display: flex;
align-items: center;
gap: 10px;
}
.cmd-form-card h3 i {
color: var(--primary-color);
}
.form-grid {
display: grid;
grid-template-columns: 1fr 2fr;
gap: 16px;
align-items: start;
}
.form-group {
display: flex;
flex-direction: column;
gap: 6px;
}
.form-group label {
font-size: 12px;
color: var(--text-secondary);
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.form-group input,
.form-group select,
.form-group textarea {
background: #0f1318;
border: 1px solid var(--border-color);
border-radius: 8px;
color: var(--text-primary);
padding: 10px 14px;
font-size: 14px;
font-family: inherit;
outline: none;
transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
border-color: var(--primary-color);
box-shadow: 0 0 0 2px rgba(83, 252, 24, 0.15);
}
.form-group textarea {
resize: vertical;
min-height: 80px;
}
.form-row {
display: flex;
gap: 16px;
align-items: end;
}
.form-row .form-group {
flex: 1;
}
.btn {
padding: 10px 20px;
border: none;
border-radius: 8px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: all 0.2s;
display: inline-flex;
align-items: center;
gap: 8px;
font-family: inherit;
}
.btn-primary {
background: var(--primary-color);
color: #000;
}
.btn-primary:hover {
background: #45d414;
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(83, 252, 24, 0.3);
}
.btn-cancel {
background: #3f3f46;
color: white;
}
.btn-cancel:hover {
background: #52525b;
}
.form-actions {
display: flex;
gap: 10px;
margin-top: 20px;
justify-content: flex-end;
}
.keyword-hint {
background: rgba(83, 252, 24, 0.08);
border: 1px solid rgba(83, 252, 24, 0.2);
border-radius: 8px;
padding: 12px 16px;
margin-top: 12px;
font-size: 12px;
color: var(--text-secondary);
line-height: 1.8;
}
.keyword-hint code {
background: rgba(83, 252, 24, 0.15);
color: var(--primary-color);
padding: 2px 6px;
border-radius: 4px;
font-size: 12px;
font-weight: 600;
}
.cmd-list-card {
background-color: var(--card-bg);
border-radius: 16px;
border: 1px solid var(--border-color);
padding: 24px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.cmd-list-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.cmd-list-header h3 {
font-size: 18px;
font-weight: 700;
display: flex;
align-items: center;
gap: 10px;
}
.cmd-list-header h3 i {
color: #3b82f6;
}
.cmd-search {
background: #0f1318;
border: 1px solid var(--border-color);
border-radius: 8px;
color: var(--text-primary);
padding: 8px 14px;
font-size: 13px;
outline: none;
width: 220px;
transition: border-color 0.2s;
}
.cmd-search:focus {
border-color: var(--primary-color);
}
.cmd-table {
width: 100%;
border-collapse: separate;
border-spacing: 0 6px;
}
.cmd-table thead th {
font-size: 11px;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 0.5px;
font-weight: 600;
text-align: left;
padding: 8px 14px;
}
.cmd-table tbody tr {
background: #151a21;
transition: background 0.2s;
}
.cmd-table tbody tr:hover {
background: rgba(83, 252, 24, 0.04);
}
.cmd-table tbody tr.disabled-row {
opacity: 0.45;
}
.cmd-table tbody td {
padding: 12px 14px;
font-size: 13px;
vertical-align: middle;
}
.cmd-table tbody td:first-child {
border-radius: 8px 0 0 8px;
}
.cmd-table tbody td:last-child {
border-radius: 0 8px 8px 0;
}
.cmd-name {
font-weight: 700;
color: var(--primary-color);
font-size: 14px;
font-family: 'Courier New', monospace;
}
.cmd-response {
color: #e2e8f0;
max-width: 320px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.cmd-badge {
display: inline-flex;
align-items: center;
gap: 4px;
padding: 3px 10px;
border-radius: 20px;
font-size: 11px;
font-weight: 600;
}
.cmd-badge.chat {
background: rgba(59, 130, 246, 0.15);
color: #60a5fa;
}
.cmd-badge.timer {
background: rgba(234, 179, 8, 0.15);
color: #fbbf24;
}
.cmd-badge.active {
background: rgba(16, 185, 129, 0.15);
color: #34d399;
}
.cmd-badge.inactive {
background: rgba(239, 68, 68, 0.15);
color: #f87171;
}
.cmd-actions {
display: flex;
gap: 6px;
}
.cmd-action-btn {
width: 30px;
height: 30px;
border: none;
border-radius: 6px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
transition: all 0.2s;
}
.cmd-action-btn.edit {
background: rgba(59, 130, 246, 0.15);
color: #60a5fa;
}
.cmd-action-btn.edit:hover {
background: rgba(59, 130, 246, 0.3);
}
.cmd-action-btn.toggle {
background: rgba(234, 179, 8, 0.15);
color: #fbbf24;
}
.cmd-action-btn.toggle:hover {
background: rgba(234, 179, 8, 0.3);
}
.cmd-action-btn.delete {
background: rgba(239, 68, 68, 0.15);
color: #f87171;
}
.cmd-action-btn.delete:hover {
background: rgba(239, 68, 68, 0.3);
}
.empty-state {
text-align: center;
padding: 40px;
color: var(--text-secondary);
}
.empty-state i {
font-size: 40px;
margin-bottom: 12px;
opacity: 0.3;
}
.empty-state p {
font-size: 14px;
}
/* Timer interval seçici */
#timerIntervalGroup {
transition: all 0.3s;
}
/* Responsive tablo */
@media (max-width: 1200px) {
.form-grid {
grid-template-columns: 1fr;
}
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(8px); }
to { opacity: 1; transform: translateY(0); }
}
.cmd-table tbody tr {
animation: fadeIn 0.3s ease;
}
/* Onay Modalı */
.cmd-modal-overlay {
display: none;
position: fixed;
top: 0; left: 0;
width: 100%; height: 100%;
background: rgba(0,0,0,0.7);
z-index: 9999;
justify-content: center;
align-items: center;
backdrop-filter: blur(4px);
}
.cmd-modal-box {
background: #1e1e2d;
border-radius: 12px;
padding: 25px;
width: 380px;
text-align: center;
box-shadow: 0 10px 25px rgba(0,0,0,0.5);
border: 1px solid rgba(255,255,255,0.1);
}
.cmd-modal-box h3 {
color: white;
margin: 0 0 12px 0;
font-size: 18px;
}
.cmd-modal-box p {
color: #a1a1aa;
font-size: 14px;
margin-bottom: 20px;
}
.cmd-modal-actions {
display: flex;
gap: 10px;
}
.cmd-modal-actions button {
flex: 1;
padding: 10px;
border: none;
border-radius: 6px;
cursor: pointer;
font-weight: bold;
font-family: inherit;
transition: opacity 0.2s;
}
</style>
</head>
<body>
<?php include 'sidebar.php'; ?>
<div class="main-content">
<header class="topbar">
<div class="page-title">Bot Komutları</div>
<div class="user-profile">
<div class="avatar">
<i class="fas fa-robot" style="color: var(--primary-color);"></i>
</div>
<span>SebastianBot</span>
</div>
</header>
<div class="commands-layout">
<div class="cmd-form-card" id="cmdFormCard">
<h3 id="formTitle"><i class="fas fa-plus-circle"></i> Yeni Komut Oluştur</h3>
<div class="form-row">
<div class="form-group">
<label>Komut Adı</label>
<input type="text" id="cmdName" placeholder="!discord" />
</div>
<div class="form-group">
<label>Komut Türü</label>
<select id="cmdType" onchange="toggleTimerInterval()">
<option value="chat">💬 Sohbet Komutu (Kullanıcı tetikler)</option>
<option value="timer">⏱️ Zamanlayıcı (Otomatik gönderir)</option>
</select>
</div>
<div class="form-group" id="timerIntervalGroup" style="display:none;">
<label>Aralık (Dakika)</label>
<input type="number" id="cmdInterval" min="1" max="1440" placeholder="5" value="5" />
</div>
<div class="form-group">
<label>Cooldown (Saniye)</label>
<input type="number" id="cmdCooldown" min="0" max="3600" placeholder="60" value="60" />
</div>
</div>
<div class="form-group" style="margin-top:16px;">
<label>Yanıt Mesajı</label>
<textarea id="cmdResponse" placeholder="Discord sunucumuza katılın: https://discord.gg/ornek"></textarea>
</div>
<div class="keyword-hint">
<strong>Kullanılabilir Değişkenler:</strong><br>
<code>$(user)</code> → Komutu yazan kullanıcının adını mention eder (ör: @DenizOzceylan)<br>
<code>$(channel)</code> → Kanal adını yazar<br>
<code>$(count)</code> → Komutun kaç kez kullanıldığını yazar<br>
<code>$(score)</code> → Komutu yazan kullanıcının güncel sadakat skorunu yazar
</div>
<div class="form-actions">
<button class="btn btn-cancel" id="btnCancelEdit" style="display:none;" onclick="cancelEdit()">
<i class="fas fa-times"></i> İptal
</button>
<button class="btn btn-primary" id="btnSubmit" onclick="submitCommand()">
<i class="fas fa-plus"></i> Komut Oluştur
</button>
</div>
</div>
<div class="cmd-list-card">
<div class="cmd-list-header">
<h3><i class="fas fa-list"></i> Kayıtlı Komutlar</h3>
<input type="text" class="cmd-search" id="cmdSearch" placeholder="Komut ara..." oninput="filterCommands()">
</div>
<table class="cmd-table">
<thead>
<tr>
<th>Komut</th>
<th>Yanıt</th>
<th>Tür</th>
<th>Cooldown</th>
<th>Durum</th>
<th>Kullanım</th>
<th style="text-align:right;">İşlemler</th>
</tr>
</thead>
<tbody id="cmdTableBody">
<tr>
<td colspan="7">
<div class="empty-state">
<i class="fas fa-terminal"></i>
<p>Henüz komut oluşturulmadı.</p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="cmd-modal-overlay" id="cmdModal">
<div class="cmd-modal-box">
<h3 id="cmdModalTitle">Onay</h3>
<p id="cmdModalDesc">Bu komutu silmek istediğinize emin misiniz?</p>
<div class="cmd-modal-actions">
<button onclick="closeCmdModal()" style="background:#3f3f46; color:white;">İptal</button>
<button onclick="confirmCmdAction()" id="cmdModalConfirmBtn" style="background:#ef4444; color:white;">Sil</button>
</div>
</div>
</div>
<script>
let allCommands = [];
let editingId = null;
let pendingAction = null;
let pendingId = null;
// Sayfa yüklendiğinde komutları çek
fetchCommands();
function toggleTimerInterval() {
const type = document.getElementById('cmdType').value;
document.getElementById('timerIntervalGroup').style.display = type === 'timer' ? 'flex' : 'none';
}
async function fetchCommands() {
try {
const response = await fetch('api/commands.php');
const data = await response.json();
if (data.status === 'success') {
allCommands = data.data;
renderCommands(allCommands);
}
} catch (err) {
console.error('Komutlar çekilemedi:', err);
}
}
function renderCommands(commands) {
const tbody = document.getElementById('cmdTableBody');
const searchTerm = document.getElementById('cmdSearch').value.toLowerCase();
let filtered = commands;
if (searchTerm) {
filtered = commands.filter(c =>
c.command_name.toLowerCase().includes(searchTerm) ||
c.response.toLowerCase().includes(searchTerm)
);
}
if (filtered.length === 0) {
tbody.innerHTML = `
<tr><td colspan="7">
<div class="empty-state">
<i class="fas fa-terminal"></i>
<p>Henüz komut oluşturulmadı.</p>
</div>
</td></tr>`;
return;
}
tbody.innerHTML = filtered.map(cmd => {
const isActive = cmd.is_active == 1;
const isTimer = cmd.command_type === 'timer';
const rowClass = isActive ? '' : 'disabled-row';
const typeBadge = isTimer
? `<span class="cmd-badge timer"><i class="fas fa-clock"></i> ${cmd.timer_interval} dk</span>`
: `<span class="cmd-badge chat"><i class="fas fa-comment"></i> Sohbet</span>`;
const statusBadge = isActive
? `<span class="cmd-badge active"><i class="fas fa-check-circle"></i> Aktif</span>`
: `<span class="cmd-badge inactive"><i class="fas fa-pause-circle"></i> Devre Dışı</span>`;
const toggleIcon = isActive ? 'fa-pause' : 'fa-play';
const toggleTitle = isActive ? 'Devre Dışı Bırak' : 'Aktifleştir';
return `
<tr class="${rowClass}">
<td><span class="cmd-name">${escapeHtml(cmd.command_name)}</span></td>
<td><span class="cmd-response" title="${escapeHtml(cmd.response)}">${escapeHtml(cmd.response)}</span></td>
<td>${typeBadge}</td>
<td style="color:var(--text-secondary); font-size:12px;">${cmd.cooldown || 60}s</td>
<td>${statusBadge}</td>
<td style="color:var(--text-secondary); font-weight:600;">${cmd.usage_count}</td>
<td>
<div class="cmd-actions" style="justify-content:flex-end;">
<button class="cmd-action-btn edit" title="Düzenle" onclick="startEdit(${cmd.id})"><i class="fas fa-pen"></i></button>
<button class="cmd-action-btn toggle" title="${toggleTitle}" onclick="toggleCommand(${cmd.id})"><i class="fas ${toggleIcon}"></i></button>
<button class="cmd-action-btn delete" title="Sil" onclick="askDeleteCommand(${cmd.id}, '${escapeHtml(cmd.command_name)}')"><i class="fas fa-trash"></i></button>
</div>
</td>
</tr>
`;
}).join('');
}
function filterCommands() {
renderCommands(allCommands);
}
async function submitCommand() {
const name = document.getElementById('cmdName').value.trim();
const response = document.getElementById('cmdResponse').value.trim();
const type = document.getElementById('cmdType').value;
const interval = document.getElementById('cmdInterval').value;
const cooldown = document.getElementById('cmdCooldown').value;
if (!name || !response) {
alert('Komut adı ve yanıt mesajı zorunludur.');
return;
}
const body = {
action: editingId ? 'update' : 'create',
command_name: name,
response: response,
command_type: type,
timer_interval: type === 'timer' ? parseInt(interval) : null,
cooldown: parseInt(cooldown) || 60
};
if (editingId) {
body.id = editingId;
}
try {
const res = await fetch('api/commands.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body)
});
const result = await res.json();
if (result.status === 'success') {
clearForm();
fetchCommands();
} else {
alert(result.message || 'Bir hata oluştu.');
}
} catch (err) {
console.error('Komut kaydedilemedi:', err);
alert('Sunucu hatası.');
}
}
function startEdit(id) {
const cmd = allCommands.find(c => c.id == id);
if (!cmd) return;
editingId = id;
document.getElementById('cmdName').value = cmd.command_name;
document.getElementById('cmdName').disabled = true;
document.getElementById('cmdResponse').value = cmd.response;
document.getElementById('cmdType').value = cmd.command_type;
document.getElementById('cmdCooldown').value = cmd.cooldown || 60;
toggleTimerInterval();
if (cmd.timer_interval) {
document.getElementById('cmdInterval').value = cmd.timer_interval;
}
document.getElementById('formTitle').innerHTML = '<i class="fas fa-pen"></i> Komut Düzenle';
document.getElementById('btnSubmit').innerHTML = '<i class="fas fa-save"></i> Kaydet';
document.getElementById('btnCancelEdit').style.display = 'inline-flex';
// Forma scroll et
document.getElementById('cmdFormCard').scrollIntoView({ behavior: 'smooth' });
}
function cancelEdit() {
clearForm();
}
function clearForm() {
editingId = null;
document.getElementById('cmdName').value = '';
document.getElementById('cmdName').disabled = false;
document.getElementById('cmdResponse').value = '';
document.getElementById('cmdType').value = 'chat';
document.getElementById('cmdInterval').value = '5';
document.getElementById('cmdCooldown').value = '60';
toggleTimerInterval();
document.getElementById('formTitle').innerHTML = '<i class="fas fa-plus-circle"></i> Yeni Komut Oluştur';
document.getElementById('btnSubmit').innerHTML = '<i class="fas fa-plus"></i> Komut Oluştur';
document.getElementById('btnCancelEdit').style.display = 'none';
}
async function toggleCommand(id) {
try {
const res = await fetch('api/commands.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'toggle', id: id })
});
const result = await res.json();
if (result.status === 'success') {
fetchCommands();
}
} catch (err) {
console.error('Toggle hatası:', err);
}
}
function askDeleteCommand(id, name) {
pendingAction = 'delete';
pendingId = id;
document.getElementById('cmdModalTitle').innerText = 'Komutu Sil';
document.getElementById('cmdModalDesc').innerText = `"${name}" komutunu kalıcı olarak silmek istediğinize emin misiniz?`;
document.getElementById('cmdModalConfirmBtn').style.background = '#ef4444';
document.getElementById('cmdModalConfirmBtn').innerText = 'Evet, Sil';
document.getElementById('cmdModal').style.display = 'flex';
}
function closeCmdModal() {
document.getElementById('cmdModal').style.display = 'none';
pendingAction = null;
pendingId = null;
}
async function confirmCmdAction() {
if (pendingAction === 'delete' && pendingId) {
try {
const res = await fetch('api/commands.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'delete', id: pendingId })
});
const result = await res.json();
if (result.status === 'success') {
fetchCommands();
}
} catch (err) {
console.error('Silme hatası:', err);
}
}
closeCmdModal();
}
function escapeHtml(str) {
const div = document.createElement('div');
div.textContent = str;
return div.innerHTML;
}
</script>
</body>
</html>