Skip to content

Commit 9ea5b4b

Browse files
authored
Merge pull request #99 from RedCokeDevelopment/rt-rewrite
Rewrite Teapot.py to support latest version of discord.py
2 parents 19c6aeb + d44397b commit 9ea5b4b

23 files changed

+435
-321
lines changed

.github/FUNDING.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# These are supported funding model platforms
2+
3+
github: RedCokeDevelopment # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
#patreon: # Replace with a single Patreon username
5+
#open_collective: # Replace with a single Open Collective username
6+
#ko_fi: # Replace with a single Ko-fi username
7+
#tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
#community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
#liberapay: # Replace with a single Liberapay username
10+
#issuehunt: # Replace with a single IssueHunt username
11+
#lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
12+
#polar: # Replace with a single Polar username
13+
buy_me_a_coffee: Colaian # Replace with a single Buy Me a Coffee username
14+
#thanks_dev: # Replace with a single thanks.dev username
15+
#custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

.github/workflows/Teapot.py.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v2
17-
- name: Set up Python 3.9.16
17+
- name: Set up Python 3.10.18
1818
uses: actions/setup-python@v2
1919
with:
20-
python-version: 3.9.16
20+
python-version: 3.10.18
2121
- name: Install dependencies
2222
run: |
2323
python -m pip install --upgrade pip

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ There are two owners for this project. They all contribute massively to the runn
5151
## 📜 Requirements
5252
These are the requirements for the bot.
5353

54-
- [Python 3.9](https://www.python.org/downloads) (Required packages listed in requirements.txt)
54+
- [Python 3.10](https://www.python.org/downloads) (Required packages listed in requirements.txt)
5555
- [LavaLink Server](https://github.com/freyacodes/lavalink) (Java 11 required)
56+
- Database is optional but preferred
5657

5758
## 💖 Credits
5859
The projects listed in below have provided inspiration, and we thought we'd mention them:

Teapot.py

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import discord
88
from discord.ext import commands as dcmd
99
from dotenv import load_dotenv
10+
import lavalink
1011

1112
import teapot
13+
from teapot.event_handler.loader import EventHandlerLoader
1214

1315
print(f"""
1416
_____ _
@@ -70,7 +72,7 @@
7072
db.execute(
7173
'CREATE TABLE IF NOT EXISTS `channels` (`channel_id` BIGINT, `channel_name` TINYTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci')
7274
db.execute(
73-
"CREATE TABLE IF NOT EXISTS `users` (`user_id` BIGINT, `user_name` TINYTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, `user_discriminator` INT) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci")
75+
"CREATE TABLE IF NOT EXISTS `users` (`user_id` BIGINT, `user_name` TINYTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, `user_display_name` TINYTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci")
7476
db.execute(
7577
"CREATE TABLE IF NOT EXISTS `bot_logs` (`timestamp` TEXT, `type` TINYTEXT, `class` TINYTEXT, `message` MEDIUMTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci")
7678
teapot.managers.database.create_table(
@@ -83,30 +85,57 @@
8385
print(
8486
f"Connected to database ({teapot.config.db_host()}:{teapot.config.db_port()}) in {round(time.perf_counter() - time_start, 2)}s")
8587

86-
intents = discord.Intents.default()
88+
89+
intents = discord.Intents.all()
8790
intents.members = True
91+
intents.message_content = True
8892
intents.typing = False
8993
bot = dcmd.Bot(intents=intents, command_prefix=teapot.config.bot_prefix(), help_command=None)
9094

95+
event_handler_loader = EventHandlerLoader(bot) # Event Handler
96+
97+
9198
@bot.event
9299
async def on_ready():
93100
print(f"Connected to Discord API in {round(time.perf_counter() - discord_time_start, 2)}s")
94101
time_start = time.perf_counter()
102+
95103
# load cogs
96104
teapot.events.__init__(bot)
97-
teapot.cogs.cmds.__init__(bot)
98-
teapot.cogs.music.setup(bot)
99-
teapot.cogs.osu.setup(bot)
100-
teapot.cogs.github.setup(bot)
101-
teapot.cogs.cat.setup(bot)
102-
teapot.cogs.neko.setup(bot)
103-
teapot.cogs.nqn.setup(bot)
105+
# Initialize lavalink client once here so cogs do not need to recreate it
106+
if not hasattr(bot, 'lavalink'):
107+
print("Initializing Lavalink client...")
108+
bot.lavalink = lavalink.Client(bot.user.id)
109+
bot.lavalink.add_node(teapot.config.lavalink_host(), teapot.config.lavalink_port(), teapot.config.lavalink_password(), 'zz', 'default')
110+
bot.add_listener(bot.lavalink.voice_update_handler, 'on_socket_response')
111+
extensions = [
112+
'teapot.cogs.cmds',
113+
'teapot.cogs.osu',
114+
'teapot.cogs.github',
115+
'teapot.cogs.cat',
116+
'teapot.cogs.neko',
117+
'teapot.cogs.nqn',
118+
'teapot.cogs.music' # TODO: WIP
119+
]
120+
121+
for extension in extensions:
122+
try:
123+
await bot.load_extension(extension)
124+
print(f"✓ Successfully loaded module: {extension}")
125+
except Exception as e:
126+
print(f"✗ Failed to load {extension}: {e}")
127+
import traceback
128+
traceback.print_exc()
104129
if teapot.config.storage_type() == "mysql":
105130
for guild in bot.guilds:
106131
teapot.managers.database.create_guild_table(guild)
107132
elif teapot.config.storage_type() == "sqlite":
108133
print("[!] Warning: SQLite storage has not been implemented yet. MySQL is recommended") # WIP
134+
109135
print(f"Registered commands and events in {round(time.perf_counter() - time_start, 2)}s")
136+
print(f"total of commands loaded: {len(bot.commands)}")
137+
print(f"Modules loaded: {list(bot.cogs.keys())}")
138+
110139
await bot.change_presence(status=discord.Status.online,
111140
activity=discord.Game(teapot.config.bot_status())) # Update Bot status
112141

requirements.txt

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
aiohttp>=3.6.2
2-
async-timeout>=3.0.1
3-
attrs>=19.3.0
4-
beautifulsoup4>=4.10.0
5-
bs4>=0.0.1
6-
certifi>=2021.5.30
7-
chardet>=3.0.4
8-
discord.py>=1.7.3
9-
idna>=2.10
10-
lavalink>=3.1.2
11-
multidict>=4.7.6
1+
aiohttp>=3.12.15
2+
async-timeout>=5.0.1
3+
attrs>=25.3.0
4+
beautifulsoup4>=4.14.0
5+
bs4>=0.0.2
6+
certifi>=2025.8.3
7+
chardet>=5.2.0
8+
discord.py>=2.6.3
9+
idna>=3.10
10+
lavalink>=5.9.0
11+
multidict>=6.6.4
1212
mysql-connector>=2.2.9
13-
psutil>=5.7.2
14-
python-dotenv>=0.14.0
15-
requests>=2.24.0
16-
soupsieve>=2.0.1
17-
typing-extensions>=3.7.4.2
18-
urllib3>=1.25.10
19-
websockets>=8.1
20-
yarl>=1.5.1
21-
mysql-connector-python>=8.0.21
22-
alt-profanity-check==1.1.3
23-
protobuf>=3.20.2 # not directly required, pinned by Snyk to avoid a vulnerability
24-
13+
psutil>=7.1.0
14+
python-dotenv>=1.1.1
15+
requests>=2.32.5
16+
soupsieve>=2.8
17+
typing-extensions>=4.15.0
18+
urllib3>=2.5.0
19+
websockets>=15.0.1
20+
yarl>=1.20.1
21+
mysql-connector-python>=9.4.0
22+
alt-profanity-check==1.7.2
23+
PyNaCl>=1.6.1
24+
protobuf>=6.32.1 # not directly required, pinned by Snyk to avoid a vulnerability

teapot/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
def version():
16-
return "v0.0.1.7"
16+
return "v0.0.2-REWRITE"
1717

1818

1919
def config_version():
@@ -29,13 +29,10 @@ def year():
2929

3030

3131
def copyright():
32-
if year() == "2020":
33-
return "© 2020 RedCoke Development"
34-
else:
3532
return f"© 2020-{year()} RedCoke Development"
3633

3734

38-
def platform():
35+
def get_platform():
3936
return platform.system() + " " + platform.release()
4037

4138

teapot/cogs/cat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ async def dog(self, ctx):
4747
await ctx.message.add_reaction(emoji='✅')
4848

4949

50-
def setup(bot):
50+
async def setup(bot):
5151
""" Setup Cat Module"""
52-
bot.add_cog(Cat(bot))
52+
await bot.add_cog(Cat(bot))

0 commit comments

Comments
 (0)