Пример #1
0
 def test_embed(self):
     embed = MessageEmbed(title='Test Title',
                          description='Test Description',
                          url='https://test.url/')
     obj = embed.to_dict()
     self.assertEqual(obj['title'], 'Test Title')
     self.assertEqual(obj['description'], 'Test Description')
     self.assertEqual(obj['url'], 'https://test.url/')
Пример #2
0
 def test_empty_embed(self):
     embed = MessageEmbed()
     self.assertDictEqual(
         embed.to_dict(), {
             'image': {},
             'author': {},
             'video': {},
             'thumbnail': {},
             'footer': {},
             'fields': [],
             'type': 'rich',
         })
Пример #3
0
    def update_hint(self, hint):
        HintsConsumer.send_to_all(
            json.dumps({
                'id':
                hint.id,
                'content':
                render_to_string('hint_list_entry.html', {
                    'hint': hint,
                    'now': timezone.localtime()
                })
            }))
        embed = MessageEmbed()
        embed.author.url = hint.full_url()
        if hint.claimed_datetime:
            embed.color = 0xdddddd
            embed.timestamp = hint.claimed_datetime.isoformat()
            embed.author.name = 'Claimed by {}'.format(hint.claimer)
            if hint.claimer in self.get_avatars():
                embed.author.icon_url = self.get_avatars()[hint.claimer]
            debug = 'claimed by {}'.format(hint.claimer)
        else:
            embed.color = 0xff00ff
            embed.author.name = 'U N C L A I M E D'
            claim_url = hint.full_url(claim=True)
            embed.title = 'Claim: ' + claim_url
            embed.url = claim_url
            debug = 'unclaimed'

        if self.client is None:
            message = hint.long_discord_message()
            logger.info('Hint, {}: {}\n{}'.format(debug, hint, message))
            logger.info('Embed: {}'.format(embed.to_dict()))
        elif hint.discord_id:
            try:
                self.client.channels_messages_modify(self.HINT_CHANNEL,
                                                     hint.discord_id,
                                                     embed=embed)
            except Exception:
                dispatch_general_alert(
                    'Discord API failure: modify\n{}'.format(
                        traceback.format_exc()))
        else:
            message = hint.long_discord_message()
            try:
                discord_id = self.client.channels_messages_create(
                    self.HINT_CHANNEL, message, embed=embed).id
            except Exception:
                dispatch_general_alert(
                    'Discord API failure: create\n{}'.format(
                        traceback.format_exc()))
                return
            hint.discord_id = discord_id
            hint.save(update_fields=('discord_id', ))