-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
132 lines (117 loc) · 4.33 KB
/
Copy pathmain.py
File metadata and controls
132 lines (117 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import os
import discord
from discord.ext import commands
from discord import app_commands
import asyncio
import logging
import json
import datetime
from dotenv import load_dotenv
import traceback
# Set up logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger('pointer_bot')
# Load environment variables
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD_ID = os.getenv('GUILD_ID')
# Define intents
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
# Create bot instance
class PointerBot(commands.Bot):
def __init__(self):
super().__init__(
command_prefix='!', # Fallback prefix (not used for slash commands)
intents=intents,
activity=discord.Activity(type=discord.ActivityType.watching, name="Pointer Community"),
status=discord.Status.online
)
self.initial_extensions = [
'cogs.economy',
'cogs.fun',
'cogs.leveling',
'cogs.jobs',
'cogs.admin',
'cogs.help',
'cogs.shop',
'cogs.giveaway',
]
async def setup_hook(self):
# Load extensions
for extension in self.initial_extensions:
try:
await self.load_extension(extension)
logger.info(f"Loaded extension: {extension}")
except Exception as e:
logger.error(f"Failed to load extension {extension}: {e}")
traceback.print_exc()
# Sync commands for the specific guild
guild = discord.Object(id=int(GUILD_ID))
self.tree.copy_global_to(guild=guild)
await self.tree.sync(guild=guild)
logger.info("Synced commands to guild")
async def on_ready(self):
logger.info(f"{self.user} is connected to Discord!")
logger.info(f"Connected to {len(self.guilds)} guild(s)")
# Create necessary directories if they don't exist
os.makedirs("data", exist_ok=True)
# Initialize database files if they don't exist
self.initialize_data_files()
def initialize_data_files(self):
# Initialize economy data
if not os.path.exists("data/economy.json"):
with open("data/economy.json", "w") as f:
json.dump({}, f)
logger.info("Created economy.json")
# Initialize leveling data
if not os.path.exists("data/levels.json"):
with open("data/levels.json", "w") as f:
json.dump({}, f)
logger.info("Created levels.json")
# Initialize jobs data
if not os.path.exists("data/jobs.json"):
jobs_data = {
"jobs": [
{
"id": "miner",
"name": "Miner",
"description": "Mine for coins every 30 minutes",
"pay_rate": 50,
"pay_interval": 30 # minutes
},
{
"id": "farmer",
"name": "Farmer",
"description": "Farm for coins every hour",
"pay_rate": 120,
"pay_interval": 60 # minutes
},
{
"id": "programmer",
"name": "Programmer",
"description": "Code for coins every 2 hours",
"pay_rate": 300,
"pay_interval": 120 # minutes
}
],
"user_jobs": {}
}
with open("data/jobs.json", "w") as f:
json.dump(jobs_data, f, indent=4)
logger.info("Created jobs.json with default jobs")
# Initialize giveaways data
if not os.path.exists("data/giveaways.json"):
with open("data/giveaways.json", "w") as f:
json.dump({}, f)
logger.info("Created giveaways.json")
# Run the bot
async def main():
bot = PointerBot()
try:
await bot.start(TOKEN)
except KeyboardInterrupt:
await bot.close()
if __name__ == "__main__":
asyncio.run(main())