Skip to content

Commit 49e1f69

Browse files
committed
fix platform and platform package name overlap
Signed-off-by: RedTeaDev <[email protected]>
1 parent 9ca6c0e commit 49e1f69

File tree

2 files changed

+65
-64
lines changed

2 files changed

+65
-64
lines changed

teapot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def copyright():
3535
return f"© 2020-{year()} RedCoke Development"
3636

3737

38-
def platform():
38+
def getPlatform():
3939
return platform.system() + " " + platform.release()
4040

4141

teapot/cogs/cmds.py

Lines changed: 64 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
11
import discord
2-
import psutil
32
import time
4-
import typing
5-
3+
import psutil
4+
from discord.ext import commands as cmd
65

76
import teapot
87

98

10-
class Commands(discord.ext.commands.Cog):
11-
def __init__(self, bot):
12-
self.bot = bot
9+
def __init__(bot):
10+
""" Initialize commands """
11+
helpcmd(bot)
12+
info(bot)
13+
ping(bot)
14+
prune(bot)
15+
kick(bot)
16+
ban(bot)
17+
admin(bot)
18+
owner(bot)
19+
debug(bot)
20+
1321

14-
@discord.ext.commands.command(aliases=['?'])
15-
async def help(self, ctx, *cog):
22+
def helpcmd(bot):
23+
bot.remove_command('help')
24+
25+
@bot.command(aliases=['?'])
26+
async def help(ctx, *cog):
1627
if not cog:
1728
embed = discord.Embed(description="📖 Help", color=0x7400FF,
1829
icon_url="https://cdn.discordapp.com/avatars/612634758744113182"
1930
"/7fe078b5ea6b43000dfb7964e3e4d21d.png?size=512")
2031
embed.set_thumbnail(url="https://avatars2.githubusercontent.com/u/60006969?s=200&v=4")
2132
cogs_desc = ""
22-
for x in self.bot.cogs:
23-
cogs_desc += f'**{x}** - {self.bot.cogs[x].__doc__}\n'
33+
for x in bot.cogs:
34+
cogs_desc += f'**{x}** - {bot.cogs[x].__doc__}\n'
2435
embed.add_field(name='Modules', value=cogs_desc[0:len(cogs_desc) - 1])
2536
embed.set_footer(text=f"{teapot.copyright()} | Code licensed under the MIT License")
2637
await ctx.send(embed=embed)
@@ -31,21 +42,21 @@ async def help(self, ctx, *cog):
3142
await ctx.message.add_reaction(emoji='🛑')
3243
else:
3344
found = False
34-
for x in self.bot.cogs:
45+
for x in bot.cogs:
3546
for y in cog:
3647
if x == y:
3748
embed = discord.Embed(color=0x7400FF)
3849
cog_info = ''
39-
for c in self.bot.get_cog(y).get_commands():
50+
for c in bot.get_cog(y).get_commands():
4051
if not c.hidden:
4152
cog_info += f"**{c.name}** - {c.help}\n"
4253
embed.add_field(name=f"{cog[0]} Module", value=cog_info)
4354
await ctx.send(embed=embed)
4455
await ctx.message.add_reaction(emoji='✅')
4556
found = True
4657
if not found:
47-
for x in self.bot.cogs:
48-
for c in self.bot.get_cog(x).get_commands():
58+
for x in bot.cogs:
59+
for c in bot.get_cog(x).get_commands():
4960
if c.name.lower() == cog[0].lower():
5061
embed = discord.Embed(title=f"Command: {c.name.lower().capitalize()}",
5162
description=f"**Description:** {c.help}\n**Syntax:** {c.qualified_name} {c.signature}",
@@ -63,18 +74,19 @@ async def help(self, ctx, *cog):
6374
await ctx.message.add_reaction(emoji='✅')
6475

6576

66-
@discord.ext.commands.command(aliases=['about'])
67-
async def info(self, ctx):
77+
def info(bot):
78+
@bot.command(aliases=['about'])
79+
async def info(ctx):
6880
embed = discord.Embed(title="Developers: RedTeaDev, ColaIan", description="Multi-purpose Discord Bot",
6981
color=0x7400FF)
7082
embed.set_author(name=f"Teapot.py {teapot.version()}",
7183
icon_url="https://cdn.discordapp.com/avatars/612634758744113182"
7284
"/7fe078b5ea6b43000dfb7964e3e4d21d.png?size=512")
7385
embed.set_thumbnail(url="https://avatars2.githubusercontent.com/u/60006969?s=200&v=4")
74-
embed.add_field(name="Bot User:", value=self.bot.user)
75-
embed.add_field(name="Guilds:", value=len(self.bot.guilds))
76-
embed.add_field(name="Members:", value=len(set(self.bot.get_all_members())))
77-
embed.add_field(name="O.S.:", value=str(teapot.platform()))
86+
embed.add_field(name="Bot User:", value=bot.user)
87+
embed.add_field(name="Guilds:", value=len(bot.guilds))
88+
embed.add_field(name="Members:", value=len(set(bot.get_all_members())))
89+
embed.add_field(name="O.S.:", value=str(teapot.getPlatform()))
7890
embed.add_field(name="Storage Type:", value=teapot.config.storage_type())
7991
embed.add_field(name="Prefix:", value=", ".join(teapot.config.bot_prefix()))
8092
embed.add_field(name="Github Repo:", value="[Teapot.py](https://github.com/RedCokeDevelopment/Teapot.py)")
@@ -85,22 +97,24 @@ async def info(self, ctx):
8597
"https://discordapp.com/oauth2/authorize?client_id=669880564270104586&permissions=8"
8698
"&scope=bot) | [Repository](https://github.com/RedCokeDevelopment/Teapot.py)",
8799
inline=False)
88-
embed.set_footer(text=f"{teapot.copyright()} | Code licensed under MIT License")
100+
embed.set_footer(text=f"{teapot.copyright()} | Code licensed under the MIT License")
89101
embed.set_image(
90102
url="https://user-images.githubusercontent.com/43201383/72987537-89830a80-3e25-11ea-95ef-ecfa0afcff7e.png")
91103
await ctx.send(embed=embed)
92104
await ctx.message.add_reaction(emoji='✅')
93105

94106

95-
@discord.ext.commands.command()
96-
async def ping(self, ctx):
97-
await ctx.send(f'Pong! {round(self.bot.latency * 1000)} ms')
107+
def ping(bot):
108+
@bot.command()
109+
async def ping(ctx):
110+
await ctx.send(f'Pong! {round(bot.latency * 1000)} ms')
98111
await ctx.message.add_reaction(emoji='✅')
99112

100113

101-
@discord.ext.commands.command(aliases=['purge', 'clear', 'cls'])
102-
@discord.ext.commands.has_permissions(manage_messages=True)
103-
async def prune(self, ctx, amount=0):
114+
def prune(bot):
115+
@bot.command(aliases=['purge', 'clear', 'cls'])
116+
@cmd.has_permissions(manage_messages=True)
117+
async def prune(ctx, amount=0):
104118
if amount == 0:
105119
await ctx.send("Please specify the number of messages you want to delete!")
106120
await ctx.message.add_reaction(emoji='❌')
@@ -112,9 +126,10 @@ async def prune(self, ctx, amount=0):
112126
await ctx.channel.purge(limit=amount + 1)
113127

114128

115-
@discord.ext.commands.command()
116-
@discord.ext.commands.has_permissions(kick_members=True) # check user permission
117-
async def kick(self, ctx, member: discord.Member, *, reason=None):
129+
def kick(bot):
130+
@bot.command()
131+
@cmd.has_permissions(kick_members=True) # check user permission
132+
async def kick(ctx, member: discord.Member, *, reason=None):
118133
try:
119134
await member.kick(reason=reason)
120135
await ctx.send(f'{member} has been kicked!')
@@ -124,39 +139,28 @@ async def kick(self, ctx, member: discord.Member, *, reason=None):
124139
await ctx.message.add_reaction(emoji='❌')
125140

126141

127-
@discord.ext.commands.command()
128-
@discord.ext.commands.has_permissions(ban_members=True) # check user permission
129-
async def ban(self, ctx, member: typing.Any[discord.Member, discord.User], *, reason=None): # Banning a member who is not in the server is also possible
142+
def ban(bot):
143+
@bot.command()
144+
@cmd.has_permissions(ban_members=True) # check user permission
145+
async def ban(ctx, member: discord.Member, *, reason=None):
130146
try:
131-
if isinstance(member, discord.Member):
132-
await member.ban(reason=reason)
133-
else:
134-
await ctx.guild.ban(member, reason=reason)
135-
136-
await ctx.send(f'{member.name} has been banned!')
147+
await member.ban(reason=reason)
148+
await ctx.send(f'{member} has been banned!')
137149
await ctx.message.add_reaction(emoji='✅')
138150
except Exception as e:
139151
await ctx.send("Failed to ban: " + str(e))
140152
await ctx.message.add_reaction(emoji='❌')
141-
142-
@discord.ext.commands.command()
143-
@discord.ext.commands.has_permissions(ban_members=True) # check user permission
144-
async def unban(self, ctx, member: discord.User, *, reason=None):
145-
try:
146-
await ctx.guild.unban(member, reason=reason)
147-
await ctx.send(f'{member.name} has been unbanned!')
148-
await ctx.message.add_reaction(emoji='✅')
149-
except Exception as e:
150-
await ctx.send("Failed to unban: " + str(e))
151-
await ctx.message.add_reaction(emoji='❌')
152153

153-
@discord.ext.commands.command() # Work In Progress
154-
async def admin(self, ctx):
154+
155+
def admin(bot): # WIP...
156+
@bot.command()
157+
async def admin(ctx):
155158
await ctx.send(embed=teapot.messages.WIP())
156159

157160

158-
@discord.ext.commands.command()
159-
async def owner(self, ctx):
161+
def owner(bot):
162+
@bot.command()
163+
async def owner(ctx):
160164
if ctx.message.author.id == teapot.config.bot_owner():
161165
found = False
162166
for role in ctx.guild.roles:
@@ -173,20 +177,21 @@ async def owner(self, ctx):
173177
break
174178

175179

176-
@discord.ext.commands.command()
177-
@discord.ext.commands.has_permissions(administrator=True)
178-
async def debug(self, ctx):
180+
def debug(bot):
181+
@bot.command()
182+
@cmd.has_permissions(administrator=True)
183+
async def debug(ctx):
179184
embed = discord.Embed(title="Developers: RedTea, ColaIan", description="Debug info:",
180185
color=0x7400FF)
181186
embed.set_author(name=f"Teapot.py {teapot.version()}",
182187
icon_url="https://cdn.discordapp.com/avatars/612634758744113182/7fe078b5ea6b43000dfb7964e3e4d21d.png?size=512")
183188
embed.set_thumbnail(url="https://avatars2.githubusercontent.com/u/60006969?s=200&v=4")
184-
embed.add_field(name="Bot User:", value=self.bot.user, inline=True)
189+
embed.add_field(name="Bot User:", value=bot.user, inline=True)
185190
embed.add_field(name="System Time:", value=time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()), inline=True)
186191
embed.add_field(name="Memory",
187192
value=str(round(psutil.virtual_memory()[1] / 1024 / 1024 / 1024)) + "GB / " + str(round(
188193
psutil.virtual_memory()[0] / 1024 / 1024 / 1024)) + "GB", inline=True)
189-
embed.add_field(name="O.S.:", value=str(teapot.platform()), inline=True)
194+
embed.add_field(name="O.S.:", value=str(teapot.getPlatform()), inline=True)
190195
embed.add_field(name="Storage Type:", value=teapot.config.storage_type(), inline=True)
191196
embed.add_field(name="Prefix:", value=", ".join(teapot.config.bot_prefix()), inline=True)
192197
embed.add_field(name="Github Repo:", value="[Teapot.py](https://github.com/RedCokeDevelopment/Teapot.py)",
@@ -201,7 +206,3 @@ async def debug(self, ctx):
201206
# embed.set_image(url="https://user-images.githubusercontent.com/43201383/72987537-89830a80-3e25-11ea-95ef-ecfa0afcff7e.png")
202207
await ctx.message.author.send(embed=embed)
203208
await ctx.message.add_reaction(emoji='✅')
204-
205-
206-
def setup(bot):
207-
bot.add_cog(Commands(bot))

0 commit comments

Comments
 (0)