Strip spaces from all lines, and add some fallback messages if some commands are run without arguments

This commit is contained in:
hillexed 2020-12-26 21:36:26 -05:00
parent 41c924a9ef
commit 781ded0984

View file

@ -62,6 +62,9 @@ async def on_message(msg):
if not command_b: if not command_b:
return return
# clear trailing spaces from each line
command = "\n".join([line.strip() for line in command.split("\n")])
if msg.author.id in config()["owners"] and command == "introduce": if msg.author.id in config()["owners"] and command == "introduce":
await introduce(msg.channel) await introduce(msg.channel)
@ -100,7 +103,7 @@ async def on_message(msg):
except: except:
await msg.channel.send("Something went wrong. Tell xvi.") await msg.channel.send("Something went wrong. Tell xvi.")
elif command == "showidol": elif command.startswith("showidol"):
try: try:
player_json = db.get_user_player(msg.author) player_json = db.get_user_player(msg.author)
embed=build_star_embed(player_json) embed=build_star_embed(player_json)
@ -109,13 +112,16 @@ async def on_message(msg):
except: except:
await msg.channel.send("We can't find your idol. Looked everywhere, too.") await msg.channel.send("We can't find your idol. Looked everywhere, too.")
elif command.startswith("showplayer "): elif command.startswith("showplayer"):
player_name = json.loads(ono.get_stats(command.split(" ",1)[1])) if " " in command:
await msg.channel.send(embed=build_star_embed(player_name)) player_name = json.loads(ono.get_stats(command.split(" ",1)[1]))
await msg.channel.send(embed=build_star_embed(player_name))
else:
await msg.channel.send("If you wanna hear about anyone in particular, I'm gonna need a name.")
elif command.startswith("startgame\n"): elif command.startswith("startgame"):
if len(gamesarray) > 45: if len(gamesarray) > 45:
await msg.channel.send("We're running 45 games and we doubt Discord will be happy with any more. These edit requests don't come cheap.") await msg.channel.send("We're running 45 games and we doubt Discord will be happy with any more. These edit requests don't come cheap.")
return return
@ -166,32 +172,42 @@ async def on_message(msg):
game_task = asyncio.create_task(setup_game(msg.channel, msg.author, games.game(msg.author.name, games.team(), games.team(), length=inningmax))) game_task = asyncio.create_task(setup_game(msg.channel, msg.author, games.game(msg.author.name, games.team(), games.team(), length=inningmax)))
await game_task await game_task
elif command.startswith("saveteam\n"): elif command.startswith("saveteam"):
if db.get_team(command.split("\n",1)[1].split("\n")[0]) == None: if "\n" in command:
save_task = asyncio.create_task(save_team_batch(msg, command)) if db.get_team(command.split("\n",1)[1].split("\n")[0]) == None:
await save_task save_task = asyncio.create_task(save_team_batch(msg, command))
await save_task
else:
name = command.split('\n',1)[1].split('\n')[0]
await msg.channel.send(f"{name} already exists. Try a new name, maybe?")
else: else:
name = command.split('\n',1)[1].split('\n')[0] await msg.channel.send("The Null Team's already in the League, chief.")
await msg.channel.send(f"{name} already exists. Try a new name, maybe?")
elif command.startswith("showteam "): elif command.startswith("showteam"):
team = games.get_team(command.split(" ",1)[1]) if " " in command:
if team is not None: team = games.get_team(command.split(" ",1)[1])
await msg.channel.send(embed=build_team_embed(team)) if team is not None:
await msg.channel.send(embed=build_team_embed(team))
else:
await msg.channel.send("Can't find that team, boss. Typo?")
else: else:
await msg.channel.send("Can't find that team, boss. Typo?") await msg.channel.send("I need a team name to look 'em up, boss. If you want to gaze from up high, you might like the 'showallteams' command.")
elif command == ("showallteams"): elif command == ("showallteams"):
list_task = asyncio.create_task(team_pages(msg, games.get_all_teams())) list_task = asyncio.create_task(team_pages(msg, games.get_all_teams()))
await list_task await list_task
elif command.startswith("searchteams "): elif command.startswith("searchteams"):
search_term = command.split("searchteams ",1)[1] if " " in command:
if len(search_term) > 30: search_term = command.split("searchteams ",1)[1]
await msg.channel.send("Team names can't even be that long, chief. Try something shorter.") if len(search_term) > 30:
return await msg.channel.send("Team names can't even be that long, chief. Try something shorter.")
list_task = asyncio.create_task(team_pages(msg, games.search_team(search_term), search_term=search_term)) return
await list_task list_task = asyncio.create_task(team_pages(msg, games.search_team(search_term), search_term=search_term))
await list_task
else:
await msg.channel.send("Gotta say what you're looking for if you want to search.")
elif command == "credit": elif command == "credit":
await msg.channel.send("Our avatar was graciously provided to us, with permission, by @HetreaSky on Twitter.") await msg.channel.send("Our avatar was graciously provided to us, with permission, by @HetreaSky on Twitter.")