yubicootp: Attempt to make it work mid-sentence

This commit is contained in:
Ave 2020-10-13 17:29:00 +03:00
parent 44518e810e
commit 6f30585c96
No known key found for this signature in database
GPG key ID: 398DD7BD03276F6D

View file

@ -8,7 +8,7 @@ import asyncio
class YubicoOTP(Cog):
def __init__(self, bot):
self.bot = bot
self.otp_re = re.compile("^[cbdefghijklnrtuv]{44}$")
self.otp_re = re.compile("(cc|vv)[cbdefghijklnrtuv]{42}$")
self.api_servers = [
"https://api.yubico.com",
"https://api2.yubico.com",
@ -93,8 +93,8 @@ class YubicoOTP(Cog):
@Cog.listener()
async def on_message(self, message):
await self.bot.wait_until_ready()
strin = self.otp_re.match(message.content)
if strin and (strin.string[:2] == "cc" or strin.string[:2] == "vv"):
strin = self.otp_re.match(message.content.strip())
if strin:
otp = strin.string
# Validate OTP
validation_result = await self.validate_yubico_otp(otp)
@ -105,6 +105,10 @@ class YubicoOTP(Cog):
serial = self.get_serial(otp)
serial_str = f" (serial: `{serial}`)" if serial else ""
# If the message content is _just_ the OTP code, delete it too
if message.content.strip() == otp:
await message.delete()
# If OTP is valid, tell user that it was revoked
msg = await message.channel.send(
f"{message.author.mention}: Ate Yubico OTP `{otp}`{serial_str}"