more generous role match function

This commit is contained in:
Bibin Muttappillil 2020-04-15 01:10:27 +02:00
parent e0029118f9
commit 240ad44e4c
2 changed files with 4 additions and 6 deletions

View File

@ -159,6 +159,6 @@ async def logout(ctx):
@developer @developer
async def debug(ctx): async def debug(ctx):
print("DEBUG") print("DEBUG")
print(ctx.message.author.id) print(ctx.message.content)
bot.run(TOKEN) bot.run(TOKEN)

View File

@ -1,4 +1,5 @@
import functools import functools
from fuzzywuzzy import fuzz
from werewolf_players import No_player from werewolf_players import No_player
@ -20,10 +21,7 @@ class Role:
@staticmethod @staticmethod
def match(message): def match(message):
for role_class in Role.__subclasses__(): return max(Role.__subclasses__(), key=lambda role_class: fuzz.ratio(message, role_class.name()))
if message.casefold() == role_class.name():
return role_class
raise ValueError(f"Invalid role: {message}")
@staticmethod @staticmethod
def no_player(func): def no_player(func):
@ -160,7 +158,7 @@ class Drunk(Role):
class Insomniac(Role): class Insomniac(Role):
@Role.no_player @Role.no_player
async def send_info(self): 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): class Villager(Role):