Example #1
0
    def __get_server_and_member(self, discord_server, discord_user):
        member = Member.objects(discord=discord_user.id).first()
        server = Server.objects(id=discord_server.id).first()

        if not server:
            server = Server.create({
                'id': discord_server.id,
                'name': discord_server.name,
                'avatar': discord_server.icon_url or ''
            })

        if not member:
            member = Member.create({
                'discord': discord_user.id,
                'name': discord_user.name,
                'avatar': discord_user.avatar_url or ''
            })

        # Checks if member being added is in the server
        server_member = Member.objects(servers=discord_server.id,
                                       discord=discord_user.id).first()
        if not server_member:
            server.members.append(member)
            server.save()
            member.servers.append(discord_server.id)
            member.save()

        return (server, member)
Example #2
0
    def on_post(self, req: falcon.Request, res: falcon.Response, token):
        data = store.token.validate(store.token.AUD_VERIFICATION, token)

        if not data:
            raise falcon.HTTPBadRequest("InvalidToken")

        # check if club exists and is enabled
        club = ClubModel.by_discord_id(data["gid"])
        if not club or not club.is_enabled:
            raise falcon.HTTPBadRequest("ClubNotExists")

        if not club.verified_role_id:
            raise falcon.HTTPBadRequest("ClubNotConfigured")

        # grab user once we verify existence of club
        user = UserModel.by_discord_id(data["uid"])

        if user == None and "user" not in req.media:
            raise falcon.HTTPBadRequest("NoUserDetails")

        # destroy and lock token
        if not store.token.destroy(token):
            raise falcon.HTTPBadRequest("InvalidToken")

        if user == None:
            user = UserModel.create({
                "discord_id": data["uid"],
                **req.media["user"]
            })
        try:
            MemberModel.create({"user_id": user._id, "club_id": club._id})
        except Exception as e:
            logger.warn("Error creating member: ", e)

        if user.is_verified:
            lib.rpc.bot_add_roles(data["uid"], data["gid"],
                                  [club.verified_role_id])
            return self.send_response(res, {"user_verified": True})
        else:
            token = store.token.generate_validation(
                user._id, "zid" if user.zid else "email")
            send_validation(
                to=f"{user.zid}@unsw.edu.au" if user.zid else user.email,
                name=user.given_name,
                token=token)

            return self.send_response(res, {"user_verified": False})
Example #3
0
    "ap": 197,
    "aap": 197,
    "dp": 238,
    "gear_score": 435,
    "progress": 0.0,
    "gear_pic": "https://i.imgur.com/UFViCXj.jpg",
    "server": 2,
    "primary": True,
    "member": 2,
})

## Test Members Creation

member1 = Member.create({
    "discord": 1,
    "servers": [1],
    "name": "Test1",
    "avatar": "Some_Url1"
})
member1.characters.append(char1)
member1.characters.append(char2)

member2 = Member.create({
    "discord": 2,
    "servers": [2],
    "name": "Test2",
    "avatar": "Some_Url2"
})
member2.characters.append(char3)

## Dummy Server Creation