feat(bot): ✨ Send a message to the user when they find an easter egg.
This commit is contained in:
@@ -0,0 +1,10 @@
|
|||||||
|
import enum
|
||||||
|
|
||||||
|
|
||||||
|
class EasterEggCommand(enum.IntFlag):
|
||||||
|
"""Flags representing the easter eggs.
|
||||||
|
|
||||||
|
This is used to keep track of which easter eggs did the user find."""
|
||||||
|
|
||||||
|
CATMASK = 1
|
||||||
|
USERPHONE = 2
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
from discord.ext import commands
|
||||||
|
|
||||||
|
from payphone.db import utils
|
||||||
|
from payphone.cogs.easter import EasterEggCommand
|
||||||
|
|
||||||
|
|
||||||
|
def easter_egg(command: EasterEggCommand):
|
||||||
|
"""Send rewards to the user when they find an easter egg."""
|
||||||
|
|
||||||
|
async def predicate(ctx: commands.Context) -> bool:
|
||||||
|
if ctx.author.bot:
|
||||||
|
return False
|
||||||
|
|
||||||
|
user, _ = await utils.get_user(ctx.author)
|
||||||
|
|
||||||
|
if command not in user.found_easter_eggs:
|
||||||
|
user.found_easter_eggs |= command
|
||||||
|
|
||||||
|
remaining_easter_eggs = len(list(EasterEggCommand)) - len(
|
||||||
|
user.found_easter_eggs.name.split("|")
|
||||||
|
)
|
||||||
|
await ctx.send(
|
||||||
|
"✨ You found an easter egg! "
|
||||||
|
+ (
|
||||||
|
f"There are {remaining_easter_eggs} easter eggs remaining."
|
||||||
|
if remaining_easter_eggs > 0
|
||||||
|
else "There are no easter eggs left, congratulations! 🎉"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
await user.save()
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
return commands.check(predicate)
|
||||||
@@ -8,6 +8,7 @@ from payphone import bot
|
|||||||
from payphone.db import models
|
from payphone.db import models
|
||||||
from payphone.cogs import base
|
from payphone.cogs import base
|
||||||
from payphone.core import constants
|
from payphone.core import constants
|
||||||
|
from payphone.cogs.easter import EasterEggCommand, checks
|
||||||
|
|
||||||
|
|
||||||
class Easter(base.Cog):
|
class Easter(base.Cog):
|
||||||
@@ -17,6 +18,7 @@ class Easter(base.Cog):
|
|||||||
self.bot = bot_instance
|
self.bot = bot_instance
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
|
@checks.easter_egg(EasterEggCommand.CATMASK)
|
||||||
@transactions.atomic()
|
@transactions.atomic()
|
||||||
async def catmask(self, ctx: commands.Context) -> None:
|
async def catmask(self, ctx: commands.Context) -> None:
|
||||||
"""
|
"""
|
||||||
@@ -45,6 +47,7 @@ class Easter(base.Cog):
|
|||||||
await channel_rs.save()
|
await channel_rs.save()
|
||||||
|
|
||||||
@commands.command(aliases=["speakerphone"])
|
@commands.command(aliases=["speakerphone"])
|
||||||
|
@checks.easter_egg(EasterEggCommand.USERPHONE)
|
||||||
async def userphone(self, ctx: commands.Context) -> None:
|
async def userphone(self, ctx: commands.Context) -> None:
|
||||||
"""
|
"""
|
||||||
The second easter egg! You found it.
|
The second easter egg! You found it.
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
from tortoise import BaseDBAsyncClient
|
||||||
|
|
||||||
|
|
||||||
|
async def upgrade(db: BaseDBAsyncClient) -> str:
|
||||||
|
return """
|
||||||
|
ALTER TABLE "user" ADD "found_easter_eggs" SMALLINT NOT NULL DEFAULT 0;"""
|
||||||
|
|
||||||
|
|
||||||
|
async def downgrade(db: BaseDBAsyncClient) -> str:
|
||||||
|
return """
|
||||||
|
ALTER TABLE "user" DROP COLUMN "found_easter_eggs";"""
|
||||||
@@ -10,6 +10,7 @@ from discord import webhook
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
from payphone.core import config, constants
|
from payphone.core import config, constants
|
||||||
|
from payphone.cogs.easter import EasterEggCommand
|
||||||
|
|
||||||
|
|
||||||
class User(models.Model):
|
class User(models.Model):
|
||||||
@@ -17,6 +18,7 @@ class User(models.Model):
|
|||||||
username: str = fields.CharField(max_length=32, db_index=True)
|
username: str = fields.CharField(max_length=32, db_index=True)
|
||||||
is_masked: bool = fields.BooleanField(default=False)
|
is_masked: bool = fields.BooleanField(default=False)
|
||||||
is_moderator: bool = fields.BooleanField(default=False)
|
is_moderator: bool = fields.BooleanField(default=False)
|
||||||
|
found_easter_eggs: int = fields.IntEnumField(EasterEggCommand, default=0)
|
||||||
profiles: fields.BackwardFKRelation["Profile"]
|
profiles: fields.BackwardFKRelation["Profile"]
|
||||||
call_rss: fields.BackwardFKRelation["CallUserChannelRelationship"]
|
call_rss: fields.BackwardFKRelation["CallUserChannelRelationship"]
|
||||||
leaderboard_position: int | None = fields.IntField(
|
leaderboard_position: int | None = fields.IntField(
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ async def get_channel(channel: discord.TextChannel) -> models.Channel:
|
|||||||
|
|
||||||
async def get_user(
|
async def get_user(
|
||||||
user: discord.User | discord.Member,
|
user: discord.User | discord.Member,
|
||||||
) -> Tuple[models.User, models.Profile | None]:
|
) -> Tuple[models.User, models.Profile]:
|
||||||
"""Returns a user from the database, creating or updating it if it already exists.
|
"""Returns a user from the database, creating or updating it if it already exists.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
|||||||
Reference in New Issue
Block a user