mirror of
https://github.com/pacnpal/Pac-cogs.git
synced 2025-12-20 02:41:06 -05:00
change to birthday
This commit is contained in:
3
birthday/.gitignore
vendored
Normal file
3
birthday/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
21
birthday/LICENSE
Normal file
21
birthday/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
Creative Commons Attribution 4.0 International License
|
||||
|
||||
This work is licensed under the Creative Commons Attribution 4.0 International License.
|
||||
|
||||
To view a copy of this license, visit:
|
||||
http://creativecommons.org/licenses/by/4.0/
|
||||
|
||||
or send a letter to:
|
||||
Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
|
||||
|
||||
The full text of the license can be found at:
|
||||
https://creativecommons.org/licenses/by/4.0/legalcode
|
||||
|
||||
You are free to:
|
||||
- Share — copy and redistribute the material in any medium or format
|
||||
- Adapt — remix, transform, and build upon the material for any purpose, even commercially.
|
||||
|
||||
Under the following terms:
|
||||
- Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
|
||||
|
||||
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
|
||||
64
birthday/README.md
Normal file
64
birthday/README.md
Normal file
@@ -0,0 +1,64 @@
|
||||
# Birthday Cog for Red-DiscordBot
|
||||
|
||||
This cog for [Red-DiscordBot](https://github.com/Cog-Creators/Red-DiscordBot) allows server administrators to assign a special "birthday role" to users until midnight Pacific Time.
|
||||
|
||||
## Features
|
||||
|
||||
- Assign a birthday role to a user that automatically expires at midnight Pacific Time
|
||||
- Restrict usage of the birthday command to specific roles
|
||||
- Ignore role hierarchy when assigning the birthday role
|
||||
- Admin commands to set up the birthday role and manage permissions
|
||||
|
||||
## Installation
|
||||
|
||||
To install this cog, follow these steps:
|
||||
|
||||
1. Ensure you have Red-DiscordBot V3 installed.
|
||||
2. Add the repository to your bot:
|
||||
```
|
||||
[p]repo add Pac-cogs https://github.com/pacnpal/Pac-cogs
|
||||
```
|
||||
3. Install the cog:
|
||||
```
|
||||
[p]cog install Pac-cogs birthday
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
After installation, load the cog with:
|
||||
```
|
||||
[p]load birthday
|
||||
```
|
||||
|
||||
### Admin Setup
|
||||
|
||||
Before the cog can be used, an admin needs to set it up:
|
||||
|
||||
1. Set the birthday role:
|
||||
```
|
||||
[p]birthdayset role @BirthdayRole
|
||||
```
|
||||
2. Add roles that can use the birthday command:
|
||||
```
|
||||
[p]birthdayset addrole @AllowedRole
|
||||
```
|
||||
|
||||
### Using the Birthday Command
|
||||
|
||||
Users with allowed roles can assign the birthday role to a member:
|
||||
```
|
||||
[p]birthday @User
|
||||
```
|
||||
|
||||
The birthday role will be automatically removed at midnight Pacific Time.
|
||||
|
||||
## Commands
|
||||
|
||||
- `[p]birthdayset role @Role`: Set the birthday role
|
||||
- `[p]birthdayset addrole @Role`: Add a role that can use the birthday command
|
||||
- `[p]birthdayset removerole @Role`: Remove a role from using the birthday command
|
||||
- `[p]birthday @User`: Assign the birthday role to a user
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the Creative Commons Attribution 4.0 International License - see the [LICENSE](LICENSE) file for details.
|
||||
95
birthday/birthday.py
Normal file
95
birthday/birthday.py
Normal file
@@ -0,0 +1,95 @@
|
||||
import discord
|
||||
from redbot.core import commands, checks
|
||||
from redbot.core.bot import Red
|
||||
from redbot.core.config import Config
|
||||
from datetime import datetime, time, timedelta
|
||||
|
||||
class Birthday(commands.Cog):
|
||||
"""A cog to assign a birthday role until midnight Pacific Time."""
|
||||
|
||||
def __init__(self, bot: Red):
|
||||
self.bot = bot
|
||||
self.config = Config.get_conf(self, identifier=1234567890)
|
||||
default_guild = {
|
||||
"birthday_role": None,
|
||||
"allowed_roles": []
|
||||
}
|
||||
self.config.register_guild(**default_guild)
|
||||
self.birthday_tasks = {}
|
||||
|
||||
@commands.group()
|
||||
@checks.admin_or_permissions(manage_roles=True)
|
||||
async def birthdayset(self, ctx):
|
||||
"""Birthday cog settings."""
|
||||
pass
|
||||
|
||||
@birthdayset.command()
|
||||
async def role(self, ctx, role: discord.Role):
|
||||
"""Set the birthday role."""
|
||||
await self.config.guild(ctx.guild).birthday_role.set(role.id)
|
||||
await ctx.send(f"Birthday role set to {role.name}")
|
||||
|
||||
@birthdayset.command()
|
||||
async def addrole(self, ctx, role: discord.Role):
|
||||
"""Add a role that can use the birthday command."""
|
||||
async with self.config.guild(ctx.guild).allowed_roles() as allowed_roles:
|
||||
if role.id not in allowed_roles:
|
||||
allowed_roles.append(role.id)
|
||||
await ctx.send(f"Added {role.name} to the list of roles that can use the birthday command.")
|
||||
|
||||
@birthdayset.command()
|
||||
async def removerole(self, ctx, role: discord.Role):
|
||||
"""Remove a role from using the birthday command."""
|
||||
async with self.config.guild(ctx.guild).allowed_roles() as allowed_roles:
|
||||
if role.id in allowed_roles:
|
||||
allowed_roles.remove(role.id)
|
||||
await ctx.send(f"Removed {role.name} from the list of roles that can use the birthday command.")
|
||||
|
||||
@commands.command()
|
||||
async def birthday(self, ctx, member: discord.Member):
|
||||
"""Assign the birthday role to a user until midnight Pacific Time."""
|
||||
# Check if the user has permission to use this command
|
||||
allowed_roles = await self.config.guild(ctx.guild).allowed_roles()
|
||||
if not any(role.id in allowed_roles for role in ctx.author.roles):
|
||||
return await ctx.send("You don't have permission to use this command.")
|
||||
|
||||
birthday_role_id = await self.config.guild(ctx.guild).birthday_role()
|
||||
if not birthday_role_id:
|
||||
return await ctx.send("The birthday role hasn't been set. An admin needs to set it using `[p]birthdayset role`.")
|
||||
|
||||
birthday_role = ctx.guild.get_role(birthday_role_id)
|
||||
if not birthday_role:
|
||||
return await ctx.send("The birthday role doesn't exist anymore. Please ask an admin to set it again.")
|
||||
|
||||
# Assign the role, ignoring hierarchy
|
||||
try:
|
||||
await member.add_roles(birthday_role, reason="Birthday role")
|
||||
except discord.Forbidden:
|
||||
return await ctx.send("I don't have permission to assign that role.")
|
||||
|
||||
await ctx.send(f"🎉 Happy Birthday, {member.mention}! You've been given the {birthday_role.name} role until midnight Pacific Time.")
|
||||
|
||||
# Schedule role removal
|
||||
utc_now = datetime.utcnow()
|
||||
pacific_offset = timedelta(hours=-8) # Pacific Standard Time offset
|
||||
pacific_now = utc_now + pacific_offset
|
||||
pacific_midnight = datetime.combine(pacific_now.date() + timedelta(days=1), time.min)
|
||||
utc_midnight = pacific_midnight - pacific_offset
|
||||
|
||||
if ctx.guild.id in self.birthday_tasks:
|
||||
self.birthday_tasks[ctx.guild.id].cancel()
|
||||
|
||||
self.birthday_tasks[ctx.guild.id] = self.bot.loop.create_task(self.remove_birthday_role(ctx.guild, member, birthday_role, utc_midnight))
|
||||
|
||||
async def remove_birthday_role(self, guild, member, role, when):
|
||||
"""Remove the birthday role at the specified time."""
|
||||
await discord.utils.sleep_until(when)
|
||||
try:
|
||||
await member.remove_roles(role, reason="Birthday role duration expired")
|
||||
except (discord.Forbidden, discord.HTTPException):
|
||||
pass # If we can't remove the role, we'll just let it be
|
||||
finally:
|
||||
del self.birthday_tasks[guild.id]
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(Birthday(bot))
|
||||
18
birthday/info.json
Normal file
18
birthday/info.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"author": [
|
||||
"PacNPal"
|
||||
],
|
||||
"install_msg": "Thank you for installing the Birthday cog! Make sure to set up the birthday role and allowed roles using `[p]birthdayset`.",
|
||||
"name": "Birthday",
|
||||
"short": "Assign a birthday role until midnight Pacific Time",
|
||||
"description": "This cog allows you to assign a special birthday role to users that automatically expires at midnight Pacific Time. It includes features to restrict usage to specific roles and ignore role hierarchy.",
|
||||
"tags": [
|
||||
"birthday",
|
||||
"role",
|
||||
"temporary"
|
||||
],
|
||||
"requirements": [],
|
||||
"min_bot_version": "3.5.0",
|
||||
"max_bot_version": "3.9.9",
|
||||
"type": "COG"
|
||||
}
|
||||
Reference in New Issue
Block a user