[Owner] Refactoring

This commit is contained in:
Twentysix 2016-11-14 14:40:28 +01:00
parent 70afff5b5f
commit 26404ebced

View File

@ -549,6 +549,45 @@ class Owner:
else:
break
@commands.command(pass_context=True)
@checks.is_owner()
async def servers(self, ctx):
"""Lists and allows to leave servers"""
owner = ctx.message.author
servers = sorted(list(self.bot.servers),
key=lambda s: s.name.lower())
msg = ""
for i, server in enumerate(servers):
msg += "{}: {}\n".format(i, server.name)
msg += "\nTo leave a server just type its number."
for page in pagify(msg, ['\n']):
await self.bot.say(page)
while msg is not None:
msg = await self.bot.wait_for_message(author=owner, timeout=15)
try:
msg = int(msg.content)
await self.leave_confirmation(servers[msg], owner, ctx)
break
except (IndexError, ValueError, AttributeError):
pass
async def leave_confirmation(self, server, owner, ctx):
await self.bot.say("Are you sure you want me "
"to leave {}? (yes/no)".format(server.name))
msg = await self.bot.wait_for_message(author=owner, timeout=15)
if msg is None:
await self.bot.say("I guess not.")
elif msg.content.lower().strip() in ("yes", "y"):
await self.bot.leave_server(server)
if server != ctx.message.server:
await self.bot.say("Done.")
else:
await self.bot.say("Alright then.")
@commands.command(pass_context=True)
async def contact(self, ctx, *, message : str):
"""Sends message to the owner"""
@ -585,24 +624,6 @@ class Owner:
"<https://github.com/Twentysix26/Red-DiscordBot/>\n"
"**Official server:**\n<https://discord.me/Red-DiscordBot>")
async def leave_confirmation(self, server, owner, ctx):
if not ctx.message.channel.is_private:
current_server = ctx.message.server
else:
current_server = None
answers = ("yes", "y")
await self.bot.say("Are you sure you want me "
"to leave {}? (yes/no)".format(server.name))
msg = await self.bot.wait_for_message(author=owner, timeout=15)
if msg is None:
await self.bot.say("I guess not.")
elif msg.content.lower().strip() in answers:
await self.bot.leave_server(server)
if server != current_server:
await self.bot.say("Done.")
else:
await self.bot.say("Alright then.")
@commands.command()
async def uptime(self):
"""Shows Red's uptime"""
@ -639,12 +660,8 @@ class Owner:
raise CogUnloadError
def _list_cogs(self):
cogs = glob.glob("cogs/*.py")
clean = []
for c in cogs:
c = c.replace("/", "\\") # Linux fix
clean.append("cogs." + c.split("\\")[1].replace(".py", ""))
return clean
cogs = [os.path.basename(f) for f in glob.glob("cogs/*.py")]
return ["cogs." + os.path.splitext(f)[0] for f in cogs]
def _does_cogfile_exist(self, module):
if "cogs." not in module: