Esempio n. 1
0
 async def list(self, context):
     server = context.message.guild
     roles  = []
     with self.bot.db() as db:
         for row in db.get('selfroles', {'server_id': server.id}):
             role = server.get_role(row['id'])
             if role is not None:
                 roles.append(role)
     await context.send(embed=MechaEmbed(
         title='Self-assignable roles',
         description=listify(roles),
         context=context
     ))
Esempio n. 2
0
 async def topic(self, context, *, channel: discord.TextChannel = None):
     target = channel or context.message.channel
     if target.topic is None:
         await context.send(
             'Sorry da-don... There is no topic set on this channel...'
             '\n(´;ω;`)')
         return
     content = target.topic
     if target != context.message.channel:
         content += '\n\nLink: {0.mention}'.format(target)
     await context.send(
         embed=MechaEmbed(title='#{}\'s topic'.format(target),
                          description=content,
                          context=context))
Esempio n. 3
0
 async def get_bday(self, context):
     with self.bot.db() as db:
         result = db.get('birthdays', context.author.id)
         if len(result) == 0:
             await context.send(
                 'You did not tell me your birthday yet da-don....'
                 '\nYou can do so with `!bday <date>`')
             return
         date = datetime.strptime(result[0]['date'], DATE_BACK)
         await context.send(
             embed=MechaEmbed(title='{0.display_name}\'s birthday 🎂'.
                              format(context.author),
                              description=date.strftime(DATE_FRONT),
                              context=context))
Esempio n. 4
0
 async def bdays(self, context, n: int = 5):
     with self.bot.db() as db:
         entries = db.get('birthdays',
                          [m.id for m in context.guild.members])
         today_power = self.to_power(datetime.now().strftime(DATE_BACK))
         ranking = {}
         for e in entries:
             relative_power = self.to_power(e['date']) - today_power
             if relative_power < 0:
                 relative_power += 1212
             ranking[relative_power] = e
         ranking = sorted(ranking.items())[:n]
         msg = listify(self.to_bdays_list(ranking,
                                          context.guild.get_member))
         await context.send(embed=MechaEmbed(
             title='Upcoming birthdays', description=msg, context=context))
Esempio n. 5
0
 async def vim(self, context, *, tag):
     with self.bot.db(self.bot.config.vim_db_path) as db:
         results = db.get('tags', {'name': tag})
         if len(results) is 0:
             raise ThinkingError
         tag = results[0]
         results = db.get('help', tag['help_id'])
         if len(results) is 0:
             await context.send(embed=MechaEmbed(
                 description=
                     'An entry for this tag exists but it\'s empty\n'
                     'Maybe it has subtags, try a more precise one!',
                 context=context
             ))
             return
         await context.send('```\n{}\n```'.format(results[0]['content']))
Esempio n. 6
0
 async def on_command_error(self, context, exception):
     if isinstance(exception, commands.errors.CommandInvokeError):
         exception = exception.original
     if isinstance(exception,
                   (commands.errors.CommandNotFound, ThinkingError)):
         logging.info('Ignoring exception: ' + str(exception))
         await context.message.add_reaction('🤔')
         return
     logging.info('Reporting {0.__class__.__name__}: {0}'.format(
         exception, ))
     embed = {
         'title': '*Dongyaa--!! An error occured da-don!*',
         'colour': discord.Colour.orange(),
         'description': str(exception),
         'context': context
     }
     await context.send(embed=MechaEmbed(**embed))
Esempio n. 7
0
 async def wishes(self):
     today = datetime.now()
     if self.to_power(today.strftime('%H-%M')) == self.wishes_time:
         self.wishes.change_interval(hours=24)
     else:
         return
     with self.bot.db() as db:
         today_bdays = db.get('birthdays',
                              {'date': today.strftime(DATE_BACK)})
         bday_servers = db.get('servers',
                               {'birthday_channel': MDB.NotEmpty},
                               ['id', 'birthday_channel'])
         for server in bday_servers:
             channel_id = server['birthday_channel']
             server_id = server['id']
             server = discord.utils.get(self.bot.guilds, id=server_id)
             if server is None:
                 logging.warn(
                     'Server id {} exists in DB but can not be found in the'
                     ' bot\'s servers'.format(server_id))
                 continue
             channel = discord.utils.get(server.channels, id=channel_id)
             if channel is None:
                 logging.warn(
                     'Channel id {} exists in the bot DB but can not be'
                     ' found on the server {}'.format(channel_id, server))
                 continue
             server_bdays = [
                 discord.utils.get(server.members, id=e['id'])
                 for e in today_bdays
             ]
             if len(server_bdays) is 0:
                 continue
             await channel.send(
                 embed=MechaEmbed(title='Today\'s birthdays! 🎉',
                                  description=listify(server_bdays),
                                  footer=self.qualified_name))
Esempio n. 8
0
 async def server(self, context):
     await context.send(embed=MechaEmbed(
         title=context.guild.name,
         description=listify(['ID: {}'.format(context.guild.id)]),
         context=context))
Esempio n. 9
0
 async def stickers(self, context):
     await context.send(
         embed=MechaEmbed(title='List of trigger words to send a sticker',
                          description=listify(self.stickers.keys()),
                          context=context))