Add user_events module and user_update event

This commit is contained in:
Dustin Pianalto 2019-12-14 01:07:25 -09:00
parent 876bd54687
commit a318f129c9
2 changed files with 30 additions and 0 deletions

View File

@ -3,6 +3,7 @@
"admin",
"exec",
"message_events",
"user_events",
"tickets"
]
}

View File

@ -0,0 +1,29 @@
import discord
from discord.ext import commands
from datetime import datetime
import logging
user_logger = logging.getLogger('UserEvents')
class UserEvents(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listner()
async def on_user_update(self, before, after):
data = {
'username': after.name,
'discriminator': after.discriminator,
'animated': after.is_avatar_animated(),
'avatar': after.avatar or str(after.default_avatar)
}
resp = await self.bot.aio_session.put(f'{self.bot.api_base}/users/{after.id}/',
headers=self.bot.auth_header,
json=data)
user_logger.info(f'User Update Response:\n{await resp.json()}')
def setup(bot):
bot.add_cog(UserEvents(bot))