TinkerStorm / interaction-prototypes

A Discord interaction prototype preparing to lay the foundations of a game service.
https://discord.gg/z5DPVHNBuw
GNU General Public License v3.0
2 stars 0 forks source link

refactor: attempt rework for pre-component / pre-command checks #14

Open sudojunior opened 2 years ago

sudojunior commented 2 years ago
// current
if (condition) {
  // run code
}

// proposed
try {
  check(condition, failReason);
} catch (error) {
  await ctx.send(error?.message || error);
  return;
}

Approach to testing condition is derived from test framework assertions assert(condition, reason).

Currently used for the setup wizard when checking for channel permissions. https://github.com/TinkerStorm/interaction-prototypes/blob/232ff467bb4ad6c4a11c45c3db7bfeca2437182f/src/commands/setup.ts#L115-L132