-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
93 lines (78 loc) · 2.54 KB
/
bot.py
File metadata and controls
93 lines (78 loc) · 2.54 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
import asyncio
import os
import platform
import discord
from discord.ext import commands
from github import Github
from canvasapi import Canvas
from pyowm.owm import OWM
import wolframalpha
from pokedex import pokedex
# Platform-specific config loading
if platform.uname().node == 'Andrew' or 'oracle' in platform.uname().release:
import config
TOKEN = config.discord_token
GITHUB_TOKEN = config.github_token
CANVAS_API_KEY = config.API_KEY
WEATHER_API_KEY = config.weather
WOLFRAM_APP_ID = config.wolf
RAPIDAPI_KEY = config.rapidapi
SERPAPI_KEY = config.serpapi
else:
TOKEN = os.getenv('config.token')
GITHUB_TOKEN = os.getenv('github_token')
CANVAS_API_KEY = os.getenv('canvasapikey')
WEATHER_API_KEY = os.getenv('weatherkey')
WOLFRAM_APP_ID = os.getenv('wolf')
RAPIDAPI_KEY = os.getenv('rapidapi')
SERPAPI_KEY = os.getenv('serpapi')
# Shared API headers
RAPIDAPI_HEADERS = {
"X-RapidAPI-Key": RAPIDAPI_KEY,
"X-RapidAPI-Host": "mashape-community-urban-dictionary.p.rapidapi.com"
}
# List of cogs to load
COG_EXTENSIONS = [
'cogs.utility',
'cogs.fun',
'cogs.storage',
'cogs.moderation',
'cogs.reference',
'cogs.reminders',
'cogs.calendar',
'cogs.canvas',
'cogs.ai',
'cogs.listeners',
]
class TreeBot(commands.Bot):
"""Main bot class with shared resources."""
def __init__(self):
intents = discord.Intents.all()
super().__init__(command_prefix='!', intents=intents)
# Initialize shared resources
self.github = Github(GITHUB_TOKEN)
self.canvas = Canvas('https://canvas.cmu.edu/', CANVAS_API_KEY)
self.owm = OWM(WEATHER_API_KEY)
self.wolfram = wolframalpha.Client(WOLFRAM_APP_ID)
self.pokedex = pokedex.Pokedex()
self.serpapi_key = SERPAPI_KEY
self.rapidapi_headers = RAPIDAPI_HEADERS
# Remove default help command to use custom one
self.remove_command('help')
async def setup_hook(self):
"""Load all cog extensions."""
for extension in COG_EXTENSIONS:
try:
await self.load_extension(extension)
print(f'Loaded extension: {extension}')
except Exception as e:
print(f'Failed to load extension {extension}: {e}')
async def on_ready(self):
"""Called when the bot is ready."""
print(f'We have logged in as {self.user}')
async def main():
"""Main entry point."""
bot = TreeBot()
await bot.start(TOKEN)
if __name__ == '__main__':
asyncio.run(main())