Fix SQL table name in insert_card function and update argument validation for optional attributes
This commit is contained in:
parent
23ffd55b7b
commit
7c7d299fc4
2 changed files with 25 additions and 4 deletions
|
@ -185,7 +185,7 @@ def insert_card(
|
||||||
if power is not None and charm is not None and wit is not None:
|
if power is not None and charm is not None and wit is not None:
|
||||||
CURSOR.execute(
|
CURSOR.execute(
|
||||||
'''
|
'''
|
||||||
INSERT INTO card (name, rarity, file_id, power, charm, wit)
|
INSERT INTO cards (name, rarity, file_id, power, charm, wit)
|
||||||
VALUES (?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
''',
|
''',
|
||||||
(name, rarity, file_id, power, charm, wit)
|
(name, rarity, file_id, power, charm, wit)
|
||||||
|
@ -193,7 +193,7 @@ def insert_card(
|
||||||
else:
|
else:
|
||||||
CURSOR.execute(
|
CURSOR.execute(
|
||||||
'''
|
'''
|
||||||
INSERT INTO card (name, rarity, file_id)
|
INSERT INTO cards (name, rarity, file_id)
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
''',
|
''',
|
||||||
(name, rarity, file_id)
|
(name, rarity, file_id)
|
||||||
|
|
|
@ -123,10 +123,10 @@ dumbass.',
|
||||||
'attachment_urls': None
|
'attachment_urls': None
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(arguments) != 2:
|
if not(len(arguments) in (2,5)):
|
||||||
return {
|
return {
|
||||||
'message': f'{author} Please specify the following attributes \
|
'message': f'{author} Please specify the following attributes \
|
||||||
in order: name, rarity',
|
in order: name, rarity. Optionally add [power, charm, wit].',
|
||||||
'attachment_urls': None
|
'attachment_urls': None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,6 +137,27 @@ be a number between 1 and 5',
|
||||||
'attachment_urls': None
|
'attachment_urls': None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(arguments) == 2:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if not all(is_float(arg) for arg in arguments[2:]):
|
||||||
|
return {
|
||||||
|
'message': f'{author} Invalid attributes: power, charm and \
|
||||||
|
wit must be numbers.',
|
||||||
|
'attachment_urls': None
|
||||||
|
}
|
||||||
|
card_id, file_id = add_card(
|
||||||
|
name=arguments[0],
|
||||||
|
rarity=int(arguments[1]),
|
||||||
|
image_url=image_url,
|
||||||
|
power=int(arguments[2]),
|
||||||
|
charm=int(arguments[3]),
|
||||||
|
wit=int(arguments[4])
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
'message': f'{author} Added {arguments[0]}, ID {card_id}.',
|
||||||
|
'attachment_urls': [file_id]
|
||||||
|
}
|
||||||
card_id, file_id = add_card(
|
card_id, file_id = add_card(
|
||||||
name=arguments[0],
|
name=arguments[0],
|
||||||
rarity=int(arguments[1]),
|
rarity=int(arguments[1]),
|
||||||
|
|
Loading…
Add table
Reference in a new issue