Files
cogs
utils
config.json
main.py
README.md
requirements.txt
Code
17 2,968
main.py
import discord
from discord.ext import commands
import os
import asyncio
import logging
from dotenv import load_dotenv
import json
import aiosqlite
load_dotenv()
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger('RyanCoBot')
class RyanCoBot(commands.Bot):
def __init__(self):
intents = discord.Intents.all()
super().__init__(command_prefix='!', intents=intents)
with open('config.json', 'r') as f:
self.config = json.load(f)
self.db = None
async def setup_hook(self):
await self.init_database()
await self.load_cogs()
guild_id = os.getenv('GUILD_ID')
if guild_id:
guild = discord.Object(id=int(guild_id))
self.tree.copy_global_to(guild=guild)
await self.tree.sync(guild=guild)
logger.info(f"Synced commands to guild {guild_id}")
else:
await self.tree.sync()
logger.info("Synced commands globally")
async def init_database(self):
self.db = await aiosqlite.connect('database.db')
await self.db.execute('''
CREATE TABLE IF NOT EXISTS tickets (
id INTEGER PRIMARY KEY AUTOINCREMENT,
ticket_id TEXT UNIQUE,
channel_id INTEGER,
user_id INTEGER,
category TEXT,
status TEXT,
claimed_by INTEGER,
priority TEXT DEFAULT 'normal',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
closed_at TIMESTAMP,
inactivity_notified BOOLEAN DEFAULT 0
)
''')
await self.db.execute('''
CREATE TABLE IF NOT EXISTS ticket_messages (
id INTEGER PRIMARY KEY AUTOINCREMENT,
ticket_id TEXT,
user_id INTEGER,
message TEXT,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (ticket_id) REFERENCES tickets (ticket_id)
)
''')
await self.db.execute('''
CREATE TABLE IF NOT EXISTS staff_notes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
ticket_id TEXT,
staff_id INTEGER,
note TEXT,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (ticket_id) REFERENCES tickets (ticket_id)
)
''')
await self.db.execute('''
CREATE TABLE IF NOT EXISTS moderation_cases (
case_id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
moderator_id INTEGER,
action TEXT,
reason TEXT,
duration INTEGER,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
await self.db.execute('''
CREATE TABLE IF NOT EXISTS warnings (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
moderator_id INTEGER,
reason TEXT,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
await self.db.execute('''
CREATE TABLE IF NOT EXISTS staff_members (
user_id INTEGER PRIMARY KEY,
strikes INTEGER DEFAULT 0,
promotions INTEGER DEFAULT 0,
activity_score INTEGER DEFAULT 0,
joined_staff TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
await self.db.execute('''
CREATE TABLE IF NOT EXISTS staff_applications (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
status TEXT DEFAULT 'pending',
application_data TEXT,
submitted_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
reviewed_by INTEGER,
reviewed_at TIMESTAMP
)
''')
await self.db.execute('''
CREATE TABLE IF NOT EXISTS suggestions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
suggestion TEXT,
status TEXT DEFAULT 'pending',
upvotes INTEGER DEFAULT 0,
downvotes INTEGER DEFAULT 0,
message_id INTEGER,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
await self.db.execute('''
CREATE TABLE IF NOT EXISTS verification (
user_id INTEGER PRIMARY KEY,
verified_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
verification_method TEXT
)
''')
await self.db.execute('''
CREATE TABLE IF NOT EXISTS safeguarding_reports (
id INTEGER PRIMARY KEY AUTOINCREMENT,
report_id TEXT UNIQUE,
reporter_id INTEGER,
anonymous BOOLEAN DEFAULT 0,
severity TEXT,
description TEXT,
evidence_links TEXT,
status TEXT DEFAULT 'open',
assigned_to INTEGER,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
resolved_at TIMESTAMP
)
''')
await self.db.commit()
logger.info("Database initialized successfully")
async def load_cogs(self):
cogs = [
'cogs.setup',
'cogs.verification',
'cogs.tickets',
'cogs.safeguarding',
'cogs.moderation',
'cogs.automod',
'cogs.staff',
'cogs.logging',
'cogs.welcome',
'cogs.business'
]
for cog in cogs:
try:
await self.load_extension(cog)
logger.info(f"Loaded {cog}")
except Exception as e:
logger.error(f"Failed to load {cog}: {e}")
async def on_ready(self):
logger.info(f'Bot is ready! Logged in as {self.user}')
logger.info(f'Bot ID: {self.user.id}')
logger.info(f'Connected to {len(self.guilds)} guild(s)')
await self.change_presence(
activity=discord.Activity(
type=discord.ActivityType.watching,
name="Ryan Co Rapid Shots"
)
)
async def close(self):
await self.db.close()