async def user_status(ctx): """ Verifica o relatório de afeição que Luci possui de um determinado membro. Uso: !user @Username """ mentions = ctx.message.mentions if not mentions: return await tx.send( 'Não sei de quem vc está falando. Marca ele tipo @Fulano.') # consulta os membros no backend server = make_hash('id', ctx.message.guild.id).decode('utf-8') user_id = make_hash(server, mentions[0].id).decode('utf-8') payload = Query.get_user(user_id) gql_client = get_gql_client(BACKEND_URL) try: response = gql_client.execute(payload) except Exception as err: log.error(f'Erro: {str(err)}\n\n') return data = response.get('users', []) if not data: return await ctx.send('Acho que não c-conheço... Desculpa.') # monta a resposta embed = discord.Embed(color=0x1E1E1E, type='rich') name = data[0].get('name') friendshipness = data[0].get('friendshipness', 0) emotions = data[0].get('emotion_resume', {}) user_id = extract_user_id(data[0]['reference']) pleasantness_status = EmotionHourglass.get_pleasantness( emotions["pleasantness"]) pleasantness = f':heart_decoration: {emotions["pleasantness"]:.2f} '\ f'| status: {pleasantness_status}' attention_status = EmotionHourglass.get_attention(emotions["attention"]) attention = f':yin_yang: {emotions["attention"]:.2f} | status: {attention_status}' sensitivity_status = EmotionHourglass.get_sensitivity( emotions["sensitivity"]) sensitivity = f':place_of_worship: {emotions["sensitivity"]:.2f} | ' \ f'status: {sensitivity_status}' aptitude_status = EmotionHourglass.get_aptitude(emotions["aptitude"]) aptitude = f':atom: {emotions["aptitude"]:.2f} | status: {aptitude_status}' embed.add_field(name='Username', value=name, inline=True) embed.add_field(name='Affection', value=friendshipness, inline=True) embed.add_field(name='Pleasantness', value=pleasantness, inline=False) embed.add_field(name='Attention', value=attention, inline=False) embed.add_field(name='Sensitivity', value=sensitivity, inline=False) embed.add_field(name='Aptitude', value=aptitude, inline=False) return await ctx.send('', embed=embed)
async def status(bot): """ Verifica o estado emocional da Luci. """ server = make_hash('id', bot.guild.id) payload = Query.get_emotions(server.decode('utf-8')) client = get_gql_client(BACKEND_URL) try: response = client.execute(payload) except Exception as err: print(f'Erro: {str(err)}\n\n') return await bot.send('Buguei') humor = response.get('emotions') if humor: luci_humor = humor[0] embed = discord.Embed(color=0x1E1E1E, type='rich') pleasantness_status = EmotionHourglass.get_pleasantness( luci_humor["pleasantness"] ) pleasantness = f':heart_decoration: {luci_humor["pleasantness"]:.2f} '\ f'| status: {pleasantness_status}' attention_status = EmotionHourglass.get_attention( luci_humor["attention"] ) attention = f':yin_yang: {luci_humor["attention"]:.2f} | status: {attention_status}' sensitivity_status = EmotionHourglass.get_sensitivity( luci_humor["sensitivity"] ) sensitivity = f':place_of_worship: {luci_humor["sensitivity"]:.2f} | ' \ f'status: {sensitivity_status}' aptitude_status = EmotionHourglass.get_aptitude(luci_humor["aptitude"]) aptitude = f':atom: {luci_humor["aptitude"]:.2f} | status: {aptitude_status}' embed.add_field(name='Pleasantness', value=pleasantness, inline=False) embed.add_field(name='Attention', value=attention, inline=False) embed.add_field(name='Sensitivity', value=sensitivity, inline=False) embed.add_field(name='Aptitude', value=aptitude, inline=False) return await bot.send('', embed=embed)
def test_get_aptitude(self): """ Verify that the method that returns the aptitude label works correcly based on the value inputed. """ self.assertEqual(EmotionHourglass.get_aptitude(-2.5), 'disgust') self.assertEqual(EmotionHourglass.get_aptitude(-2), 'disgust') self.assertEqual(EmotionHourglass.get_aptitude(-1.5), 'boredom') self.assertEqual(EmotionHourglass.get_aptitude(-1), 'boredom') self.assertEqual(EmotionHourglass.get_aptitude(-0.5), 'neutral') self.assertEqual(EmotionHourglass.get_aptitude(0), 'neutral') self.assertEqual(EmotionHourglass.get_aptitude(0.5), 'neutral') self.assertEqual(EmotionHourglass.get_aptitude(1), 'acceptance') self.assertEqual(EmotionHourglass.get_aptitude(1.5), 'acceptance') self.assertEqual(EmotionHourglass.get_aptitude(2), 'trust') self.assertEqual(EmotionHourglass.get_aptitude(2.5), 'trust')
def test_get_pleasantness(self): """ Verify that the method that returns the pleasantness label works correcly based on the value inputed. """ self.assertEqual(EmotionHourglass.get_pleasantness(-2.5), 'sadness') self.assertEqual(EmotionHourglass.get_pleasantness(-2), 'sadness') self.assertEqual(EmotionHourglass.get_pleasantness(-1.5), 'pensiveness') self.assertEqual(EmotionHourglass.get_pleasantness(-1), 'pensiveness') self.assertEqual(EmotionHourglass.get_pleasantness(-0.5), 'neutral') self.assertEqual(EmotionHourglass.get_pleasantness(0), 'neutral') self.assertEqual(EmotionHourglass.get_pleasantness(0.5), 'neutral') self.assertEqual(EmotionHourglass.get_pleasantness(1), 'serenity') self.assertEqual(EmotionHourglass.get_pleasantness(1.5), 'serenity') self.assertEqual(EmotionHourglass.get_pleasantness(2), 'joy') self.assertEqual(EmotionHourglass.get_pleasantness(2.5), 'joy')
def test_get_sensitivity(self): """ Verify that the method that returns the sensitivity label works correcly based on the value inputed. """ self.assertEqual(EmotionHourglass.get_sensitivity(-2.5), 'fear') self.assertEqual(EmotionHourglass.get_sensitivity(-2), 'fear') self.assertEqual(EmotionHourglass.get_sensitivity(-1.5), 'aprehension') self.assertEqual(EmotionHourglass.get_sensitivity(-1), 'aprehension') self.assertEqual(EmotionHourglass.get_sensitivity(-0.5), 'neutral') self.assertEqual(EmotionHourglass.get_sensitivity(0), 'neutral') self.assertEqual(EmotionHourglass.get_sensitivity(0.5), 'neutral') self.assertEqual(EmotionHourglass.get_sensitivity(1), 'annoyance') self.assertEqual(EmotionHourglass.get_sensitivity(1.5), 'annoyance') self.assertEqual(EmotionHourglass.get_sensitivity(2), 'anger') self.assertEqual(EmotionHourglass.get_sensitivity(2.5), 'anger')
def test_get_attention(self): """ Verify that the method that returns the attention label works correcly based on the value inputed. """ self.assertEqual(EmotionHourglass.get_attention(-2.5), 'surprise') self.assertEqual(EmotionHourglass.get_attention(-2), 'surprise') self.assertEqual(EmotionHourglass.get_attention(-1.5), 'distraction') self.assertEqual(EmotionHourglass.get_attention(-1), 'distraction') self.assertEqual(EmotionHourglass.get_attention(-0.5), 'neutral') self.assertEqual(EmotionHourglass.get_attention(0), 'neutral') self.assertEqual(EmotionHourglass.get_attention(0.5), 'neutral') self.assertEqual(EmotionHourglass.get_attention(1), 'interest') self.assertEqual(EmotionHourglass.get_attention(1.5), 'interest') self.assertEqual(EmotionHourglass.get_attention(2), 'anticipation') self.assertEqual(EmotionHourglass.get_attention(2.5), 'anticipation')