|
| 1 | +import { |
| 2 | + ChatInputCommandInteraction, |
| 3 | + SlashCommandBuilder, |
| 4 | + SlashCommandSubcommandsOnlyBuilder, |
| 5 | +} from "discord.js"; |
| 6 | +import { Command } from "../interactions/interactionClasses"; |
| 7 | +import { config } from "../config"; |
| 8 | +import { blacklistAdd, blacklistRemove, blacklistShow } from "../util/game-activity-tracker/blacklist"; |
| 9 | +import { |
| 10 | + statisticsAllStats, |
| 11 | + statisticsGameStats, |
| 12 | + statisticsMyStats, |
| 13 | +} from "../util/game-activity-tracker/statistics"; |
| 14 | +import { |
| 15 | + adminBlacklistGame, |
| 16 | + adminLook, |
| 17 | + adminReset, |
| 18 | + adminShow, |
| 19 | + adminWhitelistGame, |
| 20 | +} from "../util/game-activity-tracker/admin"; |
| 21 | +import { list } from "../util/game-activity-tracker/list"; |
| 22 | + |
| 23 | +class TrackerCommand extends Command { |
| 24 | + constructor() { |
| 25 | + super("game-activity-tracker"); |
| 26 | + } |
| 27 | + |
| 28 | + async execute(interaction: ChatInputCommandInteraction): Promise<void> { |
| 29 | + const group: string | null = interaction.options.getSubcommandGroup(); |
| 30 | + const sub: string | null = interaction.options.getSubcommand(); |
| 31 | + |
| 32 | + if (group === "blacklist") { |
| 33 | + if (sub === "add") { |
| 34 | + await blacklistAdd(interaction); |
| 35 | + } else if (sub === "remove") { |
| 36 | + await blacklistRemove(interaction); |
| 37 | + } else if (sub === "show") { |
| 38 | + await blacklistShow(interaction); |
| 39 | + } |
| 40 | + } else if (group === "statistics") { |
| 41 | + if (sub === "my-stats") { |
| 42 | + await statisticsMyStats(interaction); |
| 43 | + } else if (sub === "game-stats") { |
| 44 | + await statisticsGameStats(interaction); |
| 45 | + } else if (sub === "all-stats") { |
| 46 | + await statisticsAllStats(interaction); |
| 47 | + } |
| 48 | + } else if (group === "admin") { |
| 49 | + if (interaction.memberPermissions?.bitfield == config.activityTrackerAdminCommandPermission) { |
| 50 | + return; |
| 51 | + } else if (sub === "reset") { |
| 52 | + await adminReset(interaction); |
| 53 | + } else if (sub === "blacklist") { |
| 54 | + await adminBlacklistGame(interaction); |
| 55 | + } else if (sub === "whitelist") { |
| 56 | + await adminWhitelistGame(interaction); |
| 57 | + } else if (sub === "look") { |
| 58 | + await adminLook(interaction); |
| 59 | + } else if (sub == "show") { |
| 60 | + await adminShow(interaction); |
| 61 | + } |
| 62 | + } else if (sub == "list") { |
| 63 | + await list(interaction); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + register(): |
| 68 | + | SlashCommandBuilder |
| 69 | + | SlashCommandSubcommandsOnlyBuilder |
| 70 | + | Omit<SlashCommandBuilder, "addSubcommandGroup" | "addSubcommand"> |
| 71 | + | boolean { |
| 72 | + if (!config.logActivity) { |
| 73 | + return false; |
| 74 | + } |
| 75 | + return new SlashCommandBuilder() |
| 76 | + .setName("game-activity-tracker") |
| 77 | + .setDescription("All commands associated with the Game Activity Tracker!") |
| 78 | + .addSubcommand((sub) => |
| 79 | + sub |
| 80 | + .setName("list") |
| 81 | + .setDescription("Returns a list of the played games based on a selected sorting method.") |
| 82 | + .addStringOption((opt) => |
| 83 | + opt |
| 84 | + .setName("sort") |
| 85 | + .setDescription("Sort by the ...") |
| 86 | + .addChoices( |
| 87 | + { name: "logs chronolocially and per person", value: "log-history" }, |
| 88 | + { name: "playtime per game", value: "playtime-per-game" }, |
| 89 | + { name: "number of logs per game", value: "logs-per-game" }, |
| 90 | + { name: "last log date per game", value: "log-date-per-game" } |
| 91 | + ) |
| 92 | + ) |
| 93 | + .addStringOption((opt) => |
| 94 | + opt |
| 95 | + .setName("order") |
| 96 | + .setDescription("Order the list ...") |
| 97 | + .addChoices( |
| 98 | + { name: "decreasing", value: "decreasing" }, |
| 99 | + { name: "increasing", value: "increasing" } |
| 100 | + ) |
| 101 | + ) |
| 102 | + ) |
| 103 | + .addSubcommandGroup((group) => |
| 104 | + group |
| 105 | + .setName("statistics") |
| 106 | + .setDescription("Gives you statistics based on the game activity.") |
| 107 | + .addSubcommand((sub) => |
| 108 | + sub |
| 109 | + .setName("my-stats") |
| 110 | + .setDescription("Show statistics about your own logs.") |
| 111 | + .addStringOption((opt) => |
| 112 | + opt.setName("game").setDescription("Filter stats for the given name.").setAutocomplete(true) |
| 113 | + ) |
| 114 | + ) |
| 115 | + .addSubcommand((sub) => |
| 116 | + sub |
| 117 | + .setName("game-stats") |
| 118 | + .setDescription("Show statistics about a given game across all logs.") |
| 119 | + .addStringOption((opt) => |
| 120 | + opt |
| 121 | + .setName("game") |
| 122 | + .setDescription("Filter stats for the given game.") |
| 123 | + .setAutocomplete(true) |
| 124 | + .setRequired(true) |
| 125 | + ) |
| 126 | + ) |
| 127 | + .addSubcommand((sub) => sub.setName("all-stats").setDescription("Show statistics across all logs.")) |
| 128 | + ) |
| 129 | + .addSubcommandGroup((group) => |
| 130 | + group |
| 131 | + .setName("blacklist") |
| 132 | + .setDescription("Manage your blacklist - if a game is on blacklist no activity will be tracked.") |
| 133 | + .addSubcommand((sub) => |
| 134 | + sub |
| 135 | + .setName("add") |
| 136 | + .setDescription("Add a game to your blacklist.") |
| 137 | + .addStringOption((opt) => |
| 138 | + opt |
| 139 | + .setName("game") |
| 140 | + .setDescription("The game to blacklist - (capitalization doesnt matter)") |
| 141 | + .setAutocomplete(true) |
| 142 | + .setRequired(true) |
| 143 | + ) |
| 144 | + ) |
| 145 | + .addSubcommand((sub) => |
| 146 | + sub |
| 147 | + .setName("remove") |
| 148 | + .setDescription("Remove a game from your blacklist.") |
| 149 | + .addStringOption((opt) => |
| 150 | + opt |
| 151 | + .setName("game") |
| 152 | + .setDescription("The game to whitelist - (capitalization doesnt matter)") |
| 153 | + .setAutocomplete(true) |
| 154 | + .setRequired(true) |
| 155 | + ) |
| 156 | + ) |
| 157 | + .addSubcommand((sub) => sub.setName("show").setDescription("See what is on your blacklist.")) |
| 158 | + ) |
| 159 | + .addSubcommandGroup((group) => |
| 160 | + group |
| 161 | + .setName("admin") |
| 162 | + .setDescription("Commands which only users with higher permissions can use.") |
| 163 | + .addSubcommand((sub) => |
| 164 | + sub |
| 165 | + .setName("reset") |
| 166 | + .setDescription("Reset every log and blacklist entry.") |
| 167 | + .addBooleanOption((opt) => |
| 168 | + opt.setName("sure").setDescription("Are you really sure?").setRequired(true) |
| 169 | + ) |
| 170 | + .addStringOption((opt) => |
| 171 | + opt |
| 172 | + .setName("really") |
| 173 | + .setDescription("Are you really sure you want to delete every entry?") |
| 174 | + .addChoices( |
| 175 | + { name: "No. I dont want to delete every log and blacklist entry!", value: "no" }, |
| 176 | + { name: "Yes I am sure. I want to delete every log and blacklist entry!", value: "yes" } |
| 177 | + ) |
| 178 | + .setRequired(true) |
| 179 | + ) |
| 180 | + ) |
| 181 | + .addSubcommand((sub) => |
| 182 | + sub |
| 183 | + .setName("blacklist") |
| 184 | + .setDescription("Add a game on the global blacklist - don't log anything for this game.") |
| 185 | + .addStringOption((opt) => |
| 186 | + opt |
| 187 | + .setName("game") |
| 188 | + .setDescription("Enter game which should get blacklisted. (Capitalization doesnt matter)") |
| 189 | + .setRequired(true) |
| 190 | + .setAutocomplete(true) |
| 191 | + ) |
| 192 | + ) |
| 193 | + .addSubcommand((sub) => |
| 194 | + sub |
| 195 | + .setName("whitelist") |
| 196 | + .setDescription("Remove a game from the global blacklist - log this game again.") |
| 197 | + .addStringOption((opt) => |
| 198 | + opt |
| 199 | + .setName("game") |
| 200 | + .setDescription( |
| 201 | + "Enter game which should get removed from the blacklisted . (Capitalization doesnt matter)" |
| 202 | + ) |
| 203 | + .setRequired(true) |
| 204 | + .setAutocomplete(true) |
| 205 | + ) |
| 206 | + ) |
| 207 | + .addSubcommand((sub) => sub.setName("show").setDescription("Show the global blacklist.")) |
| 208 | + .addSubcommand((sub) => |
| 209 | + sub |
| 210 | + .setName("look") |
| 211 | + .setDescription("Look into a users blacklist.") |
| 212 | + .addUserOption((opt) => |
| 213 | + opt.setName("user").setDescription("Take a look into this users blacklist.").setRequired(true) |
| 214 | + ) |
| 215 | + ) |
| 216 | + ); |
| 217 | + } |
| 218 | +} |
| 219 | + |
| 220 | +export default new TrackerCommand(); |
0 commit comments