thedevs-network / the-guard-bot

The Guard, a Telegram bot to moderate groups.
https://t.me/thedevs_bot
GNU Affero General Public License v3.0
491 stars 162 forks source link

Test Custom Command for errors #88

Closed SitiSchu closed 5 years ago

SitiSchu commented 6 years ago

If a custom command has invalid HTML, the command will not be sent, and the bot will error. The user never sees a notice which is bad. A way around this could be testing if the custom command content is valid. This can be checked by either using a HTML Linter(if such thing exists) or by sending the Command. If there's an error, tell the user. If there is none delete it and tell the User that the command was added.

trgwii commented 6 years ago

I think doing something transactional would be best here (pseudocode):

try {
  await addCommandToStore(commandFromUser);
  await sendCommandSuccess(commandFromUser);
} catch (err) {
  await deleteCommandFromStore(commandFromUser);
  await sendCommandError(err);
}

Trying to send the user command as part of the success message, and if that fails, remove it and send the error.

wojpawlik commented 6 years ago

Could just try sending the command, and if it succeeds, edit the message to a success message.

trgwii commented 6 years ago

I think the success feedback should contain the formatted message as well? Successfully added command: This is the formatted response

SitiSchu commented 6 years ago

I tend to agree...I usually find myself testing the command to see if I ducked up the formatting or not so sending it is a nice idea

wojpawlik commented 5 years ago

No need to validate at all if instead of HTML formatted plaintext the command would take formatted message and unformat it using https://github.com/telegraf/telegraf/blob/develop/core/replicators.js