gondilinabot-python/app.py

106 lines
3.3 KiB
Python
Raw Permalink Normal View History

2021-11-10 00:29:32 +00:00
import discord
import re
import yaml
import random
2021-12-02 01:27:46 +00:00
import aiocron
2021-11-10 00:29:32 +00:00
# from discord.ext import commands
bot = discord.Client()
mincooldown = 3
maxcooldown = 10
counter = random.randrange(mincooldown, maxcooldown)
2021-11-30 13:59:40 +00:00
idleMessageCounter = 0
2021-11-10 00:29:32 +00:00
@bot.event
async def on_ready():
print("Logged in as")
2022-06-14 18:21:27 +00:00
print(f"{bot.user.name}#{bot.user.discriminator}")
2021-11-10 00:29:32 +00:00
print(bot.user.id)
2022-06-14 18:21:27 +00:00
print(f"Init Counter: {str(counter)}")
await bot.change_presence(
status=discord.Status.online, activity=discord.Game(name="with Godlina")
)
2021-11-10 00:29:32 +00:00
@bot.event
async def on_message(message):
global counter
global idleMessageCounter
2021-11-10 00:29:32 +00:00
if message.author == bot.user:
return
elif bool(re.search("\|\|", message.content)):
idleMessageCounter += 1
if idleMessageCounter % 5 == 0:
await bot.change_presence(
status=discord.Status.online,
activity=discord.Game(
2022-06-14 18:21:27 +00:00
name=f"with Godlina [{idleMessageCounter}]"
),
)
elif message.author.id == 581890740360052764:
2021-11-30 13:59:40 +00:00
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:
2022-06-14 18:21:27 +00:00
print(f"Message from {message.author.name}: {message.content}")
print(
"Reply: Length:"
+ str(len(reply))
+ ", Final Contents: {"
+ reply[-1]
+ "}"
)
2022-06-14 18:21:27 +00:00
await message.reply(f"Hi {reply[-1]}, I'm Dad")
print(
2022-06-14 18:21:27 +00:00
f"Replied unconditionally to {message.author.name} with Dad Joke"
)
2021-11-10 00:29:32 +00:00
else:
2021-11-18 22:29:44 +00:00
# TODO: Add detection for "genshin" and replace with "g*nshin"
2021-11-30 13:59:40 +00:00
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:
2021-11-30 13:59:40 +00:00
idleMessageCounter = 0
2022-06-14 18:21:27 +00:00
print(f"Message from {message.author.name}: {message.content}")
print(
"Reply: Length:"
+ str(len(reply))
+ ", Final Contents: {"
+ reply[-1]
+ "}"
)
if counter > 0:
counter -= 1
2022-06-14 18:21:27 +00:00
print(f"Cooldown: {counter} messages")
else:
counter = random.randrange(mincooldown, maxcooldown)
2022-06-14 18:21:27 +00:00
await message.reply(f"Hi {reply[-1]}, I'm Dad")
print(f"Replied to {message.author.name} with Dad Joke")
2021-11-30 13:59:40 +00:00
else:
idleMessageCounter += 1
if idleMessageCounter % 5 == 0:
await bot.change_presence(
status=discord.Status.online,
activity=discord.Game(
2022-06-14 18:21:27 +00:00
name=f"with Godlina [{idleMessageCounter}]"
),
)
2021-11-10 00:29:32 +00:00
2021-12-02 01:27:46 +00:00
@aiocron.crontab("0 0 * * *") # Runs every day at midnight
async def steal_first_message():
channel = bot.get_channel(249891637008793600)
await channel.send("<@295575162869383169> Not this time :)")
2021-11-10 00:29:32 +00:00
with open("secrets.yaml") as stream:
try:
secrets = yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)
print("Secrets.yaml failed to load, exiting...")
2022-06-14 18:21:27 +00:00
raise SystemExit from exc
bot.run(secrets["bottoken"])