Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2bd4fcb136 | ||
|
|
2a91274d7f | ||
|
|
4fb4927fb8 | ||
|
|
fbd8419ccf | ||
|
|
09ff620e51 | ||
|
|
9c64e574fe | ||
|
|
011b6551b0 | ||
|
|
45b304308b |
@@ -7,7 +7,6 @@ From {highcouncil_election_announce} to {highcouncil_election_start}, you will b
|
|||||||
Clan Leader
|
Clan Leader
|
||||||
Discord Server Manager
|
Discord Server Manager
|
||||||
|
|
||||||
Each member of the CCE can cast one for each category by using the emotes: <:Rank_Owner:479008325137072155> for Clan Leader and <:Rank_Deputy:479008295319896064> for Discord Server Manager.
|
Each member of the CCE can vote once in each category (Discord Server Manager and Clan Leader). Alternatively, you may choose to intentionally abstain.
|
||||||
If needed, the icon 🤷 can be used to abstain to vote in any or both categories and it should be applied to all candidates of that category.
|
|
||||||
|
|
||||||
Votes can be cast until {highcouncil_election_end}, so we can announce and have everyone set up to start the term by {term_start}.
|
Votes can be cast until {highcouncil_election_end}, so we can announce and have everyone set up to start the term by {term_start}.
|
||||||
+108
-9
@@ -4,8 +4,10 @@ Contains commands and views for request commands.
|
|||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from config import DakinyConfig
|
from config import DakinyConfig
|
||||||
|
from database_setup.sql_data_classes import Presences, engine
|
||||||
|
|
||||||
|
|
||||||
class RequestCog(commands.Cog, name="Request Commands"):
|
class RequestCog(commands.Cog, name="Request Commands"):
|
||||||
@@ -25,12 +27,46 @@ class RequestCog(commands.Cog, name="Request Commands"):
|
|||||||
Parent slash command for help. Never called.
|
Parent slash command for help. Never called.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@request.subcommand(
|
||||||
|
description="Request to add a presence to the bot's presence list."
|
||||||
|
)
|
||||||
|
async def add_presence(
|
||||||
|
self,
|
||||||
|
interaction: nextcord.Interaction,
|
||||||
|
presence: str = nextcord.SlashOption(
|
||||||
|
required=True,
|
||||||
|
min_length=1,
|
||||||
|
max_length=100,
|
||||||
|
description="The presence you want to add.",
|
||||||
|
),
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Sends a message to admins to request to add a presence.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||||
|
presence (str): The presence to add.
|
||||||
|
"""
|
||||||
|
|
||||||
|
config: DakinyConfig = self.bot.config
|
||||||
|
content = f'<@{interaction.user.id}> would like to add presence" {presence}."'
|
||||||
|
view = PresenceChange(presence)
|
||||||
|
await self.bot.get_channel(config.params.admin_channel_id).send(
|
||||||
|
content=content, view=view
|
||||||
|
)
|
||||||
|
await interaction.response.send_message(
|
||||||
|
"Request sent to admins.", ephemeral=True
|
||||||
|
)
|
||||||
|
|
||||||
@request.subcommand(description="Request to change your Dakiny nickname")
|
@request.subcommand(description="Request to change your Dakiny nickname")
|
||||||
async def change_nickname(
|
async def change_nickname(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
new_nickname: str = nextcord.SlashOption(
|
new_nickname: str = nextcord.SlashOption(
|
||||||
required=True, min_length=2, max_length=32, description="Your requested new nickname."
|
required=True,
|
||||||
|
min_length=2,
|
||||||
|
max_length=32,
|
||||||
|
description="Your requested new nickname.",
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
@@ -44,8 +80,12 @@ class RequestCog(commands.Cog, name="Request Commands"):
|
|||||||
config: DakinyConfig = self.bot.config
|
config: DakinyConfig = self.bot.config
|
||||||
content = f'<@{interaction.user.id}> would like to change their username to "{new_nickname}."'
|
content = f'<@{interaction.user.id}> would like to change their username to "{new_nickname}."'
|
||||||
view = UsernameRequest(interaction.user.id, new_nickname)
|
view = UsernameRequest(interaction.user.id, new_nickname)
|
||||||
await self.bot.get_channel(config.params.admin_channel_id).send(content=content, view=view)
|
await self.bot.get_channel(config.params.admin_channel_id).send(
|
||||||
await interaction.response.send_message("Request sent to admins.", ephemeral=True)
|
content=content, view=view
|
||||||
|
)
|
||||||
|
await interaction.response.send_message(
|
||||||
|
"Request sent to admins.", ephemeral=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class UsernameRequest(nextcord.ui.View):
|
class UsernameRequest(nextcord.ui.View):
|
||||||
@@ -53,13 +93,19 @@ class UsernameRequest(nextcord.ui.View):
|
|||||||
View provides approve and deny buttons and action for a username change request.
|
View provides approve and deny buttons and action for a username change request.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, user_id: int, new_nickname: str, *, timeout: float | None = 180, auto_defer: bool = True):
|
def __init__(
|
||||||
super().__init__(timeout=timeout, auto_defer=auto_defer)
|
self,
|
||||||
|
user_id: int,
|
||||||
|
new_nickname: str,
|
||||||
|
):
|
||||||
|
super().__init__(timeout=None, auto_defer=True)
|
||||||
self.user_id = user_id
|
self.user_id = user_id
|
||||||
self.new_nickname = new_nickname
|
self.new_nickname = new_nickname
|
||||||
|
|
||||||
@nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green)
|
@nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green)
|
||||||
async def approve(self, button: nextcord.ui.Button, interaction: nextcord.Interaction):
|
async def approve(
|
||||||
|
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Approve button for a nickname change request. Changes the target's nickname to self.new_nickname.
|
Approve button for a nickname change request. Changes the target's nickname to self.new_nickname.
|
||||||
Catches an error if the target as a higher role than the bot.
|
Catches an error if the target as a higher role than the bot.
|
||||||
@@ -73,7 +119,10 @@ class UsernameRequest(nextcord.ui.View):
|
|||||||
if user is not None:
|
if user is not None:
|
||||||
try:
|
try:
|
||||||
await user.edit(nick=self.new_nickname)
|
await user.edit(nick=self.new_nickname)
|
||||||
content = interaction.message.content + f"\nApproved by <@{interaction.user.id}>."
|
content = (
|
||||||
|
interaction.message.content
|
||||||
|
+ f"\nApproved by <@{interaction.user.id}>."
|
||||||
|
)
|
||||||
await interaction.response.edit_message(content=content, view=None)
|
await interaction.response.edit_message(content=content, view=None)
|
||||||
except nextcord.errors.Forbidden:
|
except nextcord.errors.Forbidden:
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(
|
||||||
@@ -84,10 +133,13 @@ class UsernameRequest(nextcord.ui.View):
|
|||||||
interaction.message.content
|
interaction.message.content
|
||||||
+ "\n\nFailed. User has too high permissions for bot to change nickname."
|
+ "\n\nFailed. User has too high permissions for bot to change nickname."
|
||||||
)
|
)
|
||||||
await interaction.followup.edit_message(interaction.message.id, content=content, view=None)
|
await interaction.followup.edit_message(
|
||||||
|
interaction.message.id, content=content, view=None
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
await interaction.response.edit_message(
|
await interaction.response.edit_message(
|
||||||
content="An error occured while changing the user's nickname.", view=None
|
content="An error occured while changing the user's nickname.",
|
||||||
|
view=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
@nextcord.ui.button(label="Deny", style=nextcord.ButtonStyle.red)
|
@nextcord.ui.button(label="Deny", style=nextcord.ButtonStyle.red)
|
||||||
@@ -101,3 +153,50 @@ class UsernameRequest(nextcord.ui.View):
|
|||||||
"""
|
"""
|
||||||
content = interaction.message.content + f"\nDenied by <@{interaction.user.id}>."
|
content = interaction.message.content + f"\nDenied by <@{interaction.user.id}>."
|
||||||
await interaction.response.edit_message(content=content, view=None)
|
await interaction.response.edit_message(content=content, view=None)
|
||||||
|
|
||||||
|
|
||||||
|
class PresenceChange(nextcord.ui.View):
|
||||||
|
"""
|
||||||
|
View provides approve and deny buttons and action for a username change request.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
presence: str,
|
||||||
|
):
|
||||||
|
super().__init__(timeout=None, auto_defer=True)
|
||||||
|
self.presence = presence
|
||||||
|
|
||||||
|
@nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green)
|
||||||
|
async def approve(
|
||||||
|
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Approve button for a presence add request. Adds the presence to the database.
|
||||||
|
Removes the view from the interaction message.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
button (nextcord.ui.Button): Unused.
|
||||||
|
interaction (nextcord.Interaction): The interaction of the user clicking the button.
|
||||||
|
"""
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
|
session.add(Presences(Presence=self.presence))
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
content = (
|
||||||
|
interaction.message.content + f"\nApproved by <@{interaction.user.id}>."
|
||||||
|
)
|
||||||
|
await interaction.response.edit_message(content=content, view=None)
|
||||||
|
|
||||||
|
@nextcord.ui.button(label="Deny", style=nextcord.ButtonStyle.red)
|
||||||
|
async def deny(self, button: nextcord.ui.Button, interaction: nextcord.Interaction):
|
||||||
|
"""
|
||||||
|
Deny button for a presence add request. Just removes the view and logs who denied the request.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
button (nextcord.ui.Button): Unused.
|
||||||
|
interaction (nextcord.Interaction): The interaction of the user clicking the button.
|
||||||
|
"""
|
||||||
|
content = interaction.message.content + f"\nDenied by <@{interaction.user.id}>."
|
||||||
|
await interaction.response.edit_message(content=content, view=None)
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ Initializing code for all loops.
|
|||||||
|
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
from .daily_loop import DailyLoop
|
from cogs.loops.bot_presence import BotPresence
|
||||||
|
from cogs.loops.daily_loop import DailyLoop
|
||||||
|
|
||||||
|
|
||||||
def setup(bot: commands.Bot):
|
def setup(bot: commands.Bot):
|
||||||
@@ -12,4 +13,5 @@ def setup(bot: commands.Bot):
|
|||||||
Adds functions to bot.
|
Adds functions to bot.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
bot.add_cog(BotPresence(bot))
|
||||||
bot.add_cog(DailyLoop(bot))
|
bot.add_cog(DailyLoop(bot))
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
"""
|
||||||
|
Functions for controlling the bot's presence. Also contains the loop.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import nextcord
|
||||||
|
from nextcord.ext import commands, tasks
|
||||||
|
from sqlalchemy import func, select
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from database_setup.sql_data_classes import Presences, engine
|
||||||
|
|
||||||
|
|
||||||
|
class BotPresence(commands.Cog, name="Bot Presence"):
|
||||||
|
"""Class for bot presence functions."""
|
||||||
|
|
||||||
|
def __init__(self, bot: commands.Bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_guild_join(
|
||||||
|
self, guild: nextcord.Guild
|
||||||
|
): # pylint: disable=unused-argument
|
||||||
|
"""Listener for Guild Join. Updated presence on guild join."""
|
||||||
|
await self.change_presence()
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_ready(self):
|
||||||
|
"""Starts the loop when bot is ready."""
|
||||||
|
await self.bot.wait_until_ready()
|
||||||
|
# pylint doesn't recognize that periodic_change_presense is subclassed from tasks.loop.
|
||||||
|
self.periodic_change_presence.start() # pylint: disable=no-member
|
||||||
|
|
||||||
|
@tasks.loop(minutes=5)
|
||||||
|
async def periodic_change_presence(self):
|
||||||
|
"""Loops every 5 minutes and changes presence."""
|
||||||
|
await self.change_presence()
|
||||||
|
|
||||||
|
async def change_presence(self):
|
||||||
|
"""Randomly chooses a presence and updates bot's presence."""
|
||||||
|
|
||||||
|
with Session(engine) as session:
|
||||||
|
presence = session.scalar(
|
||||||
|
select(Presences.Presence).order_by(func.random())
|
||||||
|
)
|
||||||
|
|
||||||
|
await self.bot.change_presence(
|
||||||
|
activity=nextcord.CustomActivity(name="Custom Status", state=presence)
|
||||||
|
)
|
||||||
@@ -34,3 +34,8 @@ CREATE TABLE UserBirthday (
|
|||||||
Birthday varchar(5) not null,
|
Birthday varchar(5) not null,
|
||||||
PRIMARY KEY (UserId)
|
PRIMARY KEY (UserId)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE Presences (
|
||||||
|
Id integer PRIMARY KEY,
|
||||||
|
Presence varchar(100) not null
|
||||||
|
);
|
||||||
@@ -15,3 +15,4 @@ ElectionInformation = Base.classes.ElectionInformation
|
|||||||
CouncilMembers = Base.classes.CouncilMembers
|
CouncilMembers = Base.classes.CouncilMembers
|
||||||
Votes = Base.classes.Votes
|
Votes = Base.classes.Votes
|
||||||
UserBirthday = Base.classes.UserBirthday
|
UserBirthday = Base.classes.UserBirthday
|
||||||
|
Presences = Base.classes.Presences
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ def get_datetime(day: str) -> datetime:
|
|||||||
day = int(day.split("/")[1])
|
day = int(day.split("/")[1])
|
||||||
|
|
||||||
# ensure that year rolls over if current month is December and the next month is less than 12.
|
# ensure that year rolls over if current month is December and the next month is less than 12.
|
||||||
if datetime.today().month == 12 & month < 12:
|
if datetime.today().month == 12 and month < 12:
|
||||||
year += 1
|
year += 1
|
||||||
|
|
||||||
return datetime(year, month, day)
|
return datetime(year, month, day)
|
||||||
|
|||||||
Reference in New Issue
Block a user