Add meaningful error messages for bad arguments in [p]bank set (#4801)

* bot will give meaning full message for bad argument

* reformated python code and updated warning message!

* warning message updated

* warning message updated

* warning message updated(1)

* warning message updated(2)

* warning message updated(3)

* Address the review

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
Sougata das 2021-03-26 20:30:56 +05:30 committed by GitHub
parent ef803072fa
commit a4db7a1028
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -101,19 +101,30 @@ def guild_only_check():
class SetParser:
def __init__(self, argument):
allowed = ("+", "-")
self.sum = int(argument)
try:
self.sum = int(argument)
except ValueError:
raise commands.BadArgument(
_(
"Invalid value, the argument must be an integer,"
" optionally preceded with a `+` or `-` sign."
)
)
if argument and argument[0] in allowed:
if self.sum < 0:
self.operation = "withdraw"
elif self.sum > 0:
self.operation = "deposit"
else:
raise RuntimeError
raise commands.BadArgument(
_(
"Invalid value, the amount of currency to increase or decrease"
" must be an integer different from zero."
)
)
self.sum = abs(self.sum)
elif argument.isdigit():
self.operation = "set"
else:
raise RuntimeError
self.operation = "set"
@cog_i18n(_)