Files
bot.py
requirements.txt
Code
2 1,385
bot.py
import asyncio
import json
import logging
import os
import re
import sqlite3
from datetime import datetime, timezone
from pathlib import Path
from typing import Optional
import discord
from discord import app_commands
from discord.ext import commands
from dotenv import load_dotenv
load_dotenv()
logging.basicConfig(
level=os.getenv("LOG_LEVEL", "INFO").upper(),
format="%(asctime)s %(levelname)s %(name)s: %(message)s",
)
logger = logging.getLogger("smp_portal")
DM_ADVERTISEMENT = """# sᴍᴘ ᴘᴏʀᴛᴀʟ | Staff Needed
SMP Portal is the ultimate partnership network built to help Minecraft server owners grow and connect.
# What We Offer:
🤝 Partner Trades — Cross-promote with active server owners.
🤝 Channel Partnerships — Cross-promote each other's servers in channels.
🌐 Server Directory — Get featured in high-visibility channels.
📈 Player Reach — Easy access to discover new SMPs as a player.
✨ Self Promo — Promote your server for free.
✨ Staff Self Promo — Apply for staff and get access to promote your server more.
# Partnerships & Tickets Are Open!
Join now to feature your server.
🔗 https://discord.gg/PskZcbgAwC
---
# Giveaway
Join our server and go to the Pixelraidhosting channel.
Join their server, then return to the channel and enter the giveaway to get **50 percent off lifetime Minecraft hosting** if you win.
-# Disclaimer: If you are not in the Discord server, you cannot win the prize.
-# Looking for Main Operators | DM @elifold"""
INVITE_PATTERN = re.compile(
r"(?:https?://)?(?:www\.)?(?:discord\.gg|discord(?:app)?\.com/invite)/([A-Za-z0-9-]+)",
re.IGNORECASE,
)
MESSAGE_LINK_PATTERN = re.compile(
r"https?://(?:www\.)?discord(?:app)?\.com/channels/(\d+|@me)/(\d+)/(\d+)"
)
IMAGE_EXTENSIONS = (".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp")
PORTAL_ROLE_ID = 1560768575088758884
def utc_now() -> datetime:
return datetime.now(timezone.utc)
def iso_now() -> str:
return utc_now().isoformat()
def parse_datetime(value: Optional[str]) -> Optional[datetime]:
if not value:
return None
try:
return datetime.fromisoformat(value)
except ValueError:
return None
def clip(value: str, limit: int) -> str:
return value if len(value) <= limit else value[: limit - 1] + "…"
def default_allowed_mentions() -> discord.AllowedMentions:
return discord.AllowedMentions.none()
class Database:
def __init__(self, path: str):
db_path = Path(path)
db_path.parent.mkdir(parents=True, exist_ok=True)
self.connection = sqlite3.connect(str(db_path), isolation_level=None)
self.connection.row_factory = sqlite3.Row
self.connection.execute("PRAGMA foreign_keys = ON")
self.connection.execute("PRAGMA journal_mode = WAL")
self.connection.executescript(
"""
CREATE TABLE IF NOT EXISTS partnership_settings (
guild_id INTEGER PRIMARY KEY,
submission_channel_id INTEGER NOT NULL,
review_role_ids TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS welcome_settings (
guild_id INTEGER PRIMARY KEY,
channel_id INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS submissions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
guild_id INTEGER NOT NULL,
source_message_id INTEGER NOT NULL UNIQUE,
source_channel_id INTEGER NOT NULL,
submitter_id INTEGER NOT NULL,
submitted_at TEXT NOT NULL,
invite_url TEXT NOT NULL,
invite_code TEXT NOT NULL,
server_name TEXT,
member_count INTEGER,
requirements_json TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'pending',
thread_id INTEGER,
created_at TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS evidence (
id INTEGER PRIMARY KEY AUTOINCREMENT,
submission_id INTEGER NOT NULL REFERENCES submissions(id),
message_id INTEGER NOT NULL UNIQUE,
submitter_id INTEGER NOT NULL,
attachments_json TEXT NOT NULL,
reference_url TEXT,
submitted_at TEXT NOT NULL,
report_json TEXT NOT NULL,
live_message_id INTEGER,
live_channel_id INTEGER,
live_author_id INTEGER,
live_created_at TEXT,
live_edited_at TEXT,
actual_mentions_json TEXT NOT NULL,
review_message_id INTEGER,
UNIQUE(submission_id)
);
CREATE TABLE IF NOT EXISTS decisions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
submission_id INTEGER NOT NULL UNIQUE REFERENCES submissions(id),
decision_type TEXT NOT NULL,
moderator_id INTEGER NOT NULL,
reason TEXT,
decided_at TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS warnings (
id INTEGER PRIMARY KEY AUTOINCREMENT,
guild_id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
warning_type TEXT NOT NULL,
reason TEXT NOT NULL,
moderator_id INTEGER NOT NULL,
related_submission_id INTEGER NOT NULL UNIQUE REFERENCES submissions(id),
created_at TEXT NOT NULL,
demotion_info_json TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS audit_log (
id INTEGER PRIMARY KEY AUTOINCREMENT,
guild_id INTEGER NOT NULL,
actor_id INTEGER NOT NULL,
action TEXT NOT NULL,
subject_id INTEGER,
related_submission_id INTEGER,
details_json TEXT NOT NULL,
created_at TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS demotions (
guild_id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
is_demoted INTEGER NOT NULL,
reason TEXT NOT NULL,
applied_by INTEGER,
applied_at TEXT,
removed_by INTEGER,
removed_at TEXT,
PRIMARY KEY (guild_id, user_id)
);
CREATE TABLE IF NOT EXISTS demotion_history (
id INTEGER PRIMARY KEY AUTOINCREMENT,
guild_id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
action TEXT NOT NULL,
reason TEXT NOT NULL,
moderator_id INTEGER NOT NULL,
created_at TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS leaderboards (
guild_id INTEGER PRIMARY KEY,
channel_id INTEGER NOT NULL,



