more generous role match function
This commit is contained in:
parent
e0029118f9
commit
240ad44e4c
|
@ -159,6 +159,6 @@ async def logout(ctx):
|
|||
@developer
|
||||
async def debug(ctx):
|
||||
print("DEBUG")
|
||||
print(ctx.message.author.id)
|
||||
print(ctx.message.content)
|
||||
|
||||
bot.run(TOKEN)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import functools
|
||||
from fuzzywuzzy import fuzz
|
||||
from werewolf_players import No_player
|
||||
|
||||
|
||||
|
@ -20,10 +21,7 @@ class Role:
|
|||
|
||||
@staticmethod
|
||||
def match(message):
|
||||
for role_class in Role.__subclasses__():
|
||||
if message.casefold() == role_class.name():
|
||||
return role_class
|
||||
raise ValueError(f"Invalid role: {message}")
|
||||
return max(Role.__subclasses__(), key=lambda role_class: fuzz.ratio(message, role_class.name()))
|
||||
|
||||
@staticmethod
|
||||
def no_player(func):
|
||||
|
@ -160,7 +158,7 @@ class Drunk(Role):
|
|||
class Insomniac(Role):
|
||||
@Role.no_player
|
||||
async def send_info(self):
|
||||
await self.player.send_info(f"You are now: {self.player.day_role}")
|
||||
await self.player.send_info(f"You are: {self.player.day_role}")
|
||||
|
||||
|
||||
class Villager(Role):
|
||||
|
|
Loading…
Reference in New Issue