CLIxIndia-Dev / CLIxIndia-Dev/MiTiRobot
Duplicate code for empty messages
- Dominant language
- JavaScript
- Stars
- 0
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
I assume this code was in response to the author who was authoring empty messages:
```
if type(msg) != str or len(msg) == 0:
print('empty message found in parent, trying to fix...')
msg = '?'
```
But it appears several times in the app. I would suggest breaking that out into a method on the Element class, something like:
```
class Element():
def get_valid_message(self):
if type(msg) != str or len(msg) == 0:
print('empty message found in parent, trying to fix...')
return '?'
return self.message_text
```
You could also do the `startswith("^")` check here, if that makes sense (line 168). And the `.split('~')` if that also makes sense here.
And that would make it testable against a wide variety of invalid messages, plus give you a central place to put validation code. I would also suggest testing against:
* Empty text
* Non-string text
* Text with funky characters, like ~`,./?<>\|"'!@#$%^&*()[]{}, etc.
* Text that starts wth "^" (if that makes sense to put here).
* Text with "^" not at the start.
* Text with "~" and empty substrings, etc.
* Text with unicode (are there invalid characters that Telegram will reject?)
* Super-long text (is there a limit in Telegram? Your model doesn't specify one...but I can imagine Telegram might enforce one, in which case you would want to update your model parameters to include the `max_length`)
From a UX standpoint, is sending back `?` what the user expects? How are they supposed to respond to seeing that -- will they get buttons or guidance on new messages they can send to the bot? Or is that mostly for internal testing, by the authors?
Contributor guide
No contributing guide indexed for this repository
Research direction
The issue identifies the Element class and a check around line 168, but names no file or existing test. Locate every copy of the empty-message validation and inspect how startswith("^") and split('~') are used. Done means validation has one testable home, repeated logic is removed, and the listed invalid-message cases have defined behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api, backend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100