Skip to content

Instantly share code, notes, and snippets.

@zhudotexe
Created February 25, 2017 07:25
Show Gist options
  • Save zhudotexe/93b9f864a8792abf18d1d5c8bdb0d548 to your computer and use it in GitHub Desktop.
Save zhudotexe/93b9f864a8792abf18d1d5c8bdb0d548 to your computer and use it in GitHub Desktop.
@commands.command(hidden=True, pass_context=True)
@checks.is_owner()
async def assume_direct_control(self, ctx, chan:str):
"""Assumes direct control of Avrae."""
def cleanup_code(content):
"""Automatically removes code blocks from the code."""
# remove ```py\n```
if content.startswith('```') and content.endswith('```'):
return '\n'.join(content.split('\n')[1:-1])
# remove `foo`
return content.strip('` \n')
self.assume_dir_control_chan = self.bot.get_channel(chan)
while True:
response = await self.bot.wait_for_message(author=ctx.message.author, channel=ctx.message.channel,
check=lambda m: m.content.startswith('`'))
cleaned = cleanup_code(response.content)
if cleaned in ('quit', 'exit', 'exit()'):
await self.bot.say('Exiting.')
self.assume_dir_control_chan = None
return
else:
await self.bot.send_message(self.assume_dir_control_chan, cleaned)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment