def description(self):
return 'Converts image for use as Discord avatars.'
- @asyncio.coroutine
- def handle_command(self, message, command, raw):
+ async def handle_command(self, message, command, raw):
if command not in self.valid_commands():
return PluginCommand.ignored
- yield from self.bling(message, shlex.split(raw)[1:])
+ await self.bling(message, shlex.split(raw)[1:])
return PluginCommand.exclusive
- @asyncio.coroutine
- def handle_help(self, message, *args):
+ async def handle_help(self, message, *args):
lines = [
'Convert an image into an avatar suitable for use on Discord.',
'```',
'If no `PROFILE` is specified with `--profile` I will use the `default` profile. All `PROFILE`s, including `default`, are installed by my administrator under a subdirectory of `{0}`. The background image should be installed as `{1}` and the foreground image should be installed as `{2}`, for example `{0}{3}default{3}{1} and {0}{3}default{3}{2}.'.format(self.path, self.bgname, self.fgname, os.sep),
'Your image will be overlaid *above* {} and *beneath* {}.'.format(self.bgname, self.fgname)
]
- yield from bot.say_many(message.channel, lines)
+ await bot.say_many(message.channel, lines)
- @asyncio.coroutine
- def bling(self, message, args):
+ async def bling(self, message, args):
ap = ThrowingArgumentParser()
ap.add_argument('--profiles', action='store_true')
ap.add_argument('--profile', nargs='?')
try:
parsed = ap.parse_args(args)
except ArgumentParserError:
- yield from cat.yelp(message.channel)
+ await cat.yelp(message.channel)
return
if parsed.profiles:
- yield from self.list_profiles(message)
+ await self.list_profiles(message)
else:
create = {}
if parsed.name:
create['name'] = parsed.name
if parsed.profile:
create['profile'] = parsed.profile
- yield from self.bling_message(message, **create)
+ await self.bling_message(message, **create)
def profiles(self):
# Subdirectories with a foreground or background image.
fgs = glob.glob(os.sep.join([self.path, '*', self.fgname]))
return list(filter(lambda dir: dir != 'default', set([path.split(os.sep)[-2] for path in bgs + fgs])))
- @asyncio.coroutine
- def list_profiles(self, message):
+ async def list_profiles(self, message):
profiles = self.profiles()
if len(profiles):
- yield from bot.say_many(message.channel, profiles)
+ await bot.say_many(message.channel, profiles)
else:
- yield from cat.shrug(message.channel)
+ await cat.shrug(message.channel)
def parse_message(self, message, name):
parsed = {
parsed['url'] = message.author.avatar_url
return parsed
- @asyncio.coroutine
- def bling_message(self, message, *, name = None, profile = 'default'):
+ async def bling_message(self, message, *, name = None, profile = 'default'):
if profile != 'default':
if profile not in self.profiles():
- yield from bot.say(message.channel, '{}?'.format(profile))
+ await bot.say(message.channel, '{}?'.format(profile))
return
parsed = self.parse_message(message, name)
if parsed['url'] is None:
log.debug('No URL for avatar to bling.')
- yield from cat.zzz(message.channel)
+ await cat.zzz(message.channel)
return
- yield from client.send_typing(message.channel)
+ await client.send_typing(message.channel)
data = self.create_avatar(parsed['url'], os.sep.join([self.path, profile, self.bgname]), os.sep.join([self.path, profile, self.fgname]))
if data is None:
- yield from cat.yelp(message.channel)
+ await cat.yelp(message.channel)
return
text = ' '.join(parsed['mentions']) if parsed['mentions'] is not None else 'purr'
- yield from bot.say(message.channel, text, attachment = bot.parse_attachment(data, parsed['filename'] + '.png'))
+ await bot.say(message.channel, text, attachment = bot.parse_attachment(data, parsed['filename'] + '.png'))
def create_avatar(self, url, bgfile, fgfile):
# Get Delta images.