start on moderation stuff

This commit is contained in:
chrisbell committed 2026-11-10 17:14:35 -06:00
1 parent b538da6033
commit 53e0daac1e
6 files changed
+271 -15

No files matched your search

+8 -14
View File
@@ -90,11 +90,10 @@ class Countdown(commands.Cog):
"""Posts once per day during the 9:00-9:04 Central window."""
try:
now = datetime.now(CENTRAL)
if (
now.hour != DAILY_HOUR
or now.minute >= 5
or self.last_posted == now.date()
):
today = now.date().isoformat()
if now.hour != DAILY_HOUR or now.minute >= 5:
return
if await self.bot.db.get_setting("countdown_last_posted") == today:
return
embed = countdown_embed()
@@ -102,19 +101,14 @@ class Countdown(commands.Cog):
return
guild = self.bot.get_guild(config.GUILD.id)
channel = (
discord.utils.get(guild.text_channels, name=DAILY_CHANNEL)
if guild
else None
)
channel = (discord.utils.get(guild.text_channels, name=DAILY_CHANNEL)
if guild else None)
if channel is None:
print(
f"daily_countdown: no channel named {DAILY_CHANNEL!r}", flush=True
)
print(f"daily_countdown: no channel named {DAILY_CHANNEL!r}", flush=True)
return
await channel.send(embed=embed)
self.last_posted = now.date()
await self.bot.db.set_setting("countdown_last_posted", today)
print(f"daily_countdown: posted in #{DAILY_CHANNEL}", flush=True)
except discord.HTTPException as e:
print(f"daily_countdown: could not post: {e}", flush=True)
+72
View File
@@ -0,0 +1,72 @@
import discord
from discord import app_commands
from discord.ext import commands
import config
import guildconf
class Settings(commands.Cog):
def __init__(self, bot):
self.bot = bot
group = app_commands.Group(
name="config",
description="Configure the bot",
guild_ids=[config.GUILD.id],
guild_only=True,
default_permissions=discord.Permissions(manage_guild=True),
)
@group.command(name="modlog", description="Set the mod-log channel")
@app_commands.describe(channel="Channel where moderation actions are logged")
@app_commands.checks.has_permissions(manage_guild=True)
async def modlog(self, interaction: discord.Interaction,
channel: discord.TextChannel):
perms = channel.permissions_for(interaction.guild.me)
if not (perms.view_channel and perms.send_messages and perms.embed_links):
await interaction.response.send_message(
f"I need View Channel, Send Messages and Embed Links in {channel.mention}.",
ephemeral=True)
return
await self.bot.db.set_setting(guildconf.MOD_LOG, channel.id)
await interaction.response.send_message(
f"Mod log set to {channel.mention}.", ephemeral=True)
@group.command(name="modrole", description="Set the moderator role")
@app_commands.checks.has_permissions(manage_guild=True)
async def modrole(self, interaction: discord.Interaction, role: discord.Role):
await self._set_role(interaction, guildconf.MOD_ROLE, role, "Moderator")
@group.command(name="adminrole", description="Set the admin role")
@app_commands.checks.has_permissions(manage_guild=True)
async def adminrole(self, interaction: discord.Interaction, role: discord.Role):
await self._set_role(interaction, guildconf.ADMIN_ROLE, role, "Admin")
@group.command(name="show", description="Show the current configuration")
@app_commands.checks.has_permissions(manage_guild=True)
async def show(self, interaction: discord.Interaction):
def fmt(value, prefix):
return f"<{prefix}{value}>" if value else "not set"
modlog = await guildconf.get_id(self.bot, guildconf.MOD_LOG)
modrole = await guildconf.get_id(self.bot, guildconf.MOD_ROLE)
adminrole = await guildconf.get_id(self.bot, guildconf.ADMIN_ROLE)
await interaction.response.send_message(
f"Mod log: {fmt(modlog, '#')}\n"
f"Moderator role: {fmt(modrole, '@&')}\n"
f"Admin role: {fmt(adminrole, '@&')}",
ephemeral=True)
async def _set_role(self, interaction, key, role, label):
if role.is_default():
await interaction.response.send_message(
"@everyone can't be used here.", ephemeral=True)
return
await self.bot.db.set_setting(key, role.id)
await interaction.response.send_message(
f"{label} role set to {role.mention}.", ephemeral=True)
async def setup(bot):
await bot.add_cog(Settings(bot))