(interaction, config, client)
| 135 | category: "Utility", |
| 136 | |
| 137 | async execute(interaction, config, client) { |
| 138 | const userId = interaction.user.id; |
| 139 | const subcommand = interaction.options.getSubcommand(); |
| 140 | const shareSubcommand = interaction.options.getSubcommandGroup() === 'share' ? interaction.options.getSubcommand() : null; |
| 141 | |
| 142 | async function getOrCreateSharedList(listId, creatorId = null, listName = null) { |
| 143 | const listKey = `shared_todo_${listId}`; |
| 144 | let listData = await getFromDb(listKey, null); |
| 145 | |
| 146 | if (!listData || (listData.ok === false && listData.error)) { |
| 147 | if (creatorId) { |
| 148 | listData = { |
| 149 | id: listId, |
| 150 | name: listName, |
| 151 | creatorId, |
| 152 | members: [creatorId], |
| 153 | tasks: [], |
| 154 | nextId: 1, |
| 155 | createdAt: new Date().toISOString() |
| 156 | }; |
| 157 | await setInDb(listKey, listData); |
| 158 | } else { |
| 159 | return null; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | if (listData) { |
| 164 | if (!Array.isArray(listData.tasks)) listData.tasks = []; |
| 165 | if (!listData.nextId) listData.nextId = 1; |
| 166 | if (!Array.isArray(listData.members)) listData.members = []; |
| 167 | } |
| 168 | |
| 169 | return listData; |
| 170 | } |
| 171 | |
| 172 | try { |
| 173 | const deferSuccess = await InteractionHelper.safeDefer(interaction); |
| 174 | if (!deferSuccess) { |
| 175 | logger.warn(`Todo interaction defer failed`, { |
| 176 | userId: interaction.user.id, |
| 177 | guildId: interaction.guildId, |
| 178 | commandName: 'todo' |
| 179 | }); |
| 180 | return; |
| 181 | } |
| 182 | |
| 183 | if (shareSubcommand) { |
| 184 | switch (shareSubcommand) { |
| 185 | case 'create': { |
| 186 | const listName = interaction.options.getString('name'); |
| 187 | const listId = generateShareId(); |
| 188 | |
| 189 | await getOrCreateSharedList(listId, userId, listName); |
| 190 | |
| 191 | const userSharedLists = await getFromDb(`user_shared_lists_${userId}`, []); |
| 192 | const sharedListsArray = Array.isArray(userSharedLists) ? userSharedLists : []; |
| 193 | if (!sharedListsArray.includes(listId)) { |
| 194 | sharedListsArray.push(listId); |
nothing calls this directly
no test coverage detected