def setup(self, guild=False): # pylint: disable=attribute-defined-outside-init self.bot = mock.Bot() self.cog = score.Score(self.bot) self.ctx = mock.Context(self.bot) if guild: self.ctx.set_guild() database.delete(f"channel:{self.ctx.channel.id}") database.zrem("score:global", str(self.ctx.channel.id)) database.zrem("users:global", str(self.ctx.author.id)) database.zrem("streak:global", str(self.ctx.author.id)) database.zrem("streak.max:global", str(self.ctx.author.id)) if self.ctx.guild is not None: database.delete(f"users.server:{self.ctx.guild.id}") asyncio.run(channel_setup(self.ctx)) asyncio.run(user_setup(self.ctx))
def update_web_user(user_data): logger.info("updating user data") session_id = get_session_id() user_id = str(user_data["id"]) database.hset(f"web.session:{session_id}", "user_id", user_id) database.expire(f"web.session:{session_id}", DATABASE_SESSION_EXPIRE) database.hset( f"web.user:{user_id}", mapping={ "avatar_hash": str(user_data["avatar"]), "avatar_url": f"https://cdn.discordapp.com/avatars/{user_id}/{user_data['avatar']}.png", "username": str(user_data["username"]), "discriminator": str(user_data["discriminator"]), }, ) asyncio.run(user_setup(user_id)) tempScore = int(database.hget(f"web.session:{session_id}", "tempScore")) if tempScore not in (0, -1): database.zincrby("users:global", tempScore, int(user_id)) database.hset(f"web.session:{session_id}", "tempScore", -1) logger.info("updated user data")