Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions events/interactionCreate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
const chalk = require('chalk');
const { doc, getDoc } = require('firebase/firestore');

// In-memory cache to prevent excessive DB reads
const globalCache = {
maintenance: { data: null, lastFetch: 0 },
blacklist: { data: null, lastFetch: 0 },
guildSettings: new Map() // guildId -> { data, lastFetch }
};

const CACHE_TTL = 60 * 1000; // 1 minute

async function getCachedDoc(db, collection, id, cacheObj) {
const now = Date.now();
if (cacheObj.data && (now - cacheObj.lastFetch < CACHE_TTL)) {
return cacheObj.data;
}
try {
const snap = await getDoc(doc(db, collection, id));
cacheObj.data = snap.exists() ? snap.data() : null;
cacheObj.lastFetch = now;
return cacheObj.data;
} catch (err) {
console.error(chalk.red(`[CACHE ERROR] Failed to fetch ${collection}/${id}:`), err);
return cacheObj.data; // Return stale data on error
}
}

module.exports = {
name: 'interactionCreate',
Expand All @@ -7,7 +33,52 @@ module.exports = {

if (!interaction.isChatInputCommand() && !interaction.isAutocomplete() && !interaction.isModalSubmit()) return;

// 1. Global Checks (Maintenance & Blacklist)
const maintenanceData = await getCachedDoc(client.db, 'bot_settings', 'maintenance', globalCache.maintenance);
const blacklistData = await getCachedDoc(client.db, 'bot_settings', 'blacklist', globalCache.blacklist);

// Blacklist check
if (blacklistData && blacklistData.users?.includes(interaction.user.id)) {
const message = { content: '[ERR] あなたはボットの使用を制限されています。', ephemeral: true };
return interaction.isAutocomplete() ? null : interaction.reply(message);
}

// Maintenance mode check (Bypass for Bot Owners)
if (maintenanceData && maintenanceData.enabled) {
// Get bot owners from application
if (!client.application.owner) await client.application.fetch();
const owners = client.application.owner.members
? client.application.owner.members.map(m => m.id)
: [client.application.owner.id];

if (!owners.includes(interaction.user.id)) {
const reason = maintenanceData.reason || '現在メンテナンス中です。';
const message = { content: `[INFO] ${reason}`, ephemeral: true };
return interaction.isAutocomplete() ? null : interaction.reply(message);
}
}

if (interaction.isChatInputCommand()) {
// 2. Guild-specific Command Check
if (interaction.guildId) {
if (!globalCache.guildSettings.has(interaction.guildId)) {
globalCache.guildSettings.set(interaction.guildId, { data: null, lastFetch: 0 });
}
const guildSettings = await getCachedDoc(
client.db,
'guild_settings',
interaction.guildId,
globalCache.guildSettings.get(interaction.guildId)
);

if (guildSettings && guildSettings.disabledCommands?.includes(interaction.commandName)) {
return interaction.reply({
content: `[INFO] このコマンド「${interaction.commandName}」はこのサーバーで無効化されています。`,
ephemeral: true
});
}
}

const command = client.commands.get(interaction.commandName);
if (!command) {
console.error(chalk.red(`[ERROR] Unknown command: ${interaction.commandName}`));
Expand Down
31 changes: 17 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@google/generative-ai": "^0.2.1",
"@napi-rs/canvas": "^0.1.77",
"chalk": "^4.1.2",
"chart.js": "^4.4.2",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"discord-player": "^7.1.0",
Expand Down
2 changes: 0 additions & 2 deletions public/admin-login.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
--font-mono: 'Share Tech Mono', monospace;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: 0; } }

Expand All @@ -41,7 +40,6 @@
.login-container {
width: 100%;
max-width: 500px;
animation: fadeIn 0.7s ease-out;
}

.terminal {
Expand Down
13 changes: 0 additions & 13 deletions public/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ body {
padding: 12px 20px;
color: var(--text-muted-color);
text-decoration: none;
transition: all 0.3s;
border-left: 3px solid transparent;
}

Expand Down Expand Up @@ -234,12 +233,6 @@ body {
height: 8px;
background-color: var(--success-color);
border-radius: 50%;
animation: pulse 2s infinite;
}

@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}

#page-content-wrapper {
Expand All @@ -260,12 +253,6 @@ body {
border-radius: 8px;
padding: 25px;
margin-bottom: 25px;
transition: transform 0.3s, box-shadow 0.3s;
}

.card:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.card-header {
Expand Down
9 changes: 9 additions & 0 deletions public/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@ <h2 id="bot-name" class="glitch" data-text="OrderlyCore">OrderlyCore</h2>
<a href="#status" class="nav-item" data-page="status">
<i data-feather="zap"></i><span>ステータス管理</span>
</a>
<a href="#maintenance" class="nav-item" data-page="maintenance">
<i data-feather="tool"></i><span>メンテナンス設定</span>
</a>
<a href="#blacklist" class="nav-item" data-page="blacklist">
<i data-feather="user-x"></i><span>ブラックリスト</span>
</a>
<div class="nav-category">MONITORING</div>
<a href="#health" class="nav-item" data-page="health">
<i data-feather="activity"></i><span>システム状態</span>
</a>
<a href="#logs" class="nav-item" data-page="logs">
<i data-feather="file-text"></i><span>システムログ</span>
</a>
Expand Down
Loading