mirror of
https://github.com/Ryujinx/ryuko-ng.git
synced 2024-12-23 01:25:29 +00:00
yubicootp: Attempt to make it work mid-sentence
This commit is contained in:
parent
44518e810e
commit
6f30585c96
|
@ -8,7 +8,7 @@ import asyncio
|
||||||
class YubicoOTP(Cog):
|
class YubicoOTP(Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.otp_re = re.compile("^[cbdefghijklnrtuv]{44}$")
|
self.otp_re = re.compile("(cc|vv)[cbdefghijklnrtuv]{42}$")
|
||||||
self.api_servers = [
|
self.api_servers = [
|
||||||
"https://api.yubico.com",
|
"https://api.yubico.com",
|
||||||
"https://api2.yubico.com",
|
"https://api2.yubico.com",
|
||||||
|
@ -93,8 +93,8 @@ class YubicoOTP(Cog):
|
||||||
@Cog.listener()
|
@Cog.listener()
|
||||||
async def on_message(self, message):
|
async def on_message(self, message):
|
||||||
await self.bot.wait_until_ready()
|
await self.bot.wait_until_ready()
|
||||||
strin = self.otp_re.match(message.content)
|
strin = self.otp_re.match(message.content.strip())
|
||||||
if strin and (strin.string[:2] == "cc" or strin.string[:2] == "vv"):
|
if strin:
|
||||||
otp = strin.string
|
otp = strin.string
|
||||||
# Validate OTP
|
# Validate OTP
|
||||||
validation_result = await self.validate_yubico_otp(otp)
|
validation_result = await self.validate_yubico_otp(otp)
|
||||||
|
@ -105,6 +105,10 @@ class YubicoOTP(Cog):
|
||||||
serial = self.get_serial(otp)
|
serial = self.get_serial(otp)
|
||||||
serial_str = f" (serial: `{serial}`)" if serial else ""
|
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
|
# If OTP is valid, tell user that it was revoked
|
||||||
msg = await message.channel.send(
|
msg = await message.channel.send(
|
||||||
f"{message.author.mention}: Ate Yubico OTP `{otp}`{serial_str}"
|
f"{message.author.mention}: Ate Yubico OTP `{otp}`{serial_str}"
|
||||||
|
|
Loading…
Reference in a new issue