diff --git a/src/Program.cs b/src/Program.cs index 76d6193..06756af 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -41,28 +41,26 @@ var host = builder.Build(); string Time(DateTimeOffset value) => $"\n"; InteractionMessageProperties Reply(string title, string text, int color, params (string Name, string Value, bool Inline)[] fields) { - var embed = new EmbedProperties().WithTitle(title).WithColor(new(color)) - .WithTimestamp(DateTimeOffset.UtcNow).WithFooter(new EmbedFooterProperties().WithText("Beetlejuice | Project Zomboid")); + var embed = new EmbedProperties().WithTitle(title).WithColor(new(color)); if (text.Length > 0) embed.WithDescription(text); if (fields.Length > 0) embed.AddFields(fields.Select(x => new EmbedFieldProperties().WithName(x.Name).WithValue(x.Value).WithInline(x.Inline))); return new InteractionMessageProperties().AddEmbeds(embed).WithFlags(MessageFlags.Ephemeral); } -InteractionMessageProperties Denied(string text = "You are not authorised to use this command.") => Reply("⛔ Access denied", text, 0xED4245); +InteractionMessageProperties Denied(string text = "Not authorized.") => Reply("Access denied", text, 0xED4245); bool Allowed(ApplicationCommandContext c) { lock (whitelistLock) return whitelist.Contains(c.User.Id); } InteractionMessageProperties Whitelist(ApplicationCommandContext c, User user, bool add) { - if (c.User.Id != initialUser) return Denied("Only the whitelist owner can manage access."); - if (!add && user.Id == initialUser) return Reply("⚠️ Whitelist unchanged", "The whitelist owner cannot be removed.", 0xFEE75C); + if (c.User.Id != initialUser) return Denied(); + if (!add && user.Id == initialUser) return Reply("Unchanged", "The owner cannot be removed.", 0xFEE75C); lock (whitelistLock) { bool changed = add ? whitelist.Add(user.Id) : whitelist.Remove(user.Id); - if (!changed) return Reply("⚠️ Whitelist unchanged", add ? $"<@{user.Id}> is already whitelisted." : $"<@{user.Id}> is not whitelisted.", 0xFEE75C); + if (!changed) return Reply("Unchanged", add ? $"<@{user.Id}> is already allowed." : $"<@{user.Id}> is not allowed.", 0xFEE75C); string temp = whitelistPath + ".tmp"; File.WriteAllLines(temp, whitelist.Order().Select(x => x.ToString())); File.Move(temp, whitelistPath, true); - return Reply("Whitelist updated", "Access control was updated successfully.", 0x57F287, - ("User", $"<@{user.Id}>\n`{user.Id}`", true), ("Action", add ? "`ADDED`" : "`REMOVED`", true)); + return Reply(add ? "Added" : "Removed", $"<@{user.Id}>", 0x57F287); } } async Task Command(string command, bool allowDisconnect = false) @@ -127,24 +125,22 @@ async Task Ready(string kind) } async Task Manual() { - if (!await gate.WaitAsync(0)) return Reply("⏳ Restart in progress", "Please wait for the current restart to finish.", 0xFEE75C); + if (!await gate.WaitAsync(0)) return Reply("Busy", "A restart is in progress.", 0xFEE75C); bool release = true; try { if (lastManual is { } last && DateTimeOffset.UtcNow - last < cooldown) - return Reply("⏱️ Restart cooldown", $"Try again in {Math.Ceiling((cooldown - (DateTimeOffset.UtcNow - last)).TotalSeconds)} seconds.", 0xFEE75C); + return Reply("Cooldown", $"Try again in {Math.Ceiling((cooldown - (DateTimeOffset.UtcNow - last)).TotalSeconds)} seconds.", 0xFEE75C); int count = (await Players()).Count; if (count == 0) count = (await Players()).Count; - if (count != 0) return Reply("Restart denied", "The server cannot restart while players are connected.", 0xED4245, - ("Players Online", $"`{count}`", true)); + if (count != 0) return Reply("Denied", $"{count} player{(count == 1 ? " is" : "s are")} online.", 0xED4245); await Quit(); lastManual = DateTimeOffset.UtcNow; release = false; _ = Task.Run(async () => { try { await Ready("Manual"); } finally { gate.Release(); } }); - return Reply("Restart initiated", "The server is restarting safely.", 0x57F287, - ("Requested", Time(DateTimeOffset.UtcNow), false), ("Cooldown Ends", Time(DateTimeOffset.UtcNow + cooldown), false)); + return Reply("Restarting", "No players online.", 0x57F287); } - catch (Exception e) { return Reply("❌ Restart unavailable", e.Message, 0xED4245); } + catch { return Reply("Unavailable", "Restart failed.", 0xED4245); } finally { if (release) gate.Release(); } } async Task Warn(int seconds) @@ -222,7 +218,7 @@ async Task PlayerList() return Reply("Online players", "", 0x5865F2, ("Connected", $"`{p.Count}`", true), ("Players", names, false)); } - catch { return Reply("❌ Player query failed", "Unable to reach the Project Zomboid server.", 0xED4245); } + catch { return Reply("Unavailable", "Player query failed.", 0xED4245); } } await host.StartAsync();