forked from c0de/BaseballBot
Fixed point fetching and special resolution by player
This commit is contained in:
parent
16a74828a2
commit
f96618d2d1
@ -76,7 +76,7 @@ async def on_message(message):
|
|||||||
# Closes off the active play to be ready for the next set
|
# Closes off the active play to be ready for the next set
|
||||||
if content.startswith('!resolve'):
|
if content.startswith('!resolve'):
|
||||||
# try:
|
# try:
|
||||||
args, has_batter = __parse_resolve_play__(content)
|
pitch_number, batter_id, batter_guess, has_batter = __parse_resolve_play__(content)
|
||||||
if args is None:
|
if args is None:
|
||||||
await message.channel.send("Hey " + "<@" + str(message.author.id) + ">, I'm not sure what you meant. "
|
await message.channel.send("Hey " + "<@" + str(message.author.id) + ">, I'm not sure what you meant. "
|
||||||
"You need real, numeric, values for this command to work. "
|
"You need real, numeric, values for this command to work. "
|
||||||
@ -88,18 +88,17 @@ async def on_message(message):
|
|||||||
await message.channel.send("You confused me. There's no active play so I have nothing to close!")
|
await message.channel.send("You confused me. There's no active play so I have nothing to close!")
|
||||||
else:
|
else:
|
||||||
if has_batter:
|
if has_batter:
|
||||||
referenced_member_id = args[1][3:-1]
|
referenced_member_id = batter_id[3:-1]
|
||||||
play = play_dao.get_active_play(server_id)
|
play = play_dao.get_active_play(server_id)
|
||||||
guess_object = {PLAY_ID: play['play_id'],
|
guess_object = {PLAY_ID: play['play_id'],
|
||||||
MEMBER_ID: str(referenced_member_id),
|
MEMBER_ID: str(referenced_member_id),
|
||||||
GUESSED_NUMBER: args[2],
|
GUESSED_NUMBER: batter_guess,
|
||||||
MEMBER_NAME: bot.get_user(int(referenced_member_id)).name}
|
MEMBER_NAME: bot.get_user(int(referenced_member_id)).name}
|
||||||
|
|
||||||
guess_dao.insert(guess_object)
|
guess_dao.insert(guess_object, True)
|
||||||
|
|
||||||
pitch_value = args[0]
|
play = play_dao.resolve_play(pitch_number, server_id)
|
||||||
play = play_dao.resolve_play(pitch_value, server_id)
|
guess_dao.set_differences(pitch_number, play['play_id'])
|
||||||
guess_dao.set_differences(pitch_value, play['play_id'])
|
|
||||||
guesses = points_service.fetch_sorted_guesses_by_play(guess_dao, play['play_id'])
|
guesses = points_service.fetch_sorted_guesses_by_play(guess_dao, play['play_id'])
|
||||||
|
|
||||||
response_message = "Closed this play! Here are the results:\n"
|
response_message = "Closed this play! Here are the results:\n"
|
||||||
@ -128,6 +127,7 @@ async def on_message(message):
|
|||||||
points_by_user = points_service.fetch_points(timestamp, server_id, play_dao, guess_dao)
|
points_by_user = points_service.fetch_points(timestamp, server_id, play_dao, guess_dao)
|
||||||
response = "Here are the top guessers by points as per your request..."
|
response = "Here are the top guessers by points as per your request..."
|
||||||
for user in points_by_user:
|
for user in points_by_user:
|
||||||
|
if str(user[2]) != '0':
|
||||||
response += "\n" + str(user[1]) + " : " + str(user[2])
|
response += "\n" + str(user[1]) + " : " + str(user[2])
|
||||||
|
|
||||||
await message.channel.send(response)
|
await message.channel.send(response)
|
||||||
@ -197,9 +197,9 @@ def __parse_resolve_play__(message_content):
|
|||||||
pieces = message_content.split()
|
pieces = message_content.split()
|
||||||
try:
|
try:
|
||||||
if len(pieces) == 2:
|
if len(pieces) == 2:
|
||||||
return [pieces[1]], False
|
return pieces[1], None, None, False
|
||||||
elif len(pieces) == 4:
|
elif len(pieces) == 4:
|
||||||
return [pieces[1], pieces[2], pieces[3]], True
|
return pieces[1], pieces[2], pieces[3], True
|
||||||
else:
|
else:
|
||||||
print("Illegal resolution command")
|
print("Illegal resolution command")
|
||||||
return None, None
|
return None, None
|
||||||
|
@ -38,6 +38,9 @@ class PointsService():
|
|||||||
|
|
||||||
# Iterates through the point table, which we assume is sorted, and gets the points
|
# Iterates through the point table, which we assume is sorted, and gets the points
|
||||||
def __get_points_for_diff__(self, diff):
|
def __get_points_for_diff__(self, diff):
|
||||||
|
if diff == 'None':
|
||||||
|
return 0
|
||||||
|
|
||||||
for i in range(0, len(self._point_table)):
|
for i in range(0, len(self._point_table)):
|
||||||
if int(diff) < self._point_table[i][0]:
|
if int(diff) < self._point_table[i][0]:
|
||||||
return self._point_table[i][1]
|
return self._point_table[i][1]
|
||||||
|
Loading…
Reference in New Issue
Block a user