moved the team fuzzy searching to a get_team_fuzzy_search for ease of coding
This commit is contained in:
parent
5697c5dbb3
commit
5e00d0d271
|
@ -1,4 +1,4 @@
|
||||||
import asyncio, time, datetime, games, json, threading, jinja2
|
import asyncio, time, datetime, games, json, threading, jinja2, leagues
|
||||||
from flask import Flask, url_for, Response, render_template, request, jsonify
|
from flask import Flask, url_for, Response, render_template, request, jsonify
|
||||||
from flask_socketio import SocketIO, emit
|
from flask_socketio import SocketIO, emit
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import discord, json, math, os, roman, games, asyncio, random, main_controller, threading, time, urllib
|
import discord, json, math, os, roman, games, asyncio, random, main_controller, threading, time, urllib, leagues
|
||||||
import database as db
|
import database as db
|
||||||
import onomancer as ono
|
import onomancer as ono
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
@ -127,32 +127,19 @@ class StartGameCommand(Command):
|
||||||
innings = None
|
innings = None
|
||||||
try:
|
try:
|
||||||
team_name1 = command.split("\n")[1].strip()
|
team_name1 = command.split("\n")[1].strip()
|
||||||
team1 = games.get_team(team_name1)
|
team1 = get_team_fuzzy_search(team_name1)
|
||||||
if team1 is None:
|
|
||||||
teams = games.search_team(team_name1.lower())
|
|
||||||
if len(teams) == 1:
|
|
||||||
team1 = teams[0]
|
|
||||||
team_name2 = command.split("\n")[2].strip()
|
team_name2 = command.split("\n")[2].strip()
|
||||||
team2 = games.get_team(team_name2)
|
team2 = get_team_fuzzy_search(team_name2)
|
||||||
if team2 is None:
|
|
||||||
teams = games.search_team(team_name2.lower())
|
|
||||||
if len(teams) == 1:
|
|
||||||
team2 = teams[0]
|
|
||||||
innings = int(command.split("\n")[3])
|
innings = int(command.split("\n")[3])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
try:
|
try:
|
||||||
team_name1 = command.split("\n")[1].strip()
|
team_name1 = command.split("\n")[1].strip()
|
||||||
team1 = games.get_team(team_name1)
|
team1 = get_team_fuzzy_search(team_name1)
|
||||||
if team1 is None:
|
|
||||||
teams = games.search_team(team_name1.lower())
|
|
||||||
if len(teams) == 1:
|
|
||||||
team1 = teams[0]
|
|
||||||
team_name2 = command.split("\n")[2].strip()
|
team_name2 = command.split("\n")[2].strip()
|
||||||
team2 = games.get_team(team_name2)
|
team2 = get_team_fuzzy_search(team_name2)
|
||||||
if team2 is None:
|
|
||||||
teams = games.search_team(team_name2.lower())
|
|
||||||
if len(teams) == 1:
|
|
||||||
team2 = teams[0]
|
|
||||||
except IndexError:
|
except IndexError:
|
||||||
await msg.channel.send("We need at least three lines: startgame, away team, and home team are required. Optionally, the number of innings can go at the end, if you want a change of pace.")
|
await msg.channel.send("We need at least three lines: startgame, away team, and home team are required. Optionally, the number of innings can go at the end, if you want a change of pace.")
|
||||||
return
|
return
|
||||||
|
@ -164,8 +151,8 @@ class StartGameCommand(Command):
|
||||||
await msg.channel.send("Anything less than 2 innings isn't even an outing. Try again.")
|
await msg.channel.send("Anything less than 2 innings isn't even an outing. Try again.")
|
||||||
return
|
return
|
||||||
|
|
||||||
elif innings is not None and innings > 30 and msg.author.id not in config()["owners"]:
|
elif innings is not None and innings > 200 and msg.author.id not in config()["owners"]:
|
||||||
await msg.channel.send("Y'all can't behave, so we've limited games to 30 innings. Ask xvi to start it with more if you really want to.")
|
await msg.channel.send("Y'all can behave, so we've upped the limit on game length to 200 innings.")
|
||||||
return
|
return
|
||||||
|
|
||||||
if team1 is not None and team2 is not None:
|
if team1 is not None and team2 is not None:
|
||||||
|
@ -230,14 +217,10 @@ class ShowTeamCommand(Command):
|
||||||
|
|
||||||
async def execute(self, msg, command):
|
async def execute(self, msg, command):
|
||||||
team_name = command.strip()
|
team_name = command.strip()
|
||||||
team = games.get_team(team_name)
|
team = get_team_fuzzy_search(team_name)
|
||||||
if team is not None:
|
if team is not None:
|
||||||
await msg.channel.send(embed=build_team_embed(team))
|
await msg.channel.send(embed=build_team_embed(team))
|
||||||
else:
|
return
|
||||||
teams = games.search_team(team_name.lower())
|
|
||||||
if len(teams) == 1:
|
|
||||||
await msg.channel.send(embed=build_team_embed(teams[0]))
|
|
||||||
else:
|
|
||||||
await msg.channel.send("Can't find that team, boss. Typo?")
|
await msg.channel.send("Can't find that team, boss. Typo?")
|
||||||
|
|
||||||
class ShowAllTeamsCommand(Command):
|
class ShowAllTeamsCommand(Command):
|
||||||
|
@ -275,7 +258,7 @@ class SwapPlayerCommand(Command):
|
||||||
template = """m;swapsection
|
template = """m;swapsection
|
||||||
[team name]
|
[team name]
|
||||||
[player name]"""
|
[player name]"""
|
||||||
description = "Swaps a player from lineup to rotation, or from rotation to lineup. Requires team ownership."
|
description = "Swaps a player from lineup to rotation, or from rotation to lineup. Requires team ownership and exact spelling of team name."
|
||||||
|
|
||||||
async def execute(self, msg, command):
|
async def execute(self, msg, command):
|
||||||
try:
|
try:
|
||||||
|
@ -304,7 +287,7 @@ class MovePlayerCommand(Command):
|
||||||
[team name]
|
[team name]
|
||||||
[player name]
|
[player name]
|
||||||
[new lineup/rotation position number] (indexed with 1 being the top)"""
|
[new lineup/rotation position number] (indexed with 1 being the top)"""
|
||||||
description = "Moves a player in your lineup or rotation. Requires team ownership."
|
description = "Moves a player in your lineup or rotation. Requires team ownership and exact spelling of team name."
|
||||||
|
|
||||||
async def execute(self, msg, command):
|
async def execute(self, msg, command):
|
||||||
try:
|
try:
|
||||||
|
@ -334,7 +317,7 @@ class AddPlayerCommand(Command):
|
||||||
template = """m;addplayer pitcher (or m;addplayer batter)
|
template = """m;addplayer pitcher (or m;addplayer batter)
|
||||||
[team name]
|
[team name]
|
||||||
[player name]"""
|
[player name]"""
|
||||||
description = "Recruits a new player to your team, as either a pitcher or a batter. Requires team ownership."
|
description = "Recruits a new player to your team, as either a pitcher or a batter. Requires team ownership and exact spelling of team name."
|
||||||
|
|
||||||
async def execute(self, msg, command):
|
async def execute(self, msg, command):
|
||||||
try:
|
try:
|
||||||
|
@ -367,6 +350,7 @@ class RemovePlayerCommand(Command):
|
||||||
template = """m;removeplayer
|
template = """m;removeplayer
|
||||||
[team name]
|
[team name]
|
||||||
[player name]"""
|
[player name]"""
|
||||||
|
description = "Removes a player from your team. Requires team ownership and exact spelling of team name."
|
||||||
|
|
||||||
async def execute(self, msg, command):
|
async def execute(self, msg, command):
|
||||||
try:
|
try:
|
||||||
|
@ -412,7 +396,7 @@ class HelpCommand(Command):
|
||||||
class DeleteTeamCommand(Command):
|
class DeleteTeamCommand(Command):
|
||||||
name = "deleteteam"
|
name = "deleteteam"
|
||||||
template = "m;deleteteam [name]"
|
template = "m;deleteteam [name]"
|
||||||
description = "Allows you to delete the team with the provided name if you are the owner of it, Gives a confirmation first to prevent accidental deletions. If it isn't letting you delete your team, you probably created it before teams having owners was a thing, contact xvi and xie can assign you as the owner."
|
description = "Allows you to delete the team with the provided name. Requires team ownership. If you are the owner and the bot is telling you it's not yours, contact xvi and xie can assist."
|
||||||
|
|
||||||
async def execute(self, msg, command):
|
async def execute(self, msg, command):
|
||||||
team_name = command.strip()
|
team_name = command.strip()
|
||||||
|
@ -1006,4 +990,12 @@ def game_over_embed(game):
|
||||||
embed.add_field(name="Final score:", value=winstring)
|
embed.add_field(name="Final score:", value=winstring)
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
|
def get_team_fuzzy_search(team_name):
|
||||||
|
team = games.get_team(team_name)
|
||||||
|
if team is None:
|
||||||
|
teams = games.search_team(team_name.lower())
|
||||||
|
if len(teams) == 1:
|
||||||
|
team = teams[0]
|
||||||
|
return team
|
||||||
|
|
||||||
client.run(config()["token"])
|
client.run(config()["token"])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user