Add idle logging and tidy code

This commit is contained in:
Aadi Desai 2021-11-30 13:59:40 +00:00
parent 6ec9714e2b
commit 43057b949c
No known key found for this signature in database
GPG key ID: CFFFE425830EF4D9

14
app.py
View file

@ -9,6 +9,7 @@ bot = discord.Client()
mincooldown = 3 mincooldown = 3
maxcooldown = 10 maxcooldown = 10
counter = random.randrange(mincooldown, maxcooldown) counter = random.randrange(mincooldown, maxcooldown)
idleMessageCounter = 0
@bot.event @bot.event
@ -27,7 +28,9 @@ async def on_message(message):
if message.author == bot.user: if message.author == bot.user:
return return
elif message.author.id == 581890740360052764: elif message.author.id == 581890740360052764:
reply = re.split("(^| )(I'M|IM|I AM|I'm|Im|I am|i'm|im|i am)( )", message.content, 1) reply = re.split(
"(^| )(I'M|IM|I AM|I'm|Im|I am|i'm|im|i am)( )", message.content, 1
)
if len(reply) > 1: if len(reply) > 1:
print("Message from " + message.author.name + ": " + message.content) print("Message from " + message.author.name + ": " + message.content)
print( print(
@ -43,9 +46,13 @@ async def on_message(message):
) )
else: else:
global counter global counter
global idleMessageCounter
# TODO: Add detection for "genshin" and replace with "g*nshin" # TODO: Add detection for "genshin" and replace with "g*nshin"
reply = re.split("(^| )(I'M|IM|I AM|I'm|Im|I am|i'm|im|i am)( )", message.content, 1) reply = re.split(
"(^| )(I'M|IM|I AM|I'm|Im|I am|i'm|im|i am)( )", message.content, 1
)
if len(reply) > 1: if len(reply) > 1:
idleMessageCounter = 0
print("Message from " + message.author.name + ": " + message.content) print("Message from " + message.author.name + ": " + message.content)
print( print(
"Reply: Length:" "Reply: Length:"
@ -61,6 +68,9 @@ async def on_message(message):
counter = random.randrange(mincooldown, maxcooldown) counter = random.randrange(mincooldown, maxcooldown)
await message.reply("Hi " + reply[-1] + ", I'm Dad") await message.reply("Hi " + reply[-1] + ", I'm Dad")
print("Replied to " + message.author.name + " with Dad Joke") print("Replied to " + message.author.name + " with Dad Joke")
else:
idleMessageCounter += 1
print("Idle Message Counter: " + str(idleMessageCounter), end="\r")
with open("secrets.yaml") as stream: with open("secrets.yaml") as stream: