More easter eggs

pull/133/head
stijndcl 2022-09-20 01:40:05 +02:00
parent 1fe04b3687
commit 7517f844d8
3 changed files with 90 additions and 13 deletions

View File

@ -0,0 +1,69 @@
from sqlalchemy.ext.asyncio import AsyncSession
from database.engine import DBSession
from database.schemas import EasterEgg
__all__ = ["main"]
async def main():
"""Add the initial easter egg responses"""
session: AsyncSession
async with DBSession() as session:
# https://www.youtube.com/watch?v=Vd6hVYkkq88
do_not_cite_deep_magic = EasterEgg(
match=r"((don'?t)|(do not)) cite the deep magic to me,? witch",
response="_I was there when it was written_",
exact=True,
)
# https://www.youtube.com/watch?v=LrHTR22pIhw
dormammu = EasterEgg(match=r"dormammu", response="_I've come to bargain_", exact=True)
# https://youtu.be/rEq1Z0bjdwc?t=7
hello_there = EasterEgg(match=r"hello there", response="_General Kenobi_", exact=True)
# https://www.youtube.com/watch?v=_WZCvQ5J3pk
hey = EasterEgg(
match=r"hey,? ?(?:you)?",
response="_You're finally awake!_",
exact=True,
)
# https://www.youtube.com/watch?v=2z5ZDC1eQEA
is_this_the_kk = EasterEgg(
match=r"is (this|dis) (.*)", response="No, this is Patrick.", exact=False, startswith=True
)
# https://youtu.be/d6uckPRKvSg?t=4
its_over_anakin = EasterEgg(
match=r"it'?s over ", response="_I have the high ground_", exact=False, startswith=True
)
# https://www.youtube.com/watch?v=Vx5prDjKAcw
perfectly_balanced = EasterEgg(match=r"perfectly balanced", response="_As all things should be_", exact=True)
# ( ͡◉ ͜ʖ ͡◉)
sixty_nine = EasterEgg(match=r"(^69$)|(^69 )|( 69 )|( 69$)", response="_Nice_", exact=False, startswith=False)
# https://youtu.be/7mbLzkNFDs8?t=19
what_did_it_cost = EasterEgg(match=r"what did it cost\??", response="_Everything_", exact=True)
# https://youtu.be/EJfYh-JVbJA?t=10
you_cant_defeat_me = EasterEgg(match=r"you can'?t defeat me", response="_I know, but he can_", exact=False)
session.add_all(
[
do_not_cite_deep_magic,
dormammu,
hello_there,
hey,
is_this_the_kk,
its_over_anakin,
perfectly_balanced,
sixty_nine,
what_did_it_cost,
you_cant_defeat_me,
]
)
await session.commit()

View File

@ -1,9 +1,11 @@
import random
import re
from typing import Optional
import discord
from discord.ext import commands
import settings
from database.utils.caches import EasterEggCache
from didier.utils.discord.prefix import match_prefix
@ -11,11 +13,8 @@ __all__ = ["detect_easter_egg"]
def _roll_easter_egg(response: str) -> Optional[str]:
"""Roll a random chance for an easter egg to be responded with
The chance for an easter egg to be used is 33%
"""
rolled = random.randint(0, 100) < 33
"""Roll a random chance for an easter egg to be responded with"""
rolled = random.randint(0, 100) < settings.EASTER_EGG_CHANCE
return response if rolled else None
@ -23,7 +22,8 @@ async def detect_easter_egg(client: commands.Bot, message: discord.Message, cach
"""Try to detect an easter egg in a message"""
prefix = match_prefix(client, message)
content = message.content.strip().lower()
# Remove markdown and whitespace for better matches
content = message.content.strip().strip("_* \t\n").lower()
# Message calls Didier
if prefix is not None:
@ -37,12 +37,17 @@ async def detect_easter_egg(client: commands.Bot, message: discord.Message, cach
return None
for easter_egg in cache.easter_eggs:
# Exact matches
if easter_egg.exact and easter_egg.match == content:
return _roll_easter_egg(easter_egg.response)
pattern = easter_egg.match
# Matches that start with a certain term
if easter_egg.startswith and content.startswith(easter_egg.match):
# Use regular expressions to easily allow slight variations
if easter_egg.exact:
pattern = rf"^{pattern}$"
elif easter_egg.startswith:
pattern = rf"^{pattern}"
matched = re.search(pattern, content)
if matched is not None:
return _roll_easter_egg(easter_egg.response)
return None

View File

@ -12,6 +12,10 @@ __all__ = [
"SANDBOX",
"TESTING",
"LOGFILE",
"SEMESTER",
"YEAR",
"MENU_TIMEOUT",
"EASTER_EGG_CHANCE",
"POSTGRES_DB",
"POSTGRES_USER",
"POSTGRES_PASS",
@ -24,12 +28,10 @@ __all__ = [
"DISCORD_BOOS_REACT",
"DISCORD_CUSTOM_COMMAND_PREFIX",
"UFORA_ANNOUNCEMENTS_CHANNEL",
"BA3_ROLE",
"UFORA_RSS_TOKEN",
"URBAN_DICTIONARY_TOKEN",
"IMGFLIP_NAME",
"IMGFLIP_PASSWORD",
"BA3_SCHEDULE_URL",
"ScheduleType",
"ScheduleInfo",
"SCHEDULE_DATA",
@ -43,6 +45,7 @@ LOGFILE: str = env.str("LOGFILE", "didier.log")
SEMESTER: int = env.int("SEMESTER", 2)
YEAR: int = env.int("YEAR", 3)
MENU_TIMEOUT: int = env.int("MENU_TIMEOUT", 30)
EASTER_EGG_CHANCE: int = env.int("EASTER_EGG_CHANCE", 15)
"""Database"""
# PostgreSQL